Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define DIALOG_REGISTER 1
- #define DIALOG_LOGIN 2
- #define RAUDONA 0xFF0000FF
- #define MELYNA 0x0087FFFF
- #define LIME 0x19FF00FF
- new manomysql;
- forward OnUserCheck(playerid);
- public OnGameModeInit()
- {
- manomysql = mysql_connect(db_host, db_user, db_db, db_pass);
- return 1;
- }
- public OnGameModeExit()
- {
- mysql_close(manomysql);
- return 1;
- }
- public OnUserCheck(playerid)
- {
- new num_rows, num_fields;
- cache_get_data(num_rows, num_fields, manomysql);
- if(num_rows == 0)
- {
- //Register
- ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Registracija", "Prašome įvesti sugalvotą slaptažodį!", "Registruotis", "Išeiti");
- }
- else
- {
- //Login
- }
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- new vardas [MAX_PLAYER_NAME], query[64];
- GetPlayerName(playerid, vardas, sizeof(vardas));
- format(query, sizeof(query), "SELECT `id` FROM `user` WHERE `vardas` = '%s'", vardas);
- mysql_function_query(manomysql, query, true, "OnUserCheck", "i", playerid);
- return 1;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- if(dialogid == DIALOG_REGISTER)
- {
- if(response)
- {
- //Slaptažodžio ilgis
- new vardas[MAX_PLAYER_NAME], query[64], slaptazodis[32];
- GetPlayerName(playerid, vardas, sizeof(vardas));
- if(strlen(inputtext) >= 6)
- {
- mysql_escape_string(inputtext, slaptazodis, manomysql);
- format(query, sizeof(query), "INSERT INTO `user` (`vardas`, `slaptazodis`) VALUES ('%s', '%s')", vardas, inputtext);
- mysql_function_query(manomysql, query, false, "", "");
- SendClientMessage(playerid, LIME, "Sėkmingai užsiregistravote serveryje! Gero žaidimo");
- }
- else
- {
- SendClientMessage(playerid, MELYNA, "Slaptažodis turi būti bent 6 simbolių ilgio!");
- ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Registracija", "Prašome įvesti sugalvotą slaptažodį!", "Registruotis", "Išeiti");
- }
- }
- else
- {
- Kick(playerid);
- SendClientMessage(playerid, RAUDONA, "Atšaukėte registraciją!");
- }
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment