Rename to country code for a better name

This commit is contained in:
Benau 2019-05-10 00:43:21 +08:00
parent a569d1f823
commit 44618c2a52
8 changed files with 26 additions and 25 deletions

View File

@ -229,7 +229,7 @@ CREATE TABLE IF NOT EXISTS (table name above)
online_id INTEGER UNSIGNED NOT NULL, -- Online if of the host (0 for offline account)
username TEXT NOT NULL, -- First player name in the host (if the host has splitscreen player)
player_num INTEGER UNSIGNED NOT NULL, -- Number of player(s) from the host, more than 1 if it has splitscreen player
country_id TEXT NULL DEFAULT NULL, -- Country id of the host
country_code TEXT NULL DEFAULT NULL, -- 2-letter country code of the host
version TEXT NOT NULL, -- SuperTuxKart version of the host (with OS info)
connected_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, -- Time when connected
disconnected_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, -- Time when disconnected (saved when disconnected)

View File

@ -69,7 +69,8 @@ private:
std::atomic<KartTeam> m_team;
std::string m_country_id;
/** 2-letter country code of player. */
std::string m_country_code;
public:
// ------------------------------------------------------------------------
@ -98,7 +99,7 @@ public:
float default_kart_color, uint32_t online_id,
PerPlayerDifficulty per_player_difficulty,
uint8_t local_player_id, KartTeam team,
const std::string& country_id)
const std::string& country_code)
{
m_peer = peer;
m_player_name = name;
@ -108,7 +109,7 @@ public:
m_per_player_difficulty.store(per_player_difficulty);
m_local_player_id = local_player_id;
m_team.store(team);
m_country_id = country_id;
m_country_code = country_code;
resetGrandPrixData();
}
// ------------------------------------------------------------------------
@ -164,7 +165,7 @@ public:
// ------------------------------------------------------------------------
KartTeam getTeam() const { return m_team.load(); }
// ------------------------------------------------------------------------
const std::string& getCountryId() const { return m_country_id; }
const std::string& getCountryCode() const { return m_country_code; }
}; // class NetworkPlayerProfile
#endif // HEADER_NETWORK_PLAYER_PROFILE

View File

@ -329,12 +329,12 @@ std::vector<std::shared_ptr<NetworkPlayerProfile> >
PerPlayerDifficulty ppd = (PerPlayerDifficulty)data.getUInt8();
uint8_t local_id = data.getUInt8();
KartTeam team = (KartTeam)data.getUInt8();
std::string country_id;
data.decodeString(&country_id);
std::string country_code;
data.decodeString(&country_code);
if (is_specator && host_id == STKHost::get()->getMyHostId())
*is_specator = false;
auto player = std::make_shared<NetworkPlayerProfile>(peer, player_name,
host_id, kart_color, online_id, ppd, local_id, team, country_id);
host_id, kart_color, online_id, ppd, local_id, team, country_code);
std::string kart_name;
data.decodeString(&kart_name);
player->setKartName(kart_name);
@ -783,7 +783,7 @@ void ClientLobby::updatePlayerList(Event* event)
auto& local_players = NetworkConfig::get()->getNetworkPlayers();
std::get<2>(local_players.at(local_id)) = lp.m_difficulty;
}
data.decodeString(&lp.m_country_id);
data.decodeString(&lp.m_country_code);
m_lobby_players.push_back(lp);
}
STKHost::get()->setAuthorisedToControl(client_server_owner);
@ -1261,8 +1261,8 @@ void ClientLobby::handleKartInfo(Event* event)
uint8_t local_id = data.getUInt8();
std::string kart_name;
data.decodeString(&kart_name);
std::string country_id;
data.decodeString(&country_id);
std::string country_code;
data.decodeString(&country_code);
RemoteKartInfo& rki = race_manager->getKartInfo(kart_id);
rki.setPlayerName(player_name);
@ -1272,7 +1272,7 @@ void ClientLobby::handleKartInfo(Event* event)
rki.setPerPlayerDifficulty(ppd);
rki.setLocalPlayerId(local_id);
rki.setKartName(kart_name);
rki.setCountryId(country_id);
rki.setCountryCode(country_code);
addLiveJoiningKart(kart_id, rki, live_join_util_ticks);
core::stringw msg;

View File

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

View File

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

View File

