Advertisement
Guest User

ANTI-CHEAT

a guest
Dec 27th, 2013
4,033
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 26.86 KB | None | 0 0
  1. #include <a_samp>
  2. #include <fixes>
  3. #include <sscanf>
  4. #include <zcmdfs>
  5. #include <DiniSarp>
  6.  
  7. // Detects the following (these also apply to the arrays within settings).
  8. #define SPEEDHACKS 0 // Speed Hacks, vehicle and player (player collision, fly hacks etc).
  9. #define VEHICLERELATED 1 // Car related hacks, like remote control, car warping, etc.
  10. #define VEHICLEMODS 2 // Car Modification Hacking.
  11. #define VEHICLESPAM 3 // Car Particle Spamming.
  12. #define FAKEKILL 4 // Fake Killing.
  13. #define HACKS 5 // s0beit installed.
  14. // Need to add stuff like remote control car, fix the /anticheat menu (commands only?)
  15. // and test everything with multiple people.
  16.  
  17. // Punishments
  18. #define NOTHING 0
  19. #define BAN 1
  20. #define KICK 2
  21. #define WARN 3
  22.  
  23. // Limits
  24. #define DETECTIONS 6
  25.  
  26.  
  27. // Data structures.
  28. enum a_Settings // Anticheat settings
  29. {
  30. // Whether or not they're loaded already.
  31. bool:loaded,
  32.  
  33. // Punishment for specific hacks.
  34. // 0 - Nothing, 1 - Ban, 2 - Kick, 3 - Admin Warning.
  35. punishment[DETECTIONS],
  36.  
  37. // Whether or not to detect certain things.
  38. bool:detection[DETECTIONS],
  39.  
  40. // Not really a setting, but can rest here.
  41. detected, // Amount of detected, maybe make this an array for each hack too?
  42.  
  43. // Debugging mode, dumps info like "PInfo" in certain places.
  44. debugging
  45. };
  46. new Settings[a_Settings];
  47.  
  48. enum a_Timings // Why not?
  49. {
  50. // Will consist of arrays with at least 2 elements.
  51. // Element 1 - Tick when started.
  52. // Element 2 - Tick when ended.
  53. settingstime[2],
  54. };
  55. new Timings[a_Timings];
  56.  
  57. enum p_Info // Player info for holding various info on login.
  58. {
  59. bool:loaded,
  60. bool:checked,
  61. alevel,
  62. LastPunishment, // Save last punishment tick to avoid spamming of punishments.
  63. CurrentVeh, // Used for detecting hacks like car warping, remote control, etc.
  64. CurrentState, // ^
  65. LastState, // ^
  66. SCTime, // ^
  67. Deaths // How many times they've died, used for detecting fake kills.
  68. };
  69. new PInfo[MAX_PLAYERS][p_Info];
  70.  
  71. enum v_Info // Vehicle info, for holding info like damage to detect car particle spamming.
  72. {
  73. LastDamageInfo[4], // Holds last info for panels, doors, lights and tires.
  74. LastDamage // How many times it's state has changed.
  75. };
  76. new VInfo[MAX_VEHICLES][v_Info];
  77.  
  78. // Some arrays.
  79. new a_string[512];
  80.  
  81. // Various definitions
  82. #define DIALOG_ID_ANTICHEAT 4246 // I hope this isn't used anywhere else.
  83.  
  84. // Functions
  85. stock ToNumber(character)
  86. {
  87. if(character >= '0' && character <= '9') return character - '0';
  88. return 0;
  89. }
  90.  
  91. bool:ToggleBool(&bool:toggle)
  92. {
  93. if(toggle)
  94. {
  95. toggle = false;
  96. }
  97. else
  98. {
  99. toggle = true;
  100. }
  101. return toggle;
  102. }
  103.  
  104. stock ShowAntiCheatDialog(playerid)
  105. {
  106. format(a_string, sizeof(a_string), "Information\nPunishments\nDetections\nDebug: %s", Settings[debugging] ? ("{00FF00}ON") : ("{FF0000}OFF"));
  107. ShowPlayerDialog( playerid, DIALOG_ID_ANTICHEAT, DIALOG_STYLE_LIST,
  108. "Anticheat Menu", a_string,
  109. "Select", "Cancel");
  110. return 1;
  111. }
  112.  
  113. stock GetHackNameFromType(type)
  114. {
  115. new hackname[32];
  116. if(type == SPEEDHACKS)
  117. {
  118. format(hackname, sizeof(hackname), "Speed Hacks");
  119. }
  120. else if(type == VEHICLERELATED)
  121. {
  122. format(hackname, sizeof(hackname), "Vehicle Related Hacks");
  123. }
  124. else if(type == VEHICLEMODS)
  125. {
  126. format(hackname, sizeof(hackname), "Vehicle Mod Hacks");
  127. }
  128. else if(type == VEHICLESPAM)
  129. {
  130. format(hackname, sizeof(hackname), "Particle Spamming");
  131. }
  132. else if(type == FAKEKILL)
  133. {
  134. format(hackname, sizeof(hackname), "Fake Killing");
  135. }
  136. else if(type == HACKS)
  137. {
  138. format(hackname, sizeof(hackname), "Hacks Installed");
  139. }
  140. return hackname;
  141. }
  142.  
  143. stock PunishForType(playerid, type)
  144. {
  145. if(GetTickCount() - PInfo[playerid][LastPunishment] > 1000) // Avoid spam!!!
  146. {
  147. PInfo[playerid][LastPunishment] = GetTickCount();
  148. if(Settings[punishment][type] == BAN)
  149. {
  150. HackBan(playerid, type);
  151. }
  152. else if(Settings[punishment][type] == KICK)
  153. {
  154. HackKick(playerid, type);
  155. }
  156. else if(Settings[punishment][type] == WARN)
  157. {
  158. HackWarning(playerid, type);
  159. }
  160. GetPlayerName(playerid, a_string, MAX_PLAYER_NAME);
  161. printf("[Anticheat Debugging]: %s is being punished for \"%s\".", a_string, GetHackNameFromType(type));
  162. printf("[Anticheat Debugging]: loaded = %d, checked = %d, alevel = %d, LastPunishment = %d.", PInfo[playerid][loaded], PInfo[playerid][checked], PInfo[playerid][alevel], PInfo[playerid][LastPunishment]);
  163. printf("[Anticheat Debugging]: CurrentVeh = %d, CurrentState = %d, LastState = %d, SCTime = %d.", PInfo[playerid][CurrentVeh], PInfo[playerid][CurrentState], PInfo[playerid][LastState], PInfo[playerid][SCTime]);
  164. printf("[Anticheat Debugging]: Deaths = %d.", PInfo[playerid][Deaths]);
  165. }
  166. }
  167.  
  168. stock HackBan(playerid, type)
  169. {
  170. if(PInfo[playerid][alevel] > 1) return 1; // admin exception
  171. Settings[detected]++;
  172. GetPlayerName(playerid, a_string, MAX_PLAYER_NAME);
  173. format(a_string, sizeof(a_string), "SERVER: %s has been banned, reason: %s (%d hackers detected)", a_string, GetHackNameFromType(type), Settings[detected]);
  174. SendClientMessageToAll(0xFF6347FF, a_string);
  175. SetTimerEx("HackBanFinish", GetPlayerPing(playerid) * 2, 0, "ii", playerid, type);
  176. return 1;
  177. }
  178.  
  179. forward HackBanFinish(playerid, type);
  180. public HackBanFinish(playerid, type)
  181. {
  182. GetPlayerName(playerid, a_string, MAX_PLAYER_NAME);
  183. BanEx(playerid, GetHackNameFromType(type));
  184. SendRconCommand("reloadbans");
  185. format(a_string, sizeof(a_string), "%s.ini", a_string);
  186. dini_IntSet(a_string, "Band", 3);
  187. dini_IntSet(a_string, "PermBand", 1);
  188. dini_Set(a_string, "BanReason", GetHackNameFromType(type));
  189. return 1;
  190. }
  191.  
  192. stock HackKick(playerid, type)
  193. {
  194. if(PInfo[playerid][alevel] > 1) return 1; // admin exception
  195. Settings[detected]++;
  196. GetPlayerName(playerid, a_string, MAX_PLAYER_NAME);
  197. format(a_string, sizeof(a_string), "SERVER: %s has been kicked, reason: %s (%d hackers detected)", a_string, GetHackNameFromType(type), Settings[detected]);
  198. SendClientMessageToAll(0xFF6347FF, a_string);
  199. SetTimerEx("HackKickFinish", GetPlayerPing(playerid) * 2, 0, "i", playerid);
  200. return 1;
  201. }
  202.  
  203. forward HackKickFinish(playerid);
  204. public HackKickFinish(playerid)
  205. {
  206. Kick(playerid);
  207. return 1;
  208. }
  209.  
  210. stock HackWarning(playerid, type)
  211. {
  212. if(PInfo[playerid][alevel] > 1) return 1; // admin exception
  213. Settings[detected]++;
  214. GetPlayerName(playerid, a_string, MAX_PLAYER_NAME);
  215. format(a_string, sizeof(a_string), "AdmWarning{FFFFFF}: %s has triggered the anticheat, reason: %s", a_string, GetHackNameFromType(type));
  216. for(new i = 0; i < MAX_PLAYERS; i++)
  217. {
  218. if(!IsPlayerConnected(i)) continue;
  219. if(PInfo[i][alevel] > 0)
  220. {
  221. SendClientMessage(i, 0xFF0000FF, a_string);
  222. }
  223. }
  224. return 1;
  225. }
  226.  
  227. stock LoadSettings()
  228. {
  229. if(Settings[loaded])
  230. {
  231. print("[Anticheat]: Unloading settings for reload");
  232. // Zero em out.
  233. for(new i = 0; i < DETECTIONS; i++)
  234. {
  235. Settings[punishment][i] = 0;
  236. Settings[detection][i] = false;
  237. }
  238.  
  239. Settings[detected] = 0;
  240. Settings[debugging] = 0;
  241.  
  242. Settings[loaded] = false;
  243. print("[Anticheat]: Unloaded settings, reloading.");
  244. }
  245. else print("[Anticheat]: Loading settings.");
  246.  
  247. // Let's take down our time.
  248. Timings[settingstime][0] = GetTickCount();
  249.  
  250. // Now, let's load em.
  251. if(!dini_Exists("a_settings.ini") || !fexist("a_settings.ini")) // WAT?
  252. dini_Create("a_settings.ini"); // okay.
  253.  
  254. format(a_string, sizeof(a_string), "%s", dini_Get("a_settings.ini", "Punishments"));
  255. for(new i = 0; i < DETECTIONS; i++)
  256. {
  257. Settings[punishment][i] = ToNumber(a_string[i]);
  258. }
  259.  
  260. format(a_string, sizeof(a_string), "%s", dini_Get("a_settings.ini", "Detections"));
  261. for(new i = 0; i < DETECTIONS; i++)
  262. {
  263. if(a_string[i] > '0')
  264. {
  265. Settings[detection][i] = true;
  266. }
  267. else
  268. {
  269. Settings[detection][i] = false;
  270. }
  271. }
  272.  
  273. Settings[detected] = dini_Int("a_settings.ini", "Detected");
  274. Settings[debugging] = dini_Int("a_settings.ini", "Debug");
  275.  
  276. Settings[loaded] = true;
  277. Timings[settingstime][1] = GetTickCount();
  278. printf("[Anticheat]: Loaded settings, took %dms.", Timings[settingstime][1] - Timings[settingstime][0]);
  279. return 1;
  280. }
  281.  
  282. stock UnloadSettings()
  283. {
  284. print("[Anticheat]: Unloading settings, saving first...");
  285. SaveSettings();
  286.  
  287. // Zero em out.
  288. for(new i = 0; i < DETECTIONS; i++)
  289. {
  290. Settings[punishment][i] = 0;
  291. Settings[detection][i] = false;
  292. }
  293.  
  294. Settings[debugging] = 0;
  295. Settings[detected] = 0;
  296.  
  297. Settings[loaded] = false;
  298. print("[Anticheat]: Unloaded settings.");
  299. return 1;
  300. }
  301.  
  302. stock SaveSettings()
  303. {
  304. if(!Settings[loaded]) return print("[Anticheat]: Settings weren't loaded in the first place, canceling save.");
  305.  
  306. print("[Anticheat]: Saving settings.");
  307.  
  308. // Let's take down our time, again.
  309. Timings[settingstime][0] = GetTickCount();
  310.  
  311. if(!dini_Exists("a_settings.ini") || !fexist("a_settings.ini")) // WAT? something's up
  312. dini_Create("a_settings.ini"); // pls?
  313.  
  314. format(a_string, sizeof(a_string), "");
  315. for(new i = 0; i < DETECTIONS; i++)
  316. {
  317. format(a_string, sizeof(a_string), "%s%d", a_string, Settings[punishment][i]);
  318. }
  319. dini_Set("a_settings.ini", "Punishments", a_string);
  320.  
  321. format(a_string, sizeof(a_string), "");
  322. for(new i = 0; i < DETECTIONS; i++)
  323. {
  324. format(a_string, sizeof(a_string), "%s%d", a_string, Settings[detection][i]);
  325. }
  326. dini_Set("a_settings.ini", "Detections", a_string);
  327.  
  328. dini_IntSet("a_settings.ini", "Detected", Settings[detected]);
  329. dini_IntSet("a_settings.ini", "Debug", Settings[debugging]);
  330.  
  331. Timings[settingstime][1] = GetTickCount();
  332. printf("[Anticheat]: Saved settings, took %dms.", Timings[settingstime][1] - Timings[settingstime][0]);
  333. return 1;
  334. }
  335.  
  336. // Commmands
  337.  
  338. // Anticheat settings or information dialog for admins, and maybe players too.
  339. // If we include players, it will be restricted to info for them, I also think
  340. // /anticheat is a command in the gamemode already and this will override that.
  341. CMD:anticheat(playerid, params[])
  342. {
  343. if(PInfo[playerid][alevel] < 2) return 0; // Pass them on to the gamemode.
  344. ShowAntiCheatDialog(playerid);
  345. return 1;
  346. }
  347.  
  348. // To invoke the s0beit check.
  349. CMD:checks0b(playerid, params[])
  350. {
  351. if(PInfo[playerid][alevel] < 2) return 1;
  352. new pid;
  353. if(sscanf(params, "u", pid)) return SendClientMessage(playerid, -1, "USAGE: /checks0b [playerid]");
  354. if(!IsPlayerConnected(pid)) return SendClientMessage(playerid, -1, "Player is not connected.");
  355. if(!PInfo[playerid][loaded]) return SendClientMessage(playerid, -1, "Player is not loaded.");
  356. Starts0bCheck(pid, 0);
  357. SendClientMessage(playerid, -1, "Invoking a s0beit check.");
  358. return 1;
  359. }
  360.  
  361. // Generic callbacks.
  362. new MainTimer = -1;
  363.  
  364. public OnFilterScriptInit()
  365. {
  366. LoadSettings();
  367. for(new p = 0; p < MAX_PLAYERS; p++)
  368. {
  369. for(new i; p_Info:i < p_Info; i++)
  370. {
  371. PInfo[p][p_Info:i] = 0;
  372. }
  373. if(IsPlayerConnected(p)) PInfo[p][CurrentVeh] = GetPlayerVehicleID(p);
  374. }
  375. MainTimer = SetTimer("MainTiming", 1000, 1);
  376. return 1;
  377. }
  378.  
  379. public OnFilterScriptExit()
  380. {
  381. UnloadSettings();
  382. KillTimer(MainTimer);
  383. return 1;
  384. }
  385.  
  386. // The hack detections.
  387.  
  388. // Detecting if s0beit is installed.
  389. // As you can see below, the way we detect s0beit is simple, and it uses a flaw
  390. // in s0beit to our advantage. Basically with s0beit, when you get frozen, the
  391. // camera goes upwards, but without s0beit it doesn't. This flaw is a great
  392. // advantage for us.
  393. // Also, maybe make this use GetPlayerCameraFrontVector instead?
  394. public OnPlayerSpawn(playerid)
  395. {
  396. if(Settings[detection][HACKS] && !PInfo[playerid][checked] && PInfo[playerid][alevel] < 2)
  397. {
  398. PInfo[playerid][checked] = true;
  399. SetTimerEx("Starts0bCheck", 1000 + (GetPlayerPing(playerid) * 2), 0, "ii", playerid, 1);
  400. }
  401. return 1;
  402. }
  403.  
  404. forward Starts0bCheck(playerid, type);
  405. public Starts0bCheck(playerid, type)
  406. {
  407. if(IsPlayerConnected(playerid) && PInfo[playerid][loaded])
  408. {
  409. // Don't check people in tutorial or hospital.
  410. if( IsPlayerInRangeOfPoint(playerid, 1.0, 1192.256836, -1304.637939, 7.0000) || // All Saints
  411. IsPlayerInRangeOfPoint(playerid, 1.0, 2012.323608, -1436.354370, 5.0000) || // County General
  412. IsPlayerInRangeOfPoint(playerid, 1.0, 764.4561160, -1761.971436, 0.0000) || // Tutorial First Position.
  413. IsPlayerInRangeOfPoint(playerid, 1.0, 2324.685303, -2340.955078, 0.0000)) return 1; // Tutorial Second Position.
  414.  
  415. if(type == 1) SendClientMessage(playerid, -1, "Please wait while we process your character.");
  416. if(IsPlayerInAnyVehicle(playerid))
  417. {
  418. new Float:pos[3];
  419. GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
  420. SetPlayerPos(playerid, pos[0], pos[1], pos[2]);
  421. }
  422. SetCameraBehindPlayer(playerid);
  423. TogglePlayerControllable(playerid, 0);
  424. SetTimerEx("Finishs0bCheck", 3000, 0, "ii", playerid, type);
  425. }
  426. return 1;
  427. }
  428.  
  429. forward Finishs0bCheck(playerid, type);
  430. public Finishs0bCheck(playerid, type)
  431. {
  432. if(IsPlayerConnected(playerid) && PInfo[playerid][loaded])
  433. {
  434. new Float:testpos[6];
  435. GetPlayerCameraPos(playerid, testpos[0], testpos[1], testpos[2]);
  436. GetPlayerPos(playerid, testpos[3], testpos[4], testpos[5]);
  437. TogglePlayerControllable(playerid, 1);
  438.  
  439. if(floatabs(testpos[2] - testpos[5]) > 1.5)
  440. {
  441. PunishForType(playerid, HACKS);
  442. if(Settings[punishment][HACKS] == WARN && type == 1)
  443. {
  444. SendClientMessage(playerid, -1, "Thank you, enjoy your stay.");
  445. }
  446.  
  447. GetPlayerName(playerid, a_string, MAX_PLAYER_NAME);
  448. printf("[Anticheat]: %s has s0beit installed.", a_string);
  449. printf("[Anticheat]: Camera Position: %f, %f, %f.", testpos[0], testpos[1], testpos[2]);
  450. printf("[Anticheat]: Player Position: %f, %f, %f.", testpos[3], testpos[4], testpos[5]);
  451. printf("[Anticheat]: Absolute Difference: %f, %f, %f.", floatabs(testpos[0] - testpos[3]),
  452. floatabs(testpos[1] - testpos[4]),
  453. floatabs(testpos[2] - testpos[5]));
  454. }
  455. else
  456. {
  457. SendClientMessage(playerid, -1, "Thank you, enjoy your stay.");
  458. }
  459. }
  460. }
  461.  
  462. // Car particle spamming.
  463. // This hack right here actually reports damages of the car to the SA-MP server,
  464. // thus spamming particles (parts falling off) which actually lags nearby
  465. // clients due to all of the rendering it has to do.
  466. // Tbis detection is simple, when they report damage to their vehicle, it gets
  467. // the damages since the last damage update, and if there's changes to anything
  468. // or everything but lights, it will increase how many times they've damaged
  469. // their car in the last second, if it's above a certain amount, they're car
  470. // particle spamming.
  471. public OnVehicleDamageStatusUpdate(vehicleid, playerid)
  472. {
  473. if(PInfo[playerid][loaded])
  474. {
  475. if(Settings[detection][VEHICLESPAM])
  476. {
  477. new panels, doors, lights, tires;
  478. GetVehicleDamageStatus(vehicleid, panels, doors, lights, tires);
  479. if(VInfo[vehicleid][LastDamageInfo][0] != panels || VInfo[vehicleid][LastDamageInfo][1] != doors || VInfo[vehicleid][LastDamageInfo][3] != tires)
  480. {
  481. VInfo[vehicleid][LastDamage]++;
  482. if(VInfo[vehicleid][LastDamage] > 10)
  483. {
  484. PunishForType(playerid, VEHICLESPAM);
  485. return 0;
  486. }
  487. VInfo[vehicleid][LastDamageInfo][0] = panels;
  488. VInfo[vehicleid][LastDamageInfo][1] = doors;
  489. VInfo[vehicleid][LastDamageInfo][2] = lights;
  490. VInfo[vehicleid][LastDamageInfo][3] = tires;
  491. }
  492. }
  493. }
  494. return 1;
  495. }
  496.  
  497. // Car modification hacking.
  498. // All this does is checks the current interior of the player when they get a
  499. // car mod, if they're in interior 0, they're not in a mod shop and likely
  500. // hacking, so we ban them.
  501. // Pretty straight forward.
  502. public OnVehicleMod(playerid,vehicleid,componentid)
  503. {
  504. if(PInfo[playerid][loaded])
  505. {
  506. if(Settings[detection][VEHICLEMODS])
  507. {
  508. if(GetPlayerInterior(playerid) == 0)
  509. {
  510. PunishForType(playerid, VEHICLEMODS);
  511. return 0;
  512. }
  513. }
  514. }
  515. return 1;
  516. }
  517.  
  518. // Fake killing.
  519. // Fake killing is a very vicous hack, because 1. it will mess with kill/death
  520. // ratios of players, 2 (and the most important). it forces the server/script to
  521. // process a lot of deaths, thus causing performance problems.
  522. // Detecting it is pretty straight forward, if someone dies more than 3 times
  523. // within in a second, obviously they're fake killing and need to be dealt with.
  524. public OnPlayerDeath(playerid, killerid, reason)
  525. {
  526. if(PInfo[playerid][loaded])
  527. {
  528. if(Settings[detection][FAKEKILL])
  529. {
  530. PInfo[playerid][Deaths]++;
  531. if(PInfo[playerid][Deaths] > 3) // Fake killer.
  532. {
  533. PunishForType(playerid, FAKEKILL);
  534. return 0;
  535. }
  536. }
  537. }
  538. return 1;
  539. }
  540.  
  541. // 3 parts/functions - Car Warping and a lot of other hacks related to vehicles.
  542. // Basically car warping can involve multiple things, so I'll just explain the
  543. // detection and maybe you can get a gist of it.
  544. // The detection is simple, if they change state or vehicle and their current
  545. // and last state is driver, they're hacking.
  546. stock StateChange(playerid)
  547. {
  548. if(PInfo[playerid][loaded])
  549. {
  550. if(Settings[detection][VEHICLERELATED])
  551. {
  552. PInfo[playerid][SCTime]++;
  553. if(PInfo[playerid][CurrentState] == PLAYER_STATE_DRIVER && PInfo[playerid][LastState] == PLAYER_STATE_DRIVER)
  554. {
  555. PunishForType(playerid, VEHICLERELATED);
  556. return 0;
  557. }
  558. else if(PInfo[playerid][SCTime] > 3)
  559. {
  560. PunishForType(playerid, VEHICLERELATED);
  561. return 0;
  562. }
  563. }
  564. }
  565. return 1;
  566. }
  567.  
  568. public OnPlayerStateChange(playerid, newstate, oldstate)
  569. {
  570. if(PInfo[playerid][loaded])
  571. {
  572. PInfo[playerid][CurrentVeh] = GetPlayerVehicleID(playerid);
  573. PInfo[playerid][LastState] = PInfo[playerid][CurrentState];
  574. PInfo[playerid][CurrentState] = GetPlayerState(playerid);
  575. return StateChange(playerid);
  576. }
  577. return 1;
  578. }
  579.  
  580. // Speed Hacks
  581. public OnPlayerUpdate(playerid)
  582. {
  583. if(PInfo[playerid][loaded])
  584. {
  585. // The following is required to detect car warpers who are doing it while in
  586. // a vehicle, OnPlayerStateChange is not called in that case but this
  587. // emulates the effects of OnPlayerStateChange.
  588. if(GetPlayerVehicleID(playerid) != PInfo[playerid][CurrentVeh])
  589. {
  590. PInfo[playerid][CurrentVeh] = GetPlayerVehicleID(playerid);
  591. PInfo[playerid][LastState] = PInfo[playerid][CurrentState];
  592. PInfo[playerid][CurrentState] = GetPlayerState(playerid);
  593. return StateChange(playerid);
  594. }
  595. if(Settings[detection][SPEEDHACKS])
  596. {
  597. if(IsPlayerInAnyVehicle(playerid))
  598. {
  599. if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
  600. {
  601. // Okay, let's detect vehicle speed hacks.
  602. // Now, there was a problem in the old anticheat where the Z velocity would
  603. // reach about 2.0 when falling in a car thus banning players.
  604. // The fix for this is simple, don't ban for the Z velocity being minus 1.8.
  605. // s0beit speed hacks reaches about 1.85 at max speed in any car, so we need
  606. // to ban when we reach that velocity on X, Y (plus or minus) or Z (plus only).
  607. new Float:veloc[3];
  608. GetVehicleVelocity(GetPlayerVehicleID(playerid), veloc[0], veloc[1], veloc[2]);
  609. if(veloc[0] > 1.8 || veloc[0] < -1.8 || veloc[1] > 1.8 || veloc[1] < -1.8 || veloc[2] > 1.8)
  610. {
  611. // we gots us a speed haxer.
  612. PunishForType(playerid, SPEEDHACKS);
  613. return 0;
  614. }
  615. }
  616. }
  617. else
  618. {
  619. // Alright then, player speed hacks it is.
  620. // Now this can be multiple hacks whether it be player collision,
  621. // fly hacks, and possibly airbrake.
  622. // This would have the same problem with falling as the vehicles
  623. // so we just need to do the exact same as above to avoid false
  624. // positives.
  625. new Float:veloc[3];
  626. GetPlayerVelocity(playerid, veloc[0], veloc[1], veloc[2]);
  627. if(veloc[0] > 1.25 || veloc[0] < -1.25 || veloc[1] > 1.25 || veloc[1] < -1.25 || veloc[2] > 1.25)
  628. {
  629. // we gots us a player speeders
  630. PunishForType(playerid, SPEEDHACKS);
  631. return 0;
  632. }
  633. }
  634. }
  635. }
  636. return 1;
  637. }
  638.  
  639. // The main timer, for clearing out info and detecting admins logging in etc.
  640. forward MainTiming();
  641. public MainTiming()
  642. {
  643. for(new playerid = 0; playerid < MAX_PLAYERS; playerid++)
  644. {
  645. PInfo[playerid][SCTime] = 0; // Clear how many times their state has changed.
  646. PInfo[playerid][Deaths] = 0; // Clear how many times they've died.
  647. if(!IsPlayerConnected(playerid))
  648. {
  649. if(PInfo[playerid][loaded]) // We need to clear him, he left.
  650. {
  651. PInfo[playerid][alevel] = 0;
  652. PInfo[playerid][SCTime] = 0;
  653. PInfo[playerid][CurrentVeh] = 0;
  654. PInfo[playerid][LastState] = 0;
  655. PInfo[playerid][CurrentState] = 0;
  656. PInfo[playerid][Deaths] = 0;
  657. PInfo[playerid][LastPunishment] = 0;
  658. PInfo[playerid][checked] = false;
  659.  
  660. // Let's not repeat that.
  661. PInfo[playerid][loaded] = false;
  662. }
  663. }
  664. else
  665. {
  666. if(!PInfo[playerid][loaded])
  667. {
  668. GetPlayerName(playerid, a_string, MAX_PLAYER_NAME);
  669. format(a_string, sizeof(a_string), "%s.ini", a_string);
  670. if(fexist(a_string))
  671. {
  672. PInfo[playerid][alevel] = dini_Int(a_string, "AdminLvl");
  673. PInfo[playerid][SCTime] = 0;
  674. PInfo[playerid][CurrentVeh] = 0;
  675. PInfo[playerid][LastState] = 0;
  676. PInfo[playerid][CurrentState] = 0;
  677. PInfo[playerid][Deaths] = 0;
  678. PInfo[playerid][LastPunishment] = 0;
  679. PInfo[playerid][checked] = false;
  680.  
  681. // Let's not repeat that.
  682. PInfo[playerid][loaded] = true;
  683. }
  684. }
  685. }
  686. }
  687. for(new vid = 0; vid < MAX_VEHICLES; vid++)
  688. {
  689. VInfo[vid][LastDamage] = 0;
  690. }
  691. return 1;
  692. }
  693.  
  694. // The dialogs responses.
  695. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  696. {
  697. if(dialogid == DIALOG_ID_ANTICHEAT + 1) // Information, just to move back
  698. {
  699. ShowAntiCheatDialog(playerid);
  700. return 1;
  701. }
  702.  
  703. if(dialogid == DIALOG_ID_ANTICHEAT + 2) // Punishments, change punishments.
  704. {
  705. if(PInfo[playerid][alevel] < 2) return 1;
  706. if(!response)
  707. {
  708. ShowAntiCheatDialog(playerid);
  709. return 1;
  710. }
  711. else
  712. {
  713. if(Settings[punishment][listitem] >= 3)
  714. {
  715. Settings[punishment][listitem] = 0;
  716. }
  717. else
  718. {
  719. Settings[punishment][listitem]++;
  720. }
  721.  
  722. strdel(a_string, 0, sizeof(a_string));
  723.  
  724. for(new i = 0; i < DETECTIONS; i++)
  725. {
  726. if(strlen(a_string) > 0)
  727. {
  728. format(a_string, sizeof(a_string), "%s\n%s: ", a_string, GetHackNameFromType(i));
  729. }
  730. else
  731. {
  732. format(a_string, sizeof(a_string), "%s: ", GetHackNameFromType(i));
  733. }
  734.  
  735. if(Settings[punishment][i] == NOTHING)
  736. {
  737. format(a_string, sizeof(a_string), "%s{FF0000}Nothing", a_string);
  738. }
  739. else if(Settings[punishment][i] == BAN)
  740. {
  741. format(a_string, sizeof(a_string), "%s{00FF00}Ban", a_string);
  742. }
  743. else if(Settings[punishment][i] == KICK)
  744. {
  745. format(a_string, sizeof(a_string), "%s{00FF00}Kick", a_string);
  746. }
  747. else if(Settings[punishment][i] == WARN)
  748. {
  749. format(a_string, sizeof(a_string), "%s{00FF00}Admin Warning", a_string);
  750. }
  751. }
  752.  
  753. ShowPlayerDialog( playerid, DIALOG_ID_ANTICHEAT + 2, DIALOG_STYLE_LIST,
  754. "Anticheat Punishments", a_string,
  755. "Change", "Back");
  756. }
  757. return 1;
  758. }
  759.  
  760. if(dialogid == DIALOG_ID_ANTICHEAT + 3) // Detections, change detections.
  761. {
  762. if(PInfo[playerid][alevel] < 2) return 1;
  763. if(!response)
  764. {
  765. ShowAntiCheatDialog(playerid);
  766. return 1;
  767. }
  768. else
  769. {
  770. ToggleBool(Settings[detection][listitem]);
  771.  
  772. strdel(a_string, 0, sizeof(a_string));
  773.  
  774. for(new i = 0; i < DETECTIONS; i++)
  775. {
  776. if(strlen(a_string) > 0)
  777. {
  778. format(a_string, sizeof(a_string), "%s\n%s: ", a_string, GetHackNameFromType(i));
  779. }
  780. else
  781. {
  782. format(a_string, sizeof(a_string), "%s: ", GetHackNameFromType(i));
  783. }
  784.  
  785. if(Settings[detection][i])
  786. {
  787. format(a_string, sizeof(a_string), "%s{00FF00}ON", a_string);
  788. }
  789. else
  790. {
  791. format(a_string, sizeof(a_string), "%s{FF0000}OFF", a_string);
  792. }
  793. }
  794.  
  795. ShowPlayerDialog( playerid, DIALOG_ID_ANTICHEAT + 3, DIALOG_STYLE_LIST,
  796. "Anticheat Detections", a_string,
  797. "Change", "Back");
  798. }
  799. return 1;
  800. }
  801.  
  802. if(dialogid == DIALOG_ID_ANTICHEAT) // /anticheat
  803. {
  804. if(PInfo[playerid][alevel] < 2) return 1;
  805. if(!response)
  806. {
  807. return 1;
  808. }
  809. else
  810. {
  811. if(listitem == 0) // Information, including timing, amount of players detected.
  812. {
  813. format( a_string, sizeof(a_string),
  814. "Settings Time: %d\nPlayers Detected: %d",
  815. Timings[settingstime][1] - Timings[settingstime][0], Settings[detected]);
  816.  
  817. ShowPlayerDialog( playerid, DIALOG_ID_ANTICHEAT + 1, DIALOG_STYLE_MSGBOX,
  818. "Anticheat Information", a_string, "Back", "");
  819. }
  820. else if(listitem == 1) // Punishments, display/change punishments.
  821. {
  822. strdel(a_string, 0, sizeof(a_string));
  823.  
  824. for(new i = 0; i < DETECTIONS; i++)
  825. {
  826. if(strlen(a_string) > 0)
  827. {
  828. format(a_string, sizeof(a_string), "%s\n%s: ", a_string, GetHackNameFromType(i));
  829. }
  830. else
  831. {
  832. format(a_string, sizeof(a_string), "%s: ", GetHackNameFromType(i));
  833. }
  834.  
  835. if(Settings[punishment][i] == NOTHING)
  836. {
  837. format(a_string, sizeof(a_string), "%s{FF0000}Nothing", a_string);
  838. }
  839. else if(Settings[punishment][i] == BAN)
  840. {
  841. format(a_string, sizeof(a_string), "%s{00FF00}Ban", a_string);
  842. }
  843. else if(Settings[punishment][i] == KICK)
  844. {
  845. format(a_string, sizeof(a_string), "%s{00FF00}Kick", a_string);
  846. }
  847. else if(Settings[punishment][i] == WARN)
  848. {
  849. format(a_string, sizeof(a_string), "%s{00FF00}Admin Warning", a_string);
  850. }
  851. }
  852.  
  853. ShowPlayerDialog( playerid, DIALOG_ID_ANTICHEAT + 2, DIALOG_STYLE_LIST,
  854. "Anticheat Punishments", a_string,
  855. "Change", "Back");
  856. }
  857. else if(listitem == 2) // Detections, display/change detections.
  858. {
  859. strdel(a_string, 0, sizeof(a_string));
  860.  
  861. for(new i = 0; i < DETECTIONS; i++)
  862. {
  863. if(strlen(a_string) > 0)
  864. {
  865. format(a_string, sizeof(a_string), "%s\n%s: ", a_string, GetHackNameFromType(i));
  866. }
  867. else
  868. {
  869. format(a_string, sizeof(a_string), "%s: ", GetHackNameFromType(i));
  870. }
  871.  
  872. if(Settings[detection][i])
  873. {
  874. format(a_string, sizeof(a_string), "%s{00FF00}ON", a_string);
  875. }
  876. else
  877. {
  878. format(a_string, sizeof(a_string), "%s{FF0000}OFF", a_string);
  879. }
  880. }
  881.  
  882. ShowPlayerDialog( playerid, DIALOG_ID_ANTICHEAT + 3, DIALOG_STYLE_LIST,
  883. "Anticheat Detections", a_string,
  884. "Change", "Back");
  885. }
  886. else if(listitem == 3) // Toggle debug.
  887. {
  888. if(Settings[debugging]) Settings[debugging] = 0;
  889. else Settings[debugging] = 1;
  890. ShowAntiCheatDialog(playerid);
  891. }
  892. }
  893. return 1;
  894. }
  895. return 1;
  896. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement