OpenTTD Source: src/network/network_command.cpp File Reference

OpenTTD Source 12.2

Functions | Variables
network_command.cpp File Reference
`#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 std::string &text, CompanyID company)
| Prepare a DoCommand to be send over the network. More...
void | NetworkSyncCommandQueue (NetworkClientSocket *cs)
| Sync our local command queue to the command queue of the given socket. More...
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. More...
static void | DistributeQueue (CommandQueue *queue, const NetworkClientSocket *owner)
| "Send" a particular CommandQueue to all clients. More...
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. More...
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

## ◆ DistributeCommandPacket()

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 235 of file network_command.cpp.

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

## ◆ 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 260 of file network_command.cpp.

Referenced by NetworkDistributeCommands().

## ◆ NetworkSendCommand()

void NetworkSendCommand | ( | TileIndex | tile,
|  | uint32 | p1,
|  | uint32 | p2,
|  | uint32 | cmd,
|  | CommandCallback * | callback,
|  | const std::string & | 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 136 of file network_command.cpp.

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

Referenced by NetworkServerNewCompany(), and NetworkClientListWindow::OnClickCompanyNew().

## ◆ NetworkSyncCommandQueue()

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 178 of file network_command.cpp.

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

## Variable Documentation

## ◆ _callback_table

CommandCallback* const _callback_table[]
| static

Initial value:
= {
nullptr,
CcBuildPrimaryVehicle,
CcBuildAirport,
CcBuildBridge,
CcPlaySound_CONSTRUCTION_WATER,
CcBuildDocks,
CcFoundTown,
CcBuildRoadTunnel,
CcBuildRailTunnel,
CcBuildWagon,
CcRoadDepot,
CcRailDepot,
CcPlaceSign,
CcPlaySound_EXPLOSION,
CcPlaySound_CONSTRUCTION_OTHER,
CcPlaySound_CONSTRUCTION_RAIL,
CcStation,
CcTerraform,
CcAI,
CcCloneVehicle,
nullptr,
CcCreateGroup,
CcFoundRandomTown,
CcRoadStop,
CcBuildIndustry,
CcStartStopVehicle,
CcGame,
CcAddVehicleNewGroup,
}

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

Definition at line 21 of file network_command.cpp.

Referenced by NetworkGameSocketHandler::SendCommand().

CcBuildPrimaryVehicle
void CcBuildPrimaryVehicle(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
This is the Callback method after the construction attempt of a primary vehicle.
Definition: vehicle_gui.cpp:3123
CcRoadStop
void CcRoadStop(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
Command callback for building road stops.
Definition: road_gui.cpp:158
CcStartStopVehicle
void CcStartStopVehicle(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
This is the Callback method after attempting to start/stop a vehicle.
Definition: vehicle_gui.cpp:2622
CcBuildBridge
void CcBuildBridge(const CommandCost &result, TileIndex end_tile, uint32 p1, uint32 p2, uint32 cmd)
Callback executed after a build Bridge CMD has been called.
Definition: bridge_gui.cpp:61
CcAddVehicleNewGroup
void CcAddVehicleNewGroup(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
Open rename window after adding a vehicle to a new group via drag and drop.
Definition: group_gui.cpp:1166
CcCreateGroup
void CcCreateGroup(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
Opens a 'Rename group' window for newly created group.
Definition: group_gui.cpp:1149
CcBuildIndustry
void CcBuildIndustry(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
Command callback.
Definition: industry_gui.cpp:227
CcPlaceSign
void CcPlaceSign(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
Callback function that is called after a sign is placed.
Definition: signs_cmd.cpp:117
CcGame
void CcGame(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
DoCommand callback function for all commands executed by Game Scripts.
Definition: game_instance.cpp:90
CcBuildWagon
void CcBuildWagon(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
Callback for building wagons.
Definition: train_gui.cpp:30
CcBuildRailTunnel
void CcBuildRailTunnel(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
Command callback for building a tunnel.
Definition: rail_gui.cpp:281
CcCloneVehicle
void CcCloneVehicle(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
This is the Callback method after the cloning attempt of a vehicle.
Definition: depot_gui.cpp:120
CcAI
void CcAI(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
DoCommand callback function for all commands executed by AIs.
Definition: ai_instance.cpp:101
CcBuildRoadTunnel
void CcBuildRoadTunnel(const CommandCost &result, TileIndex start_tile, uint32 p1, uint32 p2, uint32 cmd)
Callback executed after a build road tunnel command has been called.
Definition: road_gui.cpp:99