DDraceNetwork Docs
scoreworker.h
Go to the documentation of this file.
1#ifndef GAME_SERVER_SCOREWORKER_H
2#define GAME_SERVER_SCOREWORKER_H
3
4#include <memory>
5#include <optional>
6#include <string>
7#include <utility>
8#include <vector>
9
10#include <engine/map.h>
14#include <game/server/save.h>
15#include <game/voting.h>
16
17class IDbConnection;
18class IGameController;
19
20enum
21{
23 TIMESTAMP_STR_LENGTH = 20, // 2019-04-02 19:38:36
24};
25
27{
29
30 enum
31 {
33 };
34
36 {
44 union
45 {
47 char m_aBroadcast[1024];
48 struct
49 {
50 std::optional<float> m_Time;
52 int m_Birthday; // 0 indicates no birthday
54 } m_Info = {};
55 struct
56 {
58 char m_aServer[32 + 1];
61 } m_Data = {}; // PLAYER_INFO
62
63 void SetVariant(Variant v);
64};
65
67{
70 {
71 }
73};
74
76{
77 CSqlLoadBestTimeRequest(std::shared_ptr<CScoreLoadBestTimeResult> pResult) :
78 ISqlData(std::move(pResult))
79 {
80 }
81
82 // current map
84};
85
87{
88 CSqlPlayerRequest(std::shared_ptr<CScorePlayerResult> pResult) :
89 ISqlData(std::move(pResult))
90 {
91 }
92
93 // object being requested, either map (128 bytes) or player (16 bytes)
95 // current map
98 // relevant for /top5 kind of requests
100 char m_aServer[5];
101};
102
104{
105 CScoreRandomMapResult(int ClientId) :
106 m_ClientId(ClientId)
107 {
108 m_aMap[0] = '\0';
109 m_aMessage[0] = '\0';
110 }
113 char m_aMessage[512];
114};
115
117{
118 CSqlRandomMapRequest(std::shared_ptr<CScoreRandomMapResult> pResult) :
119 ISqlData(std::move(pResult))
120 {
121 }
122
127};
128
130{
131 CSqlScoreData(std::shared_ptr<CScorePlayerResult> pResult) :
132 ISqlData(std::move(pResult))
133 {
134 }
135
136 virtual ~CSqlScoreData(){};
137
141
143 float m_Time;
146 int m_Num;
149};
150
152{
153 CScoreSaveResult(int PlayerId) :
155 m_RequestingPlayer(PlayerId)
156 {
157 m_aMessage[0] = '\0';
158 m_aBroadcast[0] = '\0';
159 }
160 enum
161 {
163 // load team in the following two cases
168 char m_aMessage[512];
169 char m_aBroadcast[512];
173};
174
176{
178 ISqlData(nullptr)
179 {
180 }
181
184 float m_Time;
186 unsigned int m_Size;
189};
190
192{
193 CSqlTeamSaveData(std::shared_ptr<CScoreSaveResult> pResult) :
194 ISqlData(std::move(pResult))
195 {
196 }
197 virtual ~CSqlTeamSaveData(){};
198
201 char m_aCode[128];
203 char m_aServer[5];
204};
205
207{
208 CSqlTeamLoadRequest(std::shared_ptr<CScoreSaveResult> pResult) :
209 ISqlData(std::move(pResult))
210 {
211 }
213
214 char m_aCode[128];
217 // struct holding all player names in the team or an empty string
221};
222
224{
225public:
227 {
228 Reset();
229 }
231
232 void Reset()
233 {
234 m_BestTime = 0;
235 for(float &BestTimeCp : m_aBestTimeCp)
236 BestTimeCp = 0;
237
238 m_RecordStopTick = -1;
239 }
240
241 void Set(float Time, const float aTimeCp[NUM_CHECKPOINTS])
242 {
243 m_BestTime = Time;
244 for(int i = 0; i < NUM_CHECKPOINTS; i++)
245 m_aBestTimeCp[i] = aTimeCp[i];
246 }
247
248 void SetBestTimeCp(const float aTimeCp[NUM_CHECKPOINTS])
249 {
250 for(int i = 0; i < NUM_CHECKPOINTS; i++)
251 m_aBestTimeCp[i] = aTimeCp[i];
252 }
253
256
259};
260
262{
265 unsigned int m_NumNames;
266 CTeamrank();
267
268 // Assumes that a database query equivalent to
269 //
270 // SELECT TeamId, Name [, ...] -- the order is important
271 // FROM record_teamrace
272 // ORDER BY TeamId, Name
273 //
274 // was executed and that the result line of the first team member is already selected.
275 // Afterwards the team member of the next team is selected.
276 //
277 // Returns true on SQL failure
278 //
279 // if another team can be extracted
280 bool NextSqlResult(IDbConnection *pSqlServer, bool *pEnd, char *pError, int ErrorSize);
281
282 bool SamePlayers(const std::vector<std::string> *pvSortedNames);
283
284 static bool GetSqlTop5Team(IDbConnection *pSqlServer, bool *pEnd, char *pError, int ErrorSize, char (*paMessages)[512], int *StartLine, int Count);
285};
286
288{
289 static bool LoadBestTime(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize);
290
291 static bool RandomMap(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize);
292 static bool RandomUnfinishedMap(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize);
293 static bool MapVote(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize);
294
295 static bool LoadPlayerData(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize);
296 static bool LoadPlayerTimeCp(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize);
297 static bool MapInfo(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize);
298 static bool ShowRank(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize);
299 static bool ShowTeamRank(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize);
300 static bool ShowTop(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize);
301 static bool ShowTeamTop5(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize);
302 static bool ShowPlayerTeamTop5(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize);
303 static bool ShowTimes(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize);
304 static bool ShowPoints(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize);
305 static bool ShowTopPoints(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize);
306 static bool GetSaves(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize);
307
308 static bool SaveTeam(IDbConnection *pSqlServer, const ISqlData *pGameData, Write w, char *pError, int ErrorSize);
309 static bool LoadTeam(IDbConnection *pSqlServer, const ISqlData *pGameData, Write w, char *pError, int ErrorSize);
310
311 static bool SaveScore(IDbConnection *pSqlServer, const ISqlData *pGameData, Write w, char *pError, int ErrorSize);
312 static bool SaveTeamScore(IDbConnection *pSqlServer, const ISqlData *pGameData, Write w, char *pError, int ErrorSize);
313};
314
315#endif // GAME_SERVER_SCOREWORKER_H
Definition: scoreworker.h:224
float m_RecordFinishTime
Definition: scoreworker.h:258
float m_BestTime
Definition: scoreworker.h:254
float m_aBestTimeCp[NUM_CHECKPOINTS]
Definition: scoreworker.h:255
~CPlayerData()
Definition: scoreworker.h:230
void Set(float Time, const float aTimeCp[NUM_CHECKPOINTS])
Definition: scoreworker.h:241
int m_RecordStopTick
Definition: scoreworker.h:257
void SetBestTimeCp(const float aTimeCp[NUM_CHECKPOINTS])
Definition: scoreworker.h:248
CPlayerData()
Definition: scoreworker.h:226
void Reset()
Definition: scoreworker.h:232
Definition: save.h:152
Definition: connection.h:19
Definition: gamecontroller.h:19
Write
Definition: connection_pool.h:35
@ MAX_CHECKPOINTS
Definition: protocol.h:90
@ MAX_CLIENTS
Definition: protocol.h:88
@ MAX_NAME_LENGTH
Definition: protocol.h:97
@ MAX_MAP_LENGTH
Definition: map.h:12
@ TIMESTAMP_STR_LENGTH
Definition: scoreworker.h:23
@ NUM_CHECKPOINTS
Definition: scoreworker.h:22
Definition: scoreworker.h:67
float m_CurrentRecord
Definition: scoreworker.h:72
CScoreLoadBestTimeResult()
Definition: scoreworker.h:68
Definition: scoreworker.h:27
union CScorePlayerResult::@281 m_Data
int m_Birthday
Definition: scoreworker.h:52
void SetVariant(Variant v)
Definition: scoreworker.cpp:23
CScorePlayerResult()
Definition: scoreworker.cpp:18
char m_aBroadcast[1024]
Definition: scoreworker.h:47
@ MAX_MESSAGES
Definition: scoreworker.h:32
char m_aReason[VOTE_REASON_LENGTH]
Definition: scoreworker.h:57
char m_aRequestedPlayer[MAX_NAME_LENGTH]
Definition: scoreworker.h:53
char m_aaMessages[MAX_MESSAGES][512]
Definition: scoreworker.h:46
char m_aServer[32+1]
Definition: scoreworker.h:58
struct CScorePlayerResult::@281::@282 m_Info
char m_aMap[MAX_MAP_LENGTH+1]
Definition: scoreworker.h:59
enum CScorePlayerResult::Variant m_MessageKind
struct CScorePlayerResult::@281::@284 m_MapVote
std::optional< float > m_Time
Definition: scoreworker.h:50
Variant
Definition: scoreworker.h:36
@ PLAYER_TIMECP
Definition: scoreworker.h:42
@ BROADCAST
Definition: scoreworker.h:39
@ DIRECT
Definition: scoreworker.h:37
@ MAP_VOTE
Definition: scoreworker.h:40
@ ALL
Definition: scoreworker.h:38
@ PLAYER_INFO
Definition: scoreworker.h:41
float m_aTimeCp[NUM_CHECKPOINTS]
Definition: scoreworker.h:51
Definition: scoreworker.h:104
char m_aMessage[512]
Definition: scoreworker.h:113
CScoreRandomMapResult(int ClientId)
Definition: scoreworker.h:105
char m_aMap[MAX_MAP_LENGTH]
Definition: scoreworker.h:112
int m_ClientId
Definition: scoreworker.h:111
Definition: scoreworker.h:152
int m_RequestingPlayer
Definition: scoreworker.h:171
char m_aMessage[512]
Definition: scoreworker.h:168
CSaveTeam m_SavedTeam
Definition: scoreworker.h:170
enum CScoreSaveResult::@291 m_Status
CUuid m_SaveId
Definition: scoreworker.h:172
@ LOAD_FAILED
Definition: scoreworker.h:166
@ SAVE_FAILED
Definition: scoreworker.h:164
@ SAVE_SUCCESS
Definition: scoreworker.h:162
@ LOAD_SUCCESS
Definition: scoreworker.h:165
char m_aBroadcast[512]
Definition: scoreworker.h:169
CScoreSaveResult(int PlayerId)
Definition: scoreworker.h:153
Definition: scoreworker.h:288
static bool LoadBestTime(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize)
Definition: scoreworker.cpp:144
static bool LoadPlayerTimeCp(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize)
Definition: scoreworker.cpp:255
static bool RandomUnfinishedMap(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize)
Definition: scoreworker.cpp:1552
static bool ShowTimes(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize)
Definition: scoreworker.cpp:1293
static bool ShowTopPoints(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize)
Definition: scoreworker.cpp:1453
static bool MapVote(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize)
Definition: scoreworker.cpp:305
static bool SaveTeam(IDbConnection *pSqlServer, const ISqlData *pGameData, Write w, char *pError, int ErrorSize)
Definition: scoreworker.cpp:1617
static bool ShowRank(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize)
Definition: scoreworker.cpp:820
static bool SaveScore(IDbConnection *pSqlServer, const ISqlData *pGameData, Write w, char *pError, int ErrorSize)
Definition: scoreworker.cpp:492
static bool GetSaves(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize)
Definition: scoreworker.cpp:1892
static bool ShowTop(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize)
Definition: scoreworker.cpp:1015
static bool ShowPlayerTeamTop5(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize)
Definition: scoreworker.cpp:1201
static bool ShowPoints(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize)
Definition: scoreworker.cpp:1408
static bool MapInfo(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize)
Definition: scoreworker.cpp:366
static bool ShowTeamTop5(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize)
Definition: scoreworker.cpp:1108
static bool LoadPlayerData(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize)
Definition: scoreworker.cpp:174
static bool SaveTeamScore(IDbConnection *pSqlServer, const ISqlData *pGameData, Write w, char *pError, int ErrorSize)
Definition: scoreworker.cpp:651
static bool RandomMap(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize)
Definition: scoreworker.cpp:1502
static bool LoadTeam(IDbConnection *pSqlServer, const ISqlData *pGameData, Write w, char *pError, int ErrorSize)
Definition: scoreworker.cpp:1762
static bool ShowTeamRank(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize)
Definition: scoreworker.cpp:932
Definition: scoreworker.h:76
CSqlLoadBestTimeRequest(std::shared_ptr< CScoreLoadBestTimeResult > pResult)
Definition: scoreworker.h:77
char m_aMap[MAX_MAP_LENGTH]
Definition: scoreworker.h:83
Definition: scoreworker.h:87
char m_aName[MAX_MAP_LENGTH]
Definition: scoreworker.h:94
char m_aServer[5]
Definition: scoreworker.h:100
char m_aMap[MAX_MAP_LENGTH]
Definition: scoreworker.h:96
int m_Offset
Definition: scoreworker.h:99
CSqlPlayerRequest(std::shared_ptr< CScorePlayerResult > pResult)
Definition: scoreworker.h:88
char m_aRequestingPlayer[MAX_NAME_LENGTH]
Definition: scoreworker.h:97
Definition: scoreworker.h:117
char m_aRequestingPlayer[MAX_NAME_LENGTH]
Definition: scoreworker.h:125
int m_Stars
Definition: scoreworker.h:126
char m_aServerType[32]
Definition: scoreworker.h:123
char m_aCurrentMap[MAX_MAP_LENGTH]
Definition: scoreworker.h:124
CSqlRandomMapRequest(std::shared_ptr< CScoreRandomMapResult > pResult)
Definition: scoreworker.h:118
Definition: scoreworker.h:130
CSqlScoreData(std::shared_ptr< CScorePlayerResult > pResult)
Definition: scoreworker.h:131
virtual ~CSqlScoreData()
Definition: scoreworker.h:136
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
Definition: scoreworker.h:207
int m_NumPlayer
Definition: scoreworker.h:220
char m_aRequestingPlayer[MAX_NAME_LENGTH]
Definition: scoreworker.h:216
char m_aClientNames[MAX_CLIENTS][MAX_NAME_LENGTH]
Definition: scoreworker.h:218
virtual ~CSqlTeamLoadRequest()
Definition: scoreworker.h:212
char m_aMap[MAX_MAP_LENGTH]
Definition: scoreworker.h:215
CSqlTeamLoadRequest(std::shared_ptr< CScoreSaveResult > pResult)
Definition: scoreworker.h:208
int m_aClientId[MAX_CLIENTS]
Definition: scoreworker.h:219
char m_aCode[128]
Definition: scoreworker.h:214
Definition: scoreworker.h:192
char m_aGeneratedCode[128]
Definition: scoreworker.h:202
char m_aClientName[MAX_NAME_LENGTH]
Definition: scoreworker.h:199
char m_aCode[128]
Definition: scoreworker.h:201
char m_aMap[MAX_MAP_LENGTH]
Definition: scoreworker.h:200
CSqlTeamSaveData(std::shared_ptr< CScoreSaveResult > pResult)
Definition: scoreworker.h:193
char m_aServer[5]
Definition: scoreworker.h:203
virtual ~CSqlTeamSaveData()
Definition: scoreworker.h:197
Definition: scoreworker.h:176
CSqlTeamScoreData()
Definition: scoreworker.h:177
float m_Time
Definition: scoreworker.h:184
CUuid m_TeamrankUuid
Definition: scoreworker.h:188
char m_aTimestamp[TIMESTAMP_STR_LENGTH]
Definition: scoreworker.h:185
char m_aGameUuid[UUID_MAXSTRSIZE]
Definition: scoreworker.h:182
char m_aaNames[MAX_CLIENTS][MAX_NAME_LENGTH]
Definition: scoreworker.h:187
char m_aMap[MAX_MAP_LENGTH]
Definition: scoreworker.h:183
unsigned int m_Size
Definition: scoreworker.h:186
Definition: scoreworker.h:262
unsigned int m_NumNames
Definition: scoreworker.h:265
CUuid m_TeamId
Definition: scoreworker.h:263
bool SamePlayers(const std::vector< std::string > *pvSortedNames)
Definition: scoreworker.cpp:90
char m_aaNames[MAX_CLIENTS][MAX_NAME_LENGTH]
Definition: scoreworker.h:264
CTeamrank()
Definition: scoreworker.cpp:56
bool NextSqlResult(IDbConnection *pSqlServer, bool *pEnd, char *pError, int ErrorSize)
Definition: scoreworker.cpp:64
static bool GetSqlTop5Team(IDbConnection *pSqlServer, bool *pEnd, char *pError, int ErrorSize, char(*paMessages)[512], int *StartLine, int Count)
Definition: scoreworker.cpp:102
Definition: uuid_manager.h:17
Definition: connection_pool.h:24
Definition: connection_pool.h:12
@ UUID_MAXSTRSIZE
Definition: uuid_manager.h:8
@ VOTE_REASON_LENGTH
Definition: voting.h:10