Move dedicated server code to OpenRA.Server.exe

This commit is contained in:
Paul Chote
2015-07-04 12:12:44 +01:00
parent b5c2703eba
commit 706d3ae52a
13 changed files with 212 additions and 70 deletions

View File

@@ -279,7 +279,7 @@ namespace OpenRA
}
}
Sound = new Sound(Settings.Server.Dedicated ? "Null" : Settings.Sound.Engine);
Sound = new Sound(Settings.Sound.Engine);
GlobalChat = new GlobalChat();
@@ -341,17 +341,11 @@ namespace OpenRA
Sound.StopVideo();
ModData = new ModData(mod, !Settings.Server.Dedicated);
ModData = new ModData(mod, true);
using (new PerfTimer("LoadMaps"))
ModData.MapCache.LoadMaps();
if (Settings.Server.Dedicated)
{
RunDedicatedServer();
Environment.Exit(0);
}
var installData = ModData.Manifest.Get<ContentInstaller>();
var isModContentInstalled = installData.TestFiles.All(f => File.Exists(Platform.ResolvePath(f)));
@@ -398,37 +392,6 @@ namespace OpenRA
ModData.LoadScreen.StartGame(args);
}
public static void RunDedicatedServer()
{
while (true)
{
Settings.Server.Map = ModData.MapCache.ChooseInitialMap(Settings.Server.Map, CosmeticRandom);
Settings.Save();
CreateServer(Settings.Server.Clone());
while (true)
{
Thread.Sleep(100);
if (server.State == Server.ServerState.GameStarted && server.Conns.Count < 1)
{
Console.WriteLine("No one is playing, shutting down...");
server.Shutdown();
break;
}
}
if (Settings.Server.DedicatedLoop)
{
Console.WriteLine("Starting a new server instance...");
ModData.MapCache.LoadMaps();
continue;
}
break;
}
}
public static void LoadEditor(string mapUid)
{
StartGame(mapUid, WorldType.Editor);
@@ -811,7 +774,7 @@ namespace OpenRA
public static void CreateServer(ServerSettings settings)
{
server = new Server.Server(new IPEndPoint(IPAddress.Any, settings.ListenPort), settings, ModData);
server = new Server.Server(new IPEndPoint(IPAddress.Any, settings.ListenPort), settings, ModData, false);
}
public static int CreateLocalServer(string map)
@@ -824,7 +787,7 @@ namespace OpenRA
AllowPortForward = false
};
server = new Server.Server(new IPEndPoint(IPAddress.Loopback, 0), settings, ModData);
server = new Server.Server(new IPEndPoint(IPAddress.Loopback, 0), settings, ModData, false);
return server.Port;
}

View File

@@ -50,16 +50,12 @@ namespace OpenRA
{
var resolution = GetResolution(graphicSettings);
var rendererName = serverSettings.Dedicated ? "Null" : graphicSettings.Renderer;
var rendererName = graphicSettings.Renderer;
var rendererPath = Platform.ResolvePath(Path.Combine(".", "OpenRA.Platforms." + rendererName + ".dll"));
Device = CreateDevice(Assembly.LoadFile(rendererPath), resolution.Width, resolution.Height, graphicSettings.Mode);
if (!serverSettings.Dedicated)
{
TempBufferSize = graphicSettings.BatchSize;
SheetSize = graphicSettings.SheetSize;
}
TempBufferSize = graphicSettings.BatchSize;
SheetSize = graphicSettings.SheetSize;
WorldSpriteRenderer = new SpriteRenderer(this, Device.CreateShader("shp"));
WorldRgbaSpriteRenderer = new SpriteRenderer(this, Device.CreateShader("rgba"));

View File

@@ -38,6 +38,7 @@ namespace OpenRA.Server
public readonly IPAddress Ip;
public readonly int Port;
public readonly MersenneTwister Random = new MersenneTwister();
public readonly bool Dedicated;
// Valid player connections
public List<Connection> Conns = new List<Connection>();
@@ -117,7 +118,7 @@ namespace OpenRA.Server
t.GameEnded(this);
}
public Server(IPEndPoint endpoint, ServerSettings settings, ModData modData)
public Server(IPEndPoint endpoint, ServerSettings settings, ModData modData, bool dedicated)
{
Log.AddChannel("server", "server.log");
@@ -126,7 +127,7 @@ namespace OpenRA.Server
var localEndpoint = (IPEndPoint)listener.LocalEndpoint;
Ip = localEndpoint.Address;
Port = localEndpoint.Port;
Dedicated = dedicated;
Settings = settings;
Settings.Name = OpenRA.Settings.SanitizedServerName(Settings.Name);
@@ -148,7 +149,7 @@ namespace OpenRA.Server
RandomSeed = randomSeed,
Map = settings.Map,
ServerName = settings.Name,
Dedicated = settings.Dedicated,
Dedicated = dedicated,
DisableSingleplayer = settings.DisableSinglePlayer,
}
};
@@ -380,7 +381,7 @@ namespace OpenRA.Server
// Send initial ping
SendOrderTo(newConn, "Ping", Game.RunTime.ToString(CultureInfo.InvariantCulture));
if (Settings.Dedicated)
if (Dedicated)
{
var motdFile = Platform.ResolvePath("^", "motd.txt");
if (!File.Exists(motdFile))
@@ -490,7 +491,7 @@ namespace OpenRA.Server
{
DispatchOrdersToClients(null, 0, new ServerOrder("Message", text).Serialize());
if (Settings.Dedicated)
if (Dedicated)
Console.WriteLine("[{0}] {1}".F(DateTime.Now.ToString(Settings.TimestampFormat), text));
}
@@ -587,7 +588,7 @@ namespace OpenRA.Server
// Client was the server admin
// TODO: Reassign admin for game in progress via an order
if (LobbyInfo.GlobalSettings.Dedicated && dropClient.IsAdmin && State == ServerState.WaitingPlayers)
if (Dedicated && dropClient.IsAdmin && State == ServerState.WaitingPlayers)
{
// Remove any bots controlled by the admin
LobbyInfo.Clients.RemoveAll(c => c.Bot != null && c.BotControllerClientIndex == toDrop.PlayerIndex);
@@ -607,10 +608,10 @@ namespace OpenRA.Server
if (!Conns.Any())
TempBans.Clear();
if (Conns.Any() || LobbyInfo.GlobalSettings.Dedicated)
if (Conns.Any() || Dedicated)
SyncLobbyClients();
if (!LobbyInfo.GlobalSettings.Dedicated && dropClient.IsAdmin)
if (!Dedicated && dropClient.IsAdmin)
Shutdown();
}

View File

@@ -65,12 +65,6 @@ namespace OpenRA
[Desc("Value in milliseconds when to terminate the game. Needs to be at least 10000 (10 s) to enable the timer.")]
public int TimeOut = 0;
[Desc("Run in headless mode with an empty renderer and without sound output.")]
public bool Dedicated = false;
[Desc("Automatically restart when a game ends. Disable this when something else already takes care about it.")]
public bool DedicatedLoop = true;
[Desc("Disallow games where only one player plays with bots.")]
public bool DisableSinglePlayer = false;