Merge pull request #11005 from pchote/server
Extract dedicated server interface to OpenRA.Server.exe
This commit is contained in:
@@ -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 = WidgetUtils.ChooseInitialMap(Settings.Server.Map);
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ using System.Threading;
|
||||
using OpenRA.FileSystem;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Primitives;
|
||||
using OpenRA.Support;
|
||||
|
||||
namespace OpenRA
|
||||
{
|
||||
@@ -81,7 +82,7 @@ namespace OpenRA
|
||||
if (!modData.Manifest.Contains<MapGrid>())
|
||||
return;
|
||||
|
||||
var mapGrid = Game.ModData.Manifest.Get<MapGrid>();
|
||||
var mapGrid = modData.Manifest.Get<MapGrid>();
|
||||
foreach (var kv in MapLocations)
|
||||
{
|
||||
foreach (var map in kv.Key.Contents)
|
||||
@@ -237,6 +238,18 @@ namespace OpenRA
|
||||
});
|
||||
}
|
||||
|
||||
public string ChooseInitialMap(string initialUid, MersenneTwister random)
|
||||
{
|
||||
if (string.IsNullOrEmpty(initialUid) || previews[initialUid].Status != MapStatus.Available)
|
||||
{
|
||||
var selected = previews.Values.Where(x => x.SuitableForInitialMap).RandomOrDefault(random) ??
|
||||
previews.Values.First(m => m.Status == MapStatus.Available && m.Visibility.HasFlag(MapVisibility.Lobby));
|
||||
return selected.Uid;
|
||||
}
|
||||
|
||||
return initialUid;
|
||||
}
|
||||
|
||||
public MapPreview this[string key]
|
||||
{
|
||||
get { return previews[key]; }
|
||||
|
||||
@@ -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"));
|
||||
|
||||
@@ -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))
|
||||
@@ -418,7 +419,7 @@ namespace OpenRA.Server
|
||||
int latency = 1;
|
||||
if (!LobbyInfo.IsSinglePlayer)
|
||||
{
|
||||
var gameSpeeds = Game.ModData.Manifest.Get<GameSpeeds>();
|
||||
var gameSpeeds = ModData.Manifest.Get<GameSpeeds>();
|
||||
GameSpeed speed;
|
||||
if (gameSpeeds.Speeds.TryGetValue(LobbyInfo.GlobalSettings.GameSpeedType, out speed))
|
||||
latency = speed.OrderLatency;
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -76,12 +76,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;
|
||||
|
||||
|
||||
@@ -94,7 +94,6 @@ namespace OpenRA
|
||||
{
|
||||
var defaultDevices = new[]
|
||||
{
|
||||
new SoundDevice("Default", null, "Default Output"),
|
||||
new SoundDevice("Null", null, "Output Disabled")
|
||||
};
|
||||
|
||||
|
||||
@@ -248,18 +248,6 @@ namespace OpenRA.Widgets
|
||||
|
||||
return trimmed;
|
||||
}
|
||||
|
||||
public static string ChooseInitialMap(string initialUid)
|
||||
{
|
||||
if (string.IsNullOrEmpty(initialUid) || Game.ModData.MapCache[initialUid].Status != MapStatus.Available)
|
||||
{
|
||||
var selected = Game.ModData.MapCache.Where(x => x.SuitableForInitialMap).RandomOrDefault(Game.CosmeticRandom) ??
|
||||
Game.ModData.MapCache.First(m => m.Status == MapStatus.Available && m.Visibility.HasFlag(MapVisibility.Lobby));
|
||||
return selected.Uid;
|
||||
}
|
||||
|
||||
return initialUid;
|
||||
}
|
||||
}
|
||||
|
||||
public class CachedTransform<T, U>
|
||||
|
||||
Reference in New Issue
Block a user