Automatically cleanup cache once a day on the dedicated server.

This commit is contained in:
lotodore
2007-10-25 21:20:35 +00:00
parent d0cea553df
commit d0c34c572b
4 changed files with 31 additions and 12 deletions
-8
View File
@@ -34,14 +34,6 @@
#define MIN_AVATAR_FILE_SIZE 32
#define MAX_AVATAR_FILE_SIZE 30720
#ifdef POKERTH_DEDICATED_SERVER
#define MAX_NUMBER_OF_FILES 1024
#define MAX_AVATAR_CACHE_AGE 2592000 // 1 Month
#else
#define MAX_NUMBER_OF_FILES 256
#define MAX_AVATAR_CACHE_AGE 2592000
#endif
struct AvatarFileState;
class AvatarManager
+8
View File
@@ -29,6 +29,14 @@
#include <fstream>
#include <cstring>
#ifdef POKERTH_DEDICATED_SERVER
#define MAX_NUMBER_OF_FILES 1024
#define MAX_AVATAR_CACHE_AGE 2592000 // 1 Month
#else
#define MAX_NUMBER_OF_FILES 256
#define MAX_AVATAR_CACHE_AGE 2592000
#endif
#define PNG_HEADER "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a"
#define PNG_HEADER_SIZE (sizeof(PNG_HEADER) - 1)
#define JPG_HEADER "\xff\xd8"
+20 -4
View File
@@ -30,10 +30,11 @@
#include <boost/lambda/lambda.hpp>
#define SERVER_CLOSE_SESSION_DELAY_SEC 1
#define SERVER_MAX_NUM_SESSIONS 512 // Maximum number of idle users in lobby.
#define SERVER_CLOSE_SESSION_DELAY_SEC 1
#define SERVER_MAX_NUM_SESSIONS 512 // Maximum number of idle users in lobby.
#define SERVER_CACHE_CLEANUP_INTERVAL_SEC 86400 // 1 day
#define SERVER_COMPUTER_PLAYER_NAME "Computer"
#define SERVER_COMPUTER_PLAYER_NAME "Computer"
using namespace std;
@@ -286,6 +287,8 @@ ServerLobbyThread::Main()
CloseSessionLoop();
// Remove games.
RemoveGameLoop();
// Cleanup cache.
CleanupAvatarCache();
}
} catch (const PokerTHException &e)
{
@@ -705,6 +708,19 @@ ServerLobbyThread::RemoveGameLoop()
m_removeGameList.clear();
}
void
ServerLobbyThread::CleanupAvatarCache()
{
// Only act on timer and if there are no sessions.
if (m_cacheCleanupTimer.elapsed().total_seconds() > SERVER_CACHE_CLEANUP_INTERVAL_SEC
&& !m_sessionManager.HasSessions() && !m_gameSessionManager.HasSessions())
{
m_avatarManager.RemoveOldAvatarCacheEntries();
m_cacheCleanupTimer.reset();
m_cacheCleanupTimer.start();
}
}
void
ServerLobbyThread::InternalAddGame(boost::shared_ptr<ServerGameThread> game)
{
@@ -867,7 +883,7 @@ ServerLobbyThread::BroadcastStatisticsUpdate()
m_sessionManager.SendToAllSessions(GetSender(), packet, SessionData::Established);
m_gameSessionManager.SendToAllSessions(GetSender(), packet, SessionData::Game);
} catch (const NetException &e)
} catch (const NetException &)
{
// Ignore errors for now.
//LOG_ERROR("ServerLobbyThread::BroadcastStatisticsUpdate: " << e.what());
+3
View File
@@ -102,6 +102,7 @@ protected:
void RequestPlayerAvatar(SessionWrapper session);
void CloseSessionLoop();
void RemoveGameLoop();
void CleanupAvatarCache();
void InternalAddGame(boost::shared_ptr<ServerGameThread> game);
void InternalRemoveGame(boost::shared_ptr<ServerGameThread> game);
@@ -173,6 +174,8 @@ private:
unsigned m_totalPlayersLoggedIn;
unsigned m_totalGamesStarted;
ServerStats m_lastStatData;
boost::timers::portable::microsec_timer m_cacheCleanupTimer;
};
#endif