Reserve code for country from players

This commit is contained in:
Benau 2019-03-03 16:37:35 +08:00
parent bb84677e35
commit 45a55a4c9b
7 changed files with 28 additions and 7 deletions

View File

@ -69,6 +69,8 @@ private:
std::atomic<KartTeam> m_team; std::atomic<KartTeam> m_team;
std::string m_country_id;
public: public:
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
static std::shared_ptr<NetworkPlayerProfile> static std::shared_ptr<NetworkPlayerProfile>
@ -95,7 +97,8 @@ public:
const irr::core::stringw &name, uint32_t host_id, const irr::core::stringw &name, uint32_t host_id,
float default_kart_color, uint32_t online_id, float default_kart_color, uint32_t online_id,
PerPlayerDifficulty per_player_difficulty, PerPlayerDifficulty per_player_difficulty,
uint8_t local_player_id, KartTeam team) uint8_t local_player_id, KartTeam team,
const std::string& country_id)
{ {
m_peer = peer; m_peer = peer;
m_player_name = name; m_player_name = name;
@ -105,6 +108,7 @@ public:
m_per_player_difficulty.store(per_player_difficulty); m_per_player_difficulty.store(per_player_difficulty);
m_local_player_id = local_player_id; m_local_player_id = local_player_id;
m_team.store(team); m_team.store(team);
m_country_id = country_id;
resetGrandPrixData(); resetGrandPrixData();
} }
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
@ -159,7 +163,8 @@ public:
void setTeam(KartTeam team) { m_team.store(team); } void setTeam(KartTeam team) { m_team.store(team); }
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
KartTeam getTeam() const { return m_team.load(); } KartTeam getTeam() const { return m_team.load(); }
// ------------------------------------------------------------------------
const std::string& getCountryId() const { return m_country_id; }
}; // class NetworkPlayerProfile }; // class NetworkPlayerProfile
#endif // HEADER_NETWORK_PLAYER_PROFILE #endif // HEADER_NETWORK_PLAYER_PROFILE

View File

@ -267,8 +267,10 @@ void ClientLobby::addAllPlayers(Event* event)
PerPlayerDifficulty ppd = (PerPlayerDifficulty)data.getUInt8(); PerPlayerDifficulty ppd = (PerPlayerDifficulty)data.getUInt8();
uint8_t local_id = data.getUInt8(); uint8_t local_id = data.getUInt8();
KartTeam team = (KartTeam)data.getUInt8(); KartTeam team = (KartTeam)data.getUInt8();
std::string country_id;
data.decodeString(&country_id);
auto player = std::make_shared<NetworkPlayerProfile>(peer, player_name, auto player = std::make_shared<NetworkPlayerProfile>(peer, player_name,
host_id, kart_color, online_id, ppd, local_id, team); host_id, kart_color, online_id, ppd, local_id, team, country_id);
std::string kart_name; std::string kart_name;
data.decodeString(&kart_name); data.decodeString(&kart_name);
player->setKartName(kart_name); player->setKartName(kart_name);
@ -736,6 +738,7 @@ void ClientLobby::updatePlayerList(Event* event)
auto& local_players = NetworkConfig::get()->getNetworkPlayers(); auto& local_players = NetworkConfig::get()->getNetworkPlayers();
std::get<2>(local_players.at(local_id)) = lp.m_difficulty; std::get<2>(local_players.at(local_id)) = lp.m_difficulty;
} }
data.decodeString(&lp.m_country_id);
m_lobby_players.push_back(lp); m_lobby_players.push_back(lp);
} }
@ -1168,6 +1171,8 @@ void ClientLobby::handleKartInfo(Event* event)
uint8_t local_id = data.getUInt8(); uint8_t local_id = data.getUInt8();
std::string kart_name; std::string kart_name;
data.decodeString(&kart_name); data.decodeString(&kart_name);
std::string country_id;
data.decodeString(&country_id);
RemoteKartInfo& rki = race_manager->getKartInfo(kart_id); RemoteKartInfo& rki = race_manager->getKartInfo(kart_id);
rki.setPlayerName(player_name); rki.setPlayerName(player_name);
@ -1177,6 +1182,7 @@ void ClientLobby::handleKartInfo(Event* event)
rki.setPerPlayerDifficulty(ppd); rki.setPerPlayerDifficulty(ppd);
rki.setLocalPlayerId(local_id); rki.setLocalPlayerId(local_id);
rki.setKartName(kart_name); rki.setKartName(kart_name);
rki.setCountryId(country_id);
addLiveJoiningKart(kart_id, rki, live_join_util_ticks); addLiveJoiningKart(kart_id, rki, live_join_util_ticks);
core::stringw msg; core::stringw msg;

