From ef991b1772f5f8b4874f76ea715a9a95811ad979 Mon Sep 17 00:00:00 2001 From: rubidium42 Date: Sat, 29 May 2021 16:16:51 +0200 Subject: Codechange: [Network] Use std::string in CommandPacket --- src/network/network.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/network/network.cpp') diff --git a/src/network/network.cpp b/src/network/network.cpp index 94a5539f0..2bc358944 100644 --- a/src/network/network.cpp +++ b/src/network/network.cpp @@ -1071,7 +1071,7 @@ void NetworkGameLoop() if (_date == next_date && _date_fract == next_date_fract) { if (cp != nullptr) { NetworkSendCommand(cp->tile, cp->p1, cp->p2, cp->cmd & ~CMD_FLAGS_MASK, nullptr, cp->text, cp->company); - DEBUG(desync, 0, "Injecting: %08x; %02x; %02x; %06x; %08x; %08x; %08x; \"%s\" (%s)", _date, _date_fract, (int)_current_company, cp->tile, cp->p1, cp->p2, cp->cmd, cp->text, GetCommandName(cp->cmd)); + DEBUG(desync, 0, "Injecting: %08x; %02x; %02x; %06x; %08x; %08x; %08x; \"%s\" (%s)", _date, _date_fract, (int)_current_company, cp->tile, cp->p1, cp->p2, cp->cmd, cp->text.c_str(), GetCommandName(cp->cmd)); free(cp); cp = nullptr; } @@ -1107,10 +1107,11 @@ void NetworkGameLoop() ) { p += 5; if (*p == ' ') p++; - cp = CallocT(1); + cp = new CommandPacket(); int company; - static_assert(sizeof(cp->text) == 128); - int ret = sscanf(p, "%x; %x; %x; %x; %x; %x; %x; \"%127[^\"]\"", &next_date, &next_date_fract, &company, &cp->tile, &cp->p1, &cp->p2, &cp->cmd, cp->text); + char buffer[128]; + int ret = sscanf(p, "%x; %x; %x; %x; %x; %x; %x; \"%127[^\"]\"", &next_date, &next_date_fract, &company, &cp->tile, &cp->p1, &cp->p2, &cp->cmd, buffer); + cp->text = buffer; /* There are 8 pieces of data to read, however the last is a * string that might or might not exist. Ignore it if that * string misses because in 99% of the time it's not used. */ @@ -1121,7 +1122,7 @@ void NetworkGameLoop() int ret = sscanf(p + 6, "%x; %x", &next_date, &next_date_fract); assert(ret == 2); DEBUG(desync, 0, "Injecting pause for join at %08x:%02x; please join when paused", next_date, next_date_fract); - cp = CallocT(1); + cp = new CommandPacket(); cp->company = COMPANY_SPECTATOR; cp->cmd = CMD_PAUSE; cp->p1 = PM_PAUSED_NORMAL; -- cgit v1.2.3-54-g00ecf