Skip to content

Commit

Permalink
Change NatNeg and Gstats names
Browse files Browse the repository at this point in the history
  • Loading branch information
Sporesirius committed Nov 1, 2020
1 parent 88874dd commit fee865e
Show file tree
Hide file tree
Showing 49 changed files with 562 additions and 120 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/gstats-cd.yml → .github/workflows/gs-cd.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: CD - GSTATS
name: CD - GS

on:
push:
paths:
- 'src/Servers/StatsAndTracking/**'
- 'src/Servers/GameStatus/**'
branches:
- master
- candidate
Expand Down Expand Up @@ -34,21 +34,21 @@ jobs:
DOCKER_HUB_KEY: ${{ secrets.DOCKER_HUB_KEY }}
steps:
- uses: actions/checkout@v2
- name: Deploy GSTATS to staging
- name: Deploy GS to staging
if: github.ref == 'refs/heads/candidate'
uses: elgohr/[email protected]
with:
name: gameprogressive/gstats
username: ${{ secrets.DOCKER_HUB_USER }}
password: ${{ secrets.DOCKER_HUB_KEY }}
tagging: true
dockerfile: ./src/Servers/StatsAndTracking/Dockerfile
- name: Deploy GSTATS to production
dockerfile: ./src/Servers/GameStatus/Dockerfile
- name: Deploy GS to production
if: github.ref == 'refs/heads/master'
uses: elgohr/[email protected]
with:
name: gameprogressive/gstats
username: ${{ secrets.DOCKER_HUB_USER }}
password: ${{ secrets.DOCKER_HUB_KEY }}
tagging: true
dockerfile: ./src/Servers/StatsAndTracking/Dockerfile
dockerfile: ./src/Servers/GameStatus/Dockerfile
16 changes: 8 additions & 8 deletions .github/workflows/natneg-cd.yml → .github/workflows/nn-cd.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: CD - NatNeg
name: CD - NN

on:
push:
paths:
- 'src/Servers/NatNegotiation/**'
- 'src/Servers/NATNegotiation/**'
branches:
- master
- candidate
Expand Down Expand Up @@ -34,21 +34,21 @@ jobs:
DOCKER_HUB_KEY: ${{ secrets.DOCKER_HUB_KEY }}
steps:
- uses: actions/checkout@v2
- name: Deploy NatNeg to staging
- name: Deploy NN to staging
if: github.ref == 'refs/heads/candidate'
uses: elgohr/[email protected]
with:
name: gameprogressive/natneg
name: gameprogressive/nn
username: ${{ secrets.DOCKER_HUB_USER }}
password: ${{ secrets.DOCKER_HUB_KEY }}
tagging: true
dockerfile: ./src/Servers/NatNegotiation/Dockerfile
- name: Deploy NatNeg to production
dockerfile: ./src/Servers/NATNegotiation/Dockerfile
- name: Deploy NN to production
if: github.ref == 'refs/heads/master'
uses: elgohr/[email protected]
with:
name: gameprogressive/natneg
name: gameprogressive/nn
username: ${{ secrets.DOCKER_HUB_USER }}
password: ${{ secrets.DOCKER_HUB_KEY }}
tagging: true
dockerfile: ./src/Servers/NatNegotiation/Dockerfile
dockerfile: ./src/Servers/NATNegotiation/Dockerfile
2 changes: 1 addition & 1 deletion RetroSpy.sln
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServerBrowser", "src\Server
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Servers", "Servers", "{9F19D8DE-3F11-44BB-BDDA-897FA2CBDB2E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GameStatus", "src\Servers\StatsAndTracking\GameStatus.csproj", "{1E16BA28-F6EA-4D85-98FC-73475764D8EA}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GameStatus", "src\Servers\GameStatus\GameStatus.csproj", "{1E16BA28-F6EA-4D85-98FC-73475764D8EA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CDKey", "src\Servers\CDKey\CDKey.csproj", "{C679E140-ED80-4D1E-BD94-C54C4158BDD5}"
EndProject
Expand Down
21 changes: 21 additions & 0 deletions src/Servers/GameStatus/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1.7-alpine3.12 AS base
WORKDIR /app
EXPOSE 29920

FROM mcr.microsoft.com/dotnet/core/sdk:3.1.401-alpine3.12 AS build
WORKDIR /src
COPY ["src/Servers/GameStatus/GameStatus.csproj", "src/Servers/GameStatus/"]
COPY ["src/Libraries/GameSpyLib/GameSpyLib.csproj", "src/Libraries/GameSpyLib/"]
RUN dotnet restore "src/Servers/GameStatus/GameStatus.csproj"
COPY . .
WORKDIR "/src/src/Servers/GameStatus"
RUN dotnet build "GameStatus.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "GameStatus.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
COPY ./common/RetroSpyServer.json .
ENTRYPOINT ["dotnet", "GameStatus.dll"]
File renamed without changes.
File renamed without changes.
File renamed without changes.
35 changes: 35 additions & 0 deletions src/Servers/NATNegotiation/Application/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using GameSpyLib.Abstraction.BaseClass;
using GameSpyLib.Entity.Structure;
using GameSpyLib.Logging;
using Serilog.Events;
using System;
namespace NATNegotiation.Application
{
/// <summary>
/// This class represents a RetroSpy Server program
/// </summary>
internal class Program
{
private static ServerManager Manager;

private static void Main(string[] args)
{

try
{
//create a instance of ServerManager class
Manager = new ServerManager(RetroSpyServerName.NATNegotiation);
Manager.Start();
Console.Title = "RetroSpy Server " + ServerManagerBase.RetroSpyVersion;
}
catch (Exception e)
{
LogWriter.ToLog(LogEventLevel.Error, e.ToString());
}


Console.WriteLine("Press < Q > to exit. ");
while (Console.ReadKey().Key != ConsoleKey.Q) { }
}
}
}
43 changes: 43 additions & 0 deletions src/Servers/NATNegotiation/Application/ServerManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using GameSpyLib.Abstraction.BaseClass;
using GameSpyLib.Extensions;
using GameSpyLib.RetroSpyConfig;
using NATNegotiation.Server;
using System;
using System.Net;

namespace NATNegotiation.Application
{
/// <summary>
/// A factory that create the instance of servers
/// </summary>
public class ServerManager : ServerManagerBase
{
/// <summary>
/// Constructor
/// </summary>
/// <param name="serverName">Server name in config file</param>
public ServerManager(string serverName) : base(serverName)
{
}

public override void Start()
{
ShowRetroSpyLogo();
//LoadDatabaseConfig();
LoadServerConfig();
}
/// <summary>
/// Starts a specific server
/// </summary>
/// <param name="cfg">The configuration of the specific server to run</param>
protected override void StartServer(ServerConfig cfg)
{
if (cfg.Name == ServerName)
{
Server = new NatNegServer(IPAddress.Parse(cfg.ListeningAddress), cfg.ListeningPort).Start();
Console.WriteLine(
StringExtensions.FormatServerTableContext(cfg.Name, cfg.ListeningAddress, cfg.ListeningPort.ToString()));
}
}
}
}
22 changes: 22 additions & 0 deletions src/Servers/NATNegotiation/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1.7-alpine3.12 AS base
WORKDIR /app
EXPOSE 27901
EXPOSE 27901/udp

FROM mcr.microsoft.com/dotnet/core/sdk:3.1.401-alpine3.12 AS build
WORKDIR /src
COPY ["src/Servers/NATNegotiation/NATNegotiation.csproj", "src/Servers/NATNegotiation/"]
COPY ["src/Libraries/GameSpyLib/GameSpyLib.csproj", "src/Libraries/GameSpyLib/"]
RUN dotnet restore "src/Servers/NATNegotiation/NATNegotiation.csproj"
COPY . .
WORKDIR "/src/src/Servers/NATNegotiation"
RUN dotnet build "NATNegotiation.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "NATNegotiation.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
COPY ./common/RetroSpyServer.json .
ENTRYPOINT ["dotnet", "NATNegotiation.dll"]
15 changes: 15 additions & 0 deletions src/Servers/NATNegotiation/Entity/Enumerator/NNErrorCode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace NATNegotiation.Entity.Enumerate
{
public enum NNErrorCode
{
NoError,
RequestError,
MagicDataError,
VersionError,
PacketTypeError,
CookieError,
InitPacketError,
ConnectPacketError,
ReportPacketError
}
}
113 changes: 113 additions & 0 deletions src/Servers/NATNegotiation/Entity/Enumerator/NatNegEnum.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
namespace NATNegotiation.Entity.Enumerate
{
public enum ConnectPacketFinishStatus : byte
{
NoError,
DeadHeartBeat,
InitPacketTimeOut
}

public enum NatPortType : byte
{
/// <summary>
/// Use game port for nat neg
/// </summary>
GP,
/// <summary>
/// IP and Port both restricted
/// </summary>
NN1,
/// <summary>
/// IP not restricted
/// </summary>
NN2,
/// <summary>
/// Port not restriced
/// </summary>
NN3
}

public enum NatPacketType : byte
{
/// <summary>
/// Initialize nat negotiation with cookie
/// </summary>
Init,
InitAck,
/// <summary>
/// External reachability test
/// </summary>
ErtTest,
ErtAck,
StateUpdate,
/// <summary>
/// Notify participant to negotiate
/// </summary>
Connect,
ConnectAck,
/// <summary>
/// Connect other participant with ping packet
/// </summary>
ConnectPing,
BackupTest,
BackupAck,
AddressCheck,
AddressReply,
NatifyRequest,
Report,
ReportAck,
PreInit,
PreInitAck,
}

internal enum NatifyPacketType : byte
{
PacketMap1a,
PacketMap2,
PacketMap3,
PacketMap1b,
NumPackets
}

public enum NATNegotiationMappingScheme : byte
{
Unrecognized,
PrivateAsPublic,
ConsistentPort,
Incremental,
Mixed,
NumMappingSchemes
}

public enum NATNegotiationType
{
NoNat,
FirewallOnly,
FullCone,
RestrictedCone,
PortRestrictedCone,
Symmetric,
Unknown,
NumNatTypes
}

public enum NatPromiscuity
{
Promiscuous,
NotPromiscuous,
PortPromiscuous,
IPPromiscuous,
PromiscuityNotApplicable,
NumPromiscuityTypes
}

public enum NATNegotiationResult
{
Success,
DeadBeatPartner,
InitTimeOut,
PingTimeOut,
UnknownError,
NoResult
}
}
20 changes: 20 additions & 0 deletions src/Servers/NATNegotiation/Entity/Structure/GameInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace NATNegotiation.Entity.Structure
{
public class GameInfo
{
public int ID;
public string Name;
public string Secretkey;
public ushort QueryPort;
public ushort BackendFlags;
public uint ServicesDisabled;
public KeyData PushKeys;
public byte NumPushKeys; //sb protocol sends as a byte so max of 255
}

public class KeyData
{
public byte Name;
public byte Type;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using GameSpyLib.Abstraction.Interface;
using NATNegotiation.Abstraction.BaseClass;
using NATNegotiation.Entity.Enumerate;
using NATNegotiation.Entity.Structure.Request;
using NATNegotiation.Entity.Structure.Response;

namespace NATNegotiation.Handler.CommandHandler
{
public class AddressCheckHandler : NNCommandHandlerBase
{
protected new AddressRequest _request;
public AddressCheckHandler(ISession session, IRequest request) : base(session, request)
{
_request = (AddressRequest)request;
}

protected override void ConstructResponse()
{
_sendingBuffer = new AddressResponse(_request, _session.RemoteEndPoint).BuildResponse();


_session.UserInfo.SetIsGotAddressCheckPacketFlag().
UpdateLastPacketReceiveTime();
}
}
}
Loading

0 comments on commit fee865e

Please sign in to comment.