Advertisement
Guest User

Zh3r0

a guest
Jan 4th, 2011
1,893
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 11.87 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.  
  21.  
  22.  
  23. //
  24. #include    <  a_samp >
  25. #include    <  ZCMD   >
  26. #include    < sscanf  >
  27. #include    <YSI/y_ini>
  28.  
  29.  
  30. #define COL_RED         \
  31.         "{F81414}"
  32.  
  33. #define COL_LIGHTBLUE   \
  34.         "{00C0FF}"
  35.  
  36. #define COL_LRED        \
  37.         "{FFA1A1}"
  38.  
  39. #define COL_GREEN       \
  40.         "{6EF83C}"
  41.  
  42. #define DIALOG_REG      \
  43.         1995
  44.  
  45. #define DIALOG_REG_REQ  \
  46.         1996
  47.  
  48. #define DIALOG_LOGIN    \
  49.         1997
  50.  
  51. #define DIALOG_LOGIN2   \
  52.         1998
  53.  
  54. #define DIALOG_LOG_DONE \
  55.         1999
  56.  
  57. #define DIALOG_LOG      \
  58.         2000
  59.  
  60. #define DIALOG_STATS    \
  61.         2001
  62.        
  63. public OnFilterScriptInit( )    return 1;
  64. public OnFilterScriptExit( )    return 1;
  65.  
  66.  
  67. forward ParsePlayerPass( playerid, name[ ], value[ ] );
  68. public ParsePlayerPass( playerid, name[ ], value[ ] )
  69. {
  70.     if ( !strcmp( name, "PASSWORD" ) )
  71.     {
  72.         SetPVarString( playerid, "pPass", value );
  73.     }
  74. }
  75.  
  76. forward LoadUser( playerid, name[ ], value[ ] );
  77. public LoadUser( playerid, name[ ], value[ ] )
  78. {
  79.     if ( !strcmp(name, "REG_DATE" ) )SetPVarString( playerid, "Date", value );
  80.  
  81.     if ( !strcmp(name, "MONEYS" ) )SetPVarInt( playerid, "Moneys", strval( value ) );
  82.  
  83.     if ( !strcmp(name, "SCORE" ) )SetPVarInt( playerid, "Score", strval( value ) );
  84. }
  85.  
  86. CMD:register( playerid, params[ ] )
  87. {
  88.     #pragma unused params
  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:stats( playerid, paramz[ ] )
  105. {
  106.     if ( GetPVarInt( playerid, "Logged" ) == 0 )
  107.         return SendClientMessage( playerid, -1, ""COL_RED"ERROR:{FFFFFF} To view your stats you must be logged in ");
  108.        
  109.     new
  110.         iBox[ 256 ],
  111.         RegDate[ 10 + 15 ]
  112.     ;
  113.     GetPVarString( playerid, "Date", RegDate, 10 + 15 );
  114.     format( iBox, sizeof iBox, "{FFFFFF}Hello "COL_LIGHTBLUE"%s{FFFFFF}, these are your stats\n\n\
  115.                                 {FFFFFF}Moneys: "COL_LIGHTBLUE"%d\n\
  116.                                 {FFFFFF}Score: "COL_LIGHTBLUE"%d\n\
  117.                                 {FFFFFF}Registration Date: "COL_LIGHTBLUE"%s\n\
  118.                                 {FFFFFF}Interior: "COL_LIGHTBLUE"%d\n\
  119.                                 {FFFFFF}Virtual World: "COL_LIGHTBLUE"%d",pName( playerid ),
  120.                                               GetPlayerMoney( playerid ),
  121.                                               GetPlayerScore( playerid ),
  122.                                               RegDate,
  123.                                               GetPlayerInterior( playerid ),
  124.                                               GetPlayerVirtualWorld( playerid ) )
  125.                                 ;
  126.     ShowPlayerDialog( playerid, DIALOG_STATS, DIALOG_STYLE_MSGBOX, "{FFFFFF}Your Stats!", iBox, "Ok", "");
  127.     return 1;
  128. }
  129. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  130. {
  131.     switch( dialogid )
  132.     {
  133.         case DIALOG_REG:
  134.         {
  135.             if ( response )
  136.             {
  137.                 if ( sscanf( inputtext, "s", inputtext[ 0 ] || strlen( inputtext[ 0 ] ) == 0 ) )
  138.                     return ShowPlayerDialog( playerid, DIALOG_REG, DIALOG_STYLE_INPUT, "{FFFFFF}Password", ""COL_RED"Error!\n\
  139.                                                                                             {FFFFFF}Please write your desired password.\n",
  140.                                                                                             ">>>", "Exit");
  141.                 if ( strlen( inputtext[ 0 ] ) < 3 || strlen( inputtext[ 0 ] ) > 20 )
  142.                     return ShowPlayerDialog( playerid, DIALOG_REG, DIALOG_STYLE_INPUT, "{FFFFFF}Password", ""COL_RED"Error!\n\
  143.                                                                                             {FFFFFF}Please write your desired password.\n\
  144.                                                                                             "COL_RED"#{FFFFFF}Min. 3 Char. Max. 20 Char.",
  145.                                                                                             ">>>", "Exit");
  146.                 new
  147.                     PlayerFile[ 13 + MAX_PLAYER_NAME ],
  148.                     pDate[ 8 + 15 ], //HH:MM:SS + DD.MM.YYYY = 18
  149.                     pYear,
  150.                     pMonth,
  151.                     pDay,
  152.                     pHour,
  153.                     pMinute,
  154.                     pSecond,
  155.                     pIP[ 20 ],
  156.                     InfBox[ 512 ]
  157.                 ;
  158.                 getdate(pYear, pMonth, pDay ),gettime(pHour, pMinute, pSecond );
  159.                 GetPlayerIp( playerid, pIP, 20 );
  160.  
  161.                 format( PlayerFile , sizeof PlayerFile, "Accounts/%s.ini", Encode( pName( playerid ) ) );
  162.                 format( pDate, sizeof pDate, "%d:%d:%d  %d/%d/%d",pHour, pMinute, pSecond , pDay, pMonth, pYear );
  163.                 format( InfBox, sizeof InfBox, "{FFFFFF}You registered your account with success!\n\n\
  164.                                                         "COL_LIGHTBLUE"Account: {FFFFFF}%s\n\
  165.                                                         "COL_LIGHTBLUE"Password: {FFFFFF}%s\n\n\
  166.                                                         You received "COL_GREEN"$5000{FFFFFF} for registering.\n\
  167.                                                         Would you like to login?", pName( playerid ),
  168.                                                                                  inputtext       );
  169.                 ShowPlayerDialog( playerid, DIALOG_LOG, DIALOG_STYLE_MSGBOX, "Login", InfBox, "Yes", "No" );
  170.  
  171.  
  172.  
  173.                 new
  174.                     INI:PlayerAcc = INI_Open( PlayerFile );
  175.  
  176.                 INI_WriteString( PlayerAcc, "NAME",               pName( playerid )    );
  177.                 INI_WriteString( PlayerAcc, "PASSWORD",           inputtext            );
  178.                 INI_WriteString( PlayerAcc, "REG_DATE",           pDate                );
  179.                 INI_WriteInt( PlayerAcc,    "MONEYS",             5000                 );
  180.                 INI_WriteInt( PlayerAcc,    "SCORE",              15                   );
  181.                 INI_Close( PlayerAcc );
  182.  
  183.                 SetPVarString( playerid, "Date", pDate );
  184.                 SetPVarInt( playerid, "Logged", 0 );
  185.                 GivePlayerMoney( playerid, 5000 );
  186.                 SetPlayerScore( playerid, GetPlayerScore( playerid ) + 15 );
  187.  
  188.  
  189.             }
  190.         }
  191.         case DIALOG_REG_REQ:
  192.         {
  193.             if ( response ) cmd_register( playerid, "");
  194.             if ( !response ) return 0;
  195.  
  196.         }
  197.  
  198.         case DIALOG_LOGIN: ShowPlayerDialog( playerid, DIALOG_LOGIN2, DIALOG_STYLE_INPUT, "{FFFFFF}Password",
  199.                                                                                           "{FFFFFF}Please write your current password.",
  200.                                                                                           "Login", "Kick");
  201.  
  202.         case DIALOG_LOG:
  203.         {
  204.             if ( response )
  205.                 ShowPlayerDialog( playerid, DIALOG_LOGIN2, DIALOG_STYLE_INPUT, "{FFFFFF}Password",  "{FFFFFF}Please write your current password.","Login","Kick");
  206.         }
  207.         case DIALOG_LOGIN2:
  208.         {
  209.             if ( !response ) return Kick( playerid );
  210.             if ( response )
  211.             {
  212.                 if ( strlen( inputtext ) == 0 )
  213.                     return ShowPlayerDialog( playerid, DIALOG_LOGIN2, DIALOG_STYLE_INPUT, "{FFFFFF}Password",   ""COL_RED"Error!\n\
  214.                                                                                                                 {FFFFFF}Please write your current password.",
  215.                                                                                                                 "Login", "Kick");
  216.  
  217.                 new
  218.                     PlayerFile[ 13 + MAX_PLAYER_NAME ],
  219.                     Password[ 20 + 1 ]
  220.                 ;
  221.                 format( PlayerFile , sizeof PlayerFile, "Accounts/%s.ini", Encode( pName( playerid ) ) );
  222.                 INI_ParseFile( PlayerFile, "ParsePlayerPass", false, true, playerid );
  223.                 GetPVarString( playerid, "pPass", Password, sizeof Password );
  224.  
  225.                 if ( !strcmp ( inputtext, Password, false ) )
  226.                 {
  227.                     new
  228.                         sTitle[ 21 + MAX_PLAYER_NAME + 25 ],
  229.                         sBoxInfo[ 512 ],
  230.                         Pdata[ 8 + 15 ]
  231.                     ;
  232.  
  233.                     SetPVarInt( playerid, "Logged", 1 );
  234.                     format( PlayerFile , sizeof PlayerFile, "Accounts/%s.ini", Encode( pName( playerid ) ) );
  235.                     INI_ParseFile( PlayerFile, "LoadUser", false, true, playerid, true, false );
  236.                     GetPVarString( playerid, "Date", Pdata, 8 + 10 );
  237.                     GivePlayerMoney( playerid,GetPVarInt( playerid, "Moneys" )  );
  238.                     SetPlayerScore( playerid, GetPVarInt( playerid, "Score" )  );
  239.  
  240.                     format( sTitle, sizeof sTitle, "{FFFFFF}Welcome back, "COL_LIGHTBLUE"%s{FFFFFF}!", pName( playerid ) );
  241.                     format( sBoxInfo, sizeof sBoxInfo, "{FFFFFF}These are your stats:\n\n\
  242.                                                         {FFFFFF}Moneys: "COL_LIGHTBLUE"%d\n\
  243.                                                         {FFFFFF}Score: "COL_LIGHTBLUE"%d\n\
  244.                                                         {FFFFFF}Registered on: "COL_LIGHTBLUE"%s", GetPVarInt( playerid, "Moneys" ),
  245.                                                                                                    GetPVarInt( playerid, "Score" ),
  246.                                                                                                    Pdata );
  247.                     ShowPlayerDialog(playerid, DIALOG_LOG_DONE, DIALOG_STYLE_MSGBOX, sTitle, sBoxInfo, "Ok", "");
  248.  
  249.                 }
  250.                 else ShowPlayerDialog(playerid, DIALOG_LOGIN2, DIALOG_STYLE_INPUT, ""COL_RED"Wrong password...", ""COL_RED"Wrong password!\n{FFFFFF}Please try again.", "Login", "Kick");
  251.  
  252.  
  253.             }
  254.         }
  255.     }
  256.     return 1;
  257. }
  258.  
  259. public OnPlayerConnect(playerid)
  260. {
  261.     if ( !INI_Exist( pName( playerid ) ) )
  262.         ShowPlayerDialog( playerid, DIALOG_REG_REQ, DIALOG_STYLE_MSGBOX, "{FFFFFF}Password", "{FFFFFF}To play you must register an account!", "Ok", "");
  263.     else
  264.         ShowPlayerDialog( playerid, DIALOG_LOGIN, DIALOG_STYLE_MSGBOX, "{FFFFFF}Password", "{FFFFFF}Your name is registered, would you like to login?", "Da", "Nu");
  265.     return 1;
  266. }
  267.  
  268. public OnPlayerDisconnect(playerid, reason)
  269. {
  270.     if ( GetPVarInt( playerid, "Logged" ) == 1 && INI_Exist( pName( playerid ) ) )
  271.     {
  272.         new
  273.             PlayerFile[ 13 + MAX_PLAYER_NAME + 1];
  274.  
  275.         format( PlayerFile , sizeof PlayerFile, "Accounts/%s.ini", Encode( pName( playerid ) ) );
  276.  
  277.  
  278.         new
  279.             INI:PlayerAcc = INI_Open( PlayerFile );
  280.  
  281.         INI_WriteInt( PlayerAcc,    "MONEYS", GetPlayerMoney( playerid ) );
  282.         INI_WriteInt( PlayerAcc,    "SCORE",  GetPlayerScore( playerid ) );
  283.         INI_Close( PlayerAcc );
  284.     }
  285.     SetPVarInt( playerid, "Logged", 0 );
  286.     return 1;
  287. }
  288.  
  289.  
  290. stock INI_Exist(nickname[])
  291. {
  292.   new tmp[255];
  293.   format(tmp,sizeof(tmp),"Accounts/%s.ini",Encode( nickname ) );
  294.   return fexist(tmp);
  295. }
  296.  
  297. stock pName( playerid )
  298. {
  299.     new Name[ MAX_PLAYER_NAME ];
  300.     GetPlayerName( playerid, Name, sizeof( Name ) );
  301.     return Name;
  302. }
  303.  
  304. //DracoBlue
  305. stock Encode(nickname[])
  306. {
  307.   new tmp[255];
  308.   set(tmp,nickname);
  309.   tmp=strreplace("_","_00",tmp);
  310.   tmp=strreplace(";","_01",tmp);
  311.   tmp=strreplace("!","_02",tmp);
  312.   tmp=strreplace("/","_03",tmp);
  313.   tmp=strreplace("\\","_04",tmp);
  314.   tmp=strreplace("[","_05",tmp);
  315.   tmp=strreplace("]","_06",tmp);
  316.   tmp=strreplace("?","_07",tmp);
  317.   tmp=strreplace(".","_08",tmp);
  318.   tmp=strreplace("*","_09",tmp);
  319.   tmp=strreplace("<","_10",tmp);
  320.   tmp=strreplace(">","_11",tmp);
  321.   tmp=strreplace("{","_12",tmp);
  322.   tmp=strreplace("}","_13",tmp);
  323.   tmp=strreplace(" ","_14",tmp);
  324.   tmp=strreplace("\"","_15",tmp);
  325.   tmp=strreplace(":","_16",tmp);
  326.   tmp=strreplace("|","_17",tmp);
  327.   tmp=strreplace("=","_18",tmp);
  328.   return tmp;
  329. }
  330. stock set(dest[],source[]) {
  331.     new count = strlen(source);
  332.     new i=0;
  333.     for (i=0;i<count;i++) {
  334.         dest[i]=source[i];
  335.     }
  336.     dest[count]=0;
  337. }
  338. stock strreplace(trg[],newstr[],src[]) {
  339.     new f=0;
  340.     new s1[255];
  341.     new tmp[255];
  342.     format(s1,sizeof(s1),"%s",src);
  343.     f = strfind(s1,trg);
  344.     tmp[0]=0;
  345.     while (f>=0) {
  346.         strcat(tmp,ret_memcpy(s1, 0, f));
  347.         strcat(tmp,newstr);
  348.         format(s1,sizeof(s1),"%s",ret_memcpy(s1, f+strlen(trg), strlen(s1)-f));
  349.         f = strfind(s1,trg);
  350.     }
  351.     strcat(tmp,s1);
  352.     return tmp;
  353. }
  354. ret_memcpy(source[],index=0,numbytes) {
  355.     new tmp[255];
  356.     new i=0;
  357.     tmp[0]=0;
  358.     if (index>=strlen(source)) return tmp;
  359.     if (numbytes+index>=strlen(source)) numbytes=strlen(source)-index;
  360.     if (numbytes<=0) return tmp;
  361.     for (i=index;i<numbytes+index;i++) {
  362.         tmp[i-index]=source[i];
  363.         if (source[i]==0) return tmp;
  364.     }
  365.     tmp[numbytes]=0;
  366.     return tmp;
  367. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement