Define ServerTraits in mod.yaml

This commit is contained in:
Paul Chote
2010-11-09 23:04:08 +13:00
parent ed4c588701
commit 8e007131c9
8 changed files with 18 additions and 10 deletions

View File

@@ -18,7 +18,7 @@ namespace OpenRA.FileFormats
public class Manifest public class Manifest
{ {
public readonly string[] public readonly string[]
Mods, Folders, Packages, Rules, Mods, Folders, Packages, Rules, ServerTraits,
Sequences, Cursors, Chrome, Assemblies, ChromeLayout, Sequences, Cursors, Chrome, Assemblies, ChromeLayout,
Weapons, Voices, Music, Movies, TileSets; Weapons, Voices, Music, Movies, TileSets;
public readonly string ShellmapUid, LoadScreen; public readonly string ShellmapUid, LoadScreen;
@@ -35,6 +35,7 @@ namespace OpenRA.FileFormats
Folders = YamlList(yaml, "Folders"); Folders = YamlList(yaml, "Folders");
Packages = YamlList(yaml, "Packages"); Packages = YamlList(yaml, "Packages");
Rules = YamlList(yaml, "Rules"); Rules = YamlList(yaml, "Rules");
ServerTraits = YamlList(yaml, "ServerTraits");
Sequences = YamlList(yaml, "Sequences"); Sequences = YamlList(yaml, "Sequences");
Cursors = YamlList(yaml, "Cursors"); Cursors = YamlList(yaml, "Cursors");
Chrome = YamlList(yaml, "Chrome"); Chrome = YamlList(yaml, "Chrome");

View File

@@ -55,16 +55,14 @@ namespace OpenRA.Server
{ {
Log.AddChannel("server", "server.log"); Log.AddChannel("server", "server.log");
ServerTraits.Add( new DebugServerTrait() );
ServerTraits.Add( new PlayerCommands() );
ServerTraits.Add( new LobbyCommands() );
ServerTraits.Add( new MasterServerPinger() );
listener = new TcpListener(IPAddress.Any, settings.Server.ListenPort); listener = new TcpListener(IPAddress.Any, settings.Server.ListenPort);
Name = settings.Server.Name; Name = settings.Server.Name;
randomSeed = (int)DateTime.Now.ToBinary(); randomSeed = (int)DateTime.Now.ToBinary();
ModData = modData; ModData = modData;
foreach (var trait in modData.Manifest.ServerTraits)
ServerTraits.Add( modData.ObjectCreator.CreateObject<ServerTrait>(trait) );
lobbyInfo = new Session( settings.Game.Mods ); lobbyInfo = new Session( settings.Game.Mods );
lobbyInfo.GlobalSettings.RandomSeed = randomSeed; lobbyInfo.GlobalSettings.RandomSeed = randomSeed;
lobbyInfo.GlobalSettings.Map = map; lobbyInfo.GlobalSettings.Map = map;

View File

@@ -16,7 +16,7 @@ using OpenRA.FileFormats;
namespace OpenRA.Server.Traits namespace OpenRA.Server.Traits
{ {
public class LobbyCommands : IInterpretCommand, INotifyServerStart, IClientJoined public class LobbyCommands : ServerTrait, IInterpretCommand, INotifyServerStart, IClientJoined
{ {
public static int MaxSpectators = 4; // How many spectators to allow // @todo Expose this as an option public static int MaxSpectators = 4; // How many spectators to allow // @todo Expose this as an option

View File

@@ -14,7 +14,7 @@ using System.Net;
namespace OpenRA.Server.Traits namespace OpenRA.Server.Traits
{ {
public class MasterServerPinger : ITick, INotifySyncLobbyInfo, IStartGame public class MasterServerPinger : ServerTrait, ITick, INotifySyncLobbyInfo, IStartGame
{ {
const int MasterPingInterval = 60 * 3; // 3 minutes. server has a 5 minute TTL for games, so give ourselves a bit const int MasterPingInterval = 60 * 3; // 3 minutes. server has a 5 minute TTL for games, so give ourselves a bit
// of leeway. // of leeway.

View File

@@ -16,7 +16,7 @@ using OpenRA.Network;
namespace OpenRA.Server.Traits namespace OpenRA.Server.Traits
{ {
public class PlayerCommands : IInterpretCommand public class PlayerCommands : ServerTrait, IInterpretCommand
{ {
public bool InterpretCommand(Connection conn, Session.Client client, string cmd) public bool InterpretCommand(Connection conn, Session.Client client, string cmd)
{ {

View File

@@ -25,8 +25,9 @@ namespace OpenRA.Server.Traits
int TickTimeout { get; } int TickTimeout { get; }
} }
public abstract class ServerTrait {}
public class DebugServerTrait : IInterpretCommand, IStartGame, INotifySyncLobbyInfo, INotifyServerStart, INotifyServerShutdown public class DebugServerTrait : ServerTrait, 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)
{ {

View File

@@ -83,3 +83,7 @@ TileSets:
LoadScreen: CncLoadScreen LoadScreen: CncLoadScreen
ShellmapUid:e7b9badb3b7d49ccc773a7aa086c0ff9a1136b77 ShellmapUid:e7b9badb3b7d49ccc773a7aa086c0ff9a1136b77
ServerTraits:
PlayerCommands
LobbyCommands
MasterServerPinger

View File

@@ -78,3 +78,7 @@ Movies:
LoadScreen: RALoadScreen LoadScreen: RALoadScreen
ShellmapUid:f1e5ed95dccfa5ba9c61f1263adffe17635ec069 ShellmapUid:f1e5ed95dccfa5ba9c61f1263adffe17635ec069
ServerTraits:
PlayerCommands
LobbyCommands
MasterServerPinger