Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*==============================================================================
- $$\ $$$$$$\ $$$$$$\ $$$$$$\ $$\ $$\
- $$ | $$ __$$\ $$ __$$\ \_$$ _|$$$\ $$ |
- $$ | $$ / $$ |$$ / \__| $$ | $$$$\ $$ |
- $$ | $$ | $$ |$$ |$$$$\ $$ | $$ $$\$$ |
- $$ | $$ | $$ |$$ |\_$$ | $$ | $$ \$$$$ |
- $$ | $$ | $$ |$$ | $$ | $$ | $$ |\$$$ |
- $$$$$$$$\ $$$$$$ |\$$$$$$ |$$$$$$\ $$ | \$$ |
- \________|\______/ \______/ \______|\__| \__|
- Login sys: 1/1/2021
- Last edited: 5/2/2022
- Credits<Fr0z3n>
- ==============================================================================*/
- // includes
- #include <a_mysql>
- #include <bcrypt>
- //
- #include <YSI_Visual\y_dialog>
- #include <YSI_Visual\y_commands>
- //
- #include <YSI_Coding\y_inline>
- #include <YSI_Coding\y_hooks>
- #include <YSI_Coding\y_timers>
- //
- #include <YSI_Extra\y_inline_bcrypt>
- #include <YSI_Extra\y_inline_mysql>
- //
- #include <YSI_Data\y_bit>
- #include <YSI_Data\y_percent>
- //
- #include <YSI_Players\y_groups>
- //
- #include <YSI_Server\y_colours>
- // declarations
- const MAX_POKUSAJ_LOGINA = 5;
- new
- BitArray:LoggedIn<MAX_PLAYERS char>,
- BitArray:RegisteredIn<MAX_PLAYERS char>,
- Timer:LoginTimer,
- LoginCount[ MAX_PLAYERS ],
- p_Password[ MAX_PLAYERS ][YSI_MAX_STRING]
- ;
- // timers
- timer t_login[20000](playerid)
- return Kick(playerid);
- // funcs
- ShowLogin(playerid)
- {
- inline const CheckAccount()
- {
- switch(cache_num_rows())
- {
- case 0: // Register
- {
- static szIP[ 16 ];
- GetPlayerIp( playerid, szIP, sizeof( szIP ) );
- inline const OnPlayerDuplicateAccountCheck()
- {
- switch(cache_num_rows())
- {
- case 0..10:
- {
- inline const Register(pid, dialogid, response, listitem, string:inputtext[])
- {
- #pragma unused pid, dialogid, listitem
- if(!response)
- return Kick(playerid);
- static Regex:regex;
- if (!regex) regex = Regex_New("^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[@$!*?&])[A-Za-z\\d@$!*?&]{8,12}$");
- new RegexMatch:match;
- if (!Regex_Match(inputtext, regex, match) || isnull(inputtext))
- {
- SendClientMessage(playerid, -1, ""CRVENA"[GRESKA] Sifra mora sadrzati minimalno 8, a maksimalno 12 karaktera.");
- SendClientMessage(playerid, -1, ""CRVENA"[GRESKA] Sifra mora sadrzati bar jedno veliko slovo, jedan broj i jedan specijalni karakter(&, !, *, @...).");
- return ShowLogin(playerid);
- }
- else // show email
- {
- inline const OnHashed(string:result[])
- {
- p_Password[playerid] = result;
- Bit_Vet(RegisteredIn, playerid);
- SetPlayerCash( playerid, 5000 );
- SetPlayerScore( playerid, 0 );
- ShowEmail(playerid); // iliti ga spawnaj ga
- SendServerMessage( playerid, "Vi ste se "ZELENA"uspesno{FFFFFF} registrovali! Automatski ste prijavljeni!" );
- YSI_PrintF("Hashed: %s", result);
- }
- BCrypt_HashInline(inputtext, 12, using inline OnHashed);
- }
- }
- Dialog_ShowCallback(playerid, using inline Register, DIALOG_STYLE_INPUT, !"Registracija", \
- va_return(""BELA"Dobrodosao, ovaj nalog ("CRVENA"%s"BELA") nije registrovan.\nUnesite zeljenu lozinku za ovaj nalog.", ReturnPlayerName(playerid)), !"OK", !"Cancel");
- }
- default:
- {
- SendClientMessage(playerid, -1, ""CRVENA"[GRESKA]Zao nam je, ova IP adresa ima vise od 10 registrovanih korisnika sto je maksimalno ogranicenje korisnika po IP-u!");
- defer KickPlayer(playerid);
- }
- }
- }
- MySQL_TQueryInline(Database, using inline OnPlayerDuplicateAccountCheck, "SELECT `IPAddress` FROM `players` WHERE `IPAddress` = '%e' LIMIT 5", szIP);
- }
- case 1: // Login
- {
- LoginTimer = defer t_login(playerid);
- inline const Login(pid, dialogid, response, listitem, string:inputtext[])
- {
- #pragma unused pid, dialogid, listitem
- if(!response)
- return Kick(playerid);
- if (isnull(inputtext))
- {
- // Try again.
- if( LoginCount[ playerid ] == MAX_POKUSAJ_LOGINA-1 ) {
- va_SendClientMessage(playerid, -1, ""CRVENA"Uneli ste pogresnu lozinku %d puta i dobili kick!", MAX_POKUSAJ_LOGINA );
- return Kick( playerid );
- }
- else {
- LoginCount[ playerid ]++;
- return Dialog_ShowCallback(playerid, using inline Login, DIALOG_STYLE_PASSWORD, !"Login", !""CRVENA"[GRESKA]:Pogresna lozinka!\n\n"BELA"Unesite lozinku\n\n"CRVENA"[NAPOMENA]: Imate 20 sekundi da ukucate lozinku", !"OK", !"Cancel");
- }
- }
- else
- {
- inline const PasswordHash()
- {
- new Password[BCRYPT_HASH_LENGTH];
- cache_get_value_name(0, "Password", Password, BCRYPT_HASH_LENGTH);
- inline const OnHashVerification(bool:same)
- {
- if(same)
- {
- ac_TogglePlayerSpectating(playerid, 0);
- cache_get_value_name_int(0, "ID", p_ID[playerid]);
- cache_get_value_name_int(0, "Cash", p_Cash[playerid]);
- cache_get_value_name_int(0, "Kills", p_Kills[playerid]);
- cache_get_value_name_int(0, "Deaths", p_Deaths[playerid]);
- Bit_Let(LoggedIn, playerid);
- SendClientMessage(playerid, -1, ""CRVENA"Dobro dosli nazad!.");
- ac_SetSpawnInfo(playerid, 0, 203, 1622.5942,-2334.1638,13.5394, 360, 0, 0, 0, 0, 0, 0);
- stop LoginTimer;
- return ac_SpawnPlayer( playerid );
- }
- else
- {
- // Try again.
- if( LoginCount[ playerid ] == MAX_POKUSAJ_LOGINA-1 ) {
- va_SendClientMessage(playerid, -1, ""CRVENA"Uneli ste pogresnu lozinku %d puta i dobili kick!", MAX_POKUSAJ_LOGINA );
- return Kick( playerid );
- }
- else {
- LoginCount[ playerid ]++;
- return Dialog_ShowCallback(playerid, using inline Login, DIALOG_STYLE_PASSWORD, !"Login", !""CRVENA"[GRESKA]:Pogresna lozinka!\n\n"BELA"Unesite lozinku\n\n"CRVENA"[NAPOMENA]: Imate 20 sekundi da ukucate lozinku", !"OK", !"Cancel");
- }
- }
- }
- BCrypt_CheckInline(inputtext, Password, using inline OnHashVerification);
- }
- MySQL_TQueryInline(Database, using inline PasswordHash, "SELECT `Password` FROM `players` WHERE `Username` = '%e'", ReturnPlayerName(playerid));
- }
- }
- Dialog_ShowCallback(playerid, using inline Login, DIALOG_STYLE_PASSWORD, !"Login", !"Unesite lozinku\n\n"CRVENA"[NAPOMENA]: Imate 20 sekundi da ukucate lozinku", !"OK", !"Cancel");
- }
- }
- }
- MySQL_TQueryInline(Database, using inline CheckAccount, "SELECT `Username` FROM `players` WHERE `Username` = '%e' LIMIT 0,1", ReturnPlayerName(playerid));
- return 1;
- }
- ShowEmail(playerid)
- {
- inline const EmailVerification(pid, dialogid, response, listitem, string:inputtext[])
- {
- #pragma unused pid, dialogid, listitem, inputtext
- if ( ! response ) {
- SendServerMessage( playerid, "Ako ikada u buducnosti budete zeleli da dodate email na vas nalog koristite komandu "SIVA"/email"BELA"." );
- return ShowClasses(playerid);
- }
- new
- email[ 64 ];
- if ( sscanf( inputtext, "s[64]", email ) )
- return Dialog_ShowCallback(playerid, using inline EmailVerification, DIALOG_STYLE_INPUT, "{FFFFFF}Account Email", !""BELA"Da li zelite da dodelite email svom nalogu radi bezbednosti?\n\nTakodje cemo vas obavestavati o dogadjajima u igri i zajednici!\n\n"CRVENA"Tvoj email mora sadrzati od 4 do 64 karaktera.", !"Confirm", !"Cancel" );
- if ( ! ( 3 < strlen( email ) < 64 ) )
- return Dialog_ShowCallback(playerid, using inline EmailVerification, DIALOG_STYLE_INPUT, "{FFFFFF}Account Email", !""BELA"Da li zelite da dodelite email svom nalogu radi bezbednosti?\n\nTakodje cemo vas obavestavati o dogadjajima u igri i zajednici!\n\n"CRVENA"Tvoj email mora sadrzati od 4 do 64 karaktera.", !"Confirm", !"Cancel" );
- static Regex:regex;
- if (!regex) regex = Regex_New("[a-zA-Z0-9_\\.]+@([a-zA-Z0-9\\-]+\\.)+[a-zA-Z]{2,4}");
- new RegexMatch:match;
- if (!Regex_Match(inputtext, regex, match))
- return Dialog_ShowCallback(playerid, using inline EmailVerification, DIALOG_STYLE_INPUT, "{FFFFFF}Account Email", !""BELA"Da li zelite da dodelite email svom nalogu radi bezbednosti?\n\nTakodje cemo vas obavestavati o dogadjajima u igri i zajednici!\n\n"CRVENA"Tvoj email mora biti validam primer: ([email protected]).", !"Confirm", !"Cancel" );
- inline const EmailSendVerification()
- {
- new
- verification_id = cache_insert_id( );
- // alert
- SendServerMessage( playerid, "Email vam je poslat na "SIVA"%s"BELA" sa instrukcijama za potvrdu vaseg naloga.", email );
- // sending email
- format( szLargeString, sizeof( szLargeString ), "<p>Pozdrav %s, dobijate ovu poruku zato sto zelite da dodate zastu na vas nalog.</p><p><a href='http://" # MAILING_URL "/email/verify/%d/%d'>Click here to verify your email</a></p>", ReturnPlayerName( playerid ), p_ID[ playerid ], verification_id );
- SendMail( email, ReturnPlayerName( playerid ), sprintf( "Verify your account, %s", ReturnPlayerName( playerid ) ), szLargeString );
- ShowClasses(playerid);
- }
- MySQL_TQueryInline(Database, using inline EmailSendVerification, "INSERT INTO `EMAIL_VERIFY`(`USER_ID`, `EMAIL`) VALUES (%d, '%e') ON DUPLICATE KEY UPDATE `EMAIL`='%e',`DATE`=CURRENT_TIMESTAMP", p_ID[ playerid ], email, email );
- return 1;
- }
- Dialog_ShowCallback(playerid, using inline EmailVerification, DIALOG_STYLE_INPUT, "{FFFFFF}Account Email", !""BELA"Da li zelite da dodelite email svom nalogu radi bezbednosti?\n\nTakodje cemo vas obavestavati o dogadjajima u igri i zajednici!", !"Confirm", !"Cancel" );
- return 1;
- }
- // hooks
- hook OnPlayerConnect(playerid)
- {
- ShowLogin(playerid);
- LoginCount[ playerid ] = 0;
- return Y_HOOKS_CONTINUE_RETURN_1;
- }
- hook OnPlayerDisconnect(playerid, reason)
- {
- return Y_HOOKS_CONTINUE_RETURN_1;
- }
- // Ac pass
- stock SetPlayerCash( playerid, money )
- {
- p_Cash[ playerid ] = money;
- ResetPlayerMoney( playerid );
- GivePlayerMoney( playerid, p_Cash[ playerid ] );
- }
- // Verify passes
- stock GetPlayerAccountID( playerid ) return p_ID[ playerid ];
- stock IsPlayerLoggedIn( playerid ) return Bit_Get(LoggedIn, playerid);
- stock IsPlayerRegistered( playerid ) return Bit_Get(RegisteredIn, playerid);
- // Deo koji je u modulima ali mene mrzi da vam delim pa cu sve u jednu skriptu da stavim HVALA!
- #if ( !defined MAILER_MAX_MAIL_SIZE )
- #define MAILER_MAX_MAIL_SIZE (1024)
- #endif
- #define MAILING_URL "montana-ogc.eu"
- #define MAILER_URL MAILING_URL#"/email/process"
- #if ( !defined MAILER_URL )
- #error Molimo definisite MAILER_URL pre nego sto includate mailer podatke.
- #endif
- stock SendMail( const szReceiver[ ], const szReceiverName[ ], const szSubject[ ], const szMessage[ ] )
- {
- new
- szBuffer[ MAILER_MAX_MAIL_SIZE ] = "t=",
- iPos = strlen( szBuffer ),
- iLength = strlen( szReceiver )
- ;
- memcpy( szBuffer, szReceiver, iPos * 4, ( iLength + 1 ) * 4 );
- StringURLEncode( szBuffer[ iPos ], 1024 - iPos );
- strcat( szBuffer, "&n=" );
- iPos = strlen( szBuffer );
- iLength = strlen( szReceiverName );
- memcpy( szBuffer, szReceiverName, iPos * 4, ( iLength + 1 ) * 4 );
- StringURLEncode( szBuffer[ iPos ], 1024 - iPos );
- strcat( szBuffer, "&s=" );
- iPos = strlen( szBuffer );
- iLength = strlen( szSubject );
- memcpy( szBuffer, szSubject, iPos * 4, ( iLength + 1 ) * 4 );
- StringURLEncode( szBuffer[ iPos ], 1024 - iPos );
- strcat( szBuffer, "&m=" );
- iPos = strlen( szBuffer );
- iLength = strlen( szMessage );
- memcpy( szBuffer, szMessage, iPos * 4, ( iLength + 1 ) * 4 );
- StringURLEncode( szBuffer[ iPos ], 1024 - iPos );
- // printf("Buffer %s", szBuffer);
- HTTP( 0xD00D, HTTP_POST, MAILER_URL, szBuffer, "OnMailScriptResponse" );
- }
- forward OnMailScriptResponse( iIndex, iResponseCode, const szData[ ] );
- public OnMailScriptResponse( iIndex, iResponseCode, const szData[ ] )
- {
- if ( szData[ 0 ] )
- YSI_Print( "Down" );
- }
- stock StringURLEncode( szString[ ], iSize = sizeof( szString ) )
- {
- for ( new i = 0, l = strlen( szString ); i < l; i++ )
- {
- switch ( szString[ i ] )
- {
- case '!', '(', ')', '\'', '*',
- '0' .. '9',
- 'A' .. 'Z',
- 'a' .. 'z':
- {
- continue;
- }
- case ' ':
- {
- szString[ i ] = '+';
- continue;
- }
- }
- new
- s_szHex[ 8 ]
- ;
- if ( i + 3 >= iSize )
- {
- szString[ i ] = EOS;
- break;
- }
- if ( l + 3 >= iSize )
- szString[ iSize - 3 ] = EOS;
- format( s_szHex, sizeof( s_szHex ), "%02h", szString[ i ] );
- szString[ i ] = '%';
- strins( szString, s_szHex, i + 1, iSize );
- l += 2;
- i += 2;
- if ( l > iSize - 1 )
- l = iSize - 1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement