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
|
/*
Prints the global record times for a map course and mode.
*/
static bool inProgress[MAXPLAYERS + 1];
static bool waitingForOtherCallback[MAXPLAYERS + 1];
static bool isPBQuery[MAXPLAYERS + 1];
static char printRecordsMap[MAXPLAYERS + 1][64];
static int printRecordsCourse[MAXPLAYERS + 1];
static int printRecordsMode[MAXPLAYERS + 1];
static bool printRecordsTimeExists[MAXPLAYERS + 1][TIMETYPE_COUNT];
static float printRecordsTimes[MAXPLAYERS + 1][TIMETYPE_COUNT];
static char printRecordsPlayerNames[MAXPLAYERS + 1][TIMETYPE_COUNT][MAX_NAME_LENGTH];
// =====[ PUBLIC ]=====
void PrintRecords(int client, const char[] map, int course, int mode, const char[] steamid = DEFAULT_STRING)
{
char mode_str[32];
if (inProgress[client])
{
GOKZ_PrintToChat(client, true, "%t", "Please Wait Before Using Command Again");
return;
}
GOKZ_GL_GetModeString(mode, mode_str, sizeof(mode_str));
DataPack dpNUB = CreateDataPack();
dpNUB.WriteCell(GetClientUserId(client));
dpNUB.WriteCell(TimeType_Nub);
GlobalAPI_GetRecordsTop(PrintRecordsCallback, dpNUB, steamid, _, _, map, 128, course, mode_str, _, _, 0, 1);
DataPack dpPRO = CreateDataPack();
dpPRO.WriteCell(GetClientUserId(client));
dpPRO.WriteCell(TimeType_Pro);
GlobalAPI_GetRecordsTop(PrintRecordsCallback, dpPRO, steamid, _, _, map, 128, course, mode_str, false, _, 0, 1);
inProgress[client] = true;
waitingForOtherCallback[client] = true;
isPBQuery[client] = !StrEqual(steamid, DEFAULT_STRING);
FormatEx(printRecordsMap[client], sizeof(printRecordsMap[]), map);
printRecordsCourse[client] = course;
printRecordsMode[client] = mode;
}
public int PrintRecordsCallback(JSON_Object records, GlobalAPIRequestData request, DataPack dp)
{
dp.Reset();
int client = GetClientOfUserId(dp.ReadCell());
int timeType = dp.ReadCell();
delete dp;
if (request.Failure)
{
LogError("Failed to retrieve record from the Global API for printing.");
return 0;
}
if (!IsValidClient(client))
{
return 0;
}
if (records.Length <= 0)
{
printRecordsTimeExists[client][timeType] = false;
}
else
{
APIRecord record = view_as<APIRecord>(records.GetObjectIndexed(0));
printRecordsTimeExists[client][timeType] = true;
printRecordsTimes[client][timeType] = record.Time;
record.GetPlayerName(printRecordsPlayerNames[client][timeType], sizeof(printRecordsPlayerNames[][]));
}
if (!waitingForOtherCallback[client])
{
if (isPBQuery[client])
{
PrintPBsFinally(client);
}
else
{
PrintRecordsFinally(client);
}
inProgress[client] = false;
}
else
{
waitingForOtherCallback[client] = false;
}
return 0;
}
// =====[ EVENTS ]=====
void OnClientPutInServer_PrintRecords(int client)
{
inProgress[client] = false;
}
// =====[ PRIVATE ]=====
static void PrintPBsFinally(int client)
{
// Print GPB header to chat
if (printRecordsCourse[client] == 0)
{
GOKZ_PrintToChat(client, true, "%t", "GPB Header",
printRecordsMap[client],
gC_ModeNamesShort[printRecordsMode[client]]);
}
else
{
GOKZ_PrintToChat(client, true, "%t", "GPB Header (Bonus)",
printRecordsMap[client],
printRecordsCourse[client],
gC_ModeNamesShort[printRecordsMode[client]]);
}
// Print GPB times to chat
if (!printRecordsTimeExists[client][TimeType_Nub])
{
GOKZ_PrintToChat(client, false, "%t", "No Global Times Found");
}
else if (!printRecordsTimeExists[client][TimeType_Pro])
{
GOKZ_PrintToChat(client, false, "%t", "GPB Time - NUB",
GOKZ_FormatTime(printRecordsTimes[client][TimeType_Nub]),
printRecordsPlayerNames[client][TimeType_Nub]);
GOKZ_PrintToChat(client, false, "%t", "GPB Time - No PRO Time");
}
else
{
GOKZ_PrintToChat(client, false, "%t", "GPB Time - NUB",
GOKZ_FormatTime(printRecordsTimes[client][TimeType_Nub]),
printRecordsPlayerNames[client][TimeType_Nub]);
GOKZ_PrintToChat(client, false, "%t", "GPB Time - PRO",
GOKZ_FormatTime(printRecordsTimes[client][TimeType_Pro]),
printRecordsPlayerNames[client][TimeType_Pro]);
}
}
static void PrintRecordsFinally(int client)
{
// Print GWR header to chat
if (printRecordsCourse[client] == 0)
{
GOKZ_PrintToChat(client, true, "%t", "GWR Header",
printRecordsMap[client],
gC_ModeNamesShort[printRecordsMode[client]]);
}
else
{
GOKZ_PrintToChat(client, true, "%t", "GWR Header (Bonus)",
printRecordsMap[client],
printRecordsCourse[client],
gC_ModeNamesShort[printRecordsMode[client]]);
}
// Print GWR times to chat
if (!printRecordsTimeExists[client][TimeType_Nub])
{
GOKZ_PrintToChat(client, false, "%t", "No Global Times Found");
}
else if (!printRecordsTimeExists[client][TimeType_Pro])
{
GOKZ_PrintToChat(client, false, "%t", "GWR Time - NUB",
GOKZ_FormatTime(printRecordsTimes[client][TimeType_Nub]),
printRecordsPlayerNames[client][TimeType_Nub]);
GOKZ_PrintToChat(client, false, "%t", "GWR Time - No PRO Time");
}
else
{
GOKZ_PrintToChat(client, false, "%t", "GWR Time - NUB",
GOKZ_FormatTime(printRecordsTimes[client][TimeType_Nub]),
printRecordsPlayerNames[client][TimeType_Nub]);
GOKZ_PrintToChat(client, false, "%t", "GWR Time - PRO",
GOKZ_FormatTime(printRecordsTimes[client][TimeType_Pro]),
printRecordsPlayerNames[client][TimeType_Pro]);
}
}
|