Work around a race condition with local servers.
This commit is contained in:
@@ -350,16 +350,17 @@ namespace OpenRA
|
|||||||
{
|
{
|
||||||
if (orderManager.world != null)
|
if (orderManager.world != null)
|
||||||
orderManager.world.traitDict.PrintReport();
|
orderManager.world.traitDict.PrintReport();
|
||||||
|
CloseServer();
|
||||||
if (IsHost && server != null)
|
|
||||||
{
|
|
||||||
Console.WriteLine("Closing server");
|
|
||||||
server.Shutdown();
|
|
||||||
}
|
|
||||||
JoinLocal();
|
JoinLocal();
|
||||||
orderManager.Dispose();
|
orderManager.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void CloseServer()
|
||||||
|
{
|
||||||
|
if (server != null)
|
||||||
|
server.Shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
public static T CreateObject<T>( string name )
|
public static T CreateObject<T>( string name )
|
||||||
{
|
{
|
||||||
return modData.ObjectCreator.CreateObject<T>( name );
|
return modData.ObjectCreator.CreateObject<T>( name );
|
||||||
|
|||||||
@@ -74,17 +74,21 @@ namespace OpenRA.Server
|
|||||||
|
|
||||||
Log.Write("server", "Initial map: {0}",lobbyInfo.GlobalSettings.Map);
|
Log.Write("server", "Initial map: {0}",lobbyInfo.GlobalSettings.Map);
|
||||||
|
|
||||||
|
new Thread( _ =>
|
||||||
|
{
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
listener.Start();
|
listener.Start();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException( "Unable to start server: port is already in use" );
|
Thread.Sleep(100);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
new Thread( _ =>
|
|
||||||
{
|
|
||||||
var timeout = ServerTraits.WithInterface<ITick>().Min(t => t.TickTimeout);
|
var timeout = ServerTraits.WithInterface<ITick>().Min(t => t.TickTimeout);
|
||||||
for( ; ; )
|
for( ; ; )
|
||||||
{
|
{
|
||||||
@@ -94,6 +98,8 @@ namespace OpenRA.Server
|
|||||||
foreach( var c in preConns ) checkRead.Add( c.socket );
|
foreach( var c in preConns ) checkRead.Add( c.socket );
|
||||||
|
|
||||||
Socket.Select( checkRead, null, null, timeout );
|
Socket.Select( checkRead, null, null, timeout );
|
||||||
|
if (shutdown)
|
||||||
|
break;
|
||||||
|
|
||||||
foreach( Socket s in checkRead )
|
foreach( Socket s in checkRead )
|
||||||
if( s == listener.Server ) AcceptConnection();
|
if( s == listener.Server ) AcceptConnection();
|
||||||
@@ -110,7 +116,6 @@ namespace OpenRA.Server
|
|||||||
if (shutdown)
|
if (shutdown)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Console.WriteLine("Server loop finished");
|
|
||||||
|
|
||||||
GameStarted = false;
|
GameStarted = false;
|
||||||
foreach (var t in ServerTraits.WithInterface<INotifyServerShutdown>())
|
foreach (var t in ServerTraits.WithInterface<INotifyServerShutdown>())
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ namespace OpenRA.Mods.Cnc.Widgets
|
|||||||
CncConnectingLogic.Connect(IPAddress.Loopback.ToString(),
|
CncConnectingLogic.Connect(IPAddress.Loopback.ToString(),
|
||||||
Game.Settings.Server.LoopbackPort,
|
Game.Settings.Server.LoopbackPort,
|
||||||
new Action(() => OpenLobbyPanel(MenuType.Main)),
|
new Action(() => OpenLobbyPanel(MenuType.Main)),
|
||||||
new Action(() => ReturnToMenu(MenuType.Main)));
|
new Action(() => { Game.CloseServer(); ReturnToMenu(MenuType.Main); }));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user