inproc server
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
<ProductVersion>9.0.30729</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{76F621A1-3D8E-4A99-9F7E-B071EB657817}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>OpenRA.Server</RootNamespace>
|
||||
<AssemblyName>OpenRA.Server</AssemblyName>
|
||||
@@ -68,4 +68,8 @@
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
<PropertyGroup>
|
||||
<PostBuildEvent>
|
||||
</PostBuildEvent>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
@@ -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<int, List<Connection>>();
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user