Skip to content

Commit

Permalink
Send a ping when the server is shut down
Browse files Browse the repository at this point in the history
and stop the LAN beacon.
  • Loading branch information
Mailaender authored and pchote committed Sep 18, 2021
1 parent 58e482c commit 0604a58
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions OpenRA.Mods.Common/ServerTraits/MasterServerPinger.cs
Expand Up @@ -22,7 +22,7 @@

namespace OpenRA.Mods.Common.Server
{
public class MasterServerPinger : ServerTrait, ITick, INotifyServerStart, INotifySyncLobbyInfo, IStartGame, IEndGame
public class MasterServerPinger : ServerTrait, ITick, INotifyServerStart, INotifyServerShutdown, INotifySyncLobbyInfo, IStartGame, IEndGame
{
// 3 minutes (in milliseconds). Server has a 5 minute TTL for games, so give ourselves a bit of leeway.
const int MasterPingInterval = 60 * 3 * 1000;
Expand Down Expand Up @@ -82,12 +82,24 @@ public void Tick(S server)
server.SendMessage(masterServerMessages.Dequeue());
}

public void ServerStarted(S server)
void INotifyServerStart.ServerStarted(S server)
{
if (server.Type != ServerType.Local && LanGameBeacon != null)
LanGameBeacon.Start();
}

void INotifyServerShutdown.ServerShutdown(S server)
{
if (server.Settings.AdvertiseOnline)
{
// Announce that the game has ended to remove it from the list.
var gameServer = new GameServer(server);
UpdateMasterServer(server, gameServer.ToPOSTData(false));
}

LanGameBeacon?.Stop();
}

public void LobbyInfoSynced(S server)
{
lastChanged = Game.RunTime;
Expand Down

0 comments on commit 0604a58

Please sign in to comment.