· 6 years ago · May 13, 2019, 08:42 PM
1#include <amxmodx>
2#include <sqlx>
3#include <fakemeta>
4#include <csgomod>
5
6#define PLUGIN "CS:GO Accounts"
7#define VERSION "1.3"
8#define AUTHOR "O'Zone"
9
10#define TASK_PASSWORD 1945
11#define TASK_LOAD 2491
12
13enum _:playerInfo { STATUS, FAILS, PASSWORD[32], TEMP_PASSWORD[32], NAME[32], SAFE_NAME[64] };
14enum _:status { NOT_REGISTERED, NOT_LOGGED, LOGGED, GUEST };
15enum _:queries { UPDATE, INSERT, DELETE };
16
17new const accountStatus[status][] = { "Niezarejestrowany", "Niezalogowany", "Zalogowany", "Gosc" };
18
19new const commandAccount[][] = { "say /haslo", "say_team /haslo", "say /password", "say_team /password",
20 "say /konto", "say_team /konto", "say /account", "say_team /account", "konto" };
21
22new playerData[MAX_PLAYERS + 1][playerInfo], setinfo[16], Handle:sql, bool:sqlConnected, dataLoaded, autoLogin, loginMaxTime, passwordMaxFails, passwordMinLength;
23
24public plugin_init()
25{
26 register_plugin(PLUGIN, VERSION, AUTHOR);
27
28 for (new i; i < sizeof commandAccount; i++) register_clcmd(commandAccount[i], "account_menu");
29
30 bind_pcvar_num(create_cvar("csgo_accounts_login_max_time", "60"), loginMaxTime);
31 bind_pcvar_num(create_cvar("csgo_accounts_password_max_fails", "3"), passwordMaxFails);
32 bind_pcvar_num(create_cvar("csgo_accounts_password_min_length", "5"), passwordMinLength);
33 bind_pcvar_string(create_cvar("csgo_accounts_setinfo", "csrpass"), setinfo, charsmax(setinfo));
34
35 register_clcmd("WPROWADZ_SWOJE_HASLO", "login_account");
36 register_clcmd("WPROWADZ_WYBRANE_HASLO", "register_step_one");
37 register_clcmd("POWTORZ_WYBRANE_HASLO", "register_step_two");
38 register_clcmd("WPROWADZ_AKTUALNE_HASLO", "change_step_one");
39 register_clcmd("WPROWADZ_NOWE_HASLO", "change_step_two");
40 register_clcmd("POWTORZ_NOWE_HASLO", "change_step_three");
41 register_clcmd("WPROWADZ_SWOJE_AKTUALNE_HASLO", "delete_account");
42
43 register_concmd("joinclass", "check_account");
44 register_concmd("jointeam", "check_account");
45 register_concmd("chooseteam", "check_account");
46
47 register_message(get_user_msgid("ShowMenu"), "message_show_menu");
48 register_message(get_user_msgid("VGUIMenu"), "message_vgui_menu");
49
50 register_forward(FM_PlayerPreThink, "player_prethink");
51}
52
53public plugin_natives()
54 register_native("csgo_check_account", "_csgo_check_account", 1);
55
56public plugin_cfg()
57 sql_init();
58
59public plugin_end()
60 SQL_FreeHandle(sql);
61
62public client_connect(id)
63{
64 playerData[id][PASSWORD] = "";
65 playerData[id][STATUS] = NOT_REGISTERED;
66 playerData[id][FAILS] = 0;
67
68 rem_bit(id, dataLoaded);
69 rem_bit(id, autoLogin);
70
71 if (is_user_bot(id) || is_user_hltv(id)) return;
72
73 get_user_name(id, playerData[id][NAME], charsmax(playerData[][NAME]));
74
75 mysql_escape_string(playerData[id][NAME], playerData[id][SAFE_NAME], charsmax(playerData[][SAFE_NAME]));
76
77 set_task(0.1, "load_account", id + TASK_LOAD);
78}
79
80public client_disconnected(id)
81{
82 remove_task(id + TASK_PASSWORD);
83 remove_task(id + TASK_LOAD);
84 remove_task(id);
85}
86
87public message_show_menu(msgId, dest, id)
88{
89 new const Team_Select[] = "#Team_Select";
90 static menuData[sizeof(Team_Select)];
91
92 get_msg_arg_string(4, menuData, charsmax(menuData));
93
94 if (equal(menuData, Team_Select) && get_bit(id, dataLoaded) && playerData[id][STATUS] < LOGGED && sql != Empty_Handle) {
95 set_pdata_int(id, 205, 0, 5);
96
97 set_task(0.1, "account_menu", id);
98
99 return PLUGIN_HANDLED;
100 }
101
102 return PLUGIN_CONTINUE;
103}
104
105public message_vgui_menu(msgId, dest, id)
106{
107 if (get_msg_arg_int(1) == 2 && get_bit(id, dataLoaded) && playerData[id][STATUS] < LOGGED && sql != Empty_Handle) {
108 set_task(0.1, "account_menu", id);
109
110 return PLUGIN_HANDLED;
111 }
112
113 return PLUGIN_CONTINUE;
114}
115
116public player_prethink(id)
117{
118 if (is_user_connected(id) && get_bit(id, dataLoaded) && !is_user_bot(id) && !is_user_hltv(id) && !is_user_alive(id) && playerData[id][STATUS] < LOGGED) {
119 static msgScreenFade;
120
121 if (!msgScreenFade) msgScreenFade = get_user_msgid("ScreenFade");
122
123 message_begin(MSG_ONE, msgScreenFade, {0, 0, 0}, id);
124 write_short(1<<12);
125 write_short(1<<12);
126 write_short(0x0000);
127 write_byte(0);
128 write_byte(0);
129 write_byte(0);
130 write_byte(255);
131 message_end();
132 }
133}
134
135public check_account(id)
136{
137 if (playerData[id][STATUS] < LOGGED) {
138 account_menu(id);
139
140 return PLUGIN_HANDLED;
141 }
142
143 return PLUGIN_CONTINUE;
144}
145
146public kick_player(id)
147{
148 id -= TASK_PASSWORD;
149
150 if (is_user_connected(id)) server_cmd("kick #%d ^"Nie zalogowales sie w ciagu %is!^"", get_user_userid(id), loginMaxTime);
151}
152
153public account_menu(id)
154{
155 if (!is_user_connected(id) || !is_user_valid(id)) return PLUGIN_HANDLED;
156
157 if (!get_bit(id, dataLoaded)) {
158 remove_task(id);
159
160 set_task(1.0, "account_menu", id);
161
162 return PLUGIN_HANDLED;
163 }
164
165 if (!get_user_team(id) && playerData[id][STATUS] == LOGGED) {
166 client_cmd(id, "chooseteam");
167 engclient_cmd(id, "chooseteam");
168
169 return PLUGIN_HANDLED;
170 }
171
172 if (playerData[id][STATUS] <= NOT_LOGGED && !task_exists(id + TASK_PASSWORD)) set_task(float(loginMaxTime), "kick_player", id + TASK_PASSWORD);
173
174 static menuData[256];
175
176 formatex(menuData, charsmax(menuData), "\rSYSTEM REJESTRACJI^n^n\rNick: \w[\y%s\w]^n\rStatus: \w[\y%s\w]", playerData[id][NAME], accountStatus[playerData[id][STATUS]]);
177
178 if ((playerData[id][STATUS] == NOT_LOGGED || playerData[id][STATUS] == LOGGED) && !get_bit(id, autoLogin)) format(menuData, charsmax(menuData),"%s^n\wWpisz w konsoli \ysetinfo ^"_%s^" ^"twojehaslo^"^n\wSprawi to, ze twoje haslo bedzie ladowane \rautomatycznie\w.", menuData, setinfo);
179
180 new menu = menu_create(menuData, "account_menu_handle"), callback = menu_makecallback("account_menu_callback");
181
182 menu_additem(menu, "\yLogowanie", _, _, callback);
183 menu_additem(menu, "\yRejestracja^n", _, _, callback);
184 menu_additem(menu, "\yZmien \wHaslo", _, _, callback);
185 menu_additem(menu, "\ySkasuj \wKonto^n", _, _, callback);
186 menu_additem(menu, "\yZaloguj jako \wGosc \r(NIEZALECANE)^n", _, _, callback);
187
188 if (playerData[id][STATUS] == LOGGED) menu_additem(menu, "\wWyjdz", _, _, callback);
189
190 menu_setprop(menu, MPROP_EXIT, MEXIT_NEVER);
191
192 menu_display(id, menu);
193
194 return PLUGIN_HANDLED;
195}
196
197public account_menu_callback(id, menu, item)
198{
199 switch(item) {
200 case 0: return playerData[id][STATUS] == NOT_LOGGED ? ITEM_ENABLED : ITEM_DISABLED;
201 case 1: return (playerData[id][STATUS] == NOT_REGISTERED || playerData[id][STATUS] == GUEST) ? ITEM_ENABLED : ITEM_DISABLED;
202 case 2, 3: return playerData[id][STATUS] == LOGGED ? ITEM_ENABLED : ITEM_DISABLED;
203 case 4: return playerData[id][STATUS] == NOT_REGISTERED ? ITEM_ENABLED : ITEM_DISABLED;
204 }
205
206 return ITEM_ENABLED;
207}
208
209public account_menu_handle(id, menu, item)
210{
211 if (!is_user_connected(id)) return PLUGIN_HANDLED;
212
213 if (item == MENU_EXIT || item == 5) {
214 menu_destroy(menu);
215
216 return PLUGIN_HANDLED;
217 }
218
219 switch(item)
220 {
221 case 0: {
222 client_print_color(id, id, "^x04[CS:GO]^x01 Wprowadz swoje^x04 haslo^x01, aby sie^x04 zalogowac.");
223
224 set_hudmessage(255, 128, 0, 0.24, 0.07, 0, 0.0, 3.5, 0.0, 0.0);
225 show_hudmessage(id, "Wprowadz swoje haslo.");
226
227 client_cmd(id, "messagemode WPROWADZ_SWOJE_HASLO");
228 }
229 case 1: {
230 client_print_color(id, id, "^x04[CS:GO]^x01 Rozpoczales proces^x04 rejestracji^x01. Wprowadz wybrane^x04 haslo^x01.");
231
232 set_hudmessage(255, 128, 0, 0.24, 0.07, 0, 0.0, 3.5, 0.0, 0.0);
233 show_hudmessage(id, "Wprowadz swoje haslo.");
234
235 client_cmd(id, "messagemode WPROWADZ_WYBRANE_HASLO");
236
237 remove_task(id + TASK_PASSWORD);
238 }
239 case 2: {
240 client_print_color(id, id, "^x04[CS:GO]^x01 Wprowadz swoje^x04 aktualne haslo^x01 w celu potwierdzenia tozsamosci.");
241
242 set_hudmessage(255, 128, 0, 0.22, 0.07, 0, 0.0, 3.5, 0.0, 0.0);
243 show_hudmessage(id, "Wprowadz swoje aktualne haslo.");
244
245 client_cmd(id, "messagemode WPROWADZ_AKTUALNE_HASLO");
246 }
247 case 3: {
248 client_print_color(id, id, "^x04[CS:GO]^x01 Wprowadz swoje^x04 aktualne haslo^x01 w celu potwierdzenia tozsamosci.");
249
250 set_hudmessage(255, 128, 0, 0.22, 0.07, 0, 0.0, 3.5, 0.0, 0.0);
251 show_hudmessage(id, "Wprowadz swoje aktualne haslo.");
252
253 client_cmd(id, "messagemode WPROWADZ_SWOJE_AKTUALNE_HASLO");
254 }
255 case 4: {
256 client_print_color(id, id, "^x04[CS:GO]^x01 Zalogowales sie jako^x04 Gosc^x01. By zabezpieczyc swoj nick^x04 zarejestruj sie^x01.");
257
258 set_hudmessage(0, 255, 0, -1.0, 0.9, 0, 0.0, 3.5, 0.0, 0.0);
259 show_hudmessage(id, "Zostales pomyslnie zalogowany jako Gosc.");
260
261 remove_task(id + TASK_PASSWORD);
262
263 playerData[id][STATUS] = GUEST;
264
265 client_cmd(id, "chooseteam");
266
267 engclient_cmd(id, "chooseteam");
268 }
269 }
270
271 menu_destroy(menu);
272
273 return PLUGIN_HANDLED;
274}
275
276public login_account(id)
277{
278 if (playerData[id][STATUS] != NOT_LOGGED || !get_bit(id, dataLoaded)) return PLUGIN_HANDLED;
279
280 new password[32];
281
282 read_args(password, charsmax(password));
283
284 remove_quotes(password);
285
286 if (!equal(playerData[id][PASSWORD], password)) {
287 if (++playerData[id][FAILS] >= passwordMaxFails) server_cmd("kick #%d ^"Nieprawidlowe haslo!^"", get_user_userid(id));
288
289 client_print_color(id, id, "^x04[CS:GO]^x01 Podane haslo jest^x04 nieprawidlowe^x01. (Bledne haslo^x04 %i/%i^x01)", playerData[id][FAILS], passwordMaxFails);
290
291 set_hudmessage(255, 0, 0, 0.24, 0.07, 0, 0.0, 3.5, 0.0, 0.0);
292
293 show_hudmessage(id, "Podane haslo jest nieprawidlowe.");
294
295 account_menu(id);
296
297 return PLUGIN_HANDLED;
298 }
299
300 playerData[id][STATUS] = LOGGED;
301
302 playerData[id][FAILS] = 0;
303
304 remove_task(id + TASK_PASSWORD);
305
306 client_print_color(id, id, "^x04[CS:GO]^x01 Zostales pomyslnie^x04 zalogowany^x01. Zyczymy milej gry.");
307
308 set_hudmessage(0, 255, 0, 0.24, 0.07, 0, 0.0, 3.5, 0.0, 0.0);
309 show_hudmessage(id, "Zostales pomyslnie zalogowany.");
310
311 client_cmd(id, "chooseteam");
312 engclient_cmd(id, "chooseteam");
313
314 return PLUGIN_HANDLED;
315}
316
317public register_step_one(id)
318{
319 if ((playerData[id][STATUS] != NOT_REGISTERED && playerData[id][STATUS] != GUEST) || !get_bit(id, dataLoaded)) return PLUGIN_HANDLED;
320
321 new password[32];
322
323 read_args(password, charsmax(password));
324 remove_quotes(password);
325
326 if (strlen(password) < passwordMinLength) {
327 client_print_color(id, id, "^x04[CS:GO]^x01 Haslo musi miec co najmniej^x04 %i znakow^x01.", passwordMinLength);
328
329 set_hudmessage(255, 0, 0, 0.24, 0.07, 0, 0.0, 3.5, 0.0, 0.0);
330 show_hudmessage(id, "Haslo musi miec co najmniej %i znakow.", passwordMinLength);
331
332 account_menu(id);
333
334 return PLUGIN_HANDLED;
335 }
336
337 copy(playerData[id][TEMP_PASSWORD], charsmax(playerData[][TEMP_PASSWORD]), password);
338
339 client_print_color(id, id, "^x04[CS:GO]^x01 Teraz powtorz wybrane^x04 haslo^x01.");
340
341 set_hudmessage(255, 128, 0, 0.24, 0.07, 0, 0.0, 3.5, 0.0, 0.0);
342 show_hudmessage(id, "Powtorz wybrane haslo.");
343
344 client_cmd(id, "messagemode POWTORZ_WYBRANE_HASLO");
345
346 return PLUGIN_HANDLED;
347}
348
349public register_step_two(id)
350{
351 if ((playerData[id][STATUS] != NOT_REGISTERED && playerData[id][STATUS] != GUEST) || !get_bit(id, dataLoaded)) return PLUGIN_HANDLED;
352
353 new password[32];
354
355 read_args(password, charsmax(password));
356 remove_quotes(password);
357
358 if (!equal(password, playerData[id][TEMP_PASSWORD])) {
359 client_print_color(id, id, "^x04[CS:GO]^x01 Podane hasla^x04 roznia sie^x01 od siebie.");
360
361 set_hudmessage(255, 0, 0, 0.24, 0.07, 0, 0.0, 3.5, 0.0, 0.0);
362 show_hudmessage(id, "Podane hasla roznia sie od siebie.");
363
364 account_menu(id);
365
366 return PLUGIN_HANDLED;
367 }
368
369 new menuData[192];
370
371 formatex(menuData, charsmax(menuData), "\rPOTWIERDZENIE REJESTRACJI^n^n\wTwoj Nick: \y[\r%s\y]^n\wTwoje Haslo: \y[\r%s\y]", playerData[id][NAME], playerData[id][TEMP_PASSWORD]);
372
373 new menu = menu_create(menuData, "register_confirmation_handle");
374
375 menu_additem(menu, "\rPotwierdz \wRejestracje");
376 menu_additem(menu, "\yZmien \wHaslo^n");
377 menu_additem(menu, "\wAnuluj \wRejestracje");
378
379 menu_setprop(menu, MPROP_EXIT, MEXIT_NEVER);
380
381 menu_display(id, menu);
382
383 return PLUGIN_HANDLED;
384}
385
386public register_confirmation_handle(id, menu, item)
387{
388 if (!is_user_connected(id)) return PLUGIN_HANDLED;
389
390 if (item == MENU_EXIT) {
391 menu_destroy(menu);
392
393 return PLUGIN_HANDLED;
394 }
395
396 menu_destroy(menu);
397
398 switch(item) {
399 case 0: {
400 playerData[id][STATUS] = LOGGED;
401
402 copy(playerData[id][PASSWORD], charsmax(playerData[][PASSWORD]), playerData[id][TEMP_PASSWORD]);
403
404 account_query(id, INSERT);
405
406 set_hudmessage(0, 255, 0, -1.0, 0.9, 0, 0.0, 3.5, 0.0, 0.0);
407 show_hudmessage(id, "Zostales pomyslnie zarejestrowany i zalogowany.");
408
409 client_print_color(id, id, "^x04[CS:GO]^x01 Twoj nick zostal pomyslnie^x04 zarejestrowany^x01.");
410 client_print_color(id, id, "^x04[CS:GO]^x01 Wpisz w konsoli komende^x04 setinfo ^"_%s^" ^"%s^"^x01, aby twoje haslo bylo ladowane automatycznie.", setinfo, playerData[id][PASSWORD]);
411
412 cmd_execute(id, "setinfo _%s %s", setinfo, playerData[id][PASSWORD]);
413 cmd_execute(id, "writecfg %s", setinfo);
414
415 client_cmd(id, "chooseteam");
416 engclient_cmd(id, "chooseteam");
417 } case 1: {
418 client_print_color(id, id, "^x04[CS:GO]^x01 Rozpoczales proces^x04 rejestracji^x01. Wprowadz wybrane^x04 haslo^x01.");
419
420 set_hudmessage(255, 128, 0, 0.24, 0.07, 0, 0.0, 3.5, 0.0, 0.0);
421 show_hudmessage(id, "Wprowadz wybrane haslo.");
422
423 client_cmd(id, "messagemode WPROWADZ_WYBRANE_HASLO");
424 } case 2: account_menu(id);
425 }
426
427 return PLUGIN_HANDLED;
428}
429
430public change_step_one(id)
431{
432 if (playerData[id][STATUS] != LOGGED || !get_bit(id, dataLoaded)) return PLUGIN_HANDLED;
433
434 new password[32];
435
436 read_args(password, charsmax(password));
437 remove_quotes(password);
438
439 if (!equal(playerData[id][PASSWORD], password)) {
440 if (++playerData[id][FAILS] >= passwordMaxFails) server_cmd("kick #%d ^"Nieprawidlowe haslo!^"", get_user_userid(id));
441
442 client_print_color(id, id, "^x04[CS:GO]^x01 Podane haslo jest^x04 nieprawidlowe^x01. (Bledne haslo^x04 %i/%i^x01)", playerData[id][FAILS], passwordMaxFails);
443
444 set_hudmessage(255, 0, 0, 0.24, 0.07, 0, 0.0, 3.5, 0.0, 0.0);
445 show_hudmessage(id, "Podane haslo jest nieprawidlowe.");
446
447 account_menu(id);
448
449 return PLUGIN_HANDLED;
450 }
451
452 client_print_color(id, id, "^x04[CS:GO]^x01 Wprowadz swoje^x04 nowe haslo^x01.");
453
454 set_hudmessage(255, 128, 0, 0.24, 0.07, 0, 0.0, 3.5, 0.0, 0.0);
455 show_hudmessage(id, "Wprowadz swoje nowe haslo.");
456
457 client_cmd(id, "messagemode WPROWADZ_NOWE_HASLO");
458
459 return PLUGIN_HANDLED;
460}
461
462public change_step_two(id)
463{
464 if (playerData[id][STATUS] != LOGGED || !get_bit(id, dataLoaded)) return PLUGIN_HANDLED;
465
466 new password[32];
467
468 read_args(password, charsmax(password));
469 remove_quotes(password);
470
471 if (equal(playerData[id][PASSWORD], password)) {
472 client_print_color(id, id, "^x04[CS:GO]^x01 Nowe haslo jest^x04 takie samo^x01 jak aktualne.");
473
474 set_hudmessage(255, 0, 0, 0.24, 0.07, 0, 0.0, 3.5, 0.0, 0.0);
475 show_hudmessage(id, "Nowe haslo jest takie samo jak aktualne.");
476
477 account_menu(id);
478
479 return PLUGIN_HANDLED;
480 }
481
482 if (strlen(password) < passwordMinLength) {
483 client_print_color(id, id, "^x04[CS:GO]^x01 Nowe haslo musi miec co najmniej^x04 %i znakow^x01.", passwordMinLength);
484
485 set_hudmessage(255, 0, 0, 0.24, 0.07, 0, 0.0, 3.5, 0.0, 0.0);
486 show_hudmessage(id, "Nowe haslo musi miec co najmniej %i znakow.", passwordMinLength);
487
488 account_menu(id);
489
490 return PLUGIN_HANDLED;
491 }
492
493 copy(playerData[id][TEMP_PASSWORD], charsmax(playerData[][TEMP_PASSWORD]), password);
494
495 client_print_color(id, id, "^x04[CS:GO]^x01 Powtorz swoje nowe^x04 haslo^x01.");
496
497 set_hudmessage(255, 128, 0, 0.24, 0.07, 0, 0.0, 3.5, 0.0, 0.0);
498 show_hudmessage(id, "Powtorz swoje nowe haslo.");
499
500 client_cmd(id, "messagemode POWTORZ_NOWE_HASLO");
501
502 return PLUGIN_HANDLED;
503}
504
505public change_step_three(id)
506{
507 if (playerData[id][STATUS] != LOGGED || !get_bit(id, dataLoaded)) return PLUGIN_HANDLED;
508
509 new password[32];
510
511 read_args(password, charsmax(password));
512 remove_quotes(password);
513
514 if (!equal(password, playerData[id][TEMP_PASSWORD])) {
515 client_print_color(id, id, "^x04[CS:GO]^x01 Podane hasla^x04 roznia sie^x01 od siebie.");
516
517 set_hudmessage(255, 0, 0, 0.24, 0.07, 0, 0.0, 3.5, 0.0, 0.0);
518 show_hudmessage(id, "Podane hasla roznia sie od siebie.");
519
520 account_menu(id);
521
522 return PLUGIN_HANDLED;
523 }
524
525 copy(playerData[id][PASSWORD], charsmax(playerData[][PASSWORD]), password);
526
527 account_query(id, UPDATE);
528
529 set_hudmessage(0, 255, 0, 0.24, 0.07, 0, 0.0, 3.5, 0.0, 0.0);
530 show_hudmessage(id, "Twoje haslo zostalo pomyslnie zmienione.");
531
532 client_print_color(id, id, "^x04[CS:GO]^x01 Twoje haslo zostalo pomyslnie^x04 zmienione^x01.");
533 client_print_color(id, id, "^x04[CS:GO]^x01 Wpisz w konsoli komende^x04 setinfo ^"_%s^" ^"%s^"^x01, aby twoje haslo bylo ladowane automatycznie.", setinfo, playerData[id][PASSWORD]);
534
535 cmd_execute(id, "setinfo _%s %s", setinfo, playerData[id][PASSWORD]);
536 cmd_execute(id, "writecfg %s", setinfo);
537
538 return PLUGIN_HANDLED;
539}
540
541public delete_account(id)
542{
543 if (playerData[id][STATUS] != LOGGED || !get_bit(id, dataLoaded)) return PLUGIN_HANDLED;
544
545 new password[32];
546
547 read_args(password, charsmax(password));
548 remove_quotes(password);
549
550 if (!equal(playerData[id][PASSWORD], password)) {
551 if (++playerData[id][FAILS] >= passwordMaxFails) server_cmd("kick #%d ^"Nieprawidlowe haslo!^"", get_user_userid(id));
552
553 client_print_color(id, id, "^x04[CS:GO]^x01 Podane haslo jest^x04 nieprawidlowe^x01. (Bledne haslo^x04 %i/%i^x01)", playerData[id][FAILS], passwordMaxFails);
554
555 set_hudmessage(255, 0, 0, 0.24, 0.07, 0, 0.0, 3.5, 0.0, 0.0);
556 show_hudmessage(id, "Podane haslo jest nieprawidlowe.");
557
558 account_menu(id);
559
560 return PLUGIN_HANDLED;
561 }
562
563 new menuData[128];
564
565 formatex(menuData, charsmax(menuData), "\wCzy na pewno chcesz \rusunac \wswoje konto?");
566
567 new menu = menu_create(menuData, "delete_account_handle");
568
569 menu_additem(menu, "\rTak");
570 menu_additem(menu, "\wNie^n");
571 menu_additem(menu, "\wWyjdz");
572
573 menu_setprop(menu, MPROP_EXIT, MEXIT_NEVER);
574
575 menu_display(id, menu);
576
577 return PLUGIN_HANDLED;
578}
579
580public delete_account_handle(id, menu, item)
581{
582 if (item == 0) {
583 account_query(id, DELETE);
584
585 console_print(id, "==================================");
586 console_print(id, "==========SYSTEM REJESTRACJI==========");
587 console_print(id, " Skasowales konto o nicku: %s", playerData[id][NAME]);
588 console_print(id, "==================================");
589
590 server_cmd("kick #%d ^"Konto zostalo usuniete!^"", get_user_userid(id));
591 }
592
593 menu_destroy(menu);
594
595 return PLUGIN_CONTINUE;
596}
597
598public sql_init()
599{
600 new host[32], user[32], pass[32], db[32], queryData[128], error[128], errorNum;
601
602 get_cvar_string("csgo_sql_host", host, charsmax(host));
603 get_cvar_string("csgo_sql_user", user, charsmax(user));
604 get_cvar_string("csgo_sql_pass", pass, charsmax(pass));
605 get_cvar_string("csgo_sql_db", db, charsmax(db));
606
607 sql = SQL_MakeDbTuple(host, user, pass, db);
608
609 new Handle:connectHandle = SQL_Connect(sql, errorNum, error, charsmax(error));
610
611 if (errorNum) {
612 log_to_file("csgo-error.log", "Error: %s", error);
613
614 sql = Empty_Handle;
615
616 set_task(5.0, "sql_init");
617
618 return;
619 }
620
621 formatex(queryData, charsmax(queryData), "CREATE TABLE IF NOT EXISTS `csgo_accounts` (`name` VARCHAR(64), `pass` VARCHAR(32), PRIMARY KEY(`name`));");
622
623 new Handle:query = SQL_PrepareQuery(connectHandle, queryData);
624
625 SQL_Execute(query);
626
627 SQL_FreeHandle(query);
628 SQL_FreeHandle(connectHandle);
629
630 sqlConnected = true;
631}
632
633public load_account(id)
634{
635 id -= TASK_LOAD;
636
637 if (!sqlConnected) {
638 set_task(1.0, "load_account", id + TASK_LOAD);
639
640 return;
641 }
642
643 new queryData[128], tempId[1];
644
645 tempId[0] = id;
646
647 formatex(queryData, charsmax(queryData), "SELECT * FROM `csgo_accounts` WHERE name = ^"%s^"", playerData[id][SAFE_NAME]);
648 SQL_ThreadQuery(sql, "load_account_handle", queryData, tempId, sizeof(tempId));
649}
650
651public load_account_handle(failState, Handle:query, error[], errorNum, tempId[], dataSize)
652{
653 new id = tempId[0];
654
655 if (failState) {
656 log_to_file("csgo-error.log", "[CS:GO Accounts] SQL Error: %s (%d)", error, errorNum);
657
658 return;
659 }
660
661 if (SQL_MoreResults(query)) {
662 SQL_ReadResult(query, SQL_FieldNameToNum(query, "pass"), playerData[id][PASSWORD], charsmax(playerData[][PASSWORD]));
663
664 if (playerData[id][PASSWORD][0]) {
665 new password[32], info[32];
666
667 formatex(info, charsmax(info), "_%s", setinfo);
668
669 cmd_execute(id, "exec %s.cfg", setinfo);
670
671 get_user_info(id, info, password, charsmax(password));
672
673 if (equal(playerData[id][PASSWORD], password)) {
674 playerData[id][STATUS] = LOGGED;
675
676 set_bit(id, autoLogin);
677 } else {
678 playerData[id][STATUS] = NOT_LOGGED;
679
680 client_print_color(id, id, "^x04[CS:GO]^x01 Musisz sie^x03 zalogowac^x01, aby miec dostep do glownych funkcji!");
681
682 account_menu(id);
683 }
684
685 cmd_execute(id, "exec config.cfg");
686 }
687 }
688
689 set_bit(id, dataLoaded);
690}
691
692public account_query(id, type)
693{
694 if (!is_user_connected(id)) return;
695
696 new queryData[128], password[32];
697
698 mysql_escape_string(playerData[id][PASSWORD], password, charsmax(password));
699
700 switch(type) {
701 case INSERT: formatex(queryData, charsmax(queryData), "INSERT INTO `csgo_accounts` VALUES (^"%s^", '%s')", playerData[id][SAFE_NAME], password);
702 case UPDATE: formatex(queryData, charsmax(queryData), "UPDATE `csgo_accounts` SET pass = '%s' WHERE name = ^"%s^"", password, playerData[id][SAFE_NAME]);
703 case DELETE: formatex(queryData, charsmax(queryData), "DELETE FROM `csgo_accounts` WHERE name = ^"%s^"", playerData[id][SAFE_NAME]);
704 }
705
706 SQL_ThreadQuery(sql, "ignore_handle", queryData);
707}
708
709public ignore_handle(failState, Handle:query, error[], errorNum, data[], dataSize)
710{
711 if (failState) {
712 if (failState == TQUERY_CONNECT_FAILED) log_to_file("csgo-error.log", "[CS:GO Accounts] Could not connect to SQL database. [%d] %s", errorNum, error);
713 else if (failState == TQUERY_QUERY_FAILED) log_to_file("csgo-error.log", "[CS:GO Accounts] Query failed. [%d] %s", errorNum, error);
714 }
715
716 return PLUGIN_CONTINUE;
717}
718
719public _csgo_check_account(id)
720{
721 if (sql == Empty_Handle) {
722 client_print_color(id, id, "^x04[CS:GO]^x01 Wystapil^x03 blad^x01 podczas tworzenia polaczenia z baza danych!");
723
724 return false;
725 } else if (playerData[id][STATUS] < LOGGED) {
726 client_print_color(id, id, "^x04[CS:GO]^x01 Musisz sie^x03 zalogowac^x01, aby miec dostep do glownych funkcji!");
727
728 account_menu(id);
729
730 return false;
731 }
732
733 return true;
734}