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
|
/*
Inserts the player into the database, or else updates their information.
*/
void DB_SetupClient(int client)
{
if (IsFakeClient(client))
{
return;
}
// Setup Client Step 1 - Upsert them into Players Table
char query[1024], name[MAX_NAME_LENGTH], nameEscaped[MAX_NAME_LENGTH * 2 + 1], clientIP[16], country[45];
int steamID = GetSteamAccountID(client);
if (!GetClientName(client, name, MAX_NAME_LENGTH))
{
LogMessage("Couldn't get name of %L.", client);
name = "Unknown";
}
SQL_EscapeString(gH_DB, name, nameEscaped, MAX_NAME_LENGTH * 2 + 1);
if (!GetClientIP(client, clientIP, sizeof(clientIP)))
{
LogMessage("Couldn't get IP of %L.", client);
clientIP = "Unknown";
}
if (!GeoipCountry(clientIP, country, sizeof(country)))
{
LogMessage("Couldn't get country of %L (%s).", client, clientIP);
country = "Unknown";
}
DataPack data = new DataPack();
data.WriteCell(GetClientUserId(client));
data.WriteCell(steamID);
Transaction txn = SQL_CreateTransaction();
// Insert/Update player into Players table
switch (g_DBType)
{
case DatabaseType_SQLite:
{
// UPDATE OR IGNORE
FormatEx(query, sizeof(query), sqlite_players_update, nameEscaped, country, clientIP, steamID);
txn.AddQuery(query);
// INSERT OR IGNORE
FormatEx(query, sizeof(query), sqlite_players_insert, nameEscaped, country, clientIP, steamID);
txn.AddQuery(query);
}
case DatabaseType_MySQL:
{
// INSERT ... ON DUPLICATE KEY ...
FormatEx(query, sizeof(query), mysql_players_upsert, nameEscaped, country, clientIP, steamID);
txn.AddQuery(query);
}
}
FormatEx(query, sizeof(query), sql_players_get_cheater, steamID);
txn.AddQuery(query);
SQL_ExecuteTransaction(gH_DB, txn, DB_TxnSuccess_SetupClient, DB_TxnFailure_Generic_DataPack, data, DBPrio_High);
}
public void DB_TxnSuccess_SetupClient(Handle db, DataPack data, int numQueries, Handle[] results, any[] queryData)
{
data.Reset();
int client = GetClientOfUserId(data.ReadCell());
int steamID = data.ReadCell();
delete data;
if (client == 0 || !IsClientAuthorized(client))
{
return;
}
switch (g_DBType)
{
case DatabaseType_SQLite:
{
if (SQL_FetchRow(results[2]))
{
gB_Cheater[client] = SQL_FetchInt(results[2], 0) == 1;
}
}
case DatabaseType_MySQL:
{
if (SQL_FetchRow(results[1]))
{
gB_Cheater[client] = SQL_FetchInt(results[1], 0) == 1;
}
}
}
gB_ClientSetUp[client] = true;
Call_OnClientSetup(client, steamID, gB_Cheater[client]);
}
|