-
Notifications
You must be signed in to change notification settings - Fork 221
bugfix(network): Map player index to slot index for CRC validation #2857
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,9 +58,9 @@ | |
| #include "GameLogic/Object.h" | ||
| #endif | ||
| #include "GameLogic/SidesList.h" | ||
| #include "GameNetwork/GameInfo.h" | ||
| #include "GameNetwork/NetworkDefs.h" | ||
|
|
||
|
|
||
| //----------------------------------------------------------------------------- | ||
| /*extern*/ PlayerList *ThePlayerList = nullptr; | ||
|
|
||
|
|
@@ -226,6 +226,7 @@ void PlayerList::newGame() | |
| p->setDefaultTeam(); | ||
| } | ||
|
|
||
| resolveSlotIndices(); | ||
| } | ||
|
|
||
| //----------------------------------------------------------------------------- | ||
|
|
@@ -237,6 +238,8 @@ void PlayerList::init() | |
| for (int i = 1; i < MAX_PLAYER_COUNT; i++) | ||
| m_players[i]->init(nullptr); | ||
|
|
||
| std::fill(m_slotIndices, m_slotIndices + ARRAY_SIZE(m_slotIndices), -1); | ||
|
|
||
| // call setLocalPlayer so that becomingLocalPlayer() gets called appropriately | ||
| setLocalPlayer(m_players[0]); | ||
|
|
||
|
|
@@ -383,7 +386,6 @@ Player *PlayerList::getEachPlayerFromMask( PlayerMaskType& maskToAdjust ) | |
| return nullptr; // mask not found | ||
| } | ||
|
|
||
|
|
||
| //------------------------------------------------------------------------------------------------- | ||
| PlayerMaskType PlayerList::getPlayersWithRelationship( Int srcPlayerIndex, UnsignedInt allowedRelationships ) | ||
| { | ||
|
|
@@ -479,6 +481,49 @@ void PlayerList::xfer( Xfer *xfer ) | |
| // ------------------------------------------------------------------------------------------------ | ||
| void PlayerList::loadPostProcess() | ||
| { | ||
| std::fill(m_slotIndices, m_slotIndices + ARRAY_SIZE(m_slotIndices), -1); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can confirm that this is called after There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it necessary to do anything in |
||
| } | ||
|
|
||
| //----------------------------------------------------------------------------- | ||
| void PlayerList::setSlotIndex(Int playerIndex, Int slotIndex) | ||
| { | ||
| if (playerIndex >= 0 && playerIndex < ARRAY_SIZE(m_slotIndices)) | ||
| { | ||
| m_slotIndices[playerIndex] = slotIndex; | ||
| } | ||
| } | ||
|
|
||
| //----------------------------------------------------------------------------- | ||
| Int PlayerList::getSlotIndex(Int playerIndex) const | ||
| { | ||
| if (playerIndex >= 0 && playerIndex < ARRAY_SIZE(m_slotIndices)) | ||
| { | ||
| return m_slotIndices[playerIndex]; | ||
| } | ||
|
|
||
| return -1; | ||
| } | ||
|
|
||
| //----------------------------------------------------------------------------- | ||
| void PlayerList::resolveSlotIndices() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe call it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe make GameInfo an argument
It makes the intent of the function even clearer from the outside. |
||
| { | ||
| if (!TheGameInfo) | ||
| return; | ||
|
|
||
| AsciiString playerName; | ||
|
|
||
| for (Int i = 0; i < MAX_SLOTS; ++i) | ||
| { | ||
| const GameSlot* slot = TheGameInfo->getSlot(i); | ||
| if (!slot || !slot->isOccupied()) | ||
| continue; | ||
|
|
||
| playerName.format("player%d", i); | ||
|
|
||
| Player* player = findPlayerWithNameKey(TheNameKeyGenerator->nameToKey(playerName)); | ||
| if (player) | ||
| { | ||
| setSlotIndex(player->getPlayerIndex(), i); | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.