View File

@ -46,6 +46,7 @@ struct LobbyPlayer
uint32_t m_online_id; uint32_t m_online_id;
/* Icon used in networking lobby, see NetworkingLobby::loadedFromFile. */ /* Icon used in networking lobby, see NetworkingLobby::loadedFromFile. */
int m_icon_id; int m_icon_id;
std::string m_country_id;
/* Icon id for spectator in NetworkingLobby::loadedFromFile is 5. */ /* Icon id for spectator in NetworkingLobby::loadedFromFile is 5. */
bool isSpectator() const { return m_icon_id == 5; } bool isSpectator() const { return m_icon_id == 5; }
}; };

View File

@ -133,6 +133,7 @@ void LobbyProtocol::configRemoteKart(
rki.setOnlineId(profile->getOnlineId()); rki.setOnlineId(profile->getOnlineId());
if (race_manager->teamEnabled()) if (race_manager->teamEnabled())
rki.setKartTeam(profile->getTeam()); rki.setKartTeam(profile->getTeam());
rki.setCountryId(profile->getCountryId());
rki.setNetworkPlayerProfile(profile); rki.setNetworkPlayerProfile(profile);
// Inform the race manager about the data for this kart. // Inform the race manager about the data for this kart.
race_manager->setPlayerKart(i, rki); race_manager->setPlayerKart(i, rki);

View File

@ -642,7 +642,8 @@ NetworkString* ServerLobby::getLoadWorldMessage(
.addUInt8(player->getPerPlayerDifficulty()) .addUInt8(player->getPerPlayerDifficulty())
.addUInt8(player->getLocalPlayerId()) .addUInt8(player->getLocalPlayerId())
.addUInt8( .addUInt8(
race_manager->teamEnabled() ? player->getTeam() : KART_TEAM_NONE); race_manager->teamEnabled() ? player->getTeam() : KART_TEAM_NONE)
.encodeString(player->getCountryId());
if (player->getKartName().empty()) if (player->getKartName().empty())
{ {
RandomGenerator rg; RandomGenerator rg;
@ -811,7 +812,8 @@ void ServerLobby::liveJoinRequest(Event* event)
std::numeric_limits<uint32_t>::max(), std::numeric_limits<uint32_t>::max(),
rki.getDefaultKartColor(), rki.getDefaultKartColor(),
rki.getOnlineId(), rki.getDifficulty(), rki.getOnlineId(), rki.getDifficulty(),
rki.getLocalPlayerId(), KART_TEAM_NONE); rki.getLocalPlayerId(), KART_TEAM_NONE,
rki.getCountryId());
player->setKartName(rki.getKartName()); player->setKartName(rki.getKartName());
} }
else else
@ -2224,7 +2226,8 @@ void ServerLobby::handleUnencryptedConnection(std::shared_ptr<STKPeer> peer,
auto player = std::make_shared<NetworkPlayerProfile> auto player = std::make_shared<NetworkPlayerProfile>
(peer, i == 0 && !online_name.empty() ? online_name : name, (peer, i == 0 && !online_name.empty() ? online_name : name,
peer->getHostId(), default_kart_color, i == 0 ? online_id : 0, peer->getHostId(), default_kart_color, i == 0 ? online_id : 0,
per_player_difficulty, (uint8_t)i, KART_TEAM_NONE); per_player_difficulty, (uint8_t)i, KART_TEAM_NONE,
""/* reserved for country id */);
if (ServerConfig::m_team_choosing) if (ServerConfig::m_team_choosing)
{ {
KartTeam cur_team = KART_TEAM_NONE; KartTeam cur_team = KART_TEAM_NONE;
@ -2346,6 +2349,7 @@ void ServerLobby::updatePlayerList(bool update_when_reset_server)
m_peers_ready.find(p) != m_peers_ready.end() && m_peers_ready.find(p) != m_peers_ready.end() &&
m_peers_ready.at(p)) ? 1 : 0; m_peers_ready.at(p)) ? 1 : 0;
pl->addUInt8(ready); pl->addUInt8(ready);
pl->encodeString(profile->getCountryId());
} }
// Don't send this message to in-game players // Don't send this message to in-game players
@ -3473,7 +3477,7 @@ void ServerLobby::handleKartInfo(Event* event)
.addUInt32(rki.getHostId()).addFloat(rki.getDefaultKartColor()) .addUInt32(rki.getHostId()).addFloat(rki.getDefaultKartColor())
.addUInt32(rki.getOnlineId()).addUInt8(rki.getDifficulty()) .addUInt32(rki.getOnlineId()).addUInt8(rki.getDifficulty())
.addUInt8((uint8_t)rki.getLocalPlayerId()) .addUInt8((uint8_t)rki.getLocalPlayerId())
.encodeString(rki.getKartName()); .encodeString(rki.getKartName()).encodeString(rki.getCountryId());
peer->sendPacket(ns, true/*reliable*/); peer->sendPacket(ns, true/*reliable*/);
delete ns; delete ns;
} // handleKartInfo } // handleKartInfo

View File

@ -29,5 +29,6 @@ void RemoteKartInfo::copyFrom(std::shared_ptr<NetworkPlayerProfile> p,
m_difficulty = p->getPerPlayerDifficulty(); m_difficulty = p->getPerPlayerDifficulty();
m_default_kart_color = p->getPerPlayerDifficulty(); m_default_kart_color = p->getPerPlayerDifficulty();
m_online_id = p->getOnlineId(); m_online_id = p->getOnlineId();
m_country_id = p->getCountryId();
m_profile = p; m_profile = p;
} // copyFrom } // copyFrom

View File

@ -57,6 +57,7 @@ class RemoteKartInfo
PerPlayerDifficulty m_difficulty; PerPlayerDifficulty m_difficulty;
float m_default_kart_color; float m_default_kart_color;
uint32_t m_online_id; uint32_t m_online_id;
std::string m_country_id;
std::weak_ptr<NetworkPlayerProfile> m_profile; std::weak_ptr<NetworkPlayerProfile> m_profile;
public: public:
RemoteKartInfo(int player_id, const std::string& kart_name, RemoteKartInfo(int player_id, const std::string& kart_name,
@ -105,6 +106,8 @@ public:
PerPlayerDifficulty getDifficulty() const { return m_difficulty; } PerPlayerDifficulty getDifficulty() const { return m_difficulty; }
float getDefaultKartColor() const { return m_default_kart_color; } float getDefaultKartColor() const { return m_default_kart_color; }
uint32_t getOnlineId() const { return m_online_id; } uint32_t getOnlineId() const { return m_online_id; }
void setCountryId(const std::string& id) { m_country_id = id; }
const std::string& getCountryId() const { return m_country_id; }
void setNetworkPlayerProfile( void setNetworkPlayerProfile(
std::weak_ptr<NetworkPlayerProfile> npp) { m_profile = npp; } std::weak_ptr<NetworkPlayerProfile> npp) { m_profile = npp; }
std::weak_ptr<NetworkPlayerProfile> getNetworkPlayerProfile() const std::weak_ptr<NetworkPlayerProfile> getNetworkPlayerProfile() const