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

Method RandomUnfinishedMap

src/game/server/scoreworker.cpp:1560–1624  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1558}
1559
1560bool CScoreWorker::RandomUnfinishedMap(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize)
1561{
1562 const auto *pData = dynamic_cast<const CSqlRandomMapRequest *>(pGameData);
1563 auto *pResult = dynamic_cast<CScoreRandomMapResult *>(pGameData->m_pResult.get());
1564
1565 char aBuf[512];
1566 if(in_range(pData->m_MinStars, 0, 5) && in_range(pData->m_MaxStars, 0, 5))
1567 {
1568 str_format(aBuf, sizeof(aBuf),
1569 "SELECT Map "
1570 "FROM %s_maps "
1571 "WHERE Server = ? AND Map != ? AND Stars BETWEEN ? AND ? AND Map NOT IN ("
1572 " SELECT Map "
1573 " FROM %s_race "
1574 " WHERE Name = ?"
1575 ") ORDER BY %s "
1576 "LIMIT 1",
1577 pSqlServer->GetPrefix(), pSqlServer->GetPrefix(), pSqlServer->Random());
1578 if(!pSqlServer->PrepareStatement(aBuf, pError, ErrorSize))
1579 {
1580 return false;
1581 }
1582 pSqlServer->BindString(1, pData->m_aServerType);
1583 pSqlServer->BindString(2, pData->m_aCurrentMap);
1584 pSqlServer->BindInt(3, pData->m_MinStars);
1585 pSqlServer->BindInt(4, pData->m_MaxStars);
1586 pSqlServer->BindString(5, pData->m_aRequestingPlayer);
1587 }
1588 else
1589 {
1590 str_format(aBuf, sizeof(aBuf),
1591 "SELECT Map "
1592 "FROM %s_maps AS maps "
1593 "WHERE Server = ? AND Map != ? AND Map NOT IN ("
1594 " SELECT Map "
1595 " FROM %s_race as race "
1596 " WHERE Name = ?"
1597 ") ORDER BY %s "
1598 "LIMIT 1",
1599 pSqlServer->GetPrefix(), pSqlServer->GetPrefix(), pSqlServer->Random());
1600 if(!pSqlServer->PrepareStatement(aBuf, pError, ErrorSize))
1601 {
1602 return false;
1603 }
1604 pSqlServer->BindString(1, pData->m_aServerType);
1605 pSqlServer->BindString(2, pData->m_aCurrentMap);
1606 pSqlServer->BindString(3, pData->m_aRequestingPlayer);
1607 }
1608
1609 bool End;
1610 if(!pSqlServer->Step(&End, pError, ErrorSize))
1611 {
1612 return false;
1613 }
1614 if(!End)
1615 {
1616 pSqlServer->GetString(1, pResult->m_aMap, sizeof(pResult->m_aMap));
1617 }

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
BindStringMethod · 0.45
BindIntMethod · 0.45
StepMethod · 0.45
GetStringMethod · 0.45

Tested by

no test coverage detected