Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* SZRegistration System v1.0
- Created by StageZero, contact me: [email protected]
- */
- #include <a_samp>
- #include <YSI\y_ini>
- #define DIALOG_REG 1
- #define DIALOG_LOGIN 2
- //COLORS
- #define COLOR_RED 0xFF0000FF
- #define COLOR_GREEN 0x33AA33AA
- #define COLOR_WHITE 0xFFFFFFAA
- #define COLOR_ORANGE 0xFF8000FF
- #define MAX_FAILED_LOGIN 3 // Maximum number of login failures
- #pragma tabsize 0
- enum stat_info {admin_level, score, money, failed_login, bool: logged}; // Players statistics
- new player_stat[MAX_PLAYERS][stat_info];
- new pstring[500], p_password[20], bool: banned; //Array & check banned at login
- new INI: opened_file; // Variable that identifies the open file
- public OnFilterScriptInit()
- {
- print("\n--------------------------------------");
- print(" SZRegistration System v1.0");
- print("--------------------------------------\n");
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- new name[24];
- GetPlayerName(playerid, name, 24);
- format(pstring,sizeof(pstring), "/Accounts/%s.ini", name);
- if(!fexist(pstring))
- {
- format(pstring, 500, "{C1C1C1}Welcome {B0EC1B}%s{C1C1C1} to the server!\n\n Your account is not registered.\nEnter a password to register a new account:", name);
- ShowPlayerDialog(playerid, DIALOG_REG, DIALOG_STYLE_INPUT, "Registering...", pstring, "Register", "");
- return 1;
- }
- else
- {
- format(pstring, 500, "{C1C1C1}Welcome {B0EC1B}%s{C1C1C1} to the server!\n\n Your account is registered.\nEnter the password to login:", name);
- ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login...", pstring, "Login!", "");
- return 1;
- }
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- new name[24];
- GetPlayerName(playerid, name, sizeof(name));
- switch(reason)
- {
- case 0: format(pstring, 500, "{B0EC1B}%s {C1C1C1}has left the server {A1A1A1}[crash].", name);
- case 1: format(pstring, 500, "{B0EC1B}%s {C1C1C1}has left the server.", name);
- case 2: format(pstring, 500, "{B0EC1B}%s {C1C1C1}has left the server {A1A1A1}[kick/ban].", name);
- }
- SendClientMessageToAll(-1, pstring);
- if(player_stat[playerid][logged])
- {
- format(pstring, sizeof(pstring), "Accounts/%s.ini", name);
- opened_file = INI_Open(pstring);
- new pyear, pmonth, pday, phour, pminute, psecond;
- getdate(pyear,pmonth,pday),gettime(phour,pminute,psecond);
- format(pstring, 500, "%d/%d/%04d - %02d:%02d:%02d", pday, pmonth, pyear, phour, pminute, psecond);
- new ip[20];
- GetPlayerIp(playerid, ip, 20);
- INI_WriteString(opened_file, "Last_Login", pstring);
- INI_WriteString(opened_file, "Last_IP", ip);
- INI_WriteInt(opened_file, "Admin_Level", player_stat[playerid][admin_level]);
- INI_WriteInt(opened_file, "Score", player_stat[playerid][score]);
- INI_WriteInt(opened_file, "Money", player_stat[playerid][money]);
- INI_Close(opened_file);
- }
- 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 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[])
- {
- new name[24];
- GetPlayerName(playerid, name, 24);
- switch(dialogid)
- {
- case DIALOG_REG:
- {
- if(!response)
- {
- PlayerPlaySound(playerid, 1055, 0, 0 ,0); //Errors Sounds
- SendClientMessage(playerid, COLOR_RED, "[SERVER:] {C1C1C1}You must register to play. You have been kicked from the server.");
- Kick(playerid);
- return 1;
- }
- if(!strlen(inputtext))
- {
- PlayerPlaySound(playerid, 1055, 0, 0 ,0);
- format(pstring, 500, "{F1781B}-Enter a valid password-\n{C1C1C1}Welcome {B0EC1B}%s{C1C1C1} to the server!\n\n Your account is not registered.\nEnter a password to register a new account:", name);
- ShowPlayerDialog(playerid, DIALOG_REG, DIALOG_STYLE_INPUT, "Registering...", pstring, "Register", "");
- return 1;
- }
- if(strlen(inputtext) > 20)
- {
- PlayerPlaySound(playerid, 1055, 0, 0 ,0);
- format(pstring, 500, "{F1781B}-Maximum 20 characters for the password-\n{C1C1C1}Welcome {B0EC1B}%s{C1C1C1} to the server!\n\n Your account is not registered.\nEnter a password to register a new account:", name);
- ShowPlayerDialog(playerid, DIALOG_REG, DIALOG_STYLE_INPUT, "Registering...", pstring, "Register", "");
- return 1;
- }
- PlayerPlaySound(playerid, 1055, 0, 0 ,0);
- GetPlayerName(playerid, name, 24);
- format(pstring,sizeof(pstring),"/Accounts/%s.ini",name);
- opened_file = INI_Open(pstring);
- new pyear, pmonth, pday, phour, pminute, psecond;
- getdate(pyear,pmonth,pday),gettime(phour,pminute,psecond);
- format(pstring, 500, "%d/%d/%04d - %02d:%02d:%02d", pday, pmonth, pyear, phour, pminute, psecond);
- new ip[20];
- GetPlayerIp(playerid, ip, 20);
- INI_WriteString(opened_file, "Password", inputtext);
- INI_WriteString(opened_file, "Date_Registration", pstring);
- INI_WriteString(opened_file, "Last_Login", pstring);
- INI_WriteString(opened_file, "IP_Registration", ip);
- INI_WriteString(opened_file, "Last_IP", ip);
- INI_WriteInt(opened_file, "Admin_Level", 0);
- INI_WriteInt(opened_file, "Score", 0);
- INI_WriteInt(opened_file, "Money", 0);
- INI_WriteBool(opened_file, "Banned", false);
- INI_Close(opened_file);
- format(pstring, 500, "{C1C1C1}Welcome {B0EC1B}%s{C1C1C1} to the server!\n\n Congratulations, you've successfully registered.\nEnter the password to login:", name);
- ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login...", pstring, "Login!", "");
- return 1;
- }
- case DIALOG_LOGIN:
- {
- if(!response)
- {
- PlayerPlaySound(playerid, 1055, 0, 0 ,0);
- SendClientMessage(playerid, COLOR_RED, "[SERVER:] {C1C1C1}You need to log to play. You have been kicked from the server.");
- Kick(playerid);
- return 1;
- }
- if(!strlen(inputtext))
- {
- PlayerPlaySound(playerid, 1055, 0, 0 ,0);
- format(pstring, 500, "{F1781B}-Enter a password to login-\n{C1C1C1}Welcome {B0EC1B}%s{C1C1C1} to the server!\n\n Congratulations, you've successfully registered.\nEnter the password to login:", name);
- ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login...", pstring, "Login", "");
- return 1;
- }
- if(strlen(inputtext) > 20)
- {
- PlayerPlaySound(playerid, 1055, 0, 0 ,0);
- format(pstring, 500, "{F1781B}-Maximum 20 characters for the password-\n{C1C1C1}Welcome {B0EC1B}%s{C1C1C1} to the server!\n\n Congratulations, you've successfully registered.\nEnter the password to login:", name);
- ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login...", pstring, "Login", "");
- return 1;
- }
- format(pstring,sizeof(pstring),"/Accounts/%s.ini",name);
- INI_ParseFile(pstring, "Parse_Player_Pass", .bExtra = true, .extra = playerid);
- if(strcmp(inputtext, p_password, true))
- {
- player_stat[playerid][failed_login]++;
- PlayerPlaySound(playerid, 1055, 0, 0 ,0);
- if(player_stat[playerid][failed_login] == MAX_FAILED_LOGIN)
- {
- SendClientMessage(playerid, COLOR_RED, "[SERVER:] {C1C1C1}Have exceeded the maximum number of login attempts. You have been kicked from the server.");
- Kick(playerid);
- return 1;
- }
- format(pstring, 500, "{F1781B}-Attempting login %d/%d. To %d attempts you will be kicked-\n{C1C1C1}Welcome {B0EC1B}%s{C1C1C1} to the server!\n\n Congratulations, you've successfully registered.\nEnter the password to login:", player_stat[playerid][failed_login], MAX_FAILED_LOGIN, MAX_FAILED_LOGIN, name);
- ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login...", pstring, "Login", "");
- return 1;
- }
- else
- {
- format(pstring,sizeof(pstring),"/Accounts/%s.ini",name);
- INI_ParseFile(pstring,"Load_Player_Data", .bExtra = true, .extra = playerid);
- if(banned)
- {
- banned = false;
- SendClientMessage(playerid, COLOR_RED, "This account is banned from the server.");
- Kick(playerid);
- return 2;
- }
- player_stat[playerid][logged] = true;
- return 1;
- }
- }
- }
- return 1;
- }
- forward Parse_Player_Pass(playerid, name[], value[]);
- public Parse_Player_Pass(playerid, name[], value[])
- {
- INI_String("Password", p_password, 20);
- return 1;
- }
- forward Load_Player_Data(playerid, name[], value[]);
- public Load_Player_Data(playerid, name[], value[])
- {
- INI_Int("Admin_Level", player_stat[playerid][admin_level]);
- INI_Int("Score", player_stat[playerid][score]);
- INI_Int("Money", player_stat[playerid][money]);
- INI_Bool("Banned", banned);
- return 1;
- }
- public OnPlayerClickPlayer(playerid, clickedplayerid, source)
- {
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement