More refactoring

This commit is contained in:
Paul Chote
2010-11-08 17:15:50 +13:00
parent e83838e9ff
commit d33806e932
4 changed files with 24 additions and 12 deletions

View File

@@ -259,7 +259,7 @@ namespace OpenRA
public static void Disconnect()
{
if (IsHost)
Server.Server.StopListening();
Server.Server.Shutdown();
orderManager.Dispose();
var shellmap = modData.Manifest.ShellmapUid;

View File

@@ -37,17 +37,16 @@ namespace OpenRA.Server
public static string Name;
static int randomSeed;
const int DownloadChunkInterval = 20000;
const int DownloadChunkSize = 16384;
public static int MaxSpectators = 4; // How many spectators to allow // @todo Expose this as an option
public static ModData ModData;
public static Map Map;
public static void StopListening()
public static void Shutdown()
{
conns.Clear();
GameStarted = false;
foreach (var t in ServerTraits.WithInterface<INotifyServerShutdown>())
t.ServerShutdown();
try { listener.Stop(); }
catch { }
}
@@ -72,14 +71,14 @@ namespace OpenRA.Server
lobbyInfo.GlobalSettings.AllowCheats = settings.Server.AllowCheats;
lobbyInfo.GlobalSettings.ServerName = settings.Server.Name;
foreach (var t in ServerTraits.WithInterface<IStartServer>())
foreach (var t in ServerTraits.WithInterface<INotifyServerStart>())
t.ServerStarted();
Log.Write("server", "Initial mods: ");
foreach( var m in lobbyInfo.GlobalSettings.Mods )
Log.Write("server","- {0}", m);
//Log.Write("server", "Initial map: {0}",lobbyInfo.GlobalSettings.Map);
Log.Write("server", "Initial map: {0}",lobbyInfo.GlobalSettings.Map);
try
{

View File

@@ -16,8 +16,10 @@ using OpenRA.FileFormats;
namespace OpenRA.Server.Traits
{
public class LobbyCommands : IInterpretCommand, IStartServer, IClientJoined
public class LobbyCommands : IInterpretCommand, INotifyServerStart, IClientJoined
{
public static int MaxSpectators = 4; // How many spectators to allow // @todo Expose this as an option
public bool InterpretCommand(Connection conn, Session.Client client, string cmd)
{
var dict = new Dictionary<string, Func<string, bool>>
@@ -242,7 +244,7 @@ namespace OpenRA.Server.Traits
.ToList();
// Generate slots for spectators
for (int i = 0; i < Server.MaxSpectators; i++)
for (int i = 0; i < MaxSpectators; i++)
Server.lobbyInfo.Slots.Add(new Session.Slot
{
Spectator = true,

View File

@@ -15,7 +15,8 @@ namespace OpenRA.Server.Traits
// Returns true if order is handled
public interface IInterpretCommand { bool InterpretCommand(Connection conn, Session.Client client, string cmd); }
public interface INotifySyncLobbyInfo { void LobbyInfoSynced(); }
public interface IStartServer { void ServerStarted(); }
public interface INotifyServerStart { void ServerStarted(); }
public interface INotifyServerShutdown { void ServerShutdown(); }
public interface IStartGame { void GameStarted(); }
public interface IClientJoined { void ClientJoined(Connection conn); }
public interface ITick
@@ -25,7 +26,7 @@ namespace OpenRA.Server.Traits
}
public class DebugServerTrait : IInterpretCommand, IStartGame, INotifySyncLobbyInfo
public class DebugServerTrait : IInterpretCommand, IStartGame, INotifySyncLobbyInfo, INotifyServerStart, INotifyServerShutdown
{
public bool InterpretCommand(Connection conn, Session.Client client, string cmd)
{
@@ -42,5 +43,15 @@ namespace OpenRA.Server.Traits
{
Console.WriteLine("LobbyInfoSynced()");
}
public void ServerStarted()
{
Console.WriteLine("ServerStarted()");
}
public void ServerShutdown()
{
Console.WriteLine("ServerShutdown()");
}
}
}