Pull LoadMap out of the server
This commit is contained in:
@@ -50,7 +50,7 @@ namespace OpenRA.Server
|
|||||||
static bool isInternetServer;
|
static bool isInternetServer;
|
||||||
static string masterServerUrl;
|
static string masterServerUrl;
|
||||||
static bool isInitialPing;
|
static bool isInitialPing;
|
||||||
static ModData ModData;
|
public static ModData ModData;
|
||||||
public static Map Map;
|
public static Map Map;
|
||||||
|
|
||||||
public static void StopListening()
|
public static void StopListening()
|
||||||
@@ -59,8 +59,8 @@ namespace OpenRA.Server
|
|||||||
GameStarted = false;
|
GameStarted = false;
|
||||||
try { listener.Stop(); }
|
try { listener.Stop(); }
|
||||||
catch { }
|
catch { }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ServerMain(ModData modData, Settings settings, string map)
|
public static void ServerMain(ModData modData, Settings settings, string map)
|
||||||
{
|
{
|
||||||
Log.AddChannel("server", "server.log");
|
Log.AddChannel("server", "server.log");
|
||||||
@@ -83,7 +83,8 @@ namespace OpenRA.Server
|
|||||||
lobbyInfo.GlobalSettings.AllowCheats = settings.Server.AllowCheats;
|
lobbyInfo.GlobalSettings.AllowCheats = settings.Server.AllowCheats;
|
||||||
lobbyInfo.GlobalSettings.ServerName = settings.Server.Name;
|
lobbyInfo.GlobalSettings.ServerName = settings.Server.Name;
|
||||||
|
|
||||||
LoadMap(); // populates the Session's slots, too.
|
foreach (var t in ServerTraits.WithInterface<IStartServer>())
|
||||||
|
t.ServerStarted();
|
||||||
|
|
||||||
Log.Write("server", "Initial mods: ");
|
Log.Write("server", "Initial mods: ");
|
||||||
foreach( var m in lobbyInfo.GlobalSettings.Mods )
|
foreach( var m in lobbyInfo.GlobalSettings.Mods )
|
||||||
@@ -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:
|
/* lobby rework todo:
|
||||||
* - "teams together" option for team games -- will eliminate most need
|
* - "teams together" option for team games -- will eliminate most need
|
||||||
* for manual spawnpoint choosing.
|
* for manual spawnpoint choosing.
|
||||||
|
|||||||
@@ -12,10 +12,11 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.Network;
|
using OpenRA.Network;
|
||||||
|
using OpenRA.FileFormats;
|
||||||
|
|
||||||
namespace OpenRA.Server.Traits
|
namespace OpenRA.Server.Traits
|
||||||
{
|
{
|
||||||
public class LobbyCommands : IInterpretCommand
|
public class LobbyCommands : IInterpretCommand, IStartServer
|
||||||
{
|
{
|
||||||
public bool InterpretCommand(Connection conn, string cmd)
|
public bool InterpretCommand(Connection conn, string cmd)
|
||||||
{
|
{
|
||||||
@@ -194,7 +195,7 @@ namespace OpenRA.Server.Traits
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Server.lobbyInfo.GlobalSettings.Map = s;
|
Server.lobbyInfo.GlobalSettings.Map = s;
|
||||||
Server.LoadMap();
|
LoadMap();
|
||||||
|
|
||||||
foreach(var client in Server.lobbyInfo.Clients)
|
foreach(var client in Server.lobbyInfo.Clients)
|
||||||
{
|
{
|
||||||
@@ -233,5 +234,37 @@ namespace OpenRA.Server.Traits
|
|||||||
|
|
||||||
return a(cmdValue);
|
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
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ namespace OpenRA.Server.Traits
|
|||||||
{
|
{
|
||||||
// Returns true if order is handled
|
// Returns true if order is handled
|
||||||
public interface IInterpretCommand { bool InterpretCommand(Connection conn, string cmd); }
|
public interface IInterpretCommand { bool InterpretCommand(Connection conn, string cmd); }
|
||||||
|
public interface IStartServer { void ServerStarted(); }
|
||||||
|
|
||||||
public class DebugServerTrait : IInterpretCommand
|
public class DebugServerTrait : IInterpretCommand
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user