Skip to content
Permalink
Browse files

fix #6325

  • Loading branch information...
rtri
rtri committed Oct 18, 2019
1 parent f934e8e commit b10785d270b60e455add8e772b4cb722faa2d3ca
Showing with 30 additions and 19 deletions.
  1. +17 −8 rts/Game/SelectedUnitsHandler.cpp
  2. +13 −11 rts/Net/NetCommands.cpp
@@ -1033,26 +1033,35 @@ void CSelectedUnitsHandler::SendCommandsToUnits(const std::vector<int>& unitIDs,
sameCmdParamSize = 0xFFFF;
}

unsigned int psize = ((sameCmdID == 0) ? 4 : 0) + ((sameCmdOpt == 0xFF) ? 1 : 0) + ((sameCmdParamSize == 0xFFFF) ? 2 : 0);
unsigned int psize = 4 * (sameCmdID == 0) + (sameCmdOpt == 0xFF) + (2 * (sameCmdParamSize == 0xFFFF));
unsigned int msgLen = 0;

msgLen += (1 + 2 + 1 + 1 + 1 + 4 + 1 + 2); // msg type, msg size, player ID, AI ID, pairwise, sameCmdID, sameCmdOpt, sameCmdParamSize
msgLen += 2; // unitID count
msgLen += unitIDCount * 2;
msgLen += 2; // command count
// msg type, msg size
msgLen += (sizeof(uint8_t) + sizeof(static_cast<uint16_t>(msgLen)));
// player ID, AI ID, pairwise
msgLen += (sizeof(uint8_t) * 2 + sizeof(pairwise));
msgLen += (sizeof(sameCmdID) + sizeof(sameCmdOpt) + static_cast<uint16_t>(sameCmdParamSize));

msgLen += sizeof(static_cast<uint16_t>(unitIDCount));
msgLen += (unitIDCount * sizeof(uint16_t));

msgLen += sizeof(static_cast<uint16_t>(commandCount));
msgLen += (commandCount * psize); // id, options, params size
msgLen += (totalParams * 4);
msgLen += (totalParams * sizeof(float));

if (msgLen > 8192) {
LOG_L(L_WARNING, "[%s] discarded oversized (len=%i) NETMSG_AICOMMANDS packet", __func__, msgLen);
return; // drop the oversized packet
return; // do not send oversized packets
}

netcode::PackPacket* packet = new netcode::PackPacket(msgLen);
*packet << static_cast<uint8_t>(NETMSG_AICOMMANDS)
<< static_cast<uint16_t>(msgLen)

<< static_cast<uint8_t>(gu->myPlayerNum)
<< MAX_AIS
<< static_cast<uint8_t>(MAX_AIS)
// << static_cast<uint8_t>(MAX_TEAMS)

<< static_cast<uint8_t>(pairwise)
<< static_cast<uint32_t>(sameCmdID)
<< static_cast<uint8_t>(sameCmdOpt)
@@ -693,14 +693,14 @@ void CGame::ClientReadNet()
try {
netcode::UnpackPacket pckt(packet, 1);

int16_t pktLen; pckt >> pktLen;
uint8_t player; pckt >> player;
int16_t pcktSize; pckt >> pcktSize;
uint8_t playerID; pckt >> playerID;

uint8_t aiInstID; pckt >> aiInstID;
uint8_t aiTeamID; pckt >> aiTeamID;
int16_t unitID; pckt >> unitID;

if (!playerHandler.IsValidPlayer(player))
if (!playerHandler.IsValidPlayer(playerID))
throw netcode::UnpackPacketException("Invalid player number");

if (unitID < 0 || static_cast<size_t>(unitID) >= unitHandler.MaxUnits())
@@ -732,8 +732,8 @@ void CGame::ClientReadNet()
}

// command originating from SkirmishAI or LuaUnsyncedCtrl
selectedUnitsHandler.AINetOrder(unitID, aiTeamID, player, c);
AddTraffic(player, packetCode, dataLength);
selectedUnitsHandler.AINetOrder(unitID, aiTeamID, playerID, c);
AddTraffic(playerID, packetCode, dataLength);
} catch (const netcode::UnpackPacketException& ex) {
LOG_L(L_ERROR, "[Game::%s][NETMSG_AICOMMAND*] exception \"%s\"", __func__, ex.what());
}
@@ -743,8 +743,9 @@ void CGame::ClientReadNet()
try {
netcode::UnpackPacket pckt(packet, 3);

uint8_t player;
uint8_t playerID;
uint8_t aiInstID;
uint8_t aiTeamID;
uint8_t pairwise;
uint32_t sameCmdID;
uint8_t sameCmdOpt;
@@ -753,12 +754,13 @@ void CGame::ClientReadNet()
int16_t unitCount;
int16_t commandCount;

pckt >> player;
pckt >> playerID;

if (!playerHandler.IsValidPlayer(player))
if (!playerHandler.IsValidPlayer(playerID))
throw netcode::UnpackPacketException("Invalid player number");

pckt >> aiInstID;
// pckt >> aiTeamID;
pckt >> pairwise;
pckt >> sameCmdID;
pckt >> sameCmdOpt;
@@ -807,16 +809,16 @@ void CGame::ClientReadNet()
// apply the "AI" commands (which actually originate from LuaUnsyncedCtrl)
if (pairwise) {
for (int16_t x = 0; x < std::min(unitCount, commandCount); ++x) {
selectedUnitsHandler.AINetOrder(unitIDs[x], aiInstID, player, commands[x]);
selectedUnitsHandler.AINetOrder(unitIDs[x], aiInstID, playerID, commands[x]);
}
} else {
for (int16_t c = 0; c < commandCount; c++) {
for (int16_t u = 0; u < unitCount; u++) {
selectedUnitsHandler.AINetOrder(unitIDs[u], aiInstID, player, commands[c]);
selectedUnitsHandler.AINetOrder(unitIDs[u], aiInstID, playerID, commands[c]);
}
}
}
AddTraffic(player, packetCode, dataLength);
AddTraffic(playerID, packetCode, dataLength);
} catch (const netcode::UnpackPacketException& ex) {
LOG_L(L_ERROR, "[Game::%s][NETMSG_AICOMMANDS] exception \"%s\"", __func__, ex.what());
}

0 comments on commit b10785d

Please sign in to comment.
You can’t perform that action at this time.