Fix: Don't send unused tile field over the network (#10507)

This commit is contained in:
dP
2023-02-25 01:50:11 +04:00
committed by GitHub
parent 9b3326e3fd
commit c73b88ddca
18 changed files with 60 additions and 78 deletions

View File

@@ -261,17 +261,15 @@ static size_t FindCallbackIndex(CommandCallback *callback)
* @param err_message Message prefix to show on error
* @param callback A callback function to call after the command is finished
* @param company The company that wants to send the command
* @param location Location of the command (e.g. for error message position)
* @param cmd_data The command proc arguments.
*/
void NetworkSendCommand(Commands cmd, StringID err_message, CommandCallback *callback, CompanyID company, TileIndex location, const CommandDataBuffer &cmd_data)
void NetworkSendCommand(Commands cmd, StringID err_message, CommandCallback *callback, CompanyID company, const CommandDataBuffer &cmd_data)
{
CommandPacket c;
c.company = company;
c.cmd = cmd;
c.err_msg = err_message;
c.callback = callback;
c.tile = location;
c.data = cmd_data;
if (_network_server) {
@@ -429,7 +427,6 @@ const char *NetworkGameSocketHandler::ReceiveCommand(Packet *p, CommandPacket *c
if (!IsValidCommand(cp->cmd)) return "invalid command";
if (GetCommandFlags(cp->cmd) & CMD_OFFLINE) return "single-player only command";
cp->err_msg = p->Recv_uint16();
cp->tile = p->Recv_uint32();
cp->data = _cmd_dispatch[cp->cmd].Sanitize(p->Recv_buffer());
byte callback = p->Recv_uint8();
@@ -449,7 +446,6 @@ void NetworkGameSocketHandler::SendCommand(Packet *p, const CommandPacket *cp)
p->Send_uint8(cp->company);
p->Send_uint16(cp->cmd);
p->Send_uint16(cp->err_msg);
p->Send_uint32(cp->tile);
p->Send_buffer(cp->data);
size_t callback = FindCallbackIndex(cp->callback);
@@ -540,5 +536,5 @@ template <Commands Tcmd, size_t Tcb>
void UnpackNetworkCommand(const CommandPacket* cp)
{
auto args = EndianBufferReader::ToValue<typename CommandTraits<Tcmd>::Args>(cp->data);
Command<Tcmd>::PostFromNet(cp->err_msg, std::get<Tcb>(_callback_tuple), cp->my_cmd, cp->tile, args);
Command<Tcmd>::PostFromNet(cp->err_msg, std::get<Tcb>(_callback_tuple), cp->my_cmd, args);
}

View File

@@ -108,7 +108,7 @@ void UpdateNetworkGameWindow();
*/
struct CommandPacket {
/** Make sure the pointer is nullptr. */
CommandPacket() : next(nullptr), company(INVALID_COMPANY), frame(0), my_cmd(false), tile(0) {}
CommandPacket() : next(nullptr), company(INVALID_COMPANY), frame(0), my_cmd(false) {}
CommandPacket *next; ///< the next command packet (if in queue)
CompanyID company; ///< company that is executing the command
uint32 frame; ///< the frame in which this packet is executed
@@ -117,7 +117,6 @@ struct CommandPacket {
Commands cmd; ///< command being executed.
StringID err_msg; ///< string ID of error message to use.
CommandCallback *callback; ///< any callback function executed upon successful completion of the command.
TileIndex tile; ///< location of the command (for e.g. error message or effect display).
CommandDataBuffer data; ///< command parameters.
};