OpenTTD Source
1.11.0-beta2
|
Go to the documentation of this file.
10 #include "../stdafx.h"
14 #include "../command_func.h"
15 #include "../company_func.h"
16 #include "../settings_type.h"
18 #include "../safeguards.h"
26 CcPlaySound_CONSTRUCTION_WATER,
35 CcPlaySound_EXPLOSION,
36 CcPlaySound_CONSTRUCTION_OTHER,
37 CcPlaySound_CONSTRUCTION_RAIL,
62 if (this->
first ==
nullptr) {
89 if (ret == this->
last) this->
last = prev_item;
115 while ((cp = this->
Pop()) !=
nullptr) {
118 assert(this->
count == 0);
184 cs->outgoing_queue.Append(&c);
198 while ((cp = queue.
Peek()) !=
nullptr) {
201 if (_frame_counter < cp->frame)
break;
206 error(
"[net] Trying to execute a packet in the past!");
241 for (NetworkClientSocket *cs : NetworkClientSocket::Iterate()) {
242 if (cs->status >= NetworkClientSocket::STATUS_MAP) {
245 cp.
callback = (cs != owner) ?
nullptr : callback;
246 cp.
my_cmd = (cs == owner);
247 cs->outgoing_queue.Append(&cp);
251 cp.
callback = (
nullptr != owner) ?
nullptr : callback;
252 cp.
my_cmd = (
nullptr == owner);
263 #ifdef DEBUG_DUMP_COMMANDS
265 int to_go = UINT16_MAX;
271 while (--to_go >= 0 && (cp = queue->
Pop(
true)) !=
nullptr) {
285 for (NetworkClientSocket *cs : NetworkClientSocket::Iterate()) {
336 DEBUG(net, 0,
"Unknown callback. (Pointer: %p) No callback sent", cp->
callback);
CommandPacket * last
The last packet in the queue; only valid when first != nullptr.
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.
uint32 TileIndex
The index/ID of a Tile.
uint32 cmd
command being executed.
uint32 _frame_counter
The current frame.
static CommandQueue _local_wait_queue
Local queue of packets waiting for handling.
void Recv_string(char *buffer, size_t size, StringValidationSettings settings=SVS_REPLACE_WITH_QUESTION_MARK)
Reads a string till it finds a '\0' in the stream.
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.
@ CMD_OFFLINE
the command cannot be executed in a multiplayer game; single-player only
static CommandCallback *const _callback_table[]
Table with all the callbacks we'll use for conversion.
bool _network_server
network-server is active
uint32 frame
the frame in which this packet is executed
static CommandQueue _local_execution_queue
Local queue of packets waiting for execution.
void CcRoadStop(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
Command callback for building road stops.
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.
void CommandCallback(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
Define a callback function for the client, after the command is finished.
char text[32 *MAX_CHAR_LENGTH]
possible text sent for name changes etc, in bytes including '\0'.
ClientSettings _settings_client
The current settings for this game.
void NetworkSyncCommandQueue(NetworkClientSocket *cs)
Sync our local command queue to the command queue of the given socket.
static ClientNetworkGameSocketHandler * my_client
This is us!
CommandPacket * next
the next command packet (if in queue)
static void DistributeCommandPacket(CommandPacket &cp, const NetworkClientSocket *owner)
"Send" a particular CommandPacket to all clients.
Owner
Enum for all companies/owners.
bool IsCommandAllowedWhilePaused(uint32 cmd)
Returns whether the command is allowed while the game is paused.
void Send_uint8(uint8 data)
Package a 8 bits integer in the packet.
static bool IsLocalCompany()
Is the current company the local company?
uint32 _frame_counter_max
To where we may go with our clients.
void Send_uint32(uint32 data)
Package a 32 bits integer in the packet.
void CcBuildBridge(const CommandCost &result, TileIndex end_tile, uint32 p1, uint32 p2, uint32 cmd)
Callback executed after a build Bridge CMD has been called.
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.
@ PM_UNPAUSED
A normal unpaused game.
void Append(CommandPacket *p)
Append a CommandPacket at the end of the queue.
bool IsValidCommand(uint32 cmd)
CompanyID company
company that is executing the command
void CcCreateGroup(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
Opens a 'Rename group' window for newly created group.
@ SVS_ALLOW_CONTROL_CODE
Allow the special control codes.
void CcBuildIndustry(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
Command callback.
uint32 Recv_uint32()
Read a 32 bits integer from the packet.
Everything we need to know about a command to be able to execute it.
bool DoCommandP(const CommandContainer *container, bool my_cmd)
Shortcut for the long DoCommandP when having a container with the data.
void CcPlaceSign(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
Callback function that is called after a sign is placed.
#define DEBUG(name, level,...)
Output a line of debugging information.
void Send_string(const char *data)
Sends a string over the network.
PauseMode _pause_mode
The current pause mode.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
A queue of CommandPackets.
void CcGame(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
DoCommand callback function for all commands executed by Game Scripts.
bool my_cmd
did the command originate from "me"
@ CMD_FLAGS_MASK
mask for all command flags
Internal entity of a packet.
const char * ReceiveCommand(Packet *p, CommandPacket *cp)
Receives a command from the network.
CommandFlags GetCommandFlags(uint32 cmd)
void CcBuildWagon(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
Callback for building wagons.
CommandCallback * callback
any callback function executed upon successful completion of the command.
CommandPacket * first
The first packet in the queue.
CompanyID _current_company
Company currently doing an action.
@ CMD_NETWORK_COMMAND
execute the command without sending it on the network
static NetworkRecvStatus SendCommand(const CommandPacket *cp)
Send a command to the server.
void Free()
Free everything that is in the queue.
uint count
The number of items in the queue.
uint8 Recv_uint8()
Read a 8 bits integer from the packet.
void CcBuildRailTunnel(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
Command callback for building a tunnel.
CommandQueue incoming_queue
The command-queue awaiting handling.
void CDECL error(const char *s,...)
Error handling for fatal non-user errors.
uint16 commands_per_frame
how many commands may be sent each frame_freq frames?
CommandPacket * Peek(bool ignore_paused=false)
Return the first item in the queue, but don't remove it.
#define lengthof(x)
Return the length of an fixed size array.
NetworkSettings network
settings related to the network
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.
void SendCommand(Packet *p, const CommandPacket *cp)
Sends a command over the network.
void CcAI(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
DoCommand callback function for all commands executed by AIs.
void NetworkExecuteLocalCommandQueue()
Execute all commands on the local command queue that ought to be executed this frame.
void NetworkAdminCmdLogging(const NetworkClientSocket *owner, const CommandPacket *cp)
Distribute CommandPacket details over the admin network for logging purposes.
TileIndex tile
tile command being executed on.
@ CMD_STR_CTRL
the command's string may contain control strings
char * strecpy(char *dst, const char *src, const char *last)
Copies characters from one buffer to another.
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
void NetworkFreeLocalCommandQueue()
Free the local command queues.
#define lastof(x)
Get the last element of an fixed size array.
@ SVS_REPLACE_WITH_QUESTION_MARK
Replace the unknown/bad bits with question marks.
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.
void NetworkDistributeCommands()
Distribute the commands of ourself and the clients.
static void DistributeQueue(CommandQueue *queue, const NetworkClientSocket *owner)
"Send" a particular CommandQueue to all clients.
CommandPacket * Pop(bool ignore_paused=false)
Return the first item in the queue and remove it from the queue.