#include <a_samp>#include <a_mysql>///////////////////////////////////////////////////////////////////////////////#define mysql_host \"127.0.0.1\" //Has to be a string#define mysql_user \"root\" //Has to be a string#define mysql_password \"\" //There is none for wamp unless you set one.#define mysql_database \"sa-mp\" //Has to be a string///////////////////////////////////////////////////////////////////////////////#define DIALOG_REGISTER 0#define DIALOG_LOGIN 1///////////////////////////////////////////////////////////////////////////////enum e_params{pname[MAX_PLAYER_NAME],bool:loggedin,score,money};new pParams[MAX_PLAYERS][e_params];new IsRegistered[MAX_PLAYERS];///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// main(){}public OnGameModeInit(){ mysql_connect(mysql_host, mysql_user, mysql_database, mysql_password); mysql_query(\"CREATE TABLE IF NOT EXISTS playerdata(user VARCHAR(24), password VARCHAR(41), score INT(20), money INT(20), IP VARCHAR(16) )\");return 1;}public OnGameModeExit(){return 1;}public OnPlayerRequestClass(playerid, classid){return 1;}public OnPlayerConnect(playerid){///////GetPlayerName(playerid, pParams[playerid][pname], MAX_PLAYER_NAME);///////new query[200];format(query, 200, \"SELECT `IP` FROM `playerdata` WHERE user = \'%s\' LIMIT 1\", pParams[playerid][pname]);mysql_query(query);mysql_store_result();new rows = mysql_num_rows();if(!rows){ ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, \"Regisztráció\", \"Üdvözöllek a szerveren!\\nKérlek gépeld be a használni kívánt jelszavadat!\", \"OK\", \"\");}else if(rows == 1){ new ip[2][16];mysql_fetch_field_row(ip[0], \"IP\");GetPlayerIp(playerid, ip[1], 16);if(strlen(ip[0]) != 0 && !strcmp(ip[0], ip[1], true)){ MySQL_Login(playerid);}else if(!strlen(ip[0]) || strcmp(ip[0], ip[1], true)){ ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, \"Bejelentkezés\", \"Üdvözöllek a szerveren!\\nKérlek gépeld be a használt jelszavad!\", \"OK\", \"\"); IsRegistered[playerid] = 1;}}mysql_free_result();return 1;}public OnPlayerDisconnect(playerid, reason){if(pParams[playerid][loggedin] == true){ pParams[playerid][score] = GetPlayerScore(playerid); pParams[playerid][money] = GetPlayerMoney(playerid);new query[200];format(query, 200, \"UPDATE playerdata SET score=%d, money=%d WHERE user=\'%s\'\", pParams[playerid][score], pParams[playerid][money]);mysql_query(query);}return 1;}public OnVehicleStreamOut(vehicleid, forplayerid){return 1;}public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]){if(dialogid == DIALOG_REGISTER){ if(response) { if(strlen(inputtext) < 3 || strlen(inputtext) > 40) { ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, \"Regisztráció\", \"Üdvözöllek a szerveren!\\nKérlek gépeld be a használni kívánt jelszavadat!\\n{FF0000}3-40 karakter!\", \"OK\", \"\"); } else { new escpass[40]; mysql_real_escape_string(inputtext, escpass); MySQL_Register(playerid, escpass); } } else ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, \"Regisztráció\", \"Üdvözöllek a szerveren!\\nKérlek gépeld be a használni kívánt jelszavadat!\", \"OK\", \"\");}if(dialogid == DIALOG_LOGIN){ if(response){ new query[200]; new escapepass[100]; mysql_real_escape_string(inputtext, escapepass); format(query, 200, \"SELECT `user` FROM playerdata WHERE user = \'%s\' AND password = \'%s\'\", pname, escapepass); mysql_query(query); mysql_store_result(); new rows = mysql_num_rows(); if(rows == 1) MySQL_Login(playerid); if(!rows) { ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, \"Bejelentkezés\", \"{FF0000}Hibás jelszó!\", \"OK\", \"\"); } mysql_free_result();}else ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, \"Bejelentkezés\", \"Üdvözöllek a szerveren!\\nKérlek gépeld be a használt jelszavad!\", \"OK\", \"\");}return 1;}public OnPlayerClickPlayer(playerid, clickedplayerid, source){return 1;} stock MySQL_Register(playerid, passwordstring[]){new query[200];new ip[16];GetPlayerIp(playerid, ip, 16);format(query, 200, \"INSERT INTO playerdata (user, password, score, money, IP) VALUES (\'%s\', \'%s\', 0, 0, \'%s\')\", pParams[playerid][pname], passwordstring, ip);mysql_query(query);pParams[playerid][loggedin] = true;SendClientMessage(playerid, 0x00FF00AA, \"Regisztrálva!\");return 1;}stock MySQL_Login(playerid){new query[300];new savingstring[20];format(query, 300, \"SELECT * FROM playerdata WHERE user = \'%s\'\", pParams[playerid][pname]);mysql_query(query);mysql_store_result();while(mysql_fetch_row_format(query, \"|\")){ mysql_fetch_field_row(savingstring, \"score\"); SetPlayerScore(playerid, strval(savingstring)); mysql_fetch_field_row(savingstring, \"money\"); SetPlayerMoney(playerid, strval(savingstring));}mysql_free_result();SendClientMessage(playerid, 0x00FF00AA, \"Üdvözlünk újra itt!\");pParams[playerid][loggedin] = true;return 1;}stock SetPlayerMoney(playerid, cash){ResetPlayerMoney(playerid);GivePlayerMoney(playerid, cash);return 1;}
format(query, 200, \"SELECT `user` FROM playerdata WHERE user = \'%s\' AND password = \'%s\'\", pname, escapepass); mysql_query(query); mysql_store_result();
format(query, 200, \"SELECT * FROM `accounts(írdát)` WHERE Name(írdát) = \'%s\' AND password = \'%s\'\", pname, escapepass); mysql_query(query); mysql_store_result();
format(query, 200, \"SELECT * FROM `playerdata` WHERE user = \'%s\' AND password = \'%s\'\", pname, escapepass); mysql_query(query); mysql_store_result();
new query[200];format(query, 200, \"UPDATE playerdata SET score=%d, money=%d WHERE user=\'%s\'\", pParams[playerid][score], pParams[playerid][money]);mysql_query(query);
stock pName(playerid) {new name[24];GetPlayerName(playerid,name,24);return name;}
format(query, 200, \"SELECT * FROM `playerdata` WHERE user = \'%s\' AND password = \'%s\'\", pName(playerid), escapepass); mysql_query(query); mysql_store_result();
Jó ezeket én is tudom, csak nem tudtam kiigazodni hogy mi az az userdata, user meg hogy hogyan használja stb...