diff --git a/OpenRA.Game/Server/Server.cs b/OpenRA.Game/Server/Server.cs index bab842cd75..46ca384c3a 100644 --- a/OpenRA.Game/Server/Server.cs +++ b/OpenRA.Game/Server/Server.cs @@ -50,7 +50,7 @@ namespace OpenRA.Server static bool isInternetServer; static string masterServerUrl; static bool isInitialPing; - static ModData ModData; + public static ModData ModData; public static Map Map; public static void StopListening() @@ -59,8 +59,8 @@ namespace OpenRA.Server GameStarted = false; try { listener.Stop(); } catch { } - } + public static void ServerMain(ModData modData, Settings settings, string map) { Log.AddChannel("server", "server.log"); @@ -83,8 +83,9 @@ namespace OpenRA.Server lobbyInfo.GlobalSettings.AllowCheats = settings.Server.AllowCheats; lobbyInfo.GlobalSettings.ServerName = settings.Server.Name; - LoadMap(); // populates the Session's slots, too. - + foreach (var t in ServerTraits.WithInterface()) + t.ServerStarted(); + Log.Write("server", "Initial mods: "); foreach( var m in lobbyInfo.GlobalSettings.Mods ) Log.Write("server","- {0}", m); @@ -133,37 +134,6 @@ namespace OpenRA.Server } - static Session.Slot MakeSlotFromPlayerReference(PlayerReference pr) - { - if (!pr.Playable) return null; - return new Session.Slot - { - MapPlayer = pr.Name, - Bot = null, /* todo: allow the map to specify a bot class? */ - Closed = false, - }; - } - - public static void LoadMap() - { - Map = new Map(ModData.AvailableMaps[lobbyInfo.GlobalSettings.Map]); - lobbyInfo.Slots = Map.Players - .Select(p => MakeSlotFromPlayerReference(p.Value)) - .Where(s => s != null) - .Select((s, i) => { s.Index = i; return s; }) - .ToList(); - - // Generate slots for spectators - for (int i = 0; i < MaxSpectators; i++) - lobbyInfo.Slots.Add(new Session.Slot - { - Spectator = true, - Index = lobbyInfo.Slots.Count(), - MapPlayer = null, - Bot = null - }); - } - /* lobby rework todo: * - "teams together" option for team games -- will eliminate most need * for manual spawnpoint choosing. diff --git a/OpenRA.Game/ServerTraits/LobbyCommands.cs b/OpenRA.Game/ServerTraits/LobbyCommands.cs index 786a39561b..40ce452952 100644 --- a/OpenRA.Game/ServerTraits/LobbyCommands.cs +++ b/OpenRA.Game/ServerTraits/LobbyCommands.cs @@ -12,10 +12,11 @@ using System; using System.Collections.Generic; using System.Linq; using OpenRA.Network; +using OpenRA.FileFormats; namespace OpenRA.Server.Traits { - public class LobbyCommands : IInterpretCommand + public class LobbyCommands : IInterpretCommand, IStartServer { public bool InterpretCommand(Connection conn, string cmd) { @@ -194,7 +195,7 @@ namespace OpenRA.Server.Traits return true; } Server.lobbyInfo.GlobalSettings.Map = s; - Server.LoadMap(); + LoadMap(); foreach(var client in Server.lobbyInfo.Clients) { @@ -233,5 +234,37 @@ namespace OpenRA.Server.Traits return a(cmdValue); } + + public void ServerStarted() { LoadMap(); } + static Session.Slot MakeSlotFromPlayerReference(PlayerReference pr) + { + if (!pr.Playable) return null; + return new Session.Slot + { + MapPlayer = pr.Name, + Bot = null, /* todo: allow the map to specify a bot class? */ + Closed = false, + }; + } + + public static void LoadMap() + { + Server.Map = new Map(Server.ModData.AvailableMaps[Server.lobbyInfo.GlobalSettings.Map]); + Server.lobbyInfo.Slots = Server.Map.Players + .Select(p => MakeSlotFromPlayerReference(p.Value)) + .Where(s => s != null) + .Select((s, i) => { s.Index = i; return s; }) + .ToList(); + + // Generate slots for spectators + for (int i = 0; i < Server.MaxSpectators; i++) + Server.lobbyInfo.Slots.Add(new Session.Slot + { + Spectator = true, + Index = Server.lobbyInfo.Slots.Count(), + MapPlayer = null, + Bot = null + }); + } } } diff --git a/OpenRA.Game/ServerTraits/TraitInterfaces.cs b/OpenRA.Game/ServerTraits/TraitInterfaces.cs index 2cec88c8d4..5f73f5008e 100644 --- a/OpenRA.Game/ServerTraits/TraitInterfaces.cs +++ b/OpenRA.Game/ServerTraits/TraitInterfaces.cs @@ -12,6 +12,7 @@ namespace OpenRA.Server.Traits { // Returns true if order is handled public interface IInterpretCommand { bool InterpretCommand(Connection conn, string cmd); } + public interface IStartServer { void ServerStarted(); } public class DebugServerTrait : IInterpretCommand {