Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Source.Common/Networking/IConnectionlessPacketHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public class NetAddress

public NetAddress Copy() => new() {
Type = Type,
Endpoint = Endpoint
Endpoint = Endpoint == null ? null : new IPEndPoint(Endpoint.Address, Endpoint.Port)
};
static char[][] renderBuffers;
static int curRenderBuffer;
Expand Down Expand Up @@ -236,10 +236,10 @@ public bool CompareAdr(NetAddress? a, bool onlyBase = false) {
}

public void SetIP(uint v) {
IP = new(v);
IP = new(System.Buffers.Binary.BinaryPrimitives.ReverseEndianness(v));
}
public void SetIP(uint v, ushort port) {
IP = new(v);
SetIP(v);
Port = port;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Source.Engine/GarrysMod/Get.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public void ShutDown() {

public void RunSteamCallbacks() {
if (IsDedicatedServer())
SteamGameServer_RunCallbacks();
Steamworks.GameServer.RunCallbacks();
else
SteamAPI.RunCallbacks();
}
Expand Down
8 changes: 8 additions & 0 deletions Source.Engine/Net.cs
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,14 @@ bool OpenSocketInternal(NetSocketType module, int setPort, int defaultPort, stri
public void Init(bool isDedicated) {
Time = 0;

ICommandLine commandLine = Singleton<ICommandLine>();
int port = commandLine.ParmValue("-port", -1);
if (port == -1)
port = commandLine.ParmValue("+port", -1);

if (port != -1)
hostport.SetValue(port);

NetSockets.EnsureCount(NetSocket.MAX);
NetPackets.EnsureCount(NetSocket.MAX);
SplitPackets.EnsureCount(NetSocket.MAX);
Expand Down
7 changes: 4 additions & 3 deletions Source.Engine/Server/BaseServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -609,12 +609,12 @@ public virtual bool ProcessConnectionlessPacket(NetPacket packet) {
if (!QueryRateChecker.CheckIP(packet.From))
return false;

if (Steam3Server().SteamGameServer() != null) {
if (Steam3Server().SteamGameServer() != null && Steam3Server().IsMasterServerUpdaterSharingGameSocket()) {
SteamGameServer.HandleIncomingPacket(
packet.Message.GetData(),
packet.Message.BytesAvailable,
(uint)packet.From.Endpoint!.AddressFamily,
(ushort)packet.From.Endpoint!.Port
packet.From.GetIPHostByteOrder(),
(ushort)packet.From.GetPort()
);

ForwardPacketsFromMasterServerUpdater();
Expand Down Expand Up @@ -1470,6 +1470,7 @@ protected void ForwardPacketsFromMasterServerUpdater() {

// Send this packet for them..
adr.SetIP(netadrAddress, netadrPort);
adr.Type = NetAddressType.IP;
Net.SendPacket(null!, Socket, adr, packetData, len);
}
}
Expand Down
26 changes: 24 additions & 2 deletions Source.Engine/Server/SteamAuth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ public EServerMode GetCurrentServerMode() {
return EServerMode.eServerModeAuthenticationAndSecure;
}

const ushort MASTERSERVERUPDATERPORT_USEGAMESOCKETSHARE = 0xFFFF;

static readonly ConVar sv_master_share_game_socket = new("sv_master_share_game_socket", "1", 0, "Use the game's socket to communicate to the master server. If this is 0, then it will create a socket on -steamport + 1 to communicate to the master server on.");

public ushort GetQueryPort() => QueryPort;
public bool IsMasterServerUpdaterSharingGameSocket() => MasterServerUpdaterSharingGameSocket;

public bool BSecure() => SteamGameServer()?.BSecure() ?? false;
public bool BIsActive() => SteamGameServer() != null && (ServerMode >= EServerMode.eServerModeNoAuthentication);
public bool BLanOnly() => ServerMode == EServerMode.eServerModeNoAuthentication;
Expand Down Expand Up @@ -131,6 +138,21 @@ public void Activate(ServerType serverType) {
if (serverType == ServerType.Normal)
gamePort = (ushort)Net.GetUDPPort(NetSocketType.Server);

ushort masterServerUpdaterPort;
if (sv_master_share_game_socket.GetBool()) {
MasterServerUpdaterSharingGameSocket = true;
masterServerUpdaterPort = MASTERSERVERUPDATERPORT_USEGAMESOCKETSHARE;
if (serverType == ServerType.TVRelay)
QueryPort = (ushort)Net.GetUDPPort(NetSocketType.HLTV);
else
QueryPort = gamePort;
}
else {
MasterServerUpdaterSharingGameSocket = false;
masterServerUpdaterPort = Port;
QueryPort = Port;
}

switch (ServerMode) {
case EServerMode.eServerModeNoAuthentication:
Msg("Initializing Steam libraries for LAN server\n");
Expand All @@ -147,7 +169,7 @@ public void Activate(ServerType serverType) {
break;
}

Steamworks.GameServer.Init(IP, gamePort, (ushort)(Port + 1), ServerMode, GetSteamInfIDVersionInfo().PatchVersion);
Steamworks.GameServer.Init(IP, gamePort, masterServerUpdaterPort, ServerMode, GetSteamInfIDVersionInfo().PatchVersion);

if (!Init()) {
Assert(false);
Expand Down Expand Up @@ -524,7 +546,7 @@ public void RunFrame() {
double CurTime = Platform.Time;
if (CurTime - LastRunCallback > 0.1f) {
LastRunCallback = CurTime;
SteamGameServer_RunCallbacks();
Steamworks.GameServer.RunCallbacks();
}
}

Expand Down
Loading