Skip to content

Commit

Permalink
Add own time to /mapinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
def- committed Apr 21, 2017
1 parent 63ca2f8 commit 9da2655
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/game/server/score/sql_score.cpp
Expand Up @@ -366,6 +366,7 @@ void CSqlScore::MapInfo(int ClientID, const char* MapName)
CSqlMapData *Tmp = new CSqlMapData();
Tmp->m_ClientID = ClientID;
Tmp->m_RequestedMap = MapName;
Tmp->m_Name = Server()->ClientName(ClientID);
str_copy(Tmp->m_aFuzzyMap, MapName, sizeof(Tmp->m_aFuzzyMap));
sqlstr::ClearString(Tmp->m_aFuzzyMap, sizeof(Tmp->m_aFuzzyMap));
sqlstr::FuzzyString(Tmp->m_aFuzzyMap, sizeof(Tmp->m_aFuzzyMap));
Expand All @@ -384,7 +385,7 @@ bool CSqlScore::MapInfoThread(CSqlServer* pSqlServer, const CSqlData *pGameData,
try
{
char aBuf[1024];
str_format(aBuf, sizeof(aBuf), "SELECT l.Map, l.Server, Mapper, Points, Stars, (select count(Name) from %s_race where Map = l.Map) as Finishes, (select count(distinct Name) from %s_race where Map = l.Map) as Finishers, (select round(avg(Time)) from %s_race where Map = l.Map) as Average, UNIX_TIMESTAMP(l.Timestamp) as Stamp, UNIX_TIMESTAMP(CURRENT_TIMESTAMP)-UNIX_TIMESTAMP(l.Timestamp) as Ago FROM (SELECT * FROM %s_maps WHERE Map LIKE '%s' COLLATE utf8_general_ci ORDER BY CASE WHEN Map = '%s' THEN 0 ELSE 1 END, CASE WHEN Map LIKE '%s%%' THEN 0 ELSE 1 END, LENGTH(Map), Map LIMIT 1) as l;", pSqlServer->GetPrefix(), pSqlServer->GetPrefix(), pSqlServer->GetPrefix(), pSqlServer->GetPrefix(), pData->m_aFuzzyMap, pData->m_RequestedMap.ClrStr(), pData->m_RequestedMap.ClrStr());
str_format(aBuf, sizeof(aBuf), "SELECT l.Map, l.Server, Mapper, Points, Stars, (select count(Name) from %s_race where Map = l.Map) as Finishes, (select count(distinct Name) from %s_race where Map = l.Map) as Finishers, (select round(avg(Time)) from %s_race where Map = l.Map) as Average, UNIX_TIMESTAMP(l.Timestamp) as Stamp, UNIX_TIMESTAMP(CURRENT_TIMESTAMP)-UNIX_TIMESTAMP(l.Timestamp) as Ago, (select min(Time) from %s_race where Map = l.Map and Name = '%s') as OwnTime FROM (SELECT * FROM %s_maps WHERE Map LIKE '%s' COLLATE utf8_general_ci ORDER BY CASE WHEN Map = '%s' THEN 0 ELSE 1 END, CASE WHEN Map LIKE '%s%%' THEN 0 ELSE 1 END, LENGTH(Map), Map LIMIT 1) as l;", pSqlServer->GetPrefix(), pSqlServer->GetPrefix(), pSqlServer->GetPrefix(), pSqlServer->GetPrefix(), pData->m_Name.ClrStr(), pSqlServer->GetPrefix(), pData->m_aFuzzyMap, pData->m_RequestedMap.ClrStr(), pData->m_RequestedMap.ClrStr());
pSqlServer->executeSqlQuery(aBuf);

if(pSqlServer->GetResults()->rowsCount() != 1)
Expand All @@ -407,6 +408,7 @@ bool CSqlScore::MapInfoThread(CSqlServer* pSqlServer, const CSqlData *pGameData,
strcpy(aMapper, pSqlServer->GetResults()->getString("Mapper").c_str());
int stamp = (int)pSqlServer->GetResults()->getInt("Stamp");
int ago = (int)pSqlServer->GetResults()->getInt("Ago");
float ownTime = (float)pSqlServer->GetResults()->getDouble("OwnTime");

char pAgoString[40] = "\0";
char pReleasedString[60] = "\0";
Expand Down Expand Up @@ -434,7 +436,13 @@ bool CSqlScore::MapInfoThread(CSqlServer* pSqlServer, const CSqlData *pGameData,
default: aStars[0] = '\0';
}

str_format(aBuf, sizeof(aBuf), "\"%s\" by %s on %s (%s, %d %s, %d %s by %d %s%s%s)", aMap, aMapper, aServer, aStars, points, points == 1 ? "point" : "points", finishes, finishes == 1 ? "finish" : "finishes", finishers, finishers == 1 ? "tee" : "tees", pAverageString, pReleasedString);
char pOwnFinishesString[40] = "\0";
if(ownTime > 0)
{
str_format(pOwnFinishesString, sizeof(pOwnFinishesString), ", your time: %02d:%05.2f", (int)(ownTime/60), ownTime-((int)ownTime/60*60));
}

str_format(aBuf, sizeof(aBuf), "\"%s\" by %s on %s, %s, %d %s%s, %d %s by %d %s%s%s", aMap, aMapper, aServer, aStars, points, points == 1 ? "point" : "points", pReleasedString, finishes, finishes == 1 ? "finish" : "finishes", finishers, finishers == 1 ? "tee" : "tees", pAverageString, pOwnFinishesString);
}

pData->GameServer()->SendChatTarget(pData->m_ClientID, aBuf);
Expand Down
1 change: 1 addition & 0 deletions src/game/server/score/sql_score.h
Expand Up @@ -90,6 +90,7 @@ struct CSqlMapData : CSqlData

sqlstr::CSqlString<128> m_RequestedMap;
char m_aFuzzyMap[128];
sqlstr::CSqlString<MAX_NAME_LENGTH> m_Name;
};

struct CSqlScoreData : CSqlData
Expand Down

0 comments on commit 9da2655

Please sign in to comment.