ircecho.pwn 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  1. //#define dpsmap
  2. #include <a_samp>
  3. #include <a_http>
  4. #if defined dpsmap
  5. #include <djson>
  6. #endif
  7. #include <streamer>
  8. new rcontimer, playertimer, players, area;
  9. new unbanip[MAX_PLAYERS][16];
  10. new lastconnect[100][16];
  11. #if defined dpsmap
  12. new vehicledriver[47][24];
  13. new dps;
  14. #endif
  15. native gpci(playerid, serial[], maxlen);
  16. enum AC_STRUCT_INFO {
  17. Float:LastOnFootPosition[3],
  18. lastantijackstate,
  19. antijackcount,
  20. checkmaptp,
  21. maptplastclick,
  22. Float:maptp[3]
  23. }
  24. new acstruct[MAX_PLAYERS][AC_STRUCT_INFO];
  25. /*
  26. * Weapon information.
  27. */
  28. enum PCOR_ENU_WEAPON_INFO {
  29. WEP_SLOT_INDEX,
  30. WEP_NAME[32],
  31. WEP_MODEL_ID,
  32. Float:WEP_BASE_DAMAGE
  33. }
  34. /*
  35. // Other
  36. // -1+1 = unknown, 12-12 = index 12, but weapon should be ignored(id 40 - Detonator)
  37. new const WeaponIDToSlot[47] = { 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 10, 10, 10, 10, 10, 10, 8, 8, 8, -1+1, -1+1, -1+1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 4, 6, 6, 7, 7, 7, 7, 8, 12-12, 9, 9, 9, 11, 11, 11 };
  38. */
  39. stock const WEAPON_DATA[47][PCOR_ENU_WEAPON_INFO] = {
  40. { 0, "Fists", 0 , 1000.0000 }, // 0 Fists
  41. { 0, "Brassknuckle", 331 , 1000.0000 }, // 1 Brassknuckle
  42. { 1, "Golf club", 333 , 1000.0000 }, // 2 Golf
  43. { 1, "Nite stick", 334 , 1000.0000 }, // 3 Nite
  44. { 1, "Knife", 335 , 1000.0000 }, // 4 Knife
  45. { 1, "Baseball bat", 336 , 1000.0000 }, // 5 Baseball
  46. { 1, "Shovel", 337 , 1000.0000 }, // 6 Shovel
  47. { 1, "Pool stick", 338 , 1000.0000 }, // 7 Pool
  48. { 1, "Katakana", 339 , 1000.0000 }, // 8 Katakana
  49. { 1, "Chainsaw", 341 , 1000.0000 }, // 9 Chainsaw
  50. { 10, "Dildo", 321 , 1000.0000 }, // 10 Dildo
  51. { 10, "Dildo2", 322 , 1000.0000 }, // 11 Dildo2
  52. { 10, "Vibrator", 323 , 1000.0000 }, // 12 Vibrator
  53. { 10, "Vibrator2", 324 , 1000.0000 }, // 13 Vibrator2
  54. { 10, "Flowers", 325 , 1000.0000 }, // 14 Flowers
  55. { 10, "Cane", 326 , 1000.0000 }, // 15 Cane
  56. { 8, "Grenade", 342 , 1000.0000 }, // 16 Grenade
  57. { 8, "Teargas", 343 , 1000.0000 }, // 17 Teargas
  58. { 8, "Molotov cocktail", 344 , 1000.0000 }, // 18 Molotov
  59. { -1+1, "Rocket projectile", -1 , 1000.0000 }, // 19 Rocket
  60. { -1+1, "Heat seeking rocket projectile", -1 , 1000.0000 }, // 20 Heat
  61. { -1+1, "Hydra rocket projectile", 345 , 1000.0000 }, // 21 Hydra
  62. { 2, "Colt45", 346 , 8.2500 }, // 22 Colt45
  63. { 2, "Silenced pistol", 347 , 13.2000 }, // 23 Silenced
  64. { 2, "Desert Eagle", 348 , 46.2000 }, // 24 Desert
  65. { 3, "Shotgun", 349 , 3.3000 }, // 25 Shotgun
  66. { 3, "Sawn-off Shotgun", 350 , 3.3000 }, // 26 Sawn
  67. { 3, "Combat Shotgun", 351 , 4.9500 }, // 27 Combat
  68. { 4, "Micro Uzi", 352 , 6.6000 }, // 28 Micro
  69. { 4, "MP5", 353 , 8.2500 }, // 29 MP5
  70. { 5, "AK47", 355 , 9.9000 }, // 30 AK47
  71. { 5, "M4", 356 , 9.9000 }, // 31 M4
  72. { 4, "Tec9", 372 , 6.6000 }, // 32 Tec9
  73. { 6, "Rifle", 357 , 24.7500 }, // 33 Rifle
  74. { 6, "Sniper rifle", 358 , 41.2500 }, // 34 Sniper
  75. { 7, "Rocketlauncher", 359 , 1000.0000 }, // 35 Rocketlauncher
  76. { 7, "Heatseeking rocketlauncher", 360 , 1000.0000 }, // 36 Heatseeking
  77. { 7, "Flamethrower", 361 , 1000.0000 }, // 37 Flamethrower (Cannot handle this properly.. seems like game calculates this on the fly, not properly divided by anything.)
  78. { 7, "Minigun", 362 , 1000.0000 }, // 38 Minigun
  79. { 8, "Satchel", 363 , 1000.0000 }, // 39 Satchel
  80. { 12-12,"Detonator", 364 , 1000.0000 }, // 40 Detonator
  81. { 9, "Spraycan", 365 , 0.3300 }, // 41 Spraycan
  82. { 9, "Fire extinguisher", 366 , 1000.0000 }, // 42 Fire (Cannot handle this properly.. seems like game calculates this on the fly, not properly divided by anything.)
  83. { 9, "Camera", 367 , 1000.0000 }, // 43 Camera
  84. { 11, "Nightvision Goggles", 368 , 1000.0000 }, // 44 Nightvision
  85. { 11, "Thermal Goggles", 369 , 1000.0000 }, // 45 Thermal
  86. { 11, "Parachute", 371 , 1000.0000 } // 46 Parachute
  87. };
  88. public OnFilterScriptInit()
  89. {
  90. for(new x;x<MAX_PLAYERS;x++)
  91. {
  92. if(IsPlayerConnected(x))
  93. {
  94. players++;
  95. #if defined dpsmap
  96. if(GetPlayerState(x) == PLAYER_STATE_DRIVER)
  97. {
  98. if(GetPlayerVehicleID(x) >= 96 && GetPlayerVehicleID(x) <= 142)
  99. {
  100. GetPlayerName(x, vehicledriver[GetPlayerVehicleID(x)-96], MAX_PLAYER_NAME);
  101. }
  102. }
  103. #endif
  104. }
  105. }
  106. CreateDynamicObject(2103, 2545.2825,1412.0287,7698.5845, 0.0, 0.0, 0.0);
  107. CreateDynamic3DTextLabel("Check out {FF0000}shop.ng-gaming.net{FFFF00} to get a boombox!\n\nVIP's boombox\n{FF0000}/setboombox {FFFF00}or\n{FF0000}/destroyboombox",0xFFFF00AA, 2545.2825,1412.0287,7699.5845+0.6, 5.0);
  108. //area = CreateDynamicSphere(2547.0, 1410.0, 7699.0, 200.0);
  109. PlayerGraph();
  110. #if defined dpsmap
  111. djson_GameModeInit();
  112. #endif
  113. AddEchoMessage("p=IRC Echo Initialized");
  114. rcontimer=SetTimer("RconEcho", 1000, true);
  115. playertimer=SetTimer("PlayerGraph", 300000, true);
  116. #if defined dpsmap
  117. dps=SetTimer("DPSGraph", 5000, true);
  118. #endif
  119. return 1;
  120. }
  121. public OnFilterScriptExit()
  122. {
  123. KillTimer(rcontimer);
  124. KillTimer(playertimer);
  125. #if defined dpsmap
  126. KillTimer(dps);
  127. djson_GameModeExit();
  128. #endif
  129. return 1;
  130. }
  131. forward Disconnect(playerid);
  132. public Disconnect(playerid)
  133. {
  134. new string[24];
  135. GetPlayerIp(playerid, unbanip[playerid], 16);
  136. format(string, sizeof(string), "banip %s", unbanip[playerid]);
  137. SendRconCommand(string);
  138. }
  139. public OnPlayerConnect(playerid)
  140. {
  141. new string[128], serial[64], name[MAX_PLAYER_NAME], ip[16];
  142. GetPlayerIp(playerid, ip, sizeof(ip));
  143. gpci(playerid, serial, sizeof(serial));
  144. GetPlayerName(playerid, name, sizeof(name));
  145. new count;
  146. for(new x;x<sizeof(lastconnect);x++)
  147. {
  148. if(strlen(lastconnect[x]) < 1)
  149. {
  150. format(lastconnect[x], 16, "%s", ip);
  151. SetTimerEx("removeip", 5000, false, "i", x);
  152. break;
  153. }
  154. }
  155. for(new x;x<sizeof(lastconnect);x++)
  156. {
  157. if(strlen(lastconnect[x]) > 0 && strcmp(ip, lastconnect[x]) == 0) count++;
  158. }
  159. if(count > 5)
  160. {
  161. Kick(playerid);
  162. format(string, sizeof(string), "banip %s", ip);
  163. SendRconCommand(string);
  164. SetTimerEx("Unban", ((60*1000)*5), false, "s", ip);
  165. format(string, sizeof(string), "p=blocked %s - %s [%d] - %s", name, ip, count, serial);
  166. AddEchoMessage(string);
  167. return 1;
  168. }
  169. players++;
  170. if((strcmp(serial, "90E44CE48A4C059CC8D848D98D9E8D084F0D8844", true) == 0))
  171. {
  172. GetPlayerName(playerid, name, sizeof(name));
  173. format(string, sizeof(string), "p=%s %d (%s) may be ban evading (F)", name, playerid, ip);
  174. AddEchoMessage(string);
  175. }
  176. if((strcmp(serial, "E8C49D8848484584A94D908A8CEA9D98D85DDA99", true) == 0))
  177. {
  178. GetPlayerName(playerid, name, sizeof(name));
  179. format(string, sizeof(string), "p=%s %d (%s) may be ban evading (F_H)", name, playerid, ip);
  180. AddEchoMessage(string);
  181. }
  182. return 1;
  183. }
  184. forward removeip(x);
  185. public removeip(x)
  186. {
  187. format(lastconnect[x], 16, "");
  188. }
  189. forward Unban(ip[]);
  190. public Unban(ip[])
  191. {
  192. new string[128];
  193. format(string, sizeof(string), "unbanip %s", ip);
  194. SendRconCommand(string);
  195. format(string, sizeof(string), "p=unblocking %s [block expired]", ip);
  196. AddEchoMessage(string);
  197. }
  198. public OnPlayerDisconnect(playerid)
  199. {
  200. if(strlen(unbanip[playerid]) > 0)
  201. {
  202. new string[26];
  203. format(string, sizeof(string), "unbanip %s", unbanip[playerid]);
  204. SendRconCommand(string);
  205. }
  206. players--;
  207. acstruct[playerid][lastantijackstate] = 0; acstruct[playerid][antijackcount] = 0;
  208. acstruct[playerid][LastOnFootPosition][0] = 0.0; acstruct[playerid][LastOnFootPosition][1] = 0.0; acstruct[playerid][LastOnFootPosition][2] = 0.0;
  209. acstruct[playerid][antijackcount] = 0; acstruct[playerid][checkmaptp] = 0; acstruct[playerid][maptplastclick] = 0; acstruct[playerid][lastantijackstate] = 0;
  210. acstruct[playerid][maptp][0] = 0.0; acstruct[playerid][maptp][1] = 0.0; acstruct[playerid][maptp][2] = 0.0;
  211. return 1;
  212. }
  213. public OnPlayerSpawn(playerid)
  214. {
  215. acstruct[playerid][lastantijackstate] = 0;
  216. acstruct[playerid][antijackcount] = 0;
  217. return 1;
  218. }
  219. forward PlayerGraph();
  220. public PlayerGraph()
  221. {
  222. new string[6];
  223. format(string, sizeof(string), "p=%d", players);
  224. HTTP(0, HTTP_POST, "samp.ng-gaming.net/scott/misc/players.php", string, "");
  225. return 1;
  226. }
  227. #if defined dpsmap
  228. forward DPSGraph();
  229. public DPSGraph()
  230. {
  231. new Float:tmp_float;
  232. new Float:tmp_floatx,Float:tmp_floaty;
  233. new tmp[255], tmp2[255];
  234. djAutocommit(false);
  235. for (new i=96;i<142;i++) {
  236. format(tmp,255,"items/p%d/id",i);
  237. djSetInt("map.json",tmp,i);
  238. format(tmp2,255,"Vehicle ID: %d",i);
  239. format(tmp,255,"items/p%d/name",i);
  240. djSet("map.json",tmp,tmp2);
  241. format(tmp,255,"items/p%d/icon",i);
  242. djSet("map.json",tmp,"30");
  243. format(tmp2,255,"%s",vehicledriver[i-96]);
  244. format(tmp,255,"items/p%d/text",i);
  245. djSet("map.json",tmp,tmp2);
  246. GetVehiclePos(i,tmp_floatx,tmp_floaty,tmp_float);
  247. format(tmp,255,"items/p%d/pos/x",i);
  248. djSetInt("map.json",tmp,floatround(tmp_floatx));
  249. format(tmp,255,"items/p%d/pos/y",i);
  250. djSetInt("map.json",tmp,floatround(tmp_floaty));
  251. }
  252. djCommit("map.json");
  253. djAutocommit(true);
  254. return 1;
  255. }
  256. #endif
  257. #if defined dpsmap
  258. public OnPlayerStateChange(playerid, newstate, oldstate)
  259. {
  260. if(newstate == PLAYER_STATE_DRIVER)
  261. {
  262. if(GetPlayerVehicleID(playerid) >= 96 && GetPlayerVehicleID(playerid) <= 142)
  263. {
  264. GetPlayerName(playerid, vehicledriver[GetPlayerVehicleID(playerid)-96], MAX_PLAYER_NAME);
  265. }
  266. }
  267. return 1;
  268. }
  269. #endif
  270. forward RconEcho();
  271. public RconEcho()
  272. {
  273. if(fexist("recho.txt"))
  274. {
  275. new string[128];
  276. new File:rcon = fopen("recho.txt", io_read);
  277. fread(rcon, string);
  278. fclose(rcon);
  279. fremove("recho.txt");
  280. format(string, sizeof(string), "say %s", string);
  281. SendRconCommand(string);
  282. format(string, sizeof(string), "p=%s", string);
  283. AddEchoMessage(string);
  284. }
  285. return 1;
  286. }
  287. public OnPlayerTakeDamage(playerid, issuerid, Float:amount, weaponid)
  288. {
  289. if(weaponid < 47)
  290. {
  291. // we only care about who took damage, not who received it.
  292. #pragma unused issuerid
  293. if (amount > 1833.33) // some weird glitch
  294. return 1;
  295. if ((WEAPON_DATA[weaponid][WEP_BASE_DAMAGE] < 1000.0) && (amount != 2.64)) {
  296. new upped = 0;
  297. new amountupped = 0;
  298. upped = floatround(WEAPON_DATA[weaponid][WEP_BASE_DAMAGE] * 10000, floatround_floor);
  299. amountupped = floatround(amount * 10000, floatround_floor);
  300. new rem = amountupped % upped;
  301. if (rem != 0) {
  302. new tmpstr[25], tmpstrrepc[25];
  303. format(tmpstr, 25, "WDATRT_%d_%0.4f", weaponid, amount);
  304. format(tmpstrrepc, 25, "WDATRN_%d_%0.4f", weaponid, amount);
  305. new lasttime = GetPVarInt(playerid, tmpstr);
  306. new reportcnt = GetPVarInt(playerid, tmpstrrepc);
  307. new rtd = GetTickCount()-lasttime;
  308. if ((lasttime == 0) || (rtd > 3000)) {
  309. reportcnt++;
  310. new string[128], name[MAX_PLAYER_NAME];
  311. GetPlayerName(playerid, name, sizeof(name));
  312. format(string, sizeof(string), "p=[weapon_dat] %s %d %d %0.5f %0.5f %d", name, playerid, weaponid, amount, WEAPON_DATA[weaponid][WEP_BASE_DAMAGE], reportcnt);
  313. AddEchoMessage(string);
  314. SetPVarInt(playerid, tmpstr, GetTickCount());
  315. SetPVarInt(playerid, tmpstrrepc, reportcnt);
  316. }
  317. }
  318. }
  319. }
  320. return 1;
  321. }
  322. stock Float:Distance( Float: x1, Float: y1, Float: z1, Float: x2, Float: y2, Float: z2 )
  323. {
  324. new Float:d;
  325. d += floatpower(x1-x2, 2.0 );
  326. d += floatpower(y1-y2, 2.0 );
  327. d += floatpower(z1-z2, 2.0 );
  328. d = floatsqroot(d);
  329. return d;
  330. }
  331. check_remote_jacking(PlayerID)
  332. {
  333. new currstate = GetPlayerVehicleID(PlayerID);
  334. if (!IsPlayerInAnyVehicle(PlayerID)) // always remember last onfoot coords.
  335. GetPlayerPos(PlayerID, acstruct[PlayerID][LastOnFootPosition][0], acstruct[PlayerID][LastOnFootPosition][1], acstruct[PlayerID][LastOnFootPosition][2]);
  336. if ((currstate != acstruct[PlayerID][lastantijackstate]) && (currstate != 0) && (GetPlayerState(PlayerID) == PLAYER_STATE_DRIVER)) {
  337. new Float:Tmppos[3];
  338. GetVehiclePos(GetPlayerVehicleID(PlayerID), Tmppos[0], Tmppos[1], Tmppos[2]);
  339. new Float:distancejack = 0.0;
  340. distancejack = Distance(Tmppos[0], Tmppos[1], Tmppos[2], acstruct[PlayerID][LastOnFootPosition][0], acstruct[PlayerID][LastOnFootPosition][1], acstruct[PlayerID][LastOnFootPosition][2]);
  341. new thiscaride;
  342. thiscaride = GetVehicleModel(GetPlayerVehicleID(PlayerID));
  343. new Float:distanceth = 10.0; // some sane random value
  344. if ((thiscaride == 577) || (thiscaride == 592)) //ignore AT-400 and andromada (false positives spam)
  345. distanceth = 25.0;
  346. if (distancejack > distanceth) {
  347. if(acstruct[PlayerID][antijackcount] > 2)
  348. {
  349. new issin = 0;
  350. if (IsVehicleStreamedIn(GetPlayerVehicleID(PlayerID), PlayerID))
  351. issin = 1;
  352. new sTemp2[256];
  353. new pNickname[MAX_PLAYER_NAME];
  354. GetPlayerName(PlayerID, pNickname, sizeof(pNickname)); // LDC: %d
  355. format(sTemp2, sizeof(sTemp2), "p=[checkremotejack] %s %d vid: %d IDE: %d distance: %0.1f (%0.2f, %0.2f, %0.2f -> %0.2f, %0.2f, %0.2f ) streamed: %d", pNickname, PlayerID, currstate, thiscaride, distancejack, Tmppos[0], Tmppos[1], Tmppos[2], acstruct[PlayerID][LastOnFootPosition][0], acstruct[PlayerID][LastOnFootPosition][1], acstruct[PlayerID][LastOnFootPosition][2], GetTickCount() /*- pLastDrunkChange[PlayerID]*/, issin);
  356. AddEchoMessage(sTemp2);
  357. Disconnect(PlayerID);
  358. }
  359. acstruct[PlayerID][antijackcount]++;
  360. }
  361. // This is now assumed last position, so we can see if player teleported from one car to another.
  362. GetPlayerPos(PlayerID, acstruct[PlayerID][LastOnFootPosition][0], acstruct[PlayerID][LastOnFootPosition][1], acstruct[PlayerID][LastOnFootPosition][2]);
  363. acstruct[PlayerID][lastantijackstate] = currstate;
  364. }
  365. }
  366. public OnPlayerUpdate(playerid)
  367. {
  368. check_remote_jacking(playerid);
  369. return 1;
  370. }
  371. stock AddEchoMessage(string[])
  372. {
  373. HTTP(0, HTTP_POST, "samp.ng-gaming.net/scott/irc/post.php", string, "");
  374. return 1;
  375. }
  376. /*public OnPlayerEnterDynamicArea(playerid, areaid)
  377. {
  378. if(areaid == area)
  379. {
  380. PlayAudioStreamForPlayer(playerid, "http://yp.shoutcast.com/sbin/tunein-station.pls?id=1280356", 2547.0, 1410.0, 7699.0, 200.0, 1);
  381. }
  382. return 1;
  383. }
  384. public OnPlayerLeaveDynamicArea(playerid, areaid)
  385. {
  386. if(areaid == area)
  387. {
  388. StopAudioStreamForPlayer(playerid);
  389. }
  390. return 1;
  391. }*/