MCPcopy Create free account
hub / github.com/ddnet/ddnet / ShowRank

Method ShowRank

src/game/server/scoreworker.cpp:822–933  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

820}
821
822bool CScoreWorker::ShowRank(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize)
823{
824 const auto *pData = dynamic_cast<const CSqlPlayerRequest *>(pGameData);
825 auto *pResult = dynamic_cast<CScorePlayerResult *>(pGameData->m_pResult.get());
826
827 char aServerLike[16];
828 str_format(aServerLike, sizeof(aServerLike), "%%%s%%", pData->m_aServer);
829
830 // check sort method
831 char aBuf[600];
832 str_format(aBuf, sizeof(aBuf),
833 "SELECT Ranking, Time, PercentRank "
834 "FROM ("
835 " SELECT RANK() OVER w AS Ranking, PERCENT_RANK() OVER w as PercentRank, MIN(Time) AS Time, Name "
836 " FROM %s_race "
837 " WHERE Map = ? "
838 " AND Server LIKE ? "
839 " GROUP BY Name "
840 " WINDOW w AS (ORDER BY MIN(Time))"
841 ") as a "
842 "WHERE Name = ?",
843 pSqlServer->GetPrefix());
844
845 if(!pSqlServer->PrepareStatement(aBuf, pError, ErrorSize))
846 {
847 return false;
848 }
849 pSqlServer->BindString(1, pData->m_aMap);
850 pSqlServer->BindString(2, aServerLike);
851 pSqlServer->BindString(3, pData->m_aName);
852
853 bool End;
854 if(!pSqlServer->Step(&End, pError, ErrorSize))
855 {
856 return false;
857 }
858
859 char aRegionalRank[16];
860 if(End)
861 {
862 str_copy(aRegionalRank, "unranked", sizeof(aRegionalRank));
863 }
864 else
865 {
866 str_format(aRegionalRank, sizeof(aRegionalRank), "rank %d", pSqlServer->GetInt(1));
867 }
868
869 const char *pAny = "%";
870
871 if(!pSqlServer->PrepareStatement(aBuf, pError, ErrorSize))
872 {
873 return false;
874 }
875 pSqlServer->BindString(1, pData->m_aMap);
876 pSqlServer->BindString(2, pAny);
877 pSqlServer->BindString(3, pData->m_aName);
878
879 if(!pSqlServer->Step(&End, pError, ErrorSize))

Callers

nothing calls this directly

Calls 11

str_formatFunction · 0.85
str_time_floatFunction · 0.85
str_comp_nocaseFunction · 0.85
getMethod · 0.80
GetPrefixMethod · 0.80
str_copyFunction · 0.50
PrepareStatementMethod · 0.45
BindStringMethod · 0.45
StepMethod · 0.45
GetIntMethod · 0.45
GetFloatMethod · 0.45

Tested by

no test coverage detected