Advertisement
Guest User

ActionSender

a guest
Jul 2nd, 2015
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 41.55 KB | None | 0 0
  1. package com.xeno.net;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.FileNotFoundException;
  5. import java.io.FileReader;
  6. import java.io.IOException;
  7.  
  8. import org.apache.mina.common.IoFuture;
  9. import org.apache.mina.common.IoFutureListener;
  10.  
  11. import com.xeno.content.combat.Combat;
  12. import com.xeno.model.Entity;
  13. import com.xeno.model.Item;
  14. import com.xeno.model.Location;
  15. import com.xeno.model.World;
  16. import com.xeno.model.masks.Appearance;
  17. import com.xeno.model.npc.NPC;
  18. import com.xeno.model.player.Player;
  19. import com.xeno.model.player.Skills;
  20. import com.xeno.net.Packet.Size;
  21. import com.xeno.packetbuilder.StaticPacketBuilder;
  22. import com.xeno.util.Misc;
  23. import com.xeno.world.Clan;
  24. import com.xeno.world.GroundItem;
  25. import com.xeno.world.grandexchange.BuyOffer;
  26. import com.xeno.world.grandexchange.GEItem;
  27.  
  28. /**
  29. *
  30. * Outgoing packets that we send so the end user does not have to mess with the builders.
  31. * @author Graham
  32. * @author Luke132
  33. */
  34. public class ActionSender {
  35.  
  36. private Player player;
  37. private int count = 0;
  38.  
  39. public ActionSender(Player player) {
  40. this.player = player;
  41. }
  42.  
  43. public void sendCloseInterface(int windowId, int position) {
  44. player.getSession().write(new StaticPacketBuilder().setId(149)
  45. .addShort(count++)
  46. .addShort(windowId)
  47. .addShort(position).toPacket());
  48. }
  49.  
  50. public void closeInterfaces() {
  51. if(player.isHd()) {
  52. sendCloseInterface(746, 6); // Main
  53. sendCloseInterface(746, 5); // Main
  54. sendCloseInterface(752, 12); // Chatbox1
  55. sendCloseInterface(752, 11); // Chatbox2
  56. sendCloseInterface(746, 76); // Inventory
  57. } else {
  58. //sendCloseInterface(752, 6); // Chatbox 3
  59. sendCloseInterface(752, 12); // Chatbox1
  60. sendCloseInterface(752, 11); // Chatbox2
  61. sendCloseInterface(548, 11); // Main
  62. sendCloseInterface(548, 80); // Inventory
  63. }
  64. player.getBank().setBanking(false);
  65. player.setShopSession(null);
  66. player.setTrade(null);
  67. player.removeTemporaryAttribute("dialogue");
  68. player.removeTemporaryAttribute("jewelleryTeleport");
  69. if (player.getGESession() != null) {
  70. if (player.getGESession().getCurrentOffer() != null) {
  71. if (player.getGESession().getCurrentOffer() instanceof BuyOffer) {
  72. sendInterface(0, 752, 6, 137); // Removes the item search
  73. }
  74. }
  75. }
  76. player.setGESession(null);
  77. if (player.getDuel() != null) {
  78. if (player.getDuel().getStatus() < 4 || player.getDuel().getStatus() >= 8) {
  79. player.setDuelSession(null);
  80. }
  81. }
  82. }
  83.  
  84. public void softCloseInterfaces() {
  85. if(player.isHd()) {
  86. sendCloseInterface(746, 6); // Main
  87. sendCloseInterface(746, 5); // Main
  88. sendCloseInterface(752, 12); // Chatbox1
  89. sendCloseInterface(752, 11); // Chatbox2
  90. //sendCloseInterface(752, 6); // Chatbox 3
  91. sendCloseInterface(746, 76); // Inventory
  92. } else {
  93. sendCloseInterface(752, 12); // Chatbox1
  94. sendCloseInterface(752, 11); // Chatbox2
  95. //sendCloseInterface(752, 6); // Chatbox 3
  96. sendCloseInterface(548, 11); // Main
  97. sendCloseInterface(548, 80); // Inventory
  98. }
  99. player.removeTemporaryAttribute("dialogue");
  100. }
  101.  
  102. public void closeChatboxInterface() {
  103. sendCloseInterface(752, 12); // Chatbox1
  104. sendCloseInterface(752, 11); // Chatbox2
  105. //sendCloseInterface(752, 6); // Chatbox 3
  106. }
  107.  
  108. public void sendSkillLevels() {
  109. for(int i = 0; i < Skills.SKILL_COUNT; i++) {
  110. sendSkillLevel(i);
  111. }
  112. }
  113.  
  114. public void sendSkillLevel(int skill) {
  115. StaticPacketBuilder spb = new StaticPacketBuilder().setId(38);
  116. if (skill == 5) {
  117. spb.addByteA((byte) Math.ceil(player.getSettings().getPrayerPoints()));
  118. } else {
  119. spb.addByteA((byte) player.getLevels().getLevel(skill));
  120. }
  121. spb.addInt1((int) player.getLevels().getXp(skill));
  122. spb.addByte((byte) skill);
  123. player.getSession().write(spb.toPacket());
  124. }
  125.  
  126.  
  127.  
  128. public void logout() {
  129. if (player.getSettings().getFightCave() == null) {
  130. if (!Combat.isXSecondsSinceCombat(player, player.getLastAttacked(), 10000)) {
  131. sendMessage("You must have been out of combat for 10 seconds before you may log out.");
  132. return;
  133. }
  134. } else
  135. if (player.getSettings().getFightCave() != null) {
  136. if (!player.getSettings().getFightCave().isGamePaused()) {
  137. sendMessage("You will logout at the end of this wave and your progress will be saved.");
  138. sendMessage("Die, or leave via the cave exit to quit the fight cave.");
  139. player.getSettings().getFightCave().setGamePaused(true);
  140. return;
  141. }
  142. }
  143. player.getSession().write(new StaticPacketBuilder().setId(86).toPacket()).addListener(new IoFutureListener() {
  144. @Override
  145. public void operationComplete(IoFuture arg0) {
  146. arg0.getSession().close();
  147. }
  148. });
  149. }
  150.  
  151. public void forceLogout() {
  152. player.getSession().write(new StaticPacketBuilder().setId(86).toPacket()).addListener(new IoFutureListener() {
  153. @Override
  154. public void operationComplete(IoFuture arg0) {
  155. arg0.getSession().close();
  156. }
  157. });
  158. }
  159.  
  160. public void sendLogin() {
  161. player.getUpdateFlags().setAppearanceUpdateRequired(true);
  162. sendWindowPane(player.isHd() ? 746 : 548);
  163. sendSkillLevels();
  164. sendMessage("Welcome to 2009 Rsmvs");
  165. sendEnergy();
  166. sendConfig(173, 0);
  167. refreshInventory();
  168. refreshEquipment();
  169. sendPlayerOption("Follow", 3, 0);
  170. sendPlayerOption("Trade with", 4, 0);
  171. player.getFriends().refresh();
  172. player.getSettings().refresh();
  173. player.getEquipment().setWeapon();
  174. setPrivacyOptions();
  175. }
  176.  
  177. /* BARROW HEADS...NEVER GOT IT TO WORK
  178. *
  179. * this packet variables from #569 = 1572868 243 100 4767
  180. animation = 2085 1572868 244
  181. * StaticPacketBuilder spb = new StaticPacketBuilder().setId(66)
  182. .addLEShortA(lols++)
  183. //.addShort(4761)
  184. .addLEInt(100)
  185. .addInt((2 << 16) + 24);
  186. player.getSession().write(spb.toPacket());
  187. animateInterface(2085, 24, 2);
  188. */
  189.  
  190. //PC CONFIG FOR ABOVE PACKET = 6874, 26673153
  191.  
  192. public void configureGameScreen(int windowType) {
  193. boolean resetVariables = false;
  194. boolean achievementDiary = player.getSettings().isAchievementDiaryTab();
  195. int magicInterface = player.getSettings().getMagicType() == 2 ? 193 : player.getSettings().getMagicType() == 3 ? 430 : 192;
  196. int lastWindowType = (Integer) player.getTemporaryAttribute("lastWindowType") == null ? -1 : (Integer) player.getTemporaryAttribute("lastWindowType");
  197. if (lastWindowType == windowType) {
  198. return;
  199. }
  200. if (windowType == 0 || windowType == 1) {
  201. resetVariables = player.isHd();
  202. player.setHd(false);
  203. sendWindowPane(548);
  204. sendTab(14, 751); // Chat options
  205. sendTab(75, 752); // Chatbox
  206. sendTab(70, 748); // HP bar
  207. sendTab(71, 749); // Prayer bar
  208. sendTab(72, 750); // Energy bar
  209. //sendTab(67, 747); // Summoning bar
  210. sendInterface(1, 752, 8, 137); // Username on chat
  211. sendTab(83, 92); // Attack tab
  212. sendTab(84, 320); // Skill tab
  213. sendTab(85, 274); // Quest tab
  214. sendTab(86, 149); // Inventory tab
  215. sendTab(87, 387); // Equipment tab
  216. sendTab(88, 271); // Prayer tab
  217. sendTab(89, 192); // Magic tab
  218. sendTab(91, 550); // Friend tab
  219. sendTab(92, 551); // Ignore tab
  220. sendTab(93, 589); // Clan tab
  221. sendTab(94, 261); // Setting tab
  222. sendTab(95, 464); // Emote tab
  223. sendTab(96, 187); // Music tab
  224. sendTab(97, 182); // Logout tab
  225. sendTab(10, 754); // PM split chat
  226. } else if (windowType == 2 || windowType == 3) {
  227. resetVariables = !player.isHd();
  228. player.setHd(true);
  229. sendWindowPane(746);
  230. sendTab(23, 751); // Chat options
  231. sendTab(70, 752); // Chatbox
  232. sendInterface(1, 752, 8, 137);
  233. sendTab(13, 748); // HP bar
  234. sendTab(14, 749); // Prayer bar
  235. sendTab(15, 750); // Energy bar
  236. //sendTab(16, 747); // Summoning bar
  237. sendTab(93, 92); // Attack tab
  238. sendTab(94, 320); // Skill tab
  239. sendTab(95, achievementDiary ? 259 : 274); // Quest tab
  240. sendTab(96, 149); // Inventory tab
  241. sendTab(97, 387); // Equipment tab
  242. sendTab(98, 271); // Prayer tab
  243. sendTab(99, magicInterface); // Magic tab
  244. sendTab(101, 550); // Friend tab
  245. sendTab(102, 551); // Ignore tab
  246. sendTab(103, 589); // Clan tab
  247. sendTab(104, 261); // Setting tab
  248. sendTab(105, 464); // Emote tab
  249. sendTab(106, 187); // Music tab
  250. sendTab(107, 182); // Logout tab
  251. sendTab(71, 754); // PM split chat
  252. }
  253. player.setTemporaryAttribute("lastWindowType", windowType);
  254. if (resetVariables) {
  255. player.removeTemporaryAttribute("inMulti");
  256. player.removeTemporaryAttribute("atDuelArea");
  257. player.removeTemporaryAttribute("atBarrows");
  258. player.removeTemporaryAttribute("inWild");
  259. player.removeTemporaryAttribute("atGodwars");
  260. player.removeTemporaryAttribute("atAgilityArena");
  261. player.removeTemporaryAttribute("snowInterface");
  262. player.getEquipment().setWeapon();
  263. }
  264. if (player.getTemporaryAttribute("sendLogin") == null) {
  265. sendLogin();
  266. player.setTemporaryAttribute("sendLogin", true);
  267. }
  268. }
  269.  
  270. /* DROP PARTY ROOM STUFF
  271. displayInterface(647);
  272. displayInventoryInterface(648);
  273. Object[] opts1 = new Object[]{"", "", "", "", "", 42401813, 0, 36, 6, 529, 42401819};
  274. Object[] opts2 = new Object[]{"", "", "", "", "", 42401814, 0, 36, 6, 91, 42401820};
  275. Object[] opts3 = new Object[]{"Withdraw X", "Withdraw All", "Withdraw 10", "Withdraw 5", "Withdraw", -1, 0, 2, 8, 92, 42401821};
  276. Object[] opts4 = new Object[]{"Deposit X", "Deposit All", "Deposit 10", "Deposit 5", "Deposit", -1, 0, 7, 4, 93, 42467328};
  277. sendClientScript2(283, 149, opts1, "IviiiIsssss");
  278. setRightClickOptions(1024, 42401819, 0, 215);
  279. sendClientScript2(285, 149, opts2, "IviiiIsssss");
  280. setRightClickOptions(1024, 42401820, 0, 215);
  281. sendClientScript2(285, 149, opts3, "IviiiIsssss");
  282. setRightClickOptions(1086, 42401821, 0, 15);
  283. sendClientScript2(289, 149, opts4, "IviiiIsssss");
  284. setRightClickOptions(1086, 42467328, 0, 27);
  285. setRightClickOptions(2360446, (648 * 65536), 0, 27);
  286. sendConfig(1135, 32); // egg timer
  287. sendItems(-1, 64000, 91, player.getInventory().getItems()); // Items being dropped
  288. sendItems(-1, 64000, 92, player.getInventory().getItems()); // Items you've deposited
  289. sendItems(-1, 64000, 529, player.getInventory().getItems()); // Items Ready to be dropped
  290. */
  291.  
  292. /*CLUE SCROLL STUFF
  293. * Container<Item> test = new Container<Item>(12, true);
  294. test.add(new Item(7329, 100));
  295. test.add(new Item(7330, 100));
  296. test.add(new Item(7331, 3));
  297. test.add(new Item(10326, 4));
  298. test.add(new Item(10327, 5));
  299. test.add(new Item(7321, 6));
  300. test.add(new Item(7319, 7));
  301. test.add(new Item(7323, 8));
  302. test.add(new Item(7325, 9));
  303. test.add(new Item(7327, 10));
  304. test.add(new Item(1046, 11));
  305. test.add(new Item(1048, 12));
  306. player.getActionSender().sendInterface(364, false);
  307. player.getActionSender().sendAccessMask(1278, 23855108, 364, 0, 12);
  308. player.getActionSender().sendRunScript(150, new Object[] {
  309. "", "", "", "", "", "", "", "", "", -1, 0, 4, 3, 32858, 23855108 }, "IviiiIsssssssss");
  310. player.getActionSender().sendItems(-1, 6, 32858, test);
  311. */
  312.  
  313. /*magic training arena shop
  314. * player.getActionSender().sendInterface(197, false);
  315. Container<Item> items = new Container<Item>(26, true);
  316. items.add(new Item(6908, 10));
  317. items.add(new Item(6910, 10));
  318. items.add(new Item(6912, 10));
  319. items.add(new Item(6914, 10));
  320. items.add(new Item(6916, 10));
  321. items.add(new Item(6918, 10));
  322. items.add(new Item(6920, 10));
  323. items.add(new Item(6922, 10));
  324. items.add(new Item(6924, 10));
  325. items.add(new Item(6889, 10));
  326. items.add(new Item(6926, 1));
  327. items.add(new Item(1391, 100));
  328. items.add(new Item(4695, 100));
  329. items.add(new Item(4696, 100));
  330. items.add(new Item(4698, 100));
  331. items.add(new Item(4697, 100));
  332. items.add(new Item(4694, 100));
  333. items.add(new Item(4699, 100));
  334. items.add(new Item(564, 100));
  335. items.add(new Item(562, 300));
  336. items.add(new Item(561, 100));
  337. items.add(new Item(560, 100));
  338. items.add(new Item(563, 100));
  339. items.add(new Item(566, 100));
  340. items.add(new Item(565, 100));
  341. items.add(new Item(6891, 1));
  342. player.getActionSender().sendItems(-1, -2, 347, items);
  343. player.getActionSender().sendConfig(213, 120);
  344. player.getActionSender().sendString("0", 197, 8);
  345. player.getActionSender().sendString("0", 197, 11);
  346. player.getActionSender().sendString("0", 197, 9);
  347. player.getActionSender().sendString("0", 197, 10);
  348. player.getActionSender().sendAccessMask(1030, 12910608, 197, 0, 25);
  349. */
  350.  
  351. public void sendMapRegion() {
  352. player.getUpdateFlags().setLastRegion(player.getLocation());
  353. if (player.getLocation().getX() >= 19000 && player.getTemporaryAttribute("sendLogin") != null) {
  354. sendFightCaveMapdata();
  355. return;
  356. }
  357. StaticPacketBuilder spb = new StaticPacketBuilder().setId(162).setSize(Packet.Size.VariableShort);
  358. boolean forceSend = true;
  359. if((((player.getLocation().getRegionX() / 8) == 48) || ((player.getLocation().getRegionX() / 8) == 49)) && ((player.getLocation().getRegionY() / 8) == 48)) {
  360. forceSend = false;
  361. }
  362. if(((player.getLocation().getRegionX() / 8) == 48) && ((player.getLocation().getRegionY() / 8) == 148)) {
  363. forceSend = false;
  364. }
  365. spb.addShortA(player.getLocation().getLocalX());
  366. for(int xCalc = (player.getLocation().getRegionX() - 6) / 8; xCalc <= ((player.getLocation().getRegionX() + 6) / 8); xCalc++) {
  367. for(int yCalc = (player.getLocation().getRegionY() - 6) / 8; yCalc <= ((player.getLocation().getRegionY() + 6) / 8); yCalc++) {
  368. int region = yCalc + (xCalc << 8); // 1786653352
  369. if(forceSend || ((yCalc != 49) && (yCalc != 149) && (yCalc != 147) && (xCalc != 50) && ((xCalc != 49) || (yCalc != 47)))) {
  370. int[] mapData = World.getInstance().getMapData(region);
  371. if (mapData == null) {
  372. spb.addInt2(0);
  373. spb.addInt2(0);
  374. spb.addInt2(0);
  375. spb.addInt2(0);
  376. } else {
  377. spb.addInt2(mapData[0]);
  378. spb.addInt2(mapData[1]);
  379. spb.addInt2(mapData[2]);
  380. spb.addInt2(mapData[3]);
  381. }
  382. }
  383. }
  384. }
  385. spb.addByteS(player.getLocation().getZ());
  386. spb.addShort(player.getLocation().getRegionX());
  387. spb.addShortA(player.getLocation().getRegionY());
  388. spb.addShortA(player.getLocation().getLocalY());
  389. player.getSession().write(spb.toPacket());
  390. World.getInstance().getGroundItems().refreshGlobalItems(player);
  391. World.getInstance().getGlobalObjects().refreshGlobalObjects(player);
  392. }
  393.  
  394. private transient int lastX = 0, lastY = 0;
  395.  
  396. public void sendFightCaveMapdata() {
  397. lastX = lastX == 0 ? 2413 : (player.getLocation().getX() - (20000 + (200 * player.getIndex())));
  398. lastY = lastY == 0 ? 5116 : (player.getLocation().getY() - 20000);
  399. StaticPacketBuilder spb = new StaticPacketBuilder().setId(214).setSize(Packet.Size.VariableShort);
  400. spb.addLEShortA(player.getLocation().getLocalX());
  401. spb.addLEShortA(player.getLocation().getRegionX());
  402. spb.addByteS(player.getLocation().getZ());
  403. spb.addLEShortA(player.getLocation().getLocalY());
  404. spb.initBitAccess();
  405. for(int height = 0; height < 4; height++) {
  406. for(int xCalc = ((lastX >> 3) - 6); xCalc <= ((lastX >> 3) + 6); xCalc++) {
  407. for(int yCalc = ((lastY >> 3) - 6); yCalc <= ((lastY >> 3) + 6); yCalc++) {
  408. int region = yCalc / 8 + (xCalc / 8 << 150189352);
  409. if (height == player.getLocation().getZ() && region == 9551) {
  410. spb.addBits(1, 1);
  411. spb.addBits(26, (xCalc << 14) | (yCalc << 3) | (0 << 1) | (0 << 24));
  412. } else {
  413. spb.addBits(1, 0);
  414. }
  415. }
  416. }
  417. }
  418. spb.finishBitAccess();
  419. int[] sent = new int[4 * 13 * 13];
  420. int sentIndex = 0;
  421. for(int xCalc = (((lastX >> 3) - 6) / 8); xCalc <= (((lastX>> 3) + 6) / 8); xCalc++) {
  422. outer:
  423. for(int yCalc = (((lastY >> 3) - 6) / 8); yCalc <= (((lastY>> 3) + 6) / 8); yCalc++) {
  424. int region = yCalc + (xCalc << 8);
  425. if (region != 9551) {
  426. continue;
  427. }
  428. for(int i = 0; i < sentIndex; i++) {
  429. if(sent[i] == region) {
  430. break outer;
  431. }
  432. }
  433. sent[sentIndex] = region;
  434. sentIndex++;
  435. int[] mapData = World.getInstance().getMapData(region);
  436. if (mapData == null) {
  437. spb.addInt2(0);
  438. spb.addInt2(0);
  439. spb.addInt2(0);
  440. spb.addInt2(0);
  441. } else {
  442. spb.addInt2(mapData[0]);
  443. spb.addInt2(mapData[1]);
  444. spb.addInt2(mapData[2]);
  445. spb.addInt2(mapData[3]);
  446. }
  447. }
  448.  
  449. }
  450. spb.addShort(player.getLocation().getRegionY());
  451. player.getSession().write(spb.toPacket());
  452. }
  453.  
  454. public void sendWindowPane(int pane) {
  455. StaticPacketBuilder spb = new StaticPacketBuilder().setId(145)
  456. .addLEShortA(pane)
  457. .addByteA((byte) 0)
  458. .addLEShortA(count++);
  459. player.getSession().write(spb.toPacket());
  460. }
  461.  
  462. public void setFriendsListStatus() {
  463. StaticPacketBuilder spb = new StaticPacketBuilder().setId(197);
  464. spb.addByte((byte) 2);
  465. player.getSession().write(spb.toPacket());
  466. }
  467.  
  468. public void sendTab(int tabId, int childId) {
  469. if(player.isHd()) {
  470. sendInterface(1, childId == 137 ? 752 : 746, tabId, childId);
  471. return;
  472. }
  473. sendInterface(1, childId == 137 ? 752 : 548, tabId, childId);
  474. }
  475.  
  476. public void displayInterface(int id) {
  477. if(player.isHd()) {
  478. sendInterface(0, 746, id == 499 ? 5 : 6, id);
  479. return;
  480. }
  481. sendInterface(0, 548, 11, id);
  482. }
  483.  
  484. public void sendOverlay(int i) {
  485. if (player.isHd()) {
  486. sendInterface(1, 746, 3, i);
  487. return;
  488. }
  489. sendInterface(1, 548, 5, i);
  490. }
  491.  
  492. public void sendRemoveOverlay() {
  493. if (player.isHd()) {
  494. sendCloseInterface(746, 3);
  495. return;
  496. }
  497. sendCloseInterface(548, 5);
  498. }
  499.  
  500. public void displayMultiIcon() {
  501. if (player.isHd()) {
  502. sendInterface(1, 746, 17, 745);
  503. } else {
  504. sendInterface(1, 548, 7, 745);
  505. }
  506. showChildInterface(745, 1, true);
  507. }
  508.  
  509. public void removeMultiIcon() {
  510. if (player.isHd()) {
  511. sendCloseInterface(746, 17);
  512. return;
  513. }
  514. sendCloseInterface(548, 7);
  515. }
  516.  
  517. public void sendInterface(int showId, int windowId, int interfaceId, int childId) {
  518. int id = windowId * 65536 + interfaceId;
  519. StaticPacketBuilder spb = new StaticPacketBuilder().setId(155)
  520. .addByte((byte) showId)
  521. .addInt2(id)
  522. .addShortA(count++)
  523. .addShort(childId);
  524. player.getSession().write(spb.toPacket());
  525. }
  526.  
  527. //p.getActionSender().sendInterface(1, 752, 6, 389);
  528. public void sendInterface3() {
  529. int id = 752 * 65536 + 6;
  530. StaticPacketBuilder spb = new StaticPacketBuilder().setId(155)
  531. .addByte((byte) 0)
  532. .addInt2(id)
  533. .addShortA(count++)
  534. .addShort(389);
  535. player.getSession().write(spb.toPacket());
  536. }
  537.  
  538. public void sendInterface36() {
  539. StaticPacketBuilder spb = new StaticPacketBuilder().setId(155)
  540. .addByte((byte) 0)
  541. .addInt2(49283078)
  542. .addShortA(count++)
  543. .addShort(389);
  544. player.getSession().write(spb.toPacket());
  545. }
  546.  
  547. public void sendConfig(int id, int value) {
  548. if(value < 128 && value > -128) {
  549. sendConfig1(id, value);
  550. } else {
  551. sendConfig2(id, value);
  552. }
  553. }
  554.  
  555. public void sendPlayerOption(String option, int slot, int pos) {
  556. StaticPacketBuilder spb = new StaticPacketBuilder().setId(44).setSize(Size.VariableByte)
  557. .addLEShortA(65535)
  558. .addByte((byte) pos)
  559. .addByte((byte) slot)
  560. .addString(option);
  561. player.getSession().write(spb.toPacket());
  562. }
  563.  
  564. public void sendConfig1(int id, int value) {
  565. player.getSession().write(new StaticPacketBuilder().setId(60)
  566. .addShortA(id)
  567. .addByteC(value).toPacket());
  568. }
  569.  
  570. public void sendConfig2(int id, int value) {
  571. player.getSession().write(new StaticPacketBuilder().setId(226)
  572. .addInt(value)
  573. .addShortA(id).toPacket());
  574. }
  575.  
  576. public void resetAllEntityAnimations() {
  577. player.getSession().write(new StaticPacketBuilder().setId(131).toPacket());
  578. }
  579.  
  580. public void clearMapFlag() {
  581. player.getSession().write(new StaticPacketBuilder().setId(153).toPacket());
  582. }
  583.  
  584. public void setPrivacyOptions() {
  585. player.getSession().write(new StaticPacketBuilder().setId(232)
  586. .addByte((byte) player.getFriends().getPrivacyOption(0))
  587. .addByte((byte) player.getFriends().getPrivacyOption(1))
  588. .addByte((byte) player.getFriends().getPrivacyOption(2)).toPacket());
  589. }
  590.  
  591. public void sendMessage(String message) {
  592. StaticPacketBuilder spb = new StaticPacketBuilder().setId(70).setSize(Size.VariableByte)
  593. .addString(message);
  594. player.getSession().write(spb.toPacket());
  595. }
  596.  
  597. public void setArrowOnEntity(int type, int id) {
  598. StaticPacketBuilder spb = new StaticPacketBuilder().setId(217);
  599. int offset = spb.curLength;
  600. spb.addByte((byte) type); // 10 player, 1 npc
  601. spb.addByte((byte) ((byte) id < 32768 ? 0 : 1)); // arrowtype
  602. spb.addShort(id);
  603. spb.curLength += 3;
  604. spb.addShort(65535);
  605. for (int i = (spb.curLength - offset); i < 9; i++) {
  606. spb.addByte((byte) 0);
  607. }
  608. player.getSession().write(spb.toPacket());
  609. }
  610.  
  611. public void followPlayer(Entity playerToFollow, int distance) {
  612. StaticPacketBuilder spb = new StaticPacketBuilder().setId(17);
  613. spb.addShortA(playerToFollow == null ? -1 : playerToFollow.getIndex());
  614. spb.addShort(playerToFollow == null ? -1 : distance);
  615. spb.addShortA(playerToFollow == null ? -1 : playerToFollow instanceof NPC ? 2 : 1);
  616. player.getSession().write(spb.toPacket());
  617. }
  618.  
  619. public void setArrowOnPosition(int x, int y, int height) {
  620. StaticPacketBuilder spb = new StaticPacketBuilder().setId(217);
  621. int offset = spb.curLength;
  622. spb.addByte((byte) 2);
  623. spb.addByte((byte) 0);
  624. spb.addShort(x);
  625. spb.addShort(y);
  626. spb.addByte((byte) height);
  627. spb.addShort(65535);
  628. for (int i = (spb.curLength - offset); i < 9; i++) {
  629. spb.addByte((byte) 0);
  630. }
  631. player.getSession().write(spb.toPacket());
  632. }
  633.  
  634. public void sendItems(int interfaceId, int childId, int type, Item[] inventory) {
  635. StaticPacketBuilder spb = new StaticPacketBuilder().setId(105).setSize(Size.VariableShort);
  636. spb.addShort(interfaceId);
  637. spb.addShort(childId);
  638. spb.addShort(type);
  639. spb.addShort(inventory.length);
  640. for(int i = 0; i < inventory.length; i++) {
  641. Item item = inventory[i];
  642. int id = -1, amt = 0;
  643. if (inventory[i] != null) {
  644. id = item.getItemId();
  645. amt = item.getItemAmount();
  646. }
  647. if(amt > 254) {
  648. spb.addByteS((byte) 255);
  649. spb.addInt(amt);
  650. } else {
  651. spb.addByteS((byte) amt);
  652. }
  653. spb.addShort(id + 1);
  654. }
  655. player.getSession().write(spb.toPacket());
  656. }
  657.  
  658. public void sendItemsSlot(int interfaceId, int childId, int type, int slot, Item item) {
  659. StaticPacketBuilder spb = new StaticPacketBuilder().setId(22).setSize(Size.VariableShort);
  660. spb.addShort(interfaceId);
  661. spb.addShort(childId);
  662. spb.addShort(type);
  663. spb.addByte((byte) slot);
  664. spb.addShort(item.getItemId() + 1);
  665. if(item.getItemAmount() > 254) {
  666. spb.addByte((byte) 255);
  667. spb.addInt(item.getItemAmount());
  668. } else {
  669. spb.addByte((byte) item.getItemAmount());
  670. }
  671. player.getSession().write(spb.toPacket());
  672. }
  673.  
  674. public void modifyText(String string, int interfaceId, int childId) {
  675. StaticPacketBuilder packet = new StaticPacketBuilder().setId(171).setSize(Packet.Size.VariableShort)
  676. .addInt2((interfaceId << 16) + childId)
  677. .addString(string)
  678. .addShortA(count++);
  679. player.getSession().write(packet.toPacket());
  680. }
  681.  
  682. public void showChildInterface(int interfaceId, int childId, boolean show) {
  683. StaticPacketBuilder spb = new StaticPacketBuilder().setId(21)
  684. .addByteC(show ? 0 : 1)
  685. .addShort(count++)
  686. .addLEInt((interfaceId << 16) + childId);
  687. player.getSession().write(spb.toPacket());
  688. }
  689.  
  690. public void updateGEProgress(GEItem offer) {
  691. StaticPacketBuilder spb = new StaticPacketBuilder().setId(116);
  692. spb.addByte((byte) offer.getSlot());
  693. spb.addByte((byte) offer.getProgress());
  694. spb.addShort(offer.getDisplayItem());
  695. spb.addInt(offer.getPriceEach());
  696. spb.addInt(offer.getTotalAmount());
  697. spb.addInt(offer.getAmountTraded());
  698. spb.addInt(offer.getTotalAmount() * offer.getPriceEach());
  699. player.getSession().write(spb.toPacket());
  700. }
  701.  
  702. public void resetGESlot(int slot) {
  703. StaticPacketBuilder spb = new StaticPacketBuilder().setId(116);
  704. spb.addByte((byte) slot);
  705. spb.addByte((byte) 0);
  706. spb.addShort(0);
  707. spb.addInt(0);
  708. spb.addInt(0);
  709. spb.addInt(0);
  710. spb.addInt(0);
  711. player.getSession().write(spb.toPacket());
  712. }
  713.  
  714. public void sendNPCHead(int npcID, int interfaceID, int childID) {
  715. StaticPacketBuilder spb = new StaticPacketBuilder().setId(73);
  716. spb.addShortA(npcID)
  717. .addLEInt((interfaceID << 16) + childID)
  718. .addLEShort(count++);
  719. player.getSession().write(spb.toPacket());
  720. }
  721.  
  722. public void sendPlayerHead(int interfaceID, int childID) {
  723. StaticPacketBuilder spb = new StaticPacketBuilder().setId(66);
  724. spb.addLEShortA(count++);
  725. spb.addInt1((interfaceID << 16) + childID);
  726. player.getSession().write(spb.toPacket());
  727. }
  728.  
  729. public void animateInterface(int animID, int interfaceID, int childID) {
  730. StaticPacketBuilder spb = new StaticPacketBuilder().setId(36);
  731. spb.addInt2((interfaceID << 16) + childID);
  732. spb.addLEShort(animID);
  733. spb.addShortA(count++);
  734. player.getSession().write(spb.toPacket());
  735. }
  736.  
  737. public void sendChatboxInterface(int childId) {
  738. sendInterface(0, 752, 11, childId);
  739. }
  740.  
  741. public void sendChatboxInterface2(int childId) {
  742. sendInterface(0, 752, 12, childId);
  743. }
  744.  
  745. /*
  746. * Only used for GE search as far as i know
  747. */
  748. public void sendChatboxInterface3(int childId) {
  749. sendInterface(0, 752, 6, childId);
  750. }
  751.  
  752. public void displayInventoryInterface(int childId) {
  753. if(player.isHd()) {
  754. sendInterface(0, 746, 76, childId);
  755. return;
  756. }
  757. sendInterface(0, 548, 80, childId);
  758. }
  759.  
  760. public void itemOnInterface(int inter, int child, int size, int item) {
  761. player.getSession().write(new StaticPacketBuilder().setId(50)
  762. .addInt(size)
  763. .addLEShort(inter)
  764. .addLEShort(child)
  765. .addLEShortA(item)
  766. .addLEShort(count++).toPacket());
  767. }
  768.  
  769. public void moveChildInterface(int interfaceId, int child, int x, int y) {
  770. //todo
  771. /*player.getSession().write(new StaticPacketBuilder().setId(84)
  772. .addInt2((x * 65536) + y)
  773. .addInt2((interfaceId * 65536) + child)
  774. .addShortA(count++).toPacket());*/
  775. }
  776.  
  777. public void sendEnergy() {
  778. player.getSession().write(new StaticPacketBuilder().setId(234)
  779. .addByte((byte) player.getRunEnergy()).toPacket());
  780. }
  781.  
  782. public void setMinimapStatus(int setting) {
  783. player.getSession().write(new StaticPacketBuilder().setId(192)
  784. .addByte((byte) setting).toPacket());
  785. }
  786.  
  787. public void newSystemUpdate(int time) {
  788. player.getSession().write(new StaticPacketBuilder().setId(85).addShort(time * 50 / 30).toPacket());
  789. }
  790.  
  791. public void sendCoords(Location location) {
  792. StaticPacketBuilder spb = new StaticPacketBuilder().setId(26);
  793. int regionX = player.getUpdateFlags().getLastRegion().getRegionX();
  794. int regionY = player.getUpdateFlags().getLastRegion().getRegionY();
  795. spb.addByteC((byte) (location.getX() - ((regionX - 6) * 8)));
  796. spb.addByte((byte) (location.getY() - ((regionY - 6) * 8)));
  797. player.getSession().write(spb.toPacket());
  798. }
  799.  
  800. public void sendProjectileCoords(Location location) {
  801. StaticPacketBuilder spb = new StaticPacketBuilder().setId(26);
  802. int regionX = player.getUpdateFlags().getLastRegion().getRegionX();
  803. int regionY = player.getUpdateFlags().getLastRegion().getRegionY();
  804. spb.addByteC((byte) (location.getX() - ((regionX - 6) * 8)-3));
  805. spb.addByte((byte) (location.getY() - ((regionY - 6) * 8)-2));
  806. player.getSession().write(spb.toPacket());
  807. }
  808.  
  809. public void sendProjectileCoords2(Location location, int i, int j) {
  810. StaticPacketBuilder spb = new StaticPacketBuilder().setId(26);
  811. int regionX = player.getUpdateFlags().getLastRegion().getRegionX();
  812. int regionY = player.getUpdateFlags().getLastRegion().getRegionY();
  813. spb.addByteC((byte) (location.getX() - ((regionX - 6) * 8)-i));
  814. spb.addByte((byte) (location.getY() - ((regionY - 6) * 8)-j));
  815. player.getSession().write(spb.toPacket());
  816. }
  817.  
  818. public void clearGroundItem(GroundItem item) {
  819. if (item != null) {
  820. sendCoords(item.getLocation());
  821. StaticPacketBuilder spb = new StaticPacketBuilder().setId(240);
  822. spb.addByte((byte) 0);
  823. spb.addShort(item.getItemId());
  824. player.getSession().write(spb.toPacket());
  825. }
  826. }
  827.  
  828. public void createGroundItem(GroundItem item) {
  829. if (item != null) {
  830. sendCoords(item.getLocation());
  831. StaticPacketBuilder spb = new StaticPacketBuilder().setId(33);
  832. spb.addLEShort(item.getItemId());
  833. spb.addByte((byte) 0);
  834. spb.addShortA(item.getItemAmount());
  835. player.getSession().write(spb.toPacket());
  836. }
  837. }
  838.  
  839. public void createGroundItem2(GroundItem item) {
  840. if (item != null) {
  841. sendCoords(item.getLocation());
  842. StaticPacketBuilder spb = new StaticPacketBuilder().setId(135);
  843. spb.addLEShortA(item.getOwner().getIndex());
  844. spb.addByteC((byte) 0);
  845. spb.addLEShort(item.getItemAmount());
  846. spb.addLEShort(item.getItemId());
  847. player.getSession().write(spb.toPacket());
  848. }
  849. }
  850.  
  851. public void createObject(int objectId, Location loc, int face, int type) {
  852. sendCoords(Location.location(loc.getX(), loc.getY(), player.getLocation().getZ()));
  853. player.getSession().write(new StaticPacketBuilder().setId(179)
  854. .addByteA((byte)((type << 2) + (face & 3)))
  855. .addByte((byte) 0)
  856. .addShortA(objectId).toPacket());
  857. }
  858.  
  859. public void removeObject(Location loc, int face, int type) {
  860. sendCoords(Location.location(loc.getX(), loc.getY(), player.getLocation().getZ()));
  861. player.getSession().write(new StaticPacketBuilder().setId(195)
  862. .addByteC((byte)((type << 2) + (face & 3)))
  863. .addByte((byte) 0).toPacket());
  864. }
  865.  
  866. public void newObjectAnimation(Location loc, int anim) {
  867. sendCoords(Location.location(loc.getX(), loc.getY(), player.getLocation().getZ()));
  868. int type = 10;
  869. int x = loc.getX();
  870. int face = 0;
  871. if (anim == 497) { // Agility ropeswing
  872. face = x == 2551 ? 4 : x == 3005 ? 2 : 0;
  873. }
  874. player.getSession().write(new StaticPacketBuilder().setId(20)
  875. .addByteS(0)
  876. .addByteS((byte) ((type << 2) + (face & 3)))
  877. .addLEShort(anim).toPacket());
  878. }
  879.  
  880. public void refreshInventory() {
  881. sendItems(149, 0, 93, player.getInventory().getItems());
  882. }
  883.  
  884. public void refreshEquipment() {
  885. sendItems(387, 28, 94, player.getEquipment().getEquipment());
  886. }
  887.  
  888. public void sendBankOptions() {
  889. setRightClickOptions(1278, (762 * 65536) + 73, 0, 496);
  890. setRightClickOptions(2360446, (763 * 65536), 0, 27);
  891. sendBlankClientScript(239, 1451);
  892. }
  893.  
  894. public void configureTrade() {
  895. displayInterface(335);
  896. displayInventoryInterface(336);
  897. setRightClickOptions(1278, (335 * 65536) + 30, 0, 27);
  898. setRightClickOptions(1026, (335 * 65536) + 32, 0, 27);
  899. setRightClickOptions(1278, (336 * 65536), 0, 27);
  900. setRightClickOptions(2360446, (336 * 65536), 0, 27);
  901. Object[] opts1 = new Object[]{"", "", "", "Value", "Remove X", "Remove All", "Remove 10", "Remove 5", "Remove 1", -1, 0, 7, 4, 90, 21954590};
  902. Object[] opts2 = new Object[]{"", "", "Lend", "Value", "Offer X", "Offer All", "Offer 10", "Offer 5", "Offer 1", -1, 0, 7, 4, 93, 22020096};
  903. Object[] opts3 = new Object[]{"", "", "", "", "", "", "", "", "Value", -1, 0, 7, 4, 90, 21954592};
  904. sendClientScript(150, opts1, "IviiiIsssssssss");
  905. sendClientScript(150, opts2, "IviiiIsssssssss");
  906. sendClientScript(695, opts3, "IviiiIsssssssss");
  907. }
  908.  
  909. public void configureDuel() {
  910. displayInventoryInterface(336);
  911. displayInterface(631);
  912. setRightClickOptions(1278, (336 * 65536), 0, 27);// should be 1086?
  913. Object[] opts1 = new Object[]{"Stake X", "Stake All", "Stake 10", "Stake 5", "Stake 1", -1, 0, 7, 4, 93, 22020096};
  914. sendClientScript2(189, 150, opts1, "IviiiIsssss");
  915. setRightClickOptions(1278, (631 * 65536) + 104, 0, 27);
  916. setRightClickOptions(1278, (631 * 65536) + 103, 0, 27);
  917. setRightClickOptions(2360446, (336 * 65536), 0, 27);
  918. }
  919.  
  920. public void openMainShop() {
  921. showChildInterface(620, 23, true);
  922. showChildInterface(620, 24, false);
  923. showChildInterface(620, 29, true);
  924. showChildInterface(620, 25, false);
  925. showChildInterface(620, 27, false);
  926. showChildInterface(620, 26, true);
  927. setRightClickOptions(1278, (620 * 65536) + 23, 0, 40);
  928. }
  929.  
  930. public void openPlayerShop() {
  931. showChildInterface(620, 23, false);
  932. showChildInterface(620, 24, true);
  933. showChildInterface(620, 29, false);
  934. showChildInterface(620, 25, true);
  935. showChildInterface(620, 27, true);
  936. showChildInterface(620, 26, false);
  937. setRightClickOptions(1278, (620 * 65536) + 24, 0, 40);
  938. }
  939.  
  940. public void tradeWarning(int slot) {
  941. Object[] opt = new Object[]{slot, 7, 4, 21954593};
  942. sendClientScript(143, opt, "Iiii");
  943. }
  944.  
  945. public void sendBlankClientScript(int id) {
  946. StaticPacketBuilder packet = new StaticPacketBuilder().setId(115).setSize(Packet.Size.VariableShort)
  947. .addShort(0)
  948. .addString("");
  949. packet.addInt(id);
  950. player.getSession().write(packet.toPacket());
  951. }
  952.  
  953. public void sendBlankClientScript(int id, String s) {
  954. StaticPacketBuilder packet = new StaticPacketBuilder().setId(115).setSize(Packet.Size.VariableShort)
  955. .addShort(0)
  956. .addString(s);
  957. packet.addInt(id);
  958. player.getSession().write(packet.toPacket());
  959. }
  960.  
  961. public void sendBlankClientScript(int id2, int id) {
  962. StaticPacketBuilder packet = new StaticPacketBuilder().setId(115).setSize(Packet.Size.VariableShort)
  963. .addShort(id2)
  964. .addString("");
  965. packet.addInt(id);
  966. player.getSession().write(packet.toPacket());
  967. }
  968.  
  969. public void sendClientScript(int id, Object[] params, String types) {
  970. if (params.length != types.length()) {
  971. throw new IllegalArgumentException("params size should be the same as types length");
  972. }
  973. StaticPacketBuilder packet = new StaticPacketBuilder().setId(115).setSize(Packet.Size.VariableShort)
  974. .addShort(count++)
  975. .addString(types);
  976. int idx = 0;
  977. for (int i = types.length() - 1;i >= 0;i--) {
  978. if (types.charAt(i) == 's') {
  979. packet.addString((String) params[idx]);
  980. } else {
  981. packet.addInt((Integer) params[idx]);
  982. }
  983. idx++;
  984. }
  985. packet.addInt(id);
  986. player.getSession().write(packet.toPacket());
  987. }
  988.  
  989. public void sendClientScript2(int id2, int id, Object[] params, String types) {
  990. if (params.length != types.length()) {
  991. throw new IllegalArgumentException("params size should be the same as types length");
  992. }
  993. StaticPacketBuilder packet = new StaticPacketBuilder().setId(115).setSize(Packet.Size.VariableShort)
  994. .addShort(count++)
  995. .addString(types);
  996. int idx = 0;
  997. for (int i = types.length() - 1;i >= 0;i--) {
  998. if (types.charAt(i) == 's') {
  999. packet.addString((String) params[idx]);
  1000. } else {
  1001. packet.addInt((Integer) params[idx]);
  1002. }
  1003. idx++;
  1004. }
  1005. packet.addInt(id);
  1006. player.getSession().write(packet.toPacket());
  1007. }
  1008.  
  1009. public void sendProjectile(Location source, Location dest, int startSpeed, int gfx, int angle, int startHeight, int endHeight, int speed, Entity lockon) {
  1010. sendProjectileCoords(source);
  1011. StaticPacketBuilder spb = new StaticPacketBuilder().setId(16)
  1012. .addByte((byte) ((byte) angle))
  1013. .addByte((byte) ((byte) (source.getX() - dest.getX()) * -1))
  1014. .addByte((byte) ((byte) (source.getY() - dest.getY()) * -1))
  1015. .addShort(lockon instanceof Player ? (- lockon.getClientIndex() - 1) : lockon.getClientIndex() + 1)
  1016. .addShort(gfx)
  1017. .addByte((byte) startHeight)
  1018. .addByte((byte) endHeight)
  1019. .addShort(startSpeed)
  1020. .addShort(speed)
  1021. .addByte((byte) ((byte) gfx == 53 ? 0 : 16))//arch..0 if cannon
  1022. .addByte((byte) 64);
  1023. player.getSession().write(spb.toPacket());
  1024. }
  1025.  
  1026. public void sendProjectile2(int offsetX, int offsetY, Location source, Location dest, int startSpeed, int gfx, int angle, int startHeight, int endHeight, int speed, Entity lockon) {
  1027. sendProjectileCoords2(source, offsetX, offsetY);
  1028. StaticPacketBuilder spb = new StaticPacketBuilder().setId(16)
  1029. .addByte((byte) ((byte) angle))
  1030. .addByte((byte) ((byte) (source.getX() - dest.getX()) * -1))
  1031. .addByte((byte) ((byte) (source.getY() - dest.getY()) * -1))
  1032. .addShort(lockon instanceof Player ? (- lockon.getClientIndex() - 1) : lockon.getClientIndex() + 1)
  1033. .addShort(gfx)
  1034. .addByte((byte) startHeight)
  1035. .addByte((byte) endHeight)
  1036. .addShort(startSpeed)
  1037. .addShort(speed)
  1038. .addByte((byte) 16)//arch..0 if cannon
  1039. .addByte((byte) 64);
  1040. player.getSession().write(spb.toPacket());
  1041. }
  1042.  
  1043. public void newEarthquake(int i, int j, int k, int l, int i1) {
  1044. StaticPacketBuilder spb = new StaticPacketBuilder().setId(27);
  1045. spb.addShort(count++);
  1046. spb.addByte((byte) i);
  1047. spb.addByte((byte) j);
  1048. spb.addByte((byte) k);
  1049. spb.addByte((byte) l);
  1050. spb.addShort(i1);
  1051. player.getSession().write(spb.toPacket());
  1052. }
  1053.  
  1054. public void resetCamera() {
  1055. player.getSession().write(new StaticPacketBuilder().setId(24)
  1056. .addShort(count++).toPacket());
  1057. }
  1058.  
  1059. //Unsure of paramaters
  1060. public void setCameraMovement(int i, int j, int k, int l, int i1) {
  1061. StaticPacketBuilder spb = new StaticPacketBuilder().setId(154);
  1062. spb.addShort(count++);
  1063. spb.addByte((byte) i); // X + Y are in region terms (0-104, 52 is middle).
  1064. spb.addByte((byte) j);
  1065. spb.addShort(k);
  1066. spb.addByte((byte) l);
  1067. spb.addByte((byte) i1);
  1068. player.getSession().write(spb.toPacket());
  1069. }
  1070.  
  1071. public void setRightClickOptions(int set, int inter, int off, int len) {
  1072. StaticPacketBuilder spb = new StaticPacketBuilder().setId(165)
  1073. .addLEShort(count++)
  1074. .addLEShort(len)
  1075. .addInt(inter)
  1076. .addShortA(off)
  1077. .addInt1(set);
  1078. player.getSession().write(spb.toPacket());
  1079. }
  1080.  
  1081. public void clearInterfaceItems(int interfaceId, int child) {
  1082. StaticPacketBuilder spb = new StaticPacketBuilder().setId(144)
  1083. .addInt2(((interfaceId * 65536) + child));
  1084. player.getSession().write(spb.toPacket());
  1085. }
  1086.  
  1087. public void displayEnterAmount() {
  1088. Object[] o = {"Enter amount:"};
  1089. sendClientScript(108, o, "s");
  1090. }
  1091.  
  1092. public void displayEnterText(String s) {
  1093. Object[] o = {s};
  1094. sendClientScript(109, o, "s");
  1095. }
  1096.  
  1097. public void sendSentPrivateMessage(long name, String text, byte[] packed) {
  1098. //byte[] bytes = new byte[message.length()];
  1099. byte[] bytes = new byte[packed.length];
  1100. Misc.textPack(bytes, text);
  1101. //Misc.method251(bytes, 0, 0, message.length(), message.getBytes());
  1102. player.getSession().write(new StaticPacketBuilder().setId(71).setSize(Size.VariableByte)
  1103. .addLong(name)
  1104. // .addByte((byte) bytes.length)
  1105. .addBytes(bytes).toPacket());
  1106. }
  1107.  
  1108. public void sendReceivedPrivateMessage(long name, int rights, String message, byte[] packed) {
  1109. int messageCounter = player.getFriends().getNextUniqueId();
  1110. //byte[] bytes = new byte[message.getBytes().length];
  1111. //Misc.textPack(bytes, message);
  1112. //Misc.method251(bytes, 0, 1, message.length(), message.getBytes());
  1113. player.getSession().write(new StaticPacketBuilder().setId(0).setSize(Size.VariableByte)
  1114. .addLong(name)
  1115. .addShort(0) // used with the message counter below
  1116. .addBytes(new byte[] { (byte) ((messageCounter << 16) & 0xFF), (byte) ((messageCounter << 8) & 0xFF), (byte) (messageCounter & 0xFF)} )
  1117. .addByte((byte) rights)
  1118. .addBytes(packed).toPacket());
  1119. }
  1120.  
  1121. public void sendFriend(long name, int world) {
  1122. Clan c = World.getInstance().getClanManager().getClanByOwner(player, player.getUsername());
  1123. int clanRank = 0;
  1124. if (c == null) {
  1125. clanRank = 0;
  1126. } else {
  1127. clanRank = c.getUserRank(Misc.longToPlayerName(name));
  1128. }
  1129. StaticPacketBuilder spb = new StaticPacketBuilder().setId(62).setSize(Size.VariableByte)
  1130. .addLong(name)
  1131. .addShort(world)
  1132. .addByte((byte) clanRank);
  1133. if(world != 0) {
  1134. if(world == player.getWorld()) {
  1135. spb.addString("Online");
  1136. } else {
  1137. spb.addString("Server " + world);
  1138. }
  1139. }
  1140. player.getSession().write(spb.toPacket());
  1141. }
  1142.  
  1143. public void sendIgnores(long[] names) {
  1144. StaticPacketBuilder spb = new StaticPacketBuilder().setId(126).setSize(Size.VariableShort);
  1145. for(long name : names) {
  1146. spb.addLong(name);
  1147. }
  1148. player.getSession().write(spb.toPacket());
  1149. }
  1150.  
  1151. public void load() throws IOException {
  1152. String line = "";
  1153. String token = "";
  1154. String token2 = "";
  1155. String token2_2 = "";
  1156. String[] token3 = new String[10];
  1157. boolean EndOfFile = false;
  1158. // int ReadMode = 0;
  1159. BufferedReader characterfile = null;
  1160.  
  1161. try {
  1162. characterfile = new BufferedReader(
  1163. new FileReader("./data/lol.cfg"));
  1164. } catch (FileNotFoundException fileex) {
  1165. return;
  1166. }
  1167. try {
  1168. line = characterfile.readLine();
  1169. } catch (IOException ioexception) {
  1170. characterfile.close();
  1171. return;
  1172. }
  1173. while (EndOfFile == false && line != null) {
  1174. line = line.trim();
  1175. int spot = line.indexOf("=");
  1176.  
  1177. if (spot > -1) {
  1178. token = line.substring(0, spot);
  1179. token = token.trim();
  1180. token2 = line.substring(spot + 1);
  1181. token2 = token2.trim();
  1182. token2_2 = token2.replaceAll("\t\t", "\t");
  1183. token2_2 = token2.replaceAll("\t\t", "\t");
  1184. token2_2 = token2.replaceAll("\t\t", "\t");
  1185. token2_2 = token2.replaceAll("\t\t", "\t");
  1186. token2_2 = token2.replaceAll("\t\t", "\t");
  1187. token2_2 = token2.replaceAll("\t\t", "\t");
  1188. token2_2 = token2.replaceAll("\t\t", "\t");
  1189. token3 = token2_2.split("\t");
  1190. if (token.equals("CONFIG")) {
  1191. int one = Integer.valueOf(token3[0]);
  1192. int two = Integer.valueOf(token3[1]);
  1193. sendConfig(one, two);
  1194. }
  1195. } else {
  1196. if (line.equals("[ENDOFFILE]")) {
  1197. try {
  1198. characterfile.close();
  1199. } catch (IOException ioexception) {}
  1200. characterfile.close();
  1201. return;
  1202. }
  1203. }
  1204. try {
  1205. line = characterfile.readLine();
  1206. } catch (IOException ioexception1) {
  1207. EndOfFile = true;
  1208. }
  1209. }
  1210. try {
  1211. characterfile.close();
  1212. } catch (IOException ioexception) {}
  1213. return;
  1214. }
  1215. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement