summaryrefslogtreecommitdiff
path: root/command.c
diff options
context:
space:
mode:
authortron <tron@openttd.org>2005-05-15 18:50:55 +0000
committertron <tron@openttd.org>2005-05-15 18:50:55 +0000
commitfea596567944fba8d9d4ead62d948db14690fdf1 (patch)
treead6dc27f46725e511e93e061f51683311027ec65 /command.c
parent6cd410afbb3cedff9f6d86fc30dbd4e67817ebc9 (diff)
downloadopenttd-fea596567944fba8d9d4ead62d948db14690fdf1.tar.xz
(svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
Diffstat (limited to 'command.c')
-rw-r--r--command.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/command.c b/command.c
index 7d9e2460b..24f6817e1 100644
--- a/command.c
+++ b/command.c
@@ -7,6 +7,8 @@
#include "player.h"
#include "network.h"
+const char* _cmd_text = NULL;
+
#define DEF_COMMAND(yyyy) int32 yyyy(int x, int y, uint32 flags, uint32 p1, uint32 p2)
DEF_COMMAND(CmdBuildRailroadTrack);
@@ -323,7 +325,10 @@ int32 DoCommand(int x, int y, uint32 p1, uint32 p2, uint32 flags, uint procc)
CommandProc *proc;
/* Do not even think about executing out-of-bounds tile-commands */
- if (TILE_FROM_XY(x,y) > MapSize()) return CMD_ERROR;
+ if (TILE_FROM_XY(x,y) > MapSize()) {
+ _cmd_text = NULL;
+ return CMD_ERROR;
+ }
proc = _command_proc_table[procc].proc;
@@ -352,6 +357,7 @@ int32 DoCommand(int x, int y, uint32 p1, uint32 p2, uint32 flags, uint procc)
if (!(flags & DC_EXEC)) {
_docommand_recursive--;
+ _cmd_text = NULL;
return res;
}
}
@@ -363,6 +369,7 @@ int32 DoCommand(int x, int y, uint32 p1, uint32 p2, uint32 flags, uint procc)
if (res & 0xFFFF) _error_message = res & 0xFFFF;
error:
_docommand_recursive--;
+ _cmd_text = NULL;
return CMD_ERROR;
}
@@ -371,6 +378,7 @@ error:
SubtractMoneyFromPlayer(res);
}
+ _cmd_text = NULL;
return res;
}
@@ -394,7 +402,10 @@ bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback,
int y = TileY(tile) * 16;
/* Do not even think about executing out-of-bounds tile-commands */
- if (tile > MapSize()) return false;
+ if (tile > MapSize()) {
+ _cmd_text = NULL;
+ return false;
+ }
assert(_docommand_recursive == 0);
@@ -405,6 +416,7 @@ bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback,
// spectator has no rights.
if (_current_player == OWNER_SPECTATOR) {
ShowErrorMessage(_error_message, _error_message_2, x, y);
+ _cmd_text = NULL;
return false;
}
@@ -446,6 +458,7 @@ bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback,
}
_docommand_recursive = 0;
+ _cmd_text = NULL;
return false;
}
@@ -467,6 +480,7 @@ bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback,
if (_networking && !(cmd & CMD_NETWORK_COMMAND)) {
NetworkSend_Command(tile, p1, p2, cmd, callback);
_docommand_recursive = 0;
+ _cmd_text = NULL;
return true;
}
#endif /* ENABLE_NETWORK */
@@ -505,6 +519,7 @@ bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback,
_docommand_recursive = 0;
if (callback) callback(true, tile, p1, p2);
+ _cmd_text = NULL;
return true;
show_error:
@@ -516,5 +531,6 @@ callb_err:
_docommand_recursive = 0;
if (callback) callback(false, tile, p1, p2);
+ _cmd_text = NULL;
return false;
}