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
|
int pointsTotal[MAXPLAYERS + 1][MODE_COUNT][TIMETYPE_COUNT];
int finishes[MAXPLAYERS + 1][MODE_COUNT][TIMETYPE_COUNT];
int pointsMap[MAXPLAYERS + 1][MODE_COUNT][TIMETYPE_COUNT];
int requestsInProgress[MAXPLAYERS + 1];
void ResetPoints(int client)
{
for (int mode = 0; mode < MODE_COUNT; mode++)
{
for (int type = 0; type < TIMETYPE_COUNT; type++)
{
pointsTotal[client][mode][type] = -1;
finishes[client][mode][type] = -1;
pointsMap[client][mode][type] = -1;
}
}
requestsInProgress[client] = 0;
}
void ResetMapPoints(int client)
{
for (int mode = 0; mode < MODE_COUNT; mode++)
{
for (int type = 0; type < TIMETYPE_COUNT; type++)
{
pointsMap[client][mode][type] = -1;
}
}
requestsInProgress[client] = 0;
}
int GetRankPoints(int client, int mode)
{
return pointsTotal[client][mode][TimeType_Nub];
}
int GetPoints(int client, int mode, int timeType)
{
return pointsTotal[client][mode][timeType];
}
int GetMapPoints(int client, int mode, int timeType)
{
return pointsMap[client][mode][timeType];
}
int GetFinishes(int client, int mode, int timeType)
{
return finishes[client][mode][timeType];
}
// Note: This only gets 128 tick records
void UpdatePoints(int client, bool force = false, int mode = -1)
{
if (requestsInProgress[client] != 0)
{
return;
}
if (mode == -1)
{
mode = GOKZ_GetCoreOption(client, Option_Mode);
}
if (!force || pointsTotal[client][mode][TimeType_Nub] == -1)
{
GetPlayerRanks(client, mode, TimeType_Nub);
GetPlayerRanks(client, mode, TimeType_Pro);
requestsInProgress[client] += 2;
}
if (gI_MapID != -1 && (!force || pointsMap[client][mode][TimeType_Nub] == -1))
{
GetPlayerRanks(client, mode, TimeType_Nub, gI_MapID);
GetPlayerRanks(client, mode, TimeType_Pro, gI_MapID);
requestsInProgress[client] += 2;
}
}
static void GetPlayerRanks(int client, int mode, int timeType, int mapID = DEFAULT_INT)
{
char steamid[21];
int modes[1], mapIDs[1];
modes[0] = view_as<int>(GOKZ_GL_GetGlobalMode(mode));
mapIDs[0] = mapID;
GetClientAuthId(client, AuthId_SteamID64, steamid, sizeof(steamid));
DataPack dp = new DataPack();
dp.WriteCell(GetClientUserId(client));
dp.WriteCell(mode);
dp.WriteCell(timeType);
dp.WriteCell(mapID == DEFAULT_INT);
GlobalAPI_GetPlayerRanks(UpdatePointsCallback, dp, _, _, _, _, steamid, _, _,
mapIDs, mapID == DEFAULT_INT ? DEFAULT_INT : 1, { 0 }, 1,
modes, 1, { 128 }, 1, timeType == TimeType_Nub ? DEFAULT_BOOL : false, _, _);
}
static void UpdatePointsCallback(JSON_Object ranks, GlobalAPIRequestData request, DataPack dp)
{
dp.Reset();
int client = GetClientOfUserId(dp.ReadCell());
int mode = dp.ReadCell();
int timeType = dp.ReadCell();
bool isTotal = dp.ReadCell();
delete dp;
requestsInProgress[client]--;
if (client == 0)
{
return;
}
int points, totalFinishes;
if (request.Failure || !ranks.IsArray || ranks.Length == 0)
{
points = 0;
totalFinishes = 0;
}
else
{
APIPlayerRank rank = view_as<APIPlayerRank>(ranks.GetObjectIndexed(0));
// points = timeType == TimeType_Nub ? rank.PointsOverall : rank.Points;
points = points == -1 ? 0 : rank.Points;
totalFinishes = rank.Finishes == -1 ? 0 : rank.Finishes;
}
if (isTotal)
{
pointsTotal[client][mode][timeType] = points;
finishes[client][mode][timeType] = totalFinishes;
}
else
{
pointsMap[client][mode][timeType] = points;
}
// We always do that cause not all of the requests might have failed
if (requestsInProgress[client] == 0)
{
Call_OnPointsUpdated(client, mode);
}
}
|