diff --git a/lib/netplay/netplay.cpp b/lib/netplay/netplay.cpp index b39f0e0e544..6a4eaa07895 100644 --- a/lib/netplay/netplay.cpp +++ b/lib/netplay/netplay.cpp @@ -174,17 +174,25 @@ class PlayerManagementRecord identitiesMovedToSpectatorsByHost.clear(); ipsMovedToSpectatorsByHost.clear(); } + // player to spectators + void movedPlayerToSpectators(const std::string& ipAddress, const EcKey::Key& publicIdentity, bool byHost) + { + if (!byHost) { return; } + ipsMovedToSpectatorsByHost.insert(ipAddress); + identitiesMovedToSpectatorsByHost.insert(base64Encode(publicIdentity)); + } void movedPlayerToSpectators(const PLAYER& player, const EcKey::Key& publicIdentity, bool byHost) { if (!byHost) { return; } ipsMovedToSpectatorsByHost.insert(player.IPtextAddress); identitiesMovedToSpectatorsByHost.insert(base64Encode(publicIdentity)); } + // spectator to players void movedSpectatorToPlayers(const std::string& ipAddress, const EcKey::Key& publicIdentity, bool byHost) { if (!byHost) { return; } - ipsMovedToSpectatorsByHost.insert(ipAddress); - identitiesMovedToSpectatorsByHost.insert(base64Encode(publicIdentity)); + ipsMovedToSpectatorsByHost.erase(ipAddress); + identitiesMovedToSpectatorsByHost.erase(base64Encode(publicIdentity)); } void movedSpectatorToPlayers(const PLAYER& player, const EcKey::Key& publicIdentity, bool byHost) { @@ -840,8 +848,8 @@ static optional NET_CreatePlayer(char const *name, bool forceTakeLowes optional index = NET_FindOpenSlotForPlayer(forceTakeLowestAvailablePlayerNumber, asSpectator); if (!index.has_value()) { - debug(LOG_ERROR, "Could not find place for player %s", name); - NETlogEntry("Could not find a place for player!", SYNC_FLAG, -1); + debug(LOG_INFO, "Could not find place for %s %s", (!asSpectator.value_or(false)) ? "player" : "spectator", name); + NETlogEntry((!asSpectator.value_or(false)) ? "Could not find a place for player!" : "Could not find a place for spectator!", SYNC_FLAG, -1); return nullopt; } @@ -3907,7 +3915,7 @@ static void NETallowJoining() } else { - debug(LOG_ERROR, "Received an invalid version \"%" PRIu32 ".%" PRIu32 "\".", major, minor); + debug(LOG_INFO, "Received an invalid version \"%" PRIu32 ".%" PRIu32 "\".", major, minor); result = htonl(ERROR_WRONGVERSION); memcpy(&tmp_connectState[i].buffer, &result, sizeof(result)); writeAll(*tmp_socket[i], &tmp_connectState[i].buffer, sizeof(result)); @@ -4016,7 +4024,9 @@ static void NETallowJoining() // verify signature that player is joining with, reject him if he can not do that if (!identity.fromBytes(pkey, EcKey::Public) || !identity.verify(challengeResponse, tmp_connectState[i].connectChallenge.data(), tmp_connectState[i].connectChallenge.size())) { - debug(LOG_ERROR, "freeing temp socket %p, couldn't create player!", static_cast(tmp_socket[i])); + auto rejectMsg = astringf("**Rejecting player(%s), failed to verify player identity.", tmp_connectState[i].ip.c_str()); + debug(LOG_INFO, "%s", rejectMsg.c_str()); + debug(LOG_NET, "freeing temp socket %p, couldn't verify player identity", static_cast(tmp_socket[i])); rejected = ERROR_WRONGDATA; NETbeginEncode(NETnetTmpQueue(i), NET_REJECTED); @@ -4078,7 +4088,7 @@ static void NETallowJoining() if (rejected) { char buf[256] = {'\0'}; - ssprintf(buf, "**Rejecting player(%s), reason (%u). ", tmp_connectState[i].ip.c_str(), (unsigned int) rejected); + ssprintf(buf, "**Rejecting player(%s), reason (%u).", tmp_connectState[i].ip.c_str(), (unsigned int) rejected); debug(LOG_INFO, "%s", buf); NETlogEntry(buf, SYNC_FLAG, i); NETbeginEncode(NETnetTmpQueue(i), NET_REJECTED); @@ -4161,7 +4171,7 @@ static void NETallowJoining() // change the player join request to spectators tmp_connectState[i].receivedJoinInfo.playerType = NET_JOIN_SPECTATOR; // enforce spectator state for this player - playerManagementRecord.movedSpectatorToPlayers(tmp_connectState[i].ip, tmp_connectState[i].receivedJoinInfo.identity.toBytes(EcKey::Privacy::Public), true); + playerManagementRecord.movedPlayerToSpectators(tmp_connectState[i].ip, tmp_connectState[i].receivedJoinInfo.identity.toBytes(EcKey::Privacy::Public), true); } else if (tmp_connectState[i].asyncJoinApprovalResult.value() == AsyncJoinApprovalAction::Approve) { @@ -4236,7 +4246,7 @@ static void NETallowJoining() if (!tmp.has_value() || tmp.value() > static_cast(std::numeric_limits::max())) { ASSERT(tmp.value_or(0) <= static_cast(std::numeric_limits::max()), "Currently limited to uint8_t"); - debug(LOG_ERROR, "freeing temp socket %p, couldn't create player!", static_cast(tmp_socket[i])); + debug(LOG_INFO, "freeing temp socket %p, couldn't create slot", static_cast(tmp_socket[i])); // Tell the player that we are full. rejected = ERROR_FULL; @@ -4280,7 +4290,7 @@ static void NETallowJoining() std::string joinerPublicKeyB64 = base64Encode(joinRequestInfo.identity.toBytes(EcKey::Public)); std::string joinerIdentityHash = joinRequestInfo.identity.publicHashString(); - wz_command_interface_output("WZEVENT: player join: %u %s %s %s\n", i, joinerPublicKeyB64.c_str(), joinerIdentityHash.c_str(), NetPlay.players[i].IPtextAddress); + wz_command_interface_output("WZEVENT: player join: %u %s %s %s\n", index, joinerPublicKeyB64.c_str(), joinerIdentityHash.c_str(), NetPlay.players[index].IPtextAddress); // Narrowcast to new player that everyone has joined. for (uint8_t j = 0; j < MAX_CONNECTED_PLAYERS; ++j) diff --git a/src/multiint.cpp b/src/multiint.cpp index 7bd88b073ac..5ed9946105d 100644 --- a/src/multiint.cpp +++ b/src/multiint.cpp @@ -7300,6 +7300,7 @@ void WzMultiplayerOptionsTitleUI::frontendMultiMessages(bool running) if (ignoredMessage) { debug(LOG_ERROR, "Didn't handle %s message!", messageTypeToString(type)); + ignoredMessage = false; } NETpop(queue);