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() public static void Disconnect()
{ {
if (IsHost) if (IsHost)
Server.Server.StopListening(); Server.Server.Shutdown();
orderManager.Dispose(); orderManager.Dispose();
var shellmap = modData.Manifest.ShellmapUid; var shellmap = modData.Manifest.ShellmapUid;

View File

@@ -37,17 +37,16 @@ namespace OpenRA.Server
public static string Name; public static string Name;
static int randomSeed; 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 ModData ModData;
public static Map Map; public static Map Map;
public static void StopListening() public static void Shutdown()
{ {
conns.Clear(); conns.Clear();
GameStarted = false; GameStarted = false;
foreach (var t in ServerTraits.WithInterface<INotifyServerShutdown>())
t.ServerShutdown();
try { listener.Stop(); } try { listener.Stop(); }
catch { } catch { }
} }
@@ -72,14 +71,14 @@ namespace OpenRA.Server
lobbyInfo.GlobalSettings.AllowCheats = settings.Server.AllowCheats; lobbyInfo.GlobalSettings.AllowCheats = settings.Server.AllowCheats;
lobbyInfo.GlobalSettings.ServerName = settings.Server.Name; lobbyInfo.GlobalSettings.ServerName = settings.Server.Name;
foreach (var t in ServerTraits.WithInterface<IStartServer>()) foreach (var t in ServerTraits.WithInterface<INotifyServerStart>())
t.ServerStarted(); t.ServerStarted();
Log.Write("server", "Initial mods: "); Log.Write("server", "Initial mods: ");
foreach( var m in lobbyInfo.GlobalSettings.Mods ) foreach( var m in lobbyInfo.GlobalSettings.Mods )
Log.Write("server","- {0}", m); Log.Write("server","- {0}", m);
//Log.Write("server", "Initial map: {0}",lobbyInfo.GlobalSettings.Map); Log.Write("server", "Initial map: {0}",lobbyInfo.GlobalSettings.Map);
try try
{ {

View File

@@ -16,8 +16,10 @@ using OpenRA.FileFormats;
namespace OpenRA.Server.Traits 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) public bool InterpretCommand(Connection conn, Session.Client client, string cmd)
{ {
var dict = new Dictionary<string, Func<string, bool>> var dict = new Dictionary<string, Func<string, bool>>
@@ -242,7 +244,7 @@ namespace OpenRA.Server.Traits
.ToList(); .ToList();
// Generate slots for spectators // 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 Server.lobbyInfo.Slots.Add(new Session.Slot
{ {
Spectator = true, Spectator = true,

View File

@@ -15,7 +15,8 @@ namespace OpenRA.Server.Traits
// Returns true if order is handled // Returns true if order is handled
public interface IInterpretCommand { bool InterpretCommand(Connection conn, Session.Client client, string cmd); } public interface IInterpretCommand { bool InterpretCommand(Connection conn, Session.Client client, string cmd); }
public interface INotifySyncLobbyInfo { void LobbyInfoSynced(); } 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 IStartGame { void GameStarted(); }
public interface IClientJoined { void ClientJoined(Connection conn); } public interface IClientJoined { void ClientJoined(Connection conn); }
public interface ITick 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) public bool InterpretCommand(Connection conn, Session.Client client, string cmd)
{ {
@@ -42,5 +43,15 @@ namespace OpenRA.Server.Traits
{ {
Console.WriteLine("LobbyInfoSynced()"); Console.WriteLine("LobbyInfoSynced()");
} }
public void ServerStarted()
{
Console.WriteLine("ServerStarted()");
}
public void ServerShutdown()
{
Console.WriteLine("ServerShutdown()");
}
} }
} }