DDraceNetwork 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 <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
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
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
148
150{
154 {
155 m_aMessage[0] = '\0';
156 m_aBroadcast[0] = '\0';
157 }
158 enum
159 {
161 // load team in the following two cases
166 char m_aMessage[512];
167 char m_aBroadcast[512];
171};
172
188
190{
191 CSqlTeamSaveData(std::shared_ptr<CScoreSaveResult> pResult) :
192 ISqlData(std::move(pResult))
193 {
194 }
195
198 char m_aCode[128];
200 char m_aServer[5];
201};
202
204{
205 CSqlTeamLoadRequest(std::shared_ptr<CScoreSaveResult> pResult) :
206 ISqlData(std::move(pResult))
207 {
208 }
209
210 char m_aCode[128];
213 // struct holding all player names in the team or an empty string
217};
218
220{
221public:
223 {
224 Reset();
225 }
226
227 void Reset()
228 {
229 m_BestTime = 0;
230 for(float &BestTimeCp : m_aBestTimeCp)
231 BestTimeCp = 0;
232
233 m_RecordStopTick = -1;
234 }
235
236 void Set(float Time, const float aTimeCp[NUM_CHECKPOINTS])
237 {
238 m_BestTime = Time;
239 for(int i = 0; i < NUM_CHECKPOINTS; i++)
240 m_aBestTimeCp[i] = aTimeCp[i];
241 }
242
244 {
245 for(int i = 0; i < NUM_CHECKPOINTS; i++)
246 m_aBestTimeCp[i] = aTimeCp[i];
247 }
248
251
254};
255
257{
260 unsigned int m_NumNames;
261 CTeamrank();
262
263 // Assumes that a database query equivalent to
264 //
265 // SELECT TeamId, Name [, ...] -- the order is important
266 // FROM record_teamrace
267 // ORDER BY TeamId, Name
268 //
269 // was executed and that the result line of the first team member is already selected.
270 // Afterwards the team member of the next team is selected.
271 //
272 // Returns true on SQL failure
273 //
274 // if another team can be extracted
275 bool NextSqlResult(IDbConnection *pSqlServer, bool *pEnd, char *pError, int ErrorSize);
276
277 bool SamePlayers(const std::vector<std::string> *pvSortedNames);
278
279 static bool GetSqlTop5Team(IDbConnection *pSqlServer, bool *pEnd, char *pError, int ErrorSize, char (*paMessages)[512], int *StartLine, int Count);
280};
281
283{
284 static bool LoadBestTime(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize);
285
286 static bool RandomMap(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize);
288 static bool MapVote(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize);
289
290 static bool LoadPlayerData(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize);
292 static bool MapInfo(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize);
293 static bool ShowRank(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize);
294 static bool ShowTeamRank(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize);
295 static bool ShowTop(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize);
296 static bool ShowTeamTop5(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize);
298 static bool ShowTimes(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize);
299 static bool ShowPoints(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize);
300 static bool ShowTopPoints(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize);
301 static bool GetSaves(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize);
302
303 static bool SaveTeam(IDbConnection *pSqlServer, const ISqlData *pGameData, Write w, char *pError, int ErrorSize);
304 static bool LoadTeam(IDbConnection *pSqlServer, const ISqlData *pGameData, Write w, char *pError, int ErrorSize);
305
306 static bool SaveScore(IDbConnection *pSqlServer, const ISqlData *pGameData, Write w, char *pError, int ErrorSize);
307 static bool SaveTeamScore(IDbConnection *pSqlServer, const ISqlData *pGameData, Write w, char *pError, int ErrorSize);
308};
309
310#endif // GAME_SERVER_SCOREWORKER_H
Definition scoreworker.h:220
float m_RecordFinishTime
Definition scoreworker.h:253
float m_BestTime
Definition scoreworker.h:249
float m_aBestTimeCp[NUM_CHECKPOINTS]
Definition scoreworker.h:250
void Set(float Time, const float aTimeCp[NUM_CHECKPOINTS])
Definition scoreworker.h:236
int m_RecordStopTick
Definition scoreworker.h:252
void SetBestTimeCp(const float aTimeCp[NUM_CHECKPOINTS])
Definition scoreworker.h:243
CPlayerData()
Definition scoreworker.h:222
void Reset()
Definition scoreworker.h:227
Definition save.h:173
Definition connection.h:19
Definition gamecontroller.h:19
Definition vmath.h:15
Write
Definition connection_pool.h:35
@ MAX_MAP_LENGTH
Definition map.h:12
@ MAX_CHECKPOINTS
Definition protocol.h:91
@ MAX_CLIENTS
Definition protocol.h:88
@ MAX_NAME_LENGTH
Definition protocol.h:98
@ 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::@267 m_Data
int m_Birthday
Definition scoreworker.h:52
void SetVariant(Variant v)
Definition scoreworker.cpp:23
CScorePlayerResult()
Definition scoreworker.cpp:18
struct CScorePlayerResult::@267::@270 m_MapVote
char m_aBroadcast[1024]
Definition scoreworker.h:47
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
char m_aMap[MAX_MAP_LENGTH+1]
Definition scoreworker.h:59
@ MAX_MESSAGES
Definition scoreworker.h:32
enum CScorePlayerResult::Variant m_MessageKind
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
struct CScorePlayerResult::@267::@269 m_Info
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:150
int m_RequestingPlayer
Definition scoreworker.h:169
char m_aMessage[512]
Definition scoreworker.h:166
CSaveTeam m_SavedTeam
Definition scoreworker.h:168
enum CScoreSaveResult::@271 m_Status
@ LOAD_FAILED
Definition scoreworker.h:164
@ SAVE_FAILED
Definition scoreworker.h:162
@ SAVE_SUCCESS
Definition scoreworker.h:160
@ LOAD_SUCCESS
Definition scoreworker.h:163
CUuid m_SaveId
Definition scoreworker.h:170
char m_aBroadcast[512]
Definition scoreworker.h:167
CScoreSaveResult(int PlayerId)
Definition scoreworker.h:151
Definition scoreworker.h:283
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:1557
static bool ShowTimes(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize)
Definition scoreworker.cpp:1298
static bool ShowTopPoints(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize)
Definition scoreworker.cpp:1458
static bool SaveTeam(IDbConnection *pSqlServer, const ISqlData *pGameData, Write w, char *pError, int ErrorSize)
Definition scoreworker.cpp:1622
static bool ShowRank(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize)
Definition scoreworker.cpp:821
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:1897
static bool ShowTop(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize)
Definition scoreworker.cpp:1016
static bool ShowPlayerTeamTop5(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize)
Definition scoreworker.cpp:1206
static bool ShowPoints(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize)
Definition scoreworker.cpp:1413
static bool ShowTeamTop5(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize)
Definition scoreworker.cpp:1109
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 LoadTeam(IDbConnection *pSqlServer, const ISqlData *pGameData, Write w, char *pError, int ErrorSize)
Definition scoreworker.cpp:1767
static bool ShowTeamRank(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize)
Definition scoreworker.cpp:933
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
int m_Num
Definition scoreworker.h:144
bool m_Search
Definition scoreworker.h:145
int m_ClientId
Definition scoreworker.h:140
float m_aCurrentTimeCp[NUM_CHECKPOINTS]
Definition scoreworker.h:143
char m_aTimestamp[TIMESTAMP_STR_LENGTH]
Definition scoreworker.h:142
float m_Time
Definition scoreworker.h:141
char m_aMap[MAX_MAP_LENGTH]
Definition scoreworker.h:136
char m_aRequestingPlayer[MAX_NAME_LENGTH]
Definition scoreworker.h:146
char m_aName[MAX_MAP_LENGTH]
Definition scoreworker.h:138
char m_aGameUuid[UUID_MAXSTRSIZE]
Definition scoreworker.h:137
Definition scoreworker.h:204
int m_NumPlayer
Definition scoreworker.h:216
char m_aRequestingPlayer[MAX_NAME_LENGTH]
Definition scoreworker.h:212
char m_aClientNames[MAX_CLIENTS][MAX_NAME_LENGTH]
Definition scoreworker.h:214
char m_aMap[MAX_MAP_LENGTH]
Definition scoreworker.h:211
CSqlTeamLoadRequest(std::shared_ptr< CScoreSaveResult > pResult)
Definition scoreworker.h:205
int m_aClientId[MAX_CLIENTS]
Definition scoreworker.h:215
char m_aCode[128]
Definition scoreworker.h:210
Definition scoreworker.h:190
char m_aGeneratedCode[128]
Definition scoreworker.h:199
char m_aClientName[MAX_NAME_LENGTH]
Definition scoreworker.h:196
char m_aCode[128]
Definition scoreworker.h:198
char m_aMap[MAX_MAP_LENGTH]
Definition scoreworker.h:197
CSqlTeamSaveData(std::shared_ptr< CScoreSaveResult > pResult)
Definition scoreworker.h:191
char m_aServer[5]
Definition scoreworker.h:200
Definition scoreworker.h:174
CSqlTeamScoreData()
Definition scoreworker.h:175
float m_Time
Definition scoreworker.h:182
CUuid m_TeamrankUuid
Definition scoreworker.h:186
char m_aTimestamp[TIMESTAMP_STR_LENGTH]
Definition scoreworker.h:183
char m_aGameUuid[UUID_MAXSTRSIZE]
Definition scoreworker.h:180
char m_aaNames[MAX_CLIENTS][MAX_NAME_LENGTH]
Definition scoreworker.h:185
char m_aMap[MAX_MAP_LENGTH]
Definition scoreworker.h:181
unsigned int m_Size
Definition scoreworker.h:184
Definition scoreworker.h:257
unsigned int m_NumNames
Definition scoreworker.h:260
CUuid m_TeamId
Definition scoreworker.h:258
bool SamePlayers(const std::vector< std::string > *pvSortedNames)
Definition scoreworker.cpp:90
char m_aaNames[MAX_CLIENTS][MAX_NAME_LENGTH]
Definition scoreworker.h:259
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
Definition score.cpp:355
Definition score.cpp:426
Definition score.cpp:555
@ UUID_MAXSTRSIZE
Definition uuid_manager.h:8
@ VOTE_REASON_LENGTH
Definition voting.h:10