Skip to content

Commit

Permalink
cmdinterface: Add readyStatus and playerResponding events
Browse files Browse the repository at this point in the history
  • Loading branch information
past-due committed Nov 13, 2024
1 parent 258e608 commit 1762fb1
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
27 changes: 24 additions & 3 deletions src/multiint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2606,7 +2606,17 @@ static bool SendReadyRequest(UBYTE player, bool bReady)
{
if (NetPlay.isHost) // do or request the change.
{
return changeReadyStatus(player, bReady);
bool changedValue = changeReadyStatus(player, bReady);
if (changedValue && wz_command_interface_enabled())
{
std::string playerPublicKeyB64 = base64Encode(getMultiStats(player).identity.toBytes(EcKey::Public));
std::string playerIdentityHash = getMultiStats(player).identity.publicHashString();
std::string playerVerifiedStatus = (ingame.VerifiedIdentity[player]) ? "V" : "?";
std::string playerName = NetPlay.players[player].name;
std::string playerNameB64 = base64Encode(std::vector<unsigned char>(playerName.begin(), playerName.end()));
wz_command_interface_output("WZEVENT: readyStatus=%d: %" PRIu32 " %s %s %s %s %s\n", bReady ? 1 : 0, player, playerPublicKeyB64.c_str(), playerIdentityHash.c_str(), playerVerifiedStatus.c_str(), playerNameB64.c_str(), NetPlay.players[player].IPtextAddress);
}
return changedValue;
}
else
{
Expand Down Expand Up @@ -2662,19 +2672,30 @@ bool recvReadyRequest(NETQUEUE queue)
return false;
}

return changeReadyStatus((UBYTE)player, bReady);
bool changedValue = changeReadyStatus((UBYTE)player, bReady);
if (changedValue && wz_command_interface_enabled())
{
std::string playerPublicKeyB64 = base64Encode(stats.identity.toBytes(EcKey::Public));
std::string playerIdentityHash = stats.identity.publicHashString();
std::string playerVerifiedStatus = (ingame.VerifiedIdentity[player]) ? "V" : "?";
std::string playerName = NetPlay.players[player].name;
std::string playerNameB64 = base64Encode(std::vector<unsigned char>(playerName.begin(), playerName.end()));
wz_command_interface_output("WZEVENT: readyStatus=%d: %" PRIu32 " %s %s %s %s %s\n", bReady ? 1 : 0, player, playerPublicKeyB64.c_str(), playerIdentityHash.c_str(), playerVerifiedStatus.c_str(), playerNameB64.c_str(), NetPlay.players[player].IPtextAddress);
}
return changedValue;
}

bool changeReadyStatus(UBYTE player, bool bReady)
{
bool changedValue = NetPlay.players[player].ready != bReady;
NetPlay.players[player].ready = bReady;
NETBroadcastPlayerInfo(player);
netPlayersUpdated = true;
// Player is fast! Clicked the "Ready" button before we had a chance to ping him/her
// change PingTime to some value less than PING_LIMIT, so that multiplayPlayersReady
// doesnt block
ingame.PingTimes[player] = ingame.PingTimes[player] == PING_LIMIT ? 1 : ingame.PingTimes[player];
return true;
return changedValue;
}

static void informIfAdminChangedOtherPosition(uint32_t targetPlayerIdx, uint32_t responsibleIdx)
Expand Down
14 changes: 13 additions & 1 deletion src/multiplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1450,8 +1450,18 @@ bool recvMessage()
if (ingame.JoiningInProgress[player_id])
{
addKnownPlayer(NetPlay.players[player_id].name, getMultiStats(player_id).identity);
ingame.JoiningInProgress[player_id] = false;

if (wz_command_interface_enabled())
{
std::string playerPublicKeyB64 = base64Encode(getMultiStats(player_id).identity.toBytes(EcKey::Public));
std::string playerIdentityHash = getMultiStats(player_id).identity.publicHashString();
std::string playerVerifiedStatus = (ingame.VerifiedIdentity[player_id]) ? "V" : "?";
std::string playerName = NetPlay.players[player_id].name;
std::string playerNameB64 = base64Encode(std::vector<unsigned char>(playerName.begin(), playerName.end()));
wz_command_interface_output("WZEVENT: playerResponding: %" PRIu32 " %s %s %s %s %s\n", player_id, playerPublicKeyB64.c_str(), playerIdentityHash.c_str(), playerVerifiedStatus.c_str(), playerNameB64.c_str(), NetPlay.players[player_id].IPtextAddress);
}
}
ingame.JoiningInProgress[player_id] = false;
break;
}
case GAME_ALLIANCE:
Expand Down Expand Up @@ -2505,6 +2515,8 @@ void resetReadyStatus(bool bSendOptions, bool ignoreReadyReset)
//Really reset ready status
if (NetPlay.isHost && !ignoreReadyReset)
{
wz_command_interface_output("WZEVENT: readyStatus=RESET\n");

for (unsigned int i = 0; i < MAX_CONNECTED_PLAYERS; ++i)
{
//Ignore for autohost launch option.
Expand Down

0 comments on commit 1762fb1

Please sign in to comment.