Advertisement
Guest User

Untitled

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