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

Method RandomMap

src/game/server/scoreworker.cpp:1509–1558  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1507}
1508
1509bool CScoreWorker::RandomMap(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize)
1510{
1511 const auto *pData = dynamic_cast<const CSqlRandomMapRequest *>(pGameData);
1512 auto *pResult = dynamic_cast<CScoreRandomMapResult *>(pGameData->m_pResult.get());
1513
1514 char aBuf[512];
1515 if(in_range(pData->m_MinStars, 0, 5) && in_range(pData->m_MaxStars, 0, 5))
1516 {
1517 str_format(aBuf, sizeof(aBuf),
1518 "SELECT Map FROM %s_maps "
1519 "WHERE Server = ? AND Map != ? AND Stars BETWEEN ? AND ? "
1520 "ORDER BY %s LIMIT 1",
1521 pSqlServer->GetPrefix(), pSqlServer->Random());
1522 if(!pSqlServer->PrepareStatement(aBuf, pError, ErrorSize))
1523 {
1524 return false;
1525 }
1526 pSqlServer->BindInt(3, pData->m_MinStars);
1527 pSqlServer->BindInt(4, pData->m_MaxStars);
1528 }
1529 else
1530 {
1531 str_format(aBuf, sizeof(aBuf),
1532 "SELECT Map FROM %s_maps "
1533 "WHERE Server = ? AND Map != ? "
1534 "ORDER BY %s LIMIT 1",
1535 pSqlServer->GetPrefix(), pSqlServer->Random());
1536 if(!pSqlServer->PrepareStatement(aBuf, pError, ErrorSize))
1537 {
1538 return false;
1539 }
1540 }
1541 pSqlServer->BindString(1, pData->m_aServerType);
1542 pSqlServer->BindString(2, pData->m_aCurrentMap);
1543
1544 bool End;
1545 if(!pSqlServer->Step(&End, pError, ErrorSize))
1546 {
1547 return false;
1548 }
1549 if(!End)
1550 {
1551 pSqlServer->GetString(1, pResult->m_aMap, sizeof(pResult->m_aMap));
1552 }
1553 else
1554 {
1555 str_copy(pResult->m_aMessage, "No maps found on this server!", sizeof(pResult->m_aMessage));
1556 }
1557 return true;
1558}
1559
1560bool CScoreWorker::RandomUnfinishedMap(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize)
1561{

Callers

nothing calls this directly

Calls 11

in_rangeFunction · 0.85
str_formatFunction · 0.85
getMethod · 0.80
GetPrefixMethod · 0.80
str_copyFunction · 0.50
RandomMethod · 0.45
PrepareStatementMethod · 0.45
BindIntMethod · 0.45
BindStringMethod · 0.45
StepMethod · 0.45
GetStringMethod · 0.45

Tested by

no test coverage detected