14 #include "../stdafx.h" 18 #include "../command_func.h" 19 #include "../company_func.h" 20 #include "../settings_type.h" 22 #include "../safeguards.h" 30 CcPlaySound_SPLAT_WATER,
39 CcPlaySound_EXPLOSION,
40 CcPlaySound_SPLAT_OTHER,
41 CcPlaySound_SPLAT_RAIL,
66 if (this->
first == NULL) {
93 if (ret == this->
last) this->
last = prev_item;
119 while ((cp = this->
Pop()) != NULL) {
122 assert(this->
count == 0);
164 _local_wait_queue.
Append(&c);
188 cs->outgoing_queue.Append(&c);
202 while ((cp = queue.
Peek()) != NULL) {
205 if (_frame_counter < cp->frame)
break;
210 error(
"[net] Trying to execute a packet in the past!");
231 _local_wait_queue.
Free();
232 _local_execution_queue.
Free();
245 NetworkClientSocket *cs;
247 if (cs->status >= NetworkClientSocket::STATUS_MAP) {
250 cp.
callback = (cs != owner) ? NULL : callback;
251 cp.
my_cmd = (cs == owner);
252 cs->outgoing_queue.Append(&cp);
256 cp.
callback = (cs != owner) ? NULL : callback;
257 cp.
my_cmd = (cs == owner);
258 _local_execution_queue.
Append(&cp);
268 #ifdef DEBUG_DUMP_COMMANDS 270 int to_go = UINT16_MAX;
276 while (--to_go >= 0 && (cp = queue->
Pop(
true)) != NULL) {
290 NetworkClientSocket *cs;
342 DEBUG(net, 0,
"Unknown callback. (Pointer: %p) No callback sent", cp->
callback);
static void DistributeCommandPacket(CommandPacket &cp, const NetworkClientSocket *owner)
"Send" a particular CommandPacket to all clients.
void CcPlaceSign(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
Callback function that is called after a sign is placed.
static bool IsLocalCompany()
Is the current company the local company?
Internal entity of a packet.
CommandPacket * Pop(bool ignore_paused=false)
Return the first item in the queue and remove it from the queue.
uint32 Recv_uint32()
Read a 32 bits integer from the packet.
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 CcGame(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
DoCommand callback function for all commands executed by Game Scripts.
void Send_string(const char *data)
Sends a string over the network.
void NetworkExecuteLocalCommandQueue()
Execute all commands on the local command queue that ought to be executed this frame.
static CommandQueue _local_execution_queue
Local queue of packets waiting for execution.
void CcCreateGroup(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
Opens a 'Rename group' window for newly created group.
void Send_uint8(uint8 data)
Package a 8 bits integer in the packet.
Client part of the network protocol.
uint count
The number of items in the queue.
static CommandCallback *const _callback_table[]
Table with all the callbacks we'll use for conversion.
void Send_uint32(uint32 data)
Package a 32 bits integer in the packet.
void CcRoadStop(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
Command callback for building road stops.
uint16 commands_per_frame
how many commands may be sent each frame_freq frames?
#define lastof(x)
Get the last element of an fixed size array.
void Append(CommandPacket *p)
Append a CommandPacket at the end of the queue.
CommandFlags GetCommandFlags(uint32 cmd)
char text[32 *MAX_CHAR_LENGTH]
possible text sent for name changes etc, in bytes including '\0'.
CommandQueue incoming_queue
The command-queue awaiting handling.
bool IsValidCommand(uint32 cmd)
CompanyByte _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
void CcAI(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
DoCommand callback function for all commands executed by AIs.
void NetworkAdminCmdLogging(const NetworkClientSocket *owner, const CommandPacket *cp)
Distribute CommandPacket details over the admin network for logging purposes.
A queue of CommandPackets.
NetworkSettings network
settings related to the network
void CcBuildWagon(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
Callback for building wagons.
mask for all command flags
void NetworkSyncCommandQueue(NetworkClientSocket *cs)
Sync our local command queue to the command queue of the given socket.
void CcCloneVehicle(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
This is the Callback method after the cloning attempt of a vehicle.
Server part of the network protocol.
execute the command without sending it on the network
void CcBuildRoadTunnel(const CommandCost &result, TileIndex start_tile, uint32 p1, uint32 p2)
Callback executed after a build road tunnel command has been called.
void CcBuildIndustry(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
Command callback.
ClientSettings _settings_client
The current settings for this game.
CommandPacket * last
The last packet in the queue; only valid when first != NULL.
static ClientNetworkGameSocketHandler * my_client
This is us!
CommandPacket * first
The first packet in the queue.
bool DoCommandP(const CommandContainer *container, bool my_cmd)
Shortcut for the long DoCommandP when having a container with the data.
CompanyID company
company that is executing the command
void Free()
Free everything that is in the queue.
#define lengthof(x)
Return the length of an fixed size array.
PauseModeByte _pause_mode
The current pause mode.
#define FOR_ALL_CLIENT_SOCKETS(var)
Iterate over all the sockets.
uint32 frame
the frame in which this packet is executed
the command's string may contain control strings
CommandCallback * callback
any callback function executed upon successful completion of the command.
#define DEBUG(name, level,...)
Output a line of debugging information.
bool IsCommandAllowedWhilePaused(uint32 cmd)
Returns whether the command is allowed while the game is paused.
void NetworkFreeLocalCommandQueue()
Free the local command queues.
uint8 Recv_uint8()
Read a 8 bits integer from the packet.
void CcBuildBridge(const CommandCost &result, TileIndex end_tile, uint32 p1, uint32 p2)
Callback executed after a build Bridge CMD has been called.
uint32 _frame_counter
The current frame.
CompanyByte _current_company
Company currently doing an action.
uint32 TileIndex
The index/ID of a Tile.
Replace the unknown/bad bits with question marks.
void CDECL error(const char *s,...)
Error handling for fatal non-user errors.
void CcBuildPrimaryVehicle(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
This is the Callback method after the construction attempt of a primary vehicle.
char * strecpy(char *dst, const char *src, const char *last)
Copies characters from one buffer to another.
const char * ReceiveCommand(Packet *p, CommandPacket *cp)
Receives a command from the network.
bool _network_server
network-server is active
TileIndex tile
tile command being executed on.
void CcStartStopVehicle(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
This is the Callback method after attempting to start/stop a vehicle.
Everything we need to know about a command to be able to execute it.
Allow the special control codes.
void CommandCallback(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
Define a callback function for the client, after the command is finished.
the command cannot be executed in a multiplayer game; single-player only
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
void CcAddVehicleNewGroup(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
Open rename window after adding a vehicle to a new group via drag and drop.
CommandPacket * Peek(bool ignore_paused=false)
Return the first item in the queue, but don't remove it.
static NetworkRecvStatus SendCommand(const CommandPacket *cp)
Send a command to the server.
static CommandQueue _local_wait_queue
Local queue of packets waiting for handling.
void CcBuildRailTunnel(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
Command callback for building a tunnel.
Owner
Enum for all companies/owners.
void SendCommand(Packet *p, const CommandPacket *cp)
Sends a command over the network.
bool my_cmd
did the command originate from "me"
CommandPacket * next
the next command packet (if in queue)
void NetworkDistributeCommands()
Distribute the commands of ourself and the clients.
uint32 _frame_counter_max
To where we may go with our clients.
uint32 cmd
command being executed.
static void DistributeQueue(CommandQueue *queue, const NetworkClientSocket *owner)
"Send" a particular CommandQueue to all clients.
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.
Server part of the admin network protocol.