Save more and send less statistics.
This commit is contained in:
+3
-2
@@ -81,9 +81,10 @@ enum NetTimeoutReason {
|
||||
struct ServerStats
|
||||
{
|
||||
ServerStats()
|
||||
: numberOfPlayersOnServer(0), totalPlayersEverLoggedIn(0), totalGamesEverCreated(0),
|
||||
maxGamesOpen(0), maxPlayersLoggedIn(0) {}
|
||||
: numberOfPlayersOnServer(0), numberOfGamesOpen(0), totalPlayersEverLoggedIn(0),
|
||||
totalGamesEverCreated(0), maxGamesOpen(0), maxPlayersLoggedIn(0) {}
|
||||
unsigned numberOfPlayersOnServer;
|
||||
unsigned numberOfGamesOpen;
|
||||
unsigned totalPlayersEverLoggedIn;
|
||||
unsigned totalGamesEverCreated;
|
||||
unsigned maxGamesOpen;
|
||||
|
||||
@@ -4139,13 +4139,15 @@ NetPacketStatisticsChanged::Clone() const
|
||||
void
|
||||
NetPacketStatisticsChanged::SetData(const NetPacketStatisticsChanged::Data &inData)
|
||||
{
|
||||
u_int16_t numValues = 0;
|
||||
if (inData.stats.numberOfPlayersOnServer)
|
||||
// Only send number of players.
|
||||
// u_int16_t numValues = 0;
|
||||
u_int16_t numValues = 1;
|
||||
/* if (inData.stats.numberOfPlayersOnServer)
|
||||
++numValues;
|
||||
if (inData.stats.totalPlayersEverLoggedIn)
|
||||
++numValues;
|
||||
if (inData.stats.totalGamesEverCreated)
|
||||
++numValues;
|
||||
++numValues;*/
|
||||
|
||||
// Resize the packet so that the data fits in.
|
||||
Resize((u_int16_t)
|
||||
@@ -4158,13 +4160,13 @@ NetPacketStatisticsChanged::SetData(const NetPacketStatisticsChanged::Data &inDa
|
||||
StatisticsData *curStatisticsData =
|
||||
(StatisticsData *)((char *)tmpData + sizeof(NetPacketStatisticsChangedData));
|
||||
|
||||
if (inData.stats.numberOfPlayersOnServer)
|
||||
{
|
||||
// if (inData.stats.numberOfPlayersOnServer)
|
||||
// {
|
||||
curStatisticsData->statisticsType = htonl(NET_STAT_CUR_PLAYERS_ON_SERVER);
|
||||
curStatisticsData->statisticsValue = htonl(inData.stats.numberOfPlayersOnServer);
|
||||
++curStatisticsData;
|
||||
}
|
||||
if (inData.stats.totalPlayersEverLoggedIn)
|
||||
// }
|
||||
/* if (inData.stats.totalPlayersEverLoggedIn)
|
||||
{
|
||||
curStatisticsData->statisticsType = htonl(NET_STAT_TOTAL_PLAYERS_EVER_ON_SERVER);
|
||||
curStatisticsData->statisticsValue = htonl(inData.stats.totalPlayersEverLoggedIn);
|
||||
@@ -4174,7 +4176,7 @@ NetPacketStatisticsChanged::SetData(const NetPacketStatisticsChanged::Data &inDa
|
||||
{
|
||||
curStatisticsData->statisticsType = htonl(NET_STAT_TOTAL_GAMES_EVER_ON_SERVER);
|
||||
curStatisticsData->statisticsValue = htonl(inData.stats.totalGamesEverCreated);
|
||||
}
|
||||
}*/
|
||||
|
||||
// Check the packet - just in case.
|
||||
Check(GetRawData());
|
||||
|
||||
@@ -51,6 +51,8 @@
|
||||
#define SERVER_STATISTICS_STR_TOTAL_GAMES "TotalNumGamesCreated"
|
||||
#define SERVER_STATISTICS_STR_MAX_GAMES "MaxGamesOpen"
|
||||
#define SERVER_STATISTICS_STR_MAX_PLAYERS "MaxPlayersLoggedIn"
|
||||
#define SERVER_STATISTICS_STR_CUR_GAMES "CurGamesOpen"
|
||||
#define SERVER_STATISTICS_STR_CUR_PLAYERS "CurPlayersLoggedIn"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -879,6 +881,7 @@ ServerLobbyThread::InternalAddGame(boost::shared_ptr<ServerGameThread> game)
|
||||
{
|
||||
boost::mutex::scoped_lock lock(m_statMutex);
|
||||
++m_statData.totalGamesEverCreated;
|
||||
++m_statData.numberOfGamesOpen;
|
||||
unsigned numGames = static_cast<unsigned>(m_gameMap.size());
|
||||
if (numGames > m_statData.maxGamesOpen)
|
||||
m_statData.maxGamesOpen = numGames;
|
||||
@@ -889,6 +892,14 @@ ServerLobbyThread::InternalAddGame(boost::shared_ptr<ServerGameThread> game)
|
||||
void
|
||||
ServerLobbyThread::InternalRemoveGame(boost::shared_ptr<ServerGameThread> game)
|
||||
{
|
||||
{
|
||||
boost::mutex::scoped_lock lock(m_statMutex);
|
||||
if (m_statData.numberOfGamesOpen)
|
||||
{
|
||||
--m_statData.numberOfGamesOpen;
|
||||
m_statDataChanged = true;
|
||||
}
|
||||
}
|
||||
// Remove game from list.
|
||||
m_gameMap.erase(game->GetId());
|
||||
// Remove all sessions left in the game.
|
||||
@@ -1150,6 +1161,7 @@ ServerLobbyThread::ReadStatisticsFile()
|
||||
m_statData.maxPlayersLoggedIn = statisticsValue;
|
||||
else if (statisticsType == SERVER_STATISTICS_STR_MAX_GAMES)
|
||||
m_statData.maxGamesOpen = statisticsValue;
|
||||
// other statistics are non-persistant and not read.
|
||||
} while (!i.fail() && !i.eof());
|
||||
m_statDataChanged = false;
|
||||
}
|
||||
@@ -1172,6 +1184,8 @@ ServerLobbyThread::SaveStatisticsFile()
|
||||
o << SERVER_STATISTICS_STR_TOTAL_GAMES " " << m_statData.totalGamesEverCreated << endl;
|
||||
o << SERVER_STATISTICS_STR_MAX_PLAYERS " " << m_statData.maxPlayersLoggedIn << endl;
|
||||
o << SERVER_STATISTICS_STR_MAX_GAMES " " << m_statData.maxGamesOpen << endl;
|
||||
o << SERVER_STATISTICS_STR_CUR_PLAYERS " " << m_statData.numberOfPlayersOnServer << endl;
|
||||
o << SERVER_STATISTICS_STR_CUR_GAMES " " << m_statData.numberOfGamesOpen << endl;
|
||||
m_statDataChanged = false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user