Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //By UltraScripter////////////////////////////////////////////////////////
- //By UltraScripter////////////////////////////////////////////////////////
- #include <a_samp>
- #include <YSI\y_ini>
- #define REGISTER 1
- #define LOGIN 2
- new bool:Active;
- new Attempts[MAX_PLAYERS];
- new PlayerText:LOADSC;
- new PlayerText:CKTD[2];
- enum PlayerInfo
- {
- Pass,
- Float:x,
- Float:y,
- Float:z,
- Float:a,
- Cash,
- Score,
- Kills,
- Deaths
- }
- new pInfo[MAX_PLAYERS][PlayerInfo];
- forward PlayerData_Data(playerid, name[], value[]);
- public PlayerData_Data(playerid, name[], value[])
- {
- INI_Int("Password", pInfo[playerid][Pass]);
- INI_Float("X", pInfo[playerid][x]);
- INI_Float("Y", pInfo[playerid][y]);
- INI_Float("Z", pInfo[playerid][z]);
- INI_Float("A", pInfo[playerid][a]);
- INI_Int("Cash", pInfo[playerid][Cash]);
- INI_Int("Score", pInfo[playerid][Score]);
- INI_Int("Kills", pInfo[playerid][Kills]);
- INI_Int("Deaths", pInfo[playerid][Deaths]);
- return 1;
- }
- stock User(playerid)
- {
- new Str[128], pName[MAX_PLAYER_NAME];
- GetPlayerName(playerid, pName, sizeof(pName));
- format(Str, sizeof(Str), "Users/%s.ini", pName);
- return Str;
- }
- public OnGameModeInit()
- {
- // Don't use these lines if it's a filterscript
- SetGameModeText("Blank Script");
- AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
- 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;
- }
- ShowRegistrationMenu(playerid, id)
- {
- if(id == 1)
- {
- LOADSC = CreatePlayerTextDraw(playerid, 0.0, 0.0, "loadsc8:loadsc8");
- PlayerTextDrawFont(playerid, LOADSC, 4);
- PlayerTextDrawAlignment(playerid, LOADSC, 2);
- PlayerTextDrawUseBox(playerid, LOADSC, 1);
- PlayerTextDrawTextSize(playerid, LOADSC, 650.0, 470.0);
- PlayerTextDrawShow(playerid, LOADSC);
- CKTD[0] = CreatePlayerTextDraw(playerid, 150.0, 240.0, "REGISTER");
- PlayerTextDrawFont(playerid, CKTD[0], 3);
- PlayerTextDrawSetOutline(playerid, CKTD[0], 1);
- PlayerTextDrawAlignment(playerid, CKTD[0], 2);
- PlayerTextDrawLetterSize(playerid, CKTD[0], 1.2, 1.2);
- PlayerTextDrawTextSize(playerid, CKTD[0], 17.0, 17.0);
- PlayerTextDrawColor(playerid, CKTD[0], 0x00C600FF);
- PlayerTextDrawSetSelectable(playerid, CKTD[0], 1);
- PlayerTextDrawShow(playerid, CKTD[0]);
- CKTD[1] = CreatePlayerTextDraw(playerid, 500.0, 240.0, "LOGIN");
- PlayerTextDrawFont(playerid, CKTD[1], 3);
- PlayerTextDrawSetOutline(playerid, CKTD[1], 1);
- PlayerTextDrawAlignment(playerid, CKTD[1], 2);
- PlayerTextDrawLetterSize(playerid, CKTD[1], 1.2, 1.2);
- PlayerTextDrawTextSize(playerid, CKTD[1], 17.0, 17.0);
- PlayerTextDrawColor(playerid, CKTD[1], 0xF20000FF);
- PlayerTextDrawSetSelectable(playerid, CKTD[1], 1);
- PlayerTextDrawShow(playerid, CKTD[1]);
- }
- if(id == 2)
- {
- LOADSC = CreatePlayerTextDraw(playerid, 0.0, 0.0, "loadsc8:loadsc8");
- PlayerTextDrawFont(playerid, LOADSC, 4);
- PlayerTextDrawAlignment(playerid, LOADSC, 2);
- PlayerTextDrawUseBox(playerid, LOADSC, 1);
- PlayerTextDrawTextSize(playerid, LOADSC, 650.0, 470.0);
- PlayerTextDrawShow(playerid, LOADSC);
- CKTD[0] = CreatePlayerTextDraw(playerid, 150.0, 240.0, "REGISTER");
- PlayerTextDrawFont(playerid, CKTD[0], 3);
- PlayerTextDrawSetOutline(playerid, CKTD[0], 1);
- PlayerTextDrawAlignment(playerid, CKTD[0], 2);
- PlayerTextDrawLetterSize(playerid, CKTD[0], 1.2, 1.2);
- PlayerTextDrawTextSize(playerid, CKTD[0], 17.0, 17.0);
- PlayerTextDrawColor(playerid, CKTD[0], 0xF20000FF);
- PlayerTextDrawSetSelectable(playerid, CKTD[0], 1);
- PlayerTextDrawShow(playerid, CKTD[0]);
- CKTD[1] = CreatePlayerTextDraw(playerid, 500.0, 240.0, "LOGIN");
- PlayerTextDrawFont(playerid, CKTD[1], 3);
- PlayerTextDrawSetOutline(playerid, CKTD[1], 1);
- PlayerTextDrawAlignment(playerid, CKTD[1], 2);
- PlayerTextDrawLetterSize(playerid, CKTD[1], 1.2, 1.2);
- PlayerTextDrawTextSize(playerid, CKTD[1], 17.0, 17.0);
- PlayerTextDrawColor(playerid, CKTD[1], 0x00C600FF);
- PlayerTextDrawSetSelectable(playerid, CKTD[1], 1);
- PlayerTextDrawShow(playerid, CKTD[1]);
- }
- return 1;
- }
- DestroyRegistrationMenu(playerid)
- {
- PlayerTextDrawDestroy(playerid, LOADSC);
- PlayerTextDrawDestroy(playerid, CKTD[0]);
- PlayerTextDrawDestroy(playerid, CKTD[1]);
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- Attempts[playerid] = 0;
- if(!fexist(User(playerid)))
- {
- ShowRegistrationMenu(playerid, 1);
- SelectTextDraw(playerid, 0x9DEF89FF);
- Active = true;
- }
- else
- {
- ShowRegistrationMenu(playerid, 2);
- SelectTextDraw(playerid, 0x9DEF89FF);
- Active = true;
- }
- return 1;
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- if(fexist(User(playerid)))
- {
- new INI:File = INI_Open(User(playerid));
- new Float:px, Float:py, Float:pz, Float:pa;
- GetPlayerPos(playerid, px, py, pz);
- GetPlayerFacingAngle(playerid, pa);
- INI_WriteFloat(File, "X", px);
- INI_WriteFloat(File, "Y", py);
- INI_WriteFloat(File, "Z", pz);
- INI_WriteFloat(File, "A", pa);
- INI_WriteInt(File, "Cash", GetPlayerMoney(playerid));
- INI_WriteInt(File, "Score", GetPlayerScore(playerid));
- INI_WriteInt(File, "Kills", pInfo[playerid][Kills]);
- INI_WriteInt(File, "Deaths", pInfo[playerid][Deaths]);
- INI_Close(File);
- }
- return 1;
- }
- public OnPlayerSpawn(playerid)
- {
- return 1;
- }
- public OnPlayerDeath(playerid, killerid, reason)
- {
- pInfo[killerid][Kills] ++;
- pInfo[playerid][Deaths] ++;
- 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("/changepassword", cmdtext, true, 10) == 0)
- {
- if(fexist(User(playerid)))
- {
- ShowPlayerDialog(playerid, 7, DIALOG_STYLE_PASSWORD, "{00FF00}Change password", "{FFFFFF}First login to change password.", "Login", "Cancel");
- }
- 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[])
- {
- if(dialogid == REGISTER)
- {
- if(!strlen(inputtext)) return ShowPlayerDialog(playerid, REGISTER, DIALOG_STYLE_PASSWORD, "{FFFF00}Register", "{FF0000}You have to register.", "Register", "Quit");
- if(!response) return Kick(playerid);
- if(response)
- {
- new INI:File = INI_Open(User(playerid));
- INI_WriteInt(File, "Password", udb_hash(inputtext));
- INI_Close(File);
- PlayerPlaySound(playerid, 1057, 0.0, 0.0, 0.0);
- SendClientMessage(playerid, 0x00FF00FF, "You registered succesfully.");
- new String[256], Name[MAX_PLAYER_NAME], dd, mm, yy, h, m;
- GetPlayerName(playerid, Name, sizeof(Name));
- getdate(yy, mm, dd);
- gettime(h, m);
- format(String, sizeof(String), "{FFFFFF}Name: {FFFF00}%s\n{FFFFFF}Date: {FFFF00}%02d/%02d/%02d\n{FFFFFF}Time: {00FF00}%02d:%02d\n{FFFFFF}Password: {FFFF00}%s\n{00773C}Press f8 to screenshot your password.", Name, dd, mm, yy, h, m, inputtext);
- ShowPlayerDialog(playerid, 11, DIALOG_STYLE_MSGBOX, "{00FF00}Registration info", String, "Ok", "");
- DestroyRegistrationMenu(playerid);
- }
- }
- if(dialogid == LOGIN)
- {
- if(!response) return Kick(playerid);
- if(!strlen(inputtext)) return ShowPlayerDialog(playerid, LOGIN, DIALOG_STYLE_PASSWORD, "{FF0000}Login", "{FF0000}You have to login.", "Login", "Quit");
- if(response)
- {
- INI_ParseFile(User(playerid), "PlayerData_%s", .bExtra = true, .extra = playerid);
- if(udb_hash(inputtext) == pInfo[playerid][Pass])
- {
- SpawnPlayer(playerid);
- SetPlayerPos(playerid, pInfo[playerid][x], pInfo[playerid][y], pInfo[playerid][z]);
- SetPlayerFacingAngle(playerid, pInfo[playerid][a]);
- GivePlayerMoney(playerid, pInfo[playerid][Cash]);
- SetPlayerScore(playerid, pInfo[playerid][Score]);
- pInfo[playerid][Kills] = pInfo[playerid][Kills];
- pInfo[playerid][Deaths] = pInfo[playerid][Deaths];
- PlayerPlaySound(playerid, 1057, 0.0, 0.0, 0.0);
- SendClientMessage(playerid, 0x00FF00FF, "Logged in succesfully.");
- DestroyRegistrationMenu(playerid);
- }
- else
- {
- if(Attempts[playerid] <= 2)
- {
- PlayerPlaySound(playerid, 1058, 0.0, 0.0, 0.0);
- Attempts[playerid] ++;
- new String[128];
- format(String, sizeof(String), "{FF0000}Wrong password {FFFF00}%d/3 {FFFFFF}attempts, left try again.", Attempts[playerid]);
- ShowPlayerDialog(playerid, LOGIN, DIALOG_STYLE_PASSWORD, "{FF0000}Login", String, "Login", "Quit");
- }
- if(Attempts[playerid] == 3)
- {
- PlayerPlaySound(playerid, 1058, 0.0, 0.0, 0.0);
- ShowPlayerDialog(playerid, 12, DIALOG_STYLE_MSGBOX, "{FF0000}Login fail", "{FF0000}You have been kicked because you failed to login 3/3 attempts.", "Ok", "");
- SetTimerEx("KickForBadLogin", 500, false, "i", playerid);
- DestroyRegistrationMenu(playerid);
- }
- }
- }
- }
- if(dialogid == 7)
- {
- if(!response) return SendClientMessage(playerid, 0xFF0000FF, "You canceled login before password change.");
- if(!strlen(inputtext)) return ShowPlayerDialog(playerid, 7, DIALOG_STYLE_PASSWORD, "{00FF00}Change password", "{FFFFFF}First login to change password.", "Login", "Cancel");
- if(response)
- {
- INI_ParseFile(User(playerid), "PlayerData_%s", .bExtra = true, .extra = playerid);
- if(udb_hash(inputtext) == pInfo[playerid][Pass])
- {
- PlayerPlaySound(playerid, 1057, 0.0, 0.0, 0.0);
- SendClientMessage(playerid, 0x00FF00FF, "Password correct you can change your password now.");
- ShowPlayerDialog(playerid, 8, DIALOG_STYLE_PASSWORD, "{00FF00}Change password", "{00FF00}Change your password to whatever you want.", "Done", "Cancel");
- }
- else
- {
- PlayerPlaySound(playerid, 1057, 0.0, 0.0, 0.0);
- SendClientMessage(playerid, 0xFF0000FF, "Wrong password.");
- }
- }
- }
- if(dialogid == 8)
- {
- if(!response) return SendClientMessage(playerid, 0xFF0000FF, "You canceled password change.");
- if(!strlen(inputtext)) return ShowPlayerDialog(playerid, 8, DIALOG_STYLE_PASSWORD, "{00FF00}Change password", "{00FF00}Change your password to whatever you want.", "Done", "Cancel");
- if(response)
- {
- new INI:File = INI_Open(User(playerid));
- INI_WriteInt(File, "Password", udb_hash(inputtext));
- INI_Close(File);
- PlayerPlaySound(playerid, 1057, 0.0, 0.0, 0.0);
- SendClientMessage(playerid, 0x00FF00FF, "Password changed succesfully.");
- new String[128];
- format(String, sizeof(String), "{FFFFFF}Password: {00FF00}%s\n{00773C}Press f8 to screenshot your new password.", inputtext);
- ShowPlayerDialog(playerid, 17, DIALOG_STYLE_MSGBOX, "{00FF00}New password info", String, "Ok", "");
- }
- }
- return 1;
- }
- forward KickForBadLogin(playerid);
- public KickForBadLogin(playerid)
- {
- Kick(playerid);
- return 1;
- }
- public OnPlayerClickPlayer(playerid, clickedplayerid, source)
- {
- return 1;
- }
- public OnPlayerClickTextDraw(playerid, Text:clickedid)
- {
- if(clickedid == Text:INVALID_TEXT_DRAW)
- {
- if(Active == false) return 0;
- if(Active == true)
- {
- DestroyRegistrationMenu(playerid);
- CancelSelectTextDraw(playerid);
- ShowPlayerDialog(playerid, 10, DIALOG_STYLE_MSGBOX, "{FF0000}Kicked", "{FFFFFF}You have been {FF0000}kicked {FFFFFF}for not logging or registering you can join later to register or login.", "Ok", "");
- SetTimerEx("KickForEsc", 500, false, "i", playerid);
- }
- }
- return 1;
- }
- public OnPlayerClickPlayerTextDraw(playerid, PlayerText:playertextid)
- {
- if(playertextid != PlayerText:INVALID_TEXT_DRAW)
- {
- if(playertextid == CKTD[0])
- {
- if(fexist(User(playerid)))
- {
- PlayerPlaySound(playerid, 1058, 0.0, 0.0, 0.0);
- SendClientMessage(playerid, 0xFF0000FF, "You allready registered.");
- }
- else
- {
- PlayerPlaySound(playerid, 1057, 0.0, 0.0, 0.0);
- new String[256], Name[MAX_PLAYER_NAME], dd, mm, yy, h, m;
- GetPlayerName(playerid, Name, sizeof(Name));
- getdate(yy, mm, dd);
- gettime(h, m);
- format(String, sizeof(String), "{FFFFFF}Name: {FFFF00}%s\n{FFFFFF}Date: {FFFF00}%02d/%02d/%02d\n{FFFFFF}Time: {00FF00}%02d:%02d", Name, dd, mm, yy, h, m);
- CancelSelectTextDraw(playerid);
- Active = false;
- ShowPlayerDialog(playerid, REGISTER, DIALOG_STYLE_PASSWORD, "{FFFF00}Register", String, "Register", "Quit");
- }
- }
- if(playertextid == CKTD[1])
- {
- if(!fexist(User(playerid)))
- {
- PlayerPlaySound(playerid, 1058, 0.0, 0.0, 0.0);
- SendClientMessage(playerid, 0xFF0000FF, "You are not registered to this server.");
- }
- else
- {
- PlayerPlaySound(playerid, 1057, 0.0, 0.0, 0.0);
- CancelSelectTextDraw(playerid);
- Active = false;
- new Name[MAX_PLAYER_NAME], String[256];
- GetPlayerName(playerid, Name, sizeof(Name));
- format(String, sizeof(String), "{FFFFFF}Welcome Back {00FF00}%s {FFFFFF}please login.", Name);
- ShowPlayerDialog(playerid, LOGIN, DIALOG_STYLE_PASSWORD, "{FFFF00}Login", String, "Login", "Quit");
- }
- }
- }
- return 1;
- }
- forward KickForEsc(playerid);
- public KickForEsc(playerid)
- {
- Kick(playerid);
- return 1;
- }
- //credits to DracoBlue for his hasher
- stock udb_hash(buf[]) {
- new length=strlen(buf);
- new s1 = 1;
- new s2 = 0;
- new n;
- for (n=0; n<length; n++)
- {
- s1 = (s1 + buf[n]) % 65521;
- s2 = (s2 + s1) % 65521;
- }
- return (s2 << 16) + s1;
- }
- //By UltraScripter////////////////////////////////////////////////////////
- //By UltraScripter////////////////////////////////////////////////////////
Add Comment
Please, Sign In to add comment