1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
|
/*
Prints the player's personal times on a map course and given mode.
*/
void DB_PrintPBs(int client, int targetSteamID, int mapID, int course, int mode)
{
char query[1024];
DataPack data = new DataPack();
data.WriteCell(GetClientUserId(client));
data.WriteCell(course);
data.WriteCell(mode);
Transaction txn = SQL_CreateTransaction();
// Retrieve Alias of SteamID
FormatEx(query, sizeof(query), sql_players_getalias, targetSteamID);
txn.AddQuery(query);
// Retrieve Map Name of MapID
FormatEx(query, sizeof(query), sql_maps_getname, mapID);
txn.AddQuery(query);
// Check for existence of map course with that MapID and Course
FormatEx(query, sizeof(query), sql_mapcourses_findid, mapID, course);
txn.AddQuery(query);
// Get PB
FormatEx(query, sizeof(query), sql_getpb, targetSteamID, mapID, course, mode, 1);
txn.AddQuery(query);
// Get Rank
FormatEx(query, sizeof(query), sql_getmaprank, mapID, course, mode, targetSteamID, mapID, course, mode);
txn.AddQuery(query);
// Get Number of Players with Times
FormatEx(query, sizeof(query), sql_getlowestmaprank, mapID, course, mode);
txn.AddQuery(query);
// Get PRO PB
FormatEx(query, sizeof(query), sql_getpbpro, targetSteamID, mapID, course, mode, 1);
txn.AddQuery(query);
// Get PRO Rank
FormatEx(query, sizeof(query), sql_getmaprankpro, mapID, course, mode, targetSteamID, mapID, course, mode);
txn.AddQuery(query);
// Get Number of Players with PRO Times
FormatEx(query, sizeof(query), sql_getlowestmaprankpro, mapID, course, mode);
txn.AddQuery(query);
SQL_ExecuteTransaction(gH_DB, txn, DB_TxnSuccess_PrintPBs, DB_TxnFailure_Generic_DataPack, data, DBPrio_Low);
}
public void DB_TxnSuccess_PrintPBs(Handle db, DataPack data, int numQueries, Handle[] results, any[] queryData)
{
data.Reset();
int client = GetClientOfUserId(data.ReadCell());
int course = data.ReadCell();
int mode = data.ReadCell();
delete data;
if (!IsValidClient(client))
{
return;
}
char playerName[MAX_NAME_LENGTH], mapName[33];
bool hasPB = false;
bool hasPBPro = false;
float runTime;
int teleportsUsed;
int rank;
int maxRank;
float runTimePro;
int rankPro;
int maxRankPro;
// Get Player Name from results
if (SQL_FetchRow(results[0]))
{
SQL_FetchString(results[0], 0, playerName, sizeof(playerName));
}
// Get Map Name from results
if (SQL_FetchRow(results[1]))
{
SQL_FetchString(results[1], 0, mapName, sizeof(mapName));
}
if (SQL_GetRowCount(results[2]) == 0)
{
if (course == 0)
{
GOKZ_PrintToChat(client, true, "%t", "Main Course Not Found", mapName);
}
else
{
GOKZ_PrintToChat(client, true, "%t", "Bonus Not Found", mapName, course);
}
return;
}
// Get PB info from results
if (SQL_GetRowCount(results[3]) > 0)
{
hasPB = true;
if (SQL_FetchRow(results[3]))
{
runTime = GOKZ_DB_TimeIntToFloat(SQL_FetchInt(results[3], 0));
teleportsUsed = SQL_FetchInt(results[3], 1);
}
if (SQL_FetchRow(results[4]))
{
rank = SQL_FetchInt(results[4], 0);
}
if (SQL_FetchRow(results[5]))
{
maxRank = SQL_FetchInt(results[5], 0);
}
}
// Get PB info (Pro) from results
if (SQL_GetRowCount(results[6]) > 0)
{
hasPBPro = true;
if (SQL_FetchRow(results[6]))
{
runTimePro = GOKZ_DB_TimeIntToFloat(SQL_FetchInt(results[6], 0));
}
if (SQL_FetchRow(results[7]))
{
rankPro = SQL_FetchInt(results[7], 0);
}
if (SQL_FetchRow(results[8]))
{
maxRankPro = SQL_FetchInt(results[8], 0);
}
}
// Print PB header to chat
if (course == 0)
{
GOKZ_PrintToChat(client, true, "%t", "PB Header", playerName, mapName, gC_ModeNamesShort[mode]);
}
else
{
GOKZ_PrintToChat(client, true, "%t", "PB Header (Bonus)", playerName, mapName, course, gC_ModeNamesShort[mode]);
}
// Print PB times to chat
if (!hasPB)
{
CPrintToChat(client, "%t", "PB Time - No Times");
}
else if (!hasPBPro)
{
CPrintToChat(client, "%t", "PB Time - NUB", GOKZ_FormatTime(runTime), teleportsUsed, rank, maxRank);
CPrintToChat(client, "%t", "PB Time - No PRO Time");
}
else if (teleportsUsed == 0)
{ // Their MAP PB has 0 teleports, and is therefore also their PRO PB
CPrintToChat(client, "%t", "PB Time - NUB and PRO", GOKZ_FormatTime(runTime), rank, maxRank, rankPro, maxRankPro);
}
else
{
CPrintToChat(client, "%t", "PB Time - NUB", GOKZ_FormatTime(runTime), teleportsUsed, rank, maxRank);
CPrintToChat(client, "%t", "PB Time - PRO", GOKZ_FormatTime(runTimePro), rankPro, maxRankPro);
}
}
void DB_PrintPBs_FindMap(int client, int targetSteamID, const char[] mapSearch, int course, int mode)
{
DataPack data = new DataPack();
data.WriteCell(GetClientUserId(client));
data.WriteCell(targetSteamID);
data.WriteString(mapSearch);
data.WriteCell(course);
data.WriteCell(mode);
DB_FindMap(mapSearch, DB_TxnSuccess_PrintPBs_FindMap, data, DBPrio_Low);
}
public void DB_TxnSuccess_PrintPBs_FindMap(Handle db, DataPack data, int numQueries, Handle[] results, any[] queryData)
{
data.Reset();
int client = GetClientOfUserId(data.ReadCell());
int targetSteamID = data.ReadCell();
char mapSearch[33];
data.ReadString(mapSearch, sizeof(mapSearch));
int course = data.ReadCell();
int mode = data.ReadCell();
delete data;
if (!IsValidClient(client))
{
return;
}
// Check if the map course exists in the database
if (SQL_GetRowCount(results[0]) == 0)
{
GOKZ_PrintToChat(client, true, "%t", "Map Not Found", mapSearch);
return;
}
else if (SQL_FetchRow(results[0]))
{ // Result is the MapID
DB_PrintPBs(client, targetSteamID, SQL_FetchInt(results[0], 0), course, mode);
if (gB_GOKZGlobal)
{
char map[33], steamid[32];
SQL_FetchString(results[0], 1, map, sizeof(map));
GetSteam2FromAccountId(steamid, sizeof(steamid), targetSteamID);
GOKZ_GL_PrintRecords(client, map, course, GOKZ_GetCoreOption(client, Option_Mode), steamid);
}
}
}
void DB_PrintPBs_FindPlayerAndMap(int client, const char[] playerSearch, const char[] mapSearch, int course, int mode)
{
DataPack data = new DataPack();
data.WriteCell(GetClientUserId(client));
data.WriteString(playerSearch);
data.WriteString(mapSearch);
data.WriteCell(course);
data.WriteCell(mode);
DB_FindPlayerAndMap(playerSearch, mapSearch, DB_TxnSuccess_PrintPBs_FindPlayerAndMap, data, DBPrio_Low);
}
public void DB_TxnSuccess_PrintPBs_FindPlayerAndMap(Handle db, DataPack data, int numQueries, Handle[] results, any[] queryData)
{
data.Reset();
int client = GetClientOfUserId(data.ReadCell());
char playerSearch[MAX_NAME_LENGTH];
data.ReadString(playerSearch, sizeof(playerSearch));
char mapSearch[33];
data.ReadString(mapSearch, sizeof(mapSearch));
int course = data.ReadCell();
int mode = data.ReadCell();
delete data;
if (!IsValidClient(client))
{
return;
}
if (SQL_GetRowCount(results[0]) == 0)
{
GOKZ_PrintToChat(client, true, "%t", "Player Not Found", playerSearch);
return;
}
else if (SQL_GetRowCount(results[1]) == 0)
{
GOKZ_PrintToChat(client, true, "%t", "Map Not Found", mapSearch);
return;
}
else if (SQL_FetchRow(results[0]) && SQL_FetchRow(results[1]))
{
int accountid = SQL_FetchInt(results[0], 0);
DB_PrintPBs(client, accountid, SQL_FetchInt(results[1], 0), course, mode);
if (gB_GOKZGlobal)
{
char map[33], steamid[32];
SQL_FetchString(results[1], 1, map, sizeof(map));
GetSteam2FromAccountId(steamid, sizeof(steamid), accountid);
GOKZ_GL_PrintRecords(client, map, course, GOKZ_GetCoreOption(client, Option_Mode), steamid);
}
}
}
|