mirror of https://github.com/OpenTTD/OpenTTD
Fix: Compilation with DEBUG_DUMP_COMMANDS enabled (#11607)
parent
49db7bbe08
commit
1e60734660
|
@ -272,9 +272,9 @@ void CommandHelperBase::InternalPostResult(const CommandCost &res, TileIndex til
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Helper to make a desync log for a command. */
|
/** Helper to make a desync log for a command. */
|
||||||
void CommandHelperBase::LogCommandExecution(Commands cmd, StringID err_message, TileIndex tile, const CommandDataBuffer &args, bool failed)
|
void CommandHelperBase::LogCommandExecution(Commands cmd, StringID err_message, const CommandDataBuffer &args, bool failed)
|
||||||
{
|
{
|
||||||
Debug(desync, 1, "{}: {:08x}; {:02x}; {:02x}; {:08x}; {:08x}; {:06x}; {} ({})", failed ? "cmdf" : "cmd", TimerGameCalendar::date, TimerGameCalendar::date_fract, (int)_current_company, cmd, err_message, tile, FormatArrayAsHex(args), GetCommandName(cmd));
|
Debug(desync, 1, "{}: {:08x}; {:02x}; {:02x}; {:08x}; {:08x}; {} ({})", failed ? "cmdf" : "cmd", (uint32_t)TimerGameCalendar::date.base(), TimerGameCalendar::date_fract, (int)_current_company, cmd, err_message, FormatArrayAsHex(args), GetCommandName(cmd));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -102,7 +102,7 @@ protected:
|
||||||
static bool InternalExecutePrepTest(CommandFlags cmd_flags, TileIndex tile, Backup<CompanyID> &cur_company);
|
static bool InternalExecutePrepTest(CommandFlags cmd_flags, TileIndex tile, Backup<CompanyID> &cur_company);
|
||||||
static std::tuple<bool, bool, bool> InternalExecuteValidateTestAndPrepExec(CommandCost &res, CommandFlags cmd_flags, bool estimate_only, bool network_command, Backup<CompanyID> &cur_company);
|
static std::tuple<bool, bool, bool> InternalExecuteValidateTestAndPrepExec(CommandCost &res, CommandFlags cmd_flags, bool estimate_only, bool network_command, Backup<CompanyID> &cur_company);
|
||||||
static CommandCost InternalExecuteProcessResult(Commands cmd, CommandFlags cmd_flags, const CommandCost &res_test, const CommandCost &res_exec, Money extra_cash, TileIndex tile, Backup<CompanyID> &cur_company);
|
static CommandCost InternalExecuteProcessResult(Commands cmd, CommandFlags cmd_flags, const CommandCost &res_test, const CommandCost &res_exec, Money extra_cash, TileIndex tile, Backup<CompanyID> &cur_company);
|
||||||
static void LogCommandExecution(Commands cmd, StringID err_message, TileIndex tile, const CommandDataBuffer &args, bool failed);
|
static void LogCommandExecution(Commands cmd, StringID err_message, const CommandDataBuffer &args, bool failed);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -385,7 +385,7 @@ protected:
|
||||||
|
|
||||||
auto [exit_test, desync_log, send_net] = InternalExecuteValidateTestAndPrepExec(ExtractCommandCost(res), cmd_flags, estimate_only, network_command, cur_company);
|
auto [exit_test, desync_log, send_net] = InternalExecuteValidateTestAndPrepExec(ExtractCommandCost(res), cmd_flags, estimate_only, network_command, cur_company);
|
||||||
if (exit_test) {
|
if (exit_test) {
|
||||||
if (desync_log) LogCommandExecution(Tcmd, err_message, tile, EndianBufferWriter<CommandDataBuffer>::FromValue(args), true);
|
if (desync_log) LogCommandExecution(Tcmd, err_message, EndianBufferWriter<CommandDataBuffer>::FromValue(args), true);
|
||||||
cur_company.Restore();
|
cur_company.Restore();
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -403,7 +403,7 @@ protected:
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (desync_log) LogCommandExecution(Tcmd, err_message, tile, EndianBufferWriter<CommandDataBuffer>::FromValue(args), false);
|
if (desync_log) LogCommandExecution(Tcmd, err_message, EndianBufferWriter<CommandDataBuffer>::FromValue(args), false);
|
||||||
|
|
||||||
/* Actually try and execute the command. */
|
/* Actually try and execute the command. */
|
||||||
Tret res2 = std::apply(CommandTraits<Tcmd>::proc, std::tuple_cat(std::make_tuple(flags | DC_EXEC), args));
|
Tret res2 = std::apply(CommandTraits<Tcmd>::proc, std::tuple_cat(std::make_tuple(flags | DC_EXEC), args));
|
||||||
|
|
|
@ -1055,21 +1055,21 @@ void NetworkGameLoop()
|
||||||
#ifdef DEBUG_DUMP_COMMANDS
|
#ifdef DEBUG_DUMP_COMMANDS
|
||||||
/* Loading of the debug commands from -ddesync>=1 */
|
/* Loading of the debug commands from -ddesync>=1 */
|
||||||
static FILE *f = FioFOpenFile("commands.log", "rb", SAVE_DIR);
|
static FILE *f = FioFOpenFile("commands.log", "rb", SAVE_DIR);
|
||||||
static Date next_date = 0;
|
static TimerGameCalendar::Date next_date(0);
|
||||||
static uint32_t next_date_fract;
|
static uint32_t next_date_fract;
|
||||||
static CommandPacket *cp = nullptr;
|
static CommandPacket *cp = nullptr;
|
||||||
static bool check_sync_state = false;
|
static bool check_sync_state = false;
|
||||||
static uint32_t sync_state[2];
|
static uint32_t sync_state[2];
|
||||||
if (f == nullptr && next_date == 0) {
|
if (f == nullptr && next_date == 0) {
|
||||||
Debug(desync, 0, "Cannot open commands.log");
|
Debug(desync, 0, "Cannot open commands.log");
|
||||||
next_date = 1;
|
next_date = TimerGameCalendar::Date(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (f != nullptr && !feof(f)) {
|
while (f != nullptr && !feof(f)) {
|
||||||
if (TimerGameCalendar::date == next_date && TimerGameCalendar::date_fract == next_date_fract) {
|
if (TimerGameCalendar::date == next_date && TimerGameCalendar::date_fract == next_date_fract) {
|
||||||
if (cp != nullptr) {
|
if (cp != nullptr) {
|
||||||
NetworkSendCommand(cp->cmd, cp->err_msg, nullptr, cp->company, cp->data);
|
NetworkSendCommand(cp->cmd, cp->err_msg, nullptr, cp->company, cp->data);
|
||||||
Debug(desync, 0, "Injecting: {:08x}; {:02x}; {:02x}; {:08x}; {:06x}; {} ({})", TimerGameCalendar::date, TimerGameCalendar::date_fract, (int)_current_company, cp->cmd, cp->tile, FormatArrayAsHex(cp->data), GetCommandName(cp->cmd));
|
Debug(desync, 0, "Injecting: {:08x}; {:02x}; {:02x}; {:08x}; {} ({})", TimerGameCalendar::date, TimerGameCalendar::date_fract, (int)_current_company, cp->cmd, FormatArrayAsHex(cp->data), GetCommandName(cp->cmd));
|
||||||
delete cp;
|
delete cp;
|
||||||
cp = nullptr;
|
cp = nullptr;
|
||||||
}
|
}
|
||||||
|
@ -1109,8 +1109,10 @@ void NetworkGameLoop()
|
||||||
int company;
|
int company;
|
||||||
uint cmd;
|
uint cmd;
|
||||||
char buffer[256];
|
char buffer[256];
|
||||||
int ret = sscanf(p, "%x; %x; %x; %x; %x; %x; %255s", &next_date, &next_date_fract, &company, &cmd, &cp->err_msg, &cp->tile, buffer);
|
uint32_t next_date_raw;
|
||||||
|
int ret = sscanf(p, "%x; %x; %x; %x; %x; %255s", &next_date_raw, &next_date_fract, &company, &cmd, &cp->err_msg, buffer);
|
||||||
assert(ret == 6);
|
assert(ret == 6);
|
||||||
|
next_date = TimerGameCalendar::Date((int32_t)next_date_raw);
|
||||||
cp->company = (CompanyID)company;
|
cp->company = (CompanyID)company;
|
||||||
cp->cmd = (Commands)cmd;
|
cp->cmd = (Commands)cmd;
|
||||||
|
|
||||||
|
@ -1119,13 +1121,15 @@ void NetworkGameLoop()
|
||||||
size_t arg_len = strlen(buffer);
|
size_t arg_len = strlen(buffer);
|
||||||
for (size_t i = 0; i + 1 < arg_len; i += 2) {
|
for (size_t i = 0; i + 1 < arg_len; i += 2) {
|
||||||
byte e = 0;
|
byte e = 0;
|
||||||
std::from_chars(buffer + i, buffer + i + 1, e, 16);
|
std::from_chars(buffer + i, buffer + i + 2, e, 16);
|
||||||
args.emplace_back(e);
|
args.emplace_back(e);
|
||||||
}
|
}
|
||||||
cp->data = args;
|
cp->data = args;
|
||||||
} else if (strncmp(p, "join: ", 6) == 0) {
|
} else if (strncmp(p, "join: ", 6) == 0) {
|
||||||
/* Manually insert a pause when joining; this way the client can join at the exact right time. */
|
/* Manually insert a pause when joining; this way the client can join at the exact right time. */
|
||||||
int ret = sscanf(p + 6, "%x; %x", &next_date, &next_date_fract);
|
uint32_t next_date_raw;
|
||||||
|
int ret = sscanf(p + 6, "%x; %x", &next_date_raw, &next_date_fract);
|
||||||
|
next_date = TimerGameCalendar::Date((int32_t)next_date_raw);
|
||||||
assert(ret == 2);
|
assert(ret == 2);
|
||||||
Debug(desync, 0, "Injecting pause for join at {:08x}:{:02x}; please join when paused", next_date, next_date_fract);
|
Debug(desync, 0, "Injecting pause for join at {:08x}:{:02x}; please join when paused", next_date, next_date_fract);
|
||||||
cp = new CommandPacket();
|
cp = new CommandPacket();
|
||||||
|
@ -1134,7 +1138,9 @@ void NetworkGameLoop()
|
||||||
cp->data = EndianBufferWriter<>::FromValue(CommandTraits<CMD_PAUSE>::Args{ PM_PAUSED_NORMAL, true });
|
cp->data = EndianBufferWriter<>::FromValue(CommandTraits<CMD_PAUSE>::Args{ PM_PAUSED_NORMAL, true });
|
||||||
_ddc_fastforward = false;
|
_ddc_fastforward = false;
|
||||||
} else if (strncmp(p, "sync: ", 6) == 0) {
|
} else if (strncmp(p, "sync: ", 6) == 0) {
|
||||||
int ret = sscanf(p + 6, "%x; %x; %x; %x", &next_date, &next_date_fract, &sync_state[0], &sync_state[1]);
|
uint32_t next_date_raw;
|
||||||
|
int ret = sscanf(p + 6, "%x; %x; %x; %x", &next_date_raw, &next_date_fract, &sync_state[0], &sync_state[1]);
|
||||||
|
next_date = TimerGameCalendar::Date((int32_t)next_date_raw);
|
||||||
assert(ret == 4);
|
assert(ret == 4);
|
||||||
check_sync_state = true;
|
check_sync_state = true;
|
||||||
} else if (strncmp(p, "msg: ", 5) == 0 || strncmp(p, "client: ", 8) == 0 ||
|
} else if (strncmp(p, "msg: ", 5) == 0 || strncmp(p, "client: ", 8) == 0 ||
|
||||||
|
|
Loading…
Reference in New Issue