Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Baza de date
- #define mysql_host "localhost"
- #define mysql_db "gamemode"
- #define mysql_user "root"
- #define mysql_pass ""
- //Include
- #include <a_samp>
- #include <a_actor>
- #include <a_mysql>
- #include <zcmd>
- //Define
- #define SCM SendClientMessage
- //Define Culori
- #define COLOR_WHITE 0xFFFFFF
- #define COLOR_RED 0xFC1F1FFF
- #define COLOR_YELLOW 0xF3F930FF
- #define COLOR_ORANGE 0xFBAB09FF
- #define COLOR_BLUE 0x2F3CFAFF
- #define COLOR_PINK 0xF92AB0FF
- #define COLOR_GREEN 0x5EF73FFF
- //Variabile
- new ActorBonus;
- new handle;
- //Enum
- enum pInfo
- {
- pID,
- pPassword,
- pSex,
- pAge,
- pEmail,
- pLevel,
- pRP,
- pAdmin,
- pHelper
- }
- //Enum Dialog
- new P_Data[MAX_PLAYERS][pInfo];
- enum
- {
- DIALOG_REGISTER,
- DIALOG_LOGIN,
- DIALOG_SEX,
- DIALOG_AGE,
- DIALOG_EMAIL,
- DIALOG_WELCOME
- }
- //Define Dialog
- #define DIALOG_REIGSTER 1
- #define DIALOG_LOGIN 2
- main()
- {
- print("\n----------------------------------");
- print("Nu dau teapa, eu zic ca merge ca trebuie :)");
- print("----------------------------------\n");
- }
- public OnGameModeInit()
- {
- MySQLConnect();
- EnableStuntBonusForAll(0);
- DisableInteriorEnterExits();
- UsePlayerPedAnims();
- ActorBonus = CreateActor(250, 1828.9287,-1875.0154,13.5600,88.8360);
- SetActorInvulnerable(ActorBonus , true);
- ApplyActorAnimation(ActorBonus , "COP_AMBIENT", "Coplook_loop", 4.0, 0, 1, 1, 1, -1);
- Create3DTextLabel("Salut, vino aici si ia bonusul de venit.\nFoloseste comanda [/bonus] pentru a-l lua!", COLOR_WHITE, 1828.9287,-1875.0154,13.5600, 30.0, 0, 0);
- SetGameModeText("RPG V0.1");
- AddPlayerClass(292,1814.5961,-1897.8883,13.5775,322.1244, 0, 0, 0, 0, 0,0);
- return 1;
- }
- public OnGameModeExit()
- {
- mysql_close(handle);
- return 1;
- }
- public OnPlayerRequestClass(playerid, classid)
- {
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- new query[100];
- mysql_format(handle, query, sizeof(query), "SELECT * FROM conturi WHERE Name = '%s'", GetName(playerid));
- mysql_tquery(handle, query, "OnPlayerLogin", "i", playerid);
- return 1;
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- return 1;
- }
- public OnPlayerSpawn(playerid)
- {
- return 1;
- }
- public OnPlayerDeath(playerid, killerid, reason)
- {
- return 1;
- }
- public OnVehicleSpawn(vehicleid)
- {
- return 1;
- }
- public OnVehicleDeath(vehicleid, killerid)
- {
- return 1;
- }
- public OnPlayerText(playerid, text[])
- {
- return 1;
- }
- public OnPlayerCommandText(playerid, cmdtext[])
- {
- return 1;
- }
- public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
- {
- return 1;
- }
- public OnPlayerExitVehicle(playerid, vehicleid)
- {
- return 1;
- }
- public OnPlayerStateChange(playerid, newstate, oldstate)
- {
- return 1;
- }
- public OnPlayerEnterCheckpoint(playerid)
- {
- return 1;
- }
- public OnPlayerLeaveCheckpoint(playerid)
- {
- return 1;
- }
- public OnPlayerEnterRaceCheckpoint(playerid)
- {
- return 1;
- }
- public OnPlayerLeaveRaceCheckpoint(playerid)
- {
- return 1;
- }
- public OnRconCommand(cmd[])
- {
- return 1;
- }
- public OnPlayerRequestSpawn(playerid)
- {
- return 1;
- }
- public OnObjectMoved(objectid)
- {
- return 1;
- }
- public OnPlayerObjectMoved(playerid, objectid)
- {
- return 1;
- }
- public OnPlayerPickUpPickup(playerid, pickupid)
- {
- return 1;
- }
- public OnVehicleMod(playerid, vehicleid, componentid)
- {
- return 1;
- }
- public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
- {
- return 1;
- }
- public OnVehicleRespray(playerid, vehicleid, color1, color2)
- {
- return 1;
- }
- public OnPlayerSelectedMenuRow(playerid, row)
- {
- return 1;
- }
- public OnPlayerExitedMenu(playerid)
- {
- return 1;
- }
- public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
- {
- return 1;
- }
- public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
- {
- return 1;
- }
- public OnRconLoginAttempt(ip[], password[], success)
- {
- return 1;
- }
- public OnPlayerUpdate(playerid)
- {
- return 1;
- }
- public OnPlayerStreamIn(playerid, forplayerid)
- {
- return 1;
- }
- public OnPlayerStreamOut(playerid, forplayerid)
- {
- return 1;
- }
- public OnVehicleStreamIn(vehicleid, forplayerid)
- {
- return 1;
- }
- public OnVehicleStreamOut(vehicleid, forplayerid)
- {
- return 1;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- new query[128], ip[25];// se creaza interogarea si ip.
- switch(dialogid)// se va folosi switch pentru a selecta dialogul
- {
- case DIALOG_REGISTER:// daca se va selecta dialogul register
- {
- if(!response)
- return Kick(playerid);// daca se va apasa pe butonul Exit ii va da kick
- if(response)// daca se apasa pe Butonul inregistrare se vor face urmatoarele verificari
- {
- if(!strlen(inputtext))// daca nu e scris nimic la parola
- return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Parola incorecta!", "Introdu-ti o parola pentru a te inregistra pe server! n", "Inregistreaza", "Exit");// ii va da din nou dialogul register cu mesajul specific
- GetPlayerIp(playerid, ip, sizeof(ip));// definim ip-ul de mai sus
- mysql_format(handle, query, sizeof(query), "INSERT INTO conturi (Name, Password, IP) VALUES ('%s', '%e', '%s')", GetName(playerid), inputtext, ip);// se insereaza in tabelul cu conturi numele playerului, parola pe care a scris-o si ip pe care il are
- mysql_query(handle, query);// se va trimite setarile si se va interoga callback-ul OnRegistration
- SpawnPlayer(playerid); // ii da spawn
- }
- return 1;
- }
- case DIALOG_LOGIN:// daca se va selecta dialogul de login
- {
- if(!response) return Kick(playerid);// si se va apasa pe butonul exit ii va da kick
- if(response)//daca se apasa pe butonul LOGARE se va face urmatoarele verificari
- {
- if(!strlen(inputtext))// daca nu a scris nimic la parola
- return ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Parola incorecta!", "Te rog sa iti introduci parola corecta, pentru a te loga pe server.", "Logare", "Exit");// ii va da dialogul cu login cu mesajul specific
- mysql_format(handle, query, sizeof(query), "SELECT * FROM `users` WHERE `Name`='%e' AND `Password` = '%e'", GetName(playerid),inputtext);// va fi selectata parola de la tabelul cu conturi
- mysql_tquery(handle, query, "OnLogin", "i", playerid);// se va face apel la baza si se va interoga CallBackUl OnLogin (Tquery = take query sau ia interogare in romana)
- }
- return 1;
- }
- }
- return 1;
- }
- public OnPlayerClickPlayer(playerid, clickedplayerid, source)
- {
- return 1;
- }
- forward OnPlayerLogin(playerid);// se creaza callbac-ul
- public OnPlayerLogin(playerid)//Se creaza publicul
- {
- new rows, fields;// definim rows(randurile)si fields(domeniile)
- cache_get_data(rows, fields);//cache_get_data interogheaza date din baza de date. acele date sunt rows si fields
- if(rows)// atunci cand playerul se inregistreaza i se va crea niste randuri. Daca i se gasesc atunci cand se va conecta ii va da:
- {
- ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Logheaza-te!", "Te rog sa-ti introduci parola contuului mai jos!", "Logare", "Exit");// dialogul register
- }
- else// daca nu i se gasesc randuri, adica daca contul nu exista, atunci i se va da urmatorul dialog
- {
- ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Inregistrare", "Trebuie sa iti creezi un cont ca sa joci pe server.\nTasteaza mai jos o parola, pentru a te inregistra!", "Inregistreaza", "Exit");// dialogul register
- }
- return 1;
- }
- forward OnLogin(playerid);// definim callback ul
- public OnLogin(playerid)// facem publicul
- {
- new rows, fields,temporar[200];
- cache_get_data(rows, fields);
- if(rows)
- {
- //deci daca are randuri
- cache_get_field_content(0, "Password",temporar), format(P_Data[playerid][pPassword], 25, temporar);// i se vaextrage parola si i se verifica daca coincide cu numele. Se foloseste new-ul temporar pentru extragerea parolei, ea retinandu-se temporar(pana cand se deconecteaza jucatorul)
- P_Data[playerid][pID] = cache_get_field_content_int(0, "ID");
- SpawnPlayer(playerid);// si se va da spawn
- }
- else
- {
- ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Parola incorecta!", "Te rog sa iti introduci parola corecta, pentru a te loga pe server.", "Logare", "Exit");// ii va da dialogul cu mesajul specific.
- }
- return 1;
- }
- forward MySQLConnect();
- public MySQLConnect()
- {
- handle = mysql_connect("localhost", "root", "gamemode", "");
- if(mysql_errno() != 0)
- {
- printf("Conexiunea la baza de date %s a esuat ---> Server Inchis ~~~", mysql_db);
- SendRconCommand("exit");
- }
- else
- {
- printf("Conexiunea la baza de date '%s' cu user-ul '%s' a reusit!!!", mysql_db, mysql_user);
- }
- return 1;
- }
- stock GetName(playerid)
- {
- new Name[MAX_PLAYER_NAME + 1];
- GetPlayerName(playerid, Name, sizeof(Name));
- return Name;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement