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
|
/*
Inserts a list of maps read from a file into the Maps table,
and updates them to be part of the ranked map pool.
*/
void DB_UpdateRankedMapPool(int client)
{
File file = OpenFile(LR_CFG_MAP_POOL, "r");
if (file == null)
{
LogError("Failed to load file: '%s'.", LR_CFG_MAP_POOL);
if (IsValidClient(client))
{
GOKZ_PrintToChat(client, true, "%t", "Ranked Map Pool - Error");
}
return;
}
char map[256];
int mapsCount = 0;
Transaction txn = new Transaction();
// Reset all maps to be unranked
txn.AddQuery(sql_maps_reset_mappool);
// Insert/Update maps in gokz-localranks-mappool.cfg to be ranked
while (file.ReadLine(map, sizeof(map)))
{
TrimString(map);
String_ToLower(map, map, sizeof(map));
// Ignore blank lines and comments
if (map[0] == '\0' || map[0] == ';' || (map[0] == '/' && map[1] == '/'))
{
continue;
}
mapsCount++;
switch (g_DBType)
{
case DatabaseType_SQLite:
{
char updateQuery[512];
gH_DB.Format(updateQuery, sizeof(updateQuery), sqlite_maps_updateranked, 1, map);
char insertQuery[512];
gH_DB.Format(insertQuery, sizeof(insertQuery), sqlite_maps_insertranked, 1, map);
txn.AddQuery(updateQuery);
txn.AddQuery(insertQuery);
}
case DatabaseType_MySQL:
{
char query[512];
gH_DB.Format(query, sizeof(query), mysql_maps_upsertranked, 1, map);
txn.AddQuery(query);
}
}
}
delete file;
if (mapsCount == 0)
{
LogError("No maps found in file: '%s'.", LR_CFG_MAP_POOL);
if (IsValidClient(client))
{
GOKZ_PrintToChat(client, true, "%t", "Ranked Map Pool - No Maps In File");
GOKZ_PlayErrorSound(client);
}
delete txn;
return;
}
// Pass client user ID (or -1) as data
int data = -1;
if (IsValidClient(client))
{
data = GetClientUserId(client);
}
gH_DB.Execute(txn, DB_TxnSuccess_UpdateRankedMapPool, DB_TxnFailure_Generic, data);
}
public void DB_TxnSuccess_UpdateRankedMapPool(Handle db, int userid, int numQueries, Handle[] results, any[] queryData)
{
int client = GetClientOfUserId(userid);
if (IsValidClient(client))
{
LogMessage("The ranked map pool was updated by %L.", client);
GOKZ_PrintToChat(client, true, "%t", "Ranked Map Pool - Success");
}
else
{
LogMessage("The ranked map pool was updated.");
}
}
|