Skip to content
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

Various netplay log message & state handling fixes #3960

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions lib/netplay/netplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -840,8 +848,8 @@ static optional<uint32_t> NET_CreatePlayer(char const *name, bool forceTakeLowes
optional<uint32_t> 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;
}

Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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<void *>(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<void *>(tmp_socket[i]));

rejected = ERROR_WRONGDATA;
NETbeginEncode(NETnetTmpQueue(i), NET_REJECTED);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -4236,7 +4246,7 @@ static void NETallowJoining()
if (!tmp.has_value() || tmp.value() > static_cast<uint32_t>(std::numeric_limits<uint8_t>::max()))
{
ASSERT(tmp.value_or(0) <= static_cast<uint32_t>(std::numeric_limits<uint8_t>::max()), "Currently limited to uint8_t");
debug(LOG_ERROR, "freeing temp socket %p, couldn't create player!", static_cast<void *>(tmp_socket[i]));
debug(LOG_INFO, "freeing temp socket %p, couldn't create slot", static_cast<void *>(tmp_socket[i]));

// Tell the player that we are full.
rejected = ERROR_FULL;
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/multiint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading