summaryrefslogtreecommitdiff
path: root/network_server.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 /network_server.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 'network_server.c')
-rw-r--r--network_server.c26
1 files changed, 3 insertions, 23 deletions
diff --git a/network_server.c b/network_server.c
index c5614bb33..89e4c4c00 100644
--- a/network_server.c
+++ b/network_server.c
@@ -458,14 +458,11 @@ DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_COMMAND)(NetworkClientState *cs, Com
// uint32: P1 (free variables used in DoCommand)
// uint32: P2
// uint32: Tile
- // uint32: decode_params
- // 10 times the last one (lengthof(cp->dp))
+ // string: text
// uint8: CallBackID (see callback_table.c)
// uint32: Frame of execution
//
- uint i;
- char *dparam_char;
Packet *p = NetworkSend_Init(PACKET_SERVER_COMMAND);
NetworkSend_uint8(p, cp->player);
@@ -473,14 +470,7 @@ DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_COMMAND)(NetworkClientState *cs, Com
NetworkSend_uint32(p, cp->p1);
NetworkSend_uint32(p, cp->p2);
NetworkSend_uint32(p, cp->tile);
- /* We are going to send them byte by byte, because dparam is misused
- for chars (if it is used), and else we have a BigEndian / LittleEndian
- problem.. we should fix the misuse of dparam... -- TrueLight */
- dparam_char = (char *)&cp->dp[0];
- for (i = 0; i < lengthof(cp->dp) * 4; i++) {
- NetworkSend_uint8(p, *dparam_char);
- dparam_char++;
- }
+ NetworkSend_string(p, cp->text);
NetworkSend_uint8(p, cp->callback);
NetworkSend_uint32(p, cp->frame);
@@ -806,8 +796,6 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND)
{
NetworkClientState *new_cs;
const NetworkClientInfo *ci;
- char *dparam_char;
- uint i;
byte callback;
CommandPacket *cp = malloc(sizeof(CommandPacket));
@@ -824,15 +812,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND)
cp->p1 = NetworkRecv_uint32(cs, p);
cp->p2 = NetworkRecv_uint32(cs, p);
cp->tile = NetworkRecv_uint32(cs, p);
- /** @todo We are going to send dparams byte by byte, because dparam is misused
- * for charstrings (if it is used), and else we have a Big/Little Endian
- * problem.. we should fix the misuse of dparam... -- TrueLight
- */
- dparam_char = (char *)&cp->dp[0];
- for (i = 0; i < lengthof(cp->dp) * 4; i++) {
- *dparam_char = NetworkRecv_uint8(cs, p);
- dparam_char++;
- }
+ NetworkRecv_string(cs, p, cp->text, lengthof(cp->text));
callback = NetworkRecv_uint8(cs, p);