Include client IDs in network server command logs
This commit is contained in:
@@ -536,6 +536,7 @@ static const Command _command_proc_table[] = {
|
||||
DEF_CMD(CmdDesyncCheck, CMD_SERVER, CMDT_SERVER_SETTING ), // CMD_DESYNC_CHECK
|
||||
};
|
||||
|
||||
ClientID _cmd_client_id = INVALID_CLIENT_ID;
|
||||
|
||||
/**
|
||||
* List of flags for a command log entry
|
||||
@@ -569,12 +570,13 @@ struct CommandLogEntry {
|
||||
CompanyID current_company;
|
||||
CompanyID local_company;
|
||||
CommandLogEntryFlag log_flags;
|
||||
ClientID client_id;
|
||||
|
||||
CommandLogEntry() { }
|
||||
|
||||
CommandLogEntry(TileIndex tile, uint32 p1, uint32 p2, uint64 p3, uint32 cmd, CommandLogEntryFlag log_flags, std::string text)
|
||||
: text(text), tile(tile), p1(p1), p2(p2), cmd(cmd), p3(p3), date(_date), date_fract(_date_fract), tick_skip_counter(_tick_skip_counter),
|
||||
current_company(_current_company), local_company(_local_company), log_flags(log_flags) { }
|
||||
current_company(_current_company), local_company(_local_company), log_flags(log_flags), client_id(_cmd_client_id) { }
|
||||
};
|
||||
|
||||
struct CommandLog {
|
||||
@@ -631,8 +633,11 @@ static void DumpSubCommandLog(char *&buffer, const char *last, const CommandLog
|
||||
if (entry.p3 != 0) {
|
||||
buffer += seprintf(buffer, last, "p3: 0x" OTTD_PRINTFHEX64PAD ", ", entry.p3);
|
||||
}
|
||||
buffer += seprintf(buffer, last, "cc: %3u, lc: %3u, cmd: 0x%08X (%s)",
|
||||
(uint) entry.current_company, (uint) entry.local_company, entry.cmd, GetCommandName(entry.cmd));
|
||||
buffer += seprintf(buffer, last, "cc: %3u, lc: %3u, ", (uint) entry.current_company, (uint) entry.local_company);
|
||||
if (_network_server) {
|
||||
buffer += seprintf(buffer, last, "client: %4u, ", entry.client_id);
|
||||
}
|
||||
buffer += seprintf(buffer, last, "cmd: 0x%08X (%s)", entry.cmd, GetCommandName(entry.cmd));
|
||||
|
||||
switch (entry.cmd & CMD_ID_MASK) {
|
||||
case CMD_CHANGE_SETTING:
|
||||
|
@@ -212,6 +212,7 @@ void NetworkSyncCommandQueue(NetworkClientSocket *cs)
|
||||
*/
|
||||
void NetworkExecuteLocalCommandQueue()
|
||||
{
|
||||
extern ClientID _cmd_client_id;
|
||||
assert(IsLocalCompany());
|
||||
|
||||
CommandQueue &queue = (_network_server ? _local_execution_queue : ClientNetworkGameSocketHandler::my_client->incoming_queue);
|
||||
@@ -230,6 +231,7 @@ void NetworkExecuteLocalCommandQueue()
|
||||
|
||||
/* We can execute this command */
|
||||
_current_company = cp->company;
|
||||
_cmd_client_id = cp->client_id;
|
||||
cp->cmd |= CMD_NETWORK_COMMAND;
|
||||
DoCommandP(cp, cp->my_cmd);
|
||||
|
||||
@@ -238,6 +240,7 @@ void NetworkExecuteLocalCommandQueue()
|
||||
|
||||
/* Local company may have changed, so we should not restore the old value */
|
||||
_current_company = _local_company;
|
||||
_cmd_client_id = INVALID_CLIENT_ID;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -113,10 +113,11 @@ void UpdateNetworkGameWindow();
|
||||
*/
|
||||
struct CommandPacket : CommandContainer {
|
||||
/** Make sure the pointer is nullptr. */
|
||||
CommandPacket() : next(nullptr), company(INVALID_COMPANY), frame(0), my_cmd(false) {}
|
||||
CommandPacket() : next(nullptr), frame(0), client_id(INVALID_CLIENT_ID), company(INVALID_COMPANY), 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
|
||||
ClientID client_id; ///< originating client ID (or INVALID_CLIENT_ID if not specified)
|
||||
CompanyID company; ///< company that is executing the command
|
||||
bool my_cmd; ///< did the command originate from "me"
|
||||
};
|
||||
|
||||
|
@@ -1157,6 +1157,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_COMMAND(Packet
|
||||
}
|
||||
|
||||
if (GetCommandFlags(cp.cmd) & CMD_CLIENT_ID) cp.p2 = this->client_id;
|
||||
cp.client_id = this->client_id;
|
||||
|
||||
this->incoming_queue.Append(std::move(cp));
|
||||
return NETWORK_RECV_STATUS_OKAY;
|
||||
|
Reference in New Issue
Block a user