/top5, /top5team, /top5points, /times also show worst results with negative numbers

This commit is contained in:
def 2018-01-21 19:08:52 +01:00
parent 1e5985a4b3
commit a731482152

View file

@ -892,6 +892,9 @@ bool CSqlScore::ShowTop5Thread(CSqlServer* pSqlServer, const CSqlData *pGameData
if (HandleFailure) if (HandleFailure)
return true; return true;
int LimitStart = abs(pData->m_Num-1);
const char *pOrder = pData->m_Num >= 0 ? "ASC" : "DESC";
try try
{ {
// check sort methode // check sort methode
@ -899,7 +902,7 @@ bool CSqlScore::ShowTop5Thread(CSqlServer* pSqlServer, const CSqlData *pGameData
pSqlServer->executeSql("SET @prev := NULL;"); pSqlServer->executeSql("SET @prev := NULL;");
pSqlServer->executeSql("SET @rank := 1;"); pSqlServer->executeSql("SET @rank := 1;");
pSqlServer->executeSql("SET @pos := 0;"); pSqlServer->executeSql("SET @pos := 0;");
str_format(aBuf, sizeof(aBuf), "SELECT Name, Time, rank FROM (SELECT Name, (@pos := @pos+1) pos, (@rank := IF(@prev = Time,@rank, @pos)) rank, (@prev := Time) Time FROM (SELECT Name, min(Time) as Time FROM %s_race WHERE Map = '%s' GROUP BY Name ORDER BY `Time` ASC) as a) as b LIMIT %d, 5;", pSqlServer->GetPrefix(), pData->m_Map.ClrStr(), pData->m_Num-1); str_format(aBuf, sizeof(aBuf), "SELECT Name, Time, Rank FROM (SELECT Name, (@pos := @pos+1) pos, (@rank := IF(@prev = Time,@rank, @pos)) Rank, (@prev := Time) Time FROM (SELECT Name, min(Time) as Time FROM %s_race WHERE Map = '%s' GROUP BY Name ORDER BY `Time` ASC) as a) as b ORDER BY Rank %s LIMIT %d, 5;", pSqlServer->GetPrefix(), pData->m_Map.ClrStr(), pOrder, LimitStart);
pSqlServer->executeSqlQuery(aBuf); pSqlServer->executeSqlQuery(aBuf);
// show top5 // show top5
@ -910,7 +913,7 @@ bool CSqlScore::ShowTop5Thread(CSqlServer* pSqlServer, const CSqlData *pGameData
while(pSqlServer->GetResults()->next()) while(pSqlServer->GetResults()->next())
{ {
Time = (float)pSqlServer->GetResults()->getDouble("Time"); Time = (float)pSqlServer->GetResults()->getDouble("Time");
Rank = (float)pSqlServer->GetResults()->getInt("rank"); Rank = (float)pSqlServer->GetResults()->getInt("Rank");
str_format(aBuf, sizeof(aBuf), "%d. %s Time: %02d:%05.2f", Rank, pSqlServer->GetResults()->getString("Name").c_str(), (int)(Time/60), Time-((int)Time/60*60)); str_format(aBuf, sizeof(aBuf), "%d. %s Time: %02d:%05.2f", Rank, pSqlServer->GetResults()->getString("Name").c_str(), (int)(Time/60), Time-((int)Time/60*60));
pData->GameServer()->SendChatTarget(pData->m_ClientID, aBuf); pData->GameServer()->SendChatTarget(pData->m_ClientID, aBuf);
//Rank++; //Rank++;
@ -950,6 +953,9 @@ bool CSqlScore::ShowTeamTop5Thread(CSqlServer* pSqlServer, const CSqlData *pGame
if (HandleFailure) if (HandleFailure)
return true; return true;
int LimitStart = abs(pData->m_Num-1);
const char *pOrder = pData->m_Num >= 0 ? "ASC" : "DESC";
try try
{ {
// check sort methode // check sort methode
@ -959,7 +965,7 @@ bool CSqlScore::ShowTeamTop5Thread(CSqlServer* pSqlServer, const CSqlData *pGame
pSqlServer->executeSql("SET @previd := NULL;"); pSqlServer->executeSql("SET @previd := NULL;");
pSqlServer->executeSql("SET @rank := 1;"); pSqlServer->executeSql("SET @rank := 1;");
pSqlServer->executeSql("SET @pos := 0;"); pSqlServer->executeSql("SET @pos := 0;");
str_format(aBuf, sizeof(aBuf), "SELECT ID, Name, Time, rank FROM (SELECT r.ID, Name, rank, l.Time FROM ((SELECT ID, rank, Time FROM (SELECT ID, (@pos := IF(@previd = ID,@pos,@pos+1)) pos, (@previd := ID), (@rank := IF(@prev = Time,@rank,@pos)) rank, (@prev := Time) Time FROM (SELECT ID, MIN(Time) as Time FROM %s_teamrace WHERE Map = '%s' GROUP BY ID ORDER BY `Time` ASC) as all_top_times) as a LIMIT %d, 5) as l) LEFT JOIN %s_teamrace as r ON l.ID = r.ID ORDER BY Time ASC, r.ID, Name ASC) as a;", pSqlServer->GetPrefix(), pData->m_Map.ClrStr(), pData->m_Num-1, pSqlServer->GetPrefix()); str_format(aBuf, sizeof(aBuf), "SELECT ID, Name, Time, Rank FROM (SELECT r.ID, Name, Rank, l.Time FROM ((SELECT ID, Rank, Time FROM (SELECT ID, (@pos := IF(@previd = ID,@pos,@pos+1)) pos, (@previd := ID), (@rank := IF(@prev = Time,@rank,@pos)) Rank, (@prev := Time) Time FROM (SELECT ID, MIN(Time) as Time FROM %s_teamrace WHERE Map = '%s' GROUP BY ID ORDER BY `Time` ASC) as all_top_times) as a ORDER BY Rank %s LIMIT %d, 5) as l) LEFT JOIN %s_teamrace as r ON l.ID = r.ID ORDER BY Time ASC, r.ID, Name ASC) as a;", pSqlServer->GetPrefix(), pData->m_Map.ClrStr(), pOrder, LimitStart, pSqlServer->GetPrefix());
pSqlServer->executeSqlQuery(aBuf); pSqlServer->executeSqlQuery(aBuf);
// show teamtop5 // show teamtop5
@ -1006,7 +1012,7 @@ bool CSqlScore::ShowTeamTop5Thread(CSqlServer* pSqlServer, const CSqlData *pGame
str_append(aNames, " & ", sizeof(aNames)); str_append(aNames, " & ", sizeof(aNames));
Time = (float)pSqlServer->GetResults()->getDouble("Time"); Time = (float)pSqlServer->GetResults()->getDouble("Time");
Rank = (float)pSqlServer->GetResults()->getInt("rank"); Rank = (float)pSqlServer->GetResults()->getInt("Rank");
if (Row == aCuts[CutPos]) if (Row == aCuts[CutPos])
{ {
@ -1068,14 +1074,17 @@ bool CSqlScore::ShowTimesThread(CSqlServer* pSqlServer, const CSqlData *pGameDat
if (HandleFailure) if (HandleFailure)
return true; return true;
int LimitStart = abs(pData->m_Num-1);
const char *pOrder = pData->m_Num >= 0 ? "ASC" : "DESC";
try try
{ {
char aBuf[512]; char aBuf[512];
if(pData->m_Search) // last 5 times of a player if(pData->m_Search) // last 5 times of a player
str_format(aBuf, sizeof(aBuf), "SELECT Time, UNIX_TIMESTAMP(CURRENT_TIMESTAMP)-UNIX_TIMESTAMP(Timestamp) as Ago, UNIX_TIMESTAMP(Timestamp) as Stamp FROM %s_race WHERE Map = '%s' AND Name = '%s' ORDER BY Timestamp DESC LIMIT %d, 5;", pSqlServer->GetPrefix(), pData->m_Map.ClrStr(), pData->m_Name.ClrStr(), pData->m_Num-1); str_format(aBuf, sizeof(aBuf), "SELECT Time, UNIX_TIMESTAMP(CURRENT_TIMESTAMP)-UNIX_TIMESTAMP(Timestamp) as Ago, UNIX_TIMESTAMP(Timestamp) as Stamp FROM %s_race WHERE Map = '%s' AND Name = '%s' ORDER BY Timestamp %s LIMIT %d, 5;", pSqlServer->GetPrefix(), pData->m_Map.ClrStr(), pData->m_Name.ClrStr(), pOrder, LimitStart);
else// last 5 times of server else// last 5 times of server
str_format(aBuf, sizeof(aBuf), "SELECT Name, Time, UNIX_TIMESTAMP(CURRENT_TIMESTAMP)-UNIX_TIMESTAMP(Timestamp) as Ago, UNIX_TIMESTAMP(Timestamp) as Stamp FROM %s_race WHERE Map = '%s' ORDER BY Timestamp DESC LIMIT %d, 5;", pSqlServer->GetPrefix(), pData->m_Map.ClrStr(), pData->m_Num-1); str_format(aBuf, sizeof(aBuf), "SELECT Name, Time, UNIX_TIMESTAMP(CURRENT_TIMESTAMP)-UNIX_TIMESTAMP(Timestamp) as Ago, UNIX_TIMESTAMP(Timestamp) as Stamp FROM %s_race WHERE Map = '%s' ORDER BY Timestamp %s LIMIT %d, 5;", pSqlServer->GetPrefix(), pData->m_Map.ClrStr(), pOrder, LimitStart);
pSqlServer->executeSqlQuery(aBuf); pSqlServer->executeSqlQuery(aBuf);
@ -1212,13 +1221,16 @@ bool CSqlScore::ShowTopPointsThread(CSqlServer* pSqlServer, const CSqlData *pGam
if (HandleFailure) if (HandleFailure)
return true; return true;
int LimitStart = abs(pData->m_Num-1);
const char *pOrder = pData->m_Num >= 0 ? "ASC" : "DESC";
try try
{ {
char aBuf[512]; char aBuf[512];
pSqlServer->executeSql("SET @prev := NULL;"); pSqlServer->executeSql("SET @prev := NULL;");
pSqlServer->executeSql("SET @rank := 1;"); pSqlServer->executeSql("SET @rank := 1;");
pSqlServer->executeSql("SET @pos := 0;"); pSqlServer->executeSql("SET @pos := 0;");
str_format(aBuf, sizeof(aBuf), "SELECT Rank, Points, Name FROM (SELECT Name, (@pos := @pos+1) pos, (@rank := IF(@prev = Points,@rank, @pos)) Rank, (@prev := Points) Points FROM (SELECT Name, Points FROM %s_points GROUP BY Name ORDER BY Points DESC) as a) as b LIMIT %d, 5;", pSqlServer->GetPrefix(), pData->m_Num-1); str_format(aBuf, sizeof(aBuf), "SELECT Rank, Points, Name FROM (SELECT Name, (@pos := @pos+1) pos, (@rank := IF(@prev = Points,@rank, @pos)) Rank, (@prev := Points) Points FROM (SELECT Name, Points FROM %s_points GROUP BY Name ORDER BY Points DESC) as a) as b ORDER BY Rank %s LIMIT %d, 5;", pSqlServer->GetPrefix(), pOrder, LimitStart);
pSqlServer->executeSqlQuery(aBuf); pSqlServer->executeSqlQuery(aBuf);