Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //---------------------------------------------------------------------------------------------//
- // -----------------------------[ MafiaGuy's Simple Registration ]-----------------------------//
- // You are free to edit, copy/paste without credits but it would be nice to leave some //
- // The system saves: Password,Level,Money,Skin,Admin and IP //
- //---------------------------------------------------------------------------------------------//
- #include <a_samp>
- #include <dini>
- //#define DINI
- #define COLOR_GREEN 0x33AA33AA
- #define COLOR_RED 0xAA3333AA
- #define COLOR_YELLOW 0xFFFF00AA
- #define COLOR_WHITE 0xFFFFFFAA
- #define SERVERNAME "SAMP RP"
- #define DINI_REGISTER 1
- #define DINI_LOGIN 2
- #define NORMAL_REGISTER 3
- #define NORMAL_LOGIN 4
- forward Encrypt(string[]);
- forward SaveAccounts();
- forward ini_GetKey( line[] );
- forward ini_GetValue( line[] );
- new pLogged[MAX_PLAYERS];
- enum pInfo
- {
- pPassword[64],
- pIP[32],
- pRegistered,
- pAdmin,
- pLevel,
- pMoney,
- pSkin,
- };
- new PlayerInfo[MAX_PLAYERS][pInfo];
- public OnFilterScriptInit()
- {
- print("\n--------------------------------------");
- print(" MafiaGuy's Simple Registration Loaded !!");
- print("--------------------------------------\n");
- SetTimer("SaveAccounts",1,1800000); // 30 mins
- return 1;
- }
- public OnFilterScriptExit()
- {
- return 1;
- }
- stock PlayerName(playerid)
- {
- new name[24];
- GetPlayerName(playerid, name, 24);
- return name;
- }
- stock SetPlayerMoney(playerid, money)
- {
- ResetPlayerMoney(playerid);
- GivePlayerMoney(playerid, money);
- return 1;
- }
- stock ShowRegistration(playerid)
- {
- new file[128];
- format(file, sizeof(file), "%s.ini", PlayerName(playerid));
- #if defined DINI
- if(dini_Exists(file))
- {
- ShowPlayerDialog(playerid, DINI_LOGIN, DIALOG_STYLE_INPUT, "Dini Login Procces","Please enter your password to procced","Login","Quit");
- return 1;
- }
- else if(!dini_Exists(file))
- {
- ShowPlayerDialog(playerid, DINI_REGISTER, DIALOG_STYLE_INPUT, "Dini Register Procces","Please enter your password to procced","Register","Quit");
- }
- #else
- if(fexist(file))
- {
- ShowPlayerDialog(playerid, NORMAL_LOGIN, DIALOG_STYLE_INPUT, "Normal Login Procces","Please enter your password to procced","Login","Quit");
- }
- else if(!fexist(file))
- {
- ShowPlayerDialog(playerid, NORMAL_REGISTER, DIALOG_STYLE_INPUT, "Normal Register Procces","Please enter your password to procced","Register","Quit");
- }
- #endif
- return 1;
- }
- 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;
- }
- public OnPlayerRequestClass(playerid, classid)
- {
- if(pLogged[playerid] == 1)
- {
- SpawnPlayer(playerid);
- }
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- new string[128];
- format(string,sizeof(string),"* Hello %s. Welcome on %s.",PlayerName(playerid),SERVERNAME);
- SendClientMessage(playerid, COLOR_YELLOW, string);
- ShowRegistration(playerid);
- return 1;
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- SendClientMessage(playerid, COLOR_WHITE, "See ya. Come again soon.");
- return 1;
- }
- public OnPlayerSpawn(playerid)
- {
- SetPlayerSkin(playerid,PlayerInfo[playerid][pSkin]);
- SetPlayerScore(playerid,PlayerInfo[playerid][pLevel]);
- SetPlayerMoney(playerid,PlayerInfo[playerid][pMoney]);
- // Now if you want to make the player spawn on certain location use SetPlayerPos, or do it thought a public function //
- 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[])
- {
- new string[128],cmd[256],idx,tmp[128],player;
- cmd = strtok(cmd,idx);
- if (strcmp(cmd, "/kick", true) == 0)
- {
- if(PlayerInfo[playerid][pAdmin] > 0 || IsPlayerAdmin(playerid))
- {
- tmp = strtok(cmdtext, idx);
- if(!strlen(tmp))
- {
- SendClientMessage(playerid, COLOR_WHITE, "/kick [ID]");
- }
- player = strval(tmp);
- format(string,sizeof(string),"Admin %s has kicked %s from the server.",PlayerName(playerid),PlayerName(player));
- SendClientMessageToAll(COLOR_RED,string);
- Kick(player);
- }
- else
- {
- SendClientMessage(playerid,COLOR_RED,"You are not allowed to use that command.");
- }
- 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)
- {
- new file[64];
- format(file, sizeof(file), "%s.ini", PlayerName(playerid)); // Player Folder
- #if defined DINI
- dini_IntSet(file,"Registered",PlayerInfo[playerid][pRegistered]);
- dini_IntSet(file,"Admin",PlayerInfo[playerid][pAdmin]);
- dini_IntSet(file,"Level",GetPlayerScore(playerid));
- dini_IntSet(file,"Skin",GetPlayerSkin(playerid));
- dini_IntSet(file,"Money", GetPlayerMoney(playerid));
- // dini_Set(file,"Name", PlayerName(playerid)); // This is a example of setting a string. But be sure to put pName[MAX_PLAYER_NAME], at the player enum at top.
- #else
- new File: hFile = fopen(file, io_write);
- if (hFile)
- {
- new key[32];
- format(key, 32, "Password=%s\n", PlayerInfo[playerid][pPassword]);fwrite(hFile, key);
- format(key, 32, "Registered=%d\n",PlayerInfo[playerid][pRegistered]);fwrite(hFile, key);
- format(key, 32, "Admin=%d\n",PlayerInfo[playerid][pAdmin]);fwrite(hFile, key);
- format(key, 32, "Level=%d\n",GetPlayerScore(playerid));fwrite(hFile, key);
- format(key, 32, "Skin=%d\n",GetPlayerSkin(playerid));fwrite(hFile, key);
- format(key, 32, "Money=%d\n",GetPlayerMoney(playerid));fwrite(hFile, key);
- fclose(hFile);
- }
- #endif
- return 1;
- }
- public SaveAccounts()
- {
- for(new i = 0; i < MAX_PLAYERS; i++)
- {
- new file[64];
- format(file, sizeof(file), "%s.ini", PlayerName(i));
- #if defined DINI
- dini_IntSet(file,"Admin",PlayerInfo[i][pAdmin]);
- dini_IntSet(file,"Level",GetPlayerScore(i));
- dini_IntSet(file,"Skin",GetPlayerSkin(i));
- dini_IntSet(file,"Money", GetPlayerMoney(i));
- #else
- new File: hFile = fopen(file, io_write);
- if (hFile)
- {
- new key[32];
- format(key, 32, "Password=%s\n", PlayerInfo[i][pPassword]);fwrite(hFile, key);
- format(key, 32, "Registered=%d\n",PlayerInfo[i][pRegistered]);fwrite(hFile, key);
- format(key, 32, "Admin=%d\n",PlayerInfo[i][pAdmin]);fwrite(hFile, key);
- format(key, 32, "Level=%d\n",GetPlayerScore(i));fwrite(hFile, key);
- format(key, 32, "Skin=%d\n",GetPlayerSkin(i));fwrite(hFile, key);
- format(key, 32, "Money=%d\n",GetPlayerMoney(i));fwrite(hFile, key);
- fclose(hFile);
- }
- #endif
- }
- }
- 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 string[128];
- new file[64];
- new ip[15];
- GetPlayerIp(playerid,ip,sizeof(ip));
- format(file, sizeof(file), "%s.ini", PlayerName(playerid)); // Player Folder
- if(response)
- {
- switch(dialogid)
- {
- #if defined DINI
- case DINI_REGISTER:
- {
- dini_Create(file); // The password is hashed. If you dont want the hash just remove teh udb_hash() //
- dini_IntSet(file, "Password", udb_hash(inputtext));
- dini_Set(file,"IP",ip);
- dini_IntSet(file,"Registered",1);
- dini_IntSet(file,"Admin",0);
- dini_IntSet(file,"Level",1); // You can always changed these values
- dini_IntSet(file,"Skin",7); // Set the default skin.
- dini_IntSet(file,"Money",5000); // Money that the receives at start
- format(string,sizeof(string),"Your account has been successfully made with password: %s (Auto Logged-in)",inputtext);
- SendClientMessage(playerid,COLOR_YELLOW,string);
- PlayerPlaySound(playerid,1057,0.0,0.0,0.0);
- pLogged[playerid] = 1;
- SpawnPlayer(playerid);
- return 1;
- }
- case DINI_LOGIN:
- {
- new pw[64];
- format(pw, 24, dini_Get(file, "Password"));
- if(udb_hash(inputtext) == strval(pw))
- {
- PlayerInfo[playerid][pRegistered] = dini_Int(file,"Registered");
- PlayerInfo[playerid][pAdmin] = dini_Int(file,"Admin"); // dini_Int is used to load normal things with numbers.
- // format(PlayerInfo[playerid][pName],24,"%s",PlayerName(playerid)); This way you can set some string to variable. This wasnt the best example but it is good.
- SetPlayerScore(playerid, dini_Int(file, "Level"));
- SetPlayerSkin(playerid, dini_Int(file, "Skin"));
- GivePlayerMoney(playerid, dini_Int(file, "Money"));
- format(string,sizeof(string),"You have logged into your account successfully.",inputtext);
- SendClientMessage(playerid,COLOR_YELLOW,string);
- PlayerPlaySound(playerid,1057,0.0,0.0,0.0);
- pLogged[playerid] = 1;
- SpawnPlayer(playerid);
- }
- else
- {
- SendClientMessage(playerid, COLOR_RED, "Wrong password.");
- ShowPlayerDialog(playerid, DINI_LOGIN, DIALOG_STYLE_INPUT, "DINI Login Procces","Please re-enter your password to procced.","Login","Quit");
- }
- return 1;
- }
- #else
- case NORMAL_REGISTER:
- {
- format(string,sizeof(string),"Your account has been successfully made with password: %s",inputtext);
- SendClientMessage(playerid,COLOR_YELLOW,string);
- Encrypt(inputtext);
- new File: hFile = fopen(file, io_write);
- if (hFile)
- {
- new key[32];
- format(key, 32, "Password=%s\n", inputtext);fwrite(hFile, key);
- format(key, 32, "Registered=%d\n",PlayerInfo[playerid][pRegistered]);fwrite(hFile, key);
- format(key, 32, "Admin=%d\n",PlayerInfo[playerid][pAdmin]);fwrite(hFile, key);
- format(key, 32, "Level=%d\n",GetPlayerScore(playerid));fwrite(hFile, key);
- format(key, 32, "Skin=%d\n",GetPlayerSkin(playerid));fwrite(hFile, key);
- format(key, 32, "Money=%d\n",GetPlayerMoney(playerid));fwrite(hFile, key);
- fclose(hFile);
- }
- format(string,sizeof(string),"Your account has been successfully made with password: %s (Auto Logged-in)",inputtext);
- SendClientMessage(playerid,COLOR_YELLOW,string);
- pLogged[playerid] = 1;
- SpawnPlayer(playerid);
- }
- case NORMAL_LOGIN:
- {
- new File:hFile = fopen(file, io_read);
- if(hFile)
- {
- new PassData[128];
- new keytmp[256], valtmp[256];
- fread(hFile, PassData, sizeof(PassData));
- keytmp = ini_GetKey(PassData);
- if(strcmp(keytmp ,"Password", true) == 0)
- {
- valtmp = ini_GetValue( PassData );
- strmid(PlayerInfo[playerid][pPassword], valtmp, 0, strlen(valtmp)-1, 255);
- }
- if(strcmp(PlayerInfo[playerid][pPassword],inputtext, true ) == 0 )
- {
- new key[256], val[256];
- new Data[256];
- while(fread(hFile, Data, sizeof(Data)))
- {
- key = ini_GetKey( Data );
- if( strcmp( key , "Registered" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pRegistered] = strval( val ); }
- if( strcmp( key , "Admin" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pAdmin] = strval( val ); }
- if( strcmp( key , "Level" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pLevel] = strval( val ); }
- if( strcmp( key , "Skin" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pSkin] = strval( val ); }
- if( strcmp( key , "Money" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pMoney] = strval( val ); }
- // if( strcmp( key , "StringExample" , true ) == 0 ) { val = ini_GetValue( Data ); strmid(PlayerInfo[playerid][pStringExample], val, 0, strlen(val)-1, 255); }
- }
- fclose(hFile);
- pLogged[playerid] = 1;
- SendClientMessage(playerid,COLOR_YELLOW,"You have logged into your account successfully.");
- SpawnPlayer(playerid);
- }
- else
- {
- SendClientMessage(playerid, COLOR_WHITE, "SERVER: Password does not match your name.");
- fclose(hFile);
- return 1;
- }
- if(PlayerInfo[playerid][pRegistered] == 0)
- {
- GivePlayerMoney(playerid, 5000);
- SetPlayerScore(playerid, 1);
- PlayerInfo[playerid][pSkin] = 7;
- PlayerInfo[playerid][pRegistered] = 1;
- }
- }
- }
- #endif
- }
- }
- return 1;
- }
- public OnPlayerClickPlayer(playerid, clickedplayerid, source)
- {
- return 1;
- }
- public Encrypt(string[])
- {
- for(new x=0; x < strlen(string); x++)
- {
- string[x] += (3^x) * (x % 15);
- if(string[x] > (0xff))
- {
- string[x] -= 256;
- }
- }
- return 1;
- }
- stock ini_GetKey( line[] )
- {
- new keyRes[256];
- keyRes[0] = 0;
- if ( strfind( line , "=" , true ) == -1 ) return keyRes;
- strmid( keyRes , line , 0 , strfind( line , "=" , true ) , sizeof( keyRes) );
- return keyRes;
- }
- stock ini_GetValue( line[] )
- {
- new valRes[256];
- valRes[0]=0;
- if ( strfind( line , "=" , true ) == -1 ) return valRes;
- strmid( valRes , line , strfind( line , "=" , true )+1 , strlen( line ) , sizeof( valRes ) );
- return valRes;
- }
- strtok(const string[], &index)
- {
- new length = strlen(string);
- while ((index < length) && (string[index] <= ' '))
- {
- index++;
- }
- new offset = index;
- new result[20];
- while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
- {
- result[index - offset] = string[index];
- index++;
- }
- result[index - offset] = EOS;
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment