Change the definition of reserved network profile

So player name doesn't go away if disconnection happens
This commit is contained in:
Benau 2019-01-03 16:00:11 +08:00
parent aa49f4ae8c
commit b2ac7489d9
3 changed files with 21 additions and 20 deletions

View File

@ -26,6 +26,7 @@
#include "irrString.h"
#include <atomic>
#include <limits>
#include <memory>
#include <string>
@ -76,12 +77,12 @@ public:
return std::make_shared<NetworkPlayerProfile>(team);
}
// ------------------------------------------------------------------------
/* Placeholder profile for reserved player in live join, which its player
* name is empty. */
/* Placeholder profile for reserved player in live join, which its host id
* is uint32_t max. */
NetworkPlayerProfile(KartTeam team)
{
m_kart_name = "tux";
m_host_id = -1;
m_host_id = std::numeric_limits<uint32_t>::max();
m_default_kart_color = 0.0f;
m_online_id = 0;
m_per_player_difficulty.store((PerPlayerDifficulty)0);

View File

@ -18,13 +18,6 @@
#include "network/remote_kart_info.hpp"
#include "network/network_player_profile.hpp"
// ----------------------------------------------------------------------------
void RemoteKartInfo::makeReserved()
{
m_user_name = L"";
m_profile.reset();
} // makeReserved
// ----------------------------------------------------------------------------
void RemoteKartInfo::copyFrom(std::shared_ptr<NetworkPlayerProfile> p,
unsigned local_id)

View File

@ -22,6 +22,7 @@
#ifndef HEADER_REMOTE_KART_INFO_HPP
#define HEADER_REMOTE_KART_INFO_HPP
#include <limits>
#include <memory>
#include <string>
#include <vector>
@ -50,8 +51,8 @@ class RemoteKartInfo
irr::core::stringw m_user_name;
int m_local_player_id;
int m_global_player_id;
int m_host_id;
KartTeam m_kart_team;
uint32_t m_host_id;
KartTeam m_kart_team;
bool m_network_player;
PerPlayerDifficulty m_difficulty;
float m_default_kart_color;
@ -59,7 +60,7 @@ class RemoteKartInfo
std::weak_ptr<NetworkPlayerProfile> m_profile;
public:
RemoteKartInfo(int player_id, const std::string& kart_name,
const irr::core::stringw& user_name, int host_id,
const irr::core::stringw& user_name, uint32_t host_id,
bool network)
: m_kart_name(kart_name), m_user_name(user_name),
m_local_player_id(player_id), m_global_player_id(-1),
@ -70,21 +71,22 @@ public:
{}
RemoteKartInfo(const std::string& kart_name) : m_kart_name(kart_name),
m_user_name(""), m_local_player_id(-1),
m_global_player_id(-1), m_host_id(-1),
m_global_player_id(-1),
m_host_id(std::numeric_limits<uint32_t>::max()),
m_kart_team(KART_TEAM_NONE), m_network_player(false),
m_difficulty(PLAYER_DIFFICULTY_NORMAL),
m_default_kart_color(0.0f), m_online_id(0)
{}
RemoteKartInfo() : m_kart_name(""), m_user_name(""),
m_local_player_id(-1), m_global_player_id(-1),
m_host_id(-1), m_kart_team(KART_TEAM_NONE),
m_network_player(false),
m_host_id(std::numeric_limits<uint32_t>::max()),
m_kart_team(KART_TEAM_NONE), m_network_player(false),
m_difficulty(PLAYER_DIFFICULTY_NORMAL),
m_default_kart_color(0.0f), m_online_id(0)
{}
void setKartName(const std::string& n) { m_kart_name = n; }
void setPlayerName(const irr::core::stringw& u) { m_user_name = u; }
void setHostId(int id) { m_host_id = id; }
void setHostId(uint32_t id) { m_host_id = id; }
void setLocalPlayerId(int id) { m_local_player_id = id; }
void setGlobalPlayerId(int id) { m_global_player_id = id; }
void setKartTeam(KartTeam team) { m_kart_team = team; }
@ -93,7 +95,7 @@ public:
void setPerPlayerDifficulty(PerPlayerDifficulty value)
{ m_difficulty = value; }
void setOnlineId(uint32_t id) { m_online_id = id; }
int getHostId() const { return m_host_id; }
uint32_t getHostId() const { return m_host_id; }
int getLocalPlayerId() const { return m_local_player_id; }
int getGlobalPlayerId() const { return m_global_player_id; }
bool isNetworkPlayer() const { return m_network_player; }
@ -108,8 +110,13 @@ public:
std::weak_ptr<NetworkPlayerProfile> getNetworkPlayerProfile() const
{ return m_profile; }
bool disconnected() const { return m_profile.expired(); }
bool isReserved() const { return m_user_name.empty(); }
void makeReserved();
bool isReserved() const
{ return m_host_id == std::numeric_limits<uint32_t>::max(); }
void makeReserved()
{
m_host_id = std::numeric_limits<uint32_t>::max();
m_profile.reset();
}
void copyFrom(std::shared_ptr<NetworkPlayerProfile> p,
unsigned local_id);
bool operator<(const RemoteKartInfo& other) const