basic dedicated server support

This commit is contained in:
Igor Popov
2012-06-07 18:08:22 +04:00
committed by Chris Forbes
parent 03229eca0c
commit bf73cdbd01
4 changed files with 28 additions and 3 deletions

View File

@@ -302,9 +302,28 @@ namespace OpenRA
JoinLocal(); JoinLocal();
viewport = new Viewport(new int2(Renderer.Resolution), Rectangle.Empty, Renderer); viewport = new Viewport(new int2(Renderer.Resolution), Rectangle.Empty, Renderer);
if (Game.Settings.Server.Dedicated)
{
Game.CreateServer(new ServerSettings(Game.Settings.Server));
while(true)
{
System.Threading.Thread.Sleep(100);
//Accessing public field and List::Count is thread safe
if((server.GameStarted)&&(server.conns.Count<=1))
{
Console.WriteLine("No one is playing, shutting down...");
server.Shutdown();
System.Environment.Exit(0);
}
}
}
else
{
modData.LoadScreen.StartGame(); modData.LoadScreen.StartGame();
Settings.Save(); Settings.Save();
} }
}
public static void LoadShellMap() public static void LoadShellMap()
{ {

View File

@@ -34,6 +34,7 @@ namespace OpenRA.GameRules
public string Map = null; public string Map = null;
public string[] Ban = null; public string[] Ban = null;
public int TimeOut = 0; public int TimeOut = 0;
public bool Dedicated = false;
public ServerSettings() { } public ServerSettings() { }
@@ -49,6 +50,7 @@ namespace OpenRA.GameRules
Map = other.Map; Map = other.Map;
Ban = other.Ban; Ban = other.Ban;
TimeOut = other.TimeOut; TimeOut = other.TimeOut;
Dedicated = other.Dedicated;
} }
} }

View File

@@ -135,7 +135,10 @@ namespace OpenRA.Graphics
FixOSX(); FixOSX();
var resolution = GetResolution( windowMode ); var resolution = GetResolution( windowMode );
var rendererPath = Path.GetFullPath( "OpenRA.Renderer.{0}.dll".F(Game.Settings.Graphics.Renderer) );
string renderer = Game.Settings.Server.Dedicated?"Null":Game.Settings.Graphics.Renderer;
var rendererPath = Path.GetFullPath( "OpenRA.Renderer.{0}.dll".F(renderer) );
device = CreateDevice( Assembly.LoadFile( rendererPath ), resolution.Width, resolution.Height, windowMode ); device = CreateDevice( Assembly.LoadFile( rendererPath ), resolution.Width, resolution.Height, windowMode );
} }

View File

@@ -500,6 +500,7 @@ namespace OpenRA.Server
{ {
GameStarted = true; GameStarted = true;
listener.Stop(); listener.Stop();
Console.WriteLine("Game started"); Console.WriteLine("Game started");
foreach( var c in conns ) foreach( var c in conns )