OpenTTD: src/network/network_command.cpp File Reference

OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

Functions | Variables
network_command.cpp File Reference

Command handling over network connections. More...

`#include "../stdafx.h"`
`#include "network_admin.h"`
`#include "network_client.h"`
`#include "network_server.h"`
`#include "../command_func.h"`
`#include "../company_func.h"`
`#include "../settings_type.h"`
`#include "../safeguards.h"`

Go to the source code of this file.

## Functions
void | NetworkSendCommand (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 queues.
static void | DistributeCommandPacket (CommandPacket &cp, const NetworkClientSocket *owner)
| "Send" a particular CommandPacket to all clients.
static void | DistributeQueue (CommandQueue *queue, const NetworkClientSocket *owner)
| "Send" a particular CommandQueue to all clients.
void | NetworkDistributeCommands ()
| Distribute the commands of ourself and the clients.

## Variables
static CommandCallback *const | _callback_table []
| Table with all the callbacks we'll use for conversion.
static CommandQueue | _local_wait_queue
| Local queue of packets waiting for handling.
static CommandQueue | _local_execution_queue
| Local queue of packets waiting for execution.

## Detailed Description

Command handling over network connections.

Definition in file network_command.cpp.

## Function Documentation

static void DistributeCommandPacket | ( | CommandPacket & | cp,
|  | const NetworkClientSocket * | owner
| ) |  |
| static

"Send" a particular CommandPacket to all clients.

Parameters

  cp | The command that has to be distributed.
  owner | The client that owns the command,

Definition at line 240 of file network_command.cpp.

References _frame_counter_max, CommandQueue::Append(), CommandContainer::callback, FOR_ALL_CLIENT_SOCKETS, CommandPacket::frame, and CommandPacket::my_cmd.

Referenced by DistributeQueue().

static void DistributeQueue | ( | CommandQueue * | queue,
|  | const NetworkClientSocket * | owner
| ) |  |
| static

"Send" a particular CommandQueue to all clients.

Parameters

  queue | The queue of commands that has to be distributed.
  owner | The client that owns the commands,

Definition at line 266 of file network_command.cpp.

References _settings_client, NetworkSettings::commands_per_frame, DistributeCommandPacket(), free(), ClientSettings::network, NetworkAdminCmdLogging(), and CommandQueue::Pop().

Referenced by NetworkDistributeCommands().

void NetworkDistributeCommands | ( |  | ) |

Distribute the commands of ourself and the clients.

Definition at line 284 of file network_command.cpp.

References DistributeQueue(), and FOR_ALL_CLIENT_SOCKETS.

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

Prepare a DoCommand to be send 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 140 of file network_command.cpp.

References _frame_counter_max, _network_server, CommandQueue::Append(), CommandContainer::callback, CommandContainer::cmd, CMD_FLAGS_MASK, CommandPacket::company, CommandPacket::frame, lastof, CommandPacket::my_cmd, CommandContainer::p1, CommandContainer::p2, ClientNetworkGameSocketHandler::SendCommand(), strecpy(), CommandContainer::text, and CommandContainer::tile.

Referenced by DoCommandPInternal(), MenuClickCompany(), NetworkServerNewCompany(), ClientNetworkGameSocketHandler::Receive_SERVER_MAP_DONE(), 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 183 of file network_command.cpp.

References CommandContainer::callback, CommandPacket::next, and CommandQueue::Peek().

Referenced by ServerNetworkGameSocketHandler::SendMap().

## 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,
CcRoadStop,
CcBuildIndustry,
CcStartStopVehicle,
CcGame,
CcAddVehicleNewGroup,
}

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

Definition at line 25 of file network_command.cpp.

Referenced by NetworkGameSocketHandler::ReceiveCommand(), and NetworkGameSocketHandler::SendCommand().

CommandQueue _local_execution_queue
| static

Local queue of packets waiting for execution.

Definition at line 128 of file network_command.cpp.

CommandQueue _local_wait_queue
| static

Local queue of packets waiting for handling.

Definition at line 126 of file network_command.cpp.