· 7 years ago · Jan 12, 2019, 02:30 PM
1public db_getclient(client)
2{
3 decl String:SteamId[65];
4 GetClientAuthString(client, SteamId, sizeof(SteamId));
5 if (StrContains(SteamId, "BOT") == -1 && IsClientInGame(client))
6 {
7 new String:query[4000];
8 Format(query, sizeof(query), "SELECT lvl, race, gold, name FROM `wcs` WHERE steamid = '%s';", SteamId);
9 SQL_TQuery(g_hDb, SQL_GetInfo, query, client);
10 }
11}
12
13public db_getclientvip(client)
14{
15 decl String:SteamId[65];
16 GetClientAuthString(client, SteamId, sizeof(SteamId));
17 if (StrContains(SteamId, "BOT") == -1 && IsClientInGame(client))
18 {
19 new String:query[4000];
20 Format(query, sizeof(query), "SELECT credits FROM `wcs_vip` WHERE SteamId = '%s';", SteamId);
21 SQL_TQuery(g_hDb3, SQL_GetInfo5, query, client);
22 }
23}
24
25public db_getclientrace(client)
26{
27 decl String:SteamId[65];
28 GetClientAuthString(client, SteamId, sizeof(SteamId));
29 if (StrContains(SteamId, "BOT") == -1 && IsClientInGame(client))
30 {
31 new String:query[4000];
32 Format(query, sizeof(query), "SELECT RaceId, RaceLvl, RaceXp FROM `wcs_races` WHERE SteamId = '%s' AND RaceId = '%d';", SteamId, ClientRace[client]);
33 SQL_TQuery(g_hDb2, SQL_GetInfo2, query, client);
34 }
35}
36
37public db_setclientrace(client)
38{
39 decl String:SteamId[65];
40 GetClientAuthString(client, SteamId, sizeof(SteamId));
41 if (StrContains(SteamId, "BOT") == -1 && IsClientInGame(client))
42 {
43 new String:query[4000];
44 Format(query, sizeof(query), "SELECT RaceId, RaceLvl, RaceXp FROM `wcs_races` WHERE SteamId = '%s' AND RaceId = '%d';", SteamId, ClientRace[client]);
45 SQL_TQuery(g_hDb2, SQL_GetInfo3, query, client);
46 }
47}
48
49public SQL_GetInfo(Handle:owner, Handle:hndl, const String:error[], any:data)
50{
51 if (hndl == INVALID_HANDLE)
52 {
53 LogError("[WC:Source] SQL Getting Players error: %s", error);
54 }
55 else
56 {
57 if (SQL_FetchRow(hndl))
58 {
59 decl String:buffer[128];
60 ClientLvl[data] = SQL_FetchInt(hndl, 0);
61 ClientRace[data] = SQL_FetchInt(hndl, 1);
62 ClientGold[data] = SQL_FetchInt(hndl, 2);
63 SQL_FetchString(hndl, 3, buffer, sizeof(buffer));
64 ClientName[data] = buffer;
65 }
66 else
67 {
68 InsertQuery(data);
69 db_getclient(data);
70 }
71 }
72}
73
74public SQL_GetInfo5(Handle:owner, Handle:hndl, const String:error[], any:data)
75{
76 if (hndl == INVALID_HANDLE)
77 {
78 LogError("[WC:Source] SQL Getting Vip Players error: %s", error);
79 }
80 else
81 {
82 if (SQL_FetchRow(hndl))
83 {
84 ClientCredits[data] = SQL_FetchInt(hndl, 0);
85 }
86 else
87 {
88 InsertQuery5(data);
89 db_getclient(data);
90 }
91 }
92}
93
94public SQL_GetInfo2(Handle:owner, Handle:hndl, const String:error[], any:data)
95{
96 if (hndl == INVALID_HANDLE)
97 {
98 LogError("[WC:Source] SQL Getting Players races error: %s", error);
99 }
100 else
101 {
102 if (SQL_FetchRow(hndl))
103 {
104 ClientCRace[data] = SQL_FetchInt(hndl, 0);
105 ClientCLvl[data] = SQL_FetchInt(hndl, 1);
106 ClientXp[data] = SQL_FetchInt(hndl, 2);
107 }
108 else
109 {
110 InsertQuery2(data);
111 db_getclientrace(data);
112 }
113 }
114}
115
116public SQL_GetInfo3(Handle:owner, Handle:hndl, const String:error[], any:data)
117{
118 if (hndl == INVALID_HANDLE)
119 {
120 LogError("[WC:Source] SQL Getting Players races error: %s", error);
121 }
122 else
123 {
124 if (SQL_FetchRow(hndl))
125 {
126 db_getclientrace(data);
127 }
128 else
129 {
130 InsertQuery2(data);
131 db_getclientrace(data);
132 }
133 }
134}
135
136public InsertQuery(client)
137{
138 decl String:steamId[65], String:query[4000], String:Name[65];
139 GetClientAuthString(client, steamId, sizeof(steamId));
140 GetClientName(client, Name, sizeof(Name));
141 ReplaceString(Name, sizeof(Name), "'", "");
142 Format(query, sizeof(query), "INSERT INTO `wcs` VALUES ('%d', 1, '%d', '%s', '%s');", GetConVarInt(FindConVar("wcs_lvl_start")), GetConVarInt(FindConVar("wcs_gold_start")), Name, steamId);
143 SQL_TQuery(g_hDb, EmptySQLCallback, query);
144}
145
146public InsertQuery5(client)
147{
148 decl String:steamId[65], String:query[4000];
149 GetClientAuthString(client, steamId, sizeof(steamId));
150 Format(query, sizeof(query), "INSERT INTO `wcs_vip` VALUES ('0', '%s');", steamId);
151 SQL_TQuery(g_hDb3, EmptySQLCallback, query);
152}
153
154public InsertQuery2(client)
155{
156 decl String:steamId[65], String:query[4000];
157 GetClientAuthString(client, steamId, sizeof(steamId));
158 Format(query, sizeof(query), "INSERT INTO `wcs_races` (RaceId, SteamId) VALUES ('%d', '%s');", ClientRace[client], steamId);
159 SQL_TQuery(g_hDb2, EmptySQLCallback, query);
160 PrintToServer(query);
161}
162
163public EmptySQLCallback(Handle:owner, Handle:hndl, const String:error[], any:data)
164{
165 if (hndl == INVALID_HANDLE)
166 LogError("SQL Error: %s", error);
167}
168
169public InitDB()
170{
171 new String:error[255];
172 g_hDb = SQL_Connect("WCS", false, error, sizeof(error));
173
174 if (g_hDb == INVALID_HANDLE)
175 SetFailState("SQL error: %s", error);
176
177 SQL_LockDatabase(g_hDb);
178 SQL_FastQuery(g_hDb, "CREATE TABLE IF NOT EXISTS `wcs` (`lvl` int(5) NOT NULL, `race` int(4) NOT NULL, `gold` int(5), `name` varchar(30), `steamid` varchar(30));");
179 SQL_UnlockDatabase(g_hDb);
180
181 g_hDb2 = SQL_Connect("WCS", false, error, sizeof(error));
182
183 if (g_hDb2 == INVALID_HANDLE)
184 SetFailState("SQL error: %s", error);
185
186 SQL_LockDatabase(g_hDb2);
187 SQL_FastQuery(g_hDb2, "CREATE TABLE IF NOT EXISTS `wcs_races` (`RaceId` int(4) NOT NULL, `RaceLvl` int(5) DEFAULT 1, `RaceXp` int(8) DEFAULT 0, `SteamId` varchar(30));");
188 SQL_UnlockDatabase(g_hDb2);
189
190 g_hDb3 = SQL_Connect("WCS", false, error, sizeof(error));
191
192 if (g_hDb3 == INVALID_HANDLE)
193 SetFailState("SQL error: %s", error);
194
195 SQL_LockDatabase(g_hDb3);
196 SQL_FastQuery(g_hDb3, "CREATE TABLE IF NOT EXISTS `wcs_vip` (`credits` int(5), `SteamId` varchar(30));");
197 SQL_UnlockDatabase(g_hDb3);
198}