pull some validation out of individual lobby/player commands
This commit is contained in:
@@ -20,7 +20,24 @@ namespace OpenRA.Mods.RA.Server
|
|||||||
{
|
{
|
||||||
public class LobbyCommands : ServerTrait, IInterpretCommand, INotifyServerStart
|
public class LobbyCommands : ServerTrait, IInterpretCommand, INotifyServerStart
|
||||||
{
|
{
|
||||||
public bool InterpretCommand(S server, Connection conn, Session.Client client, string cmd)
|
static bool ValidateSlotCommand(S server, Connection conn, string arg, bool requiresHost)
|
||||||
|
{
|
||||||
|
if (!server.lobbyInfo.Slots.ContainsKey(arg))
|
||||||
|
{
|
||||||
|
Log.Write("server", "Invalid slot: {0}", arg );
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (requiresHost && conn.PlayerIndex != 0)
|
||||||
|
{
|
||||||
|
server.SendChatTo( conn, "Only the host can do that" );
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool ValidateCommand(S server, Connection conn, Session.Client client, string cmd)
|
||||||
{
|
{
|
||||||
if (server.GameStarted)
|
if (server.GameStarted)
|
||||||
{
|
{
|
||||||
@@ -33,6 +50,14 @@ namespace OpenRA.Mods.RA.Server
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool InterpretCommand(S server, Connection conn, Session.Client client, string cmd)
|
||||||
|
{
|
||||||
|
if (!ValidateCommand(server, conn, client, cmd))
|
||||||
|
return false;
|
||||||
|
|
||||||
var dict = new Dictionary<string, Func<string, bool>>
|
var dict = new Dictionary<string, Func<string, bool>>
|
||||||
{
|
{
|
||||||
{ "ready",
|
{ "ready",
|
||||||
@@ -102,17 +127,8 @@ namespace OpenRA.Mods.RA.Server
|
|||||||
{ "slot_close",
|
{ "slot_close",
|
||||||
s =>
|
s =>
|
||||||
{
|
{
|
||||||
if (!server.lobbyInfo.Slots.ContainsKey(s))
|
if (!ValidateSlotCommand( server, conn, s, true ))
|
||||||
{
|
|
||||||
Log.Write("server", "Invalid slot: {0}", s );
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
if (conn.PlayerIndex != 0)
|
|
||||||
{
|
|
||||||
server.SendChatTo( conn, "Only the host can alter slots" );
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// kick any player that's in the slot
|
// kick any player that's in the slot
|
||||||
var occupant = server.lobbyInfo.ClientInSlot(s);
|
var occupant = server.lobbyInfo.ClientInSlot(s);
|
||||||
@@ -138,17 +154,8 @@ namespace OpenRA.Mods.RA.Server
|
|||||||
{ "slot_open",
|
{ "slot_open",
|
||||||
s =>
|
s =>
|
||||||
{
|
{
|
||||||
if (!server.lobbyInfo.Slots.ContainsKey(s))
|
if (!ValidateSlotCommand( server, conn, s, true ))
|
||||||
{
|
|
||||||
Log.Write("server", "Invalid slot: {0}", s );
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
if (conn.PlayerIndex != 0)
|
|
||||||
{
|
|
||||||
server.SendChatTo( conn, "Only the host can alter slots" );
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
var slot = server.lobbyInfo.Slots[s];
|
var slot = server.lobbyInfo.Slots[s];
|
||||||
slot.Closed = false;
|
slot.Closed = false;
|
||||||
@@ -172,17 +179,8 @@ namespace OpenRA.Mods.RA.Server
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!server.lobbyInfo.Slots.ContainsKey(parts[0]))
|
if (!ValidateSlotCommand( server, conn, parts[0], true ))
|
||||||
{
|
|
||||||
Log.Write("server", "Invalid slot: {0}", parts[0] );
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
if (conn.PlayerIndex != 0)
|
|
||||||
{
|
|
||||||
server.SendChatTo( conn, "Only the host can alter slots" );
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
var slot = server.lobbyInfo.Slots[parts[0]];
|
var slot = server.lobbyInfo.Slots[parts[0]];
|
||||||
var bot = server.lobbyInfo.ClientInSlot(parts[0]);
|
var bot = server.lobbyInfo.ClientInSlot(parts[0]);
|
||||||
|
|||||||
@@ -23,16 +23,8 @@ namespace OpenRA.Mods.RA.Server
|
|||||||
{
|
{
|
||||||
public bool InterpretCommand( S server, Connection conn, Session.Client client, string cmd)
|
public bool InterpretCommand( S server, Connection conn, Session.Client client, string cmd)
|
||||||
{
|
{
|
||||||
if (server.GameStarted)
|
if (!LobbyCommands.ValidateCommand(server, conn, client, cmd))
|
||||||
{
|
|
||||||
server.SendChatTo(conn, "Cannot change state when game started. ({0})".F(cmd));
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
else if (client.State == Session.ClientState.Ready && !(cmd == "ready" || cmd == "startgame"))
|
|
||||||
{
|
|
||||||
server.SendChatTo(conn, "Cannot change state when marked as ready.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
var dict = new Dictionary<string, Func<string, bool>>
|
var dict = new Dictionary<string, Func<string, bool>>
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user