inproc server
This commit is contained in:
@@ -20,7 +20,9 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using OpenRA.FileFormats;
|
using OpenRA.FileFormats;
|
||||||
@@ -30,9 +32,7 @@ using OpenRA.Network;
|
|||||||
using OpenRA.Support;
|
using OpenRA.Support;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
using Timer = OpenRA.Support.Timer;
|
using Timer = OpenRA.Support.Timer;
|
||||||
using System.Runtime.InteropServices;
|
using OpenRA.Server;
|
||||||
using System.IO;
|
|
||||||
using System.Diagnostics;
|
|
||||||
|
|
||||||
namespace OpenRA
|
namespace OpenRA
|
||||||
{
|
{
|
||||||
@@ -56,7 +56,7 @@ namespace OpenRA
|
|||||||
internal static Session LobbyInfo = new Session();
|
internal static Session LobbyInfo = new Session();
|
||||||
static bool changePending;
|
static bool changePending;
|
||||||
|
|
||||||
internal static Process Server;
|
|
||||||
|
|
||||||
public static void LoadModPackages(Manifest manifest)
|
public static void LoadModPackages(Manifest manifest)
|
||||||
{
|
{
|
||||||
@@ -151,15 +151,13 @@ namespace OpenRA
|
|||||||
|
|
||||||
internal static void CreateServer()
|
internal static void CreateServer()
|
||||||
{
|
{
|
||||||
Server = new Process();
|
// todo: LobbyInfo is the wrong place for this.
|
||||||
Server.StartInfo.FileName = "OpenRA.Server.exe";
|
InprocServer.Start(Game.LobbyInfo.GlobalSettings.Mods);
|
||||||
Server.StartInfo.Arguments = string.Join(" ",Game.LobbyInfo.GlobalSettings.Mods);
|
|
||||||
Server.Start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void CloseServer()
|
internal static void CloseServer()
|
||||||
{
|
{
|
||||||
Server.Kill();
|
InprocServer.Stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
static int lastTime = Environment.TickCount;
|
static int lastTime = Environment.TickCount;
|
||||||
@@ -441,9 +439,6 @@ namespace OpenRA
|
|||||||
|
|
||||||
public static void Exit()
|
public static void Exit()
|
||||||
{
|
{
|
||||||
if (Server != null)
|
|
||||||
CloseServer();
|
|
||||||
|
|
||||||
quit = true;
|
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">
|
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
@@ -277,6 +277,10 @@
|
|||||||
<Project>{BDAEAB25-991E-46A7-AF1E-4F0E03358DAA}</Project>
|
<Project>{BDAEAB25-991E-46A7-AF1E-4F0E03358DAA}</Project>
|
||||||
<Name>OpenRA.FileFormats</Name>
|
<Name>OpenRA.FileFormats</Name>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
|
<ProjectReference Include="..\OpenRA.Server\OpenRA.Server.csproj">
|
||||||
|
<Project>{76F621A1-3D8E-4A99-9F7E-B071EB657817}</Project>
|
||||||
|
<Name>OpenRA.Server</Name>
|
||||||
|
</ProjectReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<BootstrapperPackage Include="Microsoft.Net.Framework.2.0">
|
<BootstrapperPackage Include="Microsoft.Net.Framework.2.0">
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
<ProductVersion>9.0.30729</ProductVersion>
|
<ProductVersion>9.0.30729</ProductVersion>
|
||||||
<SchemaVersion>2.0</SchemaVersion>
|
<SchemaVersion>2.0</SchemaVersion>
|
||||||
<ProjectGuid>{76F621A1-3D8E-4A99-9F7E-B071EB657817}</ProjectGuid>
|
<ProjectGuid>{76F621A1-3D8E-4A99-9F7E-B071EB657817}</ProjectGuid>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Library</OutputType>
|
||||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||||
<RootNamespace>OpenRA.Server</RootNamespace>
|
<RootNamespace>OpenRA.Server</RootNamespace>
|
||||||
<AssemblyName>OpenRA.Server</AssemblyName>
|
<AssemblyName>OpenRA.Server</AssemblyName>
|
||||||
@@ -68,4 +68,8 @@
|
|||||||
<Target Name="AfterBuild">
|
<Target Name="AfterBuild">
|
||||||
</Target>
|
</Target>
|
||||||
-->
|
-->
|
||||||
|
<PropertyGroup>
|
||||||
|
<PostBuildEvent>
|
||||||
|
</PostBuildEvent>
|
||||||
|
</PropertyGroup>
|
||||||
</Project>
|
</Project>
|
||||||
@@ -27,6 +27,7 @@ using System.Net;
|
|||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
using OpenRA.FileFormats;
|
using OpenRA.FileFormats;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
namespace OpenRA.Server
|
namespace OpenRA.Server
|
||||||
{
|
{
|
||||||
@@ -38,16 +39,17 @@ namespace OpenRA.Server
|
|||||||
= new Dictionary<int, List<Connection>>();
|
= new Dictionary<int, List<Connection>>();
|
||||||
static Session lobbyInfo;
|
static Session lobbyInfo;
|
||||||
static bool GameStarted = false;
|
static bool GameStarted = false;
|
||||||
static string[] defaultMods = new string[] { "ra" };
|
static string[] initialMods;
|
||||||
|
|
||||||
const int DownloadChunkInterval = 20000;
|
const int DownloadChunkInterval = 20000;
|
||||||
const int DownloadChunkSize = 16384;
|
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 = new Session();
|
||||||
lobbyInfo.GlobalSettings.Mods = defaultMods;
|
lobbyInfo.GlobalSettings.Mods = mods;
|
||||||
|
|
||||||
Console.WriteLine("Initial mods: ");
|
Console.WriteLine("Initial mods: ");
|
||||||
foreach( var m in lobbyInfo.GlobalSettings.Mods )
|
foreach( var m in lobbyInfo.GlobalSettings.Mods )
|
||||||
@@ -64,6 +66,8 @@ namespace OpenRA.Server
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
e.Set(); // we're done starting up
|
||||||
|
|
||||||
for (; ; )
|
for (; ; )
|
||||||
{
|
{
|
||||||
var checkRead = new ArrayList();
|
var checkRead = new ArrayList();
|
||||||
@@ -510,7 +514,7 @@ namespace OpenRA.Server
|
|||||||
Console.WriteLine("Server emptied out; doing a bit of housekeeping to prepare for next game..");
|
Console.WriteLine("Server emptied out; doing a bit of housekeeping to prepare for next game..");
|
||||||
inFlightFrames.Clear();
|
inFlightFrames.Clear();
|
||||||
lobbyInfo = new Session();
|
lobbyInfo = new Session();
|
||||||
lobbyInfo.GlobalSettings.Mods = defaultMods;
|
lobbyInfo.GlobalSettings.Mods = initialMods;
|
||||||
GameStarted = false;
|
GameStarted = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -538,4 +542,25 @@ namespace OpenRA.Server
|
|||||||
new ServerOrder("SyncInfo", clientData.WriteToString()).Serialize());
|
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}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenRA.FileFormats", "OpenRA.FileFormats\OpenRA.FileFormats.csproj", "{BDAEAB25-991E-46A7-AF1E-4F0E03358DAA}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenRA.Game", "OpenRA.Game\OpenRA.Game.csproj", "{0DFB103F-2962-400F-8C6D-E2C28CCBA633}"
|
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
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SequenceEditor", "SequenceEditor\SequenceEditor.csproj", "{230F65CE-A6DE-4235-8B38-13A3D606C7F7}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SequenceEditor", "SequenceEditor\SequenceEditor.csproj", "{230F65CE-A6DE-4235-8B38-13A3D606C7F7}"
|
||||||
EndProject
|
EndProject
|
||||||
|
|||||||
Reference in New Issue
Block a user