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
|
/*
Processes a newly submitted time, determining if the player beat their
personal best and if they beat the map course and mode's record time.
*/
void DB_ProcessNewTime(int client, int steamID, int mapID, int course, int mode, int style, int runTimeMS, int teleportsUsed)
{
char query[1024];
DataPack data = new DataPack();
data.WriteCell(GetClientUserId(client));
data.WriteCell(steamID);
data.WriteCell(mapID);
data.WriteCell(course);
data.WriteCell(mode);
data.WriteCell(style);
data.WriteCell(runTimeMS);
data.WriteCell(teleportsUsed);
Transaction txn = SQL_CreateTransaction();
// Get Top 2 PBs
FormatEx(query, sizeof(query), sql_getpb, steamID, mapID, course, mode, 2);
txn.AddQuery(query);
// Get Rank
FormatEx(query, sizeof(query), sql_getmaprank, mapID, course, mode, steamID, mapID, course, mode);
txn.AddQuery(query);
// Get Number of Players with Times
FormatEx(query, sizeof(query), sql_getlowestmaprank, mapID, course, mode);
txn.AddQuery(query);
if (teleportsUsed == 0)
{
// Get Top 2 PRO PBs
FormatEx(query, sizeof(query), sql_getpbpro, steamID, mapID, course, mode, 2);
txn.AddQuery(query);
// Get PRO Rank
FormatEx(query, sizeof(query), sql_getmaprankpro, mapID, course, mode, steamID, 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_ProcessTimerEnd, DB_TxnFailure_Generic_DataPack, data, DBPrio_Normal);
}
public void DB_TxnSuccess_ProcessTimerEnd(Handle db, DataPack data, int numQueries, Handle[] results, any[] queryData)
{
data.Reset();
int client = GetClientOfUserId(data.ReadCell());
int steamID = data.ReadCell();
int mapID = data.ReadCell();
int course = data.ReadCell();
int mode = data.ReadCell();
int style = data.ReadCell();
int runTimeMS = data.ReadCell();
int teleportsUsed = data.ReadCell();
delete data;
if (!IsValidClient(client))
{
return;
}
bool firstTime = SQL_GetRowCount(results[0]) == 1;
int pbDiff = 0;
int rank = -1;
int maxRank = -1;
if (!firstTime)
{
SQL_FetchRow(results[0]);
int pb = SQL_FetchInt(results[0], 0);
if (runTimeMS == pb) // New time is new PB
{
SQL_FetchRow(results[0]);
int oldPB = SQL_FetchInt(results[0], 0);
pbDiff = runTimeMS - oldPB;
}
else // Didn't beat PB
{
pbDiff = runTimeMS - pb;
}
}
// Get NUB Rank
SQL_FetchRow(results[1]);
rank = SQL_FetchInt(results[1], 0);
SQL_FetchRow(results[2]);
maxRank = SQL_FetchInt(results[2], 0);
// Repeat for PRO Runs
bool firstTimePro = false;
int pbDiffPro = 0;
int rankPro = -1;
int maxRankPro = -1;
if (teleportsUsed == 0)
{
firstTimePro = SQL_GetRowCount(results[3]) == 1;
if (!firstTimePro)
{
SQL_FetchRow(results[3]);
int pb = SQL_FetchInt(results[3], 0);
if (runTimeMS == pb) // New time is new PB
{
SQL_FetchRow(results[3]);
int oldPB = SQL_FetchInt(results[3], 0);
pbDiffPro = runTimeMS - oldPB;
}
else // Didn't beat PB
{
pbDiffPro = runTimeMS - pb;
}
}
// Get PRO Rank
SQL_FetchRow(results[4]);
rankPro = SQL_FetchInt(results[4], 0);
SQL_FetchRow(results[5]);
maxRankPro = SQL_FetchInt(results[5], 0);
}
// Call OnTimeProcessed forward
Call_OnTimeProcessed(
client,
steamID,
mapID,
course,
mode,
style,
GOKZ_DB_TimeIntToFloat(runTimeMS),
teleportsUsed,
firstTime,
GOKZ_DB_TimeIntToFloat(pbDiff),
rank,
maxRank,
firstTimePro,
GOKZ_DB_TimeIntToFloat(pbDiffPro),
rankPro,
maxRankPro);
// Call OnNewRecord forward
bool newWR = (firstTime || pbDiff < 0) && rank == 1;
bool newWRPro = (firstTimePro || pbDiffPro < 0) && rankPro == 1;
if (newWR && newWRPro)
{
Call_OnNewRecord(client, steamID, mapID, course, mode, style, RecordType_NubAndPro, GOKZ_DB_TimeIntToFloat(pbDiffPro), teleportsUsed);
}
else if (newWR)
{
Call_OnNewRecord(client, steamID, mapID, course, mode, style, RecordType_Nub, GOKZ_DB_TimeIntToFloat(pbDiff), teleportsUsed);
}
else if (newWRPro)
{
Call_OnNewRecord(client, steamID, mapID, course, mode, style, RecordType_Pro, GOKZ_DB_TimeIntToFloat(pbDiffPro), teleportsUsed);
}
}
|