Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- native WP_Hash(buffer[],len,const str[]);
- enum PlayerInfo{
- ID,
- pName[128],
- pPassword[130],
- Float: Pos[3],
- Skin,
- pAdminLevel,
- pBanned,
- pHealth,
- pArmour,
- }
- new PlayerStats[MAX_PLAYERS][PlayerInfo];
- stock GetName(playerid)
- {
- new name[MAX_PLAYER_NAME];
- GetPlayerName(playerid, name, sizeof(name));
- strreplace(name, '_', ' ');
- return name;
- }
- stock LoginPlayer(playerid)
- {
- new query[500],string[256];
- format(query,sizeof(query),"SELECT * EVERYTHING FROM accounts WHERE name = '%s'", GetName(playerid));
- mysql_query(query);
- mysql_store_result();
- while(mysql_fetch_row_format(query,"|"))
- {
- mysql_fetch_field_row(string, "id"); PlayerStats[playerid][ID] = strval(string);
- mysql_fetch_field_row(PlayerStats[playerid][pName],"Name");
- mysql_fetch_field_row(PlayerStats[playerid][pPassword],"Password");
- mysql_fetch_field_row(string, "PlayerPos"); sscanf(query,"fff",PlayerStats[playerid][Pos][0],PlayerStats[playerid][Pos][1],PlayerStats[playerid][Pos][2]);
- mysql_fetch_field_row(string, "AdminLevel"); PlayerStats[playerid][pAdminLevel] = strval(string);
- mysql_fetch_field_row(string, "Skin"); PlayerStats[playerid][Skin] = strval(string);
- mysql_fetch_field_row(string, "Health"); PlayerStats[playerid][pHealth] = floatstr(string);
- mysql_fetch_field_row(string, "Armour"); PlayerStats[playerid][pArmour] = floatstr(string);
- }
- mysql_free_result();
- AddPlayerClass(PlayerStats[playerid][Skin], PlayerStats[playerid][Pos][0], PlayerStats[playerid][Pos][1], PlayerStats[playerid][Pos][2], 0, 0, 0, 0, 0, 0, 0);
- SetSpawnInfo(playerid, 0, PlayerStats[playerid][Skin], PlayerStats[playerid][Pos][0], PlayerStats[playerid][Pos][1], PlayerStats[playerid][Pos][2], 90, 0, 0, 0, 0, 0, 0);
- SpawnPlayer(playerid);
- SetPlayerPos(playerid, PlayerStats[playerid][Pos][0], PlayerStats[playerid][Pos][1], PlayerStats[playerid][Pos][2]);
- SetPlayerSkin(playerid, PlayerStats[playerid][Skin]);
- SetCameraBehindPlayer(playerid);
- SetPlayerHealth(playerid, PlayerStats[playerid][pHealth]);
- SetPlayerArmour(playerid, PlayerStats[playerid][pArmour]);
- SetPlayerInterior(playerid, 0);
- SetPlayerVirtualWorld(playerid, 0);
- }
- stock SavePlayerStats(playerid)
- {
- new query[500], EncryptPass[130];
- WP_Hash(EncryptPass,sizeof(EncryptPass),PlayerStats[playerid][pPassword]);
- GetPlayerPos(playerid,PlayerStats[playerid][Pos][0],PlayerStats[playerid][Pos][1],PlayerStats[playerid][Pos][2]);
- format(query,sizeof(query),"UPDATE accounts SET Name = '%s', Password = '%s', PlayerPos = '%f %f %f', AdminLevel = '%d', Skin = '%d' WHERE id = '%d'",GetName(playerid),PlayerStats[playerid][pPassword],PlayerStats[playerid][Pos][0],
- PlayerStats[playerid][Pos][1],PlayerStats[playerid][Pos][2],PlayerStats[playerid][pAdminLevel],PlayerStats[playerid][Skin],PlayerStats[playerid][ID]);
- mysql_query(query);
- printf("Player %s has been saved into the mysql table",GetName(playerid));
- }
- stock RegisterPlayer(playerid,registeredpassword[])
- {
- new query[256], EncryptPass[130];
- WP_Hash(EncryptPass,sizeof(EncryptPass),registeredpassword);
- format(query,sizeof(query),"INSERT INTO accounts (Name, Password, PlayerPos, Skin) ('%s', '%s', '1.0,2.0,3.0','299')",GetName(playerid),EncryptPass);
- mysql_query(query);
- LoginPlayer(playerid);
- return 1;
- }
- stock CheckBan(playerid)
- {
- new query[128], playerIPAddress[128];
- GetPlayerIp(playerid,playerIPAddress,sizeof(playerIPAddress));
- format(query,sizeof(query),"SELECT * FROM bans WHERE (name = '%s' OR IPAddress = '%s') AND status = 1",GetName(playerid),playerIPAddress);
- mysql_query(query);
- mysql_store_result();
- if(mysql_num_rows() >= 1)
- {
- new banReason[128], bannedBy[50], dialogString[128];
- while(mysql_fetch_row_format(query,"|"))
- {
- mysql_fetch_field_row(banReason,"Reason");
- mysql_fetch_field_row(bannedBy,"BannedBy");
- format(dialogString,sizeof(dialogString),"You are banned from this server\nReason: %s\nBanned by: %s",banReason,bannedBy);
- ShowPlayerDialog(playerid,dialogThreadBanned,DIALOG_STYLE_MSGBOX,"Banned",dialogString,"Close","");
- }
- return 1;
- }
- mysql_free_result();
- return 0;
- }
- public OnPlayerConnect(playerid)
- {
- new query[128];
- if(CheckBan(playerid) == 0)
- {
- format(query,sizeof(query),"SELECT * FROM bans WHERE (name = '%s' OR IPAddress = '%s') AND status = 1");
- mysql_query(query);
- format(query,sizeof(query),"SELECT * FROM accounts WHERE name = '%s'",GetName(playerid));
- mysql_query(query);
- mysql_store_result();
- if(mysql_num_rows() == 1)
- {
- SendClientMessage(playerid,COLOUR_WHITE,"That username is registered.");
- ShowPlayerDialog(playerid,dialogThreadLogin,DIALOG_STYLE_INPUT, "Login", "Enter your password to login","Login", "Back");
- }
- else
- {
- SendClientMessage(playerid,COLOUR_WHITE,"That username is not registered.");
- ShowPlayerDialog(playerid,dialogThreadRegister,DIALOG_STYLE_INPUT, "Register", "Enter a password to register this account","Register", "Back");
- }
- }
- return 1;
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- SavePlayerStats(playerid);
- return 1;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- switch(dialogid)
- {
- case dialogThreadLogin:
- {
- if(response)
- {
- new query[256], EncryptPass[130];
- WP_Hash(EncryptPass,sizeof(EncryptPass),inputtext);
- format(query,sizeof(query),"SELECT * FROM accounts WHERE name = '%s' AND password = '%s'", GetName(playerid),EncryptPass);
- mysql_query(query);
- mysql_store_result();
- if(mysql_num_rows() == 1)
- {
- LoginPlayer(playerid);
- }
- else
- {
- SendClientMessage(playerid,COLOUR_WHITE,"You have entered an incorrect password!");
- ShowPlayerDialog(playerid,dialogThreadLogin,DIALOG_STYLE_INPUT, "Login", "Enter your password to login","Login", "Back");
- }
- }
- }
- case dialogThreadRegister:
- {
- if(response)
- {
- RegisterPlayer(playerid,inputtext);
- }
- }
- case dialogThreadBanned:
- {
- if(response)
- {
- Kick(playerid);
- }
- }
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement