forked from mirror/OpenTTD
(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.
This commit is contained in:
@@ -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);
|
||||
|
||||
|
Reference in New Issue
Block a user