diff options
author | rubidium <rubidium@openttd.org> | 2009-01-08 14:40:18 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2009-01-08 14:40:18 +0000 |
commit | 427e2d30c538e2edc1e9a570a2bf349b36dc5d75 (patch) | |
tree | aaad012b34556fa555a78f97f1b9ff51be515025 /src/network/network_client.cpp | |
parent | 38bd396f9022748b8768a543be5234c46c7d68fa (diff) | |
download | openttd-427e2d30c538e2edc1e9a570a2bf349b36dc5d75.tar.xz |
(svn r14915) -Codechange: unify the receiving and sending of commands, and thus unifying most of the validity checking too.
Diffstat (limited to 'src/network/network_client.cpp')
-rw-r--r-- | src/network/network_client.cpp | 33 |
1 files changed, 5 insertions, 28 deletions
diff --git a/src/network/network_client.cpp b/src/network/network_client.cpp index 77d18d291..23d112ce1 100644 --- a/src/network/network_client.cpp +++ b/src/network/network_client.cpp @@ -205,7 +205,7 @@ DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_ACK) } // Send a command packet to the server -DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_COMMAND)(CommandPacket *cp) +DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_COMMAND)(const CommandPacket *cp) { // // Packet: CLIENT_COMMAND @@ -221,14 +221,7 @@ DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_COMMAND)(CommandPacket *cp) // Packet *p = NetworkSend_Init(PACKET_CLIENT_COMMAND); - - p->Send_uint8 (cp->company); - p->Send_uint32(cp->cmd); - p->Send_uint32(cp->p1); - p->Send_uint32(cp->p2); - p->Send_uint32((uint32)cp->tile); - p->Send_string(cp->text); - p->Send_uint8 (cp->callback); + MY_CLIENT->Send_Command(p, cp); MY_CLIENT->Send_Packet(p); } @@ -674,29 +667,13 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_SYNC) DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_COMMAND) { CommandPacket cp; - cp.company = (CompanyID)p->Recv_uint8(); - cp.cmd = p->Recv_uint32(); - cp.p1 = p->Recv_uint32(); - cp.p2 = p->Recv_uint32(); - cp.tile = p->Recv_uint32(); - p->Recv_string(cp.text, sizeof(cp.text)); - cp.callback = p->Recv_uint8(); + const char *err = MY_CLIENT->Recv_Command(p, &cp); cp.frame = p->Recv_uint32(); cp.my_cmd = p->Recv_bool(); cp.next = NULL; - if (!IsValidCommand(cp.cmd)) { - IConsolePrintF(CC_ERROR, "WARNING: invalid command from server, dropping..."); - return NETWORK_RECV_STATUS_MALFORMED_PACKET; - } - - if (GetCommandFlags(cp.cmd) & CMD_OFFLINE) { - IConsolePrintF(CC_ERROR, "WARNING: offline only command from server, dropping..."); - return NETWORK_RECV_STATUS_MALFORMED_PACKET; - } - - if ((cp.cmd & CMD_FLAGS_MASK) != 0) { - IConsolePrintF(CC_ERROR, "WARNING: invalid command flag from server, dropping..."); + if (err != NULL) { + IConsolePrintF(CC_ERROR, "WARNING: %s from server, dropping...", err); return NETWORK_RECV_STATUS_MALFORMED_PACKET; } |