Automatically cleanup cache once a day on the dedicated server.
This commit is contained in:
@@ -34,14 +34,6 @@
|
|||||||
#define MIN_AVATAR_FILE_SIZE 32
|
#define MIN_AVATAR_FILE_SIZE 32
|
||||||
#define MAX_AVATAR_FILE_SIZE 30720
|
#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;
|
struct AvatarFileState;
|
||||||
|
|
||||||
class AvatarManager
|
class AvatarManager
|
||||||
|
|||||||
@@ -29,6 +29,14 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <cstring>
|
#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 "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a"
|
||||||
#define PNG_HEADER_SIZE (sizeof(PNG_HEADER) - 1)
|
#define PNG_HEADER_SIZE (sizeof(PNG_HEADER) - 1)
|
||||||
#define JPG_HEADER "\xff\xd8"
|
#define JPG_HEADER "\xff\xd8"
|
||||||
|
|||||||
@@ -30,10 +30,11 @@
|
|||||||
|
|
||||||
#include <boost/lambda/lambda.hpp>
|
#include <boost/lambda/lambda.hpp>
|
||||||
|
|
||||||
#define SERVER_CLOSE_SESSION_DELAY_SEC 1
|
#define SERVER_CLOSE_SESSION_DELAY_SEC 1
|
||||||
#define SERVER_MAX_NUM_SESSIONS 512 // Maximum number of idle users in lobby.
|
#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;
|
using namespace std;
|
||||||
|
|
||||||
@@ -286,6 +287,8 @@ ServerLobbyThread::Main()
|
|||||||
CloseSessionLoop();
|
CloseSessionLoop();
|
||||||
// Remove games.
|
// Remove games.
|
||||||
RemoveGameLoop();
|
RemoveGameLoop();
|
||||||
|
// Cleanup cache.
|
||||||
|
CleanupAvatarCache();
|
||||||
}
|
}
|
||||||
} catch (const PokerTHException &e)
|
} catch (const PokerTHException &e)
|
||||||
{
|
{
|
||||||
@@ -705,6 +708,19 @@ ServerLobbyThread::RemoveGameLoop()
|
|||||||
m_removeGameList.clear();
|
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
|
void
|
||||||
ServerLobbyThread::InternalAddGame(boost::shared_ptr<ServerGameThread> game)
|
ServerLobbyThread::InternalAddGame(boost::shared_ptr<ServerGameThread> game)
|
||||||
{
|
{
|
||||||
@@ -867,7 +883,7 @@ ServerLobbyThread::BroadcastStatisticsUpdate()
|
|||||||
|
|
||||||
m_sessionManager.SendToAllSessions(GetSender(), packet, SessionData::Established);
|
m_sessionManager.SendToAllSessions(GetSender(), packet, SessionData::Established);
|
||||||
m_gameSessionManager.SendToAllSessions(GetSender(), packet, SessionData::Game);
|
m_gameSessionManager.SendToAllSessions(GetSender(), packet, SessionData::Game);
|
||||||
} catch (const NetException &e)
|
} catch (const NetException &)
|
||||||
{
|
{
|
||||||
// Ignore errors for now.
|
// Ignore errors for now.
|
||||||
//LOG_ERROR("ServerLobbyThread::BroadcastStatisticsUpdate: " << e.what());
|
//LOG_ERROR("ServerLobbyThread::BroadcastStatisticsUpdate: " << e.what());
|
||||||
|
|||||||
@@ -102,6 +102,7 @@ protected:
|
|||||||
void RequestPlayerAvatar(SessionWrapper session);
|
void RequestPlayerAvatar(SessionWrapper session);
|
||||||
void CloseSessionLoop();
|
void CloseSessionLoop();
|
||||||
void RemoveGameLoop();
|
void RemoveGameLoop();
|
||||||
|
void CleanupAvatarCache();
|
||||||
|
|
||||||
void InternalAddGame(boost::shared_ptr<ServerGameThread> game);
|
void InternalAddGame(boost::shared_ptr<ServerGameThread> game);
|
||||||
void InternalRemoveGame(boost::shared_ptr<ServerGameThread> game);
|
void InternalRemoveGame(boost::shared_ptr<ServerGameThread> game);
|
||||||
@@ -173,6 +174,8 @@ private:
|
|||||||
unsigned m_totalPlayersLoggedIn;
|
unsigned m_totalPlayersLoggedIn;
|
||||||
unsigned m_totalGamesStarted;
|
unsigned m_totalGamesStarted;
|
||||||
ServerStats m_lastStatData;
|
ServerStats m_lastStatData;
|
||||||
|
|
||||||
|
boost::timers::portable::microsec_timer m_cacheCleanupTimer;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user