# network_command.cpp File Reference

Command handling over network connections. More...

`#include "../stdafx.h"`
`#include "../debug.h"`
`#include "network_client.h"`
`#include "network.h"`
`#include "../command_func.h"`
`#include "../company_func.h"`

Go to the source code of this file.

## Functions
void | NetworkAddCommandQueue (CommandPacket cp, NetworkClientSocket *cs)
| Add a command to the local or client socket command queue, based on the socket.
void | NetworkSend_Command (TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback, const char *text, CompanyID company)
| Prepare a DoCommand to be send over the network.
void | NetworkSyncCommandQueue (NetworkClientSocket *cs)
| Sync our local command queue to the command queue of the given socket.
void | NetworkExecuteLocalCommandQueue ()
| Execute all commands on the local command queue that ought to be executed this frame.
void | NetworkFreeLocalCommandQueue ()
| Free the local command queue.
## Variables
static CommandCallback *const | _callback_table []
| Table with all the callbacks we'll use for conversion.
static CommandPacket * | _local_command_queue = NULL
| Local queue of packets.

## Detailed Description

Command handling over network connections.

Definition in file network_command.cpp.

## Function Documentation

void NetworkAddCommandQueue | ( | CommandPacket | cp,
|  | NetworkClientSocket * | cs |
| ) |  |  |

Add a command to the local or client socket command queue, based on the socket.

Parameters:

  | cp | the command packet to add
  | cs | the socket to send to (NULL = locally)

Definition at line 61 of file network_command.cpp.

References NetworkClientSocket::command_queue, and CommandPacket::next.

Referenced by DEF_SERVER_RECEIVE_COMMAND(), NetworkSend_Command(), and NetworkSyncCommandQueue().

void NetworkSend_Command | ( | TileIndex | tile,
|  | uint32 | p1,
|  | uint32 | p2,
|  | uint32 | cmd,
|  | CommandCallback * | callback,
|  | const char * | text,
|  | CompanyID | company |
| ) |  |  |

Prepare a DoCommand to be send over the network.

Send a command over the network.

Parameters:

  | tile | The tile to perform a command on (see CommandProc)
  | p1 | Additional data for the command (see CommandProc)
  | p2 | Additional data for the command (see CommandProc)
  | cmd | The command to execute (a CMD_* value)
  | callback | A callback function to call after the command is finished
  | text | The text to pass
  | company | The company that wants to send the command

Definition at line 87 of file network_command.cpp.

References _network_server, CommandContainer::callback, CommandContainer::cmd, CMD_FLAGS_MASK, CommandPacket::company, CommandPacket::frame, lastof, CommandPacket::my_cmd, NetworkAddCommandQueue(), CommandPacket::next, CommandContainer::p1, CommandContainer::p2, NetworkClientSocket::status, STATUS_MAP_WAIT, strecpy(), CommandContainer::text, and CommandContainer::tile.

Referenced by CmdCompanyCtrl(), DoCommandPInternal(), and SyncCompanySettings().

void NetworkSyncCommandQueue | ( | NetworkClientSocket * | cs | ) |

Sync our local command queue to the command queue of the given socket.

This is needed for the case where we receive a command before saving the game for a joining client, but without the execution of those commands. Not syncing those commands means that the client will never get them and as such will be in a desynced state from the time it started with joining.

Parameters:

  | cs | The client to sync the queue to.

Definition at line 139 of file network_command.cpp.

References CommandContainer::callback, NetworkAddCommandQueue(), and CommandPacket::next.

## Variable Documentation

CommandCallback* const _callback_table[]`[static]`

Initial value:

     {
       NULL,
       CcBuildPrimaryVehicle,
       CcBuildAirport,
       CcBuildBridge,
       CcBuildCanal,
       CcBuildDocks,
       CcFoundTown,
       CcBuildRoadTunnel,
       CcBuildRailTunnel,
       CcBuildWagon,
       CcRoadDepot,
       CcRailDepot,
       CcPlaceSign,
       CcPlaySound10,
       CcPlaySound1D,
       CcPlaySound1E,
       CcStation,
       CcTerraform,

       CcAI,

       CcCloneVehicle,
       CcGiveMoney,
       CcCreateGroup,
       CcFoundRandomTown,
    }

Table with all the callbacks we'll use for conversion.

Definition at line 22 of file network_command.cpp.

Referenced by NetworkClientSocket::Recv_Command(), and NetworkClientSocket::Send_Command().