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

Support for admins performing host-only actions via UI #4110

Merged
merged 2 commits into from
Oct 28, 2024
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
10 changes: 8 additions & 2 deletions lib/netplay/netplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "src/console.h"
#include "src/component.h" // FIXME: we need to handle this better
#include "src/modding.h" // FIXME: we need to handle this better
#include "src/multilobbycommands.h"

#include <time.h> // for stats
#include <physfs.h>
Expand Down Expand Up @@ -668,6 +669,7 @@ void NET_InitPlayer(uint32_t i, bool initPosition, bool initTeams, bool initSpec
{
NetPlay.players[i].isSpectator = false;
}
NetPlay.players[i].isAdmin = false;
}

uint8_t NET_numHumanPlayers(void)
Expand Down Expand Up @@ -736,6 +738,7 @@ static void NETSendNPlayerInfoTo(uint32_t *index, uint32_t indexLen, unsigned to
NETint8_t(reinterpret_cast<int8_t*>(&NetPlay.players[index[n]].difficulty));
NETuint8_t(reinterpret_cast<uint8_t *>(&NetPlay.players[index[n]].faction));
NETbool(&NetPlay.players[index[n]].isSpectator);
NETbool(&NetPlay.players[index[n]].isAdmin);
}
NETend();
ActivityManager::instance().updateMultiplayGameData(game, ingame, NETGameIsLocked());
Expand Down Expand Up @@ -2533,6 +2536,7 @@ static bool NETprocessSystemMessage(NETQUEUE playerQueue, uint8_t *type)
int8_t difficulty = 0;
uint8_t faction = FACTION_NORMAL;
bool isSpectator = false;
bool isAdmin = false;
bool error = false;

NETbeginDecode(playerQueue, NET_PLAYER_INFO);
Expand Down Expand Up @@ -2577,6 +2581,7 @@ static bool NETprocessSystemMessage(NETQUEUE playerQueue, uint8_t *type)
NETint8_t(&difficulty);
NETuint8_t(&faction);
NETbool(&isSpectator);
NETbool(&isAdmin);

auto newFactionId = uintToFactionID(faction);
if (!newFactionId.has_value())
Expand All @@ -2596,6 +2601,7 @@ static bool NETprocessSystemMessage(NETQUEUE playerQueue, uint8_t *type)
NetPlay.players[index].difficulty = static_cast<AIDifficulty>(difficulty);
NetPlay.players[index].faction = newFactionId.value();
NetPlay.players[index].isSpectator = isSpectator;
NetPlay.players[index].isAdmin = isAdmin;
}

debug(LOG_NET, "%s for player %u (%s)", n == 0 ? "Receiving MSG_PLAYER_INFO" : " and", (unsigned int)index, NetPlay.players[index].allocated ? "human" : "AI");
Expand Down Expand Up @@ -4477,7 +4483,7 @@ bool NEThostGame(const char *SessionName, const char *PlayerName, bool spectator
// Now switch player color of the host to what they normally use for MP games
if (war_getMPcolour() >= 0)
{
changeColour(NetPlay.hostPlayer, war_getMPcolour(), true);
changeColour(NetPlay.hostPlayer, war_getMPcolour(), realSelectedPlayer);
}
return true;
}
Expand Down Expand Up @@ -4535,7 +4541,7 @@ bool NEThostGame(const char *SessionName, const char *PlayerName, bool spectator
// Now switch player color of the host to what they normally use for SP games
if (NetPlay.hostPlayer < MAX_PLAYERS && war_getMPcolour() >= 0)
{
changeColour(NetPlay.hostPlayer, war_getMPcolour(), true);
changeColour(NetPlay.hostPlayer, war_getMPcolour(), realSelectedPlayer);
}

NETregisterServer(WZ_SERVER_DISCONNECT);
Expand Down
2 changes: 2 additions & 0 deletions lib/netplay/netplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ struct PLAYER
bool autoGame; ///< if we are running a autogame (AI controls us)
FactionID faction; ///< which faction the player has
bool isSpectator; ///< whether this slot is a spectator slot
bool isAdmin; ///< whether this slot has admin privs

// used on host-ONLY (not transmitted to other clients):
std::shared_ptr<std::vector<WZFile>> wzFiles = std::make_shared<std::vector<WZFile>>(); ///< for each player, we keep track of map/mod download progress
Expand Down Expand Up @@ -302,6 +303,7 @@ struct PLAYER
IPtextAddress[0] = '\0';
faction = FACTION_NORMAL;
isSpectator = false;
isAdmin = false;
}
};

Expand Down
Loading
Loading