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

cmdinterface: Add new event output, room status json output #4128

Merged
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
22 changes: 22 additions & 0 deletions lib/netplay/netplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,11 @@ void NET_setLobbyDisabled(const std::string& infoLinkURL)
lobby_disabled_info_link_url = infoLinkURL;
}

uint32_t NET_getCurrentHostedLobbyGameId()
{
return gamestruct.gameId;
}

// Sets if the game is password protected or not
void NETGameLocked(bool flag)
{
Expand Down Expand Up @@ -991,12 +996,19 @@ static void NETplayerLeaving(UDWORD index, bool quietSocketClose)
sync_counter.left++;
bool wasSpectator = NetPlay.players[index].isSpectator;
MultiPlayerLeave(index); // more cleanup
bool resetReadyCalled = false;
if (ingame.localJoiningInProgress) // Only if game hasn't actually started yet.
{
NET_DestroyPlayer(index); // sets index player's array to false
if (!wasSpectator)
{
resetReadyStatus(false); // reset ready status for all players
resetReadyCalled = true;
}

if (!resetReadyCalled)
{
wz_command_interface_output_room_status_json();
}
}
}
Expand All @@ -1020,6 +1032,7 @@ static void NETplayerDropped(UDWORD index)
sync_counter.drops++;
bool wasSpectator = NetPlay.players[index].isSpectator;
MultiPlayerLeave(id); // more cleanup
bool resetReadyCalled = false;
if (ingame.localJoiningInProgress) // Only if game hasn't actually started yet.
{
// Send message type specifically for dropped / disconnects
Expand All @@ -1031,6 +1044,12 @@ static void NETplayerDropped(UDWORD index)
if (!wasSpectator)
{
resetReadyStatus(false); // reset ready status for all players
resetReadyCalled = true;
}

if (!resetReadyCalled)
{
wz_command_interface_output_room_status_json();
}
}

Expand Down Expand Up @@ -4361,6 +4380,9 @@ static void NETallowJoining()
{
ASSERT(false, "wzFiles is uninitialized?? (Player: %" PRIu8 ")", index);
}

wz_command_interface_output_room_status_json();

continue; // continue to next tmp_socket
}

Expand Down
1 change: 1 addition & 0 deletions lib/netplay/netplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ void NET_clearDownloadingWZFiles();
bool NET_getLobbyDisabled();
const std::string& NET_getLobbyDisabledInfoLinkURL();
void NET_setLobbyDisabled(const std::string& infoLinkURL);
uint32_t NET_getCurrentHostedLobbyGameId();

bool NETGameIsLocked();
void NETGameLocked(bool flag);
Expand Down
45 changes: 41 additions & 4 deletions src/multiint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2606,7 +2606,19 @@ 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);

wz_command_interface_output_room_status_json();
}
return changedValue;
}
else
{
Expand Down Expand Up @@ -2662,19 +2674,32 @@ 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);

wz_command_interface_output_room_status_json();
}
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 Expand Up @@ -6889,7 +6914,7 @@ class WzHostLobbyOperationsInterface : public HostLobbyOperationsInterface
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: hostChatPermissions=%s: %" PRIu32 " %" PRIu32 "%s %s %s %s %s\n", (freeChatEnabled) ? "Y" : "N", player, gameTime, playerPublicKeyB64.c_str(), playerIdentityHash.c_str(), playerVerifiedStatus.c_str(), playerNameB64.c_str(), NetPlay.players[player].IPtextAddress);
wz_command_interface_output("WZEVENT: hostChatPermissions=%s: %" PRIu32 " %" PRIu32 " %s %s %s %s %s\n", (freeChatEnabled) ? "Y" : "N", player, gameTime, playerPublicKeyB64.c_str(), playerIdentityHash.c_str(), playerVerifiedStatus.c_str(), playerNameB64.c_str(), NetPlay.players[player].IPtextAddress);
}

return true;
Expand Down Expand Up @@ -7297,6 +7322,18 @@ void WzMultiplayerOptionsTitleUI::frontendMultiMessages(bool running)
NETuint32_t(&player_id);
NETend();

if (player_id >= MAX_CONNECTED_PLAYERS)
{
debug(LOG_ERROR, "Bad NET_PLAYERRESPONDING received, ID is %d", (int)player_id);
break;
}

if (whosResponsible(player_id) != queue.index && queue.index != NetPlay.hostPlayer)
{
HandleBadParam("NET_PLAYERRESPONDING given incorrect params.", player_id, queue.index);
break;
}

ingame.JoiningInProgress[player_id] = false;
ingame.DataIntegrity[player_id] = false;
break;
Expand Down
4 changes: 3 additions & 1 deletion src/multijoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,8 @@ void recvPlayerLeft(NETQUEUE queue)

debug(LOG_INFO, "** player %u has dropped, in-game! (gameTime: %" PRIu32 ")", playerIndex, gameTime);
ActivityManager::instance().updateMultiplayGameData(game, ingame, NETGameIsLocked());

wz_command_interface_output_room_status_json();
}

// ////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -479,7 +481,7 @@ bool MultiPlayerLeave(UDWORD playerIndex)
std::string playerVerifiedStatus = (ingame.VerifiedIdentity[playerIndex]) ? "V" : "?";
std::string playerName = NetPlay.players[playerIndex].name;
std::string playerNameB64 = base64Encode(std::vector<unsigned char>(playerName.begin(), playerName.end()));
wz_command_interface_output("WZEVENT: playerLeft: %" PRIu32 " %" PRIu32 "%s %s %s %s %s\n", playerIndex, gameTime, playerPublicKeyB64.c_str(), playerIdentityHash.c_str(), playerVerifiedStatus.c_str(), playerNameB64.c_str(), NetPlay.players[playerIndex].IPtextAddress);
wz_command_interface_output("WZEVENT: playerLeft: %" PRIu32 " %" PRIu32 " %s %s %s %s %s\n", playerIndex, gameTime, playerPublicKeyB64.c_str(), playerIdentityHash.c_str(), playerVerifiedStatus.c_str(), playerNameB64.c_str(), NetPlay.players[playerIndex].IPtextAddress);
}

if (ingame.localJoiningInProgress)
Expand Down
19 changes: 18 additions & 1 deletion src/multiplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ bool multiPlayerLoop()
}
ingame.lastPlayerDataCheck2 = std::chrono::steady_clock::now();
wz_command_interface_output("WZEVENT: allPlayersJoined\n");
wz_command_interface_output_room_status_json();
}
if (NetPlay.bComms)
{
Expand Down Expand Up @@ -1450,8 +1451,20 @@ 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);

wz_command_interface_output_room_status_json();
}
}
ingame.JoiningInProgress[player_id] = false;
break;
}
case GAME_ALLIANCE:
Expand Down Expand Up @@ -2505,6 +2518,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 All @@ -2518,6 +2533,8 @@ void resetReadyStatus(bool bSendOptions, bool ignoreReadyReset)
changeReadyStatus(i, false);
}
}

wz_command_interface_output_room_status_json();
}
}

Expand Down
Loading
Loading