Get local player id from server for GP sorting later

This commit is contained in:
Benau 2018-04-20 19:10:40 +08:00
parent 75a63f6bae
commit d55d5d0f3f
4 changed files with 18 additions and 37 deletions

View File

@ -56,19 +56,15 @@ private:
/** The selected kart id. */
std::string m_kart_name;
/** The unique id of the player for this race. The number is assigned
* by the server (and it might not be the index of this player in the
* peer list. */
uint8_t m_global_player_id;
/** The kart id in the World class (pointer to AbstractKart). */
uint8_t m_world_kart_id;
/** The local player id relative to each peer. */
int m_local_player_id;
public:
NetworkPlayerProfile(std::shared_ptr<STKPeer> peer,
const irr::core::stringw &name, uint32_t host_id,
float default_kart_color, uint32_t online_id,
PerPlayerDifficulty per_player_difficulty)
PerPlayerDifficulty per_player_difficulty,
uint8_t local_player_id)
{
m_peer = peer;
m_player_name = name;
@ -76,20 +72,13 @@ public:
m_default_kart_color = default_kart_color;
m_online_id = online_id;
m_per_player_difficulty = per_player_difficulty;
m_global_player_id = 0;
m_world_kart_id = 0;
m_local_player_id = local_player_id;
}
// ------------------------------------------------------------------------
~NetworkPlayerProfile() {}
// ------------------------------------------------------------------------
bool isLocalPlayer() const;
// ------------------------------------------------------------------------
/** Sets the global player id of this player. */
void setGlobalPlayerId(int player_id) { m_global_player_id = player_id; }
// ------------------------------------------------------------------------
/** Returns the global ID of this player in this race. */
int getGlobalPlayerId() const { return m_global_player_id; }
// ------------------------------------------------------------------------
/** Returns the host id of this player. */
uint32_t getHostId() const { return m_host_id; }
// ------------------------------------------------------------------------
@ -99,11 +88,8 @@ public:
/** Returns the name of the kart this player has selected. */
const std::string &getKartName() const { return m_kart_name; }
// ------------------------------------------------------------------------
/** Sets the world kart id for this player. */
void setWorldKartID(int id) { m_world_kart_id = id; }
// ------------------------------------------------------------------------
/** Retuens the world kart id for this player. */
int getWorldKartID() const { return m_world_kart_id; }
/** Retuens the local player id for this player. */
int getLocalPlayerId() const { return m_local_player_id; }
// ------------------------------------------------------------------------
/** Returns the per-player difficulty. */
PerPlayerDifficulty getPerPlayerDifficulty() const

View File

@ -235,8 +235,9 @@ void ClientLobby::addAllPlayers(Event* event)
float kart_color = data.getFloat();
uint32_t online_id = data.getUInt32();
PerPlayerDifficulty ppd = (PerPlayerDifficulty)data.getUInt8();
uint8_t local_id = data.getUInt8();
auto player = std::make_shared<NetworkPlayerProfile>(peer, player_name,
host_id, kart_color, online_id, ppd);
host_id, kart_color, online_id, ppd, local_id);
std::string kart_name;
data.decodeString(&kart_name);
player->setKartName(kart_name);

View File

@ -94,7 +94,6 @@ void LobbyProtocol::configRemoteKart(
// Create the kart information for the race manager:
// -------------------------------------------------
int local_player_id = 0;
for (unsigned int i = 0; i < players.size(); i++)
{
std::shared_ptr<NetworkPlayerProfile> profile = players[i];
@ -102,20 +101,20 @@ void LobbyProtocol::configRemoteKart(
// All non-local players are created here. This means all players
// on the server, and all non-local players on a client (the local
// karts are created in the NetworkingLobby).
// karts are created in the ClientLobby).
int local_player_id = profile->getLocalPlayerId();
if (!is_local)
{
// On the server no device or player profile is needed.
StateManager::get()->createActivePlayer(NULL, NULL);
// No device or player profile is needed for remote kart.
local_player_id =
(int)(StateManager::get()->createActivePlayer(NULL, NULL));
}
// Adjust the local player id so that local players have the numbers
// 0 to num-1; and all other karts start with num. This way the local
// players get the first ActivePlayers assigned (which have the
// corresponding device associated with it).
RemoteKartInfo rki(is_local ? local_player_id
: i - local_player_id
+ m_game_setup->getNumLocalPlayers(),
RemoteKartInfo rki(local_player_id,
profile->getKartName(),
profile->getName(),
profile->getHostId(),
@ -123,12 +122,6 @@ void LobbyProtocol::configRemoteKart(
rki.setGlobalPlayerId(i);
rki.setDefaultKartColor(profile->getDefaultKartColor());
rki.setPerPlayerDifficulty(profile->getPerPlayerDifficulty());
if (is_local)
{
rki.setLocalPlayerId(local_player_id);
local_player_id++;
}
// Inform the race manager about the data for this kart.
race_manager->setPlayerKart(i, rki);
} // for i in players

View File

@ -336,7 +336,8 @@ void ServerLobby::asynchronousUpdate()
.addUInt32(player->getHostId())
.addFloat(player->getDefaultKartColor())
.addUInt32(player->getOnlineId())
.addUInt8(player->getPerPlayerDifficulty());
.addUInt8(player->getPerPlayerDifficulty())
.addUInt8(player->getLocalPlayerId());
if (player->getKartName().empty())
{
RandomGenerator rg;
@ -851,7 +852,7 @@ void ServerLobby::connectionRequested(Event* event)
(PerPlayerDifficulty)data.getUInt8();
peer->addPlayer(std::make_shared<NetworkPlayerProfile>
(peer, name, peer->getHostId(), default_kart_color, online_id,
per_player_difficulty));
per_player_difficulty, (uint8_t)i));
}
bool is_banned = false;