Split stk version and os string to 2 columns for better statistic purpose

This commit is contained in:
Benau 2019-11-08 01:17:27 +08:00
parent 4b23552ea8
commit 42d341a925
2 changed files with 21 additions and 11 deletions

View File

@ -247,7 +247,8 @@ CREATE TABLE IF NOT EXISTS (table name above)
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_code TEXT NULL DEFAULT NULL, -- 2-letter country code of the host
version TEXT NOT NULL, -- SuperTuxKart version of the host (with OS info)
version TEXT NOT NULL, -- SuperTuxKart version of the host
os TEXT NOT NULL, -- Operating system of the host
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)
ping INTEGER UNSIGNED NOT NULL DEFAULT 0 -- Ping of the host

View File

@ -280,7 +280,8 @@ void ServerLobby::initServerStatsTable()
" 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_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"
" version TEXT NOT NULL, -- SuperTuxKart version of the host\n"
" os TEXT NOT NULL, -- Operating system of the host\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"
" ping INTEGER UNSIGNED NOT NULL DEFAULT 0, -- Ping of the host\n"
@ -336,7 +337,7 @@ void ServerLobby::initServerStatsTable()
if (ServerConfig::m_ipv6_server)
oss << " ipv6,";
oss << " port, online_id, username, player_num,\n"
<< " " << m_server_stats_table << ".country_code AS country_code, country_flag, country_name, version,\n"
<< " " << m_server_stats_table << ".country_code AS country_code, country_flag, country_name, version, os,\n"
<< " ROUND((STRFTIME(\"%s\", disconnected_time) - STRFTIME(\"%s\", connected_time)) / 60.0, 2) AS time_played,\n"
<< " connected_time, disconnected_time, ping, packet_loss FROM " << m_server_stats_table << "\n"
<< " LEFT JOIN " << country_table_name << " ON "
@ -359,7 +360,7 @@ void ServerLobby::initServerStatsTable()
if (ServerConfig::m_ipv6_server)
oss << " ipv6,";
oss << " port, online_id, username, player_num,\n"
<< " " << m_server_stats_table << ".country_code AS country_code, country_flag, country_name, version,\n"
<< " " << m_server_stats_table << ".country_code AS country_code, country_flag, country_name, version, os,\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"
<< " LEFT JOIN " << country_table_name << " ON "
@ -397,7 +398,7 @@ void ServerLobby::initServerStatsTable()
if (ServerConfig::m_ipv6_server)
oss << " a.ipv6,";
oss << " a.port, a.player_num,\n"
<< " a.country_code, a.country_flag, a.country_name, a.version, a.ping, a.packet_loss,\n"
<< " a.country_code, a.country_flag, a.country_name, a.version, a.os, a.ping, a.packet_loss,\n"
<< " b.num_connections, b.first_connected_time, b.first_disconnected_time,\n"
<< " a.connected_time AS last_connected_time, a.disconnected_time AS last_disconnected_time,\n"
<< " a.time_played AS last_time_played, b.total_time_played, b.average_time_played,\n"
@ -3302,8 +3303,8 @@ void ServerLobby::handleUnencryptedConnection(std::shared_ptr<STKPeer> peer,
query = StringUtils::insertValues(
"INSERT INTO %s "
"(host_id, ip, ipv6 ,port, online_id, username, player_num, "
"country_code, version, ping) "
"VALUES (%u, 0, \"%s\" ,%u, %u, ?, %u, ?, ?, %u);",
"country_code, version, os, ping) "
"VALUES (%u, 0, \"%s\" ,%u, %u, ?, %u, ?, ?, ?, %u);",
m_server_stats_table.c_str(), peer->getHostId(),
peer->getIPV6Address(), peer->getAddress().getPort(), online_id,
player_count, peer->getAveragePing());
@ -3313,8 +3314,8 @@ void ServerLobby::handleUnencryptedConnection(std::shared_ptr<STKPeer> peer,
query = StringUtils::insertValues(
"INSERT INTO %s "
"(host_id, ip, port, online_id, username, player_num, "
"country_code, version, ping) "
"VALUES (%u, %u, %u, %u, ?, %u, ?, ?, %u);",
"country_code, version, os, ping) "
"VALUES (%u, %u, %u, %u, ?, %u, ?, ?, ?, %u);",
m_server_stats_table.c_str(), peer->getHostId(),
peer->getAddress().getIP(), peer->getAddress().getPort(),
online_id, player_count, peer->getAveragePing());
@ -3346,11 +3347,19 @@ void ServerLobby::handleUnencryptedConnection(std::shared_ptr<STKPeer> peer,
country_code.c_str());
}
}
if (sqlite3_bind_text(stmt, 3, peer->getUserVersion().c_str(),
auto version_os =
StringUtils::extractVersionOS(peer->getUserVersion());
if (sqlite3_bind_text(stmt, 3, version_os.first.c_str(),
-1, SQLITE_TRANSIENT) != SQLITE_OK)
{
Log::error("easySQLQuery", "Failed to bind %s.",
peer->getUserVersion().c_str());
version_os.first.c_str());
}
if (sqlite3_bind_text(stmt, 4, version_os.second.c_str(),
-1, SQLITE_TRANSIENT) != SQLITE_OK)
{
Log::error("easySQLQuery", "Failed to bind %s.",
version_os.second.c_str());
}
}
);