Add server setting 'AdvertiseOnLocalNetwork' to be able to disable BeaconLib.

This commit is contained in:
Vapre
2025-06-14 19:46:58 +02:00
committed by Matthias Mailänder
parent c19a7d338b
commit f325e9c7b9
5 changed files with 34 additions and 15 deletions

View File

@@ -969,7 +969,8 @@ namespace OpenRA
{
Name = "Skirmish Game",
Map = map,
AdvertiseOnline = false
AdvertiseOnline = false,
AdvertiseOnLocalNetwork = !isSkirmish
};
// Always connect to local games using the same loopback connection

View File

@@ -53,6 +53,9 @@ namespace OpenRA
[Desc("Reports the game to the master server list.")]
public bool AdvertiseOnline = true;
[Desc("Reports the game on the local area network.")]
public bool AdvertiseOnLocalNetwork = true;
[Desc("Locks the game with a password.")]
public string Password = "";

View File

@@ -48,13 +48,14 @@ namespace OpenRA.Mods.Common.Server
[FluentReference]
const string GameOffline = "notification-game-offline";
static readonly Beacon LanGameBeacon;
static readonly ushort LanAdvertisePort = (ushort)new Random(DateTime.Now.Millisecond).Next(2048, 60000);
static readonly Dictionary<int, string> MasterServerErrors = new()
{
{ 1, NoPortForward },
{ 2, BlacklistedTitle }
};
Beacon lanGameBeacon;
long lastPing = 0;
long lastChanged = 0;
bool isInitialPing = true;
@@ -62,14 +63,16 @@ namespace OpenRA.Mods.Common.Server
volatile bool isBusy;
readonly Queue<string> masterServerMessages = [];
static MasterServerPinger()
void CreateLanGameBeacon()
{
try
{
LanGameBeacon = new Beacon("OpenRALANGame", (ushort)new Random(DateTime.Now.Millisecond).Next(2048, 60000));
lanGameBeacon?.Stop();
lanGameBeacon = new Beacon("OpenRALANGame", LanAdvertisePort);
}
catch (Exception ex)
{
lanGameBeacon = null;
Log.Write("server", "BeaconLib.Beacon: " + ex.Message);
}
}
@@ -83,27 +86,34 @@ namespace OpenRA.Mods.Common.Server
// Update the master server and LAN clients if something has changed
// Note that isBusy is set while the master server ping is running on a
// background thread, and limits LAN pings as well as master server pings for simplicity.
if (!isBusy && ((lastChanged > lastPing && Game.RunTime - lastPing > RateLimitInterval) || isInitialPing))
if ((server.Settings.AdvertiseOnline || server.Settings.AdvertiseOnLocalNetwork)
&& !isBusy && ((lastChanged > lastPing && Game.RunTime - lastPing > RateLimitInterval) || isInitialPing))
{
var gs = new GameServer(server);
if (server.Settings.AdvertiseOnline)
UpdateMasterServer(server, gs.ToPOSTData(false));
if (LanGameBeacon != null)
LanGameBeacon.BeaconData = gs.ToPOSTData(true);
if (server.Settings.AdvertiseOnLocalNetwork && lanGameBeacon != null)
lanGameBeacon.BeaconData = gs.ToPOSTData(true);
lastPing = Game.RunTime;
}
lock (masterServerMessages)
while (masterServerMessages.Count > 0)
server.SendFluentMessage(masterServerMessages.Dequeue());
if (server.Settings.AdvertiseOnline)
lock (masterServerMessages)
while (masterServerMessages.Count > 0)
server.SendFluentMessage(masterServerMessages.Dequeue());
}
void INotifyServerStart.ServerStarted(S server)
{
if (server.IsMultiplayer && LanGameBeacon != null)
LanGameBeacon.Start();
if (server.IsMultiplayer && server.Settings.AdvertiseOnLocalNetwork)
{
if (lanGameBeacon == null)
CreateLanGameBeacon();
lanGameBeacon?.Start();
}
}
void INotifyServerShutdown.ServerShutdown(S server)
@@ -115,7 +125,8 @@ namespace OpenRA.Mods.Common.Server
UpdateMasterServer(server, gameServer.ToPOSTData(false));
}
LanGameBeacon?.Stop();
lanGameBeacon?.Stop();
lanGameBeacon = null;
}
public void LobbyInfoSynced(S server)
@@ -130,7 +141,8 @@ namespace OpenRA.Mods.Common.Server
public void GameEnded(S server)
{
LanGameBeacon?.Stop();
lanGameBeacon?.Stop();
lanGameBeacon = null;
lastChanged = Game.RunTime;
}

