Advertisement
Guest User

Untitled

a guest
Aug 15th, 2015
584
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.77 KB | None | 0 0
  1. #include <a_samp>
  2. #include <a_mysql>
  3. #include <sscanf2>
  4. #include <streamer>
  5.  
  6. #define name_modifications "« Role Play 0.3.7 »"
  7. #define name_servers "f0Re3t Role Play"
  8.  
  9. #define maximum_flood_kick 5
  10.  
  11. #define publics:%0(%1) forward %0(%1); public %0(%1)
  12.  
  13. #define mysql_hostname "localhost"
  14. #define mysql_username "root"
  15. #define mysql_database "f0Re3t"
  16. #define mysql_password ""
  17.  
  18. #define table_users "users"
  19.  
  20. #include "../library/color.library"
  21. #include "../library/variables.library"
  22.  
  23. enum
  24. {
  25. dialogue_registration,
  26. dialogue_authorization,
  27. dialogue_email,
  28. dialogue_gender
  29. }
  30.  
  31. main() { }
  32.  
  33. public OnGameModeInit()
  34. {
  35. connection = mysql_connect(mysql_hostname, mysql_username, mysql_database, mysql_password);
  36. SetGameModeText(""name_modifications"");
  37. AddPlayerClass(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
  38. DisableInteriorEnterExits();
  39. EnableStuntBonusForAll(false);
  40. LimitPlayerMarkerRadius(30.0);
  41. ManualVehicleEngineAndLights();
  42. SetTimer("SAPI", 1000, true);
  43. return true;
  44. }
  45.  
  46. public OnGameModeExit()
  47. {
  48. mysql_close(connection);
  49. return true;
  50. }
  51.  
  52. public OnPlayerRequestClass(playerid, classid)
  53. {
  54. if(temporary[playerid][authorization] == true) return SpawnPlayer(playerid);
  55. new ORM:key = player[playerid][user_data] = orm_create(table_users);
  56. orm_addvar_int(key, player[playerid][user_number], "user_number");
  57. orm_addvar_string(key, player[playerid][user_name], MAX_PLAYER_NAME, "user_name");
  58. orm_addvar_string(key, player[playerid][user_password], 65, "user_password");
  59. orm_addvar_string(key, player[playerid][user_email], 130, "user_email");
  60. orm_addvar_string(key, player[playerid][user_address], 16, "user_address");
  61. orm_addvar_string(key, player[playerid][user_last_address], 16, "user_last_address");
  62. orm_addvar_int(key, player[playerid][user_gender], "user_gender");
  63. orm_addvar_int(key, player[playerid][user_clothing], "user_clothing");
  64. orm_addvar_int(key, player[playerid][user_money], "user_money");
  65. orm_addvar_int(key, player[playerid][user_level], "user_level");
  66. orm_setkey(key, "user_name");
  67. orm_select(key, "registration", "d", playerid);
  68. return true;
  69. }
  70.  
  71. public OnPlayerConnect(playerid)
  72. {
  73. GetPlayerName(playerid, player[playerid][user_name], MAX_PLAYER_NAME);
  74. reset_variables(playerid);
  75. return true;
  76. }
  77.  
  78. public OnPlayerDisconnect(playerid, reason)
  79. {
  80. if(temporary[playerid][authorization] == true) orm_update(player[playerid][user_data]), orm_destroy(player[playerid][user_data]);
  81. return true;
  82. }
  83.  
  84. public OnPlayerSpawn(playerid)
  85. {
  86. if(temporary[playerid][authorization] == false) return Kick(playerid);
  87. spawn_player_function(playerid);
  88. return true;
  89. }
  90.  
  91. public OnPlayerDeath(playerid, killerid, reason)
  92. {
  93. return true;
  94. }
  95.  
  96. public OnVehicleSpawn(vehicleid)
  97. {
  98. return true;
  99. }
  100.  
  101. public OnVehicleDeath(vehicleid, killerid)
  102. {
  103. return true;
  104. }
  105.  
  106. public OnPlayerText(playerid, text[])
  107. {
  108. if(temporary[playerid][authorization] == false || temporary[playerid][flood] > gettime())
  109. {
  110. temporary[playerid][flood_kick] ++;
  111. return false;
  112. }
  113. if(temporary[playerid][flood_kick] >= maximum_flood_kick) return Kick(playerid);
  114. temporary[playerid][flood] = gettime() + 1;
  115. format(strings, sizeof(strings), "- %s (%s) [%d]", text, player[playerid][user_name], playerid);
  116. send_radius_message(playerid, strings, 10.0, 0xD3D3D3FF);
  117. return false;
  118. }
  119.  
  120. public OnPlayerCommandText(playerid, cmdtext[])
  121. {
  122. return true;
  123. }
  124.  
  125. public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
  126. {
  127. return true;
  128. }
  129.  
  130. public OnPlayerExitVehicle(playerid, vehicleid)
  131. {
  132. return true;
  133. }
  134.  
  135. public OnPlayerStateChange(playerid, newstate, oldstate)
  136. {
  137. return true;
  138. }
  139.  
  140. public OnPlayerEnterCheckpoint(playerid)
  141. {
  142. return true;
  143. }
  144.  
  145. public OnPlayerLeaveCheckpoint(playerid)
  146. {
  147. return true;
  148. }
  149.  
  150. public OnPlayerEnterRaceCheckpoint(playerid)
  151. {
  152. return true;
  153. }
  154.  
  155. public OnPlayerLeaveRaceCheckpoint(playerid)
  156. {
  157. return true;
  158. }
  159.  
  160. public OnRconCommand(cmd[])
  161. {
  162. return true;
  163. }
  164.  
  165. public OnPlayerRequestSpawn(playerid)
  166. {
  167. if(temporary[playerid][authorization] == false) return Kick(playerid);
  168. return true;
  169. }
  170.  
  171. public OnObjectMoved(objectid)
  172. {
  173. return true;
  174. }
  175.  
  176. public OnPlayerObjectMoved(playerid, objectid)
  177. {
  178. return true;
  179. }
  180.  
  181. public OnPlayerPickUpPickup(playerid, pickupid)
  182. {
  183. return true;
  184. }
  185.  
  186. public OnVehicleMod(playerid, vehicleid, componentid)
  187. {
  188. return true;
  189. }
  190.  
  191. public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
  192. {
  193. return true;
  194. }
  195.  
  196. public OnVehicleRespray(playerid, vehicleid, color1, color2)
  197. {
  198. return true;
  199. }
  200.  
  201. public OnPlayerSelectedMenuRow(playerid, row)
  202. {
  203. return true;
  204. }
  205.  
  206. public OnPlayerExitedMenu(playerid)
  207. {
  208. return true;
  209. }
  210.  
  211. public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
  212. {
  213. return true;
  214. }
  215.  
  216. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  217. {
  218. return true;
  219. }
  220.  
  221. public OnRconLoginAttempt(ip[], password[], success)
  222. {
  223. return true;
  224. }
  225.  
  226. public OnPlayerUpdate(playerid)
  227. {
  228. return true;
  229. }
  230.  
  231. public OnPlayerStreamIn(playerid, forplayerid)
  232. {
  233. return true;
  234. }
  235.  
  236. public OnPlayerStreamOut(playerid, forplayerid)
  237. {
  238. return true;
  239. }
  240.  
  241. public OnVehicleStreamIn(vehicleid, forplayerid)
  242. {
  243. return true;
  244. }
  245.  
  246. public OnVehicleStreamOut(vehicleid, forplayerid)
  247. {
  248. return true;
  249. }
  250.  
  251. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  252. {
  253. switch(dialogid)
  254. {
  255. case dialogue_authorization:
  256. {
  257. if(!response) return Kick(playerid);
  258. if(!strlen(inputtext))
  259. {
  260. format(strings, sizeof(strings), "Добро пожаловать на сервер "name_servers"\nВаш персонаж найден в базе данных\n\nИмя персонажа: %s\nВведите ваш игровой пароль:", player[playerid][user_name]);
  261. ShowPlayerDialog(playerid, dialogue_authorization, DIALOG_STYLE_PASSWORD, "Авторизация", strings, "Войти", "Отмена");
  262. return true;
  263. }
  264. new password_hash[65];
  265. SHA256_PassHash(inputtext, "3b?jKqe>9qr1WqUCd.B?]N!>!joa>at8", password_hash, 65);
  266. if(!strcmp(password_hash, player[playerid][user_password], false, 65)) user_authorization(playerid);
  267. else
  268. {
  269. if(temporary[playerid][wrong_password] == 2) return Kick(playerid);
  270. temporary[playerid][wrong_password] ++;
  271. format(strings, sizeof(strings), "Добро пожаловать на сервер "name_servers"\nВаш персонаж найден в базе данных\n\nИмя персонажа: %s\nВведите ваш игровой пароль:", player[playerid][user_name]);
  272. ShowPlayerDialog(playerid, dialogue_authorization, DIALOG_STYLE_PASSWORD, "Авторизация", strings, "Войти", "Отмена");
  273. }
  274. }
  275. case dialogue_registration:
  276. {
  277. if(!response) return Kick(playerid);
  278. if(!strlen(inputtext) || strlen(inputtext) < 6 || strlen(inputtext) > 16)
  279. {
  280. format(strings, sizeof(strings), "Добро пожаловать на сервер "name_servers"\nВаш персонаж не найден в базе данных\n\nИмя персонажа: %s\nВведите ваш будущий пароль:", player[playerid][user_name]);
  281. ShowPlayerDialog(playerid, dialogue_registration, DIALOG_STYLE_INPUT, "Регистрация", strings, "Дальше", "Отмена");
  282. return true;
  283. }
  284. SHA256_PassHash(inputtext, "3b?jKqe>9qr1WqUCd.B?]N!>!joa>at8", player[playerid][user_password], 65);
  285. ShowPlayerDialog(playerid, dialogue_email, DIALOG_STYLE_INPUT, "Регистрация", "Введите действующий адрес электронной почты", "Дальше", "Отмена");
  286. }
  287. case dialogue_email:
  288. {
  289. if(!response) return Kick(playerid);
  290. if(!strlen(inputtext) || strlen(inputtext) > 129) return ShowPlayerDialog(playerid, dialogue_email, DIALOG_STYLE_INPUT, "Регистрация", "Введите действующий адрес электронной почты", "Дальше", "Отмена");
  291. strins(player[playerid][user_email], inputtext, 0);
  292. ShowPlayerDialog(playerid, dialogue_gender, DIALOG_STYLE_MSGBOX, "Регистрация", "Выберите пол своего персонажа", "Мужчина", "Женщина");
  293. }
  294. case dialogue_gender:
  295. {
  296. switch(response)
  297. {
  298. case 0: player[playerid][user_gender] = 2;
  299. case 1: player[playerid][user_gender] = 1;
  300. }
  301. user_registration(playerid);
  302. }
  303. }
  304. return true;
  305. }
  306.  
  307. public OnPlayerClickPlayer(playerid, clickedplayerid, source)
  308. {
  309. return true;
  310. }
  311.  
  312. publics: registration(playerid)
  313. {
  314. switch(orm_errno(player[playerid][user_data]))
  315. {
  316. case ERROR_OK:
  317. {
  318. format(strings, sizeof(strings), "Добро пожаловать на сервер "name_servers"\nВаш персонаж найден в базе данных\n\nИмя персонажа: %s\nВведите ваш игровой пароль:", player[playerid][user_name]);
  319. ShowPlayerDialog(playerid, dialogue_authorization, DIALOG_STYLE_PASSWORD, "Авторизация", strings, "Войти", "Отмена");
  320. temporary[playerid][timer] = SetTimerEx("time_authorization", 30000, false, "d", playerid);
  321. }
  322. case ERROR_NO_DATA:
  323. {
  324. format(strings, sizeof(strings), "Добро пожаловать на сервер "name_servers"\nВаш персонаж не найден в базе данных\n\nИмя персонажа: %s\nВведите ваш будущий пароль:", player[playerid][user_name]);
  325. ShowPlayerDialog(playerid, dialogue_registration, DIALOG_STYLE_INPUT, "Регистрация", strings, "Дальше", "Отмена");
  326. }
  327. }
  328. orm_setkey(player[playerid][user_data], "user_number");
  329. return true;
  330. }
  331.  
  332. publics: time_authorization(playerid)
  333. {
  334. switch(temporary[playerid][authorization])
  335. {
  336. case true: KillTimer(temporary[playerid][timer]);
  337. case false: Kick(playerid);
  338. }
  339. return true;
  340. }
  341.  
  342. publics: SAPI()
  343. {
  344. for(new cycle = 0; cycle <= GetPlayerPoolSize(); cycle ++)
  345. {
  346. SAPI_money(cycle);
  347. if(temporary[cycle][flood_kick] > 0) temporary[cycle][flood_kick] --;
  348. }
  349. return true;
  350. }
  351.  
  352. stock SAPI_money(playerid)
  353. {
  354. if(GetPlayerMoney(playerid) != player[playerid][user_money]) ResetPlayerMoney(playerid), GivePlayerMoney(playerid, player[playerid][user_money]);
  355. return true;
  356. }
  357.  
  358. stock reset_variables(playerid)
  359. {
  360. player[playerid][user_number] = 0;
  361. player[playerid][user_gender] = 0;
  362. player[playerid][user_clothing] = 0;
  363. player[playerid][user_money] = 0;
  364. player[playerid][user_level] = 0;
  365. temporary[playerid][authorization] = false;
  366. temporary[playerid][flood] = 0;
  367. temporary[playerid][flood_kick] = 0;
  368. temporary[playerid][wrong_password] = 0;
  369. return true;
  370. }
  371.  
  372. stock user_authorization(playerid)
  373. {
  374. temporary[playerid][authorization] = true;
  375. SpawnPlayer(playerid);
  376. return true;
  377. }
  378.  
  379. stock user_registration(playerid)
  380. {
  381. new address[16];
  382. GetPlayerIp(playerid, address, sizeof(address));
  383. strins(player[playerid][user_address], address, 0);
  384. strins(player[playerid][user_last_address], address, 0);
  385. temporary[playerid][authorization] = true;
  386. switch(player[playerid][user_gender])
  387. {
  388. case 1: player[playerid][user_clothing] = clothing_man[random(sizeof(clothing_man))];
  389. case 2: player[playerid][user_clothing] = clothing_woman[random(sizeof(clothing_woman))];
  390. }
  391. player[playerid][user_level] = 1;
  392. player[playerid][user_money] = 1000;
  393. SpawnPlayer(playerid);
  394. orm_insert(player[playerid][user_data], "", "");
  395. return true;
  396. }
  397.  
  398. stock spawn_player_function(playerid)
  399. {
  400. SetPlayerSkin(playerid, player[playerid][user_clothing]);
  401. SetPlayerScore(playerid, player[playerid][user_level]);
  402. SetPlayerColor(playerid, 0xFFFFFF30);
  403. SetPlayerPos(playerid, 1154.3717, -1769.2594, 16.5938);
  404. SetPlayerFacingAngle(playerid, 0.6853);
  405. SetCameraBehindPlayer(playerid);
  406. SetPlayerVirtualWorld(playerid, 0);
  407. SetPlayerInterior(playerid, 0);
  408. return true;
  409. }
  410.  
  411. stock send_radius_message(playerid, string[], Float: radius, color)
  412. {
  413. new Float: position[3];
  414. GetPlayerPos(playerid, position[0], position[1], position[2]);
  415. for(new cycle = 0; cycle <= GetPlayerPoolSize(); cycle ++)
  416. {
  417. if(!IsPlayerConnected(cycle) || temporary[cycle][authorization] == false || GetPlayerVirtualWorld(playerid) != GetPlayerVirtualWorld(cycle) || GetPlayerInterior(playerid) != GetPlayerInterior(cycle) || GetPlayerDistanceFromPoint(cycle, position[0], position[1], position[2]) > radius) continue;
  418. SendClientMessage(cycle, color, string);
  419. }
  420. return true;
  421. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement