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

Method SaveScore

src/game/server/scoreworker.cpp:493–650  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

491}
492
493bool CScoreWorker::SaveScore(IDbConnection *pSqlServer, const ISqlData *pGameData, Write w, char *pError, int ErrorSize)
494{
495 const auto *pData = dynamic_cast<const CSqlScoreData *>(pGameData);
496 auto *pResult = dynamic_cast<CScorePlayerResult *>(pGameData->m_pResult.get());
497 auto *paMessages = pResult->m_Data.m_aaMessages;
498
499 char aBuf[1024];
500
501 if(w == Write::NORMAL_SUCCEEDED)
502 {
503 str_format(aBuf, sizeof(aBuf),
504 "DELETE FROM %s_race_backup WHERE GameId=? AND Name=? AND Timestamp=%s",
505 pSqlServer->GetPrefix(), pSqlServer->InsertTimestampAsUtc());
506 if(!pSqlServer->PrepareStatement(aBuf, pError, ErrorSize))
507 {
508 return false;
509 }
510 pSqlServer->BindString(1, pData->m_aGameUuid);
511 pSqlServer->BindString(2, pData->m_aName);
512 pSqlServer->BindString(3, pData->m_aTimestamp);
513 pSqlServer->Print();
514 int NumDeleted;
515 if(!pSqlServer->ExecuteUpdate(&NumDeleted, pError, ErrorSize))
516 {
517 return false;
518 }
519 if(NumDeleted == 0)
520 {
521 log_warn("sql", "Rank got moved out of backup database, will show up as duplicate rank in MySQL");
522 }
523 return true;
524 }
525 if(w == Write::NORMAL_FAILED)
526 {
527 int NumUpdated;
528 // move to non-tmp table succeeded. delete from backup again
529 str_format(aBuf, sizeof(aBuf),
530 "INSERT INTO %s_race SELECT * FROM %s_race_backup WHERE GameId=? AND Name=? AND Timestamp=%s",
531 pSqlServer->GetPrefix(), pSqlServer->GetPrefix(), pSqlServer->InsertTimestampAsUtc());
532 if(!pSqlServer->PrepareStatement(aBuf, pError, ErrorSize))
533 {
534 return false;
535 }
536 pSqlServer->BindString(1, pData->m_aGameUuid);
537 pSqlServer->BindString(2, pData->m_aName);
538 pSqlServer->BindString(3, pData->m_aTimestamp);
539 pSqlServer->Print();
540 if(!pSqlServer->ExecuteUpdate(&NumUpdated, pError, ErrorSize))
541 {
542 return false;
543 }
544
545 // move to non-tmp table succeeded. delete from backup again
546 str_format(aBuf, sizeof(aBuf),
547 "DELETE FROM %s_race_backup WHERE GameId=? AND Name=? AND Timestamp=%s",
548 pSqlServer->GetPrefix(), pSqlServer->InsertTimestampAsUtc());
549 if(!pSqlServer->PrepareStatement(aBuf, pError, ErrorSize))
550 {

Callers

nothing calls this directly

Calls 13

str_formatFunction · 0.85
getMethod · 0.80
GetPrefixMethod · 0.80
InsertTimestampAsUtcMethod · 0.45
PrepareStatementMethod · 0.45
BindStringMethod · 0.45
PrintMethod · 0.45
ExecuteUpdateMethod · 0.45
StepMethod · 0.45
GetIntMethod · 0.45
AddPointsMethod · 0.45
InsertIgnoreMethod · 0.45

Tested by

no test coverage detected