DDNet documentation
Loading...
Searching...
No Matches
scoreworker.h
Go to the documentation of this file.
1#ifndef GAME_SERVER_SCOREWORKER_H
2#define GAME_SERVER_SCOREWORKER_H
3
4#include <base/str.h>
5
6#include <engine/map.h>
10
11#include <game/server/save.h>
12#include <game/voting.h>
13
14#include <memory>
15#include <optional>
16#include <string>
17#include <utility>
18#include <vector>
19
20class IDbConnection;
21class IGameController;
22
23enum
24{
26 TIMESTAMP_STR_LENGTH = 20, // 2019-04-02 19:38:36
27 // Every team member name at maximum length, joined by ", " and " & ".
29};
30
32{
34
35 enum
36 {
38 };
39
49 union
50 {
51 char m_aaMessages[MAX_MESSAGES][512];
52 char m_aBroadcast[1024];
53 struct
54 {
55 std::optional<float> m_Time;
57 int m_Birthday; // 0 indicates no birthday
59 } m_Info = {};
60 struct
61 {
63 char m_aServer[32 + 1];
64 char m_aMap[MAX_MAP_LENGTH + 1];
65 } m_MapVote;
66 } m_Data = {}; // PLAYER_INFO
67
68 void SetVariant(Variant v);
69};
70
72{
73 std::optional<float> m_CurrentRecord = std::nullopt;
74};
75
77{
78 CSqlLoadBestTimeRequest(std::shared_ptr<CScoreLoadBestTimeResult> pResult) :
79 ISqlData(std::move(pResult))
80 {
81 }
82
83 // current map
85};
86
88{
89 CSqlPlayerRequest(std::shared_ptr<CScorePlayerResult> pResult) :
90 ISqlData(std::move(pResult))
91 {
92 }
93
94 // object being requested, either map (128 bytes) or player (16 bytes)
96 // current map
99 // relevant for /top5 kind of requests
101 char m_aServer[5];
102};
103
105{
106 CScoreRandomMapResult(int ClientId) :
107 m_ClientId(ClientId)
108 {
109 m_aMap[0] = '\0';
110 m_aMessage[0] = '\0';
111 }
114 char m_aMessage[512];
115};
116
118{
119 CSqlRandomMapRequest(std::shared_ptr<CScoreRandomMapResult> pResult) :
120 ISqlData(std::move(pResult))
121 {
122 }
123
129};
130
132{
133 CSqlScoreData(std::shared_ptr<CScorePlayerResult> pResult) :
134 ISqlData(std::move(pResult))
135 {
136 }
137
141
143 float m_Time;
146 int m_Num;
149};
150
152{
153 CScoreSaveResult(int PlayerId, const char *pPlayerName, const char *pServer) :
155 m_RequestingPlayer(PlayerId)
156 {
157 m_aMessage[0] = '\0';
158 m_aBroadcast[0] = '\0';
159 m_aCode[0] = '\0';
160 m_aGeneratedCode[0] = '\0';
161 str_copy(m_aRequestingPlayer, pPlayerName);
162 str_copy(m_aServer, pServer);
163 }
164 enum
165 {
169 // load team in the following two cases
174 char m_aMessage[512];
175 char m_aBroadcast[512];
180 char m_aServer[5];
181 char m_aCode[128];
183};
184
200
202{
203 CSqlTeamSaveData(std::shared_ptr<CScoreSaveResult> pResult) :
204 ISqlData(std::move(pResult))
205 {
206 }
207
210 char m_aCode[128];
212 char m_aServer[5];
213};
214
216{
217 CSqlTeamLoadRequest(std::shared_ptr<CScoreSaveResult> pResult) :
218 ISqlData(std::move(pResult))
219 {
220 }
221
222 char m_aCode[128];
225 // struct holding all player names in the team or an empty string
229};
230
232{
233public:
235 {
236 Reset();
237 }
238
239 void Reset()
240 {
241 m_BestTime.reset();
242 for(float &BestTimeCp : m_aBestTimeCp)
243 BestTimeCp = 0;
244
245 m_RecordStopTick = -1;
246 }
247
248 void Set(float Time, const float aTimeCp[NUM_CHECKPOINTS])
249 {
250 m_BestTime = Time;
251 for(int i = 0; i < NUM_CHECKPOINTS; i++)
252 m_aBestTimeCp[i] = aTimeCp[i];
253 }
254
255 void SetBestTimeCp(const float aTimeCp[NUM_CHECKPOINTS])
256 {
257 for(int i = 0; i < NUM_CHECKPOINTS; i++)
258 m_aBestTimeCp[i] = aTimeCp[i];
259 }
260
261 std::optional<float> m_BestTime;
263
266};
267
269{
272 unsigned int m_NumNames;
273 CTeamrank();
274
275 // Assumes that a database query equivalent to
276 //
277 // SELECT TeamId, Name [, ...] -- the order is important
278 // FROM record_teamrace
279 // ORDER BY TeamId, Name
280 //
281 // was executed and that the result line of the first team member is already selected.
282 // Afterwards the team member of the next team is selected.
283 //
284 // Returns true on SQL failure
285 //
286 // if another team can be extracted
287 bool NextSqlResult(IDbConnection *pSqlServer, bool *pEnd, char *pError, int ErrorSize);
288
289 bool SamePlayers(const std::vector<std::string> *pvSortedNames);
290
291 // Formats the names into pBuf, joined by ", " and " & ". Names that don't
292 // fit are summarized as " & %d more".
293 void FormatNames(char *pBuf, int BufSize) const;
294
295 void FormatTeamTopLine(char *pMessage, int MessageSize, int Rank, const char *pTime) const;
296
297 static bool GetSqlTop5Team(IDbConnection *pSqlServer, bool *pEnd, char *pError, int ErrorSize, char (*paMessages)[512], int *StartLine, int Count);
298};
299
301{
302 static bool LoadBestTime(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize);
303
304 static bool RandomMap(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize);
305 static bool RandomUnfinishedMap(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize);
306 static bool MapVote(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize);
307
308 static bool LoadPlayerData(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize);
309 static bool LoadPlayerTimeCp(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize);
310 static bool MapInfo(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize);
311 static bool ShowRank(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize);
312 static bool ShowTeamRank(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize);
313 static bool ShowTop(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize);
314 static bool ShowTeamTop5(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize);
315 static bool ShowPlayerTeamTop5(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize);
316 static bool ShowTimes(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize);
317 static bool ShowPoints(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize);
318 static bool ShowTopPoints(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize);
319 static bool GetSaves(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize);
320
321 static bool SaveTeam(IDbConnection *pSqlServer, const ISqlData *pGameData, Write w, char *pError, int ErrorSize);
322 static bool LoadTeam(IDbConnection *pSqlServer, const ISqlData *pGameData, Write w, char *pError, int ErrorSize);
323
324 static bool SaveScore(IDbConnection *pSqlServer, const ISqlData *pGameData, Write w, char *pError, int ErrorSize);
325 static bool SaveTeamScore(IDbConnection *pSqlServer, const ISqlData *pGameData, Write w, char *pError, int ErrorSize);
326};
327
328#endif // GAME_SERVER_SCOREWORKER_H
float m_RecordFinishTime
Definition scoreworker.h:265
float m_aBestTimeCp[NUM_CHECKPOINTS]
Definition scoreworker.h:262
std::optional< float > m_BestTime
Definition scoreworker.h:261
void Set(float Time, const float aTimeCp[NUM_CHECKPOINTS])
Definition scoreworker.h:248
int m_RecordStopTick
Definition scoreworker.h:264
void SetBestTimeCp(const float aTimeCp[NUM_CHECKPOINTS])
Definition scoreworker.h:255
CPlayerData()
Definition scoreworker.h:234
void Reset()
Definition scoreworker.h:239
Definition save.h:181
Definition connection.h:19
Definition gamecontroller.h:24
Write
Definition connection_pool.h:37
@ MAX_MAP_LENGTH
Definition map.h:16
int str_copy(char *dst, const char *src, int dst_size)
Definition str.cpp:18
@ MAX_CHECKPOINTS
Definition protocol.h:93
@ MAX_CLIENTS
Definition protocol.h:89
@ MAX_NAME_LENGTH
Definition protocol.h:109
@ MAX_TEAM_NAMES_LENGTH
Definition scoreworker.h:28
@ TIMESTAMP_STR_LENGTH
Definition scoreworker.h:26
@ NUM_CHECKPOINTS
Definition scoreworker.h:25
Definition scoreworker.h:72
std::optional< float > m_CurrentRecord
Definition scoreworker.h:73
union CScorePlayerResult::@306052261263210267064004055070110266005066160136 m_Data
void SetVariant(Variant v)
Definition scoreworker.cpp:27
CScorePlayerResult()
Definition scoreworker.cpp:22
@ MAX_MESSAGES
Definition scoreworker.h:37
enum CScorePlayerResult::Variant m_MessageKind
Variant
Definition scoreworker.h:41
@ PLAYER_TIMECP
Definition scoreworker.h:47
@ BROADCAST
Definition scoreworker.h:44
@ DIRECT
Definition scoreworker.h:42
@ MAP_VOTE
Definition scoreworker.h:45
@ ALL
Definition scoreworker.h:43
@ PLAYER_INFO
Definition scoreworker.h:46
char m_aMessage[512]
Definition scoreworker.h:114
CScoreRandomMapResult(int ClientId)
Definition scoreworker.h:106
char m_aMap[MAX_MAP_LENGTH]
Definition scoreworker.h:113
int m_ClientId
Definition scoreworker.h:112
char m_aCode[128]
Definition scoreworker.h:181
CScoreSaveResult(int PlayerId, const char *pPlayerName, const char *pServer)
Definition scoreworker.h:153
int m_RequestingPlayer
Definition scoreworker.h:177
char m_aMessage[512]
Definition scoreworker.h:174
CSaveTeam m_SavedTeam
Definition scoreworker.h:176
char m_aRequestingPlayer[MAX_NAME_LENGTH]
Definition scoreworker.h:178
@ LOAD_FAILED
Definition scoreworker.h:172
@ SAVE_FAILED
Definition scoreworker.h:170
@ SAVE_SUCCESS
Definition scoreworker.h:166
@ LOAD_SUCCESS
Definition scoreworker.h:171
@ SAVE_FALLBACKFILE
Definition scoreworker.h:168
@ SAVE_WARNING
Definition scoreworker.h:167
CUuid m_SaveId
Definition scoreworker.h:179
char m_aGeneratedCode[128]
Definition scoreworker.h:182
char m_aServer[5]
Definition scoreworker.h:180
enum CScoreSaveResult::@124217027350255103366367351154207121346173146027 m_Status
char m_aBroadcast[512]
Definition scoreworker.h:175
Definition scoreworker.h:301
static bool LoadBestTime(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize)
Definition scoreworker.cpp:185
static bool LoadPlayerTimeCp(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize)
Definition scoreworker.cpp:296
static bool RandomUnfinishedMap(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize)
Definition scoreworker.cpp:1644
static bool ShowTimes(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize)
Definition scoreworker.cpp:1384
static bool ShowTopPoints(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize)
Definition scoreworker.cpp:1544
static bool SaveTeam(IDbConnection *pSqlServer, const ISqlData *pGameData, Write w, char *pError, int ErrorSize)
Definition scoreworker.cpp:1710
static bool ShowRank(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize)
Definition scoreworker.cpp:883
static bool SaveScore(IDbConnection *pSqlServer, const ISqlData *pGameData, Write w, char *pError, int ErrorSize)
Definition scoreworker.cpp:554
static bool GetSaves(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize)
Definition scoreworker.cpp:1974
static bool ShowTop(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize)
Definition scoreworker.cpp:1081
static bool ShowPlayerTeamTop5(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize)
Definition scoreworker.cpp:1304
static bool ShowPoints(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize)
Definition scoreworker.cpp:1499
static bool ShowTeamTop5(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize)
Definition scoreworker.cpp:1207
static bool LoadPlayerData(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize)
Definition scoreworker.cpp:215
static bool SaveTeamScore(IDbConnection *pSqlServer, const ISqlData *pGameData, Write w, char *pError, int ErrorSize)
Definition scoreworker.cpp:713
static bool LoadTeam(IDbConnection *pSqlServer, const ISqlData *pGameData, Write w, char *pError, int ErrorSize)
Definition scoreworker.cpp:1844
static bool ShowTeamRank(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize)
Definition scoreworker.cpp:1002
CSqlLoadBestTimeRequest(std::shared_ptr< CScoreLoadBestTimeResult > pResult)
Definition scoreworker.h:78
char m_aMap[MAX_MAP_LENGTH]
Definition scoreworker.h:84
char m_aName[MAX_MAP_LENGTH]
Definition scoreworker.h:95
char m_aServer[5]
Definition scoreworker.h:101
char m_aMap[MAX_MAP_LENGTH]
Definition scoreworker.h:97
int m_Offset
Definition scoreworker.h:100
CSqlPlayerRequest(std::shared_ptr< CScorePlayerResult > pResult)
Definition scoreworker.h:89
char m_aRequestingPlayer[MAX_NAME_LENGTH]
Definition scoreworker.h:98
char m_aRequestingPlayer[MAX_NAME_LENGTH]
Definition scoreworker.h:126
int m_MaxStars
Definition scoreworker.h:128
char m_aServerType[32]
Definition scoreworker.h:124
char m_aCurrentMap[MAX_MAP_LENGTH]
Definition scoreworker.h:125
CSqlRandomMapRequest(std::shared_ptr< CScoreRandomMapResult > pResult)
Definition scoreworker.h:119
int m_MinStars
Definition scoreworker.h:127
CSqlScoreData(std::shared_ptr< CScorePlayerResult > pResult)
Definition scoreworker.h:133
int m_Num
Definition scoreworker.h:146
bool m_Search
Definition scoreworker.h:147
int m_ClientId
Definition scoreworker.h:142
float m_aCurrentTimeCp[NUM_CHECKPOINTS]
Definition scoreworker.h:145
char m_aTimestamp[TIMESTAMP_STR_LENGTH]
Definition scoreworker.h:144
float m_Time
Definition scoreworker.h:143
char m_aMap[MAX_MAP_LENGTH]
Definition scoreworker.h:138
char m_aRequestingPlayer[MAX_NAME_LENGTH]
Definition scoreworker.h:148
char m_aName[MAX_MAP_LENGTH]
Definition scoreworker.h:140
char m_aGameUuid[UUID_MAXSTRSIZE]
Definition scoreworker.h:139
int m_NumPlayer
Definition scoreworker.h:228
char m_aRequestingPlayer[MAX_NAME_LENGTH]
Definition scoreworker.h:224
char m_aClientNames[MAX_CLIENTS][MAX_NAME_LENGTH]
Definition scoreworker.h:226
char m_aMap[MAX_MAP_LENGTH]
Definition scoreworker.h:223
CSqlTeamLoadRequest(std::shared_ptr< CScoreSaveResult > pResult)
Definition scoreworker.h:217
int m_aClientId[MAX_CLIENTS]
Definition scoreworker.h:227
char m_aCode[128]
Definition scoreworker.h:222
char m_aGeneratedCode[128]
Definition scoreworker.h:211
char m_aClientName[MAX_NAME_LENGTH]
Definition scoreworker.h:208
char m_aCode[128]
Definition scoreworker.h:210
char m_aMap[MAX_MAP_LENGTH]
Definition scoreworker.h:209
CSqlTeamSaveData(std::shared_ptr< CScoreSaveResult > pResult)
Definition scoreworker.h:203
char m_aServer[5]
Definition scoreworker.h:212
CSqlTeamScoreData()
Definition scoreworker.h:187
float m_Time
Definition scoreworker.h:194
CUuid m_TeamrankUuid
Definition scoreworker.h:198
char m_aTimestamp[TIMESTAMP_STR_LENGTH]
Definition scoreworker.h:195
char m_aGameUuid[UUID_MAXSTRSIZE]
Definition scoreworker.h:192
char m_aaNames[MAX_CLIENTS][MAX_NAME_LENGTH]
Definition scoreworker.h:197
char m_aMap[MAX_MAP_LENGTH]
Definition scoreworker.h:193
unsigned int m_Size
Definition scoreworker.h:196
unsigned int m_NumNames
Definition scoreworker.h:272
void FormatTeamTopLine(char *pMessage, int MessageSize, int Rank, const char *pTime) const
Definition scoreworker.cpp:137
CUuid m_TeamId
Definition scoreworker.h:270
bool SamePlayers(const std::vector< std::string > *pvSortedNames)
Definition scoreworker.cpp:97
char m_aaNames[MAX_CLIENTS][MAX_NAME_LENGTH]
Definition scoreworker.h:271
void FormatNames(char *pBuf, int BufSize) const
Definition scoreworker.cpp:109
CTeamrank()
Definition scoreworker.cpp:60
bool NextSqlResult(IDbConnection *pSqlServer, bool *pEnd, char *pError, int ErrorSize)
Definition scoreworker.cpp:68
static bool GetSqlTop5Team(IDbConnection *pSqlServer, bool *pEnd, char *pError, int ErrorSize, char(*paMessages)[512], int *StartLine, int Count)
Definition scoreworker.cpp:146
Definition uuid_manager.h:17
Definition connection_pool.h:26
ISqlData(std::shared_ptr< ISqlResult > pResult)
Definition connection_pool.h:27
Definition connection_pool.h:14
MapInfo()
Definition score_test.cpp:459
MapVote()
Definition score_test.cpp:531
RandomMap()
Definition score_test.cpp:663
struct CScorePlayerResult::@306052261263210267064004055070110266005066160136::@311371205211055213175200034225050274071154167100 m_MapVote
struct CScorePlayerResult::@306052261263210267064004055070110266005066160136::@067225374045354243024376012344351334244367112027 m_Info
char m_aaMessages[MAX_MESSAGES][512]
@ UUID_MAXSTRSIZE
Definition uuid_manager.h:8
@ VOTE_REASON_LENGTH
Definition voting.h:10