Advertisement
Guest User

Untitled

a guest
Feb 4th, 2022
514
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.73 KB | None | 0 0
  1. /*==============================================================================
  2.  
  3. $$\ $$$$$$\ $$$$$$\ $$$$$$\ $$\ $$\
  4. $$ | $$ __$$\ $$ __$$\ \_$$ _|$$$\ $$ |
  5. $$ | $$ / $$ |$$ / \__| $$ | $$$$\ $$ |
  6. $$ | $$ | $$ |$$ |$$$$\ $$ | $$ $$\$$ |
  7. $$ | $$ | $$ |$$ |\_$$ | $$ | $$ \$$$$ |
  8. $$ | $$ | $$ |$$ | $$ | $$ | $$ |\$$$ |
  9. $$$$$$$$\ $$$$$$ |\$$$$$$ |$$$$$$\ $$ | \$$ |
  10. \________|\______/ \______/ \______|\__| \__|
  11.  
  12. Login sys: 1/1/2021
  13.  
  14. Last edited: 5/2/2022
  15.  
  16. Credits<Fr0z3n>
  17.  
  18. ==============================================================================*/
  19.  
  20. // includes
  21. #include <a_mysql>
  22. #include <bcrypt>
  23. //
  24. #include <YSI_Visual\y_dialog>
  25. #include <YSI_Visual\y_commands>
  26. //
  27. #include <YSI_Coding\y_inline>
  28. #include <YSI_Coding\y_hooks>
  29. #include <YSI_Coding\y_timers>
  30. //
  31. #include <YSI_Extra\y_inline_bcrypt>
  32. #include <YSI_Extra\y_inline_mysql>
  33. //
  34. #include <YSI_Data\y_bit>
  35. #include <YSI_Data\y_percent>
  36. //
  37. #include <YSI_Players\y_groups>
  38. //
  39. #include <YSI_Server\y_colours>
  40.  
  41. // declarations
  42. const MAX_POKUSAJ_LOGINA = 5;
  43.  
  44. new
  45. BitArray:LoggedIn<MAX_PLAYERS char>,
  46. BitArray:RegisteredIn<MAX_PLAYERS char>,
  47. Timer:LoginTimer,
  48. LoginCount[ MAX_PLAYERS ],
  49. p_Password[ MAX_PLAYERS ][YSI_MAX_STRING]
  50. ;
  51.  
  52. // timers
  53. timer t_login[20000](playerid)
  54. return Kick(playerid);
  55.  
  56. // funcs
  57. ShowLogin(playerid)
  58. {
  59. inline const CheckAccount()
  60. {
  61. switch(cache_num_rows())
  62. {
  63. case 0: // Register
  64. {
  65. static szIP[ 16 ];
  66. GetPlayerIp( playerid, szIP, sizeof( szIP ) );
  67. inline const OnPlayerDuplicateAccountCheck()
  68. {
  69. switch(cache_num_rows())
  70. {
  71. case 0..10:
  72. {
  73. inline const Register(pid, dialogid, response, listitem, string:inputtext[])
  74. {
  75. #pragma unused pid, dialogid, listitem
  76.  
  77. if(!response)
  78. return Kick(playerid);
  79.  
  80. static Regex:regex;
  81. if (!regex) regex = Regex_New("^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[@$!*?&])[A-Za-z\\d@$!*?&]{8,12}$");
  82.  
  83. new RegexMatch:match;
  84. if (!Regex_Match(inputtext, regex, match) || isnull(inputtext))
  85. {
  86. SendClientMessage(playerid, -1, ""CRVENA"[GRESKA] Sifra mora sadrzati minimalno 8, a maksimalno 12 karaktera.");
  87. SendClientMessage(playerid, -1, ""CRVENA"[GRESKA] Sifra mora sadrzati bar jedno veliko slovo, jedan broj i jedan specijalni karakter(&, !, *, @...).");
  88. return ShowLogin(playerid);
  89. }
  90. else // show email
  91. {
  92. inline const OnHashed(string:result[])
  93. {
  94. p_Password[playerid] = result;
  95. Bit_Vet(RegisteredIn, playerid);
  96. SetPlayerCash( playerid, 5000 );
  97. SetPlayerScore( playerid, 0 );
  98. ShowEmail(playerid); // iliti ga spawnaj ga
  99. SendServerMessage( playerid, "Vi ste se "ZELENA"uspesno{FFFFFF} registrovali! Automatski ste prijavljeni!" );
  100. YSI_PrintF("Hashed: %s", result);
  101. }
  102. BCrypt_HashInline(inputtext, 12, using inline OnHashed);
  103. }
  104. }
  105. Dialog_ShowCallback(playerid, using inline Register, DIALOG_STYLE_INPUT, !"Registracija", \
  106. va_return(""BELA"Dobrodosao, ovaj nalog ("CRVENA"%s"BELA") nije registrovan.\nUnesite zeljenu lozinku za ovaj nalog.", ReturnPlayerName(playerid)), !"OK", !"Cancel");
  107. }
  108. default:
  109. {
  110. 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!");
  111. defer KickPlayer(playerid);
  112. }
  113. }
  114. }
  115. MySQL_TQueryInline(Database, using inline OnPlayerDuplicateAccountCheck, "SELECT `IPAddress` FROM `players` WHERE `IPAddress` = '%e' LIMIT 5", szIP);
  116. }
  117. case 1: // Login
  118. {
  119. LoginTimer = defer t_login(playerid);
  120. inline const Login(pid, dialogid, response, listitem, string:inputtext[])
  121. {
  122. #pragma unused pid, dialogid, listitem
  123.  
  124. if(!response)
  125. return Kick(playerid);
  126.  
  127. if (isnull(inputtext))
  128. {
  129. // Try again.
  130. if( LoginCount[ playerid ] == MAX_POKUSAJ_LOGINA-1 ) {
  131. va_SendClientMessage(playerid, -1, ""CRVENA"Uneli ste pogresnu lozinku %d puta i dobili kick!", MAX_POKUSAJ_LOGINA );
  132. return Kick( playerid );
  133. }
  134. else {
  135. LoginCount[ playerid ]++;
  136. 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");
  137. }
  138. }
  139. else
  140. {
  141.  
  142. inline const PasswordHash()
  143. {
  144. new Password[BCRYPT_HASH_LENGTH];
  145. cache_get_value_name(0, "Password", Password, BCRYPT_HASH_LENGTH);
  146. inline const OnHashVerification(bool:same)
  147. {
  148. if(same)
  149. {
  150. ac_TogglePlayerSpectating(playerid, 0);
  151. cache_get_value_name_int(0, "ID", p_ID[playerid]);
  152. cache_get_value_name_int(0, "Cash", p_Cash[playerid]);
  153. cache_get_value_name_int(0, "Kills", p_Kills[playerid]);
  154. cache_get_value_name_int(0, "Deaths", p_Deaths[playerid]);
  155.  
  156. Bit_Let(LoggedIn, playerid);
  157. SendClientMessage(playerid, -1, ""CRVENA"Dobro dosli nazad!.");
  158. ac_SetSpawnInfo(playerid, 0, 203, 1622.5942,-2334.1638,13.5394, 360, 0, 0, 0, 0, 0, 0);
  159. stop LoginTimer;
  160. return ac_SpawnPlayer( playerid );
  161. }
  162. else
  163. {
  164. // Try again.
  165. if( LoginCount[ playerid ] == MAX_POKUSAJ_LOGINA-1 ) {
  166. va_SendClientMessage(playerid, -1, ""CRVENA"Uneli ste pogresnu lozinku %d puta i dobili kick!", MAX_POKUSAJ_LOGINA );
  167. return Kick( playerid );
  168. }
  169. else {
  170. LoginCount[ playerid ]++;
  171. 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");
  172. }
  173. }
  174. }
  175. BCrypt_CheckInline(inputtext, Password, using inline OnHashVerification);
  176. }
  177. MySQL_TQueryInline(Database, using inline PasswordHash, "SELECT `Password` FROM `players` WHERE `Username` = '%e'", ReturnPlayerName(playerid));
  178. }
  179. }
  180. Dialog_ShowCallback(playerid, using inline Login, DIALOG_STYLE_PASSWORD, !"Login", !"Unesite lozinku\n\n"CRVENA"[NAPOMENA]: Imate 20 sekundi da ukucate lozinku", !"OK", !"Cancel");
  181. }
  182. }
  183. }
  184. MySQL_TQueryInline(Database, using inline CheckAccount, "SELECT `Username` FROM `players` WHERE `Username` = '%e' LIMIT 0,1", ReturnPlayerName(playerid));
  185. return 1;
  186. }
  187.  
  188. ShowEmail(playerid)
  189. {
  190. inline const EmailVerification(pid, dialogid, response, listitem, string:inputtext[])
  191. {
  192. #pragma unused pid, dialogid, listitem, inputtext
  193.  
  194. if ( ! response ) {
  195. SendServerMessage( playerid, "Ako ikada u buducnosti budete zeleli da dodate email na vas nalog koristite komandu "SIVA"/email"BELA"." );
  196. return ShowClasses(playerid);
  197. }
  198.  
  199. new
  200. email[ 64 ];
  201.  
  202. if ( sscanf( inputtext, "s[64]", email ) )
  203. 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" );
  204.  
  205.  
  206. if ( ! ( 3 < strlen( email ) < 64 ) )
  207. 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" );
  208.  
  209. static Regex:regex;
  210. if (!regex) regex = Regex_New("[a-zA-Z0-9_\\.]+@([a-zA-Z0-9\\-]+\\.)+[a-zA-Z]{2,4}");
  211.  
  212. new RegexMatch:match;
  213. if (!Regex_Match(inputtext, regex, match))
  214. 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" );
  215.  
  216. inline const EmailSendVerification()
  217. {
  218. new
  219. verification_id = cache_insert_id( );
  220.  
  221. // alert
  222. SendServerMessage( playerid, "Email vam je poslat na "SIVA"%s"BELA" sa instrukcijama za potvrdu vaseg naloga.", email );
  223.  
  224. // sending email
  225. 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 );
  226. SendMail( email, ReturnPlayerName( playerid ), sprintf( "Verify your account, %s", ReturnPlayerName( playerid ) ), szLargeString );
  227. ShowClasses(playerid);
  228. }
  229. 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 );
  230. return 1;
  231. }
  232. 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" );
  233. return 1;
  234. }
  235.  
  236. // hooks
  237. hook OnPlayerConnect(playerid)
  238. {
  239. ShowLogin(playerid);
  240. LoginCount[ playerid ] = 0;
  241. return Y_HOOKS_CONTINUE_RETURN_1;
  242. }
  243.  
  244. hook OnPlayerDisconnect(playerid, reason)
  245. {
  246. return Y_HOOKS_CONTINUE_RETURN_1;
  247. }
  248.  
  249. // Ac pass
  250. stock SetPlayerCash( playerid, money )
  251. {
  252. p_Cash[ playerid ] = money;
  253. ResetPlayerMoney( playerid );
  254. GivePlayerMoney( playerid, p_Cash[ playerid ] );
  255. }
  256.  
  257. // Verify passes
  258. stock GetPlayerAccountID( playerid ) return p_ID[ playerid ];
  259. stock IsPlayerLoggedIn( playerid ) return Bit_Get(LoggedIn, playerid);
  260. stock IsPlayerRegistered( playerid ) return Bit_Get(RegisteredIn, playerid);
  261.  
  262.  
  263. // Deo koji je u modulima ali mene mrzi da vam delim pa cu sve u jednu skriptu da stavim HVALA!
  264. #if ( !defined MAILER_MAX_MAIL_SIZE )
  265. #define MAILER_MAX_MAIL_SIZE (1024)
  266. #endif
  267.  
  268. #define MAILING_URL "montana-ogc.eu"
  269. #define MAILER_URL MAILING_URL#"/email/process"
  270. #if ( !defined MAILER_URL )
  271. #error Molimo definisite MAILER_URL pre nego sto includate mailer podatke.
  272. #endif
  273.  
  274. stock SendMail( const szReceiver[ ], const szReceiverName[ ], const szSubject[ ], const szMessage[ ] )
  275. {
  276. new
  277. szBuffer[ MAILER_MAX_MAIL_SIZE ] = "t=",
  278. iPos = strlen( szBuffer ),
  279. iLength = strlen( szReceiver )
  280. ;
  281.  
  282. memcpy( szBuffer, szReceiver, iPos * 4, ( iLength + 1 ) * 4 );
  283.  
  284. StringURLEncode( szBuffer[ iPos ], 1024 - iPos );
  285.  
  286. strcat( szBuffer, "&n=" );
  287.  
  288. iPos = strlen( szBuffer );
  289. iLength = strlen( szReceiverName );
  290.  
  291. memcpy( szBuffer, szReceiverName, iPos * 4, ( iLength + 1 ) * 4 );
  292.  
  293. StringURLEncode( szBuffer[ iPos ], 1024 - iPos );
  294.  
  295. strcat( szBuffer, "&s=" );
  296.  
  297. iPos = strlen( szBuffer );
  298. iLength = strlen( szSubject );
  299.  
  300. memcpy( szBuffer, szSubject, iPos * 4, ( iLength + 1 ) * 4 );
  301.  
  302. StringURLEncode( szBuffer[ iPos ], 1024 - iPos );
  303.  
  304. strcat( szBuffer, "&m=" );
  305.  
  306. iPos = strlen( szBuffer );
  307. iLength = strlen( szMessage );
  308.  
  309. memcpy( szBuffer, szMessage, iPos * 4, ( iLength + 1 ) * 4 );
  310.  
  311. StringURLEncode( szBuffer[ iPos ], 1024 - iPos );
  312.  
  313. // printf("Buffer %s", szBuffer);
  314. HTTP( 0xD00D, HTTP_POST, MAILER_URL, szBuffer, "OnMailScriptResponse" );
  315. }
  316.  
  317. forward OnMailScriptResponse( iIndex, iResponseCode, const szData[ ] );
  318. public OnMailScriptResponse( iIndex, iResponseCode, const szData[ ] )
  319. {
  320. if ( szData[ 0 ] )
  321. YSI_Print( "Down" );
  322. }
  323.  
  324. stock StringURLEncode( szString[ ], iSize = sizeof( szString ) )
  325. {
  326. for ( new i = 0, l = strlen( szString ); i < l; i++ )
  327. {
  328. switch ( szString[ i ] )
  329. {
  330. case '!', '(', ')', '\'', '*',
  331. '0' .. '9',
  332. 'A' .. 'Z',
  333. 'a' .. 'z':
  334. {
  335. continue;
  336. }
  337.  
  338. case ' ':
  339. {
  340. szString[ i ] = '+';
  341.  
  342. continue;
  343. }
  344. }
  345.  
  346. new
  347. s_szHex[ 8 ]
  348. ;
  349.  
  350. if ( i + 3 >= iSize )
  351. {
  352. szString[ i ] = EOS;
  353.  
  354. break;
  355. }
  356.  
  357. if ( l + 3 >= iSize )
  358. szString[ iSize - 3 ] = EOS;
  359.  
  360. format( s_szHex, sizeof( s_szHex ), "%02h", szString[ i ] );
  361.  
  362. szString[ i ] = '%';
  363.  
  364. strins( szString, s_szHex, i + 1, iSize );
  365.  
  366. l += 2;
  367. i += 2;
  368.  
  369. if ( l > iSize - 1 )
  370. l = iSize - 1;
  371. }
  372. }
  373.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement