Move ServerTraits into Mods.
This commit is contained in:
@@ -192,10 +192,7 @@
|
||||
<Compile Include="Traits\ActorStance.cs" />
|
||||
<Compile Include="Traits\Armor.cs" />
|
||||
<Compile Include="Graphics\CursorProvider.cs" />
|
||||
<Compile Include="ServerTraits\TraitInterfaces.cs" />
|
||||
<Compile Include="ServerTraits\LobbyCommands.cs" />
|
||||
<Compile Include="ServerTraits\PlayerCommands.cs" />
|
||||
<Compile Include="ServerTraits\MasterServerPinger.cs" />
|
||||
<Compile Include="Server\TraitInterfaces.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||
|
||||
@@ -20,7 +20,6 @@ using System.Threading;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.GameRules;
|
||||
using OpenRA.Network;
|
||||
using OpenRA.Server.Traits;
|
||||
|
||||
namespace OpenRA.Server
|
||||
{
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
using System;
|
||||
using OpenRA.Network;
|
||||
|
||||
namespace OpenRA.Server.Traits
|
||||
namespace OpenRA.Server
|
||||
{
|
||||
// Returns true if order is handled
|
||||
public interface IInterpretCommand { bool InterpretCommand(Connection conn, Session.Client client, string cmd); }
|
||||
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
@@ -292,6 +292,9 @@
|
||||
<Compile Include="Scripting\Media.cs" />
|
||||
<Compile Include="OpenWidgetAtGameStart.cs" />
|
||||
<Compile Include="World\WorldGameOver.cs" />
|
||||
<Compile Include="ServerTraits\MasterServerPinger.cs" />
|
||||
<Compile Include="ServerTraits\PlayerCommands.cs" />
|
||||
<Compile Include="ServerTraits\LobbyCommands.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||
@@ -318,4 +321,7 @@
|
||||
copy "$(TargetPath)" "$(SolutionDir)mods/ra/"
|
||||
cd "$(SolutionDir)"</PostBuildEvent>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="ServerTraits\" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -13,8 +13,10 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Network;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Server;
|
||||
using server = OpenRA.Server.Server;
|
||||
|
||||
namespace OpenRA.Server.Traits
|
||||
namespace OpenRA.Mods.RA.Server
|
||||
{
|
||||
public class LobbyCommands : ServerTrait, IInterpretCommand, INotifyServerStart, IClientJoined
|
||||
{
|
||||
@@ -22,14 +24,14 @@ namespace OpenRA.Server.Traits
|
||||
|
||||
public bool InterpretCommand(Connection conn, Session.Client client, string cmd)
|
||||
{
|
||||
if (Server.GameStarted)
|
||||
if (server.GameStarted)
|
||||
{
|
||||
Server.SendChatTo(conn, "Cannot change state when game started. ({0})".F(cmd));
|
||||
server.SendChatTo(conn, "Cannot change state when game started. ({0})".F(cmd));
|
||||
return false;
|
||||
}
|
||||
else if (client.State == Session.ClientState.Ready && !(cmd == "ready" || cmd == "startgame"))
|
||||
{
|
||||
Server.SendChatTo(conn, "Cannot change state when marked as ready.");
|
||||
server.SendChatTo(conn, "Cannot change state when marked as ready.");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -47,9 +49,9 @@ namespace OpenRA.Server.Traits
|
||||
Log.Write("server", "Player @{0} is {1}",
|
||||
conn.socket.RemoteEndPoint, client.State);
|
||||
|
||||
Server.SyncLobbyInfo();
|
||||
server.SyncLobbyInfo();
|
||||
|
||||
if (Server.conns.Count > 0 && Server.conns.All(c => Server.GetClient(c).State == Session.ClientState.Ready))
|
||||
if (server.conns.Count > 0 && server.conns.All(c => server.GetClient(c).State == Session.ClientState.Ready))
|
||||
InterpretCommand(conn, client, "startgame");
|
||||
|
||||
return true;
|
||||
@@ -57,7 +59,7 @@ namespace OpenRA.Server.Traits
|
||||
{ "startgame",
|
||||
s =>
|
||||
{
|
||||
Server.StartGame();
|
||||
server.StartGame();
|
||||
return true;
|
||||
}},
|
||||
{ "lag",
|
||||
@@ -68,21 +70,21 @@ namespace OpenRA.Server.Traits
|
||||
|
||||
Log.Write("server", "Order lag is now {0} frames.", lag);
|
||||
|
||||
Server.lobbyInfo.GlobalSettings.OrderLatency = lag;
|
||||
Server.SyncLobbyInfo();
|
||||
server.lobbyInfo.GlobalSettings.OrderLatency = lag;
|
||||
server.SyncLobbyInfo();
|
||||
return true;
|
||||
}},
|
||||
{ "spectator",
|
||||
s =>
|
||||
{
|
||||
var slotData = Server.lobbyInfo.Slots.Where(ax => ax.Spectator && !Server.lobbyInfo.Clients.Any(l => l.Slot == ax.Index)).FirstOrDefault();
|
||||
var slotData = server.lobbyInfo.Slots.Where(ax => ax.Spectator && !server.lobbyInfo.Clients.Any(l => l.Slot == ax.Index)).FirstOrDefault();
|
||||
if (slotData == null)
|
||||
return true;
|
||||
|
||||
client.Slot = slotData.Index;
|
||||
SyncClientToPlayerReference(client, slotData.MapPlayer != null ? Server.Map.Players[slotData.MapPlayer] : null);
|
||||
SyncClientToPlayerReference(client, slotData.MapPlayer != null ? server.Map.Players[slotData.MapPlayer] : null);
|
||||
|
||||
Server.SyncLobbyInfo();
|
||||
server.SyncLobbyInfo();
|
||||
return true;
|
||||
}},
|
||||
{ "slot",
|
||||
@@ -91,15 +93,15 @@ namespace OpenRA.Server.Traits
|
||||
int slot;
|
||||
if (!int.TryParse(s, out slot)) { Log.Write("server", "Invalid slot: {0}", s ); return false; }
|
||||
|
||||
var slotData = Server.lobbyInfo.Slots.FirstOrDefault( x => x.Index == slot );
|
||||
var slotData = server.lobbyInfo.Slots.FirstOrDefault( x => x.Index == slot );
|
||||
if (slotData == null || slotData.Closed || slotData.Bot != null
|
||||
|| Server.lobbyInfo.Clients.Any( c => c.Slot == slot ))
|
||||
|| server.lobbyInfo.Clients.Any( c => c.Slot == slot ))
|
||||
return false;
|
||||
|
||||
client.Slot = slot;
|
||||
SyncClientToPlayerReference(client, slotData.MapPlayer != null ? Server.Map.Players[slotData.MapPlayer] : null);
|
||||
SyncClientToPlayerReference(client, slotData.MapPlayer != null ? server.Map.Players[slotData.MapPlayer] : null);
|
||||
|
||||
Server.SyncLobbyInfo();
|
||||
server.SyncLobbyInfo();
|
||||
return true;
|
||||
}},
|
||||
{ "slot_close",
|
||||
@@ -108,13 +110,13 @@ namespace OpenRA.Server.Traits
|
||||
int slot;
|
||||
if (!int.TryParse(s, out slot)) { Log.Write("server", "Invalid slot: {0}", s ); return false; }
|
||||
|
||||
var slotData = Server.lobbyInfo.Slots.FirstOrDefault( x => x.Index == slot );
|
||||
var slotData = server.lobbyInfo.Slots.FirstOrDefault( x => x.Index == slot );
|
||||
if (slotData == null)
|
||||
return false;
|
||||
|
||||
if (conn.PlayerIndex != 0)
|
||||
{
|
||||
Server.SendChatTo( conn, "Only the host can alter slots" );
|
||||
server.SendChatTo( conn, "Only the host can alter slots" );
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -122,15 +124,15 @@ namespace OpenRA.Server.Traits
|
||||
slotData.Bot = null;
|
||||
|
||||
/* kick any player that's in the slot */
|
||||
var occupant = Server.lobbyInfo.Clients.FirstOrDefault( c => c.Slot == slotData.Index );
|
||||
var occupant = server.lobbyInfo.Clients.FirstOrDefault( c => c.Slot == slotData.Index );
|
||||
if (occupant != null)
|
||||
{
|
||||
var occupantConn = Server.conns.FirstOrDefault( c => c.PlayerIndex == occupant.Index );
|
||||
var occupantConn = server.conns.FirstOrDefault( c => c.PlayerIndex == occupant.Index );
|
||||
if (occupantConn != null)
|
||||
Server.DropClient( occupantConn, new Exception() );
|
||||
server.DropClient( occupantConn, new Exception() );
|
||||
}
|
||||
|
||||
Server.SyncLobbyInfo();
|
||||
server.SyncLobbyInfo();
|
||||
return true;
|
||||
}},
|
||||
{ "slot_open",
|
||||
@@ -139,20 +141,20 @@ namespace OpenRA.Server.Traits
|
||||
int slot;
|
||||
if (!int.TryParse(s, out slot)) { Log.Write("server", "Invalid slot: {0}", s ); return false; }
|
||||
|
||||
var slotData = Server.lobbyInfo.Slots.FirstOrDefault( x => x.Index == slot );
|
||||
var slotData = server.lobbyInfo.Slots.FirstOrDefault( x => x.Index == slot );
|
||||
if (slotData == null)
|
||||
return false;
|
||||
|
||||
if (conn.PlayerIndex != 0)
|
||||
{
|
||||
Server.SendChatTo( conn, "Only the host can alter slots" );
|
||||
server.SendChatTo( conn, "Only the host can alter slots" );
|
||||
return true;
|
||||
}
|
||||
|
||||
slotData.Closed = false;
|
||||
slotData.Bot = null;
|
||||
|
||||
Server.SyncLobbyInfo();
|
||||
server.SyncLobbyInfo();
|
||||
return true;
|
||||
}},
|
||||
{ "slot_bot",
|
||||
@@ -162,26 +164,26 @@ namespace OpenRA.Server.Traits
|
||||
|
||||
if (parts.Length != 2)
|
||||
{
|
||||
Server.SendChatTo( conn, "Malformed slot_bot command" );
|
||||
server.SendChatTo( conn, "Malformed slot_bot command" );
|
||||
return true;
|
||||
}
|
||||
|
||||
int slot;
|
||||
if (!int.TryParse(parts[0], out slot)) { Log.Write("server", "Invalid slot: {0}", s ); return false; }
|
||||
|
||||
var slotData = Server.lobbyInfo.Slots.FirstOrDefault( x => x.Index == slot );
|
||||
var slotData = server.lobbyInfo.Slots.FirstOrDefault( x => x.Index == slot );
|
||||
if (slotData == null)
|
||||
return false;
|
||||
|
||||
if (conn.PlayerIndex != 0)
|
||||
{
|
||||
Server.SendChatTo( conn, "Only the host can alter slots" );
|
||||
server.SendChatTo( conn, "Only the host can alter slots" );
|
||||
return true;
|
||||
}
|
||||
|
||||
slotData.Bot = parts[1];
|
||||
|
||||
Server.SyncLobbyInfo();
|
||||
server.SyncLobbyInfo();
|
||||
return true;
|
||||
}},
|
||||
{ "map",
|
||||
@@ -189,23 +191,23 @@ namespace OpenRA.Server.Traits
|
||||
{
|
||||
if (conn.PlayerIndex != 0)
|
||||
{
|
||||
Server.SendChatTo( conn, "Only the host can change the map" );
|
||||
server.SendChatTo( conn, "Only the host can change the map" );
|
||||
return true;
|
||||
}
|
||||
Server.lobbyInfo.GlobalSettings.Map = s;
|
||||
server.lobbyInfo.GlobalSettings.Map = s;
|
||||
LoadMap();
|
||||
|
||||
foreach(var c in Server.lobbyInfo.Clients)
|
||||
foreach(var c in server.lobbyInfo.Clients)
|
||||
{
|
||||
c.SpawnPoint = 0;
|
||||
var slotData = Server.lobbyInfo.Slots.FirstOrDefault( x => x.Index == c.Slot );
|
||||
var slotData = server.lobbyInfo.Slots.FirstOrDefault( x => x.Index == c.Slot );
|
||||
if (slotData != null && slotData.MapPlayer != null)
|
||||
SyncClientToPlayerReference(c, Server.Map.Players[slotData.MapPlayer]);
|
||||
SyncClientToPlayerReference(c, server.Map.Players[slotData.MapPlayer]);
|
||||
|
||||
c.State = Session.ClientState.NotReady;
|
||||
}
|
||||
|
||||
Server.SyncLobbyInfo();
|
||||
server.SyncLobbyInfo();
|
||||
return true;
|
||||
}},
|
||||
{ "lockteams",
|
||||
@@ -213,12 +215,12 @@ namespace OpenRA.Server.Traits
|
||||
{
|
||||
if (conn.PlayerIndex != 0)
|
||||
{
|
||||
Server.SendChatTo( conn, "Only the host can set that option" );
|
||||
server.SendChatTo( conn, "Only the host can set that option" );
|
||||
return true;
|
||||
}
|
||||
|
||||
bool.TryParse(s, out Server.lobbyInfo.GlobalSettings.LockTeams);
|
||||
Server.SyncLobbyInfo();
|
||||
bool.TryParse(s, out server.lobbyInfo.GlobalSettings.LockTeams);
|
||||
server.SyncLobbyInfo();
|
||||
return true;
|
||||
}},
|
||||
};
|
||||
@@ -247,8 +249,8 @@ namespace OpenRA.Server.Traits
|
||||
|
||||
public static void LoadMap()
|
||||
{
|
||||
Server.Map = new Map(Server.ModData.AvailableMaps[Server.lobbyInfo.GlobalSettings.Map]);
|
||||
Server.lobbyInfo.Slots = Server.Map.Players
|
||||
server.Map = new Map(server.ModData.AvailableMaps[server.lobbyInfo.GlobalSettings.Map]);
|
||||
server.lobbyInfo.Slots = server.Map.Players
|
||||
.Select(p => MakeSlotFromPlayerReference(p.Value))
|
||||
.Where(s => s != null)
|
||||
.Select((s, i) => { s.Index = i; return s; })
|
||||
@@ -256,10 +258,10 @@ namespace OpenRA.Server.Traits
|
||||
|
||||
// Generate slots for spectators
|
||||
for (int i = 0; i < MaxSpectators; i++)
|
||||
Server.lobbyInfo.Slots.Add(new Session.Slot
|
||||
server.lobbyInfo.Slots.Add(new Session.Slot
|
||||
{
|
||||
Spectator = true,
|
||||
Index = Server.lobbyInfo.Slots.Count(),
|
||||
Index = server.lobbyInfo.Slots.Count(),
|
||||
MapPlayer = null,
|
||||
Bot = null
|
||||
});
|
||||
@@ -282,23 +284,23 @@ namespace OpenRA.Server.Traits
|
||||
Slot = ChooseFreeSlot(),
|
||||
};
|
||||
|
||||
var slotData = Server.lobbyInfo.Slots.FirstOrDefault( x => x.Index == client.Slot );
|
||||
var slotData = server.lobbyInfo.Slots.FirstOrDefault( x => x.Index == client.Slot );
|
||||
if (slotData != null)
|
||||
SyncClientToPlayerReference(client, Server.Map.Players[slotData.MapPlayer]);
|
||||
SyncClientToPlayerReference(client, server.Map.Players[slotData.MapPlayer]);
|
||||
|
||||
Server.lobbyInfo.Clients.Add(client);
|
||||
server.lobbyInfo.Clients.Add(client);
|
||||
|
||||
Log.Write("server", "Client {0}: Accepted connection from {1}",
|
||||
newConn.PlayerIndex, newConn.socket.RemoteEndPoint);
|
||||
|
||||
Server.SendChat(newConn, "has joined the game.");
|
||||
Server.SyncLobbyInfo();
|
||||
server.SendChat(newConn, "has joined the game.");
|
||||
server.SyncLobbyInfo();
|
||||
}
|
||||
|
||||
static int ChooseFreeSlot()
|
||||
{
|
||||
return Server.lobbyInfo.Slots.First(s => !s.Closed && s.Bot == null
|
||||
&& !Server.lobbyInfo.Clients.Any( c => c.Slot == s.Index )).Index;
|
||||
return server.lobbyInfo.Slots.First(s => !s.Closed && s.Bot == null
|
||||
&& !server.lobbyInfo.Clients.Any( c => c.Slot == s.Index )).Index;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,8 +11,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using OpenRA.Server;
|
||||
using server = OpenRA.Server.Server;
|
||||
|
||||
namespace OpenRA.Server.Traits
|
||||
namespace OpenRA.Mods.RA.Server
|
||||
{
|
||||
public class MasterServerPinger : ServerTrait, ITick, INotifySyncLobbyInfo, IStartGame
|
||||
{
|
||||
@@ -26,7 +28,7 @@ namespace OpenRA.Server.Traits
|
||||
else
|
||||
lock (masterServerMessages)
|
||||
while (masterServerMessages.Count > 0)
|
||||
Server.SendChat(null, masterServerMessages.Dequeue());
|
||||
server.SendChat(null, masterServerMessages.Dequeue());
|
||||
|
||||
}
|
||||
|
||||
@@ -61,11 +63,11 @@ namespace OpenRA.Server.Traits
|
||||
{
|
||||
wc.DownloadData(
|
||||
masterServerUrl + url.F(
|
||||
externalPort, Uri.EscapeUriString(Server.Name),
|
||||
Server.GameStarted ? 2 : 1, // todo: post-game states, etc.
|
||||
Server.lobbyInfo.Clients.Count,
|
||||
string.Join(",", Server.lobbyInfo.GlobalSettings.Mods),
|
||||
Server.lobbyInfo.GlobalSettings.Map));
|
||||
externalPort, Uri.EscapeUriString(server.Name),
|
||||
server.GameStarted ? 2 : 1, // todo: post-game states, etc.
|
||||
server.lobbyInfo.Clients.Count,
|
||||
string.Join(",", server.lobbyInfo.GlobalSettings.Mods),
|
||||
server.lobbyInfo.GlobalSettings.Map));
|
||||
|
||||
if (isInitialPing)
|
||||
{
|
||||
@@ -13,21 +13,23 @@ using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.Network;
|
||||
using OpenRA.Server;
|
||||
using server = OpenRA.Server.Server;
|
||||
|
||||
namespace OpenRA.Server.Traits
|
||||
namespace OpenRA.Mods.RA.Server
|
||||
{
|
||||
public class PlayerCommands : ServerTrait, IInterpretCommand
|
||||
{
|
||||
public bool InterpretCommand(Connection conn, Session.Client client, string cmd)
|
||||
{
|
||||
if (Server.GameStarted)
|
||||
if (server.GameStarted)
|
||||
{
|
||||
Server.SendChatTo(conn, "Cannot change state when game started. ({0})".F(cmd));
|
||||
server.SendChatTo(conn, "Cannot change state when game started. ({0})".F(cmd));
|
||||
return false;
|
||||
}
|
||||
else if (client.State == Session.ClientState.Ready && !(cmd == "ready" || cmd == "startgame"))
|
||||
{
|
||||
Server.SendChatTo(conn, "Cannot change state when marked as ready.");
|
||||
server.SendChatTo(conn, "Cannot change state when marked as ready.");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -38,14 +40,14 @@ namespace OpenRA.Server.Traits
|
||||
{
|
||||
Log.Write("server", "Player@{0} is now known as {1}", conn.socket.RemoteEndPoint, s);
|
||||
client.Name = s;
|
||||
Server.SyncLobbyInfo();
|
||||
server.SyncLobbyInfo();
|
||||
return true;
|
||||
}},
|
||||
{ "race",
|
||||
s =>
|
||||
{
|
||||
client.Country = s;
|
||||
Server.SyncLobbyInfo();
|
||||
server.SyncLobbyInfo();
|
||||
return true;
|
||||
}},
|
||||
{ "team",
|
||||
@@ -55,7 +57,7 @@ namespace OpenRA.Server.Traits
|
||||
if (!int.TryParse(s, out team)) { Log.Write("server", "Invalid team: {0}", s ); return false; }
|
||||
|
||||
client.Team = team;
|
||||
Server.SyncLobbyInfo();
|
||||
server.SyncLobbyInfo();
|
||||
return true;
|
||||
}},
|
||||
{ "spawn",
|
||||
@@ -68,14 +70,14 @@ namespace OpenRA.Server.Traits
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Server.lobbyInfo.Clients.Where( c => c != client ).Any( c => (c.SpawnPoint == spawnPoint) && (c.SpawnPoint != 0) ))
|
||||
if (server.lobbyInfo.Clients.Where( c => c != client ).Any( c => (c.SpawnPoint == spawnPoint) && (c.SpawnPoint != 0) ))
|
||||
{
|
||||
Server.SendChatTo( conn, "You can't be at the same spawn point as another player" );
|
||||
server.SendChatTo( conn, "You can't be at the same spawn point as another player" );
|
||||
return true;
|
||||
}
|
||||
|
||||
client.SpawnPoint = spawnPoint;
|
||||
Server.SyncLobbyInfo();
|
||||
server.SyncLobbyInfo();
|
||||
return true;
|
||||
}},
|
||||
{ "color",
|
||||
@@ -84,7 +86,7 @@ namespace OpenRA.Server.Traits
|
||||
var c = s.Split(',').Select(cc => int.Parse(cc)).ToArray();
|
||||
client.Color1 = Color.FromArgb(c[0],c[1],c[2]);
|
||||
client.Color2 = Color.FromArgb(c[3],c[4],c[5]);
|
||||
Server.SyncLobbyInfo();
|
||||
server.SyncLobbyInfo();
|
||||
return true;
|
||||
}}
|
||||
};
|
||||
Reference in New Issue
Block a user