3690: Update to /top feature r=def- a=houseme-kyle

Feedback from the community. It will hide the local ranks if there are any duplicates so the larger communities, who were previously disadvantaged by the change aren't anymore. 

Added an extra rank to the global list seeing that it is still smaller than the combined

![image](https://user-images.githubusercontent.com/25198124/110504260-a8b22980-8105-11eb-9d76-21cf5b7672cc.png)

![image](https://user-images.githubusercontent.com/25198124/110504302-b23b9180-8105-11eb-947a-2de2c3f1851a.png)

## Checklist

- [x] Tested the change ingame
- [x] Provided screenshots if it is a visual change
- [x] Tested in combination with possibly related configuration options
- [ ] Written a unit test if it works standalone, system.c especially
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: houseme-kyle <kyle@houseme.co.za>
Co-authored-by: Kyle Bradley <kyle@house.me>
This commit is contained in:
bors[bot] 2021-03-09 18:13:18 +00:00 committed by GitHub
commit d721e8ff2d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 60 additions and 35 deletions

View file

@ -35,8 +35,8 @@ CHAT_COMMAND("teamrank", "?r[player name]", CFGFLAG_CHAT | CFGFLAG_SERVER, ConTe
CHAT_COMMAND("rank", "?r[player name]", CFGFLAG_CHAT | CFGFLAG_SERVER, ConRank, this, "Shows the rank of player with name r (your rank by default)")
CHAT_COMMAND("top5team", "?s[player name] ?i[rank to start with]", CFGFLAG_CHAT | CFGFLAG_SERVER, ConTeamTop5, this, "Shows five team ranks of the ladder or of a player beginning with rank i (1 by default, -1 for worst)")
CHAT_COMMAND("teamtop5", "?s[player name] ?i[rank to start with]", CFGFLAG_CHAT | CFGFLAG_SERVER, ConTeamTop5, this, "Shows five team ranks of the ladder or of a player beginning with rank i (1 by default, -1 for worst)")
CHAT_COMMAND("top", "?i[rank to start with]", CFGFLAG_CHAT | CFGFLAG_SERVER, ConTop, this, "Shows five ranks of the global and regional ladder beginning with rank i (1 by default, -1 for worst)")
CHAT_COMMAND("top5", "?i[rank to start with]", CFGFLAG_CHAT | CFGFLAG_SERVER, ConTop, this, "Shows five ranks of the global and regional ladder beginning with rank i (1 by default, -1 for worst)")
CHAT_COMMAND("top", "?i[rank to start with]", CFGFLAG_CHAT | CFGFLAG_SERVER, ConTop, this, "Shows the top ranks of the global and regional ladder beginning with rank i (1 by default, -1 for worst)")
CHAT_COMMAND("top5", "?i[rank to start with]", CFGFLAG_CHAT | CFGFLAG_SERVER, ConTop, this, "Shows the top ranks of the global and regional ladder beginning with rank i (1 by default, -1 for worst)")
CHAT_COMMAND("times", "?s[player name] ?i[number of times to skip]", CFGFLAG_CHAT | CFGFLAG_SERVER, ConTimes, this, "/times ?s?i shows last 5 times of the server or of a player beginning with name s starting with time i (i = 1 by default, -1 for first)")
CHAT_COMMAND("points", "?r[player name]", CFGFLAG_CHAT | CFGFLAG_SERVER, ConPoints, this, "Shows the global points of a player beginning with name r (your rank by default)")
CHAT_COMMAND("top5points", "?i[number]", CFGFLAG_CHAT | CFGFLAG_SERVER, ConTopPoints, this, "Shows five points of the global point ladder beginning with rank i (1 by default)")

View file

@ -975,9 +975,9 @@ bool CScore::ShowTopThread(IDbConnection *pSqlServer, const ISqlData *pGameData,
// check sort method
char aBuf[512];
str_format(aBuf, sizeof(aBuf),
"SELECT Name, Time, Rank "
"SELECT Name, Time, Rank, Server "
"FROM ("
" SELECT RANK() OVER w AS Rank, Name, MIN(Time) AS Time "
" SELECT RANK() OVER w AS Rank, Name, MIN(Time) AS Time, Server "
" FROM %s_race "
" WHERE Map = ? "
" AND Server LIKE ? "
@ -985,7 +985,7 @@ bool CScore::ShowTopThread(IDbConnection *pSqlServer, const ISqlData *pGameData,
" WINDOW w AS (ORDER BY Time)"
") as a "
"ORDER BY Rank %s "
"LIMIT %d, 3;",
"LIMIT %d, ?;",
pSqlServer->GetPrefix(),
pOrder,
LimitStart);
@ -996,40 +996,17 @@ bool CScore::ShowTopThread(IDbConnection *pSqlServer, const ISqlData *pGameData,
}
pSqlServer->BindString(1, pData->m_Map);
pSqlServer->BindString(2, pAny);
pSqlServer->BindInt(3, 6);
// show top
str_copy(pResult->m_Data.m_aaMessages[0], "-----------< Global Top 3 >-----------", sizeof(pResult->m_Data.m_aaMessages[0]));
char aTime[32];
int Line = 1;
bool End = false;
while(!pSqlServer->Step(&End, pError, ErrorSize) && !End)
{
char aName[MAX_NAME_LENGTH];
pSqlServer->GetString(1, aName, sizeof(aName));
float Time = pSqlServer->GetFloat(2);
str_time_float(Time, TIME_HOURS_CENTISECS, aTime, sizeof(aTime));
int Rank = pSqlServer->GetInt(3);
str_format(pResult->m_Data.m_aaMessages[Line], sizeof(pResult->m_Data.m_aaMessages[Line]),
"%d. %s Time: %s", Rank, aName, aTime);
Line++;
}
char aServerLike[16];
str_format(aServerLike, sizeof(aServerLike), "%%%s%%", pData->m_Server);
if(pSqlServer->PrepareStatement(aBuf, pError, ErrorSize))
{
return true;
}
pSqlServer->BindString(1, pData->m_Map);
pSqlServer->BindString(2, aServerLike);
str_format(pResult->m_Data.m_aaMessages[Line], sizeof(pResult->m_Data.m_aaMessages[Line]),
"-----------< %s Top 3 >-----------", pData->m_Server);
int Line = 0;
str_copy(pResult->m_Data.m_aaMessages[Line], "------------ Global Top ------------", sizeof(pResult->m_Data.m_aaMessages[Line]));
Line++;
// show top
char aTime[32];
bool End = false;
bool HasLocal = false;
while(!pSqlServer->Step(&End, pError, ErrorSize) && !End)
{
char aName[MAX_NAME_LENGTH];
@ -1039,8 +1016,56 @@ bool CScore::ShowTopThread(IDbConnection *pSqlServer, const ISqlData *pGameData,
int Rank = pSqlServer->GetInt(3);
str_format(pResult->m_Data.m_aaMessages[Line], sizeof(pResult->m_Data.m_aaMessages[Line]),
"%d. %s Time: %s", Rank, aName, aTime);
char aRecordServer[6];
pSqlServer->GetString(4, aRecordServer, sizeof(aRecordServer));
HasLocal = HasLocal || str_comp(aRecordServer, pData->m_Server) == 0;
Line++;
if(!HasLocal && Line == 4)
{
break;
}
}
if(!HasLocal)
{
char aServerLike[16];
str_format(aServerLike, sizeof(aServerLike), "%%%s%%", pData->m_Server);
if(pSqlServer->PrepareStatement(aBuf, pError, ErrorSize))
{
return true;
}
pSqlServer->BindString(1, pData->m_Map);
pSqlServer->BindString(2, aServerLike);
pSqlServer->BindInt(3, 3);
str_format(pResult->m_Data.m_aaMessages[Line], sizeof(pResult->m_Data.m_aaMessages[Line]),
"------------ %s Top ------------", pData->m_Server);
Line++;
// show top
while(!pSqlServer->Step(&End, pError, ErrorSize) && !End)
{
char aName[MAX_NAME_LENGTH];
pSqlServer->GetString(1, aName, sizeof(aName));
float Time = pSqlServer->GetFloat(2);
str_time_float(Time, TIME_HOURS_CENTISECS, aTime, sizeof(aTime));
int Rank = pSqlServer->GetInt(3);
str_format(pResult->m_Data.m_aaMessages[Line], sizeof(pResult->m_Data.m_aaMessages[Line]),
"%d. %s Time: %s", Rank, aName, aTime);
Line++;
}
}
else
{
str_copy(pResult->m_Data.m_aaMessages[Line], "---------------------------------------",
sizeof(pResult->m_Data.m_aaMessages[Line]));
}
if(!End)
{
return true;