Advertisement
Guest User

Joe Torran C

a guest
Jun 20th, 2010
1,287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 15.31 KB | None | 0 0
  1. // [FS] torran's Registration System v3
  2. // Made by Joe Torran C
  3. // DO NOT REMOVE THESE CREDITS
  4.  
  5. #include <a_samp>
  6. #include <dini>
  7. #include <dudb>
  8. #include <zcmd>
  9.  
  10. #define SCRIPT_VERSION          "v3"
  11.  
  12. #define colorRed                0xFF0000FF
  13. #define colorGreen              0x008000FF
  14.  
  15. #define DIALOG_REGISTER         1
  16. #define DIALOG_LOGIN            2
  17. #define DIALOG_ACCOUNT          3
  18. #define DIALOG_CHANGEPASS       4
  19. #define DIALOG_CHANGENAME       5
  20. #define DIALOG_VIEWSTATS        6
  21. #define DIALOG_CHECKSTATS       7
  22.  
  23. #pragma unused                  ret_memcpy
  24. #pragma unused                  strtok
  25.  
  26. forward UpdateTime(playerid);
  27.  
  28. new str[128];
  29. new file[128];
  30. new playerIP[16];
  31.  
  32. new Update;
  33.  
  34. public OnPlayerConnect(playerid)
  35. {
  36.     format(file, 128, "/tReg/%s.ini", GetName(playerid));
  37.  
  38.     GetPlayerIp(playerid, playerIP, 16);
  39.    
  40.     TogglePlayerSpectating(playerid, 1);
  41.  
  42.     if(!dini_Exists(file))
  43.     {
  44.         format(str, 128, "Welcome %s \n\nPlease register your account", GetName(playerid));
  45.         ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Account Management", str, "Register", "Quit");
  46.     }
  47.     if(dini_Exists(file))
  48.     {
  49.         if(strcmp(playerIP, dini_Get(file, "IP"), true) == 0)
  50.         {
  51.             dini_Set(file, "IP", playerIP);
  52.  
  53.             SetPVarInt(playerid, "Logged", 1);
  54.  
  55.             SetPlayerCash(playerid, dini_Int(file, "Money"));
  56.             SetPlayerScore(playerid, dini_Int(file, "Score"));
  57.             SetPVarInt(playerid, "Kills", dini_Int(file, "Kills"));
  58.             SetPVarInt(playerid, "Deaths", dini_Int(file, "Deaths"));
  59.             SetPVarInt(playerid, "Time", dini_Int(file, "Minutes Ingame"));
  60.  
  61.             Update = SetTimerEx("UpdateTime", 60*1000, 1, "i", playerid);
  62.  
  63.             SendClientMessage(playerid, colorGreen, "You have been automatically logged in.");
  64.         }
  65.         else
  66.         {
  67.             format(str, 128, "Welcome %s \n\nPlease login to your account", GetName(playerid));
  68.             ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Account Management", str, "Login", "Quit");
  69.         }
  70.     }
  71.     return 1;
  72. }
  73.  
  74. public OnPlayerDisconnect(playerid, reason)
  75. {
  76.     format(file, 128, "/tReg/%s.ini", GetName(playerid));
  77.  
  78.     if(GetPVarInt(playerid, "Logged") == 1)
  79.     {
  80.         dini_IntSet(file, "Money", GetPlayerMoney(playerid));
  81.         dini_IntSet(file, "Score", GetPlayerScore(playerid));
  82.         dini_IntSet(file, "Kills", GetPVarInt(playerid, "Kills"));
  83.         dini_IntSet(file, "Deaths", GetPVarInt(playerid, "Deaths"));
  84.         dini_IntSet(file, "Minutes Ingame", GetPVarInt(playerid, "Time"));
  85.  
  86.         KillTimer(Update);
  87.     }
  88.     return 1;
  89. }
  90.  
  91. public OnFilterScriptInit()
  92. {
  93.     printf("\n  [FS] torran's Registration System %s \n", SCRIPT_VERSION);
  94.     return 1;
  95. }
  96.  
  97. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  98. {
  99.     format(file, 128, "/tReg/%s.ini", GetName(playerid));
  100.  
  101.     if(dialogid == DIALOG_REGISTER)
  102.     {
  103.         if(!response) return Kick(playerid);
  104.         if(response)
  105.         {
  106.             if(strlen(inputtext) == 0)
  107.             {
  108.                 format(str, 128, "Welcome %s \n\nPlease register your account", GetName(playerid));
  109.                 ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Account Management", str, "Register", "Quit");
  110.                 return 0;
  111.             }
  112.             if(!dini_Exists(file))
  113.             {
  114.                 dini_Create(file);
  115.                 dini_IntSet(file, "Password", udb_hash(inputtext));
  116.                 dini_IntSet(file, "Money", GetPlayerMoney(playerid));
  117.                 dini_IntSet(file, "Score", GetPlayerScore(playerid));
  118.                 dini_IntSet(file, "Kills", GetPVarInt(playerid, "Kills"));
  119.                 dini_IntSet(file, "Deaths", GetPVarInt(playerid, "Deaths"));
  120.                 dini_IntSet(file, "Minutes Ingame", GetPVarInt(playerid, "Time"));
  121.  
  122.                 format(str, 128, "Account successfully Registered \n\n\nWelcome %s \n\nPlease login to your account", GetName(playerid));
  123.                 ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Account Management", str, "Login", "Quit");
  124.             }
  125.         }
  126.     }
  127.     if(dialogid == DIALOG_LOGIN)
  128.     {
  129.         if(!response) return Kick(playerid);
  130.         if(response)
  131.         {
  132.             if(strlen(inputtext) == 0)
  133.             {
  134.                 format(str, 128, "Welcome %s \n\nPlease login to your account", GetName(playerid));
  135.                 ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Account Management", str, "Login", "Quit");
  136.                 return 0;
  137.             }
  138.             if(fexist(file))
  139.             {
  140.                 new password = dini_Int(file, "Password");
  141.                 if(udb_hash(inputtext) != password)
  142.                 {
  143.                     if(GetPVarInt(playerid, "Attempts") == 0)
  144.                     {
  145.                         SetPVarInt(playerid, "Attempts", 1);
  146.                         SendClientMessage(playerid, colorRed, "Incorrect password, You have 1 more attempt");
  147.  
  148.                         format(str, 128, "Welcome %s \n\nPlease login to your account", GetName(playerid));
  149.                         ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Account Management", str, "Login", "Quit");
  150.                     }
  151.                     else if(GetPVarInt(playerid, "Attempts") == 1)
  152.                     {
  153.                         SendClientMessage(playerid, colorRed, "Incorrect password, You do not have any attempts left");
  154.                         Kick(playerid);
  155.                     }
  156.                 }
  157.                 else
  158.                 {
  159.                     SetPVarInt(playerid, "Logged", 1);
  160.  
  161.                     SetPlayerCash(playerid, dini_Int(file, "Money"));
  162.                     SetPlayerScore(playerid, dini_Int(file, "Score"));
  163.                     SetPVarInt(playerid, "Kills", dini_Int(file, "Kills"));
  164.                     SetPVarInt(playerid, "Deaths", dini_Int(file, "Deaths"));
  165.                     SetPVarInt(playerid, "Time", dini_Int(file, "Minutes Ingame"));
  166.  
  167.                     GetPlayerIp(playerid, playerIP, 16);
  168.                     dini_Set(file, "IP", playerIP);
  169.  
  170.                     Update = SetTimerEx("UpdateTime", 60*1000, 1, "i", playerid);
  171.  
  172.                     TogglePlayerSpectating(playerid, 0);
  173.  
  174.                     SendClientMessage(playerid, colorGreen, "You have successfully logged in.");
  175.                 }
  176.             }
  177.         }
  178.     }
  179.     if(dialogid == DIALOG_CHANGEPASS)
  180.     {
  181.         if(response)
  182.         {
  183.             if(GetPVarInt(playerid, "PassStage") == 1)
  184.             {
  185.                 new password = dini_Int(file, "Password");
  186.                 if(udb_hash(inputtext) == password)
  187.                 {
  188.                     SetPVarInt(playerid, "PassStage", 2);
  189.                     ShowPlayerDialog(playerid, DIALOG_CHANGEPASS, DIALOG_STYLE_INPUT, "Account Management", "Please input your new password", "Change Pass", "Cancel");
  190.                 }
  191.                 else
  192.                 {
  193.                     SendClientMessage(playerid, colorRed, "Incorrect password.");
  194.                 }
  195.             }
  196.             else if(GetPVarInt(playerid, "PassStage") == 2)
  197.             {
  198.                 if(GetPVarInt(playerid, "Logged") == 1)
  199.                 {
  200.                     dini_IntSet(file, "Password", udb_hash(inputtext));
  201.                     SendClientMessage(playerid, colorGreen, "Password successfully changed.");
  202.                 }
  203.             }
  204.         }
  205.     }
  206.     if(dialogid == DIALOG_CHANGENAME)
  207.     {
  208.         if(response)
  209.         {
  210.             if(GetPVarInt(playerid, "NameStage") == 1)
  211.             {
  212.                 new password = dini_Int(file, "Password");
  213.                 if(udb_hash(inputtext) == password)
  214.                 {
  215.                     SetPVarInt(playerid, "NameStage", 2);
  216.                     ShowPlayerDialog(playerid, DIALOG_CHANGENAME, DIALOG_STYLE_INPUT, "Account Management", "Please input your new name", "Change", "Cancel");
  217.                 }
  218.                 else
  219.                 {
  220.                     SendClientMessage(playerid, colorRed, "Incorrect password.");
  221.                 }
  222.             }
  223.             else if(GetPVarInt(playerid, "NameStage") == 2)
  224.             {
  225.                 format(file, 128, "/tReg/%s.ini", inputtext);
  226.                 if(dini_Exists(file))
  227.                 {
  228.                     SetPVarInt(playerid, "NameStage", 2);
  229.                     ShowPlayerDialog(playerid, DIALOG_CHANGENAME, DIALOG_STYLE_INPUT, "Account Management", "A user has already registered with this name \nIf this is you please reconnect using that account\n\nElse please enter your new name", "Change", "Cancel");
  230.                 }
  231.                 else
  232.                 {
  233.                     format(file, 128, "/tReg/%s.ini", GetName(playerid)); dini_Remove(file);
  234.                     format(file, 128, "/tReg/%s.ini", inputtext); dini_Create(file);
  235.                     dini_IntSet(file, "Password", udb_hash(inputtext));
  236.                     dini_IntSet(file, "Money", GetPlayerMoney(playerid));
  237.                     dini_IntSet(file, "Score", GetPlayerScore(playerid));
  238.                     dini_IntSet(file, "Kills", GetPVarInt(playerid, "Kills"));
  239.                     dini_IntSet(file, "Deaths", GetPVarInt(playerid, "Deaths"));
  240.                     dini_IntSet(file, "Minutes Ingame", GetPVarInt(playerid, "Time"));
  241.                    
  242.                     SetPlayerName(playerid, inputtext);
  243.                    
  244.                     SendClientMessage(playerid, colorGreen, "Name successfully changed.");
  245.                 }
  246.             }
  247.         }
  248.     }
  249.     return 0;
  250. }
  251.  
  252. public UpdateTime(playerid)
  253. {
  254.     format(file, 128, "/tReg/%s.ini", GetName(playerid));
  255.  
  256.     SetPVarInt(playerid, "Time", GetPVarInt(playerid, "Time")+1);
  257.     return 1;
  258. }
  259.  
  260. CMD:changepass(playerid, params[])
  261. {
  262.     if(GetPVarInt(playerid, "Logged") == 1)
  263.     {
  264.         SetPVarInt(playerid, "PassStage", 1);
  265.         ShowPlayerDialog(playerid, DIALOG_CHANGEPASS, DIALOG_STYLE_INPUT, "Account Management", "Please input your current password for verification", "Continue", "Cancel");
  266.     }
  267.     return 1;
  268. }
  269.  
  270. CMD:changename(playerid, params[])
  271. {
  272.     if(GetPVarInt(playerid, "Logged") == 1)
  273.     {
  274.         SetPVarInt(playerid, "NameStage", 1);
  275.         ShowPlayerDialog(playerid, DIALOG_CHANGENAME, DIALOG_STYLE_INPUT, "Account Management", "Please input your password for verification", "Continue", "Cancel");
  276.     }
  277.     return 1;
  278. }
  279.  
  280. CMD:viewstats(playerid, params[])
  281. {
  282.     if(GetPVarInt(playerid, "Logged") == 1)
  283.     {
  284.         new Float:health; GetPlayerHealth(playerid, health);
  285.         new Float:armour; GetPlayerArmour(playerid, armour);
  286.        
  287.         format(str, 128, "Name: %s\nHealth: %0.00f\nArmour: %0.00f\nMoney: %i\nScore: %i\nKills: %i\nDeaths: %i", GetName(playerid), health, armour, GetPlayerMoney(playerid), GetPlayerScore(playerid), GetPVarInt(playerid, "Kills"), GetPVarInt(playerid, "Deaths"));
  288.         ShowPlayerDialog(playerid, DIALOG_VIEWSTATS, DIALOG_STYLE_MSGBOX, "Account Management", str, "Ok", "Cancel");
  289.     }
  290.     return 1;
  291. }
  292.  
  293. CMD:checkstats(playerid, params[])
  294. {
  295.     new targetid;
  296.     if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, colorRed, "You need to be an RCON Admin to use this command.");
  297.     if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, colorRed, "Usage: /checkstats [PlayerID/PartOfName]");
  298.     if(targetid == playerid) return SendClientMessage(playerid, colorRed, "You are trying to view the stats of you, To do this type: /viewstats");
  299.     if(targetid == INVALID_PLAYER_ID) return SendClientMessage(playerid, colorRed, "Player not Found");
  300.    
  301.     if(GetPVarInt(playerid, "Logged") == 1)
  302.     {
  303.         new Float:health; GetPlayerHealth(targetid, health);
  304.         new Float:armour; GetPlayerArmour(targetid, armour);
  305.  
  306.         format(str, 128, "Name: %s\nHealth: %0.00f\nArmour: %0.00f\nMoney: %i\nScore: %i\nKills: %i\nDeaths: %i", GetName(targetid), health, armour, GetPlayerMoney(targetid), GetPlayerScore(targetid), GetPVarInt(targetid, "Kills"), GetPVarInt(targetid, "Deaths"));
  307.         ShowPlayerDialog(playerid, DIALOG_VIEWSTATS, DIALOG_STYLE_MSGBOX, "Account Management", str, "Ok", "Cancel");
  308.     }
  309.     return 1;
  310. }
  311.  
  312. stock GetName(playerid)
  313. {
  314.     new name[MAX_PLAYER_NAME];
  315.     GetPlayerName(playerid, name, sizeof name);
  316.     return name;
  317. }
  318.  
  319. stock SetPlayerCash(playerid, amount)
  320. {
  321.     ResetPlayerMoney(playerid);
  322.     return GivePlayerMoney(playerid, amount);
  323. }
  324.  
  325. stock sscanf(string[], format[], {Float,_}:...)
  326. {
  327.     #if defined isnull
  328.         if (isnull(string))
  329.     #else
  330.         if (string[0] == 0 || (string[0] == 1 && string[1] == 0))
  331.     #endif
  332.         {
  333.             return format[0];
  334.         }
  335.     #pragma tabsize 4
  336.     new
  337.         formatPos = 0,
  338.         stringPos = 0,
  339.         paramPos = 2,
  340.         paramCount = numargs(),
  341.         delim = ' ';
  342.     while (string[stringPos] && string[stringPos] <= ' ')
  343.     {
  344.         stringPos++;
  345.     }
  346.     while (paramPos < paramCount && string[stringPos])
  347.     {
  348.         switch (format[formatPos++])
  349.         {
  350.             case '\0':
  351.             {
  352.                 return 0;
  353.             }
  354.             case 'i', 'd':
  355.             {
  356.                 new
  357.                     neg = 1,
  358.                     num = 0,
  359.                     ch = string[stringPos];
  360.                 if (ch == '-')
  361.                 {
  362.                     neg = -1;
  363.                     ch = string[++stringPos];
  364.                 }
  365.                 do
  366.                 {
  367.                     stringPos++;
  368.                     if ('0' <= ch <= '9')
  369.                     {
  370.                         num = (num * 10) + (ch - '0');
  371.                     }
  372.                     else
  373.                     {
  374.                         return -1;
  375.                     }
  376.                 }
  377.                 while ((ch = string[stringPos]) > ' ' && ch != delim);
  378.                 setarg(paramPos, 0, num * neg);
  379.             }
  380.             case 'h', 'x':
  381.             {
  382.                 new
  383.                     num = 0,
  384.                     ch = string[stringPos];
  385.                 do
  386.                 {
  387.                     stringPos++;
  388.                     switch (ch)
  389.                     {
  390.                         case 'x', 'X':
  391.                         {
  392.                             num = 0;
  393.                             continue;
  394.                         }
  395.                         case '0' .. '9':
  396.                         {
  397.                             num = (num << 4) | (ch - '0');
  398.                         }
  399.                         case 'a' .. 'f':
  400.                         {
  401.                             num = (num << 4) | (ch - ('a' - 10));
  402.                         }
  403.                         case 'A' .. 'F':
  404.                         {
  405.                             num = (num << 4) | (ch - ('A' - 10));
  406.                         }
  407.                         default:
  408.                         {
  409.                             return -1;
  410.                         }
  411.                     }
  412.                 }
  413.                 while ((ch = string[stringPos]) > ' ' && ch != delim);
  414.                 setarg(paramPos, 0, num);
  415.             }
  416.             case 'c':
  417.             {
  418.                 setarg(paramPos, 0, string[stringPos++]);
  419.             }
  420.             case 'f':
  421.             {
  422.  
  423.                 new changestr[16], changepos = 0, strpos = stringPos;
  424.                 while(changepos < 16 && string[strpos] && string[strpos] != delim)
  425.                 {
  426.                     changestr[changepos++] = string[strpos++];
  427.                     }
  428.                 changestr[changepos] = '\0';
  429.                 setarg(paramPos,0,_:floatstr(changestr));
  430.             }
  431.             case 'p':
  432.             {
  433.                 delim = format[formatPos++];
  434.                 continue;
  435.             }
  436.             case '\'':
  437.             {
  438.                 new
  439.                     end = formatPos - 1,
  440.                     ch;
  441.                 while ((ch = format[++end]) && ch != '\'') {}
  442.                 if (!ch)
  443.                 {
  444.                     return -1;
  445.                 }
  446.                 format[end] = '\0';
  447.                 if ((ch = strfind(string, format[formatPos], false, stringPos)) == -1)
  448.                 {
  449.                     if (format[end + 1])
  450.                     {
  451.                         return -1;
  452.                     }
  453.                     return 0;
  454.                 }
  455.                 format[end] = '\'';
  456.                 stringPos = ch + (end - formatPos);
  457.                 formatPos = end + 1;
  458.             }
  459.             case 'u':
  460.             {
  461.                 new
  462.                     end = stringPos - 1,
  463.                     id = 0,
  464.                     bool:num = true,
  465.                     ch;
  466.                 while ((ch = string[++end]) && ch != delim)
  467.                 {
  468.                     if (num)
  469.                     {
  470.                         if ('0' <= ch <= '9')
  471.                         {
  472.                             id = (id * 10) + (ch - '0');
  473.                         }
  474.                         else
  475.                         {
  476.                             num = false;
  477.                         }
  478.                     }
  479.                 }
  480.                 if (num && IsPlayerConnected(id))
  481.                 {
  482.                     setarg(paramPos, 0, id);
  483.                 }
  484.                 else
  485.                 {
  486.                     #if !defined foreach
  487.                         #define foreach(%1,%2) for (new %2 = 0; %2 < MAX_PLAYERS; %2++) if (IsPlayerConnected(%2))
  488.                         #define __SSCANF_FOREACH__
  489.                     #endif
  490.                     string[end] = '\0';
  491.                     num = false;
  492.                     new
  493.                         name[MAX_PLAYER_NAME];
  494.                     id = end - stringPos;
  495.                     foreach (Player, playerid)
  496.                     {
  497.                         GetPlayerName(playerid, name, sizeof (name));
  498.                         if (!strcmp(name, string[stringPos], true, id))
  499.                         {
  500.                             setarg(paramPos, 0, playerid);
  501.                             num = true;
  502.                             break;
  503.                         }
  504.                     }
  505.                     if (!num)
  506.                     {
  507.                         setarg(paramPos, 0, INVALID_PLAYER_ID);
  508.                     }
  509.                     string[end] = ch;
  510.                     #if defined __SSCANF_FOREACH__
  511.                         #undef foreach
  512.                         #undef __SSCANF_FOREACH__
  513.                     #endif
  514.                 }
  515.                 stringPos = end;
  516.             }
  517.             case 's', 'z':
  518.             {
  519.                 new
  520.                     i = 0,
  521.                     ch;
  522.                 if (format[formatPos])
  523.                 {
  524.                     while ((ch = string[stringPos++]) && ch != delim)
  525.                     {
  526.                         setarg(paramPos, i++, ch);
  527.                     }
  528.                     if (!i)
  529.                     {
  530.                         return -1;
  531.                     }
  532.                 }
  533.                 else
  534.                 {
  535.                     while ((ch = string[stringPos++]))
  536.                     {
  537.                         setarg(paramPos, i++, ch);
  538.                     }
  539.                 }
  540.                 stringPos--;
  541.                 setarg(paramPos, i, '\0');
  542.             }
  543.             default:
  544.             {
  545.                 continue;
  546.             }
  547.         }
  548.         while (string[stringPos] && string[stringPos] != delim && string[stringPos] > ' ')
  549.         {
  550.             stringPos++;
  551.         }
  552.         while (string[stringPos] && (string[stringPos] == delim || string[stringPos] <= ' '))
  553.         {
  554.             stringPos++;
  555.         }
  556.         paramPos++;
  557.     }
  558.     do
  559.     {
  560.         if ((delim = format[formatPos++]) > ' ')
  561.         {
  562.             if (delim == '\'')
  563.             {
  564.                 while ((delim = format[formatPos++]) && delim != '\'') {}
  565.             }
  566.             else if (delim != 'z')
  567.             {
  568.                 return delim;
  569.             }
  570.         }
  571.     }
  572.     while (delim > ' ');
  573.     return 0;
  574. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement