daily pastebin goal
36%
SHARE
TWEET

Untitled

a guest Feb 13th, 2018 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // includes
  2.  
  3. #include <a_samp>
  4. #include <a_mysql>
  5. #include <Pawn.CMD>
  6.  
  7. // defines
  8.  
  9. #define MYSQL_HOST                      "localhost"
  10. #define MYSQL_USER                      "root"
  11. #define MYSQL_DB                        "db1"
  12. #define MYSQL_PASS                      ""
  13. #define SCM                             SendClientMessage
  14.  
  15. // new
  16.  
  17. new mysql_id;
  18.  
  19. new Random_Skin_Male[] = {
  20.     292, 293
  21. };
  22. new Random_Skin_Female[] = {
  23.     12, 138
  24. };
  25.  
  26. // enums
  27.  
  28. enum {
  29.     D_LANGUAGE, D_REG, D_REG_SEX,
  30.     D_LOGIN,
  31.     D_ATM,
  32.     D_SETTINGS,
  33. };
  34.  
  35. enum player_info {
  36.     ID,
  37.     Name[MAX_PLAYER_NAME],
  38.     Password[24],
  39.     Language, // 1 - Russian, 2 - English
  40.     Sex,
  41.     Skin,
  42. };
  43. new pInfo[MAX_PLAYERS][player_info];
  44.  
  45. main(){}
  46.  
  47. public OnGameModeInit() {
  48.     mysql_id = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_DB, MYSQL_PASS);
  49.     SetGameModeText(" ");
  50.     return true;
  51. }
  52.  
  53. public OnGameModeExit() {
  54.     mysql_close(mysql_id);
  55.     return true;
  56. }
  57.  
  58. public OnPlayerRequestClass(playerid, classid) {
  59.     if(GetPVarInt(playerid, "Is_Authed")) return SpawnPlayer(playerid);
  60.     return true;
  61. }
  62.  
  63. public OnPlayerConnect(playerid) {
  64.     GetPlayerName(playerid, pInfo[playerid][Name], MAX_PLAYER_NAME);
  65.     //
  66.     new query[40+MAX_PLAYER_NAME];
  67.     mysql_format(mysql_id, query, sizeof(query), "SELECT * FROM `accounts` WHERE `Name`='%s'", pInfo[playerid][Name]);
  68.     mysql_function_query(mysql_id, query, true, "@_FindPlayerInTable", "i", playerid);
  69.     return true;
  70. }
  71.  
  72. public OnPlayerDisconnect(playerid, reason) {
  73.     RemovePlayerInfo(playerid);
  74.     DeletePVar(playerid, "Is_Authed");
  75.     return true;
  76. }
  77.  
  78. public OnPlayerSpawn(playerid) {
  79.     SetPlayerPos(playerid, 0.0, 0.0, 5.0);
  80.     SetPlayerSkin(playerid, pInfo[playerid][Skin]);
  81.     return true;
  82. }
  83.  
  84. public OnPlayerDeath(playerid, killerid, reason)
  85. {
  86.     return true;
  87. }
  88.  
  89. public OnVehicleSpawn(vehicleid)
  90. {
  91.     return true;
  92. }
  93.  
  94. public OnVehicleDeath(vehicleid, killerid)
  95. {
  96.     return true;
  97. }
  98.  
  99. public OnPlayerText(playerid, text[])
  100. {
  101.     return true;
  102. }
  103.  
  104. public OnPlayerCommandText(playerid, cmdtext[]) {
  105.     return 0;
  106. }
  107.  
  108. public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
  109. {
  110.     return true;
  111. }
  112.  
  113. public OnPlayerExitVehicle(playerid, vehicleid)
  114. {
  115.     return true;
  116. }
  117.  
  118. public OnPlayerStateChange(playerid, newstate, oldstate)
  119. {
  120.     return true;
  121. }
  122.  
  123. public OnPlayerEnterCheckpoint(playerid)
  124. {
  125.     return true;
  126. }
  127.  
  128. public OnPlayerLeaveCheckpoint(playerid)
  129. {
  130.     return true;
  131. }
  132.  
  133. public OnPlayerEnterRaceCheckpoint(playerid)
  134. {
  135.     return true;
  136. }
  137.  
  138. public OnPlayerLeaveRaceCheckpoint(playerid)
  139. {
  140.     return true;
  141. }
  142.  
  143. public OnRconCommand(cmd[])
  144. {
  145.     return true;
  146. }
  147.  
  148. public OnPlayerRequestSpawn(playerid)
  149. {
  150.     return true;
  151. }
  152.  
  153. public OnObjectMoved(objectid)
  154. {
  155.     return true;
  156. }
  157.  
  158. public OnPlayerObjectMoved(playerid, objectid)
  159. {
  160.     return true;
  161. }
  162.  
  163. public OnPlayerPickUpPickup(playerid, pickupid)
  164. {
  165.     return true;
  166. }
  167.  
  168. public OnVehicleMod(playerid, vehicleid, componentid)
  169. {
  170.     return true;
  171. }
  172.  
  173. public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
  174. {
  175.     return true;
  176. }
  177.  
  178. public OnVehicleRespray(playerid, vehicleid, color1, color2)
  179. {
  180.     return true;
  181. }
  182.  
  183. public OnPlayerSelectedMenuRow(playerid, row)
  184. {
  185.     return true;
  186. }
  187.  
  188. public OnPlayerExitedMenu(playerid)
  189. {
  190.     return true;
  191. }
  192.  
  193. public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
  194. {
  195.     return true;
  196. }
  197.  
  198. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys) {
  199.     if(newkeys & 1024) { // alt
  200.         if(IsPlayerInRangeOfPoint(playerid, 5.0, 0.0, 0.0, 5.0)) {
  201.             if(pInfo[playerid][Language] == 1)
  202.                 return ShowPlayerDialog(playerid, D_ATM, DIALOG_STYLE_LIST, "Банкомат", "1. Пополнить счёт\n2. Снять со счёта", "Выбрать", "Отмена");
  203.             else ShowPlayerDialog(playerid, D_ATM, DIALOG_STYLE_LIST, "ATM", "1. Deposit\n2. Withdraw", "Choose", "Cancel");
  204.         }
  205.     }
  206.     return true;
  207. }
  208.  
  209. public OnRconLoginAttempt(ip[], password[], success)
  210. {
  211.     return true;
  212. }
  213.  
  214. public OnPlayerUpdate(playerid)
  215. {
  216.     return true;
  217. }
  218.  
  219. public OnPlayerStreamIn(playerid, forplayerid)
  220. {
  221.     return true;
  222. }
  223.  
  224. public OnPlayerStreamOut(playerid, forplayerid)
  225. {
  226.     return true;
  227. }
  228.  
  229. public OnVehicleStreamIn(vehicleid, forplayerid)
  230. {
  231.     return true;
  232. }
  233.  
  234. public OnVehicleStreamOut(vehicleid, forplayerid)
  235. {
  236.     return true;
  237. }
  238.  
  239. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) {
  240.     switch(dialogid) {
  241.         case D_LANGUAGE: {
  242.             if(!response)
  243.                 return Kick(playerid);
  244.             pInfo[playerid][Language] = listitem+1;
  245.             Show_Register(playerid);
  246.             return true;
  247.         }
  248.         case D_REG: {
  249.             if(!response) return Kick(playerid);
  250.             if(!(0 <= strlen(inputtext) <= 24)) return Show_Register(playerid);
  251.             strmid(pInfo[playerid][Password], inputtext, 0, 64, 255);
  252.             if(pInfo[playerid][Language] == 1)
  253.                 return ShowPlayerDialog(playerid, D_REG_SEX, DIALOG_STYLE_LIST,
  254.                     "Выберете ваш пол",
  255.                     "1. Мужской\n2. Женский",
  256.                     "Далее", "Отмена");
  257.             else ShowPlayerDialog(playerid, D_REG_SEX, DIALOG_STYLE_LIST,
  258.                 "Choose your sex",
  259.                 "1. Male\n2. Female",
  260.                 "Next", "Exit");
  261.             return true;
  262.         }
  263.         case D_REG_SEX: {
  264.             if(!response)
  265.                 return Kick(playerid);
  266.             pInfo[playerid][Sex] = listitem + 1;
  267.             pInfo[playerid][Skin] = (listitem == 0) ?
  268.             (Random_Skin_Male[random(sizeof(Random_Skin_Male))]) :
  269.             (Random_Skin_Female[random(sizeof(Random_Skin_Female))]);
  270.             CreateNewAccount(playerid);
  271.             return true;
  272.         }
  273.         case D_LOGIN: {
  274.             if(!response)
  275.                 return Kick(playerid);
  276.             if(!(0 <= strlen(inputtext) <= 24))
  277.                 return Show_Login(playerid);
  278.             if(!strcmp(pInfo[playerid][Password], inputtext)) {
  279.                 new query[44+24];
  280.                 mysql_format(mysql_id, query, sizeof(query), "SELECT * FROM `accounts` WHERE `Password`='%s'", inputtext);
  281.                 mysql_function_query(mysql_id, query, true, "@_LoadAccount", "i", playerid);
  282.             } else {
  283.                 SetPVarInt(playerid, "Wrong_Pass", GetPVarInt(playerid, "Wrong_Pass") + 1);
  284.                 SCM(playerid, -1, "You have entered the wrong password many times, so they were kicked.");
  285.                 Show_Login(playerid);
  286.                 if(GetPVarInt(playerid, "Wrong_Pass") >= 3)
  287.                     return Kick(playerid);
  288.             }
  289.             return true;
  290.         }
  291.         case D_SETTINGS: {
  292.             if(!response) return true;
  293.             switch(listitem) {
  294.                 case 0: {
  295.                     if(pInfo[playerid][Language] == 1)
  296.                         return SCM(playerid, -1, "Вы сменили язык на Английский.");
  297.                     else SCM(playerid, -1, "You changed your language to Russian.");
  298.                 }
  299.             }
  300.             pInfo[playerid][Language] = listitem+1;
  301.             return true;
  302.         }
  303.     }
  304.     return true;
  305. }
  306.  
  307. public OnPlayerClickPlayer(playerid, clickedplayerid, source)
  308. {
  309.     return true;
  310. }
  311.  
  312. // publics, forwards, stocks
  313.  
  314. @_FindPlayerInTable(playerid);
  315. @_FindPlayerInTable(playerid) {
  316.     new rows, fields;
  317.     cache_get_data(rows, fields);
  318.     if(!rows) ShowPlayerDialog(playerid, D_LANGUAGE, DIALOG_STYLE_LIST,
  319.         "Choose a language",
  320.         "1. Русский\n2. English",
  321.         "Далее", "Отмена");
  322.     else {
  323.         cache_get_field_content(0, "Password", pInfo[playerid][Password], mysql_id, 24);
  324.         pInfo[playerid][Language] = cache_get_field_content_int(0, "Language", mysql_id);
  325.         Show_Login(playerid);
  326.     }
  327.     return true;
  328. }
  329.  
  330. Show_Register(playerid) {
  331.     if(pInfo[playerid][Language] == 1) {
  332.         ShowPlayerDialog(playerid, D_REG, DIALOG_STYLE_INPUT,
  333.             "Регистрация",
  334.             "Введите ваш будущий пароль в окно ниже",
  335.             "Далее", "Отмена");
  336.     } else {
  337.         ShowPlayerDialog(playerid, D_REG, DIALOG_STYLE_INPUT,
  338.             "Registration",
  339.             "Enter your future password in the window below",
  340.             "Next", "Exit");
  341.     }
  342.     return true;
  343. }
  344.  
  345. Show_Login(playerid) {
  346.     if(pInfo[playerid][Language] == 1) {
  347.         ShowPlayerDialog(playerid, D_LOGIN, DIALOG_STYLE_INPUT,
  348.             "Авторизация",
  349.             "Введите ваш пароль в окно ниже",
  350.             "Далее", "Отмена");
  351.     } else {
  352.         ShowPlayerDialog(playerid, D_LOGIN, DIALOG_STYLE_INPUT,
  353.             "Authorization",
  354.             "Enter your password in the window below",
  355.             "Next", "Exit");
  356.     }
  357.     return true;
  358. }
  359.  
  360. @_LoadAccount(playerid);
  361. @_LoadAccount(playerid) {
  362.     pInfo[playerid][ID] = cache_get_field_content_int(0, "ID", mysql_id);
  363.     pInfo[playerid][Sex] = cache_get_field_content_int(0, "Sex", mysql_id);
  364.     pInfo[playerid][Skin] = cache_get_field_content_int(0, "Skin", mysql_id);
  365.     if(pInfo[playerid][Language] == 1)
  366.         return SCM(playerid, -1, "Вы успешно авторизовались.");
  367.     else SCM(playerid, -1, "You have been successfully authorized.");
  368.     SetPVarInt(playerid, "Is_Authed", true);
  369.     DeletePVar(playerid, "Wrong_Pass");
  370.     SpawnPlayer(playerid);
  371.     return true;
  372. }
  373.  
  374. RemovePlayerInfo(playerid) {
  375.     pInfo[playerid][ID] = EOS; pInfo[playerid][Password] = EOS; pInfo[playerid][Language] = EOS; pInfo[playerid][Sex] = EOS; pInfo[playerid][Skin] = EOS;
  376. }
  377.  
  378. Show_Settings(playerid) {
  379.     if(pInfo[playerid][Language] == 1) {
  380.         static const frm_setting[] = "\
  381.             1. Сменить язык [Русский]";
  382.         new str_setting[sizeof(frm_setting)];
  383.         format(str_setting, sizeof(str_setting), frm_setting);
  384.         ShowPlayerDialog(playerid, D_SETTINGS, DIALOG_STYLE_LIST,
  385.             "Настройки",
  386.             str_setting,
  387.             "Выбрать", "Отмена");
  388.     } if(pInfo[playerid][Language] == 2) {
  389.         static const frm_setting[] = "\
  390.             1. Change language [English]";
  391.         new str_setting[sizeof(frm_setting)];
  392.         format(str_setting, sizeof(str_setting), frm_setting);
  393.         ShowPlayerDialog(playerid, D_SETTINGS, DIALOG_STYLE_LIST,
  394.             "Settings",
  395.             str_setting,
  396.             "Choose", "Cancel");
  397.     }
  398.     return true;
  399. }
  400.  
  401. CreateNewAccount(playerid) {
  402.     new query[107+MAX_PLAYER_NAME+24];
  403.     mysql_format(mysql_id, query, sizeof(query),
  404.     "INSERT INTO `accounts` (`Name`, `Password`, `Language`, `Sex`, `Skin`) VALUE ('%s', '%s', '%d', '%d', '%d')",
  405.     pInfo[playerid][Name], pInfo[playerid][Password], pInfo[playerid][Language], pInfo[playerid][Sex], pInfo[playerid][Skin]);
  406.     mysql_function_query(mysql_id, query, false, "", "");
  407.     SetPVarInt(playerid, "Is_Authed", true);
  408.     SpawnPlayer(playerid);
  409.     return true;
  410. }
  411.  
  412. // commands
  413.  
  414. cmd:settings(playerid, params[]) {
  415.     Show_Settings(playerid);
  416.     return true;
  417. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top