Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- .Andy47.
- MySql R8 Login Register System
- */
- // *** Includes
- #include <a_samp>
- #include <a_mysql>
- #include <zcmd>
- // *** Defines
- #define mysql_host "localhost"
- #define mysql_user "root"
- #define mysql_db "legend"
- #define mysql_pass ""
- #define COLOR_GREY 0xAFAFAFAA
- #define G "{00FF00}"
- #define W "{FFFFFF}"
- #define LB "{00C0FF}"
- #define O "{FFAF00}"
- #define R "{F81414}"
- #define SRV "{AFE7FF}"
- #define GR "{C3C3C3}"
- #define Function::%0(%1) forward%0(%1); public%0(%1)
- // *** News
- new gQuery[2800], gString[4000];
- // *** Functii
- #define SPD ShowPlayerDialog
- #define SCM SendClientMessage
- stock bool:False = false;
- #define SCMF(%0,%1,%2,%3)\
- do{\
- gString[0] = EOS;\
- format(gString,256,(%2),%3);\
- SendClientMessage((%0),(%1),gString);\
- }\
- while( False )
- // *** Enums
- enum
- {
- THREAD_DIALOG_REGISTER,
- THREAD_DIALOG_LOGIN
- }
- enum PlayerData
- {
- ID,
- pKills,
- pDeaths,
- pMoney
- }
- new P_DATA[MAX_PLAYERS][PlayerData];
- new bool:Logged[MAX_PLAYERS];
- main()
- {
- print(" MySql Project ");
- print(" MySql r8 ");
- print(" by .ANdy47. ");
- }
- public OnGameModeInit()
- {
- //===============================MySql Connect==================================
- mysql_connect(mysql_host,mysql_user,mysql_db,mysql_pass);
- //==============================================================================
- SetGameModeText("MySql Project");
- AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
- UsePlayerPedAnims();
- DisableInteriorEnterExits();
- SetTimer("SavePlayerData",600000,false); // odata la 10 minute se salveaza conturile
- return 1;
- }
- public OnGameModeExit()
- {
- return 1;
- }
- public OnPlayerRequestClass(playerid, classid)
- {
- SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
- SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
- SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- new pName[MAX_PLAYER_NAME],
- pName1[MAX_PLAYER_NAME],
- string[256];
- GetPlayerName(playerid,pName,sizeof(pName));
- mysql_real_escape_string(pName,pName1);
- format(string,sizeof(string),"SELECT `Name` FROM `Users` WHERE `Name` = '%s' LIMIT 0,1",pName1);
- mysql_function_query(1,string,true,"AccountLoad","is",playerid,pName1);
- return 1;
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- if(Logged[playerid] == false) // daca playerul nu este logat i se va sterge contul
- {
- gQuery[0] = EOS;
- format(gQuery, 256, "SELECT `Name` FROM `Users` WHERE `Name` = '%s' LIMIT 0,1", GetName(playerid));
- mysql_function_query(1, gQuery, true, "DeletePlayerAccount", "s", GetName(playerid));
- }
- else
- {
- SavePlayerData(playerid);
- }
- return 1;
- }
- public OnPlayerSpawn(playerid)
- {
- SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
- return 1;
- }
- public OnPlayerDeath(playerid, killerid, reason)
- {
- P_DATA[playerid][pDeaths] ++;
- P_DATA[killerid][pKills] ++;
- return 1;
- }
- public OnVehicleSpawn(vehicleid)
- {
- return 1;
- }
- public OnVehicleDeath(vehicleid, killerid)
- {
- return 1;
- }
- public OnPlayerText(playerid, text[])
- {
- 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[])
- {
- switch(dialogid)
- {
- case THREAD_DIALOG_REGISTER:
- {
- if(!response)
- return SetTimerEx("KickRegister",500,false,"i",playerid);
- if(response)
- {
- new string[256];
- gQuery[0] = EOS;
- format(gQuery, 256, ""W"Nu ai introdus nici o parola!\n"W"Te rugam introdu parola cu care vrei sa te inregistrezi!");
- if(!strlen(inputtext)) return SPD(playerid,THREAD_DIALOG_REGISTER,DIALOG_STYLE_PASSWORD,""GR"Inregistrare",gQuery,"Register","Kick");
- format(string, sizeof(string),"INSERT INTO `Users`(Name,Password,Kills,Deaths,Money) VALUES('%s','%s','0','0','0')",GetName(playerid),inputtext);
- mysql_function_query(1,string,false,"","");
- format(gQuery, 256,""W"Bine ai venit inapoi, "LB"%s!\nPoti sa te loghezi.",GetName(playerid));
- SPD(playerid,THREAD_DIALOG_LOGIN,DIALOG_STYLE_PASSWORD,""GR"Logare",gQuery,"Login","Cancel");
- }
- }
- case THREAD_DIALOG_LOGIN:
- {
- if(!response)
- return SetTimerEx("KickRegister",500,false,"i",playerid);
- if(response)
- {
- gQuery[0] = EOS;
- new q_str[256];
- format(q_str,sizeof(q_str),"SELECT `Name` FROM `Users` WHERE `Name` = '%s' AND `Password` = '%s'", GetName(playerid),inputtext);
- mysql_function_query(1,q_str,true,"Query_LoadP_DATA","is",playerid,GetName(playerid));
- Logged[playerid] = true;
- SpawnPlayer(playerid);
- }
- }
- }
- return 1;
- }
- public OnPlayerClickPlayer(playerid, clickedplayerid, source)
- {
- return 1;
- }
- CMD:stats(playerid, params[])
- {
- SCMF(playerid, -1,""SRV"Name: %s Kills: %d Deaths: %d Money: %d",GetName(playerid),P_DATA[playerid][pKills],P_DATA[playerid][pDeaths],P_DATA[playerid][pMoney]);
- return 1;
- }
- Function:: Query_LoadP_DATA(playerid,q_acc[])
- {
- new q_rows,
- q_fields,
- q_str[150];
- cache_get_data(q_rows,q_fields);
- if(!q_rows)
- {
- new str[300];
- format(str,sizeof(str),""W"Hey "LB"%s !\nAi introdus parola gresita\nTe rugam rescrieti parola mai jos pentru a te loga .",GetName(playerid));
- SPD(playerid,THREAD_DIALOG_LOGIN,DIALOG_STYLE_PASSWORD,""GR"Login",str,"Login","exit");
- }
- else
- {
- format(q_str, sizeof(q_str),"SELECT * FROM `Users` WHERE Name = '%s'",q_acc);
- mysql_function_query(1, q_str,true,"OnPlayerCheckedLogin","ds",playerid,q_acc);
- }
- return 1;
- }
- Function:: OnPlayerCheckedLogin(playerid)
- {
- P_DATA[playerid][ID] = cache_get_field_content_int(0, "ID");
- P_DATA[playerid][pKills] = cache_get_field_content_int(0, "Kills");
- P_DATA[playerid][pDeaths] = cache_get_field_content_int(0, "Deaths");
- P_DATA[playerid][pMoney] = cache_get_field_content_int(0, "Money");
- return 1;
- }
- Function:: AccountLoad(playerid,q_acc[])
- {
- new q_rows,
- q_fields;
- cache_get_data(q_rows,q_fields);
- if(q_rows)
- {
- gQuery[0] = EOS;
- format(gQuery,256,""W"Bine ai venit inapoi, "LB"%s!\nPoti sa te loghezi.",q_acc);
- SPD(playerid,THREAD_DIALOG_LOGIN,DIALOG_STYLE_PASSWORD,""GR"Logare",gQuery,"Login","Cancel");
- }
- else
- {
- gQuery[0] = EOS;
- format(gQuery, 256,""W"Bun Venit, "LB"%s!\nPoti sa te inregistrezi!",q_acc);
- SPD(playerid,THREAD_DIALOG_REGISTER,DIALOG_STYLE_PASSWORD,""GR"Inregistrare",gQuery,"Register","Kick");
- }
- return 1;
- }
- Function:: SavePlayerData(playerid)
- {
- new ks = P_DATA[playerid][pKills],
- dth = P_DATA[playerid][pDeaths],
- mn = P_DATA[playerid][pMoney];
- gQuery[0] = EOS;
- format(gQuery, 256,"UPDATE `Users` SET `Kills`='%d',`Deaths`='%d',`Money`='%d'WHERE `Name`='%s'",ks,dth,mn,GetName(playerid));
- mysql_function_query(1,gQuery,false,"","");
- SendClientMessageToAll(-1,""LB"Conturi:"O"Conturile au fost salvate in baza de date.");
- return 1;
- }
- Function:: DeletePlayerAccount(q_acc[])
- {
- new rows, fields;
- cache_get_data(rows, fields);
- if(rows)
- {
- gQuery[0] = EOS;
- format(gQuery, 256, "DELETE FROM `Users` WHERE `Name` = '%s'", q_acc);
- mysql_function_query(1, gQuery, false, "", "");
- }
- return 1;
- }
- stock GetName(playerid)
- {
- new AlEx[24];
- GetPlayerName(playerid,AlEx,sizeof(AlEx));
- return AlEx;
- }
- // *** Kick Function
- Function:: KickRegister(playerid)
- {
- Kick(playerid);
- SCMF(playerid,-1,""SRV"%s ai primit kick!",GetName(playerid));
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement