Guest User

Register/Login Sys

a guest
Dec 7th, 2011
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.34 KB | None | 0 0
  1. /*
  2. :::::::::::::::::::::::::::::::::::::::::::::::::
  3. ::
  4. ::              Register/Login
  5. ::                 System
  6. ::
  7. ::
  8. :::::::::::::::::::::::::::::::::::::::::::::::::
  9. */
  10.  
  11.  
  12. #include <a_samp>
  13. #include <dini>
  14.  
  15.  
  16. #define DIALOG_REGISTER 1
  17. #define DIALOG_LOGIN 2
  18.  
  19.  
  20. public OnPlayerConnect(playerid)
  21. {
  22.     new data[64];
  23.     new name[MAX_PLAYER_NAME];
  24.     GetPlayerName(playerid, name, sizeof(name));
  25.     format(data, sizeof(data), "/Accounts/%s.txt", name);
  26.     if(dini_Exists(data))
  27.     {
  28.         ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login", "Please login by typing you password below.", "Login", "Cancel");
  29.         SetPlayerScore(playerid, dini_Int(data, "Score"));
  30.         return 1;
  31.     }
  32.     ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Register", "Please register by typing you password below.", "Register", "Cancel");
  33.     return 1;
  34. }
  35.  
  36. public OnPlayerDisconnect(playerid, reason)
  37. {
  38.     new data[64];
  39.     new name[MAX_PLAYER_NAME];
  40.     GetPlayerName(playerid, name, sizeof(name));
  41.     format(data, sizeof(data), "/Accounts/%s.txt", name);
  42.     if(dini_Exists(data))
  43.     {
  44.     dini_IntSet(data, "Score", GetPlayerScore(playerid));
  45.     }
  46.     else
  47.     {
  48.     dini_Create(data);
  49.     dini_IntSet(data, "Score", GetPlayerScore(playerid));
  50.     }
  51.  
  52.     return 1;
  53. }
  54.  
  55. public OnDialogResponse(playerid, dialogid, response, listitem,inputtext[])
  56. {
  57.     if(dialogid == DIALOG_LOGIN)
  58.     {
  59.         if(response == 0)
  60.         {
  61.             SendClientMessage(playerid,0xFFFFFFFF, "You choosed to not login!");
  62.             Kick(playerid);
  63.             return 1;
  64.         }
  65.         if(response == 1)
  66.         {
  67.             if(!strlen(inputtext))
  68.             {
  69.             SendClientMessage(playerid,0xFFFFFFFF, "You havent filled in a password!");
  70.             ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login", "Please login by typing you password below.", "Login", "Cancel");
  71.             return 1;
  72.             }
  73.             Login(playerid, inputtext);
  74.             return 1;
  75.         }
  76.     }
  77.     if(dialogid == DIALOG_REGISTER)
  78.     {
  79.         if(response == 0)
  80.         {
  81.             SendClientMessage(playerid,0xFFFFFFFF, "You choosed to not register!");
  82.             Kick(playerid);
  83.             return 1;
  84.         }
  85.         if(response == 1)
  86.         {
  87.             if(!strlen(inputtext))
  88.             {
  89.             SendClientMessage(playerid,0xFFFFFFFF, "You havent filled in a password!");
  90.             ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Register", "Please register by typing you password below.", "Register", "Cancel");
  91.             return 1;
  92.             }
  93.             Register(playerid, inputtext);
  94.             return 1;
  95.         }
  96.     }
  97.     return 1;
  98. }
  99.  
  100. stock Register(playerid,key[])
  101. {
  102.     new data[64];
  103.     new name[MAX_PLAYER_NAME];
  104.     GetPlayerName(playerid, name, sizeof(name));
  105.     format(data, sizeof(data), "/Accounts/%s.txt", name);
  106.     dini_Create(data);
  107.     dini_Set(data, "Password", key);
  108.     SendClientMessage(playerid,0xFFFFFFFF, "Account Registered!");
  109.     dini_IntSet(data, "Score",0);
  110.     return 1;
  111. }
  112.  
  113. stock Login(playerid,key[])
  114. {
  115.     new data[64];
  116.     new name[MAX_PLAYER_NAME];
  117.     GetPlayerName(playerid, name, sizeof(name));
  118.     format(data, sizeof(data), "/Accounts/#s.txt", name);
  119.    
  120.     if(!strcmp(key,dini_Get(data,"Password"),false))
  121.     {
  122.          SetPlayerScore(playerid, dini_Int(data, "Score"));
  123.          SendClientMessage(playerid,0xFFFFFFFF, "Login Successful!");
  124.          return 1;
  125.     }
  126.     else
  127.     {
  128.         SendClientMessage(playerid,0xFF0000FF, "Wrong Password!");
  129.         ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login", "Please login by typing you password below.", "Login", "Cancel");
  130.         return 1;
  131.     }
  132. }
  133.  
Advertisement
Add Comment
Please, Sign In to add comment