Guest User

Untitled

a guest
Feb 26th, 2011
541
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.93 KB | None | 0 0
  1. /*
  2. Login / Register system by Zh3r0, using ZCMD + SSCANF + Y_INI
  3. Y_INI is the fastet writing system ever.
  4. ZCMD is the fastet command proccessor.
  5. SSCANF is the most usefull function ever made.
  6.  
  7.  
  8. [ Credits ]
  9. Y_Less - Y_Ini, SSCANF
  10. Zeex - ZCMD
  11. Dracoblue - Set, strreplace, pName, Encode, INI_Exist
  12. Zh3r0 - Building up this system using the above functions...
  13.  
  14.  
  15. !!!
  16. INI_Exist Function is not from Y_Ini, i transformed it from DINI to this.
  17. Remove the credits, and you are a complete moron. Do it! You will be a moron!
  18. !!!
  19.  
  20. Changelog:
  21.  
  22. v1.2 - Added VIP System 3 levels;
  23. Level 1: /vipgod
  24. Level 2: /vipgod /vipcargod
  25. Level 3: /vipgod /vipcargod /vnrg /vinf
  26.  
  27. v1.1 - Added Admin system.
  28. v1.0 - Initial release
  29. */
  30.  
  31.  
  32. #include < a_samp >
  33. #include < ZCMD >
  34. #include < sscanf2 >
  35. #include <YSI/y_ini>
  36.  
  37. //0.3c Colors
  38. #define COL_RED "{F81414}"
  39. #define COL_LIGHTBLUE "{00C0FF}"
  40. #define COL_LRED "{FFA1A1}"
  41. #define COL_GREEN "{6EF83C}"
  42. #define COL_GREY "{C3C3C3}"
  43.  
  44. //Dialogs
  45. #define DIALOG_REG 1995
  46. #define DIALOG_REG_REQ 1996
  47. #define DIALOG_LOGIN 1997
  48. #define DIALOG_LOGIN2 1998
  49. #define DIALOG_LOG_DONE 1999
  50. #define DIALOG_LOG 2000
  51. #define DIALOG_STATS 2001
  52. #define INFO_BOX 2002
  53.  
  54. //
  55. #define Level0 "Member"
  56. #define Level1 "Moderator"
  57. #define Level2 "Administrator"
  58. #define Level3 "Lead Administrator"
  59. #define Level4 "Keeper of the Keys"
  60.  
  61. public OnFilterScriptInit( ) return 1;
  62. public OnFilterScriptExit( ) return 1;
  63.  
  64. forward ParsePlayerPass( playerid, name[ ], value[ ] );
  65. public ParsePlayerPass( playerid, name[ ], value[ ] )
  66. {
  67. if ( !strcmp( name, "PASSWORD" ) )
  68. {
  69. SetPVarString( playerid, "pPass", value );
  70. }
  71. }
  72.  
  73. forward LoadUser( playerid, name[ ], value[ ] );
  74. public LoadUser( playerid, name[ ], value[ ] )
  75. {
  76. if ( !strcmp(name, "REG_DATE" ) ) SetPVarString( playerid, "Date", value );
  77. if ( !strcmp(name, "MONEYS" ) ) SetPVarInt( playerid, "Moneys", strval( value ) );
  78. if ( !strcmp(name, "SCORE" ) ) SetPVarInt( playerid, "Score", strval( value ) );
  79. if ( !strcmp(name, "LEVEL" ) ) SetPVarInt( playerid, "Level", strval( value ) );
  80. if ( !strcmp(name, "VIP_LEVEL" ) ) SetPVarInt( playerid, "VIP Level", strval( value ) );
  81. if ( !strcmp(name, "LAST_ON" ) ) SetPVarString( playerid, "On", value );
  82. if ( !strcmp(name, "KILLS" ) ) SetPVarInt( playerid, "Kills", strval( value ) );
  83. if ( !strcmp(name, "DEATHS" ) ) SetPVarInt( playerid, "Deaths", strval( value ) );
  84. if ( !strcmp(name, "MUTED" ) ) SetPVarInt( playerid, "Muted", strval( value ) );
  85. }
  86.  
  87. CMD:register( playerid, params[ ] )
  88. {
  89. if ( GetPVarInt( playerid, "Logged" ) == 1 )
  90. return SendClientMessage( playerid, -1, ""COL_RED"ERROR:{FFFFFF} You are already registered and logged in.");
  91.  
  92. ShowPlayerDialog( playerid, DIALOG_REG, DIALOG_STYLE_INPUT, "{FFFFFF}Registering...", "{FFFFFF}Please write your desired password.", ">>>", "Exit");
  93. return 1;
  94. }
  95. CMD:login( playerid, params[ ] )
  96. {
  97. #pragma unused params
  98. if ( GetPVarInt( playerid, "Logged" ) == 1 )
  99. return SendClientMessage( playerid, -1, ""COL_RED"ERROR:{FFFFFF} You are already registered and logged in.");
  100.  
  101. ShowPlayerDialog( playerid, DIALOG_LOGIN2, DIALOG_STYLE_INPUT, "{FFFFFF}Login", "{FFFFFF}Please write your current password", "Login", "Kick");
  102. return 1;
  103. }
  104. CMD:changepass( playerid, params[ ] )
  105. {
  106. if ( !INI_Exist( pName( playerid ) ) )
  107. return SendClientMessage( playerid, -1, ""COL_RED"ERROR:{FFFFFF} You must be registered to change your pass.Use "COL_LIGHTBLUE"/register{FFFFFF}.");
  108.  
  109. if ( GetPVarInt( playerid, "Logged" ) == 0 )
  110. return SendClientMessage( playerid, -1, ""COL_RED"ERROR:{FFFFFF} Please "COL_LIGHTBLUE"/login{FFFFFF} to change your password.");
  111.  
  112. new NewPass[ 21 ], OldPass[ 21 ];
  113. if ( sscanf( params, "ss", OldPass, NewPass ) )
  114. return SendClientMessage( playerid, -1, ""COL_LIGHTBLUE"Usage:{FFFFFF} /changepass [OLD] [NEW]");
  115.  
  116. new PlayerFile[ 13 + MAX_PLAYER_NAME ];
  117.  
  118. format( PlayerFile , sizeof PlayerFile, "Accounts/%s.ini", Encode( pName( playerid ) ) );
  119. INI_ParseFile( PlayerFile, "ParsePlayerPass", false, true, playerid );
  120.  
  121. new Password[ 20 ],
  122. String[ 129 ]
  123. ;
  124. GetPVarString( playerid, "pPass", Password, 20 );
  125.  
  126. if ( strcmp( Password, OldPass, false ) != 0 )
  127. return SendClientMessage( playerid, -1, ""COL_RED"ERROR:{FFFFFF} Old password didn't match the one you inserted!");
  128.  
  129. if ( strlen( NewPass ) < 3 || strlen( NewPass ) > 20 )
  130. return SendClientMessage( playerid, -1, ""COL_RED"ERROR:{FFFFFF} New password may contain Min. 3 Char. and Max. 20 Char.");
  131.  
  132. format( String, sizeof String, "You have changed your password to \""COL_LIGHTBLUE"%s{FFFFFF}\" ", NewPass );
  133. SendClientMessage( playerid, -1, String );
  134.  
  135. format( PlayerFile , sizeof PlayerFile, "Accounts/%s.ini", Encode( pName( playerid ) ) );
  136. new
  137. INI:PlayerAcc = INI_Open( PlayerFile );
  138. INI_WriteString( PlayerAcc, "OLD_PASSWORD", OldPass);
  139. INI_WriteString( PlayerAcc, "PASSWORD", NewPass);
  140. INI_Close( PlayerAcc );
  141. return 1;
  142. }
  143.  
  144. stock GetPlayerLevelName( playerid )
  145. {
  146. new Llevel[ 15 ];
  147. if ( GetPVarInt( playerid, "Level" ) == 0 ) Llevel = Level0;
  148. if ( GetPVarInt( playerid, "Level" ) == 1 ) Llevel = Level1;
  149. if ( GetPVarInt( playerid, "Level" ) == 2 ) Llevel = Level2;
  150. if ( GetPVarInt( playerid, "Level" ) == 3 ) Llevel = Level3;
  151. if ( GetPVarInt( playerid, "Level" ) == 4 ) Llevel = Level4;
  152. return Llevel;
  153. }
  154.  
  155. CMD:setlevel( playerid, params[ ] )
  156. {
  157. if ( GetPVarInt( playerid, "Level" ) < 3 && !IsPlayerAdmin( playerid ) )
  158. return SendClientMessage( playerid, -1, "You are not allowed to use this command");
  159.  
  160. if ( sscanf( params, "ui", params[ 0 ], params[ 1 ] ) )
  161. return SendClientMessage( playerid, -1, ""COL_LIGHTBLUE"Usage:{FFFFFF} /setlevel <id/name> <level> "),SendClientMessage( playerid, -1, "-Check "COL_LIGHTBLUE"/levelranks{FFFFFF} to view each level's name");
  162.  
  163. if ( !IsPlayerConnected( params[ 0 ] ) )
  164. return SendClientMessage( playerid, -1, ""COL_RED"Player is not connected");
  165.  
  166. if ( params[ 1 ] < 0 || params[ 1 ] > 3 )
  167. return SendClientMessage( playerid, -1, "You must insert from level "COL_LIGHTBLUE"0{FFFFFF} to "COL_LIGHTBLUE"3{FFFFFF}");
  168.  
  169. if ( GetPVarInt( playerid, "Level" ) < GetPVarInt( params[ 0 ], "Level" ) )
  170. return SendClientMessage( playerid, -1, "You are not allowed to use this command on this admin."),SendClientMessage( playerid, -1, "REASON: Player is higher in grade than you.");
  171.  
  172.  
  173. SetPVarInt( params[ 0 ], "Level", params[ 1 ] );
  174. new String[ 256 ];
  175. if ( playerid == params[ 0 ] )
  176. {
  177. format( String, sizeof String, "You made yourself an admin level "COL_LIGHTBLUE"%d{FFFFFF}["COL_LIGHTBLUE"%s{FFFFFF}]", params[ 1 ], GetPlayerLevelName( playerid ) );
  178. SendClientMessage( playerid, -1, String );
  179. }
  180. else
  181. {
  182. format( String, sizeof String, "You made "COL_LIGHTBLUE"%s{FFFFFF} an "COL_LIGHTBLUE"%s{FFFFFF} level "COL_LIGHTBLUE"%d",pName( params[ 0 ] ), GetPlayerLevelName( playerid ), params[ 1 ] );
  183. SendClientMessage( playerid, -1, String );
  184. format( String, sizeof String, "%s( %s ) made you an %s",pName( playerid ), GetPlayerLevelName( playerid ),GetPlayerLevelName( params[ 0 ] ) );
  185. SendClientMessage( params[ 0 ], -1, String );
  186. }
  187. return 1;
  188. }
  189. CMD:setvip( playerid, params[ ] )
  190. {
  191. if ( GetPVarInt( playerid, "Level" ) < 3 )
  192. return SendClientMessage( playerid, -1, "You are not allowed to use this command!");
  193.  
  194. if ( sscanf( params, "ui", params[ 0 ], params[ 1 ] ) )
  195. return SendClientMessage( playerid, -1, ""COL_LIGHTBLUE"Usage:{FFFFFF} /setvip <id/name> <level> ");
  196.  
  197. if ( !IsPlayerConnected( params[ 0 ] ) )
  198. return SendClientMessage( playerid, -1, ""COL_RED"Player is not connected");
  199.  
  200. if ( params[ 1 ] < 0 || params[ 1 ] > 3 )
  201. return SendClientMessage( playerid, -1, "You must insert from level "COL_LIGHTBLUE"0{FFFFFF} to "COL_LIGHTBLUE"3{FFFFFF}");
  202.  
  203. if (GetPVarInt( playerid, "Level" ) < GetPVarInt( params[ 0 ], "Level" ) )
  204. return SendClientMessage( playerid, -1, "You are not allowed to use this command on this admin."),SendClientMessage( playerid, -1, "REASON: Player is higher in grade than you.");
  205.  
  206.  
  207. SetPVarInt( params[ 0 ], "VIP Level", params[ 1 ] );
  208. new String[ 256 ];
  209. if ( playerid == params[ 0 ] )
  210. {
  211. format( String, sizeof String, "You made yourself a VIP level "COL_LIGHTBLUE"%d", params[ 1 ]);
  212. SendClientMessage( playerid, -1, String );
  213. }
  214. else
  215. {
  216. format( String, sizeof String, "You made "COL_LIGHTBLUE"%s{FFFFFF} a VIP level %d", pName( params[ 0 ] ),params[ 1 ] );
  217. SendClientMessage( playerid, -1, String );
  218. format( String, sizeof String, "%s( %s ) made you a VIP Level %d",pName( playerid ), GetPlayerLevelName( playerid ), params[ 1 ] );
  219. SendClientMessage( params[ 0 ], -1, String );
  220. }
  221. return 1;
  222. }
  223.  
  224. CMD:mute( playerid,params[])
  225. {
  226. if ( GetPVarInt( playerid, "Level" ) < 2 )
  227. return SendClientMessage( playerid, -1, "You must be an "#Level2" to use this command");
  228.  
  229. if ( sscanf( params, "u", params[ 0 ], params[ 1 ] ) )
  230. return SendClientMessage( playerid, -1, ""COL_LIGHTBLUE"Usage:{FFFFFF} /mute <id/name>");
  231.  
  232. if ( GetPVarInt( playerid, "Muted" ) == 1 )
  233. return SendClientMessage( playerid, -1, ""COL_RED"ERROR:{FFFFFF} Player is already muted.");
  234.  
  235. if ( !IsPlayerConnected( params[ 0 ] ) )
  236. return SendClientMessage( playerid, -1, ""COL_RED"Player is not connected");
  237.  
  238. if (GetPVarInt( playerid, "Level" ) < GetPVarInt( params[ 0 ], "Level" ) )
  239. return SendClientMessage( playerid, -1, "You are not allowed to use this command on this admin."),SendClientMessage( playerid, -1, "REASON: Player is higher in grade than you.");
  240.  
  241. SetPVarInt( params[ 0 ], "Muted", 1 );
  242.  
  243. new String[ 245 ];
  244. format( String, sizeof String, "You muted "COL_LIGHTBLUE"%s", pName( params[ 0 ] ));
  245. SendClientMessage( playerid, -1, String );
  246. format( String, sizeof String, ""COL_LIGHTBLUE"%s( %s ){FFFFFF} muted you.",pName( playerid ), GetPlayerLevelName( playerid ));
  247. SendClientMessage( params[ 0 ], -1, String );
  248. return 1;
  249. }
  250. CMD:unmute( playerid,params[])
  251. {
  252. if ( GetPVarInt( playerid, "Level" ) < 2 )
  253. return SendClientMessage( playerid, -1, "You must be an "#Level2" to use this command");
  254.  
  255. if ( sscanf( params, "u", params[ 0 ], params[ 1 ] ) )
  256. return SendClientMessage( playerid, -1, ""COL_LIGHTBLUE"Usage:{FFFFFF} /mute <id/name>");
  257.  
  258. if ( GetPVarInt( playerid, "Muted" ) == 0 )
  259. return SendClientMessage( playerid, -1, ""COL_RED"ERROR:{FFFFFF} Player is already un-muted.");
  260.  
  261. if ( !IsPlayerConnected( params[ 0 ] ) )
  262. return SendClientMessage( playerid, -1, ""COL_RED"Player is not connected");
  263.  
  264. if (GetPVarInt( playerid, "Level" ) < GetPVarInt( params[ 0 ], "Level" ) )
  265. return SendClientMessage( playerid, -1, "You are not allowed to use this command on this admin."),SendClientMessage( playerid, -1, "REASON: Player is higher in grade than you.");
  266.  
  267. SetPVarInt( params[ 0 ], "Muted", 0 );
  268.  
  269. new String[ 245 ];
  270. format( String, sizeof String, "You unmuted "COL_LIGHTBLUE"%s", pName( params[ 0 ] ));
  271. SendClientMessage( playerid, -1, String );
  272. format( String, sizeof String, ""COL_LIGHTBLUE"%s( %s ){FFFFFF} unmuted you.",pName( playerid ), GetPlayerLevelName( playerid ));
  273. SendClientMessage( params[ 0 ], -1, String );
  274. return 1;
  275. }
  276. CMD:stats( playerid, paramz[ ] )
  277. {
  278. if ( GetPVarInt( playerid, "Logged" ) == 0 )
  279. return SendClientMessage( playerid, -1, ""COL_RED"ERROR:{FFFFFF} To view your stats you must be logged in ");
  280.  
  281. new
  282. iBox[ 1024 ],
  283. RegDate[ 40 ],
  284. pLastOn[ 20 + 20 ],
  285. pLevel = GetPVarInt( playerid, "Level")
  286. ;
  287. GetPVarString( playerid, "Date", RegDate, sizeof RegDate );
  288. GetPVarString( playerid, "On", pLastOn, sizeof pLastOn );
  289.  
  290. format( iBox, sizeof iBox, "{FFFFFF}Hello "COL_LIGHTBLUE"%s{FFFFFF}, these are your stats\n\n\
  291. {FFFFFF}Admin level: "COL_LIGHTBLUE"%s{FFFFFF}["COL_LIGHTBLUE"%d{FFFFFF}]\n\
  292. {FFFFFF}VIP Level: "COL_LIGHTBLUE"%d\n\
  293. {FFFFFF}Moneys: "COL_LIGHTBLUE"%d\n\
  294. {FFFFFF}Score: "COL_LIGHTBLUE"%d\n\
  295. {FFFFFF}Kills: "COL_LIGHTBLUE"%d\n\
  296. {FFFFFF}Deaths: "COL_LIGHTBLUE"%d\n\
  297. {FFFFFF}Registration Date: "COL_LIGHTBLUE"%s\n\
  298. {FFFFFF}Interior: "COL_LIGHTBLUE"%d\n",
  299. pName( playerid ),
  300. GetPlayerLevelName( playerid ),
  301. pLevel,
  302. GetPlayerVLevel( playerid ),
  303. GetPlayerMoney( playerid ),
  304. GetPlayerScore( playerid ),
  305. GetPVarInt( playerid,"Kills" ),
  306. GetPVarInt( playerid,"Deaths" ),
  307. RegDate,
  308. GetPlayerInterior( playerid ) );
  309.  
  310. format( iBox, sizeof iBox, "%s{FFFFFF}Virtual World: "COL_LIGHTBLUE"%d\n\
  311. {FFFFFF}My Favorite Skin: "COL_LIGHTBLUE"%d\n\
  312. {FFFFFF}My Time: "COL_LIGHTBLUE"%d\n\
  313. {FFFFFF}My Weather: "COL_LIGHTBLUE"%d\n\
  314. {FFFFFF}Last On: "COL_LIGHTBLUE"%s\n\
  315. {FFFFFF}Car God: "COL_LIGHTBLUE"%s\n\
  316. {FFFFFF}Player God: "COL_LIGHTBLUE"%s",
  317. iBox,
  318. GetPlayerVirtualWorld( playerid ),
  319. pLastOn;
  320.  
  321. ShowPlayerDialog( playerid, DIALOG_STATS, DIALOG_STYLE_MSGBOX, "{FFFFFF}Your Stats!", iBox, "Ok", "");
  322. return 1;
  323. }
  324.  
  325. public OnPlayerDeath( playerid, killerid, reason )
  326. {
  327. SetPVarInt( killerid, "Kills", GetPVarInt( playerid, "Kills" ) + 1 );
  328. SetPVarInt( playerid, "Deaths", GetPVarInt( playerid, "Deaths" ) + 1 );
  329. return 1;
  330. }
  331. public OnPlayerText( playerid, text[] )
  332. {
  333. if ( GetPVarInt( playerid, "Muted" ) == 1 && !IsPlayerAdmin( playerid ) )
  334. {
  335. SendClientMessage( playerid, -1, ""COL_RED"ERROR:{FFFFFF} You are muted, you cannot chat!");
  336. }
  337. return 1;
  338. }
  339. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  340. {
  341. switch( dialogid )
  342. {
  343. case DIALOG_REG:
  344. {
  345. if ( response )
  346. {
  347. if ( sscanf( inputtext, "s", inputtext[ 0 ] || strlen( inputtext[ 0 ] ) == 0 ) )
  348. return ShowPlayerDialog( playerid, DIALOG_REG, DIALOG_STYLE_INPUT, "{FFFFFF}Password", ""COL_RED"Error!\n\
  349. {FFFFFF}Please write your desired password.\n",
  350. ">>>", "Exit");
  351. if ( strlen( inputtext[ 0 ] ) < 3 || strlen( inputtext[ 0 ] ) > 20 )
  352. return ShowPlayerDialog( playerid, DIALOG_REG, DIALOG_STYLE_INPUT, "{FFFFFF}Password", ""COL_RED"Error!\n\
  353. {FFFFFF}Please write your desired password.\n\
  354. "COL_RED"#{FFFFFF}Min. 3 Char. Max. 20 Char.",
  355. ">>>", "Exit");
  356. new
  357. PlayerFile[ 13 + MAX_PLAYER_NAME ],
  358. pDate[ 8 + 15 ], //HH:MM:SS + DD.MM.YYYY = 18
  359. pYear,
  360. pMonth,
  361. pDay,
  362. pHour,
  363. pMinute,
  364. pSecond,
  365. pIP[ 20 ],
  366. InfBox[ 512 ]
  367. ;
  368. getdate(pYear, pMonth, pDay ),gettime(pHour, pMinute, pSecond );
  369. GetPlayerIp( playerid, pIP, 20 );
  370.  
  371.  
  372. format( PlayerFile , sizeof PlayerFile, "Accounts/%s.ini", Encode( pName( playerid ) ) );
  373. format( pDate, sizeof pDate, "%d:%d:%d %d/%d/%d",pHour, pMinute, pSecond , pDay, pMonth, pYear );
  374. format( InfBox, sizeof InfBox, "{FFFFFF}You registered your account with success!\n\n\
  375. "COL_LIGHTBLUE"Account: {FFFFFF}%s\n\
  376. "COL_LIGHTBLUE"Password: {FFFFFF}%s\n\n\
  377. You received "COL_GREEN"$5000{FFFFFF} for registering.\n\
  378. Would you like to login?", pName( playerid ),
  379. inputtext );
  380. ShowPlayerDialog( playerid, DIALOG_LOG, DIALOG_STYLE_MSGBOX, "Login", InfBox, "Yes", "No" );
  381.  
  382.  
  383. new
  384. INI:PlayerAcc = INI_Open( PlayerFile );
  385.  
  386. INI_WriteString( PlayerAcc, "NAME", pName( playerid ) );
  387. INI_WriteString( PlayerAcc, "PASSWORD", inputtext );
  388. INI_WriteString( PlayerAcc, "REG_DATE", pDate );
  389. INI_WriteString( PlayerAcc, "LAST_ON", "First connection" );
  390. INI_WriteInt( PlayerAcc, "MONEYS", 5000 );
  391. INI_WriteInt( PlayerAcc, "SCORE", 15 );
  392. INI_WriteInt( PlayerAcc, "KILLS", 0 );
  393. INI_WriteInt( PlayerAcc, "DEATHS", 0 );
  394. INI_WriteInt( PlayerAcc, "VIP_LEVEL", 0 );
  395. INI_WriteInt( PlayerAcc, "LEVEL", 0 );
  396. INI_WriteInt( PlayerAcc, "MY_SKIN", 0 );
  397. INI_WriteInt( PlayerAcc, "MY_TIME", 12 );
  398. INI_WriteInt( PlayerAcc, "MY_WEATHER", 1 );
  399.  
  400. INI_Close( PlayerAcc );
  401.  
  402. SetPVarString( playerid, "Date", pDate );
  403. SetPVarInt( playerid, "Logged", 0 );
  404. GivePlayerMoney( playerid, 5000 );
  405. SetPlayerScore( playerid, GetPlayerScore( playerid ) + 15 );
  406.  
  407.  
  408. }
  409. }
  410. case DIALOG_REG_REQ:
  411. {
  412. if ( response ) cmd_register( playerid, "");
  413. if ( !response ) return 0;
  414.  
  415. }
  416.  
  417. case DIALOG_LOGIN: ShowPlayerDialog( playerid, DIALOG_LOGIN2, DIALOG_STYLE_INPUT, "{FFFFFF}Password",
  418. "{FFFFFF}Please write your current password.",
  419. "Login", "Kick");
  420.  
  421. case DIALOG_LOG:
  422. {
  423. if ( response )
  424. ShowPlayerDialog( playerid, DIALOG_LOGIN2, DIALOG_STYLE_INPUT, "{FFFFFF}Password", "{FFFFFF}Please write your current password.","Login","Kick");
  425. }
  426. case DIALOG_LOGIN2:
  427. {
  428. if ( !response ) return Kick( playerid );
  429. if ( response )
  430. {
  431. if ( strlen( inputtext ) == 0 )
  432. return ShowPlayerDialog( playerid, DIALOG_LOGIN2, DIALOG_STYLE_INPUT, "{FFFFFF}Password", ""COL_RED"Error!\n\
  433. {FFFFFF}Please write your current password.",
  434. "Login", "Kick");
  435.  
  436. new
  437. PlayerFile[ 13 + MAX_PLAYER_NAME ],
  438. Password[ 20 + 1 ]
  439. ;
  440. format( PlayerFile , sizeof PlayerFile, "Accounts/%s.ini", Encode( pName( playerid ) ) );
  441. INI_ParseFile( PlayerFile, "ParsePlayerPass", false, true, playerid );
  442. GetPVarString( playerid, "pPass", Password, sizeof Password );
  443.  
  444. if ( !strcmp ( inputtext, Password, false ) )
  445. {
  446. new
  447. sTitle[ 21 + MAX_PLAYER_NAME + 25 ],
  448. sBoxInfo[ 512 ],
  449. Pdata[ 8 + 15 ]
  450. ;
  451.  
  452. SetPVarInt( playerid, "Logged", 1 );
  453. format( PlayerFile , sizeof PlayerFile, "Accounts/%s.ini", Encode( pName( playerid ) ) );
  454. INI_ParseFile( PlayerFile, "LoadUser", false, true, playerid, true, false );
  455. GetPVarString( playerid, "Date", Pdata, 8 + 10 );
  456.  
  457. format( sTitle, sizeof sTitle, "{FFFFFF}Welcome back, "COL_LIGHTBLUE"%s{FFFFFF}!", pName( playerid ) );
  458. if ( GetPVarInt( playerid, "Level" ) == 0 )
  459. {
  460. format( sBoxInfo, sizeof sBoxInfo, "{FFFFFF}These are your stats:\n\n\
  461. {FFFFFF}Rank: "COL_LIGHTBLUE"%s\n\
  462. {FFFFFF}VIP Level: "COL_LIGHTBLUE"%d\n\
  463. {FFFFFF}Score: "COL_LIGHTBLUE"%d\n\
  464. {FFFFFF}Registered on: "COL_LIGHTBLUE"%s\n\n\
  465. {FFFFFF}To view more stats please type to "COL_LIGHTBLUE"/stats\n\
  466. {FFFFFF}Type "COL_LIGHTBLUE"/mycmds{FFFFFF} to view your current commands.",
  467. GetPlayerLevelName( playerid ),
  468. GetPlayerVLevel( playerid ),
  469. GetPVarInt( playerid, "Score" ),
  470. Pdata );
  471. }
  472. if ( GetPVarInt( playerid, "Level" ) > 1 )
  473. {
  474. format( sBoxInfo, sizeof sBoxInfo, "{FFFFFF}These are your stats:\n\n\
  475. {FFFFFF}Level: "COL_LIGHTBLUE"%s\n\
  476. {FFFFFF}VIP Level: "COL_LIGHTBLUE"%d\n\
  477. {FFFFFF}Score: "COL_LIGHTBLUE"%d\n\
  478. {FFFFFF}Registered on: "COL_LIGHTBLUE"%s\n\n",
  479. GetPlayerLevelName( playerid ),
  480. GetPlayerVLevel( playerid ),
  481. GetPVarInt( playerid, "Score" ),
  482. Pdata );
  483.  
  484. format( sBoxInfo, sizeof sBoxInfo, "%s{FFFFFF}To view more stats please type to "COL_LIGHTBLUE"/stats\n\
  485. {FFFFFF}Type "COL_LIGHTBLUE"/mycmds{FFFFFF} to view your current commands.\n\
  486. "COL_RED"Admin note:{FFFFFF}Use "COL_LIGHTBLUE"/acmds {FFFFFF}and "COL_LIGHTBLUE"/arules {FFFFFF}for commands and Admin rules.",sBoxInfo);
  487. }
  488. ShowPlayerDialog(playerid, DIALOG_LOG_DONE, DIALOG_STYLE_MSGBOX, sTitle, sBoxInfo, "Ok", "");
  489.  
  490. }
  491. else ShowPlayerDialog(playerid, DIALOG_LOGIN2, DIALOG_STYLE_INPUT, ""COL_RED"Wrong password...", ""COL_RED"Wrong password!\n{FFFFFF}Please try again.", "Login", "Kick");
  492.  
  493.  
  494. }
  495. }
  496. }
  497. return 1;
  498. }
  499.  
  500. public OnPlayerConnect(playerid)
  501. {
  502. if ( !INI_Exist( pName( playerid ) ) )
  503. ShowPlayerDialog( playerid, DIALOG_REG_REQ, DIALOG_STYLE_MSGBOX, "{FFFFFF}Password", "{FFFFFF}To play you must register an account!", "Ok", "");
  504. else
  505. ShowPlayerDialog( playerid, DIALOG_LOGIN, DIALOG_STYLE_MSGBOX, "{FFFFFF}Password", "{FFFFFF}Your name is registered, would you like to login?", "Yes", "No");
  506. return 1;
  507. }
  508.  
  509. public OnPlayerDisconnect(playerid, reason)
  510. {
  511. if ( GetPVarInt( playerid, "Logged" ) == 1 && INI_Exist( pName( playerid ) ) )
  512. {
  513. new
  514. PlayerFile[ 13 + MAX_PLAYER_NAME + 1],
  515. tDate[ 40 ],
  516. Year,
  517. Month,
  518. Day,
  519. Hour,
  520. Minute,
  521. Second
  522. ;
  523.  
  524. format( PlayerFile , sizeof PlayerFile, "Accounts/%s.ini", Encode( pName( playerid ) ) );
  525. getdate( Year,Month,Day );
  526. gettime( Hour,Minute,Second );
  527. format( tDate, sizeof tDate, "%d/%d/%d at %d:%d:%d", Day,Month,Year,Hour,Minute,Second);
  528.  
  529. new
  530. INI:PlayerAcc = INI_Open( PlayerFile );
  531.  
  532. INI_WriteInt( PlayerAcc, "MONEYS", GetPlayerMoney( playerid ) );
  533. INI_WriteInt( PlayerAcc, "SCORE", GetPlayerScore( playerid ) );
  534. INI_WriteInt( PlayerAcc, "KILLS", GetPVarInt( playerid, "Kills" ) );
  535. INI_WriteInt( PlayerAcc, "DEATHS", GetPVarInt( playerid, "Deaths" ) );
  536. INI_WriteInt( PlayerAcc, "LEVEL", GetPVarInt( playerid, "Level" ) );
  537. INI_WriteInt( PlayerAcc, "VIP_LEVEL", GetPVarInt( playerid, "VIP Level" ) );
  538. INI_WriteInt( PlayerAcc, "MUTED", GetPVarInt( playerid, "Muted" ) );
  539. INI_WriteString( PlayerAcc, "LAST_ON", tDate );
  540. INI_Close( PlayerAcc );
  541. }
  542. SetPVarInt( playerid, "Logged", 0 );
  543. return 1;
  544. }
  545. //Stocks
  546. stock GetPlayerVLevel( playerid ) return GetPVarInt( playerid, "VIP Level" );
  547.  
  548. stock INI_Exist(nickname[])
  549. {
  550. new tmp[255];
  551. format(tmp,sizeof(tmp),"Accounts/%s.ini",Encode( nickname ) );
  552. return fexist(tmp);
  553. }
  554.  
  555. stock pName( playerid )
  556. {
  557. new Name[ MAX_PLAYER_NAME ];
  558. GetPlayerName( playerid, Name, sizeof( Name ) );
  559. return Name;
  560. }
  561.  
  562. //DracoBlue
  563. stock Encode(nickname[])
  564. {
  565. new tmp[255];
  566. set(tmp,nickname);
  567. tmp=strreplace("_","_00",tmp);
  568. tmp=strreplace(";","_01",tmp);
  569. tmp=strreplace("!","_02",tmp);
  570. tmp=strreplace("/","_03",tmp);
  571. tmp=strreplace("\\","_04",tmp);
  572. tmp=strreplace("[","_05",tmp);
  573. tmp=strreplace("]","_06",tmp);
  574. tmp=strreplace("?","_07",tmp);
  575. tmp=strreplace(".","_08",tmp);
  576. tmp=strreplace("*","_09",tmp);
  577. tmp=strreplace("<","_10",tmp);
  578. tmp=strreplace(">","_11",tmp);
  579. tmp=strreplace("{","_12",tmp);
  580. tmp=strreplace("}","_13",tmp);
  581. tmp=strreplace(" ","_14",tmp);
  582. tmp=strreplace("\"","_15",tmp);
  583. tmp=strreplace(":","_16",tmp);
  584. tmp=strreplace("|","_17",tmp);
  585. tmp=strreplace("=","_18",tmp);
  586. return tmp;
  587. }
  588. stock set(dest[],source[]) {
  589. new count = strlen(source);
  590. new i=0;
  591. for (i=0;i<count;i++) {
  592. dest[i]=source[i];
  593. }
  594. dest[count]=0;
  595. }
  596. stock strreplace(trg[],newstr[],src[]) {
  597. new f=0;
  598. new s1[255];
  599. new tmp[255];
  600. format(s1,sizeof(s1),"%s",src);
  601. f = strfind(s1,trg);
  602. tmp[0]=0;
  603. while (f>=0) {
  604. strcat(tmp,ret_memcpy(s1, 0, f));
  605. strcat(tmp,newstr);
  606. format(s1,sizeof(s1),"%s",ret_memcpy(s1, f+strlen(trg), strlen(s1)-f));
  607. f = strfind(s1,trg);
  608. }
  609. strcat(tmp,s1);
  610. return tmp;
  611. }
  612. ret_memcpy(source[],index=0,numbytes) {
  613. new tmp[255];
  614. new i=0;
  615. tmp[0]=0;
  616. if (index>=strlen(source)) return tmp;
  617. if (numbytes+index>=strlen(source)) numbytes=strlen(source)-index;
  618. if (numbytes<=0) return tmp;
  619. for (i=index;i<numbytes+index;i++) {
  620. tmp[i-index]=source[i];
  621. if (source[i]==0) return tmp;
  622. }
  623. tmp[numbytes]=0;
  624. return tmp;
  625. }
Advertisement
Add Comment
Please, Sign In to add comment