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

Method ShowTopPoints

src/game/server/scoreworker.cpp:1460–1507  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1458}
1459
1460bool CScoreWorker::ShowTopPoints(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize)
1461{
1462 const auto *pData = dynamic_cast<const CSqlPlayerRequest *>(pGameData);
1463 auto *pResult = dynamic_cast<CScorePlayerResult *>(pGameData->m_pResult.get());
1464 auto *paMessages = pResult->m_Data.m_aaMessages;
1465
1466 int LimitStart = maximum(pData->m_Offset - 1, 0);
1467
1468 char aBuf[512];
1469 str_format(aBuf, sizeof(aBuf),
1470 "SELECT RANK() OVER (ORDER BY a.Points DESC) as Ranking, Points, Name "
1471 "FROM ("
1472 " SELECT Points, Name "
1473 " FROM %s_points "
1474 " ORDER BY Points DESC LIMIT ?"
1475 ") as a "
1476 "ORDER BY Ranking ASC, Name ASC LIMIT ?, 5",
1477 pSqlServer->GetPrefix());
1478 if(!pSqlServer->PrepareStatement(aBuf, pError, ErrorSize))
1479 {
1480 return false;
1481 }
1482 pSqlServer->BindInt(1, LimitStart + 5);
1483 pSqlServer->BindInt(2, LimitStart);
1484
1485 // show top points
1486 str_copy(paMessages[0], "-------- Top Points --------", sizeof(paMessages[0]));
1487
1488 bool End = false;
1489 int Line = 1;
1490 while(pSqlServer->Step(&End, pError, ErrorSize) && !End)
1491 {
1492 int Rank = pSqlServer->GetInt(1);
1493 int Points = pSqlServer->GetInt(2);
1494 char aName[MAX_NAME_LENGTH];
1495 pSqlServer->GetString(3, aName, sizeof(aName));
1496 str_format(paMessages[Line], sizeof(paMessages[Line]),
1497 "%d. %s Points: %d", Rank, aName, Points);
1498 Line++;
1499 }
1500 if(!End)
1501 {
1502 return false;
1503 }
1504 str_copy(paMessages[Line], "-------------------------------", sizeof(paMessages[Line]));
1505
1506 return true;
1507}
1508
1509bool CScoreWorker::RandomMap(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize)
1510{

Callers

nothing calls this directly

Calls 10

maximumFunction · 0.85
str_formatFunction · 0.85
getMethod · 0.80
GetPrefixMethod · 0.80
str_copyFunction · 0.50
PrepareStatementMethod · 0.45
BindIntMethod · 0.45
StepMethod · 0.45
GetIntMethod · 0.45
GetStringMethod · 0.45

Tested by

no test coverage detected