Birthday check when player joins

This commit is contained in:
def 2016-03-26 00:20:18 +01:00
parent 52fcc6e550
commit fc2bf86174
5 changed files with 70 additions and 0 deletions

View file

@ -45,6 +45,7 @@ public:
virtual void MapInfo(int ClientID, const char* MapName) = 0;
virtual void MapVote(int ClientID, const char* MapName) = 0;
virtual void CheckBirthday(int ClientID) = 0;
virtual void LoadScore(int ClientID) = 0;
virtual void SaveScore(int ClientID, float Time, float CpTime[NUM_CHECKPOINTS]) = 0;

View file

@ -202,6 +202,11 @@ void CFileScore::UpdatePlayer(int ID, float Score,
Save();
}
void CFileScore::CheckBirthday(int ClientID)
{
// TODO: implement
}
void CFileScore::LoadScore(int ClientID)
{
CPlayerScore *pPlayer = SearchScore(ClientID, 0);

View file

@ -62,6 +62,7 @@ public:
CFileScore(CGameContext *pGameServer);
~CFileScore();
virtual void CheckBirthday(int ClientID);
virtual void LoadScore(int ClientID);
virtual void MapInfo(int ClientID, const char* MapName);
virtual void MapVote(int ClientID, const char* MapName);

View file

@ -215,6 +215,67 @@ void CSqlScore::Init()
}
}
void CSqlScore::CheckBirthdayThread(void *pUser)
{
lock_wait(gs_SqlLock);
CSqlScoreData *pData = (CSqlScoreData *)pUser;
// Connect to database
if(pData->m_pSqlData->Connect())
{
try
{
// check strings
char originalName[MAX_NAME_LENGTH];
strcpy(originalName,pData->m_aName);
pData->m_pSqlData->ClearString(pData->m_aName);
char aBuf[512];
str_format(aBuf, sizeof(aBuf), "select year(Current) - year(Stamp) as YearsAgo from (select CURRENT_TIMESTAMP as Current, min(Timestamp) as Stamp from %s_race WHERE Name='%s') as l where dayofmonth(Current) = dayofmonth(Stamp) and month(Current) = month(Stamp) and year(Current) > year(Stamp);", pData->m_pSqlData->m_pPrefix, pData->m_aName);
pData->m_pSqlData->m_pResults = pData->m_pSqlData->m_pStatement->executeQuery(aBuf);
if(pData->m_pSqlData->m_pResults->next())
{
int yearsAgo = (int)pData->m_pSqlData->m_pResults->getInt("YearsAgo");
str_format(aBuf, sizeof(aBuf), "Happy DDNet birthday to %s for finishing their first map %d year%s ago!", originalName, yearsAgo, yearsAgo > 1 ? "s" : "");
pData->m_pSqlData->GameServer()->SendChat(-1, CGameContext::CHAT_ALL, aBuf, pData->m_ClientID);
}
dbg_msg("SQL", "Checking birthday done");
// delete statement and results
delete pData->m_pSqlData->m_pResults;
}
catch (sql::SQLException &e)
{
char aBuf[256];
str_format(aBuf, sizeof(aBuf), "MySQL Error: %s", e.what());
dbg_msg("SQL", aBuf);
dbg_msg("SQL", "ERROR: Could not check birthday");
}
// disconnect from database
pData->m_pSqlData->Disconnect();
}
delete pData;
lock_unlock(gs_SqlLock);
}
void CSqlScore::CheckBirthday(int ClientID)
{
CSqlScoreData *Tmp = new CSqlScoreData();
Tmp->m_ClientID = ClientID;
str_copy(Tmp->m_aName, Server()->ClientName(ClientID), MAX_NAME_LENGTH);
Tmp->m_pSqlData = this;
void *CheckThread = thread_init(CheckBirthdayThread, Tmp);
thread_detach(CheckThread);
}
// update stuff
void CSqlScore::LoadScoreThread(void *pUser)
{

View file

@ -42,6 +42,7 @@ class CSqlScore: public IScore
static void MapInfoThread(void *pUser);
static void MapVoteThread(void *pUser);
static void CheckBirthdayThread(void *pUser);
static void LoadScoreThread(void *pUser);
static void SaveScoreThread(void *pUser);
static void SaveTeamScoreThread(void *pUser);
@ -73,6 +74,7 @@ public:
CSqlScore(CGameContext *pGameServer);
~CSqlScore();
virtual void CheckBirthday(int ClientID);
virtual void LoadScore(int ClientID);
virtual void MapInfo(int ClientID, const char* MapName);
virtual void MapVote(int ClientID, const char* MapName);