View File

@@ -7,6 +7,7 @@ set Mod=ra
set Map=""
set ListenPort=1234
set AdvertiseOnline=True
set AdvertiseOnLocalNetwork=True
set Password=""
set RecordReplays=False
@@ -26,6 +27,6 @@ set SupportDir=""
:loop
bin\OpenRA.Server.exe Engine.EngineDir=".." Game.Mod=%Mod% Server.Name=%Name% Server.Map=%Map% Server.ListenPort=%ListenPort% Server.AdvertiseOnline=%AdvertiseOnline% Server.EnableSingleplayer=%EnableSingleplayer% Server.Password=%Password% Server.RecordReplays=%RecordReplays% Server.RequireAuthentication=%RequireAuthentication% Server.ProfileIDBlacklist=%ProfileIDBlacklist% Server.ProfileIDWhitelist=%ProfileIDWhitelist% Server.EnableSyncReports=%EnableSyncReports% Server.EnableGeoIP=%EnableGeoIP% Server.EnableLintChecks=%EnableLintChecks% Server.ShareAnonymizedIPs=%ShareAnonymizedIPs% Server.FloodLimitJoinCooldown=%FloodLimitJoinCooldown% Engine.SupportDir=%SupportDir%
bin\OpenRA.Server.exe Engine.EngineDir=".." Game.Mod=%Mod% Server.Name=%Name% Server.Map=%Map% Server.ListenPort=%ListenPort% Server.AdvertiseOnline=%AdvertiseOnline% Server.AdvertiseOnLocalNetwork=%AdvertiseOnLocalNetwork% Server.EnableSingleplayer=%EnableSingleplayer% Server.Password=%Password% Server.RecordReplays=%RecordReplays% Server.RequireAuthentication=%RequireAuthentication% Server.ProfileIDBlacklist=%ProfileIDBlacklist% Server.ProfileIDWhitelist=%ProfileIDWhitelist% Server.EnableSyncReports=%EnableSyncReports% Server.EnableGeoIP=%EnableGeoIP% Server.EnableLintChecks=%EnableLintChecks% Server.ShareAnonymizedIPs=%ShareAnonymizedIPs% Server.FloodLimitJoinCooldown=%FloodLimitJoinCooldown% Engine.SupportDir=%SupportDir%
goto loop

View File

@@ -15,6 +15,7 @@ Mod="${Mod:-"ra"}"
Map="${Map:-""}"
ListenPort="${ListenPort:-"1234"}"
AdvertiseOnline="${AdvertiseOnline:-"True"}"
AdvertiseOnLocalNetwork="${AdvertiseOnLocalNetwork:-"True"}"
Password="${Password:-""}"
RecordReplays="${RecordReplays:-"False"}"
@@ -38,6 +39,7 @@ while true; do
Server.Map="$Map" \
Server.ListenPort="$ListenPort" \
Server.AdvertiseOnline="$AdvertiseOnline" \
Server.AdvertiseOnLocalNetwork="$AdvertiseOnLocalNetwork" \
Server.EnableSingleplayer="$EnableSingleplayer" \
Server.Password="$Password" \
Server.RecordReplays="$RecordReplays" \