diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs
index 97daa78499..6be9ef9059 100644
--- a/OpenRA.Game/Game.cs
+++ b/OpenRA.Game/Game.cs
@@ -20,7 +20,9 @@
using System;
using System.Collections.Generic;
+using System.Diagnostics;
using System.Drawing;
+using System.IO;
using System.Linq;
using System.Windows.Forms;
using OpenRA.FileFormats;
@@ -30,9 +32,7 @@ using OpenRA.Network;
using OpenRA.Support;
using OpenRA.Traits;
using Timer = OpenRA.Support.Timer;
-using System.Runtime.InteropServices;
-using System.IO;
-using System.Diagnostics;
+using OpenRA.Server;
namespace OpenRA
{
@@ -56,7 +56,7 @@ namespace OpenRA
internal static Session LobbyInfo = new Session();
static bool changePending;
- internal static Process Server;
+
public static void LoadModPackages(Manifest manifest)
{
@@ -151,15 +151,13 @@ namespace OpenRA
internal static void CreateServer()
{
- Server = new Process();
- Server.StartInfo.FileName = "OpenRA.Server.exe";
- Server.StartInfo.Arguments = string.Join(" ",Game.LobbyInfo.GlobalSettings.Mods);
- Server.Start();
+ // todo: LobbyInfo is the wrong place for this.
+ InprocServer.Start(Game.LobbyInfo.GlobalSettings.Mods);
}
internal static void CloseServer()
{
- Server.Kill();
+ InprocServer.Stop();
}
static int lastTime = Environment.TickCount;
@@ -441,9 +439,6 @@ namespace OpenRA
public static void Exit()
{
- if (Server != null)
- CloseServer();
-
quit = true;
}
}
diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj
index 16c5c88344..999bca3237 100644
--- a/OpenRA.Game/OpenRA.Game.csproj
+++ b/OpenRA.Game/OpenRA.Game.csproj
@@ -1,4 +1,4 @@
-
+
Debug
@@ -277,6 +277,10 @@
{BDAEAB25-991E-46A7-AF1E-4F0E03358DAA}
OpenRA.FileFormats
+
+ {76F621A1-3D8E-4A99-9F7E-B071EB657817}
+ OpenRA.Server
+
diff --git a/OpenRA.Server/OpenRA.Server.csproj b/OpenRA.Server/OpenRA.Server.csproj
index d3e07b5e65..f045247896 100644
--- a/OpenRA.Server/OpenRA.Server.csproj
+++ b/OpenRA.Server/OpenRA.Server.csproj
@@ -6,7 +6,7 @@
9.0.30729
2.0
{76F621A1-3D8E-4A99-9F7E-B071EB657817}
- Exe
+ Library
Properties
OpenRA.Server
OpenRA.Server
@@ -68,4 +68,8 @@
-->
+
+
+
+
\ No newline at end of file
diff --git a/OpenRA.Server/Server.cs b/OpenRA.Server/Server.cs
index 2cc907f41c..55cbdfc14c 100644
--- a/OpenRA.Server/Server.cs
+++ b/OpenRA.Server/Server.cs
@@ -27,6 +27,7 @@ using System.Net;
using System.Net.Sockets;
using System.Security.Cryptography;
using OpenRA.FileFormats;
+using System.Threading;
namespace OpenRA.Server
{
@@ -38,16 +39,17 @@ namespace OpenRA.Server
= new Dictionary>();
static Session lobbyInfo;
static bool GameStarted = false;
- static string[] defaultMods = new string[] { "ra" };
+ static string[] initialMods;
const int DownloadChunkInterval = 20000;
const int DownloadChunkSize = 16384;
- public static int Main(string[] args)
+ public static int ServerMain(string[] mods, AutoResetEvent e)
{
- if (args.Length > 0) defaultMods = args;
+ initialMods = mods;
+
lobbyInfo = new Session();
- lobbyInfo.GlobalSettings.Mods = defaultMods;
+ lobbyInfo.GlobalSettings.Mods = mods;
Console.WriteLine("Initial mods: ");
foreach( var m in lobbyInfo.GlobalSettings.Mods )
@@ -63,6 +65,8 @@ namespace OpenRA.Server
Console.WriteLine("Server failed to start.");
return 1;
}
+
+ e.Set(); // we're done starting up
for (; ; )
{
@@ -510,7 +514,7 @@ namespace OpenRA.Server
Console.WriteLine("Server emptied out; doing a bit of housekeeping to prepare for next game..");
inFlightFrames.Clear();
lobbyInfo = new Session();
- lobbyInfo.GlobalSettings.Mods = defaultMods;
+ lobbyInfo.GlobalSettings.Mods = initialMods;
GameStarted = false;
}
@@ -538,4 +542,25 @@ namespace OpenRA.Server
new ServerOrder("SyncInfo", clientData.WriteToString()).Serialize());
}
}
+
+ // temporary threaded inproc server wrapper.
+ public static class InprocServer
+ {
+ static Thread t;
+
+ public static void Start( string[] mods )
+ {
+ var e = new AutoResetEvent(false);
+ t = new Thread(() => Server.ServerMain(mods, e)) { IsBackground = true };
+
+ t.Start();
+ e.WaitOne(); // when the event is signaled, the server is finished initializing
+ }
+
+ public static void Stop()
+ {
+ if (t != null)
+ t.Abort();
+ }
+ }
}
diff --git a/OpenRA.sln b/OpenRA.sln
index a3e27d272f..54edd52e8d 100644
--- a/OpenRA.sln
+++ b/OpenRA.sln
@@ -4,6 +4,9 @@ Microsoft Visual Studio Solution File, Format Version 10.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenRA.FileFormats", "OpenRA.FileFormats\OpenRA.FileFormats.csproj", "{BDAEAB25-991E-46A7-AF1E-4F0E03358DAA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenRA.Game", "OpenRA.Game\OpenRA.Game.csproj", "{0DFB103F-2962-400F-8C6D-E2C28CCBA633}"
+ ProjectSection(ProjectDependencies) = postProject
+ {76F621A1-3D8E-4A99-9F7E-B071EB657817} = {76F621A1-3D8E-4A99-9F7E-B071EB657817}
+ EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SequenceEditor", "SequenceEditor\SequenceEditor.csproj", "{230F65CE-A6DE-4235-8B38-13A3D606C7F7}"
EndProject