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

Method ShowTimes

src/game/server/scoreworker.cpp:1300–1413  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1298}
1299
1300bool CScoreWorker::ShowTimes(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize)
1301{
1302 const auto *pData = dynamic_cast<const CSqlPlayerRequest *>(pGameData);
1303 auto *pResult = dynamic_cast<CScorePlayerResult *>(pGameData->m_pResult.get());
1304 auto *paMessages = pResult->m_Data.m_aaMessages;
1305
1306 int LimitStart = maximum(absolute(pData->m_Offset) - 1, 0);
1307 const char *pOrder = pData->m_Offset >= 0 ? "DESC" : "ASC";
1308
1309 char aCurrentTimestamp[512];
1310 pSqlServer->ToUnixTimestamp("CURRENT_TIMESTAMP", aCurrentTimestamp, sizeof(aCurrentTimestamp));
1311 char aTimestamp[512];
1312 pSqlServer->ToUnixTimestamp("Timestamp", aTimestamp, sizeof(aTimestamp));
1313 char aBuf[512];
1314 if(pData->m_aName[0] != '\0') // last 5 times of a player
1315 {
1316 str_format(aBuf, sizeof(aBuf),
1317 "SELECT Time, (%s-%s) as Ago, %s as Stamp, Server "
1318 "FROM %s_race "
1319 "WHERE Map = ? AND Name = ? "
1320 "ORDER BY Timestamp %s "
1321 "LIMIT ?, 5",
1322 aCurrentTimestamp, aTimestamp, aTimestamp,
1323 pSqlServer->GetPrefix(), pOrder);
1324 if(!pSqlServer->PrepareStatement(aBuf, pError, ErrorSize))
1325 {
1326 return false;
1327 }
1328 pSqlServer->BindString(1, pData->m_aMap);
1329 pSqlServer->BindString(2, pData->m_aName);
1330 pSqlServer->BindInt(3, LimitStart);
1331 }
1332 else // last 5 times of server
1333 {
1334 str_format(aBuf, sizeof(aBuf),
1335 "SELECT Time, (%s-%s) as Ago, %s as Stamp, Server, Name "
1336 "FROM %s_race "
1337 "WHERE Map = ? "
1338 "ORDER BY Timestamp %s "
1339 "LIMIT ?, 5",
1340 aCurrentTimestamp, aTimestamp, aTimestamp,
1341 pSqlServer->GetPrefix(), pOrder);
1342 if(!pSqlServer->PrepareStatement(aBuf, pError, ErrorSize))
1343 {
1344 return false;
1345 }
1346 pSqlServer->BindString(1, pData->m_aMap);
1347 pSqlServer->BindInt(2, LimitStart);
1348 }
1349
1350 // show top5
1351 bool End;
1352 if(!pSqlServer->Step(&End, pError, ErrorSize))
1353 {
1354 return false;
1355 }
1356 if(End)
1357 {

Callers

nothing calls this directly

Calls 15

maximumFunction · 0.85
absoluteFunction · 0.85
str_formatFunction · 0.85
str_time_floatFunction · 0.85
str_compFunction · 0.85
getMethod · 0.80
GetPrefixMethod · 0.80
str_copyFunction · 0.50
ToUnixTimestampMethod · 0.45
PrepareStatementMethod · 0.45
BindStringMethod · 0.45
BindIntMethod · 0.45

Tested by

no test coverage detected