summaryrefslogtreecommitdiff
path: root/command.c
diff options
context:
space:
mode:
authortruelight <truelight@openttd.org>2005-01-05 14:39:48 +0000
committertruelight <truelight@openttd.org>2005-01-05 14:39:48 +0000
commit523a6a1cffd1a7567453835500f387f3499b10a2 (patch)
tree0321af6b507ef39cda02042c21cc3ae5e417a162 /command.c
parentf1e9fdf76d951dec71c330f12783917cae464160 (diff)
downloadopenttd-523a6a1cffd1a7567453835500f387f3499b10a2.tar.xz
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
reads beyond the size of the packet -Fix: [Network] A server no longer crashes when a client sends an invalid DoCommand, but drops the client instead.
Diffstat (limited to 'command.c')
-rw-r--r--command.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/command.c b/command.c
index 6c0e0d7c9..cf4ac7944 100644
--- a/command.c
+++ b/command.c
@@ -312,6 +312,17 @@ static CommandProc * const _command_proc_table[] = {
CmdReplaceVehicle, /* 114 */
};
+/* This function range-checks a cmd, and checks if the cmd is not NULL */
+bool IsValidCommand(int cmd)
+{
+ cmd = cmd & 0xFF;
+
+ if (cmd < 0 || cmd >= lengthof(_command_proc_table) || _command_proc_table[cmd] == NULL)
+ return false;
+
+ return true;
+}
+
int32 DoCommandByTile(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint procc)
{
return DoCommand(GET_TILE_X(tile)*16, GET_TILE_Y(tile)*16, p1, p2, flags, procc);