Merge branch 'DDRace64' of github.com:def-/teeworlds into DDRace64

This commit is contained in:
def 2014-01-09 19:00:48 +01:00
commit 2a573d54ff
3 changed files with 33 additions and 14 deletions

View file

@ -1008,6 +1008,11 @@ void CClient::ProcessConnlessPacket(CNetChunk *pPacket)
CUnpacker Up; CUnpacker Up;
CServerInfo Info = {0}; CServerInfo Info = {0};
CServerBrowser::CServerEntry *pEntry = m_ServerBrowser.Find(pPacket->m_Address);
// Don't add info if we already got info64
if(pEntry->m_Info.m_MaxClients > VANILLA_MAX_CLIENTS)
return;
Up.Reset((unsigned char*)pPacket->m_pData+sizeof(SERVERBROWSE_INFO), pPacket->m_DataSize-sizeof(SERVERBROWSE_INFO)); Up.Reset((unsigned char*)pPacket->m_pData+sizeof(SERVERBROWSE_INFO), pPacket->m_DataSize-sizeof(SERVERBROWSE_INFO));
int Token = str_toint(Up.GetString()); int Token = str_toint(Up.GetString());
str_copy(Info.m_aVersion, Up.GetString(CUnpacker::SANITIZE_CC|CUnpacker::SKIP_START_WHITESPACES), sizeof(Info.m_aVersion)); str_copy(Info.m_aVersion, Up.GetString(CUnpacker::SANITIZE_CC|CUnpacker::SKIP_START_WHITESPACES), sizeof(Info.m_aVersion));

View file

@ -32,41 +32,54 @@ CSqlScore::CSqlScore(CGameContext *pGameServer) : m_pGameServer(pGameServer),
gs_SqlLock = lock_create(); gs_SqlLock = lock_create();
Init(); Init();
LoadPointMapList(); LoadPointMapListThread(this);
} }
void CSqlScore::LoadPointMapList() void CSqlScore::LoadPointMapList()
{
//CSqlScoreData *Tmp = new CSqlScoreData();
//Tmp->m_ClientID = ClientID;
//str_copy(Tmp->m_aName, Server()->ClientName(ClientID), MAX_NAME_LENGTH);
//Tmp->m_pSqlData = this;
void *LoadThread = thread_create(LoadPointMapListThread, this);
#if defined(CONF_FAMILY_UNIX)
pthread_detach((pthread_t)LoadThread);
#endif
}
void CSqlScore::LoadPointMapListThread(void *pUser)
{ {
lock_wait(gs_SqlLock); lock_wait(gs_SqlLock);
m_PointsSize = 0; CSqlScore *pScore = (CSqlScore *)pUser;
std::ifstream f("points.cfg"); std::ifstream f("points.cfg");
if (f.fail()) if (f.fail())
return; return;
if(!Connect()) if(!pScore->Connect())
return; return;
m_PointsSize = std::count(std::istreambuf_iterator<char>(f), std::istreambuf_iterator<char>(), '\n'); pScore->m_PointsSize = std::count(std::istreambuf_iterator<char>(f), std::istreambuf_iterator<char>(), '\n');
f.seekg(0); f.seekg(0);
delete m_PointsInfos; delete pScore->m_PointsInfos;
m_PointsInfos = new CPointsInfo[m_PointsSize]; pScore->m_PointsInfos = new CPointsInfo[pScore->m_PointsSize];
char aBuf[256]; char aBuf[256];
unsigned int Position = 0; unsigned int Position = 0;
while (f.getline(aBuf, 256) && Position < m_PointsSize) while (f.getline(aBuf, 256) && Position < pScore->m_PointsSize)
{ {
CPointsInfo& Info = m_PointsInfos[Position]; CPointsInfo& Info = pScore->m_PointsInfos[Position];
if (sscanf(aBuf, "%u %127[^\t\n]", &Info.m_Points, Info.m_aMapName) == 2) if (sscanf(aBuf, "%u %127[^\t\n]", &Info.m_Points, Info.m_aMapName) == 2)
{ {
NormalizeMapname(Info.m_aMapName); pScore->NormalizeMapname(Info.m_aMapName);
str_format(aBuf, sizeof(aBuf), "SELECT count(Name) FROM %s_%s_race;", m_pPrefix, Info.m_aMapName); str_format(aBuf, sizeof(aBuf), "SELECT count(Name) FROM %s_%s_race;", pScore->m_pPrefix, Info.m_aMapName);
try try
{ {
m_pResults = m_pStatement->executeQuery(aBuf); pScore->m_pResults = pScore->m_pStatement->executeQuery(aBuf);
delete m_pResults; delete pScore->m_pResults;
} }
catch (sql::SQLException &e) catch (sql::SQLException &e)
{ {
@ -76,11 +89,11 @@ void CSqlScore::LoadPointMapList()
} }
} }
m_PointsSize = Position; pScore->m_PointsSize = Position;
lock_release(gs_SqlLock); lock_release(gs_SqlLock);
Disconnect(); pScore->Disconnect();
return; return;
} }

View file

@ -46,6 +46,7 @@ class CSqlScore: public IScore
return m_pServer; return m_pServer;
} }
static void LoadPointMapListThread(void *pUser);
static void LoadScoreThread(void *pUser); static void LoadScoreThread(void *pUser);
static void SaveScoreThread(void *pUser); static void SaveScoreThread(void *pUser);
static void SaveTeamScoreThread(void *pUser); static void SaveTeamScoreThread(void *pUser);