Advertisement
Guest User

Untitled

a guest
Aug 12th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 10.33 KB | None | 0 0
  1. #include <a_samp>
  2. #include <mysql>
  3.  
  4. #define DIALOG_LOGIN      100
  5. #define DIALOG_REGISTER   101
  6. #define SERVERNAME        "Server"
  7. //=====Colors====
  8. #define cGREEN           0x33AA33AA
  9. #define cRED             0xAA3333AA
  10. #define cYELLOW          0xFFFF00AA
  11. #define cLIGHTBLUE       0x33CCFFAA
  12. #define cORANGE          0xFF9900AA
  13.  
  14. enum pInfo
  15. {
  16.     Id,
  17.     username[25],
  18.     Password[50],
  19.     CallSign[8],
  20.     Admin,
  21.     VIP,
  22.     Money,
  23.     Score,
  24.     Banned,
  25.     Reason[100],
  26.     PlayerIP[20],
  27.     LoggedIn
  28. }
  29.  
  30.  
  31. new PlayerInfo[MAX_PLAYERS][pInfo];
  32.  
  33. public OnPlayerConnect(playerid)
  34. {
  35. if(CheckUser(playerid))
  36. {
  37.     ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, SERVERNAME, "Please enter your password to login", "Login", "Cancel");
  38. }
  39.  
  40.  
  41. else
  42. {
  43.     ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, SERVERNAME, "Please enter a password to register", "Register", "Cancel");
  44. }
  45. }
  46.  
  47. //========Dialogs=======
  48.  
  49. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  50. {
  51.     if(dialogid == DIALOG_LOGIN)
  52.     {
  53.             if(CheckUserLogin(playerid,inputtext))
  54.             {
  55.             LoginUser(playerid)
  56.             }
  57.             else
  58.             {
  59.             Kick(playerid);
  60.             }
  61.     }
  62.     return 0;
  63. }
  64.  
  65. //======= Stocks========
  66. stock GetName(playerid)
  67. {
  68.     new pName[MAX_PLAYER_NAME];
  69.     GetPlayerName(playerid, pName, sizeof(pName));
  70.     return pName;
  71. }
  72.  
  73. stock CheckUser(playerid)
  74. {
  75.     new Query[200]; format(Query, sizeof(Query), "SELECT * FROM users WHERE username = '%s';",GetName(playerid));
  76.     mysql_query(Query);
  77.     mysql_store_result();
  78.     if(mysql_num_rows()) return 1;
  79.     return 0;
  80. }
  81.  
  82. stock LoginUser(playerid)
  83. {
  84.     new Query[200]; format(Query, sizeof(Query), "SELECT * FROM users WHERE username = '%s';",GetName(playerid));
  85.     mysql_query(Query);
  86.     mysql_store_result();
  87.     if(mysql_fetch_row(Query,"|")) {
  88.         sscanf(Query, "p<|>e<is[25]s[50]s[8]iiiiiiiiiiiiis[100]iii>", PlayerInfo[playerid]);
  89.     }
  90.     PlayerInfo[playerid][LoggedIn] = 1;
  91.     GivePlayerMoney(playerid, PlayerInfo[playerid][Money]);
  92.     SetPlayerScore(playerid, PlayerInfo[playerid][Score]);
  93.     SendClientMessage(playerid, cGREEN, "Successfully logged in.");
  94.     GetPlayerIp(playerid, PlayerInfo[playerid][PlayerIP], 20);
  95.  
  96.     SaveUser(playerid);
  97.     SaveTimer[playerid] = SetTimerEx("SaveUser", 60 * 1000 * 5, true, "i", playerid);
  98. }
  99.  
  100. stock CheckUserLogin(playerid, password[])
  101. {
  102.     new Query[200]; format(Query, sizeof(Query), "SELECT * FROM users WHERE username = '%s' AND password = MD5('%s');",GetName(playerid), password);
  103.     mysql_query(Query);
  104.     mysql_store_result();
  105.     if(mysql_num_rows()) return 1;
  106.     return 0;
  107. }
  108.  
  109. //=======sscanf=======
  110. stock sscanf(string[], format[], {Float,_}:...)
  111. {
  112.     #if defined isnull
  113.         if (isnull(string))
  114.     #else
  115.         if (string[0] == 0 || (string[0] == 1 && string[1] == 0))
  116.     #endif
  117.         {
  118.             return format[0];
  119.         }
  120.     #pragma tabsize 4
  121.     new
  122.         formatPos = 0,
  123.         stringPos = 0,
  124.         paramPos = 2,
  125.         paramCount = numargs(),
  126.         delim = ' ';
  127.     while (string[stringPos] && string[stringPos] <= ' ')
  128.     {
  129.         stringPos++;
  130.     }
  131.     while (paramPos < paramCount && string[stringPos])
  132.     {
  133.         switch (format[formatPos++])
  134.         {
  135.             case '\0':
  136.             {
  137.                 return 0;
  138.             }
  139.             case 'i', 'd':
  140.             {
  141.                 new
  142.                     neg = 1,
  143.                     num = 0,
  144.                     ch = string[stringPos];
  145.                 if (ch == '-')
  146.                 {
  147.                     neg = -1;
  148.                     ch = string[++stringPos];
  149.                 }
  150.                 do
  151.                 {
  152.                     stringPos++;
  153.                     if ('0' <= ch <= '9')
  154.                     {
  155.                         num = (num * 10) + (ch - '0');
  156.                     }
  157.                     else
  158.                     {
  159.                         return -1;
  160.                     }
  161.                 }
  162.                 while ((ch = string[stringPos]) > ' ' && ch != delim);
  163.                 setarg(paramPos, 0, num * neg);
  164.             }
  165.             case 'h', 'x':
  166.             {
  167.                 new
  168.                     num = 0,
  169.                     ch = string[stringPos];
  170.                 do
  171.                 {
  172.                     stringPos++;
  173.                     switch (ch)
  174.                     {
  175.                         case 'x', 'X':
  176.                         {
  177.                             num = 0;
  178.                             continue;
  179.                         }
  180.                         case '0' .. '9':
  181.                         {
  182.                             num = (num << 4) | (ch - '0');
  183.                         }
  184.                         case 'a' .. 'f':
  185.                         {
  186.                             num = (num << 4) | (ch - ('a' - 10));
  187.                         }
  188.                         case 'A' .. 'F':
  189.                         {
  190.                             num = (num << 4) | (ch - ('A' - 10));
  191.                         }
  192.                         default:
  193.                         {
  194.                             return -1;
  195.                         }
  196.                     }
  197.                 }
  198.                 while ((ch = string[stringPos]) > ' ' && ch != delim);
  199.                 setarg(paramPos, 0, num);
  200.             }
  201.             case 'c':
  202.             {
  203.                 setarg(paramPos, 0, string[stringPos++]);
  204.             }
  205.             case 'f':
  206.             {
  207.  
  208.                 new changestr[16], changepos = 0, strpos = stringPos;
  209.                 while(changepos < 16 && string[strpos] && string[strpos] != delim)
  210.                 {
  211.                     changestr[changepos++] = string[strpos++];
  212.                     }
  213.                 changestr[changepos] = '\0';
  214.                 setarg(paramPos,0,_:floatstr(changestr));
  215.             }
  216.             case 'p':
  217.             {
  218.                 delim = format[formatPos++];
  219.                 continue;
  220.             }
  221.             case '\'':
  222.             {
  223.                 new
  224.                     end = formatPos - 1,
  225.                     ch;
  226.                 while ((ch = format[++end]) && ch != '\'') {}
  227.                 if (!ch)
  228.                 {
  229.                     return -1;
  230.                 }
  231.                 format[end] = '\0';
  232.                 if ((ch = strfind(string, format[formatPos], false, stringPos)) == -1)
  233.                 {
  234.                     if (format[end + 1])
  235.                     {
  236.                         return -1;
  237.                     }
  238.                     return 0;
  239.                 }
  240.                 format[end] = '\'';
  241.                 stringPos = ch + (end - formatPos);
  242.                 formatPos = end + 1;
  243.             }
  244.             case 'u':
  245.             {
  246.                 new
  247.                     end = stringPos - 1,
  248.                     id = 0,
  249.                     bool:num = true,
  250.                     ch;
  251.                 while ((ch = string[++end]) && ch != delim)
  252.                 {
  253.                     if (num)
  254.                     {
  255.                         if ('0' <= ch <= '9')
  256.                         {
  257.                             id = (id * 10) + (ch - '0');
  258.                         }
  259.                         else
  260.                         {
  261.                             num = false;
  262.                         }
  263.                     }
  264.                 }
  265.                 if (num && IsPlayerConnected(id))
  266.                 {
  267.                     setarg(paramPos, 0, id);
  268.                 }
  269.                 else
  270.                 {
  271.                     #if !defined foreach
  272.                         #define foreach(%1,%2) for (new %2 = 0; %2 < MAX_PLAYERS; %2++) if (IsPlayerConnected(%2))
  273.                         #define __SSCANF_FOREACH__
  274.                     #endif
  275.                     string[end] = '\0';
  276.                     num = false;
  277.                     new
  278.                         name[MAX_PLAYER_NAME];
  279.                     id = end - stringPos;
  280.                     foreach (Player, playerid)
  281.                     {
  282.                         GetPlayerName(playerid, name, sizeof (name));
  283.                         if (!strcmp(name, string[stringPos], true, id))
  284.                         {
  285.                             setarg(paramPos, 0, playerid);
  286.                             num = true;
  287.                             break;
  288.                         }
  289.                     }
  290.                     if (!num)
  291.                     {
  292.                         setarg(paramPos, 0, INVALID_PLAYER_ID);
  293.                     }
  294.                     string[end] = ch;
  295.                     #if defined __SSCANF_FOREACH__
  296.                         #undef foreach
  297.                         #undef __SSCANF_FOREACH__
  298.                     #endif
  299.                 }
  300.                 stringPos = end;
  301.             }
  302.             case 's', 'z':
  303.             {
  304.                 new
  305.                     i = 0,
  306.                     ch;
  307.                 if (format[formatPos])
  308.                 {
  309.                     while ((ch = string[stringPos++]) && ch != delim)
  310.                     {
  311.                         setarg(paramPos, i++, ch);
  312.                     }
  313.                     if (!i)
  314.                     {
  315.                         return -1;
  316.                     }
  317.                 }
  318.                 else
  319.                 {
  320.                     while ((ch = string[stringPos++]))
  321.                     {
  322.                         setarg(paramPos, i++, ch);
  323.                     }
  324.                 }
  325.                 stringPos--;
  326.                 setarg(paramPos, i, '\0');
  327.             }
  328.             default:
  329.             {
  330.                 continue;
  331.             }
  332.         }
  333.         while (string[stringPos] && string[stringPos] != delim && string[stringPos] > ' ')
  334.         {
  335.             stringPos++;
  336.         }
  337.         while (string[stringPos] && (string[stringPos] == delim || string[stringPos] <= ' '))
  338.         {
  339.             stringPos++;
  340.         }
  341.         paramPos++;
  342.     }
  343.     do
  344.     {
  345.         if ((delim = format[formatPos++]) > ' ')
  346.         {
  347.             if (delim == '\'')
  348.             {
  349.                 while ((delim = format[formatPos++]) && delim != '\'') {}
  350.             }
  351.             else if (delim != 'z')
  352.             {
  353.                 return delim;
  354.             }
  355.         }
  356.     }
  357.     while (delim > ' ');
  358.     return 0;
  359. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement