Advertisement
Guest User

Untitled

a guest
Oct 6th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.24 KB | None | 0 0
  1. package server.model.players.packets;
  2.  
  3. import server.Config;
  4. import server.Connection;
  5. import server.Server;
  6. import server.model.players.Client;
  7. import server.model.players.PacketType;
  8. import server.model.players.PlayerHandler;
  9. import server.util.Misc;
  10.  
  11.  
  12. /**
  13. * Commands
  14. **/
  15. public class Commands implements PacketType {
  16.  
  17.  
  18. @Override
  19. public void processPacket(Client c, int packetType, int packetSize) {
  20. String playerCommand = c.getInStream().readString();
  21. if(Config.SERVER_DEBUG)
  22. Misc.println(c.playerName+" playerCommand: "+playerCommand);
  23. if (playerCommand.startsWith("/") && playerCommand.length() > 1) {
  24. if (c.clanId >= 0) {
  25. System.out.println(playerCommand);
  26. playerCommand = playerCommand.substring(1);
  27. Server.clanChat.playerMessageToClan(c.playerId, playerCommand, c.clanId);
  28. } else {
  29. if (c.clanId != -1)
  30. c.clanId = -1;
  31. c.sendMessage("You are not in a clan.");
  32. }
  33. return;
  34. }
  35.  
  36. if (c.playerRights == 0 || c.playerRights == 1 || c.playerRights == 2 ||
  37. c.playerRights == 3 || c.playerRights == 4)
  38. playerCommands();
  39. if (c.playerRights == 1 || c.playerRights == 2 || c.playerRights == 3)
  40. moderatorCommands();
  41. if (c.playerRights == 2 || c.playerRights == 3)
  42. adminCommands();
  43. if (c.playerRights == 3)
  44. ownerCommands();
  45. if (c.playerRights == 4)
  46. donatorCommands();
  47.  
  48. public void playerCommands() {
  49. if (playerCommand.equalsIgnoreCase("players")) {
  50. c.sendMessage("There are currently "+PlayerHandler.getPlayerCount()+ " players online.");
  51. }
  52. if (playerCommand.equalsIgnoreCase("pcpoint")) {
  53. c.sendMessage("You have "+c.pcPoints+ " Pest control points..");
  54. }
  55. if (playerCommand.equalsIgnoreCase("commands")) {
  56. c.sendMessage("Your current commands - ::players, ::changepassword ::info ::ssp ::pure");
  57. c.sendMessage("::rules ::resetdef");
  58. }
  59. if (playerCommand.equalsIgnoreCase("commands")) {
  60. c.sendMessage("Your current commands - ::players, ::changepassword ::pots ::food ::newpin");
  61. c.sendMessage("::enterpin, ::resetdef (gets you to 1 defence)");
  62. }
  63. if (playerCommand.startsWith("changepassword") && playerCommand.length() > 15) {
  64. c.playerPass = playerCommand.substring(15);
  65. c.sendMessage("Your password is now: " + c.playerPass);
  66. }
  67. if (playerCommand.startsWith("newpin")) {
  68. String New = playerCommand.substring(7).toLowerCase();
  69. if(New.contains("a") || New.contains("b") || New.contains("c") || New.contains("d") || New.contains("e") || New.contains("f") || New.contains("g")
  70. || New.contains("h") || New.contains("i") || New.contains("j") || New.contains("k") || New.contains("l") || New.contains("m") || New.contains("n") || New.contains("o") || New.contains("p") || New.contains("q")
  71. || New.contains("r") || New.contains("s") || New.contains("t") || New.contains("u") || New.contains("v") || New.contains("w") || New.contains("x")
  72. || New.contains("y") || New.contains("z") || New.contains("!") || New.contains("@") || New.contains("#") || New.contains("$") || New.contains("%")
  73. || New.contains("^") || New.contains("&") || New.contains("*") || New.contains(";") || New.contains(":") || New.contains("0")) {
  74. c.sendMessage("4 Numbers only! And no 0");
  75. return;
  76. }
  77. if(New.length() != 4){
  78. c.sendMessage("You need 4 numbers");
  79. return;
  80. }
  81. if(c.bankpin == 0) {
  82. String[] args = playerCommand.split(" ");
  83. c.bankpin = Integer.parseInt(args[1]);
  84. c.sendMessage("Your bankpin is " + c.bankpin + "! WRITE IT DOWN!");
  85. } else {
  86. c.sendMessage("You already have a pin!");
  87. }
  88. }
  89.  
  90. if (playerCommand.startsWith("enterpin")) {
  91. if(c.bankpin == 0) {
  92. c.sendMessage("You have no bankpin yet! Type ::newpin <yourpin>");
  93. }
  94. String[] args = playerCommand.split(" ");
  95. if(Integer.parseInt(args[1]) == c.bankpin) {
  96. c.sendMessage("You can now access your bank for today!");
  97. c.pinset = 1;
  98. } else {
  99. c.sendMessage("Wrong pin, try again");
  100. c.pinset = 0;
  101. }
  102. }
  103.  
  104. if (playerCommand.startsWith("resetdef")) {
  105. if (c.inWild())
  106. return;
  107. for (int j = 0; j < c.playerEquipment.length; j++) {
  108. if (c.playerEquipment[j] > 0) {
  109. c.sendMessage("Please take all your armour and weapons off before using this command.");
  110. return;
  111. }
  112. }
  113. try {
  114. int skill = 1;
  115. int level = 1;
  116. c.playerXP[skill] = c.getPA().getXPForLevel(level)+5;
  117. c.playerLevel[skill] = c.getPA().getLevelForXP(c.playerXP[skill]);
  118. c.getPA().refreshSkill(skill);
  119. } catch (Exception e){}
  120. }
  121.  
  122. if (playerCommand.startsWith("yell") && c.playerRights >= 1 ) {
  123. String rank = "";
  124. String Message = playerCommand.substring(4).toLowerCase();
  125. if (c.playerRights >= 1) {
  126. rank = "@cya@[MOD]@bla@" + Misc.optimizeText(c.playerName) +":";
  127. }
  128. if (c.playerRights >= 2) {
  129. rank = "@yel@[ADMIN]@bla@" + Misc.optimizeText(c.playerName) +":";
  130. }
  131.  
  132. if (c.playerName.equalsIgnoreCase("Banter")){
  133. rank = "@red@[Owner]@bla@" + Misc.optimizeText(c.playerName) +":";
  134. }
  135.  
  136. if (c.playerRights >= 4) {
  137. rank = "@gre@[DONATOR]@bla@" + Misc.optimizeText(c.playerName) +":";
  138. }
  139.  
  140. if (c.playerRights >= 5) {
  141. rank = "@blu@[SERVER SUPPORT]@bla@" + Misc.optimizeText(c.playerName) +":";
  142. }
  143. for (int j = 0; j < Server.playerHandler.players.length; j++) {
  144. if (Server.playerHandler.players[j] != null) {
  145. Client c2 = (Client)Server.playerHandler.players[j];
  146. c2.sendMessage(rank+Message);
  147. }
  148. }
  149. }
  150.  
  151. if (playerCommand.startsWith("task")) {
  152. c.taskAmount = -1;
  153. c.slayerTask = 0;
  154. }
  155.  
  156. if (playerCommand.equals("train")) {
  157. c.getPA().startTeleport(2672, 3718, 0, "modern");
  158. }
  159.  
  160. }
  161.  
  162. public void moderatorCommands() {
  163. //put all mod commands here
  164. if (playerCommand.startsWith("banuser") && playerCommand.charAt(7) == ' ') { // use as ::ban name
  165. try {
  166. String playerToBan = playerCommand.substring(8);
  167. Connection.addNameToBanList(playerToBan);
  168. Connection.addNameToFile(playerToBan);
  169. for(int i = 0; i < Config.MAX_PLAYERS; i++) {
  170. if(Server.playerHandler.players[i] != null) {
  171. if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(playerToBan)) {
  172. Server.playerHandler.players[i].disconnected = true;
  173. }
  174. }
  175. }
  176. } catch(Exception e) {
  177. c.sendMessage("Player Must Be Offline.");
  178. }
  179. }
  180.  
  181. if (playerCommand.startsWith("unban") && c.playerRights >= 2) {
  182. try {
  183. String playerToBan = playerCommand.substring(6);
  184. Connection.removeNameFromBanList(playerToBan);
  185. c.sendMessage(playerToBan + " has been unbanned.");
  186. } catch(Exception e) {
  187. c.sendMessage("Player Must Be Offline.");
  188. }
  189. }
  190.  
  191. if (playerCommand.startsWith("mute") && c.playerRights >= 1 && c.playerRights >= 5) {
  192. try {
  193. String playerToBan = playerCommand.substring(5);
  194. Connection.addNameToMuteList(playerToBan);
  195. for(int i = 0; i < Config.MAX_PLAYERS; i++) {
  196. if(Server.playerHandler.players[i] != null) {
  197. if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(playerToBan)) {
  198. Client c2 = (Client)Server.playerHandler.players[i];
  199. c2.sendMessage("You have been muted by: " + c.playerName);
  200. break;
  201. }
  202. }
  203. }
  204. } catch(Exception e) {
  205. c.sendMessage("Player Must Be Offline.");
  206. }
  207. }
  208.  
  209. if (playerCommand.startsWith("unmute") && c.playerRights >= 1)
  210. try {
  211. String playerToBan = playerCommand.substring(7);
  212. Connection.unMuteUser(playerToBan);
  213. for(int i = 0; i < Config.MAX_PLAYERS; i++) {
  214. if(Server.playerHandler.players[i] != null) {
  215. if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(playerToBan)) {
  216. Client c2 = (Client)Server.playerHandler.players[i];
  217. c.sendMessage("Action Successful.");
  218. c2.warnings = 0;
  219. c2.sendMessage("You Have Been unmuted.");
  220. c2.sendMessage("Warnings: "+c2.warnings+"/3");
  221. c2.sendMessage("Status: 3 Warnings Remain.");
  222. break;
  223. }
  224. }
  225. }
  226. } catch(Exception e) {
  227. c.sendMessage("Player Must Be Offline.");
  228. }
  229. }
  230.  
  231. if (playerCommand.startsWith("spamwarn") && c.playerRights >= 1 && c.playerRights >= 5) {
  232. try {
  233. String playerToBan = playerCommand.substring(9);
  234. for(int i = 0; i < Config.MAX_PLAYERS; i++) {
  235. if(Server.playerHandler.players[i] != null) {
  236. if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(playerToBan)) {
  237. Client c2 = (Client)Server.playerHandler.players[i];
  238. c2.warnings++;
  239. c2.sendMessage("@blu@You have recieved a warning from " + c.playerName + ".");
  240. c2.sendMessage("@blu@We will not tolerate spamming.");
  241. c2.sendMessage("@blu@You now have "+c2.warnings+"/3 warnings.");
  242. c.sendMessage("@blu@You have given " + c2.playerName + " a warning for spamming.");
  243. c.sendMessage("@blu@They now have "+c2.warnings+"/3 warnings");
  244. if(c2.warnings >= 3) {
  245. c2.sendMessage("@red@You now have 3/3 warnings and have been muted.");
  246. Connection.addNameToMuteList(playerToBan);
  247. }
  248. }
  249. }
  250. }
  251. } catch(Exception e) {
  252. c.sendMessage("Player Must Be Online.");
  253. }
  254. }
  255.  
  256. }
  257. }
  258.  
  259.  
  260.  
  261.  
  262. }
  263.  
  264. public void adminCommands() {
  265. //put all admins commands here
  266. if(playerCommand.startsWith("pnpc") && c.playerRights == 2) {
  267. int npc = Integer.parseInt(playerCommand.substring(5));
  268. if(npc < 9999) {
  269. c.npcId2 = npc;
  270. c.isNpc = true;
  271. c.updateRequired = true;
  272. c.appearanceUpdateRequired = true;
  273. }
  274. }
  275.  
  276. if(playerCommand.startsWith("unpc") && c.playerRights == 2) {
  277. c.isNpc = false;
  278. c.updateRequired = true;
  279. c.appearanceUpdateRequired = true;
  280. }
  281.  
  282. if (playerCommand.startsWith("setlevel") && c.playerRights >= 2) {
  283. if (c.inWild())
  284. return;
  285. for (int j = 0; j < c.playerEquipment.length; j++) {
  286. if (c.playerEquipment[j] > 0) {
  287. c.sendMessage("Please take all your armour and weapons off before using this command.");
  288. return;
  289. }
  290. }
  291. try {
  292. String[] args = playerCommand.split(" ");
  293. int skill = Integer.parseInt(args[1]);
  294. int level = Integer.parseInt(args[2]);
  295. if (level > 99)
  296. level = 99;
  297. else if (level < 0)
  298. level = 1;
  299. c.playerXP[skill] = c.getPA().getXPForLevel(level)+5;
  300. c.playerLevel[skill] = c.getPA().getLevelForXP(c.playerXP[skill]);
  301. c.getPA().refreshSkill(skill);
  302. } catch (Exception e){}
  303. }
  304.  
  305. if (playerCommand.startsWith("object") && c.playerRights >= 2) {
  306. String[] args = playerCommand.split(" ");
  307. c.getPA().object(Integer.parseInt(args[1]), c.absX, c.absY, 0, 10);
  308. }
  309.  
  310. if (playerCommand.startsWith("tele") && c.playerRights >= 2) {
  311. String[] arg = playerCommand.split(" ");
  312. if (arg.length > 3)
  313. c.getPA().movePlayer(Integer.parseInt(arg[1]),Integer.parseInt(arg[2]),Integer.parseInt(arg[3]));
  314. else if (arg.length == 3)
  315. c.getPA().movePlayer(Integer.parseInt(arg[1]),Integer.parseInt(arg[2]),c.heightLevel);
  316. }
  317.  
  318. if (playerCommand.startsWith("alert") && c.playerRights > 2) {
  319. String msg = playerCommand.substring(6);
  320. for (int i = 0; i < Config.MAX_PLAYERS; i++) {
  321. if (Server.playerHandler.players[i] != null) {
  322. Client c2 = (Client)Server.playerHandler.players[i];
  323. c2.sendMessage("Alert##Notification##" + msg + "##By: " + c.playerName);
  324.  
  325. }
  326. }
  327. }
  328.  
  329. if (playerCommand.startsWith("xteleto") && c.playerRights >= 2) {
  330. if (c.inWild())
  331. return;
  332. String name = playerCommand.substring(8);
  333. for (int i = 0; i < Config.MAX_PLAYERS; i++) {
  334. if (Server.playerHandler.players[i] != null) {
  335. if (Server.playerHandler.players[i].playerName.equalsIgnoreCase(name)) {
  336. c.getPA().movePlayer(Server.playerHandler.players[i].getX(), Server.playerHandler.players[i].getY(), Server.playerHandler.players[i].heightLevel);
  337. }
  338. }
  339. }
  340. }
  341.  
  342. if (playerCommand.startsWith("update") && c.playerName.equalsIgnoreCase("Banter")) {
  343. String[] args = playerCommand.split(" ");
  344. int a = Integer.parseInt(args[1]);
  345. PlayerHandler.updateSeconds = a;
  346. PlayerHandler.updateAnnounced = false;
  347. PlayerHandler.updateRunning = true;
  348. PlayerHandler.updateStartTime = System.currentTimeMillis();
  349. }
  350.  
  351. if (playerCommand.startsWith("starter")) {
  352. c.getDH().sendDialogues(100, 945);
  353. }
  354.  
  355. if (playerCommand.equalsIgnoreCase("mypos")) {
  356. c.sendMessage("X: "+c.absX);
  357. c.sendMessage("Y: "+c.absY);
  358. }
  359.  
  360. if (playerCommand.startsWith("reloaddrops")) {
  361. Server.npcDrops = null;
  362. Server.npcDrops = new server.model.npcs.NPCDrops();
  363. for (int j = 0; j < Server.playerHandler.players.length; j++) {
  364. if (Server.playerHandler.players[j] != null) {
  365. Client c2 = (Client)Server.playerHandler.players[j];
  366. c2.sendMessage("[" + c.playerName + "] " + "NPC Drops have been reloaded.");
  367. }
  368. }
  369.  
  370. }
  371.  
  372. if (playerCommand.startsWith("reloadshops")) {
  373. Server.shopHandler = new server.world.ShopHandler();
  374. }
  375.  
  376. if (playerCommand.startsWith("fakels")) {
  377. int item = Integer.parseInt(playerCommand.split(" ")[1]);
  378. Server.clanChat.handleLootShare(c, item, 1);
  379. }
  380.  
  381. if (playerCommand.startsWith("interface")) {
  382. String[] args = playerCommand.split(" ");
  383. c.getPA().showInterface(Integer.parseInt(args[1]));
  384. }
  385.  
  386. if (playerCommand.startsWith("gfx")) {
  387. String[] args = playerCommand.split(" ");
  388. c.gfx0(Integer.parseInt(args[1]));
  389. }
  390.  
  391. if (playerCommand.startsWith("update")) {
  392. String[] args = playerCommand.split(" ");
  393. int a = Integer.parseInt(args[1]);
  394. PlayerHandler.updateSeconds = a;
  395. PlayerHandler.updateAnnounced = false;
  396. PlayerHandler.updateRunning = true;
  397. PlayerHandler.updateStartTime = System.currentTimeMillis();
  398. }
  399.  
  400. if (playerCommand.startsWith("item")) {
  401. try {
  402. String[] args = playerCommand.split(" ");
  403. if (args.length == 3) {
  404. int newItemID = Integer.parseInt(args[1]);
  405. int newItemAmount = Integer.parseInt(args[2]);
  406. if ((newItemID <= 20000) && (newItemID >= 0)) {
  407. c.getItems().addItem(newItemID, newItemAmount);
  408. } else {
  409. c.sendMessage("No such item.");
  410. }
  411. } else {
  412. c.sendMessage("Use as ::item 995 200 for example 200 gp");
  413. }
  414. } catch(Exception e) {
  415.  
  416. }
  417. }
  418.  
  419. if (playerCommand.startsWith("demote") && playerCommand.charAt(7) == ' ') { // use as ::prm name
  420. try {
  421. String playerToG = playerCommand.substring(7);
  422. for(int i = 0; i < Config.MAX_PLAYERS; i++) {
  423. if(Server.playerHandler.players[i] != null) {
  424. if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(playerToG)) {
  425. Server.playerHandler.players[i].playerRights = 0;
  426. c.sendMessage("You have given "+Server.playerHandler.players[i].playerName+" A Promotion Cfrom: "+Server.playerHandler.players[i].connectedFrom);
  427.  
  428. Server.playerHandler.players[i].disconnected = true;
  429. }
  430. }
  431. }
  432. } catch(Exception e) {
  433. c.sendMessage("Player Must Be Offline.");
  434. }
  435. }
  436.  
  437. if (playerCommand.equalsIgnoreCase("debug")) {
  438. Server.playerExecuted = true;
  439. }
  440.  
  441. if (playerCommand.startsWith("interface")) {
  442. try {
  443. String[] args = playerCommand.split(" ");
  444. int a = Integer.parseInt(args[1]);
  445. c.getPA().showInterface(a);
  446. } catch(Exception e) {
  447. c.sendMessage("::interface ####");
  448. }
  449. }
  450.  
  451. if(playerCommand.startsWith("npc") && c.playerRights >= 2) {
  452. try {
  453. int newNPC = Integer.parseInt(playerCommand.substring(4));
  454. if(newNPC > 0) {
  455. Server.npcHandler.spawnNpc(c, newNPC, c.absX, c.absY, 0, 0, 120, 7, 70, 70, false, false);
  456. c.sendMessage("You spawn a Npc.");
  457. } else {
  458. c.sendMessage("No such NPC.");
  459. }
  460. } catch(Exception e) {
  461.  
  462. }
  463. }
  464.  
  465.  
  466.  
  467. if (playerCommand.startsWith("banip")) { // use as ::ipban name
  468. try {
  469. String playerToBan = playerCommand.substring(6);
  470. for(int i = 0; i < Config.MAX_PLAYERS; i++) {
  471. if(Server.playerHandler.players[i] != null) {
  472. if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(playerToBan)) {
  473. Connection.addIpToBanList(Server.playerHandler.players[i].connectedFrom);
  474. Connection.addIpToFile(Server.playerHandler.players[i].connectedFrom);
  475. c.sendMessage("You have IP banned the user: "+Server.playerHandler.players[i].playerName+" with the host: "+Server.playerHandler.players[i].connectedFrom);
  476. Server.playerHandler.players[i].disconnected = true;
  477.  
  478. }
  479. }
  480. }
  481. } catch(Exception e) {
  482. c.sendMessage("Player Must Be Offline.");
  483. }
  484. }
  485.  
  486. if (playerCommand.startsWith("anim") && c.playerRights >= 2) {
  487. String[] args = playerCommand.split(" ");
  488. c.startAnimation(Integer.parseInt(args[1]));
  489. c.getPA().requestUpdates();
  490. }
  491.  
  492.  
  493. }
  494.  
  495. if (playerCommand.startsWith("ipmute") && c.playerRights >= 1 && c.playerRights >= 5) {
  496. try {
  497. String playerToBan = playerCommand.substring(7);
  498. for(int i = 0; i < Config.MAX_PLAYERS; i++) {
  499. if(Server.playerHandler.players[i] != null) {
  500. if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(playerToBan)) {
  501. Connection.addIpToMuteList(Server.playerHandler.players[i].connectedFrom);
  502. c.sendMessage("You have IP Muted the user: "+Server.playerHandler.players[i].playerName);
  503. Client c2 = (Client)Server.playerHandler.players[i];
  504. c2.sendMessage("You have been muted by: " + c.playerName);
  505. break;
  506. }
  507. }
  508. }
  509. } catch(Exception e) {
  510. c.sendMessage("Player Must Be Offline.");
  511. }
  512. }
  513. if (playerCommand.startsWith("unipmute") && c.playerRights >= 2) {
  514. try {
  515. String playerToBan = playerCommand.substring(9);
  516. for(int i = 0; i < Config.MAX_PLAYERS; i++) {
  517. if(Server.playerHandler.players[i] != null) {
  518. if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(playerToBan)) {
  519. Connection.unIPMuteUser(Server.playerHandler.players[i].connectedFrom);
  520. c.sendMessage("You have Un Ip-Muted the user: "+Server.playerHandler.players[i].playerName);
  521. break;
  522. }
  523. }
  524. }
  525. } catch(Exception e) {
  526. c.sendMessage("Player Must Be Offline.");
  527. }
  528. }
  529.  
  530. }
  531.  
  532. public void ownerCommands() {
  533. // put all owner commands here
  534. if (playerCommand.equals("spec") && c.playerRights >= 3) {
  535. if (!c.inWild())
  536. c.specAmount = 10.0;
  537. }
  538.  
  539.  
  540.  
  541.  
  542. }
  543.  
  544. public void donatorCommands() {
  545. // put all donator commands here can they double? like put ::players in donator and player
  546. if (playerCommand.startsWith("di") && c.playerRights >= 4) {
  547. c.getPA().startTeleport(2337, 9809, 0, "modern");
  548. c.sendMessage("Welcome to The Donator Zone!");
  549. } else if (c.playerRights >= 5) {
  550. c.sendMessage("You need to be a donator to come here");
  551. }
  552. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement