Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Includes & Plugins:
- I-ZCMD 0.2.3.0: http://forum.sa-mp.com/showthread.php?t=576114
- MySQL R39-6: http://forum.sa-mp.com/showthread.php?t=56564 | https://github.com/pBlueG/SA-MP-MySQL/releases/tag/R39-6
- Streamer 2.9.0: http://forum.sa-mp.com/showthread.php?t=102865
- Foreach: http://forum.sa-mp.com/showthread.php?t=570868
- sscanf 2.8.2: http://forum.sa-mp.com/showthread.php?t=570927
- All work completed in this script was with the help of iGetty:
- http://forum.sa-mp.com/member.php?u=105293
- https://www.youtube.com/channel/UCBWCX6AxNL7-O3xuvSKaG-A
- This is the work of XXXXXXXXX, for the roleplay script.
- */
- #include <a_samp>
- #include <zcmd>
- #include <a_mysql>
- #include <streamer>
- #include <foreach>
- #include <sscanf2>
- #define Server:%0(%1) forward %0(%1); public %0(%1)
- #define SQL_HOST = "localhost"
- #define SQL_USER = "root"
- #define SQL_DB = "rp"
- #define SQL_PASSWORD = ""
- #define COLOR_WHITE 0xFFFFFF00
- #define DIALOG_UNUSED 0
- #define DIALOG_REGISTER 1
- #define DIALOG_LOGIN 2
- enum PLAYER_DATA
- {
- pSQLID,
- pAdminLevel
- }
- // Global Variables
- new sqlConnection;
- // Player Variables
- new bool:LoggedIn[MAX_PLAYERS], PlayerData[MAX_PLAYERS][PLAYER_DATA];
- main(){}
- public OnGameModeInit()
- {
- mysql_log(LOG_ERROR | LOG_WARNING, LOG_TYPE_HTML);
- sqlConnection = mysql_connect("localhost", "root", "", "rp");
- return true;
- }
- public OnGameModeExit()
- {
- mysql_close(sqlConnection);
- return true
- ;
- }
- public OnPlayerConnect(playerid)
- {
- DefaultPlayerValues(playerid);
- DoesPlayerExist(playerid);
- return true;
- }
- Server:DoesPlayerExist(playerid)
- {
- new query[128];
- mysql_format(sqlConnection, query, sizeof(query), "SELECT id FROM players WHERE Name = '%e' LIMIT 1", GetName(playerid));
- mysql_pquery(sqlConnection, query, "SQL_DoesPlayerExist", "i", playerid);
- return true;
- }
- Server:SQL_DoesPlayerExist(playerid)
- {
- if(cache_num_rows(sqlConnection) != 0) // Exists
- {
- ShowLoginDialog(playerid, "");
- }
- else // Doesn't Exist
- {
- ShowRegisterDialog(playerid, "");
- }
- return true;
- }
- Server:ShowLoginDialog(playerid, error[])
- {
- if(LoggedIn[playerid])return true;
- if(!strmatch(error, "")){
- SendClientMessage(playerid, COLOR_WHITE, error);
- }
- ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Scratch RP - Login", "Please enter your password to begin playing.", "Login", "Quit");
- return true;
- }
- Server:ShowRegisterDialog(playerid, error[])
- {
- if(LoggedIn[playerid])return true;
- if(!strmatch(error, "")){
- SendClientMessage(playerid, COLOR_WHITE, error);
- }
- ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Scratch RP - Register", "Please enter your desired password below to begin playing", "Register", "Quit");
- return true;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- switch(dialogid)
- {
- case DIALOG_REGISTER:
- {
- if(!response)return Kick(playerid);
- if(strlen(inputtext) < 3 || strlen(inputtext) > 30){
- ShowRegisterDialog(playerid, "Password length must be above 3 characters AND below 30 characters long.");
- return true;
- }
- new query[128];
- mysql_format(sqlConnection, query, sizeof(query), "INSERT INTO players (Name, Password, RegIP) VALUES('%e', sha1('%e%'), '%e')", GetName(playerid), inputtext, GetIP(playerid));
- mysql_pquery(sqlConnection, query, "SQL_OnAccountRegister", "i", playerid);
- }
- case DIALOG_LOGIN:
- {
- if(!response)return Kick(playerid);
- if(strlen(inputtext) < 3 || strlen(inputtext) > 30) {
- ShowLoginDialog(playerid, "Password length must be above 3 characters AND below 30 characters long.");
- return true;
- }
- new query[128];
- mysql_format(sqlConnection, query, sizeof(query), "SELECT id FROM players WHERE Name = '%e' AND Password = sha1('%e') LIMIT 1", GetName(playerid), inputtext);
- mysql_pquery(sqlConnection, query, "SQL_OnAccountLogin", "i", playerid);
- }
- }
- return false;
- }
- Server:SQL_OnAccountLogin(playerid)
- {
- if(cache_num_rows() == 0) {
- ShowLoginDialog(playerid, "Incorrect password.");
- return true;
- }
- PlayerData[playerid][pSQLID] = cache_get_field_content_int(0, "id", sqlConnection);
- PlayerData[playerid][pAdminLevel] = cache_get_field_content_int(9, "AdminLevel", sqlConnection);
- new string[128];
- format(string, sizeof(string), "SQLID: %d | Admin: %d, PlayerData[playerid][pSQLID], PlayerData[playerid][pAdminLevel]");
- SendClientMessage(playerid, COLOR_WHITE, string);
- return true;
- }
- Server:SQL_OnAccountRegister(playerid)
- {
- SendClientMessage(playerid, COLOR_WHITE, "You have successfully registered onto the server.");
- DefaultPlayerValues(playerid);
- PlayerData[playerid][pSQLID] = cache_insert_id();
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- DefaultPlayerValues(playerid);
- return true;
- }
- public OnPlayerDeath(playerid, killerid, reason)
- {
- return true;
- }
- public OnPlayerUpdate(playerid)
- {
- return true;
- }
- Server:DefaultPlayerValues(playerid)
- {
- PlayerData[playerid][pSQLID] = 0;
- PlayerData[playerid][pAdminLevel] = 0;
- return true;
- }
- // Stocks & Other Functions
- GetIP(playerid)
- {
- new ip[20];
- GetPlayerIp(playerid, ip, sizeof(ip));
- return 1;
- }
- GetName(playerid)
- {
- new name[MAX_PLAYER_NAME];
- GetPlayerName(playerid, name, sizeof(name));
- return name;
- }
- stock strmatch(const String1[], const String2[])
- {
- if ((strcmp(String1, String2, true, strlen(String2)) == 0) && (strlen(String2) == strlen(String1)))
- {
- return true;
- }
- else
- {
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement