Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #include <a_mysql>
- native WP_Hash(buffer[], len, const str[]); //Hashing the passwords
- //============= DATABASE =============== //
- #define MYSQL_HOST "x" //hiding for security reasons
- #define MYSQL_USER "x"
- #define MYSQL_PASSWORD "x"
- #define MYSQL_DATABASE "x"
- //============= NEWLY REGISTERED PLAYERS ============== //
- #define SPAWN_X 10.0
- #define SPAWN_Y 10.0
- #define SPAWN_Z 14.0
- #define SPAWN_A 0.0
- //============= DIALOG REGISTER / LOGIN =============== //
- enum
- {
- LoginDialog,
- RegisterDialog
- };
- new
- mysql;
- //============ PLAYER DATA =============== //
- enum PlayerData
- {
- ID,
- Name[MAX_PLAYER_NAME],
- Password[129],
- IP[16],
- Admin,
- VIP,
- Money,
- Float:posX,
- Float:posY,
- Float:posZ,
- Float:posR,
- Gun1,
- Ammo1,
- Gun2,
- Ammo2,
- Gun3,
- Ammo3,
- Skin
- };
- new PlayerInfo[MAX_PLAYERS][PlayerData];
- //============ FORWARDS ================= //
- forward OnAccountCheck(playerid);
- main()
- {
- print("\n----------------------------------");
- print(" Blank Gamemode by your name here");
- print("----------------------------------\n");
- }
- public OnGameModeInit()
- {
- // Don't use these lines if it's a filterscript
- SetGameModeText("GTA RPG"); //Tha name
- UsePlayerPedAnims(); //Walking like CJ
- mysql_log(LOG_ALL);
- mysql = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_DATABASE, MYSQL_PASSWORD);
- if(mysql_errno() != 0)
- {
- printf("[MySQL] Could not connect to MYSQL Database :(");
- }
- else
- {
- printf("[MySQL] Successfully connected to MYSQL Database!");
- }
- 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)
- {
- TogglePlayerSpectating(playerid, true);
- new
- query[128],
- playername[MAX_PLAYER_NAME];
- GetPlayerName(playerid, playername, sizeof(playername));
- mysql_format(mysql, query, sizeof(query), "SELECT `Password`, `ID` FROM `accounts` WHERE `Name` = '%e' LIMIT 1", playername);
- mysql_tquery(mysql, query, "OnAccountCheck", "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[])
- {
- if (strcmp("/mycommand", cmdtext, true, 10) == 0)
- {
- // Do something here
- return 1;
- }
- return 0;
- }
- 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 LoginDialog:
- {
- if(!response) Kick(playerid);
- new
- hashpass[129],
- query[100],
- playername[MAX_PLAYER_NAME];
- GetPlayerName(playerid, playername, sizeof(playername));
- WP_Hash(hashpass, sizeof(hashpass), inputtext);
- if(!strcmp(hashpass, PlayerInfo[playerid][Password]))
- {
- mysql_format(mysql, query, sizeof(query), "SELECT * FROM `accounts` WHERE `Name` = '%e' LIMIT 1", playername);
- mysql_tquery(mysql, query, "OnAccountLoad", "i", playerid);
- }
- else
- {
- SendClientMessage(playerid, -1, "You have specified an incorrect password!");
- ShowPlayerDialog(playerid, LoginDialog, DIALOG_STYLE_INPUT, "Login", "Welcome player!\nYour account has been found in our database. Please fill in your password:", "Login", "Quit");
- }
- }
- case RegisterDialog:
- {
- if(!response) return Kick(playerid);
- if(strlen(inputtext) < 5)
- {
- SendClientMessage(playerid, -1, "Your password must at least contain more than 4 characters.");
- return ShowPlayerDialog(playerid, RegisterDialog, DIALOG_STYLE_INPUT, "Register", "Welcome player!\nYour account has not been registered yet. Please fill in your desired password:", "Register", "Quit");
- }
- new
- query[512],
- playername[MAX_PLAYER_NAME],
- playerip[16];
- GetPlayerName(playerid, playername, sizeof(playername));
- GetPlayerIp(playerid, playerip, sizeof(playerip));
- WP_Hash(PlayerInfo[playerid][Password], 129, inputtext);
- mysql_format(mysql, query, sizeof(query), "INSERT INTO `accounts` (`Name`, `Password`, `IP`, `Admin`, `VIP`, `Money`, `PosX`, `PosY`, `PosZ`, `PosR`, `Gun1`, `Ammo1`, `Gun2`, `Ammo2`, `Gun3`, `Ammo3`, `Skin`) VALUES ('%e', '%e', '%e', 0, 0, 0, %f, %f, %f, %f, 0, 0, 0, 0, 0, 0, 0)", playername, PlayerInfo[playerid][Password], playerip, SPAWN_X, SPAWN_Y, SPAWN_Z, SPAWN_A);
- mysql_tquery(mysql, query, "OnAccountRegister", "i", playerid);
- }
- }
- return 1;
- }
- public OnPlayerClickPlayer(playerid, clickedplayerid, source)
- {
- return 1;
- }
- //========================== ACCOUNT CHECK =====================================
- public OnAccountCheck(playerid)
- {
- new
- rows,
- fields;
- cache_get_data(rows, fields, mysql);
- if(rows)
- {
- cache_get_value_index(0, 3, PlayerInfo[playerid][Password], mysql, 129);
- PlayerInfo[playerid][ID] = cache_get_value_index_int(0, "ID");
- ShowPlayerDialog(playerid, LoginDialog, DIALOG_STYLE_INPUT, "Login", "Welcome player!\nYour account has been found in our database. Please fill in your password:", "Login", "Quit");
- }
- else
- {
- ShowPlayerDialog(playerid, RegisterDialog, DIALOG_STYLE_INPUT, "Register", "Welcome player!\nYour account has not been registered yet. Please fill in your desired password:", "Register", "Quit");
- }
- return true;
- }
- forward OnAccountLoad(playerid);
- public OnAccountLoad(playerid)
- {
- cache_get_value_index_int(0, 5, PlayerInfo[playerid][Admin]);
- cache_get_value_index_int(0, 6, PlayerInfo[playerid][VIP]);
- cache_get_value_index_int(0, 7, PlayerInfo[playerid][Money]);
- cache_get_value_index_float(0, 8, PlayerInfo[playerid][posX]);
- cache_get_value_index_float(0, 9, PlayerInfo[playerid][posY]);
- cache_get_value_index_float(0, 10, PlayerInfo[playerid][posZ]);
- cache_get_value_index_float(0, 11, PlayerInfo[playerid][posR]);
- cache_get_value_index_int(0, 12, PlayerInfo[playerid][Gun1]);
- cache_get_value_index_int(0, 13, PlayerInfo[playerid][Ammo1]);
- cache_get_value_index_int(0, 14, PlayerInfo[playerid][Gun2]);
- cache_get_value_index_int(0, 15, PlayerInfo[playerid][Ammo2]);
- cache_get_value_index_int(0, 16, PlayerInfo[playerid][Gun3]);
- cache_get_value_index_int(0, 17, PlayerInfo[playerid][Ammo3]);
- cache_get_value_index_int(0, 18, PlayerInfo[playerid][Skin]);
- TogglePlayerSpectating(playerid, false);
- GivePlayerMoney(playerid, PlayerInfo[playerid][Money]);
- SetSpawnInfo(playerid, 0, PlayerInfo[playerid][Skin], PlayerInfo[playerid][posX], PlayerInfo[playerid][posY], PlayerInfo[playerid][posZ], PlayerInfo[playerid][posR], PlayerInfo[playerid][Gun1],PlayerInfo[playerid][Ammo1],PlayerInfo[playerid][Gun2],PlayerInfo[playerid][Ammo2],PlayerInfo[playerid][Gun3],PlayerInfo[playerid][Ammo3]);
- SpawnPlayer(playerid);
- SendClientMessage(playerid, -1, "You have successfully logged in.");
- return true;
- }
- forward OnAccountRegister(playerid);
- public OnAccountRegister(playerid)
- {
- PlayerInfo[playerid][ID] = cache_insert_id();
- printf("[Registration] New account registered. Database ID: [%d]", PlayerInfo[playerid][ID]);
- TogglePlayerSpectating(playerid, false);
- SetSpawnInfo(playerid, 0, 23, SPAWN_X, SPAWN_Y, SPAWN_Z, SPAWN_A, 0, 0, 0, 0, 0, 0);
- SpawnPlayer(playerid);
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement