Advertisement
MarkoGamer123

LOGIN I REGISTER SISTEM

Apr 20th, 2022
1,227
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //-------------------------------------------------OVA NAJGORE DA SE STAVAT OBAVEZNO INCLUDE STO SE NAJGORE --------------------
  2.  
  3. #include <YSI\y_ini>
  4.  
  5. #define DIALOG_REGISTER 1
  6. #define DIALOG_LOGIN 2
  7. #define DIALOG_SUCCESS_1 3
  8. #define DIALOG_SUCCESS_2 4
  9.  
  10. #define PATH "/Korisnici/%s.ini"
  11.  
  12. #define COL_WHITE "{FFFFFF}"
  13. #define COL_RED "{F81414}"
  14. #define COL_GREEN "{00FF22}"
  15. #define COL_LIGHTBLUE "{00CED1}"
  16.  
  17. enum pInfo
  18. {
  19.     pLozinka,
  20.     pPari,
  21.     pAdmin,
  22.     pUbistva,
  23.     pUmrenost
  24. }
  25. new PlayerInfo[MAX_PLAYERS][pInfo];
  26.  
  27. //--------------------------------------------------------------------------------------------------------------------------
  28.  
  29. //-------------------------------------------------------OVA KADE SAKATE----------------------------------------------------
  30.  
  31. forward LoadUser_data(playerid,name[],value[]);
  32. public LoadUser_data(playerid,name[],value[])
  33. {
  34.     INI_Int("Password",PlayerInfo[playerid][pLozinka]);
  35.     INI_Int("Cash",PlayerInfo[playerid][pPari]);
  36.     INI_Int("Admin",PlayerInfo[playerid][pAdmin]);
  37.     INI_Int("Kills",PlayerInfo[playerid][pUbistva]);
  38.     INI_Int("Deaths",PlayerInfo[playerid][pUmrenost]);
  39.     return 1;
  40. }
  41.  
  42. stock UserPath(playerid)
  43. {
  44.     new string[128],playername[MAX_PLAYER_NAME];
  45.     GetPlayerName(playerid,playername,sizeof(playername));
  46.     format(string,sizeof(string),PATH,playername);
  47.     return string;
  48. }
  49.  
  50. stock udb_hash(buf[]) {
  51.     new length=strlen(buf);
  52.     new s1 = 1;
  53.     new s2 = 0;
  54.     new n;
  55.     for (n=0; n<length; n++)
  56.     {
  57.        s1 = (s1 + buf[n]) % 65521;
  58.        s2 = (s2 + s1)     % 65521;
  59.     }
  60.     return (s2 << 16) + s1;
  61. }
  62. //--------------------------------------------------------------------------------------------------------------------------
  63.  
  64. //-------------------------------------------OVA KADE STO SE BARA-----------------------------------------------------------
  65. public OnPlayerConnect(playerid)
  66. {
  67.     if(fexist(UserPath(playerid)))
  68.     {
  69.         INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
  70.         ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,""COL_WHITE"Login",""COL_WHITE"Napisete ja vasata lozinka.","Login","Izlez");
  71.     }
  72.     else
  73.     {
  74.         ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT,""COL_WHITE"Register",""COL_WHITE"Kako sakate da vi bidi vasata lozinka.","Register",Izlezi");
  75.     }
  76.     return 1;
  77. }
  78.  
  79. public OnPlayerDisconnect(playerid, reason)
  80. {
  81.     new INI:File = INI_Open(UserPath(playerid));
  82.     INI_SetTag(File,"data");
  83.     INI_WriteInt(File,"Pari",GetPlayerMoney(playerid));
  84.     INI_WriteInt(File,"Admin",PlayerInfo[playerid][pAdmin]);
  85.     INI_WriteInt(File,"Ubistva",PlayerInfo[playerid][pUbistva]);
  86.     INI_WriteInt(File,"Umrenost",PlayerInfo[playerid][pUmrenost]);
  87.     INI_Close(File);
  88.     return 1;
  89. }
  90.  
  91. public OnPlayerDeath(playerid, killerid, reason)
  92. {
  93.     PlayerInfo[killerid][pUbistva]++;
  94.     PlayerInfo[playerid][pUmrenost]++;
  95.     return 1;
  96. }
  97.  
  98. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  99. {
  100.    switch( dialogid )
  101.    {
  102.        case DIALOG_REGISTER:
  103.        {
  104.            if (!response) return Kick(playerid);
  105.            if(response)
  106.            {
  107.                if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, ""COL_WHITE"Registering...",""COL_RED"You have entered an invalid password.\n"COL_WHITE"Type your password below to register a new account.","Register","Quit");
  108.                new INI:File = INI_Open(UserPath(playerid));
  109.                INI_SetTag(File,"data");
  110.                INI_WriteInt(File,"Lozinka",udb_hash(inputtext));
  111.                INI_WriteInt(File,"Pari",0);
  112.                INI_WriteInt(File,"Admin",0);
  113.                INI_WriteInt(File,Ubistva",0);
  114.                 INI_WriteInt(File,"Umrenost",0);
  115.                 INI_Close(File);
  116.  
  117.                 SetSpawnInfo(playerid, 0, 0, 1958.33, 1343.12, 15.36, 269.15, 0, 0, 0, 0, 0, 0);
  118.                 SpawnPlayer(playerid);
  119.                 ShowPlayerDialog(playerid, DIALOG_SUCCESS_1, DIALOG_STYLE_MSGBOX,""COL_WHITE"Success!",""COL_GREEN"Uspesno se registriravte!","Ok","");
  120.             }
  121.         }
  122.  
  123.         case DIALOG_LOGIN:
  124.         {
  125.             if ( !response ) return Kick ( playerid );
  126.             if( response )
  127.             {
  128.                 if(udb_hash(inputtext) == PlayerInfo[playerid][pPass])
  129.                 {
  130.                     INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
  131.                     GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
  132.                     ShowPlayerDialog(playerid, DIALOG_SUCCESS_2, DIALOG_STYLE_MSGBOX,""COL_WHITE"Login!",""COL_GREEN"Uspesno se logiravte!","Ok","");
  133.                 }
  134.                 else
  135.                 {
  136.                     ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,""COL_WHITE"Login",""COL_RED"Vnesovte pogresna lozinka.\n"COL_WHITE"Napisete ja vasata lozinka.","Login","Izlezi");
  137.                 }
  138.                 return 1;
  139.             }
  140.         }
  141.     }
  142.     return 1;
  143. }
  144.  
Advertisement
RAW Paste Data Copied
Advertisement