Files
@ r10554:611efc1f7583
Branch filter:
Location: cpp/openttd-patchpack/source/src/network/network_data.cpp - annotation
r10554:611efc1f7583
3.1 KiB
text/x-c
(svn r14811) -Fix: off-by-one causing possible out-of-bounds reads.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | r5584:545d748cc681 r5584:545d748cc681 r9111:983de9c5a848 r9111:983de9c5a848 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r9428:6800206a6c0d r5584:545d748cc681 r8116:df67d3c5e4fd r5584:545d748cc681 r8130:bece2e5c7460 r8214:9a3935f9ef4e r8247:adcdb6aead11 r10208:ef8fcc3dc4ca r5584:545d748cc681 r5584:545d748cc681 r10466:1402601a87b9 r5584:545d748cc681 r5609:a56ae00a9125 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r10499:570896340d7a r5584:545d748cc681 r6843:81227cd4a391 r5584:545d748cc681 r10207:a1fc2f2a33db r10207:a1fc2f2a33db r10207:a1fc2f2a33db r10207:a1fc2f2a33db r10207:a1fc2f2a33db r10207:a1fc2f2a33db r5584:545d748cc681 r6843:81227cd4a391 r6843:81227cd4a391 r6843:81227cd4a391 r5584:545d748cc681 r5584:545d748cc681 r6843:81227cd4a391 r6843:81227cd4a391 r6843:81227cd4a391 r5584:545d748cc681 r5584:545d748cc681 r10499:570896340d7a r5584:545d748cc681 r5584:545d748cc681 r6843:81227cd4a391 r6843:81227cd4a391 r6843:81227cd4a391 r6843:81227cd4a391 r6843:81227cd4a391 r6843:81227cd4a391 r6843:81227cd4a391 r5584:545d748cc681 r6843:81227cd4a391 r6843:81227cd4a391 r7222:da613e351034 r6843:81227cd4a391 r6843:81227cd4a391 r6843:81227cd4a391 r6843:81227cd4a391 r6843:81227cd4a391 r6843:81227cd4a391 r6843:81227cd4a391 r5584:545d748cc681 r5584:545d748cc681 r6843:81227cd4a391 r6843:81227cd4a391 r6843:81227cd4a391 r10466:1402601a87b9 r10465:263aa0f74150 r8694:3508b7438c77 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r6843:81227cd4a391 r6843:81227cd4a391 r6843:81227cd4a391 r6843:81227cd4a391 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r10207:a1fc2f2a33db r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r7187:ab6c70e149d9 r10499:570896340d7a r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 | /* $Id$ */
/** @file network_data.cpp Command handling over network connections. */
#ifdef ENABLE_NETWORK
#include "../stdafx.h"
#include "../debug.h"
#include "network_internal.h"
#include "network_client.h"
#include "../command_func.h"
#include "../callback_table.h"
#include "../core/alloc_func.hpp"
#include "../string_func.h"
#include "../date_func.h"
#include "../company_func.h"
// Add a command to the local command queue
void NetworkAddCommandQueue(NetworkClientSocket *cs, CommandPacket *cp)
{
CommandPacket* new_cp = MallocT<CommandPacket>(1);
*new_cp = *cp;
if (cs->command_queue == NULL) {
cs->command_queue = new_cp;
} else {
CommandPacket *c = cs->command_queue;
while (c->next != NULL) c = c->next;
c->next = new_cp;
}
}
// Prepare a DoCommand to be send over the network
void NetworkSend_Command(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback, const char *text)
{
CommandPacket c;
c.company = _local_company;
c.next = NULL;
c.tile = tile;
c.p1 = p1;
c.p2 = p2;
c.cmd = cmd;
c.callback = 0;
while (c.callback < _callback_table_count && _callback_table[c.callback] != callback) {
c.callback++;
}
if (c.callback == _callback_table_count) {
DEBUG(net, 0, "Unknown callback. (Pointer: %p) No callback sent", callback);
c.callback = 0; // _callback_table[0] == NULL
}
strecpy(c.text, (text != NULL) ? text : "", lastof(c.text));
if (_network_server) {
/* If we are the server, we queue the command in our 'special' queue.
* In theory, we could execute the command right away, but then the
* client on the server can do everything 1 tick faster than others.
* So to keep the game fair, we delay the command with 1 tick
* which gives about the same speed as most clients.
*/
c.frame = _frame_counter_max + 1;
CommandPacket *new_cp = MallocT<CommandPacket>(1);
*new_cp = c;
new_cp->my_cmd = true;
if (_local_command_queue == NULL) {
_local_command_queue = new_cp;
} else {
/* Find last packet */
CommandPacket *cp = _local_command_queue;
while (cp->next != NULL) cp = cp->next;
cp->next = new_cp;
}
/* Only the local client (in this case, the server) gets the callback */
c.callback = 0;
/* And we queue it for delivery to the clients */
NetworkClientSocket *cs;
FOR_ALL_CLIENT_SOCKETS(cs) {
if (cs->status > STATUS_MAP_WAIT) NetworkAddCommandQueue(cs, &c);
}
return;
}
c.frame = 0; // The client can't tell which frame, so just make it 0
/* Clients send their command to the server and forget all about the packet */
SEND_COMMAND(PACKET_CLIENT_COMMAND)(&c);
}
// Execute a DoCommand we received from the network
void NetworkExecuteCommand(CommandPacket *cp)
{
_current_company = cp->company;
/* cp->callback is unsigned. so we don't need to do lower bounds checking. */
if (cp->callback > _callback_table_count) {
DEBUG(net, 0, "Received out-of-bounds callback (%d)", cp->callback);
cp->callback = 0;
}
DoCommandP(cp->tile, cp->p1, cp->p2, cp->cmd | CMD_NETWORK_COMMAND, _callback_table[cp->callback], cp->text, cp->my_cmd);
}
#endif /* ENABLE_NETWORK */
|