inproc server
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
@@ -277,6 +277,10 @@
|
||||
<Project>{BDAEAB25-991E-46A7-AF1E-4F0E03358DAA}</Project>
|
||||
<Name>OpenRA.FileFormats</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\OpenRA.Server\OpenRA.Server.csproj">
|
||||
<Project>{76F621A1-3D8E-4A99-9F7E-B071EB657817}</Project>
|
||||
<Name>OpenRA.Server</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Framework.2.0">
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user