Advertisement
Guest User

Untitled

a guest
Nov 5th, 2016
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 86.63 KB | None | 0 0
  1. package com.rs.net.decoders;
  2.  
  3. import com.rs.Settings;
  4. import com.rs.cache.loaders.ItemDefinitions;
  5. import com.rs.cache.loaders.QuickChatOptionDefinition;
  6. import com.rs.game.Animation;
  7. import com.rs.game.Graphics;
  8. import com.rs.game.TemporaryAtributtes.Key;
  9. import com.rs.game.World;
  10. import com.rs.game.WorldObject;
  11. import com.rs.game.WorldTile;
  12. import com.rs.game.item.FloorItem;
  13. import com.rs.game.item.Item;
  14. import com.rs.game.map.bossInstance.BossInstanceHandler;
  15. import com.rs.game.map.bossInstance.BossInstanceHandler.Boss;
  16. import com.rs.game.minigames.Sawmill;
  17. import com.rs.game.minigames.Sawmill.Plank;
  18. import com.rs.game.minigames.clanwars.ClanWars;
  19. import com.rs.game.minigames.duel.DuelArena;
  20. import com.rs.game.minigames.stealingcreation.StealingCreationController;
  21. import com.rs.game.minigames.stealingcreation.StealingCreationLobbyController;
  22. import com.rs.game.npc.NPC;
  23. import com.rs.game.npc.familiar.Familiar;
  24. import com.rs.game.npc.familiar.Familiar.SpecialAttack;
  25. import com.rs.game.npc.others.DoorSupport;
  26. import com.rs.game.player.ActionBar;
  27. import com.rs.game.player.ActionBar.DefenceAbilityShortcut;
  28. import com.rs.game.player.ActionBar.HealAbilityShortcut;
  29. import com.rs.game.player.ActionBar.ItemShortcut;
  30. import com.rs.game.player.ActionBar.MagicAbilityShortcut;
  31. import com.rs.game.player.ActionBar.MeleeAbilityShortcut;
  32. import com.rs.game.player.ActionBar.PrayerShortcut;
  33. import com.rs.game.player.ActionBar.RangeAbilityShortcut;
  34. import com.rs.game.player.ActionBar.StrengthAbilityShortcut;
  35. import com.rs.game.player.ChatMessage;
  36. import com.rs.game.player.FarmingManager.FarmingSpot;
  37. import com.rs.game.player.FarmingManager.SpotInfo;
  38. import com.rs.game.player.InterfaceManager;
  39. import com.rs.game.player.Inventory;
  40. import com.rs.game.player.LogicPacket;
  41. import com.rs.game.player.MoneyPouch;
  42. import com.rs.game.player.Player;
  43. import com.rs.game.player.PublicChatMessage;
  44. import com.rs.game.player.QuickChatMessage;
  45. import com.rs.game.player.RouteEvent;
  46. import com.rs.game.player.Skills;
  47. import com.rs.game.player.actions.Firemaking;
  48. import com.rs.game.player.actions.GlassBlowing;
  49. import com.rs.game.player.actions.Firemaking.Fire;
  50. import com.rs.game.player.actions.PlayerCombatNew;
  51. import com.rs.game.player.actions.PlayerFollow;
  52. import com.rs.game.player.actions.PowerOrbs;
  53. import com.rs.game.player.actions.Smithing;
  54. import com.rs.game.player.content.AccessorySmithing;
  55. import com.rs.game.player.content.FriendsChat;
  56. import com.rs.game.player.content.ItemConstants;
  57. import com.rs.game.player.content.Magic;
  58. import com.rs.game.player.content.Shop;
  59. import com.rs.game.player.content.SkillCapeCustomizer;
  60. import com.rs.game.player.content.Summoning;
  61. import com.rs.game.player.content.TicketSystem;
  62. import com.rs.game.player.content.TicketSystem.TicketEntry;
  63. import com.rs.game.player.content.clans.ClansManager;
  64. import com.rs.game.player.content.commands.Commands;
  65. import com.rs.game.player.content.construction.House;
  66. import com.rs.game.player.content.construction.TabletMaking;
  67. import com.rs.game.player.content.grandExchange.GrandExchange;
  68. import com.rs.game.player.content.pet.Pets;
  69. import com.rs.game.player.controllers.Controller;
  70. import com.rs.game.player.controllers.DungeonController;
  71. import com.rs.game.player.controllers.SawmillController;
  72. import com.rs.game.player.dialogues.impl.EnchantingOrbsDialogue;
  73. import com.rs.game.player.dialogues.impl.PetShopOwner;
  74. import com.rs.game.player.dialogues.impl.SkillAlchemist;
  75. import com.rs.game.route.RouteFinder;
  76. import com.rs.game.route.strategy.FixedTileStrategy;
  77. import com.rs.game.tasks.WorldTask;
  78. import com.rs.game.tasks.WorldTasksManager;
  79. import com.rs.io.InputStream;
  80. import com.rs.login.account.Account;
  81. import com.rs.net.LoginClientChannelManager;
  82. import com.rs.net.LoginProtocol;
  83. import com.rs.net.Session;
  84. import com.rs.net.decoders.handlers.ButtonHandler;
  85. import com.rs.net.decoders.handlers.InventoryOptionsHandler;
  86. import com.rs.net.decoders.handlers.NPCHandler;
  87. import com.rs.net.decoders.handlers.ObjectHandler;
  88. import com.rs.net.encoders.LoginChannelsPacketEncoder;
  89. import com.rs.utils.ItemExamines;
  90. import com.rs.utils.Logger;
  91. import com.rs.utils.LoginFilesManager;
  92. import com.rs.utils.ReportAbuse;
  93. import com.rs.utils.Utils;
  94. import com.rs.utils.huffman.Huffman;
  95.  
  96. public final class WorldPacketsDecoder extends Decoder {
  97.  
  98. private static final byte[] PACKET_SIZES = new byte[121];
  99.  
  100. private final static int WALKING_PACKET = 50;
  101. private final static int MINI_WALKING_PACKET = 63;
  102. public final static int ACTION_BUTTON1_PACKET = 103;
  103. public final static int ACTION_BUTTON2_PACKET = 7;
  104. public final static int ACTION_BUTTON3_PACKET = 113;
  105. public final static int ACTION_BUTTON4_PACKET = 29;
  106. public final static int ACTION_BUTTON5_PACKET = 65;
  107. public final static int ACTION_BUTTON6_PACKET = 87;
  108. public final static int ACTION_BUTTON7_PACKET = 21;
  109. public final static int ACTION_BUTTON8_PACKET = 66;
  110. public final static int ACTION_BUTTON9_PACKET = 27;
  111. public final static int ACTION_BUTTON10_PACKET = 64;
  112. public final static int WORLD_MAP_CLICK = 40;
  113. public final static int RECEIVE_PACKET_COUNT_PACKET = 58;
  114. private final static int PLAYER_OPTION_3_PACKET = 55;
  115. private final static int PLAYER_OPTION_4_PACKET = 106;
  116. private final static int PLAYER_OPTION_6_PACKET = 98;
  117. private final static int MOVE_CAMERA_PACKET = 16;
  118. private final static int INTERFACE_ON_OBJECT = 109;
  119. private final static int CLICK_PACKET = 95;
  120. private final static int CLICK_PACKET_2 = 59;
  121. private final static int MOUVE_MOUSE_PACKET = 46;
  122. private final static int MOUSE_MOVEMENT_DELAY = 2;
  123. private final static int KEY_TYPED_PACKET = 68;
  124. private final static int CLOSE_INTERFACE_PACKET = 36;
  125. private final static int COMMANDS_PACKET = 24;
  126. private final static int INTERFACE_ON_INTERFACE = 90;
  127. private final static int IN_OUT_SCREEN_PACKET = 54;
  128. private final static int DONE_LOADING_REGION_PACKET = 61;
  129. private final static int PING_PACKET = 100;
  130. private final static int SCREEN_PACKET = 86;
  131. private final static int CHAT_TYPE_PACKET = 91;
  132. private final static int CHAT_PACKET = 77;
  133. private final static int PUBLIC_QUICK_CHAT_PACKET = 20;
  134. private final static int ADD_FRIEND_PACKET = 85;
  135. private final static int ADD_IGNORE_PACKET = 80;
  136. private final static int REMOVE_IGNORE_PACKET = 53;
  137. private final static int JOIN_FRIEND_CHAT_PACKET = 43;
  138. private final static int CHANGE_FRIEND_CHAT_PACKET = 51;
  139. private final static int KICK_FRIEND_CHAT_PACKET = 28;
  140. private final static int KICK_CLAN_CHAT_PACKET = 71;
  141. private final static int REMOVE_FRIEND_PACKET = 14;
  142. private final static int SEND_FRIEND_MESSAGE_PACKET = 47;
  143. private final static int SEND_FRIEND_QUICK_CHAT_PACKET = 101;
  144. private final static int OBJECT_CLICK1_PACKET = 38;
  145. private final static int OBJECT_CLICK2_PACKET = 42;
  146. private final static int OBJECT_CLICK3_PACKET = 94;
  147. private final static int OBJECT_CLICK4_PACKET = 41;
  148. private final static int OBJECT_CLICK5_PACKET = 17;
  149. private final static int OBJECT_EXAMINE_PACKET = 118;
  150. private final static int NPC_CLICK1_PACKET = 92;
  151. private final static int ATTACK_NPC_PACKET = 32;
  152. private final static int NPC_CLICK2_PACKET = 60;
  153. private final static int NPC_CLICK3_PACKET = 117;
  154. private final static int NPC_CLICK4_PACKET = 1;
  155. private static final int NPC_EXAMINE_PACKET = 0;
  156. private final static int PLAYER_OPTION_1_PACKET = 3;
  157. private final static int PLAYER_OPTION_2_PACKET = 110;
  158. private final static int PLAYER_OPTION_9_PACKET = 39;
  159. private final static int ITEM_TAKE_PACKET = 12;
  160. private final static int ITEM_EXAMINE_PACKET = 84;
  161. private final static int GROUND_ITEM_OPTION_2 = 75;
  162. private final static int DIALOGUE_CONTINUE_PACKET = 104;
  163. private final static int ENTER_INTEGER_PACKET = 116;
  164. private final static int ENTER_NAME_PACKET = 23;
  165. private final static int ENTER_LONG_TEXT_PACKET = 76;
  166. private final static int SWITCH_INTERFACE_COMPONENTS_PACKET = 74;
  167. private final static int INTERFACE_ON_PLAYER = 114;
  168. private final static int INTERFACE_ON_NPC = 37;
  169. private final static int INTERFACE_ON_GROUND = 30;
  170. private final static int COLOR_ID_PACKET = 93;
  171. private static final int FORUM_THREAD_ID_PACKET = 31;
  172. private final static int OPEN_URL_PACKET = 108;
  173. private final static int REPORT_ABUSE_PACKET = 49;
  174. private final static int GRAND_EXCHANGE_ITEM_SELECT_PACKET = 69;
  175. private final static int WORLD_LIST_UPDATE = 79;
  176. private final static int UPDATE_GAMEBAR_PACKET = 111;
  177. private final static int NIS_VAR_PACKET = 119;
  178. private final static int MUSIC_PACKET = 99;
  179. private final static int REQUEST_PLAY_MUSIC_PACKET = 45;
  180. private final static int CUTSCENE_DONE_PACKET = 62;
  181. private final static int GARBAGE_CLEAR_PACKET = 13;
  182.  
  183. static {
  184. loadPacketSizes();
  185. }
  186.  
  187. public static void loadPacketSizes() {
  188. PACKET_SIZES[0] = 3;
  189. PACKET_SIZES[1] = 3;
  190. PACKET_SIZES[2] = -1;
  191. PACKET_SIZES[3] = 3;
  192. PACKET_SIZES[4] = 0;
  193. PACKET_SIZES[5] = -2;
  194. PACKET_SIZES[6] = 15;
  195. PACKET_SIZES[7] = 8;
  196. PACKET_SIZES[8] = -1;
  197. PACKET_SIZES[9] = 4;
  198. PACKET_SIZES[10] = -1;
  199. PACKET_SIZES[11] = -1;
  200. PACKET_SIZES[12] = 7;
  201. PACKET_SIZES[13] = 4;
  202. PACKET_SIZES[14] = -1;
  203. PACKET_SIZES[15] = -2;
  204. PACKET_SIZES[16] = 4;
  205. PACKET_SIZES[17] = 9;
  206. PACKET_SIZES[18] = 3;
  207. PACKET_SIZES[19] = -1;
  208. PACKET_SIZES[20] = -1;
  209. PACKET_SIZES[21] = 8;
  210. PACKET_SIZES[22] = -1;
  211. PACKET_SIZES[23] = -1;
  212. PACKET_SIZES[24] = -1;
  213. PACKET_SIZES[25] = 7;
  214. PACKET_SIZES[26] = -1;
  215. PACKET_SIZES[27] = 8;
  216. PACKET_SIZES[28] = -1;
  217. PACKET_SIZES[29] = 8;
  218. PACKET_SIZES[30] = 15;
  219. PACKET_SIZES[31] = -1;
  220. PACKET_SIZES[32] = 3;
  221. PACKET_SIZES[33] = 1;
  222. PACKET_SIZES[34] = -2;
  223. PACKET_SIZES[35] = -1;
  224. PACKET_SIZES[36] = 0;
  225. PACKET_SIZES[37] = 11;
  226. PACKET_SIZES[38] = 9;
  227. PACKET_SIZES[39] = 3;
  228. PACKET_SIZES[40] = 4;
  229. PACKET_SIZES[41] = 9;
  230. PACKET_SIZES[42] = 9;
  231. PACKET_SIZES[43] = -1;
  232. PACKET_SIZES[44] = 9;
  233. PACKET_SIZES[45] = 4;
  234. PACKET_SIZES[46] = -1;
  235. PACKET_SIZES[47] = -2;
  236. PACKET_SIZES[48] = -1;
  237. PACKET_SIZES[49] = -1;
  238. PACKET_SIZES[50] = 5;
  239. PACKET_SIZES[51] = -1;
  240. PACKET_SIZES[52] = 0;
  241. PACKET_SIZES[53] = -1;
  242. PACKET_SIZES[54] = 1;
  243. PACKET_SIZES[55] = 3;
  244. PACKET_SIZES[56] = 9;
  245. PACKET_SIZES[57] = -2;
  246. PACKET_SIZES[58] = 4;
  247. PACKET_SIZES[59] = 7;
  248. PACKET_SIZES[60] = 3;
  249. PACKET_SIZES[61] = 0;
  250. PACKET_SIZES[62] = 1;
  251. PACKET_SIZES[63] = 18;
  252. PACKET_SIZES[64] = 8;
  253. PACKET_SIZES[65] = 8;
  254. PACKET_SIZES[66] = 8;
  255. PACKET_SIZES[67] = 1;
  256. PACKET_SIZES[68] = -2;
  257. PACKET_SIZES[69] = 2;
  258. PACKET_SIZES[70] = 0;
  259. PACKET_SIZES[71] = -1;
  260. PACKET_SIZES[72] = 4;
  261. PACKET_SIZES[73] = 12;
  262. PACKET_SIZES[74] = 16;
  263. PACKET_SIZES[75] = 7;
  264. PACKET_SIZES[76] = -1;
  265. PACKET_SIZES[77] = -1;
  266. PACKET_SIZES[78] = 1;
  267. PACKET_SIZES[79] = 4;
  268. PACKET_SIZES[80] = -1;
  269. PACKET_SIZES[81] = -1;
  270. PACKET_SIZES[82] = 18;
  271. PACKET_SIZES[83] = -1;
  272. PACKET_SIZES[84] = 7;
  273. PACKET_SIZES[85] = -1;
  274. PACKET_SIZES[86] = 6;
  275. PACKET_SIZES[87] = 8;
  276. PACKET_SIZES[88] = -2;
  277. PACKET_SIZES[89] = 5;
  278. PACKET_SIZES[90] = 16;
  279. PACKET_SIZES[91] = 1;
  280. PACKET_SIZES[92] = 3;
  281. PACKET_SIZES[93] = 2;
  282. PACKET_SIZES[94] = 9;
  283. PACKET_SIZES[95] = 6;
  284. PACKET_SIZES[96] = 2;
  285. PACKET_SIZES[97] = 3;
  286. PACKET_SIZES[98] = 3;
  287. PACKET_SIZES[99] = 4;
  288. PACKET_SIZES[100] = 0;
  289. PACKET_SIZES[101] = -1;
  290. PACKET_SIZES[102] = 3;
  291. PACKET_SIZES[103] = 8;
  292. PACKET_SIZES[104] = 6;
  293. PACKET_SIZES[105] = 7;
  294. PACKET_SIZES[106] = 3;
  295. PACKET_SIZES[107] = 7;
  296. PACKET_SIZES[108] = -2;
  297. PACKET_SIZES[109] = 17;
  298. PACKET_SIZES[110] = 3;
  299. PACKET_SIZES[111] = 3;
  300. PACKET_SIZES[112] = -2;
  301. PACKET_SIZES[113] = 8;
  302. PACKET_SIZES[114] = 11;
  303. PACKET_SIZES[115] = 3;
  304. PACKET_SIZES[116] = 4;
  305. PACKET_SIZES[117] = 3;
  306. PACKET_SIZES[118] = 9;
  307. PACKET_SIZES[119] = -2;
  308. PACKET_SIZES[120] = -2;
  309. }
  310.  
  311. private Player player;
  312. private int chatType;
  313.  
  314. // temp spam protection
  315. private int[] pthrotlecounter = new int[256];
  316. private long[] pthrotletimer = new long[256];
  317.  
  318. // temp spam protection
  319.  
  320. public WorldPacketsDecoder(Session session, Player player) {
  321. super(session);
  322. this.player = player;
  323. }
  324.  
  325. @Override
  326. public int decode(InputStream stream) {
  327. while (stream.getRemaining() > 0 && !player.hasFinished()) {
  328. int start = stream.getOffset();
  329. int opcode = stream.readPacket(player);
  330. if (opcode < 0 || opcode >= PACKET_SIZES.length) {
  331. if (Settings.DEBUG)
  332. System.out.println("Invalid opcode: " + opcode + ".");
  333. return -1; // drop
  334. }
  335.  
  336. int length = PACKET_SIZES[opcode];
  337. if ((length == -1 && stream.getRemaining() < 1) || (length == -2 && stream.getRemaining() < 2))
  338. return start;
  339.  
  340. if (length == -1)
  341. length = stream.readUnsignedByte();
  342. else if (length == -2)
  343. length = stream.readUnsignedShort();
  344.  
  345. if (stream.getRemaining() < length) {
  346. return start;
  347. }
  348.  
  349. byte[] data = new byte[length];
  350. stream.readBytes(data);
  351. try {
  352. processPackets(opcode, new InputStream(data));
  353. } catch (Throwable e) {
  354. Logger.handle(e);
  355. }
  356. }
  357. return stream.getOffset();
  358. }
  359.  
  360. public static void decodeLogicPacket(final Player player, LogicPacket packet) {
  361. int opcode = packet.getId();
  362. InputStream stream = packet.getStream();
  363. if (opcode == WALKING_PACKET || opcode == MINI_WALKING_PACKET) {
  364. if (!player.hasStarted() || !player.clientHasLoadedMapRegion() || player.isDead())
  365. return;
  366. if (player.isLocked() || player.isCantWalk() || player.isStunned())
  367. return;
  368. if (player.isBound()) {
  369. player.getPackets().sendGameMessage("A magical force prevents you from moving.");
  370. return;
  371. }
  372. int toX = stream.readUnsignedShort();
  373. boolean forceRun = stream.readUnsigned128Byte() == 1;
  374. int toY = stream.readUnsignedShortLE();
  375. player.stopAll();
  376. if (forceRun)
  377. player.setRun(forceRun);
  378. int steps = RouteFinder.findRoute(RouteFinder.WALK_ROUTEFINDER, player.getX(), player.getY(),
  379. player.getPlane(), player.getSize(), new FixedTileStrategy(toX, toY), true);
  380. int[] bufferX = RouteFinder.getLastPathBufferX();
  381. int[] bufferY = RouteFinder.getLastPathBufferY();
  382. int last = -1;
  383. for (int i = steps - 1; i >= 0; i--) {
  384. if (!player.addWalkSteps(bufferX[i], bufferY[i], 25, true))
  385. break;
  386. last = i;
  387. }
  388.  
  389. if (last != -1) {
  390. WorldTile tile = new WorldTile(bufferX[last], bufferY[last], player.getPlane());
  391. player.getPackets().sendMinimapFlag(tile.getXInScene(player), tile.getYInScene(player));
  392. } else {
  393. player.getPackets().sendResetMinimapFlag();
  394. }
  395. } else if (opcode == INTERFACE_ON_PLAYER) {
  396. if (!player.hasStarted() || !player.clientHasLoadedMapRegion() || player.isDead())
  397. return;
  398. if (player.isLocked() || player.getEmotesManager().isDoingEmote())
  399. return;
  400. final int slot = stream.readUnsignedShortLE();
  401. final boolean forceRun = stream.readByte128() == 1;
  402. int interfaceHash = stream.readIntV1();
  403. final int itemId = stream.readUnsignedShortLE128();
  404. int playerIndex = stream.readUnsignedShortLE();
  405. int interfaceId = interfaceHash >> 16;
  406. int componentId = interfaceHash & 0xFF;
  407. if (Settings.DEBUG)
  408. System.out.println("interface on player - player index:" + playerIndex + ", inter " + interfaceId + ", "
  409. + componentId + ", " + slot + ", " + itemId);
  410. if (Utils.getInterfaceDefinitionsSize() <= interfaceId)
  411. return;
  412. if (!player.getInterfaceManager().containsInterface(interfaceId))
  413. return;
  414. if (componentId == 65535)
  415. componentId = -1;
  416. if (componentId != -1 && Utils.getInterfaceDefinitionsComponentsSize(interfaceId) <= componentId)
  417. return;
  418. final Player p2 = World.getPlayers().get(playerIndex);
  419. if (p2 == null || p2 == player || p2.isDead() || p2.hasFinished()
  420. || !player.getMapRegionsIds().contains(p2.getRegionId()))
  421. return;
  422. player.stopAll();
  423. if (forceRun)
  424. player.setRun(forceRun);
  425. switch (interfaceId) {
  426. case 1430:
  427. if (componentId >= 55 && componentId <= 229)
  428. player.getActionbar().pushShortcutOnSomething((componentId - 55) / 13, p2);
  429. break;
  430. case 1110:
  431. case 1140:
  432. case 234:
  433. if ((interfaceId == 1110 && componentId == 16) || (interfaceId == 1140 && componentId == 10)
  434. || (interfaceId == 234 && componentId == 10))
  435. ClansManager.invite(player, p2);
  436. break;
  437. case Inventory.INVENTORY_INTERFACE:
  438. case Inventory.INVENTORY_INTERFACE_2:
  439. final Item item = player.getInventory().getItem(slot);
  440. if (item == null || item.getId() != itemId)
  441. return;
  442. player.setRouteEvent(new RouteEvent(p2, new Runnable() {
  443. @Override
  444. public void run() {
  445. if (!player.getControlerManager().processItemOnPlayer(p2, item, slot))
  446. return;
  447. if (itemId == 4155)
  448. player.getSlayerManager().invitePlayer(p2);
  449. }
  450. }));
  451. break;
  452. case 662:
  453. case 747:
  454. if (player.getFamiliar() == null)
  455. return;
  456. player.resetWalkSteps();
  457. if ((interfaceId == 747 && componentId == 15) || (interfaceId == 662 && componentId == 65)
  458. || (interfaceId == 662 && componentId == 74) || interfaceId == 747 && componentId == 18) {
  459. if ((interfaceId == 662 && componentId == 74 || interfaceId == 747 && componentId == 24
  460. || interfaceId == 747 && componentId == 18)) {
  461. if (player.getFamiliar().getSpecialAttack() != SpecialAttack.ENTITY)
  462. return;
  463. }
  464. if (!player.isCanPvp() || !p2.isCanPvp()) {
  465. player.getPackets().sendGameMessage("You can only attack players in a player-vs-player area.");
  466. return;
  467. }
  468. if (!player.getFamiliar().canAttack(p2)) {
  469. player.getPackets().sendGameMessage("You can only use your familiar in a multi-zone area.");
  470. return;
  471. } else {
  472. player.getFamiliar().setSpecial(
  473. interfaceId == 662 && componentId == 74 || interfaceId == 747 && componentId == 18);
  474. player.getFamiliar().setTarget(p2);
  475. }
  476. }
  477. break;
  478. case 1461:
  479. if (componentId == 1)
  480. player.getActionbar().useAbility(new MagicAbilityShortcut(slot), p2);
  481. // Magic.handleSpellOnEntity(player, interfaceSlot, p2);
  482. break;
  483. case 1449:
  484. if (componentId == 1)
  485. player.getActionbar().useAbility(player.getCombatDefinitions().onDefenceMenu()
  486. ? new DefenceAbilityShortcut(slot) : new HealAbilityShortcut(slot), p2);
  487. break;
  488. case 1460:
  489. if (componentId == 1)
  490. player.getActionbar().useAbility(player.getCombatDefinitions().onStrengthMenu()
  491. ? new StrengthAbilityShortcut(slot) : new MeleeAbilityShortcut(slot), p2);
  492. break;
  493. case 1452:
  494. if (componentId == 1)
  495. player.getActionbar().useAbility(new RangeAbilityShortcut(slot), p2);
  496. break;
  497. }
  498. } else if (opcode == INTERFACE_ON_NPC) {
  499. if (!player.hasStarted() || !player.clientHasLoadedMapRegion() || player.isDead())
  500. return;
  501. if (player.isLocked() || player.getEmotesManager().isDoingEmote())
  502. return;
  503.  
  504. int interfaceHash = stream.readIntLE();
  505. int interfaceSlot = stream.readUnsignedShort();
  506. int interfaceSlot2 = stream.readUnsignedShort();
  507. int npcIndex = stream.readUnsignedShort();
  508. boolean forceRun = stream.readByte128() == 1;
  509.  
  510. int interfaceId = interfaceHash >> 16;
  511. int componentId = interfaceHash - (interfaceId << 16);
  512.  
  513. if (Settings.DEBUG)
  514. System.out.println("interface on npc - player index:" + npcIndex + ", inter " + interfaceId + ", "
  515. + componentId + ", " + interfaceSlot + ", " + interfaceSlot2);
  516.  
  517. if (Utils.getInterfaceDefinitionsSize() <= interfaceId)
  518. return;
  519. if (!player.getInterfaceManager().containsInterface(interfaceId))
  520. return;
  521. if (componentId == 65535)
  522. componentId = -1;
  523. if (componentId != -1 && Utils.getInterfaceDefinitionsComponentsSize(interfaceId) <= componentId)
  524. return;
  525. NPC npc = World.getNPCs().get(npcIndex);
  526. if (npc == null || npc.isDead() || npc.hasFinished()
  527. || !player.getMapRegionsIds().contains(npc.getRegionId()))
  528. return;
  529. if (!player.getControlerManager().canAttack(npc))
  530. return;
  531. player.stopAll();
  532. if (forceRun)
  533. player.setRun(forceRun);
  534. switch (interfaceId) {
  535. case 1430:
  536. if (componentId >= 55 && componentId <= 229)
  537. player.getActionbar().pushShortcutOnSomething((componentId - 55) / 13, npc);
  538. break;
  539. case Inventory.INVENTORY_INTERFACE:
  540. case Inventory.INVENTORY_INTERFACE_2:
  541. Item item = player.getInventory().getItem(interfaceSlot);
  542. if (item == null || !player.getControlerManager().processItemOnNPC(npc, item))
  543. return;
  544. else if (npc instanceof Familiar) {
  545. Familiar familiar = (Familiar) npc;
  546. if (familiar != player.getFamiliar()) {
  547. player.getPackets().sendGameMessage("This is not your familiar!");
  548. return;
  549. }
  550. }
  551. NPCHandler.handleItemOnNPC(player, npc, interfaceSlot, item);
  552. break;
  553. case 1165:
  554. /*
  555. * if (componentId == 3) { if
  556. * (!player.getControlerManager().canAttack(npc)) {
  557. * player.getInterfaceManager().closeInventory(); return; } else
  558. * if (player.getAttackedBy() == null) {
  559. * player.getPackets().sendGameMessage(
  560. * "You need to have a target in order to deploy a dreadnip.");
  561. * player.getInterfaceManager().closeInventory(); return; }
  562. * player.getInventory().deleteItem(22370, 1); Dreadnip dread =
  563. * new Dreadnip(player, Utils.getFreeTile(player, 2), -1, true);
  564. * dread.getCombat().setTarget(dread.getTarget().getAttackedBy()
  565. * ); }
  566. */
  567. break;
  568. case 662:
  569. case 747:
  570. if (player.getFamiliar() == null)
  571. return;
  572. player.resetWalkSteps();
  573. if ((interfaceId == 747 && componentId == 15) || (interfaceId == 662 && componentId == 65)
  574. || (interfaceId == 662 && componentId == 74) || interfaceId == 747 && componentId == 18
  575. || interfaceId == 747 && componentId == 24) {
  576. if ((interfaceId == 662 && componentId == 74 || interfaceId == 747 && componentId == 18)) {
  577. if (player.getFamiliar().getSpecialAttack() != SpecialAttack.ENTITY)
  578. return;
  579. }
  580. if (npc instanceof Familiar) {
  581. Familiar familiar = (Familiar) npc;
  582. if (familiar == player.getFamiliar()) {
  583. player.getPackets().sendGameMessage("You can't attack your own familiar.");
  584. return;
  585. }
  586. if (!player.getFamiliar().canAttack(familiar.getOwner())) {
  587. player.getPackets()
  588. .sendGameMessage("You can only attack players in a player-vs-player area.");
  589. return;
  590. }
  591. } else if (!npc.getDefinitions().hasAttackOption()) {
  592. player.getPackets().sendGameMessage("You can't attack this npc.");
  593. return;
  594. }
  595.  
  596. if (!player.getFamiliar().canAttack(npc)) {
  597. player.getPackets().sendGameMessage("You can only use your familiar in a multi-zone area.");
  598. return;
  599. } else {
  600. player.getFamiliar().setSpecial(
  601. interfaceId == 662 && componentId == 74 || interfaceId == 747 && componentId == 18);
  602. player.getFamiliar().setTarget(npc);
  603. }
  604. }
  605. break;
  606. case 1461:
  607. if (componentId == 1)
  608. player.getActionbar().useAbility(new MagicAbilityShortcut(interfaceSlot), npc);
  609. // Magic.handleSpellOnEntity(player, interfaceSlot, npc);
  610. break;
  611. case 1449:
  612. if (componentId == 1)
  613. player.getActionbar().useAbility(player.getCombatDefinitions().onDefenceMenu()
  614. ? new DefenceAbilityShortcut(interfaceSlot) : new HealAbilityShortcut(interfaceSlot), npc);
  615. break;
  616. case 1452:
  617. if (componentId == 1)
  618. player.getActionbar().useAbility(new RangeAbilityShortcut(interfaceSlot), npc);
  619. break;
  620. case 1460:
  621. if (componentId == 1)
  622. player.getActionbar()
  623. .useAbility(player.getCombatDefinitions().onStrengthMenu()
  624. ? new StrengthAbilityShortcut(interfaceSlot)
  625. : new MeleeAbilityShortcut(interfaceSlot), npc);
  626. break;
  627. }
  628. } else if (opcode == INTERFACE_ON_OBJECT) {
  629.  
  630. boolean forceRun = stream.readByte() == 1;
  631. int interfaceHash = stream.readInt();
  632. int slotId = stream.readShort128();
  633. int x = stream.readShortLE128();
  634. int objectId = stream.readIntV1();
  635. int y = stream.readShortLE();
  636. int itemId = stream.readIntV1();
  637.  
  638. final int interfaceId = interfaceHash >> 16;
  639. int componentId = interfaceHash - (interfaceId << 16);
  640.  
  641. if (Settings.DEBUG)
  642. Logger.log(WorldPacketsDecoder.class, "inter on object - " + interfaceId + ", " + componentId + ", " + x
  643. + ", " + y + ", " + objectId + ", " + slotId + ", " + itemId);
  644.  
  645. if (!player.hasStarted() || !player.clientHasLoadedMapRegion() || player.isDead())
  646. return;
  647. if (player.isLocked() || player.getEmotesManager().isDoingEmote())
  648. return;
  649. final WorldTile tile = new WorldTile(x, y, player.getPlane());
  650. int regionId = tile.getRegionId();
  651. if (!player.getMapRegionsIds().contains(regionId))
  652. return;
  653. WorldObject mapObject = World.getObjectWithId(tile, objectId);
  654. if (mapObject == null || mapObject.getId() != objectId)
  655. return;
  656. final WorldObject object = mapObject;
  657. if (player.isDead() || Utils.getInterfaceDefinitionsSize() <= interfaceId)
  658. return;
  659. if (player.isLocked())
  660. return;
  661. if (!player.getInterfaceManager().containsInterface(interfaceId))
  662. return;
  663. player.stopAll();
  664. if (forceRun)
  665. player.setRun(forceRun);
  666. switch (interfaceId) {
  667. case Inventory.INVENTORY_INTERFACE: // inventory
  668. case Inventory.INVENTORY_INTERFACE_2:
  669. ObjectHandler.handleItemOnObject(player, object, interfaceId, slotId, itemId);
  670. break;
  671. case 430:// lunars
  672. switch (componentId) {
  673. case 55:
  674. if (player.getSkills().getLevel(Skills.MAGIC) < 66) {
  675. player.getPackets().sendGameMessage("You need a level of 65 in order to cast Cure Plant.");
  676. return;
  677. }
  678. if (!Magic.checkRunes(player, true, Magic.ASTRAL_RUNE, 1, Magic.EARTH_RUNE, 8))
  679. return;
  680. final FarmingSpot spot = player.getFarmingManager().getSpot(SpotInfo.getInfo(object.getId()));
  681. if (spot == null || spot.isDead()) {
  682. player.getPackets().sendGameMessage("This cannot be cured.");
  683. return;
  684. } else if (!spot.isDiseased()) {
  685. player.getPackets().sendGameMessage("Your patch is not diseased.");
  686. return;
  687. }
  688. player.lock(3);
  689. WorldTasksManager.schedule(new WorldTask() {
  690.  
  691. @Override
  692. public void run() {
  693. spot.setDiseased(false);
  694. spot.refresh();
  695. }
  696. }, 2);
  697. player.getSkills().addXp(Skills.MAGIC, 60);
  698. player.setNextGraphics(new Graphics(742, 0, 150));
  699. player.setNextAnimation(new Animation(4409));
  700. player.getPackets().sendGameMessage("You cast the spell and your patch is in perfect health.");
  701. break;
  702. }
  703. break;
  704. case 1461: // regular spellbook
  705. switch (slotId) {
  706. case 48: // water charge
  707. if(object.getId() == 2151)
  708. player.setRouteEvent(new RouteEvent(object, new Runnable() {
  709. @Override
  710. public void run() {
  711. player.setNextFaceWorldTile(object);
  712. if(player.withinDistance(object, 2))
  713. player.getDialogueManager().startDialogue("PowerOrbsD", PowerOrbs.TanHide.WATER_ORB);
  714. }
  715. }, true));
  716. else
  717. player.getPackets().sendEntityMessage(1, 14338209, player, "You can only cast this spell on an Obelisk of Water.");
  718. break;
  719. case 52: // earth charge
  720. if(object.getId() == 29415)
  721. player.setRouteEvent(new RouteEvent(object, new Runnable() {
  722. @Override
  723. public void run() {
  724. player.setNextFaceWorldTile(object);
  725. if(player.withinDistance(object, 2))
  726. player.getDialogueManager().startDialogue("PowerOrbsD", PowerOrbs.TanHide.EARTH_ORB);
  727. }
  728. }, true));
  729. else
  730. player.getPackets().sendEntityMessage(1, 14338209, player, "You can only cast this spell on an Obelisk of Earth.");
  731. break;
  732. case 59: // fire charge
  733. if(object.getId() == 74862)
  734. player.setRouteEvent(new RouteEvent(object, new Runnable() {
  735. @Override
  736. public void run() {
  737. player.setNextFaceWorldTile(object);
  738. if(player.withinDistance(object, 2))
  739. player.getDialogueManager().startDialogue("PowerOrbsD", PowerOrbs.TanHide.FIRE_ORB);
  740. }
  741. }, true));
  742. else
  743. player.getPackets().sendEntityMessage(1, 14338209, player, "You can only cast this spell on an Obelisk of Fire.");
  744. break;
  745. case 62: // air charge
  746. if(object.getId() == 2152)
  747. player.setRouteEvent(new RouteEvent(object, new Runnable() {
  748. @Override
  749. public void run() {
  750. player.setNextFaceWorldTile(object);
  751. if(player.withinDistance(object, 2))
  752. player.getDialogueManager().startDialogue("PowerOrbsD", PowerOrbs.TanHide.AIR_ORB);
  753. }
  754. }, true));
  755. else
  756. player.getPackets().sendEntityMessage(1, 14338209, player, "You can only cast this spell on an Obelisk of Air.");
  757. break;
  758. }
  759.  
  760. break;
  761. }
  762. } else if (opcode == PLAYER_OPTION_1_PACKET) {
  763. if (!player.hasStarted() || !player.clientHasLoadedMapRegion() || player.isDead())
  764. return;
  765. boolean forceRun = stream.readUnsignedByte128() == 1;
  766. int playerIndex = stream.readUnsignedShort128();
  767. Player p2 = World.getPlayers().get(playerIndex);
  768. if (forceRun)
  769. player.setRun(forceRun);
  770. player.stopAll();
  771.  
  772. if (p2 == null || p2 == player || p2.isDead() || p2.hasFinished()
  773. || !player.getMapRegionsIds().contains(p2.getRegionId()))
  774. return;
  775. if (player.isLocked() || player.getEmotesManager().isDoingEmote()
  776. || !player.getControlerManager().canPlayerOption1(p2))
  777. return;
  778. if (!player.isCanPvp())
  779. return;
  780. if (!player.getControlerManager().canAttack(p2))
  781. return;
  782. if (!player.isCanPvp() || !p2.isCanPvp()) {
  783. player.getPackets().sendGameMessage("You can only attack players in a player-vs-player area.");
  784. return;
  785. }
  786.  
  787. player.getActionManager().setAction(new PlayerCombatNew(p2));
  788. } else if (opcode == PLAYER_OPTION_2_PACKET) {
  789. if (!player.hasStarted() || !player.clientHasLoadedMapRegion() || player.isDead())
  790. return;
  791. boolean forceRun = stream.readUnsignedByte128() == 1;
  792. int playerIndex = stream.readUnsignedShort128();
  793. Player p2 = World.getPlayers().get(playerIndex);
  794. if (p2 == null || p2 == player || p2.isDead() || p2.hasFinished()
  795. || !player.getMapRegionsIds().contains(p2.getRegionId()))
  796. return;
  797. if (player.isLocked() || player.isCantWalk())
  798. return;
  799. if (!player.getControlerManager().canPlayerOption2(p2))
  800. return;
  801. if (forceRun)
  802. player.setRun(forceRun);
  803. player.stopAll();
  804. player.getActionManager().setAction(new PlayerFollow(p2));
  805. } else if (opcode == PLAYER_OPTION_3_PACKET) {
  806. boolean forceRun = stream.readUnsignedByte128() == 1;
  807. int playerIndex = stream.readUnsignedShort128();
  808. final Player p2 = World.getPlayers().get(playerIndex);
  809. if (p2 == null || p2 == player || p2.isDead() || p2.hasFinished()
  810. || !player.getMapRegionsIds().contains(p2.getRegionId()))
  811. return;
  812. if (player.isLocked())
  813. return;
  814. if (forceRun)
  815. player.setRun(forceRun);
  816. player.stopAll();
  817. player.setRouteEvent(new RouteEvent(p2, new Runnable() {
  818. @Override
  819. public void run() {
  820. if (!player.getControlerManager().canPlayerOption3(p2))
  821. return;
  822. }
  823. }));
  824. } else if (opcode == PLAYER_OPTION_4_PACKET) {
  825. boolean forceRun = stream.readUnsignedByte128() == 1;
  826. int playerIndex = stream.readUnsignedShort128();
  827. final Player p2 = World.getPlayers().get(playerIndex);
  828. if (p2 == null || p2 == player || p2.isDead() || p2.hasFinished()
  829. || !player.getMapRegionsIds().contains(p2.getRegionId()))
  830. return;
  831. if (player.isLocked())
  832. return;
  833. if (forceRun)
  834. player.setRun(forceRun);
  835. player.stopAll();
  836. player.setRouteEvent(new RouteEvent(p2, new Runnable() {
  837. @Override
  838. public void run() {
  839. if (!player.getControlerManager().canPlayerOption4(p2))
  840. return;
  841. player.stopAll();
  842. if (player.isBeginningAccount()) {
  843. player.getPackets()
  844. .sendGameMessage("Starter accounts cannot trade for the first hour of playing time.");
  845. return;
  846. }
  847. if (p2.getRights() >= 3) {
  848.  
  849. player.getPackets().sendGameMessage("You cannot trade with Administrators.");
  850. return;
  851. }
  852.  
  853. if (p2.isIronMan()) {
  854. player.getPackets().sendGameMessage("You can't trade with an Iron man.");
  855. return;
  856. }
  857.  
  858. if (player.isIronMan()) {
  859. player.getPackets().sendGameMessage("You can't trade with other players.");
  860. return;
  861. }
  862.  
  863. if (player.isCantTrade() || player.getControlerManager().getControler() != null
  864. && player.getControlerManager().getControler() instanceof StealingCreationLobbyController) {
  865. player.getPackets().sendGameMessage("You are busy.");
  866. return;
  867. }
  868. if (p2.isBeginningAccount()) {
  869. player.getPackets().sendGameMessage(
  870. "Your target is a starter account, which cannot trade for the first hour of playing time.");
  871. return;
  872. }
  873. if (p2.getInterfaceManager().containsScreenInterface()
  874. || p2.isCantTrade() || p2.getControlerManager().getControler() != null && p2
  875. .getControlerManager().getControler() instanceof StealingCreationLobbyController
  876. || p2.isLocked()) {
  877. player.getPackets().sendGameMessage("The other player is busy.");
  878. return;
  879. }
  880. if (!p2.withinDistance(player, 14)) {
  881. player.getPackets().sendGameMessage("Unable to find target " + p2.getDisplayName());
  882. return;
  883. }
  884. if (!player.getBank().hasVerified(10)) {
  885. return;
  886. }
  887. if (p2.getTemporaryAttributtes().get("TradeTarget") == player) {
  888. p2.getTemporaryAttributtes().remove("TradeTarget");
  889. player.getTrade().openTrade(p2);
  890. p2.getTrade().openTrade(player);
  891. return;
  892. }
  893. player.getTemporaryAttributtes().put("TradeTarget", p2);
  894. player.getPackets().sendGameMessage("Sending " + p2.getDisplayName() + " a request...");
  895. p2.getPackets().sendTradeRequestMessage(player);
  896. }
  897. }));
  898. } else if (opcode == PLAYER_OPTION_6_PACKET) {
  899. if (!player.hasStarted() || !player.clientHasLoadedMapRegion() || player.isDead())
  900. return;
  901. boolean forceRun = stream.readUnsignedByte128() == 1;
  902. int playerIndex = stream.readUnsignedShort128();
  903. Player p2 = World.getPlayers().get(playerIndex);
  904. if (p2 == null || p2 == player || p2.isDead() || p2.hasFinished()
  905. || !player.getMapRegionsIds().contains(p2.getRegionId()))
  906. return;
  907. if (player.isLocked())
  908. return;
  909. if (forceRun)
  910. player.setRun(forceRun);
  911. player.stopAll();
  912. player.getPlayerExamineManager().openExamineDetails(p2);
  913.  
  914. }
  915.  
  916. else if (opcode == PLAYER_OPTION_9_PACKET) {// TODO no longer used
  917. boolean forceRun = stream.readUnsignedByte128() == 1;
  918. int playerIndex = stream.readUnsignedShort128();
  919. Player p2 = World.getPlayers().get(playerIndex);
  920. if (p2 == null || p2 == player || p2.isDead() || p2.hasFinished()
  921. || !player.getMapRegionsIds().contains(p2.getRegionId()))
  922. return;
  923. if (player.isLocked())
  924. return;
  925. if (forceRun)
  926. player.setRun(forceRun);
  927. player.stopAll();
  928. if (ClansManager.viewInvite(player, p2))
  929. return;
  930. if (p2.getTemporaryAttributtes().get("social_request") == player)
  931. player.getSlayerManager().invitePlayer(p2);
  932. } else if (opcode == ATTACK_NPC_PACKET) {
  933. if (!player.hasStarted() || !player.clientHasLoadedMapRegion() || player.isDead())
  934. return;
  935. boolean forceRun = stream.readUnsignedByteC() == 1;
  936. int npcIndex = stream.readUnsignedShort128();
  937. NPC npc = World.getNPCs().get(npcIndex);
  938. if (npc == null || npc.isDead() || npc.hasFinished()
  939. || !player.getMapRegionsIds().contains(npc.getRegionId())
  940. || !npc.getDefinitions().hasAttackOption())
  941. return;
  942. if (player.isLocked() || player.getEmotesManager().isDoingEmote())
  943. return;
  944. if (!player.getControlerManager().canAttack(npc))
  945. return;
  946. if (forceRun) // you scrwed up cutscenes
  947. player.setRun(forceRun);
  948. player.stopAll();
  949. if (npc instanceof Familiar) {
  950. Familiar familiar = (Familiar) npc;
  951. if (familiar == player.getFamiliar()) {
  952. player.getPackets().sendGameMessage("You can't attack your own familiar.");
  953. return;
  954. }
  955. if (!familiar.canAttack(player)) {
  956. player.getPackets().sendGameMessage("You can't attack this npc.");
  957. return;
  958. }
  959.  
  960. } else if (npc instanceof DoorSupport) {
  961. if (!((DoorSupport) npc).canDestroy(player)) {
  962. player.getPackets().sendGameMessage("You cannot see a way to open this door...");
  963. return;
  964. }
  965. }
  966. player.getActionManager().setAction(new PlayerCombatNew(npc));
  967. } else if (opcode == NPC_CLICK1_PACKET)
  968. NPCHandler.handleOption1(player, stream);
  969. else if (opcode == NPC_CLICK2_PACKET)
  970. NPCHandler.handleOption2(player, stream);
  971. else if (opcode == NPC_CLICK3_PACKET)
  972. NPCHandler.handleOption3(player, stream);
  973. else if (opcode == NPC_CLICK4_PACKET)
  974. NPCHandler.handleOption4(player, stream);
  975. else if (opcode == OBJECT_CLICK1_PACKET)
  976. ObjectHandler.handleOption(player, stream, 1);
  977. else if (opcode == OBJECT_CLICK2_PACKET)
  978. ObjectHandler.handleOption(player, stream, 2);
  979. else if (opcode == OBJECT_CLICK3_PACKET)
  980. ObjectHandler.handleOption(player, stream, 3);
  981. else if (opcode == OBJECT_CLICK4_PACKET)
  982. ObjectHandler.handleOption(player, stream, 4);
  983. else if (opcode == OBJECT_CLICK5_PACKET)
  984. ObjectHandler.handleOption(player, stream, 5);
  985. else if (opcode == ITEM_TAKE_PACKET) {
  986. if (!player.hasStarted() || !player.clientHasLoadedMapRegion() || player.isDead())
  987. return;
  988. if (player.isLocked())
  989. return;
  990. int y = stream.readUnsignedShortLE128();
  991. int id = stream.readUnsignedShort128();
  992. boolean forceRun = stream.readByte() == 1;
  993. int x = stream.readShort128();
  994. final WorldTile tile = new WorldTile(x, y, player.getPlane());
  995. final int regionId = tile.getRegionId();
  996. if (!player.getMapRegionsIds().contains(regionId))
  997. return;
  998. final FloorItem item = World.getRegion(regionId).getGroundItem(id, tile, player);
  999. if (item == null)
  1000. return;
  1001. if (item.getId() == 245 && x == 2952 && y == 3473){
  1002. player.getPackets().sendEntityMessage(1, 14338209, player, "A magical force prevents you from picking up this item.");
  1003. return;
  1004. }
  1005. if (forceRun)
  1006. player.setRun(forceRun);
  1007. player.stopAll();
  1008. player.setRouteEvent(new RouteEvent(item, new Runnable() {
  1009. @Override
  1010. public void run() {
  1011. final FloorItem item = World.getRegion(regionId).getGroundItem(id, tile, player);
  1012. if (item == null || !player.getControlerManager().canTakeItem(item))
  1013. return;
  1014. if (World.removeGroundItem(player, item))
  1015. Logger.globalLog(player.getUsername(), player.getSession().getIP(),
  1016. new String(" has picked up item [ id: " + item.getId() + ", amount: " + item.getAmount()
  1017. + " ] originally owned to "
  1018. + (item.getOwner() == null ? "no owner" : item.getOwner()) + "."));
  1019. }
  1020. }));
  1021. } else if (opcode == GROUND_ITEM_OPTION_2) {
  1022. if (!player.hasStarted() || !player.clientHasLoadedMapRegion() || player.isDead())
  1023. return;
  1024. if (player.isLocked())
  1025. return;
  1026. int y = stream.readUnsignedShortLE128();
  1027. int id = stream.readUnsignedShort128();
  1028. boolean forceRun = stream.readByte() == 1;
  1029. int x = stream.readShort128();
  1030. final WorldTile tile = new WorldTile(x, y, player.getPlane());
  1031. final int regionId = tile.getRegionId();
  1032. if (!player.getMapRegionsIds().contains(regionId))
  1033. return;
  1034. final FloorItem item = World.getRegion(regionId).getGroundItem(id, tile, player);
  1035. if (item == null)
  1036. return;
  1037. if (forceRun)
  1038. player.setRun(forceRun);
  1039. player.stopAll();
  1040. player.setRouteEvent(new RouteEvent(item, new Runnable() {
  1041. @Override
  1042. public void run() {
  1043. final FloorItem item = World.getRegion(regionId).getGroundItem(id, tile, player);
  1044. if (item == null)
  1045. return;
  1046. for (Fire fire : Fire.values()) {
  1047. if (item.getId() == fire.getLogId()) {
  1048. player.getActionManager().setAction(new Firemaking(fire, true));
  1049. return;
  1050. }
  1051. }
  1052. }
  1053. }));
  1054. }
  1055. }
  1056.  
  1057. public void processPackets(final int opcode, InputStream stream) {
  1058.  
  1059.  
  1060. if (opcode != NIS_VAR_PACKET) { // dont want interface t oget messed up
  1061. // <...<
  1062. long ctime = System.nanoTime();
  1063. if ((ctime - pthrotletimer[opcode]) > (1000000 * 600)) {
  1064. pthrotlecounter[opcode] = 0;
  1065. pthrotletimer[opcode] = ctime;
  1066. }
  1067.  
  1068. if (++pthrotlecounter[opcode] > 10) {
  1069. pthrotletimer[opcode] = ctime; // reset timer to completly
  1070. // mitigate ddos
  1071. return;
  1072. }
  1073. }
  1074. // System.out.println("packet: "+packetId +", "+
  1075. // Thread.currentThread().getName());
  1076. if (opcode == PING_PACKET) {
  1077. player.getPackets().sendPing();
  1078. } else if (opcode == 26) { // testing
  1079. int shorta = stream.readShort();
  1080. boolean b = stream.readUnsignedByte() == 1;
  1081. String s = stream.readString();
  1082. System.out.println("p26: " + shorta + ", " + b + ", " + s);
  1083. } else if (opcode == CUTSCENE_DONE_PACKET) {
  1084. @SuppressWarnings("unused")
  1085. boolean done = stream.readUnsignedByte() == 1;
  1086. // if not done means skipped
  1087. player.loadMapRegions();
  1088. } else if (opcode == NIS_VAR_PACKET) {
  1089. @SuppressWarnings("unused")
  1090. boolean unknown = stream.readUnsignedByte() == 1;
  1091. int count = (stream.getLength() - 1) / 6;
  1092. for (int i = 0; i < count; i++) {
  1093. Integer id = stream.readUnsignedShort();
  1094. Integer value = stream.readInt();
  1095. // System.out.println("nisvar: "+id+", "+value);
  1096. if (value == 0)
  1097. player.getILayoutVars().remove(id);
  1098. else
  1099. player.getILayoutVars().put(id, value);
  1100. }
  1101. // System.out.println(player.getILayoutVars().size()+",
  1102. // "+player.getILayoutVars());
  1103. if (player.getILayoutVars().size() > 1000)
  1104. player.resetILayoutVars();
  1105. player.getPackets().sendResetNISVars();
  1106. } else if (opcode == MUSIC_PACKET) {
  1107. int archiveId = stream.readInt(); // started playing, request send
  1108. // again
  1109. // player.getMusicsManager().resetMusicDelay(player.getMusicsManager().getMusicId(archiveId));
  1110. player.getMusicsManager().resetMusicDelay(player.getMusicsManager().getMusicId(archiveId));
  1111. } else if (opcode == REQUEST_PLAY_MUSIC_PACKET) { // request play such
  1112. // as after turn off
  1113. // and on
  1114. int archiveId = stream.readInt();
  1115. player.getMusicsManager().resetMusicDelay(player.getMusicsManager().getMusicId(archiveId));
  1116. } else if (opcode == WORLD_LIST_UPDATE) {
  1117. if (!player.isLobby())
  1118. return;
  1119. int checksum = stream.readInt();
  1120. LoginClientChannelManager.sendReliablePacket(LoginChannelsPacketEncoder
  1121. .encodePlayerWorldListStatusRequest(player.getUsername(), checksum).getBuffer());
  1122. } else if (opcode == MOUVE_MOUSE_PACKET || opcode == MOUSE_MOVEMENT_DELAY) {
  1123. // USELESS PACKET
  1124. } else if (opcode == KEY_TYPED_PACKET) {
  1125. // USELESS PACKET
  1126. } else if (opcode == RECEIVE_PACKET_COUNT_PACKET) {
  1127. // count
  1128. stream.readInt();
  1129. } else if (opcode == INTERFACE_ON_INTERFACE) {
  1130. InventoryOptionsHandler.handleInterfaceOnInterface(player, stream);
  1131. } else if (opcode == CLOSE_INTERFACE_PACKET) {
  1132. player.stopAll();
  1133. } else if (opcode == MOVE_CAMERA_PACKET) {
  1134. // not using it atm
  1135. stream.readShort();
  1136. stream.readShortLE128();
  1137. } else if (opcode == IN_OUT_SCREEN_PACKET) {
  1138. // not using this check because not 100% efficient
  1139. @SuppressWarnings("unused")
  1140. boolean inScreen = stream.readByte() == 1;
  1141. } else if (opcode == SCREEN_PACKET) {
  1142. int displayMode = stream.readUnsignedByte();
  1143. player.setScreenWidth(stream.readUnsignedShort());
  1144. player.setScreenHeight(stream.readUnsignedShort());
  1145. @SuppressWarnings("unused")
  1146. boolean switchScreenMode = stream.readUnsignedByte() == 1;
  1147. if (!player.hasStarted() || player.hasFinished() || displayMode == player
  1148. .getDisplayMode()/*
  1149. * || !player.getInterfaceManager().
  1150. * containsInterface(742)
  1151. */)
  1152. return;
  1153. player.setDisplayMode(displayMode);
  1154. /*
  1155. * player.getInterfaceManager().removeAll();
  1156. * player.getInterfaceManager().sendInterfaces();
  1157. * player.getInterfaceManager().sendCentralInterface(742);
  1158. */
  1159. } else if (opcode == CLICK_PACKET) {
  1160. int mouseHash = stream.readShort128();
  1161. int mouseButton = mouseHash >> 15;
  1162. int time = mouseHash - (mouseButton << 15); // time
  1163. int positionHash = stream.readInt();
  1164. int y = positionHash >> 16; // y;
  1165. int x = positionHash - (y << 16); // x
  1166. @SuppressWarnings("unused")
  1167. boolean clicked;
  1168. // mass click or stupid autoclicker, lets stop lagg
  1169. if (time <= 1 || x < 0 || x > player.getScreenWidth() || y < 0 || y > player.getScreenHeight()) {
  1170. // player.getSession().getChannel().close();
  1171. clicked = false;
  1172. return;
  1173. }
  1174. clicked = true;
  1175. } else if (opcode == CLICK_PACKET_2) { // TODO
  1176.  
  1177. } else if (opcode == DIALOGUE_CONTINUE_PACKET) {
  1178. int junk = stream.readShortLE128();
  1179. int interfaceHash = stream.readIntV2();
  1180. int interfaceId = interfaceHash >> 16;
  1181. int buttonId = (interfaceHash & 0xFF);
  1182. if (Utils.getInterfaceDefinitionsSize() <= interfaceId) {
  1183. // hack, or server error or client error
  1184. // player.getSession().getChannel().close();
  1185. return;
  1186. }
  1187. if (Settings.DEBUG)
  1188. Logger.log(this, "Dialogue: " + interfaceId + ", " + buttonId + ", " + junk);
  1189. if (!player.isRunning() || !player.getInterfaceManager().containsInterface(interfaceId))
  1190. return;
  1191. int componentId = interfaceHash - (interfaceId << 16);
  1192. player.getDialogueManager().continueDialogue(interfaceId, componentId);
  1193. } else if (opcode == WORLD_MAP_CLICK) {
  1194. int coordinateHash = stream.readIntV2();
  1195. int x = coordinateHash >> 14;
  1196. int y = coordinateHash & 0x3fff;
  1197. int plane = coordinateHash >> 28;
  1198. Integer hash = (Integer) player.getTemporaryAttributtes().get("worldHash");
  1199. if (hash == null || coordinateHash != hash)
  1200. player.getTemporaryAttributtes().put("worldHash", coordinateHash);
  1201. else {
  1202. player.getTemporaryAttributtes().remove("worldHash");
  1203. player.getHintIconsManager().addHintIcon(x, y, plane, 20, 0, 2, -1, true);
  1204. player.getVarsManager().sendVar(2807, coordinateHash);
  1205. }
  1206. } else if (opcode == ACTION_BUTTON1_PACKET || opcode == ACTION_BUTTON2_PACKET || opcode == ACTION_BUTTON4_PACKET
  1207. || opcode == ACTION_BUTTON5_PACKET || opcode == ACTION_BUTTON6_PACKET || opcode == ACTION_BUTTON7_PACKET
  1208. || opcode == ACTION_BUTTON8_PACKET || opcode == ACTION_BUTTON3_PACKET || opcode == ACTION_BUTTON9_PACKET
  1209. || opcode == ACTION_BUTTON10_PACKET) {
  1210. ButtonHandler.handleButtons(player, stream, opcode);
  1211. } else if (opcode == ENTER_NAME_PACKET) {
  1212. if (!player.isRunning() || player.isDead() || !player.getInterfaceManager().containsInputTextInterface())
  1213. return;
  1214. player.getInterfaceManager().removeInputTextInterface();
  1215. String value = stream.readString();
  1216. if (value.equals(""))
  1217. return;
  1218. if (player.getInterfaceManager().containsInterface(1108))
  1219. player.getFriendsIgnores().setChatPrefix(value);
  1220. else if (player.getTemporaryAttributtes().remove("setclan") != null)
  1221. ClansManager.createClan(player, value);
  1222. else if (player.getTemporaryAttributtes().remove("joinguestclan") != null)
  1223. ClansManager.connectToClan(player, value, true);
  1224. else if (player.getTemporaryAttributtes().remove("banclanplayer") != null)
  1225. ClansManager.banPlayer(player, value);
  1226. else if (player.getTemporaryAttributtes().remove("unbanclanplayer") != null)
  1227. ClansManager.unbanPlayer(player, value);
  1228. else if (player.getTemporaryAttributtes().remove(Key.DUNGEON_INVITE) != null)
  1229. player.getDungManager().invite(value);
  1230. else if (player.getTemporaryAttributtes().remove(Key.CLAN_WARS_VIEW) != null)
  1231. ClanWars.enter(player, value);
  1232. else if (player.getTemporaryAttributtes().remove("enterhouse") != null)
  1233. House.enterHouse(player, value);
  1234. else {
  1235. Boss boss = (Boss) player.getTemporaryAttributtes().remove(Key.JOIN_BOSS_INSTANCE);
  1236. if (boss != null)
  1237. BossInstanceHandler.joinInstance(player, boss, value.toLowerCase(), false);
  1238. }
  1239. } else if (opcode == ENTER_LONG_TEXT_PACKET) {
  1240. if (!player.isRunning() || player.isDead() || !player.getInterfaceManager().containsInputTextInterface())
  1241. return;
  1242. player.getInterfaceManager().removeInputTextInterface();
  1243. String value = stream.readString();
  1244. if (value.equals(""))
  1245. return;
  1246. if (player.getTemporaryAttributtes().remove(Key.PERSONAL_MESSAGE) != null) {
  1247. player.getPlayerExamineManager().setPersonalMessage(value);
  1248. } else if (player.getTemporaryAttributtes().remove("entering_note") == Boolean.TRUE)
  1249. player.getNotes().add(value);
  1250. else if (player.getTemporaryAttributtes().remove("editing_note") == Boolean.TRUE)
  1251. player.getNotes().edit(value);
  1252. else if (player.getTemporaryAttributtes().remove("ticket_other") != null) {
  1253. TicketSystem.addTicket(player, new TicketEntry(player, value));
  1254. player.getDialogueManager().startDialogue("SimpleMessage", "Your ticket has been submitted.");
  1255. } else if (player.getTemporaryAttributtes().remove("forum_authuserinput") == Boolean.TRUE) {
  1256. player.getTemporaryAttributtes().put("forum_authuser", value);
  1257. player.getTemporaryAttributtes().put("forum_authpasswordinput", true);
  1258. player.getPackets().sendInputLongTextScript("Enter your forum password:");
  1259. } else if (player.getTemporaryAttributtes().remove("forum_authpasswordinput") == Boolean.TRUE) {
  1260. String authuser = (String) player.getTemporaryAttributtes().get("forum_authuser");
  1261. String authpassword = value;
  1262. if (authuser == null || authpassword == null)
  1263. return;
  1264. LoginClientChannelManager
  1265. .sendReliablePacket(LoginChannelsPacketEncoder.encodeAccountVarUpdate(player.getUsername(),
  1266. LoginProtocol.VAR_TYPE_AUTH, authuser + "@AUTHSPLIT@" + authpassword).getBuffer());
  1267. player.getTemporaryAttributtes().remove("forum_authuser");
  1268. // player.getPackets().sendGameMessage("Feature disabled due to
  1269. // rework.");
  1270. } else if (player.getTemporaryAttributtes().remove("change_troll_name") == Boolean.TRUE) {
  1271. value = Utils.formatPlayerNameForDisplay(value);
  1272. if (value.length() < 3 || value.length() > 14) {
  1273. player.getPackets()
  1274. .sendGameMessage("You can't use a name shorter than 3 or longer than 14 characters.");
  1275. return;
  1276. }
  1277. if (value.equalsIgnoreCase("none")) {
  1278. player.getPetManager().setTrollBabyName(null);
  1279. } else {
  1280. player.getPetManager().setTrollBabyName(value);
  1281. if (player.getPet() != null && player.getPet().getId() == Pets.TROLL_BABY.getBabyNpcId()) {
  1282. player.getPet().setName(value);
  1283. }
  1284. }
  1285. } else if (player.getTemporaryAttributtes().remove("yellcolor") == Boolean.TRUE) {
  1286. if (value.length() != 6) {
  1287. player.getPackets().sendGameMessage(
  1288. "The HEX yell color you wanted to pick cannot be longer and shorter then 6.");
  1289. } else if (Utils.containsInvalidCharacter(value) || value.contains("_")) {
  1290. player.getPackets().sendGameMessage(
  1291. "The requested yell color can only contain numeric and regular characters.");
  1292. } else {
  1293. player.setYellColor(value);
  1294. player.getPackets().sendGameMessage("Your yell color has been changed to <col="
  1295. + player.getYellColor() + ">" + player.getYellColor() + "</col>.");
  1296. }
  1297. } else if (player.getTemporaryAttributtes().remove("setdisplay") == Boolean.TRUE) {
  1298. if (Utils.invalidAccountName(Utils.formatPlayerNameForProtocol(value))) {
  1299. player.getPackets().sendGameMessage("Name contains invalid characters or is too short/long.");
  1300. return;
  1301. }
  1302. LoginClientChannelManager.sendReliablePacket(LoginChannelsPacketEncoder
  1303. .encodeAccountVarUpdate(player.getUsername(), LoginProtocol.VAR_TYPE_DISPLAY_NAME,
  1304. Utils.formatPlayerNameForDisplay(value))
  1305. .getBuffer());
  1306. // player.getPackets().sendGameMessage("Feature disabled due to
  1307. // rework.");
  1308. } else if (player.getTemporaryAttributtes().remove(Key.CLAN_MOTTO) == Boolean.TRUE)
  1309. ClansManager.setClanMottoInterface(player, value);
  1310. } else if (opcode == ENTER_INTEGER_PACKET) {
  1311. if (!player.isRunning() || player.isDead() || !player.getInterfaceManager().containsInputTextInterface())
  1312. return;
  1313. player.getInterfaceManager().removeInputTextInterface();
  1314. int value = stream.readInt();
  1315. if (value < 0)
  1316. return;
  1317. if ((player.getInterfaceManager().containsInterface(762))
  1318. || player.getInterfaceManager().containsInterface(11)) {
  1319. Integer bank_item_X_Slot = (Integer) player.getTemporaryAttributtes().remove("bank_item_X_Slot");
  1320. if (bank_item_X_Slot == null)
  1321. return;
  1322. player.getBank().setLastX(value);
  1323. player.getBank().refreshLastX();
  1324. if (player.getTemporaryAttributtes().remove("bank_isWithdraw") != null)
  1325. player.getBank().withdrawItem(bank_item_X_Slot, value);
  1326. else
  1327. player.getBank().depositItem(bank_item_X_Slot, value,
  1328. player.getInterfaceManager().containsInterface(11) ? false : true);
  1329. } else if (player.getInterfaceManager().containsInterface(631)
  1330. && player.getTemporaryAttributtes().get(Key.DUEL_COIN_WITHDRAWL) != null) {
  1331. DuelArena arena = (DuelArena) player.getTemporaryAttributtes().get(Key.DUEL_COIN_WITHDRAWL);
  1332. Controller control = player.getControlerManager().getControler();
  1333. if (control == null || control != arena)
  1334. return;
  1335. int coinsAmount = player.getInventory().getCoinsAmount();
  1336. if (coinsAmount == 0)
  1337. return;
  1338. else if (value >= coinsAmount)
  1339. value = coinsAmount;
  1340. arena.addItem(new Item(995, value));
  1341. } else if (player.getInterfaceManager().containsInterface(AccessorySmithing.ACCESSORY_INTERFACE)
  1342. && player.getTemporaryAttributtes().get(Key.JEWLERY_SMITH_COMP) != null) {
  1343. AccessorySmithing.handleButtonClick(player,
  1344. (int) player.getTemporaryAttributtes().get(Key.JEWLERY_SMITH_COMP), value);
  1345. } else if (player.getInterfaceManager().containsInterface(206)
  1346. && player.getInterfaceManager().containsInterface(207)) {
  1347. Integer pc_item_X_Slot = (Integer) player.getTemporaryAttributtes().remove("pc_item_X_Slot");
  1348. if (pc_item_X_Slot == null)
  1349. return;
  1350. if (player.getTemporaryAttributtes().remove("pc_isRemove") != null)
  1351. player.getPriceCheckManager().removeItem(pc_item_X_Slot, value);
  1352. else
  1353. player.getPriceCheckManager().addItem(pc_item_X_Slot, value);
  1354. } else if (player.getInterfaceManager().containsInterface(400)) {
  1355. Integer create_tab_X_component = (Integer) player.getTemporaryAttributtes()
  1356. .remove("create_tab_X_component");
  1357. if (create_tab_X_component == null)
  1358. return;
  1359. TabletMaking.handleTabletCreation(player, create_tab_X_component, value);
  1360. } else if (player.getInterfaceManager().containsInterface(671)
  1361. && player.getInterfaceManager().containsInterface(665)) {
  1362. if (player.getFamiliar() == null || player.getFamiliar().getBob() == null)
  1363. return;
  1364. Integer bob_item_X_Slot = (Integer) player.getTemporaryAttributtes().remove("bob_item_X_Slot");
  1365. if (bob_item_X_Slot == null)
  1366. return;
  1367. if (player.getTemporaryAttributtes().remove("bob_isRemove") != null)
  1368. player.getFamiliar().getBob().removeItem(bob_item_X_Slot, value);
  1369. else
  1370. player.getFamiliar().getBob().addItem(bob_item_X_Slot, value);
  1371. } else if (player.getInterfaceManager().containsInterface(335)
  1372. && player.getInterfaceManager().containsInterface(336)) {
  1373. if (player.getTemporaryAttributtes().remove(Key.TRADE_COIN_WITHDRAWL) != null) {
  1374. int coinsAmount = player.getInventory().getCoinsAmount();
  1375. if (coinsAmount == 0)
  1376. return;
  1377. else if (value >= coinsAmount)
  1378. value = coinsAmount;
  1379. Item item = new Item(995, value);
  1380. player.getInventory().removeItemMoneyPouch(item);
  1381. player.getTrade().addItem(item);
  1382. return;
  1383. }
  1384. Integer trade_item_X_Slot = (Integer) player.getTemporaryAttributtes().remove("trade_item_X_Slot");
  1385. if (trade_item_X_Slot == null)
  1386. return;
  1387. if (player.getTemporaryAttributtes().remove("trade_isRemove") != null)
  1388. player.getTrade().removeItem(trade_item_X_Slot, value);
  1389. else
  1390. player.getTrade().addItem(trade_item_X_Slot, value);
  1391. } else if (player.getInterfaceManager().containsInterface(403)
  1392. && player.getTemporaryAttributtes().get("PlanksConvert") != null) {
  1393. Sawmill.convertPlanks(player, (Plank) player.getTemporaryAttributtes().remove("PlanksConvert"), value);
  1394. } else if (player.getInterfaceManager().containsInterface(902)
  1395. && player.getTemporaryAttributtes().get("PlankMake") != null) {
  1396. Integer type = (Integer) player.getTemporaryAttributtes().remove("PlankMake");
  1397. if (player.getControlerManager().getControler() instanceof SawmillController)
  1398. ((SawmillController) player.getControlerManager().getControler()).cutPlank(type, value);
  1399. } else if (player.getInterfaceManager().containsInterface(903)
  1400. && player.getTemporaryAttributtes().get("PlankWithdraw") != null) {
  1401. Integer type = (Integer) player.getTemporaryAttributtes().remove("PlankWithdraw");
  1402. if (player.getControlerManager().getControler() instanceof SawmillController)
  1403. ((SawmillController) player.getControlerManager().getControler()).withdrawFromCart(type, value);
  1404. } else if (player.getInterfaceManager().containsInterface(105)
  1405. && player.getTemporaryAttributtes().remove("GEPRICESET") != null) {
  1406. player.getGeManager().modifyPricePerItem(value);
  1407. } else if (player.getInterfaceManager().containsInterface(105)
  1408. && player.getTemporaryAttributtes().remove("GEQUANTITYSET") != null) {
  1409. player.getGeManager().modifyAmount(value);
  1410. } else if (player.getTemporaryAttributtes().remove("withdrawingPouch") == Boolean.TRUE) {
  1411. player.getMoneyPouch().sendDynamicInteraction(value, true, MoneyPouch.TYPE_POUCH_INVENTORY);
  1412. } else if (player.getTemporaryAttributtes().remove("lootbeam") == Boolean.TRUE) {
  1413. player.setLootBeam(value);
  1414. }
  1415. else if (player.getTemporaryAttributtes().remove("newSecurityPin") == Boolean.TRUE){
  1416. player.setSecurityPin(value);
  1417. if(value == 0){
  1418. player.getDialogueManager().startDialogue("SimpleMessage","Your security pin has been disabled.");
  1419. return;
  1420. }
  1421. player.getDialogueManager().startDialogue("SimpleMessage","Your security pin has been set to "+player.getSecurityPin()+".<br>"
  1422. + "<col=ff0000>Please make sure to write down this number somewhere incase you might forget it!");
  1423. return;
  1424. }
  1425. else if (player.getTemporaryAttributtes().remove("securityPin") == Boolean.TRUE){
  1426. if(player.getSecurityPin() == 0){
  1427. player.setSecurityPin(value);
  1428. player.getDialogueManager().startDialogue("SimpleMessage","Your security pin has been set to "+player.getSecurityPin()+".<br>"
  1429. + "<col=ff0000>Please make sure to write down this number somewhere incase you might forget it!");
  1430. return;
  1431. }
  1432. if(value == player.getSecurityPin()){
  1433. player.unlock();
  1434. player.resetSecurityWarning();
  1435. player.getDialogueManager().startDialogue("SimpleMessage","Welcome "+player.getDisplayName()+", your session is now authenticated.");
  1436. }
  1437. if(value != player.getSecurityPin()){
  1438. player.setSecurityWarning();
  1439. if(player.getSecurityWarning() < 5){
  1440. player.getPackets().sendInputIntegerScript("Please insert your character's security pin.<br>"
  1441. + "Attempts Remaining :"+player.getSecurityWarning()+"/5 .");
  1442. player.getTemporaryAttributtes().put("securityPin", Boolean.TRUE);
  1443. }
  1444. if(player.getSecurityWarning() >= 5){
  1445. player.resetSecurityWarning();
  1446. player.disconnect(true, false);
  1447. player.setSecurityWarningTimer();
  1448. }
  1449. }
  1450. }
  1451.  
  1452. else if (player.getControlerManager().getControler() != null
  1453. && player.getTemporaryAttributtes().get(Key.SERVANT_REQUEST_ITEM) != null) {
  1454. Integer type = (Integer) player.getTemporaryAttributtes().remove(Key.SERVANT_REQUEST_TYPE);
  1455. Integer item = (Integer) player.getTemporaryAttributtes().remove(Key.SERVANT_REQUEST_ITEM);
  1456. if (!player.getHouse().isLoaded() || !player.getHouse().getPlayers().contains(player) || type == null
  1457. || item == null)
  1458. return;
  1459. player.getHouse().getServantInstance().requestType(item, value, type.byteValue());
  1460. } else if (player.getTemporaryAttributtes().remove("xformring") == Boolean.TRUE)
  1461. player.getAppearence().transformIntoNPC(value);
  1462. else if (player.getTemporaryAttributtes().remove(Key.SELL_SPIRIT_SHARDS) != null)
  1463. PetShopOwner.sellShards(player, value);
  1464. else if (player.getTemporaryAttributtes().get("selected_neg") != null) {
  1465. int selectedSkill = (int) player.getTemporaryAttributtes().get("selected_neg");
  1466. int skillLevel = player.getSkills().getLevelForXp(selectedSkill);
  1467. if (value >= skillLevel) {
  1468. if (skillLevel == 1)
  1469. value = 1;
  1470. else
  1471. value = skillLevel - 1;
  1472. } else if (value == 0)
  1473. value = 1;
  1474. int skillOffset = skillLevel - value;
  1475. if (skillOffset <= 0)
  1476. skillOffset = 0;
  1477. int price = SkillAlchemist.calculatePrice(player, skillOffset);
  1478. player.getDialogueManager().finishDialogue();
  1479. if (player.getInventory().getCoinsAmount() < price) {
  1480. player.getDialogueManager().startDialogue("SimpleNPCMessage", 5585, "You need " + price
  1481. + " amount of coins, in order to reduce your level by " + skillOffset + ".");
  1482. return;
  1483. } else if (player.getEquipment().wearingArmour()) {
  1484. player.getDialogueManager().startDialogue("SimpleNPCMessage", 5585,
  1485. "Please remove any equipment you have equipped, the tranmutation possibly could damage other metals and fabrics.");
  1486. return;
  1487. } else {
  1488. if (player.getFamiliar() != null)
  1489. player.getFamiliar().dissmissFamiliar(false);
  1490. player.getPrayer().closeAllPrayers();
  1491. player.getSkills().set(selectedSkill, value);
  1492. player.getSkills().setXp(selectedSkill, Skills.getXPForLevel(value));
  1493. player.getAppearence().generateAppearenceData();
  1494. player.getInventory().removeItemMoneyPouch(new Item(995, price));
  1495. player.getDialogueManager().startDialogue("SimpleMessage",
  1496. "As your coins transmute, you begin feel like your forgetting something...");
  1497. if (player.isExtremeDonator())
  1498. player.getPackets()
  1499. .sendGameMessage("You notice that your gold is still the same quantity as before....");
  1500. }
  1501. } else if (player.getTemporaryAttributtes().remove("kilnX") != null) {
  1502. int componentId = (Integer) player.getTemporaryAttributtes().get("sc_component");
  1503. if (player.getControlerManager().getControler() instanceof StealingCreationController) {
  1504. StealingCreationController controller = (StealingCreationController) player.getControlerManager()
  1505. .getControler();
  1506. player.getTemporaryAttributtes().put("sc_amount_making", value);
  1507. controller.processKilnExchange(componentId, 50);
  1508. }
  1509. } else if (player.getTemporaryAttributtes().get("sc_request") != null) {
  1510. int requestedId = (int) player.getTemporaryAttributtes().get("sc_request");
  1511. WorldTile tile = (WorldTile) player.getTemporaryAttributtes().get("sc_object");
  1512. if (ItemDefinitions.getItemDefinitions(requestedId).isStackable()) {
  1513. FloorItem item = World.getRegion(player.getRegionId()).getGroundItem(requestedId, tile, player);
  1514. if (item == null)
  1515. return;
  1516. if (item.getAmount() > value) {
  1517. World.addGroundItem(new Item(requestedId, item.getAmount() - value), tile);
  1518. item.setAmount(value);
  1519. }
  1520. if (player.getControlerManager().canTakeItem(item))
  1521. World.removeGroundItem(player, item);
  1522. } else {
  1523. if (value > 28)
  1524. value = 28;
  1525. for (int i = 0; i < value; i++) {
  1526. FloorItem item = World.getRegion(player.getRegionId()).getGroundItem(requestedId, tile, player);
  1527. if (item == null || !player.getControlerManager().canTakeItem(item))
  1528. break;
  1529. World.removeGroundItem(player, item);
  1530. }
  1531. }
  1532. } else if (player.getTemporaryAttributtes().get("skillId") != null) {
  1533. Integer skill = (Integer) player.getTemporaryAttributtes().remove("skillId");
  1534. player.getDialogueManager().finishDialogue();
  1535. if (value > 99) {
  1536. player.getPackets().sendGameMessage("Please choose a valid level.");
  1537. return;
  1538. }
  1539. player.getSkills().set(skill, value);
  1540. player.getSkills().setXp(skill, Skills.getXPForLevel(value));
  1541. player.getPrayer().closeAllPrayers();
  1542. player.getAppearence().generateAppearenceData();
  1543. }
  1544. } else if (opcode == SWITCH_INTERFACE_COMPONENTS_PACKET) {
  1545. int toSlotId2 = stream.readUnsignedShort128();
  1546. int fromSlotId2 = stream.readUnsignedShortLE128();
  1547. int toInterfaceHash = stream.readIntV1();
  1548. int fromInterfaceHash = stream.readInt();
  1549. int toSlot = stream.readUnsignedShortLE128();
  1550. int fromSlot = stream.readUnsignedShort();
  1551.  
  1552. int toInterfaceId = toInterfaceHash >> 16;
  1553. int toComponentId = toInterfaceHash - (toInterfaceId << 16);
  1554. int fromInterfaceId = fromInterfaceHash >> 16;
  1555. int fromComponentId = fromInterfaceHash - (fromInterfaceId << 16);
  1556. if (Settings.DEBUG)
  1557. System.out.println("Switch item " + fromInterfaceId + ", " + toInterfaceId + ", " + fromSlot + ", "
  1558. + toSlot + ", " + fromComponentId + ", " + toComponentId);
  1559.  
  1560. if (Utils.getInterfaceDefinitionsSize() <= fromInterfaceId
  1561. || Utils.getInterfaceDefinitionsSize() <= toInterfaceId)
  1562. return;
  1563. if (!player.getInterfaceManager().containsInterface(fromInterfaceId)
  1564. || !player.getInterfaceManager().containsInterface(toInterfaceId))
  1565. return;
  1566. if (fromComponentId != -1
  1567. && Utils.getInterfaceDefinitionsComponentsSize(fromInterfaceId) <= fromComponentId)
  1568. return;
  1569. if (toComponentId != -1 && Utils.getInterfaceDefinitionsComponentsSize(toInterfaceId) <= toComponentId)
  1570. return;
  1571. if ((fromInterfaceId == Inventory.INVENTORY_INTERFACE || fromInterfaceId == Inventory.INVENTORY_INTERFACE_2)
  1572. && (toInterfaceId == Inventory.INVENTORY_INTERFACE
  1573. || toInterfaceId == Inventory.INVENTORY_INTERFACE_2)) {
  1574. if (toSlot < 0 || toSlot >= player.getInventory().getItemsContainerSize()
  1575. || fromSlot >= player.getInventory().getItemsContainerSize())
  1576. return;
  1577. player.getInventory().switchItem(fromSlot, toSlot);
  1578. } else if ((fromInterfaceId == Inventory.INVENTORY_INTERFACE
  1579. || fromInterfaceId == Inventory.INVENTORY_INTERFACE_2)
  1580. && ((toInterfaceId == 1462 && toComponentId == 14)
  1581. || (toInterfaceId == 1464 && toComponentId == 15))) {
  1582. if (fromSlot >= player.getInventory().getItemsContainerSize()
  1583. || player.getInterfaceManager().containsInventoryInter())
  1584. return;
  1585. Item item = player.getInventory().getItem(fromSlot);
  1586. if (item == null)
  1587. return;
  1588. ItemDefinitions defs = ItemDefinitions.getItemDefinitions(item.getId());
  1589. if (!defs.isWearItem())
  1590. return;
  1591. InventoryOptionsHandler.handleItemOption2(player, fromSlot, item.getId(), item);
  1592. } else if (((fromInterfaceId == 1462 && fromComponentId == 14)
  1593. || (fromInterfaceId == 1464 && fromComponentId == 15))
  1594. && (toInterfaceId == Inventory.INVENTORY_INTERFACE
  1595. || toInterfaceId == Inventory.INVENTORY_INTERFACE_2)) {
  1596. if (fromSlot >= player.getEquipment().getItems().getSize()
  1597. || player.getInterfaceManager().containsInventoryInter())
  1598. return;
  1599.  
  1600. Item item = player.getEquipment().getItem(fromSlot);
  1601. if (item == null)
  1602. return;
  1603. ItemDefinitions defs = ItemDefinitions.getItemDefinitions(item.getId());
  1604. if (!defs.isWearItem())
  1605. return;
  1606. player.getEquipment().handleEquipment(defs.getEquipSlot(), item.getId(),
  1607. WorldPacketsDecoder.ACTION_BUTTON1_PACKET);
  1608. } else if (toInterfaceId == 1430 && (toComponentId >= 55 && toComponentId <= 229)
  1609. || (toInterfaceId == 1436 && (toComponentId >= 25 && toComponentId <= 194))) { // ability
  1610. // bar
  1611. // switch shortcut
  1612. if (fromInterfaceId == 1430 && (fromComponentId >= 55 && fromComponentId <= 229)
  1613. || (fromInterfaceId == 1436 && (fromComponentId >= 25 && fromComponentId <= 194)))
  1614. player.getActionbar().switchShortcut((fromComponentId - (fromInterfaceId == 1430 ? 55 : 25)) / 13,
  1615. (toComponentId - (toInterfaceId == 1430 ? 55 : 25)) / 13);
  1616. // item shortcut inv
  1617. else if (fromInterfaceId == Inventory.INVENTORY_INTERFACE
  1618. || fromInterfaceId == Inventory.INVENTORY_INTERFACE_2) {
  1619. if (fromSlot >= player.getInventory().getItemsContainerSize())
  1620. return;
  1621. Item item = player.getInventory().getItem(fromSlot);
  1622. if (item == null || item.getId() != fromSlotId2)
  1623. return;
  1624. player.getActionbar().setShortcut((toComponentId - (toInterfaceId == 1430 ? 55 : 25)) / 13,
  1625. new ItemShortcut(item.getId()));
  1626. // item shortcut equip
  1627. } else if ((fromInterfaceId == 1464 && fromComponentId == 15)
  1628. || (fromInterfaceId == 1464 && fromComponentId == 14)) {
  1629. if (fromSlot >= player.getEquipment().getItems().getSize())
  1630. return;
  1631. Item item = player.getEquipment().getItem(fromSlot);
  1632. if (item == null || item.getId() != fromSlotId2)
  1633. return;
  1634. player.getActionbar().setShortcut((toComponentId - (toInterfaceId == 1430 ? 55 : 25)) / 13,
  1635. new ItemShortcut(item.getId()));
  1636. // spell shortcut
  1637. // Switch item 1464, 1430, 3, 65535, 15, 142
  1638. } else if (fromInterfaceId == 1461 && fromComponentId == 1) {
  1639. if (Magic.getSpellData(fromSlot) == null) // fake spell
  1640. return;
  1641. player.getActionbar().setShortcut((toComponentId - (toInterfaceId == 1430 ? 55 : 25)) / 13,
  1642. new MagicAbilityShortcut(fromSlot));
  1643.  
  1644. } else if (fromInterfaceId == 1449 && fromComponentId == 1) {
  1645. boolean usingDefenceAbilities = player.getCombatDefinitions().onDefenceMenu();
  1646. if (ActionBar.getAbilityData(usingDefenceAbilities ? ActionBar.DEFENCE_ABILITY_SHORTCUT
  1647. : ActionBar.HEAL_ABILITY_SHORTCUT, fromSlot) == null) // fake
  1648. // spell
  1649. return;
  1650. player.getActionbar().setShortcut((toComponentId - (toInterfaceId == 1430 ? 55 : 25)) / 13,
  1651. usingDefenceAbilities ? new DefenceAbilityShortcut(fromSlot)
  1652. : new HealAbilityShortcut(fromSlot));
  1653. } else if (fromInterfaceId == 1452 && fromComponentId == 1) {
  1654. if (ActionBar.getAbilityData(ActionBar.RANGED_ABILITY_SHORTCUT, fromSlot) == null) // fake
  1655. // spell
  1656. return;
  1657. player.getActionbar().setShortcut((toComponentId - (toInterfaceId == 1430 ? 55 : 25)) / 13,
  1658. new RangeAbilityShortcut(fromSlot));
  1659. // prayer shortcut
  1660. } else if (fromInterfaceId == 1460 && fromComponentId == 1) {
  1661. boolean usingStrAbilities = player.getCombatDefinitions().onStrengthMenu();
  1662. if (ActionBar.getAbilityData(
  1663. usingStrAbilities ? ActionBar.STRENGTH_ABILITY_SHORTCUT : ActionBar.MELEE_ABILITY_SHORTCUT,
  1664. fromSlot) == null) // fake spell
  1665. return;
  1666. player.getActionbar().setShortcut((toComponentId - (toInterfaceId == 1430 ? 55 : 25)) / 13,
  1667. usingStrAbilities ? new StrengthAbilityShortcut(fromSlot)
  1668. : new MeleeAbilityShortcut(fromSlot));
  1669. } else if (fromInterfaceId == 1458 && fromComponentId == 31) {
  1670. if (!player.getPrayer().exists(fromSlot))
  1671. return;
  1672. player.getActionbar().setShortcut((toComponentId - (toInterfaceId == 1430 ? 55 : 25)) / 13,
  1673. new PrayerShortcut(fromSlot, player.getPrayer().isAncientCurses()));
  1674. }
  1675. } else if (fromInterfaceId == 1430 && (fromComponentId >= 55 && fromComponentId <= 229)
  1676. || (fromInterfaceId == 1436 && (fromComponentId >= 25 && fromComponentId <= 194))) { // ability
  1677. // bar
  1678. // drag
  1679. // inventory droping drag
  1680. if ((toInterfaceId == InterfaceManager.RESIZABLE_WINDOW_ID && toComponentId == 18))
  1681. player.getActionbar().clearShortcut((fromComponentId - (fromInterfaceId == 1430 ? 55 : 25)) / 13);
  1682. } else if ((fromInterfaceId == Inventory.INVENTORY_INTERFACE
  1683. || fromInterfaceId == Inventory.INVENTORY_INTERFACE_2)
  1684. && (toInterfaceId == InterfaceManager.RESIZABLE_WINDOW_ID && toComponentId == 18)) {
  1685. if (fromSlot >= player.getInventory().getItemsContainerSize())
  1686. return;
  1687. Item item = player.getInventory().getItem(fromSlot);
  1688. if (item == null || item.getId() != fromSlotId2)
  1689. return;
  1690. InventoryOptionsHandler.handleItemOption7(player, fromSlot, fromSlotId2, item);
  1691. } else if (fromInterfaceId == 762 && toInterfaceId == 762) {
  1692. if (fromComponentId == 7 && toComponentId == 7) {
  1693. if (toSlot >= player.getInventory().getItemsContainerSize()
  1694. || fromSlot >= player.getInventory().getItemsContainerSize())
  1695. return;
  1696. player.getInventory().switchItem(fromSlot, toSlot);
  1697. } else if (fromComponentId == 7 && toComponentId != 7) {
  1698.  
  1699. } else if (fromComponentId == 215 && toComponentId == 7) {
  1700.  
  1701. } else
  1702. player.getBank().switchItem(fromSlot, toSlot, fromComponentId, toComponentId);
  1703.  
  1704. } else if (fromInterfaceId == 1265 && toInterfaceId == 1266
  1705. && player.getTemporaryAttributtes().get("is_buying") != null) {
  1706. if ((boolean) player.getTemporaryAttributtes().get("is_buying") == true) {
  1707. Shop shop = (Shop) player.getTemporaryAttributtes().get("shop_instance");
  1708. if (shop == null)
  1709. return;
  1710. // shop.buyItem(player, fromSlot, 1);
  1711. }
  1712. } else if ((fromInterfaceId == 34 || fromInterfaceId == 1417)
  1713. && (toInterfaceId == 34 || toInterfaceId == 1417))
  1714. player.getNotes().switchNotes(fromSlot, toSlot);
  1715. } else if (opcode == DONE_LOADING_REGION_PACKET) {
  1716. /*
  1717. * if(!player.clientHasLoadedMapRegion()) { //load objects and items
  1718. * here player.setClientHasLoadedMapRegion(); }
  1719. * //player.refreshSpawnedObjects(); //player.refreshSpawnedItems();
  1720. */
  1721. if (!player.isRunAfterLoad())
  1722. player.runAfterLoad();
  1723. if (!player.clientHasLoadedMapRegionFinished()) {
  1724. // load objects and items here
  1725. player.setClientHasLoadedMapRegion();
  1726. player.refreshSpawnedObjects();
  1727. player.refreshSpawnedItems();
  1728. }
  1729. } else if (opcode == GARBAGE_CLEAR_PACKET) {
  1730. if (!player.isRunAfterLoad())
  1731. player.runAfterLoad();
  1732. if (!player.clientHasLoadedMapRegionFinished()) {
  1733. // load objects and items here
  1734. player.setClientHasLoadedMapRegion();
  1735. player.refreshSpawnedObjects();
  1736. player.refreshSpawnedItems();
  1737. }
  1738. } else if (opcode == WALKING_PACKET || opcode == MINI_WALKING_PACKET || opcode == GROUND_ITEM_OPTION_2
  1739. || opcode == ITEM_TAKE_PACKET || opcode == PLAYER_OPTION_2_PACKET || opcode == PLAYER_OPTION_3_PACKET
  1740. || opcode == PLAYER_OPTION_4_PACKET || opcode == PLAYER_OPTION_6_PACKET
  1741. || opcode == PLAYER_OPTION_9_PACKET || opcode == PLAYER_OPTION_1_PACKET || opcode == ATTACK_NPC_PACKET
  1742. || opcode == INTERFACE_ON_PLAYER || opcode == INTERFACE_ON_NPC || opcode == NPC_CLICK1_PACKET
  1743. || opcode == NPC_CLICK2_PACKET || opcode == NPC_CLICK3_PACKET || opcode == NPC_CLICK4_PACKET
  1744. || opcode == OBJECT_CLICK1_PACKET || opcode == SWITCH_INTERFACE_COMPONENTS_PACKET
  1745. || opcode == OBJECT_CLICK2_PACKET || opcode == OBJECT_CLICK3_PACKET || opcode == OBJECT_CLICK4_PACKET
  1746. || opcode == OBJECT_CLICK5_PACKET || opcode == INTERFACE_ON_OBJECT) {
  1747. if (!player.isRunning())
  1748. return;
  1749. player.addLogicPacketToQueue(new LogicPacket(opcode, stream));
  1750. } else if (opcode == OBJECT_EXAMINE_PACKET) {
  1751. ObjectHandler.handleOption(player, stream, -1);
  1752. } else if (opcode == NPC_EXAMINE_PACKET) {
  1753. NPCHandler.handleExamine(player, stream);
  1754. } else if (opcode == JOIN_FRIEND_CHAT_PACKET) {
  1755. if (!player.hasStarted())
  1756. return;
  1757. String str = stream.getLength() == 0 ? null : stream.readString();
  1758. if (str == null)
  1759. FriendsChat.requestLeave(player);
  1760. else
  1761. FriendsChat.requestJoin(player, Utils.formatPlayerNameForDisplay(str));
  1762. } else if (opcode == KICK_FRIEND_CHAT_PACKET) {
  1763. if (!player.hasStarted())
  1764. return;
  1765. if (player.getCurrentFriendsChat() != null)
  1766. player.getCurrentFriendsChat().kickMember(player,
  1767. Utils.formatPlayerNameForDisplay(stream.readString()));
  1768. } else if (opcode == KICK_CLAN_CHAT_PACKET) {
  1769. if (!player.hasStarted())
  1770. return;
  1771. boolean guest = stream.readByte() == 1;
  1772. if (!guest)
  1773. return;
  1774. stream.readUnsignedShort();
  1775. player.kickPlayerFromClanChannel(stream.readString());
  1776. } else if (opcode == CHANGE_FRIEND_CHAT_PACKET) {
  1777. if (!player.hasStarted() || !player.getInterfaceManager().containsInterface(1108))
  1778. return;
  1779. player.getFriendsIgnores().changeRank(Utils.formatPlayerNameForDisplay(stream.readString()),
  1780. stream.readUnsignedByteC());
  1781. } else if (opcode == UPDATE_GAMEBAR_PACKET) {
  1782. if (!player.hasStarted())
  1783. return;
  1784. int public_ = stream.readUnsignedByte();
  1785. int private_ = stream.readUnsignedByte();
  1786. int trade = stream.readUnsignedByte();
  1787. if (!player.isLobby()) {
  1788. player.setPublicStatus(public_);
  1789. player.setTradeStatus(trade);
  1790. }
  1791. player.getFriendsIgnores().setPmStatus(private_, true);
  1792. } else if (opcode == ADD_FRIEND_PACKET) {
  1793. if (!player.hasStarted())
  1794. return;
  1795. player.getFriendsIgnores().addFriend(Utils.formatPlayerNameForDisplay(stream.readString()));
  1796. } else if (opcode == REMOVE_FRIEND_PACKET) {
  1797. if (!player.hasStarted())
  1798. return;
  1799. player.getFriendsIgnores().removeFriend(Utils.formatPlayerNameForDisplay(stream.readString()));
  1800. } else if (opcode == ADD_IGNORE_PACKET) {
  1801. if (!player.hasStarted())
  1802. return;
  1803. player.getFriendsIgnores().addIgnore(Utils.formatPlayerNameForDisplay(stream.readString()),
  1804. stream.readUnsignedByte() == 1);
  1805. } else if (opcode == REMOVE_IGNORE_PACKET) {
  1806. if (!player.hasStarted())
  1807. return;
  1808. player.getFriendsIgnores().removeIgnore(Utils.formatPlayerNameForDisplay(stream.readString()));
  1809. } else if (opcode == SEND_FRIEND_MESSAGE_PACKET) {
  1810. if (!player.hasStarted())
  1811. return;
  1812. String target = stream.readString();
  1813. String message = Huffman.decodeString(150, stream);
  1814. player.getFriendsIgnores().sendPrivateMessage(target, message);
  1815. } else if (opcode == SEND_FRIEND_QUICK_CHAT_PACKET) {
  1816. if (!player.hasStarted())
  1817. return;
  1818. String target = stream.readString();
  1819. int qcFileId = stream.readUnsignedShort();
  1820. long[] data = null;
  1821. QuickChatOptionDefinition option = QuickChatOptionDefinition.loadOption(qcFileId);
  1822. if (option.dynamicDataTypes != null) {
  1823. data = new long[option.dynamicDataTypes.length];
  1824. for (int i = 0; i < option.dynamicDataTypes.length; i++) {
  1825. if (option.getType(i).clientToServerBytes > 0) {
  1826. data[i] = stream.readDynamic(option.getType(i).clientToServerBytes);
  1827. }
  1828.  
  1829. }
  1830. }
  1831. player.getFriendsIgnores().sendPrivateMessage(target, option, data);
  1832. } else if (opcode == PUBLIC_QUICK_CHAT_PACKET) {
  1833. if (!player.hasStarted())
  1834. return;
  1835. if (player.getLastPublicMessage() > Utils.currentTimeMillis())
  1836. return;
  1837. player.setLastPublicMessage(Utils.currentTimeMillis() + 300);
  1838.  
  1839. int quickChatType = stream.readUnsignedByte(); // quickchat does not
  1840. // use chattype as
  1841. // it's only
  1842. // temporary!!!
  1843.  
  1844. int qcFileId = stream.readUnsignedShort();
  1845.  
  1846. long[] data = null;
  1847. QuickChatOptionDefinition option = QuickChatOptionDefinition.loadOption(qcFileId);
  1848. if (option.dynamicDataTypes != null) {
  1849. data = new long[option.dynamicDataTypes.length];
  1850. for (int i = 0; i < option.dynamicDataTypes.length; i++) {
  1851. if (option.getType(i).clientToServerBytes > 0) {
  1852. data[i] = stream.readDynamic(option.getType(i).clientToServerBytes);
  1853. }
  1854.  
  1855. }
  1856. }
  1857. if (quickChatType == 0)
  1858. player.sendPublicChatMessage(new QuickChatMessage(player, option, data));
  1859. else if (quickChatType == 1) {
  1860. if (player.getCurrentFriendsChat() != null)
  1861. player.getCurrentFriendsChat().sendMessage(player, option, data);
  1862. } else if (quickChatType == 2)
  1863. player.sendClanChannelQuickMessage(new QuickChatMessage(player, option, data));
  1864. else if (quickChatType == 3)
  1865. player.sendGuestClanChannelQuickMessage(new QuickChatMessage(player, option, data));
  1866. else if (Settings.DEBUG)
  1867. Logger.log(this, "Unknown chat type: " + quickChatType);
  1868. } else if (opcode == CHAT_TYPE_PACKET) {
  1869. chatType = stream.readUnsignedByte();
  1870. } else if (opcode == CHAT_PACKET) {
  1871. if (!player.hasStarted())
  1872. return;
  1873. if (player.getLastPublicMessage() > Utils.currentTimeMillis())
  1874. return;
  1875. player.setLastPublicMessage(Utils.currentTimeMillis() + 300);
  1876. int colorEffect = stream.readUnsignedByte();
  1877. int moveEffect = stream.readUnsignedByte();
  1878. String message = Huffman.decodeString(200, stream);
  1879. if (message == null || message.replaceAll(" ", "").equals(""))
  1880. return;
  1881. if (message.startsWith("::") || message.startsWith(";;")) {
  1882. // if command exists and processed wont send message as public
  1883. // message
  1884. Commands.processCommand(player, message.replace("::", "").replace(";;", ""), false, false);
  1885. return;
  1886. }
  1887. if (player.isMuted()) {
  1888. player.getPackets().sendGameMessage("You temporary muted. Recheck in 48 hours.");
  1889. return;
  1890. }
  1891. int effects = (colorEffect << 8) | (moveEffect & 0xff);
  1892. if ((effects & 0x8000) != 0)
  1893. return; // someone trying to crash server using qc as chat
  1894. // effect in normal chat
  1895. if (chatType == 1) {
  1896. if (player.getCurrentFriendsChat() != null) {
  1897. if (message.equals("[Attempting to kick/ban user from this Friends Chat.]"))
  1898. return;
  1899. player.getCurrentFriendsChat().sendMessage(player, message);
  1900. }
  1901. } else if (chatType == 2)
  1902. player.sendClanChannelMessage(new ChatMessage(message));
  1903. else if (chatType == 3)
  1904. player.sendGuestClanChannelMessage(new ChatMessage(message));
  1905. else {
  1906. // Think i also fixed the large view scene thing, but just
  1907. // incase, spoof message
  1908. if (player.getControlerManager().getControler() instanceof DungeonController) {
  1909. for (Player party : player.getDungManager().getParty().getTeam()) {
  1910. /*
  1911. * if (player.getLocalPlayerUpdate().getLocalPlayers()[
  1912. * party.getIndex()] == null ||
  1913. * party.getLocalPlayerUpdate().getLocalPlayers()[player
  1914. * .getIndex()] == null) {
  1915. * party.getPackets().sendGameMessage(player.
  1916. * getDisplayName() + ":<col=7fa9ff> " + message); }
  1917. */
  1918. party.getPackets().sendPublicMessage(player, new PublicChatMessage(message, effects));
  1919. }
  1920. } else
  1921. player.sendPublicChatMessage(new PublicChatMessage(message, effects));
  1922. }
  1923. if (Settings.DEBUG)
  1924. Logger.log(this, "Chat type: " + chatType);
  1925. } else if (opcode == COMMANDS_PACKET) {
  1926. if (!player.isRunning())
  1927. return;
  1928. boolean clientCommand = stream.readUnsignedByte() == 1;
  1929. @SuppressWarnings("unused")
  1930. boolean unknown = stream.readUnsignedByte() == 1;
  1931. String command = stream.readString();
  1932. if (!Commands.processCommand(player, command, true, clientCommand) && Settings.DEBUG)
  1933. Logger.log(this, "Command: " + command);
  1934. } else if (opcode == COLOR_ID_PACKET) {
  1935. if (!player.hasStarted())
  1936. return;
  1937. int colorId = stream.readUnsignedShort();
  1938. if (player.getTemporaryAttributtes().get("SkillcapeCustomize") != null)
  1939. SkillCapeCustomizer.handleSkillCapeCustomizerColor(player, colorId);
  1940. else if (player.getTemporaryAttributtes().get("MottifCustomize") != null)
  1941. ClansManager.setMottifColor(player, colorId);
  1942. else if (player.getTemporaryAttributtes().remove(Key.COSTUME_COLOR_CUSTOMIZE) != null)
  1943. SkillCapeCustomizer.handleCostumeColor(player, colorId);
  1944. } else if (opcode == REPORT_ABUSE_PACKET) {
  1945. if (!player.hasStarted())
  1946. return;
  1947. String displayName = stream.readString();
  1948. int type = stream.readUnsignedByte();
  1949. boolean mute = stream.readUnsignedByte() == 1;
  1950. @SuppressWarnings("unused")
  1951. String unknown2 = stream.readString();
  1952. ReportAbuse.report(player, displayName, type, mute);
  1953. } else if (opcode == FORUM_THREAD_ID_PACKET) {
  1954. String threadId = stream.readString();
  1955. if (player.getInterfaceManager().containsInterface(1100))
  1956. ClansManager.setThreadIdInterface(player, threadId);
  1957. else if (Settings.DEBUG)
  1958. Logger.log(this, "Called FORUM_THREAD_ID_PACKET: " + threadId);
  1959. } else if (opcode == OPEN_URL_PACKET) {
  1960. String type = stream.readString();
  1961. String path = stream.readString();
  1962. String unknown = stream.readString();
  1963. int flag = stream.readUnsignedByte();
  1964. if (Settings.DEBUG)
  1965. Logger.log(WorldPacketsDecoder.class,
  1966. "openUrl(" + type + "," + path + "," + unknown + "," + flag + ")");
  1967. if (type.equals("clan-forum"))
  1968. player.getPackets().sendOpenURL(Settings.SHOWTHREAD_LINK + path.replace("threads.ws?threadid=", ""));
  1969. else if (path.contains("messages"))
  1970. player.getPackets().sendOpenURL(Settings.VOTE_LINK);
  1971. else if (path.contains("set_members_dob") || path.contains("userdetails"))
  1972. player.getPackets().sendOpenURL(Settings.STORE_LINK);
  1973. else if (path.contains("recoveries"))
  1974. player.getPackets().sendOpenURL(Settings.OFFENCES_LINK);
  1975. else if (path.contains("mod=email"))
  1976. player.getPackets().sendOpenURL(Settings.EMAIL_LINK);
  1977. else if (path.contains("title.ws") || path.toLowerCase().contains("squeal"))
  1978. player.getPackets().sendOpenURL(Settings.FORUMS_LINK);
  1979. } else if (opcode == GRAND_EXCHANGE_ITEM_SELECT_PACKET) {
  1980. int itemId = stream.readUnsignedShort();
  1981. player.getGeManager().chooseItem(itemId);
  1982. }
  1983.  
  1984. else if (opcode == ITEM_EXAMINE_PACKET) {
  1985. if (!player.hasStarted() || !player.clientHasLoadedMapRegion() || player.isDead())
  1986. return;
  1987. if (player.isLocked())
  1988. return;
  1989. int y = stream.readUnsignedShortLE128();
  1990. int id = stream.readUnsignedShort128();
  1991. boolean forceRun = stream.readByte() == 1;
  1992. int x = stream.readShort128();
  1993. final WorldTile tile = new WorldTile(x, y, player.getPlane());
  1994. final int regionId = tile.getRegionId();
  1995. if (!player.getMapRegionsIds().contains(regionId))
  1996. return;
  1997. final FloorItem item = World.getRegion(regionId).getGroundItem(id, tile, player);
  1998. if (item == null)
  1999. return;
  2000.  
  2001. if (item.getDefinitions().noted == true){
  2002. player.getPackets().sendEntityMessage(1, 14338209, player, ItemExamines.getExamine(item) + (ItemConstants.isTradeable(item)
  2003. ? "<br>GE guide price: " + GrandExchange.getGrandExchangePrice(item.getDefinitions().getCertId()) + " gp" : ""));
  2004.  
  2005. return;
  2006. }
  2007. player.getPackets().sendEntityMessage(1, 14338209, player, ItemExamines.getExamine(item) + (ItemConstants.isTradeable(item)
  2008. ? "<br>GE guide price: " + GrandExchange.getGrandExchangePrice(item.getId()) + " gp" : ""));
  2009.  
  2010.  
  2011.  
  2012. }
  2013. else if (opcode == INTERFACE_ON_GROUND){
  2014. int TELEGRAB = 32;
  2015. if (!player.hasStarted() || !player.clientHasLoadedMapRegion() || player.isDead())
  2016. return;
  2017. if (player.isLocked())
  2018. return;
  2019. int forceRun = stream.read128Byte();
  2020. int componentId = stream.readShort128();
  2021. int x = stream.readShort128();
  2022. int interfaceId = stream.readIntV2();
  2023. int itemId2 = stream.readShort();
  2024. int y = stream.readShort();
  2025. int itemId3 = stream.readShort128();
  2026. if(componentId == TELEGRAB)
  2027. Magic.handleTeleGrab(player, x, y, itemId3);
  2028.  
  2029. }
  2030.  
  2031. else {
  2032. if (Settings.DEBUG)
  2033. Logger.log(this, "Missing packet " + opcode + ", length: " + stream.getLength() + ", sizedef: "
  2034. + PACKET_SIZES[opcode]);
  2035. }
  2036. }
  2037. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement