summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-01-07 15:27:19 +0000
committerrubidium <rubidium@openttd.org>2009-01-07 15:27:19 +0000
commit4231c3ee82539e73808b5d35c4612b29a43d4884 (patch)
tree26ecdc3e2c01b662df452e9e13bbf21461754bc2 /src
parent505641833633f19b64080b652afe99328e726d42 (diff)
downloadopenttd-4231c3ee82539e73808b5d35c4612b29a43d4884.tar.xz
(svn r14897) -Codechange: don't allow a few command flags to be sent over the network as it's bogus information anyway; e.g. the "do not send over network" flag as it will be set whenever the command is received from the server/client.
-Codechange: test earlier whether the command (send from the server) is actually valid.
Diffstat (limited to 'src')
-rw-r--r--src/command.cpp2
-rw-r--r--src/network/network_client.cpp18
-rw-r--r--src/network/network_data.cpp2
-rw-r--r--src/network/network_server.cpp5
4 files changed, 26 insertions, 1 deletions
diff --git a/src/command.cpp b/src/command.cpp
index 03a7d3c80..08a9269aa 100644
--- a/src/command.cpp
+++ b/src/command.cpp
@@ -560,7 +560,7 @@ bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallbac
if (_networking && !(cmd & CMD_NETWORK_COMMAND)) {
CompanyID bck = _local_company;
if (_network_dedicated || (_network_server && bck == COMPANY_SPECTATOR)) _local_company = COMPANY_FIRST;
- NetworkSend_Command(tile, p1, p2, cmd, callback, text);
+ NetworkSend_Command(tile, p1, p2, cmd & ~CMD_FLAGS_MASK, callback, text);
if (_network_dedicated || (_network_server && bck == COMPANY_SPECTATOR)) _local_company = bck;
_docommand_recursive = 0;
ClearStorageChanges(false);
diff --git a/src/network/network_client.cpp b/src/network/network_client.cpp
index 2d7256beb..1c56fda7c 100644
--- a/src/network/network_client.cpp
+++ b/src/network/network_client.cpp
@@ -685,6 +685,24 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_COMMAND)
cp->my_cmd = p->Recv_bool();
cp->next = NULL;
+ if (!IsValidCommand(cp->cmd)) {
+ IConsolePrintF(CC_ERROR, "WARNING: invalid command from server, dropping...");
+ free(cp);
+ return NETWORK_RECV_STATUS_MALFORMED_PACKET;
+ }
+
+ if (GetCommandFlags(cp->cmd) & CMD_OFFLINE) {
+ IConsolePrintF(CC_ERROR, "WARNING: offline only command from server, dropping...");
+ free(cp);
+ return NETWORK_RECV_STATUS_MALFORMED_PACKET;
+ }
+
+ if ((cp->cmd & CMD_FLAGS_MASK) != 0) {
+ IConsolePrintF(CC_ERROR, "WARNING: invalid command flag from server, dropping...");
+ free(cp);
+ return NETWORK_RECV_STATUS_MALFORMED_PACKET;
+ }
+
// The server did send us this command..
// queue it in our own queue, so we can handle it in the upcoming frame!
diff --git a/src/network/network_data.cpp b/src/network/network_data.cpp
index cdcf0ba39..c56c7905f 100644
--- a/src/network/network_data.cpp
+++ b/src/network/network_data.cpp
@@ -34,6 +34,8 @@ void NetworkAddCommandQueue(NetworkClientSocket *cs, CommandPacket *cp)
// Prepare a DoCommand to be send over the network
void NetworkSend_Command(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback, const char *text)
{
+ assert((cmd & CMD_FLAG_MASK) == 0);
+
CommandPacket c;
c.company = _local_company;
diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp
index 2fc06f4a1..e496bb6a5 100644
--- a/src/network/network_server.cpp
+++ b/src/network/network_server.cpp
@@ -839,6 +839,11 @@ static bool CheckCommandFlags(const CommandPacket *cp, const NetworkClientInfo *
return false;
}
+ if ((cp->cmd & CMD_FLAGS_MASK) != 0) {
+ IConsolePrintF(CC_ERROR, "WARNING: invalid command flag from client %d (IP: %s), kicking...", ci->client_id, GetClientIP(ci));
+ return false;
+ }
+
return true;
}