22.09.2014, 14:51
Код:
#include <a_samp> #include <a_mysql> #define host "127.0.0.1" #define user "root" #define db "server2" #define pass "" #define dRegistrar 0 #define dLogar 1 #define dGenero 2 forward IniciarConta(playerid); forward CriarConta(playerid); forward ChecarConta(playerid); main(); static mysql, Name[MAX_PLAYERS][24], IP[MAX_PLAYERS][16] ; native WP_Hash(buffer[], len, const str[]); enum PDATA { ID, Password[129], Admin, VIP, Money, Genero, Skin } new pInfo[MAX_PLAYERS][PDATA]; public OnGameModeInit() { UsePlayerPedAnims(); ShowPlayerMarkers(0); AddPlayerClass(0,1958.3783, 1343.1572, 15.3746,0,0,0,0,0,0,0); mysql_log(LOG_ERROR | LOG_WARNING | LOG_DEBUG); mysql = mysql_connect(host, user, db, pass); if(mysql_errno(mysql) != 0) print("Erro ao conectar ao banco de dados"); return 1; } public OnGameModeExit() { return 1; } public OnPlayerConnect(playerid) { SetPlayerPos(playerid, 154.0621,-1951.3917,51.3438);//local onde jogador estб qndo logar/registrar nгo aparecerar o char SetPlayerCameraPos(playerid, 126.3775,-1974.8680,108.9316);// local da camera SetPlayerCameraLookAt(playerid, 657.95,-1508.55,69.01);//onde a camera estб focada new query[128]; GetPlayerName(playerid, Name[playerid], 24); GetPlayerIp(playerid, IP[playerid], 16); mysql_format(mysql, query, sizeof(query),"SELECT `Password`, `ID` FROM `players` WHERE `Username` = '%e' LIMIT 1", Name[playerid]); mysql_tquery(mysql, query, "ChecarConta", "i", playerid); return 1; } public OnPlayerDisconnect(playerid, reason) { new query[128]; mysql_format(mysql, query, sizeof(query), "UPDATE `players` SET `Admin`=%d, `VIP`=%d, `Money`=%d, `Genero`=%d, `Skin`=%d, WHERE `ID`=%d",\ pInfo[playerid][Admin], pInfo[playerid][VIP], pInfo[playerid][Money],pInfo[playerid][Genero],pInfo[playerid][Skin], pInfo[playerid][ID]); mysql_tquery(mysql, query, "", ""); return 1; } public OnPlayerSpawn(playerid) { SetPlayerPos(playerid, 1140.3031,-2037.5127,68.3737); SetPlayerCameraPos(playerid,1140.3031,-2037.5127,68.3737); SetPlayerFacingAngle ( playerid, -90 ) ; return 1; } public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) { switch(dialogid) { case dLogar: { if(!response) Kick(playerid); new hpass[129]; new query[100]; WP_Hash(hpass, 129, inputtext); if(!strcmp(hpass,pInfo[playerid][Password])) { mysql_format(mysql, query, sizeof(query), "SELECT * FROM `players` WHERE `Username` = '%e' LIMIT 1", Name[playerid]); mysql_tquery(mysql, query, "IniciarConta", "i", playerid); } else { ShowPlayerDialog(playerid, dLogar, DIALOG_STYLE_INPUT, "{F0F569}Logar", "{F7FA9B}Entre com sua senha para jogar\n{FA0A16}Senha incorreta!", "Logar", "Sair"); } } case dRegistrar: { if(!response) return Kick(playerid); if(strlen(inputtext) < 8) return ShowPlayerDialog(playerid, dRegistrar, DIALOG_STYLE_INPUT, "{F0F569}Registrar", "{F7FA9B}Vocк precisa se registrar para jogar.\n{F50A0A}Sua senha deve ter no minimo 8 caracteres!", "Registrar", "Sair"); new query[300]; WP_Hash(pInfo[playerid][Password], 129, inputtext); mysql_format(mysql, query, sizeof(query), "INSERT INTO `players` (`Username`, `Password`, `IP`, `Admin`, `VIP`, `Money`, `Genero`, `Skin`) VALUES ('%e', '%s', '%s', 0, 0, 0, %d, %d)",\ Name[playerid], pInfo[playerid][Password], IP[playerid],pInfo[playerid][Admin], pInfo[playerid][VIP], pInfo[playerid][Money], pInfo[playerid][Genero], pInfo[playerid][Skin]); mysql_tquery(mysql, query, "CriarConta", "i", playerid); } } if(dialogid == dGenero) { if(response) { pInfo[playerid][Genero] = 1; SetPlayerSkin(playerid,171); SetPlayerInterior(playerid,0); ShowPlayerDialog(playerid, dLogar, DIALOG_STYLE_INPUT, "{F0F569}Logar", "{F7FA9B}Agora entre com sua senha para jogar", "Logar", "Sair"); SendClientMessage(playerid,0xDAFC5DAA,"Ok! Vocк й Homem.."); } else { pInfo[playerid][Genero] = 2; SetPlayerSkin(playerid,172); SetPlayerInterior(playerid,0); ShowPlayerDialog(playerid, dLogar, DIALOG_STYLE_INPUT, "{F0F569}Logar", "{F7FA9B}Agora entre com sua senha para jogar", "Logar", "Sair"); SendClientMessage(playerid,0xDAFC5DAA,"Ok! Vocк й Mulher.."); } return 1; } return 1; } public IniciarConta(playerid) { ClearChatbox(playerid, 10); pInfo[playerid][Admin] = cache_get_field_content_int(0, "Admin"); pInfo[playerid][VIP] = cache_get_field_content_int(0, "VIP"); pInfo[playerid][Money] = cache_get_field_content_int(0, "Money"); pInfo[playerid][Genero] = cache_get_field_content_int(0, "Genero"); pInfo[playerid][Skin] = cache_get_field_content_int(0, "Skin"); SetPlayerSkin(playerid,pInfo[playerid][Skin]); GivePlayerMoney(playerid, pInfo[playerid][Money]); new string[64], Nome[MAX_PLAYER_NAME]; GetPlayerName(playerid,Nome,MAX_PLAYER_NAME); format(string,sizeof string,"SERVIDOR: %s seja bem vindo ao nosso servidor !",Nome); SendClientMessage(playerid,0xDAFC5DAA,string); SpawnPlayer(playerid); return 1; } public CriarConta(playerid) { ClearChatbox(playerid, 10); pInfo[playerid][ID] = cache_insert_id(); new string[64], Nome[MAX_PLAYER_NAME]; GetPlayerName(playerid,Nome,MAX_PLAYER_NAME); format(string,sizeof string,"SERVIDOR: %s sua conta foi registrada!",Nome); SendClientMessage(playerid,0xDAFC5DAA,string); ShowPlayerDialog(playerid, dGenero,DIALOG_STYLE_MSGBOX,"{F0F569} Escolha seu Genero","Vocк й Homem ou Mulher?","Homem","Mulher"); printf("Nova conta registrada. ID: %d", pInfo[playerid][ID]); return 1; } public ChecarConta(playerid) { new rows, fields; cache_get_data(rows, fields, mysql); if(rows) { cache_get_field_content(0, "Password", pInfo[playerid][Password], mysql, 129); pInfo[playerid][ID] = cache_get_field_content_int(0, "ID"); printf("Senha: %s ", pInfo[playerid][Password]); ShowPlayerDialog(playerid, dLogar, DIALOG_STYLE_INPUT, "{F0F569}Logar", "{F7FA9B}Entre com sua senha para jogar", "Logar", "Sair"); } else { ShowPlayerDialog(playerid, dRegistrar, DIALOG_STYLE_INPUT, "{F0F569}Registrar", "{F7FA9B}Vocк precisa se registrar para jogar.", "Registrar", "Sair"); } return 1; } stock ClearChatbox(playerid, lines) { if(IsPlayerConnected(playerid)) { for(new i = 0; i < lines; i++) { SendClientMessage(playerid, -1, " "); } } return 1; }