@ -212,7 +212,7 @@ void ServerLobby::initServerStatsTable()
" online_id INTEGER UNSIGNED NOT NULL, -- Online if of the host (0 for offline account)\n"
" username TEXT NOT NULL, -- First player name in the host (if the host has splitscreen player)\n"
" player_num INTEGER UNSIGNED NOT NULL, -- Number of player(s) from the host, more than 1 if it has splitscreen player\n"
" country_id TEXT NULL DEFAULT NULL, -- Country id of the host\n"
" country_code TEXT NULL DEFAULT NULL, -- 2-letter country code of the host\n"
" version TEXT NOT NULL, -- SuperTuxKart version of the host (with OS info)\n"
" connected_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, -- Time when connected\n"
" disconnected_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, -- Time when disconnected (saved when disconnected)\n"
@ -252,7 +252,7 @@ void ServerLobby::initServerStatsTable()
oss << "CREATE VIEW IF NOT EXISTS " << view_name << " AS\n"
<< " SELECT host_id, ip,\n"
<< " ((ip >> 24) & 255) ||'.'|| ((ip >> 16) & 255) ||'.'|| ((ip >> 8) & 255) ||'.'|| ((ip ) & 255) AS ip_readable,\n"
<< " port, online_id, username, player_num, country_id, version,\n"
<< " port, online_id, username, player_num, country_code, version,\n"
<< " ROUND((STRFTIME(\"%s\", disconnected_time) - STRFTIME(\"%s\", connected_time)) / 60.0, 2) AS time_played,\n"
<< " connected_time, disconnected_time, ping\n"
<< " FROM " << m_server_stats_table << ";";
@ -270,7 +270,7 @@ void ServerLobby::initServerStatsTable()
oss << "CREATE VIEW IF NOT EXISTS " << view_name << " AS\n"
<< " SELECT host_id, ip,\n"
<< " ((ip >> 24) & 255) ||'.'|| ((ip >> 16) & 255) ||'.'|| ((ip >> 8) & 255) ||'.'|| ((ip ) & 255) AS ip_readable,\n"
<< " port, online_id, username, player_num, country_id, version,\n"
<< " port, online_id, username, player_num, country_code, version,\n"
<< " ROUND((STRFTIME(\"%s\", 'now') - STRFTIME(\"%s\", connected_time)) / 60.0, 2) AS time_played,\n"
<< " connected_time, ping FROM " << m_server_stats_table << "\n"
<< " WHERE connected_time = disconnected_time;";
@ -1077,7 +1077,7 @@ void ServerLobby::encodePlayers(BareNetworkString* bns,
.addUInt8(player->getLocalPlayerId())
.addUInt8(
race_manager->teamEnabled() ? player->getTeam() : KART_TEAM_NONE)
.encodeString(player->getCountryId());
.encodeString(player->getCountryCode());
bns->encodeString(player->getKartName());
}
} // encodePlayers
@ -1269,7 +1269,7 @@ std::vector<std::shared_ptr<NetworkPlayerProfile> >
rki.getDefaultKartColor(),
rki.getOnlineId(), rki.getDifficulty(),
rki.getLocalPlayerId(), KART_TEAM_NONE,
rki.getCountryId());
rki.getCountryCode());
player->setKartName(rki.getKartName());
}
else
@ -2890,7 +2890,7 @@ void ServerLobby::updatePlayerList(bool update_when_reset_server)
pl->addUInt8(profile->getTeam());
else
pl->addUInt8(KART_TEAM_NONE);
pl->encodeString(profile->getCountryId());
pl->encodeString(profile->getCountryCode());
}
// Don't send this message to in-game players
@ -4079,7 +4079,7 @@ void ServerLobby::handleKartInfo(Event* event)
.addUInt32(rki.getHostId()).addFloat(rki.getDefaultKartColor())
.addUInt32(rki.getOnlineId()).addUInt8(rki.getDifficulty())
.addUInt8((uint8_t)rki.getLocalPlayerId())
.encodeString(rki.getKartName()).encodeString(rki.getCountryId());
.encodeString(rki.getKartName()).encodeString(rki.getCountryCode());
peer->sendPacket(ns, true/*reliable*/);
delete ns;
} // handleKartInfo

View File

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

View File

@ -57,7 +57,7 @@ class RemoteKartInfo
PerPlayerDifficulty m_difficulty;
float m_default_kart_color;
uint32_t m_online_id;
std::string m_country_id;
std::string m_country_code;
std::weak_ptr<NetworkPlayerProfile> m_profile;
public:
RemoteKartInfo(int player_id, const std::string& kart_name,
@ -106,8 +106,8 @@ public:
PerPlayerDifficulty getDifficulty() const { return m_difficulty; }
float getDefaultKartColor() const { return m_default_kart_color; }
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 setCountryCode(const std::string& id) { m_country_code = id; }
const std::string& getCountryCode() const { return m_country_code; }
void setNetworkPlayerProfile(
std::weak_ptr<NetworkPlayerProfile> npp) { m_profile = npp; }
std::weak_ptr<NetworkPlayerProfile> getNetworkPlayerProfile() const