src/network/network_data.cpp
changeset 10207 c291a21b304e
parent 9428 1ba05b499957
child 10208 72c00af5c95d
equal deleted inserted replaced
10206:0050610c0368 10207:c291a21b304e
    34 // Prepare a DoCommand to be send over the network
    34 // Prepare a DoCommand to be send over the network
    35 void NetworkSend_Command(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback)
    35 void NetworkSend_Command(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback)
    36 {
    36 {
    37 	CommandPacket c;
    37 	CommandPacket c;
    38 
    38 
    39 	c.player = _local_player;
    39 	c.company = _local_company;
    40 	c.next   = NULL;
    40 	c.next    = NULL;
    41 	c.tile   = tile;
    41 	c.tile    = tile;
    42 	c.p1     = p1;
    42 	c.p1      = p1;
    43 	c.p2     = p2;
    43 	c.p2      = p2;
    44 	c.cmd    = cmd;
    44 	c.cmd     = cmd;
    45 
    45 
    46 	c.callback = 0;
    46 	c.callback = 0;
    47 	while (c.callback < _callback_table_count && _callback_table[c.callback] != callback) {
    47 	while (c.callback < _callback_table_count && _callback_table[c.callback] != callback) {
    48 		c.callback++;
    48 		c.callback++;
    49 	}
    49 	}
    93 }
    93 }
    94 
    94 
    95 // Execute a DoCommand we received from the network
    95 // Execute a DoCommand we received from the network
    96 void NetworkExecuteCommand(CommandPacket *cp)
    96 void NetworkExecuteCommand(CommandPacket *cp)
    97 {
    97 {
    98 	_current_player = cp->player;
    98 	_current_company = cp->company;
    99 	_cmd_text = cp->text;
    99 	_cmd_text = cp->text;
   100 	/* cp->callback is unsigned. so we don't need to do lower bounds checking. */
   100 	/* cp->callback is unsigned. so we don't need to do lower bounds checking. */
   101 	if (cp->callback > _callback_table_count) {
   101 	if (cp->callback > _callback_table_count) {
   102 		DEBUG(net, 0, "Received out-of-bounds callback (%d)", cp->callback);
   102 		DEBUG(net, 0, "Received out-of-bounds callback (%d)", cp->callback);
   103 		cp->callback = 0;
   103 		cp->callback = 0;
   104 	}
   104 	}
   105 
   105 
   106 	DebugDumpCommands("ddc:cmd:%d;%d;%d;%d;%d;%d;%d;%s\n", _date, _date_fract, (int)cp->player, cp->tile, cp->p1, cp->p2, cp->cmd, cp->text);
   106 	DebugDumpCommands("ddc:cmd:%d;%d;%d;%d;%d;%d;%d;%s\n", _date, _date_fract, (int)cp->company, cp->tile, cp->p1, cp->p2, cp->cmd, cp->text);
   107 
   107 
   108 	DoCommandP(cp->tile, cp->p1, cp->p2, _callback_table[cp->callback], cp->cmd | CMD_NETWORK_COMMAND, cp->my_cmd);
   108 	DoCommandP(cp->tile, cp->p1, cp->p2, _callback_table[cp->callback], cp->cmd | CMD_NETWORK_COMMAND, cp->my_cmd);
   109 }
   109 }
   110 
   110 
   111 #endif /* ENABLE_NETWORK */
   111 #endif /* ENABLE_NETWORK */