Advertisement
Guest User

Untitled

a guest
Jul 4th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.04 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. import java.util.Map;
  11. import java.util.HashMap;
  12.  
  13.  
  14. import java.io.*;
  15.  
  16. /**
  17. * Commands
  18. **/
  19. public class Commands implements PacketType
  20. {
  21.  
  22.  
  23. @Override
  24. public void processPacket(Client c, int packetType, int packetSize)
  25. {
  26. String playerCommand = c.getInStream().readString();
  27. if (!playerCommand.startsWith("/"))
  28. {
  29. c.getPA().writeCommandLog(playerCommand);
  30. }
  31. if (playerCommand.startsWith("/") && playerCommand.length() > 1) {
  32. if (c.clanId >= 0) {
  33. System.out.println(playerCommand);
  34. playerCommand = playerCommand.substring(1);
  35. Server.clanChat.playerMessageToClan(c.playerId, playerCommand, c.clanId);
  36. } else {
  37. if (c.clanId != -1)
  38. c.clanId = -1;
  39. c.sendMessage("You are not in a clan.");
  40. }
  41. return;
  42. }
  43. if (Config.SERVER_DEBUG)
  44. Misc.println(c.playerName+" playerCommand: "+playerCommand);
  45.  
  46. if (c.playerRights >= 0)
  47. playerCommands(c, playerCommand);
  48. if (c.playerRights == 1 || c.playerRights == 2 || c.playerRights == 3)
  49. moderatorCommands(c, playerCommand);
  50. if (c.playerRights == 2 || c.playerRights == 3)
  51. administratorCommands(c, playerCommand);
  52. if (c.playerRights == 3)
  53. ownerCommands(c, playerCommand);
  54. if (c.playerRights == 4)
  55. DonatorCommands(c, playerCommand);
  56.  
  57. }
  58.  
  59.  
  60. public void playerCommands(Client c, String playerCommand)
  61. {
  62. if (playerCommand.startsWith("yell") && c.isDonator == 0) {
  63. c.sendMessage("Only donators can use this command!");
  64. }
  65. if (playerCommand.equalsIgnoreCase("players")) {
  66. c.sendMessage("There are currently "+PlayerHandler.getPlayerCount()+ " players online.");
  67. }
  68. if (playerCommand.startsWith("changepassword") && playerCommand.length() > 15) {
  69. c.playerPass = playerCommand.substring(15);
  70. c.sendMessage("Your password is now: " + c.playerPass);
  71. }
  72.  
  73. if (playerCommand.startsWith("smsk")) {
  74. c.startAnimation(8525);
  75. c.gfx0(1515);
  76. }
  77.  
  78. if (playerCommand.startsWith("sit") && c.sit == false) {
  79. if(c.inWild()) {
  80. c.sendMessage("You cannot do this in wildy");
  81. return;
  82. }
  83. c.sit = true;
  84. if(c.playerRights == 1) {
  85. c.startAnimation(4113);
  86. }
  87. if(c.playerRights == 2 || c.playerRights == 3) {
  88. c.startAnimation(4117);
  89. }
  90. if(c.isDonator == 0) {
  91. c.startAnimation(4115);
  92. }
  93. if(c.playerRights == 4) {
  94. c.startAnimation(4116);
  95. }
  96. }
  97.  
  98. if (playerCommand.startsWith("unsit") && c.sit == true) {
  99. if(c.inWild()) {
  100. c.sendMessage("You cannot do this in wildy");
  101. return;
  102. }
  103. c.sit = false;
  104. c.startAnimation(4191);
  105. }
  106.  
  107. if (playerCommand.startsWith("qpsk")) {
  108. c.startAnimation(4945);
  109. c.gfx0(816);
  110. }
  111. if (playerCommand.startsWith("ep") || playerCommand.startsWith("Ep") || playerCommand.startsWith("EP") ||
  112.  
  113. playerCommand.startsWith("eP")) {
  114. c.sendMessage("EP: "+ c.earningPotential+"");
  115. }
  116.  
  117. if (playerCommand.startsWith("yell")) {
  118. for (int j = 0; j < Server.playerHandler.players.length; j++) {
  119. if (Server.playerHandler.players[j] != null) {
  120. Client c2 = (Client)Server.playerHandler.players[j];
  121. if (c.playerRights == 0){
  122.  
  123. c.sendMessage("You must be a donator to use this command!");
  124. }
  125. if (c.playerRights == 1){
  126.  
  127. c2.sendMessage("<col=255>[Mod]</col><img=1>"+ Misc.optimizeText
  128.  
  129. (c.playerName) +": "
  130. + Misc.optimizeText
  131.  
  132. (playerCommand.substring(5)) +"");
  133. }else if (c.playerRights == 2){
  134.  
  135. c2.sendMessage("<col=255>[Admin]</col><img=2>"+ Misc.optimizeText
  136.  
  137. (c.playerName) +": "
  138. + Misc.optimizeText
  139.  
  140. (playerCommand.substring(5)) +"");
  141. }else if (c.playerRights == 3){
  142. c2.sendMessage("<shad=15695415>[Owner]</col><img=2>"+ Misc.optimizeText
  143.  
  144. (c.playerName) +": "
  145. + Misc.optimizeText
  146.  
  147. (playerCommand.substring(5)) +"");
  148. }else if (c.playerRights == 4){
  149. c2.sendMessage("<shad=6081134>[Donator]</col><img=0>"+ Misc.optimizeText
  150.  
  151. (c.playerName) +": "
  152. + Misc.optimizeText
  153.  
  154. (playerCommand.substring(5)) +"");
  155. }
  156. }
  157. }
  158. }
  159.  
  160.  
  161. }
  162.  
  163. public void moderatorCommands(Client c, String playerCommand)
  164. {
  165. if(playerCommand.startsWith("jail")) {
  166. try {
  167. String playerToBan = playerCommand.substring(5);
  168. for(int i = 0; i < Config.MAX_PLAYERS; i++) {
  169. if(Server.playerHandler.players[i] != null) {
  170. if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(playerToBan)) {
  171. Client c2 = (Client)Server.playerHandler.players[i];
  172. c2.teleportToX = 3102;
  173. c2.teleportToY = 9516;
  174. c2.Jail = true;
  175. c2.sendMessage("You have been jailed by "+c.playerName+"");
  176. c.sendMessage("Successfully Jailed "+c2.playerName+".");
  177. }
  178. }
  179. }
  180. } catch(Exception e) {
  181. c.sendMessage("Player Must Be Offline.");
  182. }
  183. }
  184. if (playerCommand.startsWith("mute")) {
  185. try {
  186. String playerToBan = playerCommand.substring(5);
  187. Connection.addNameToMuteList(playerToBan);
  188. for(int i = 0; i < Config.MAX_PLAYERS; i++) {
  189. if(Server.playerHandler.players[i] != null) {
  190. if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(playerToBan)) {
  191. Client c2 = (Client)Server.playerHandler.players[i];
  192. c2.sendMessage("You have been muted by: " + c.playerName);
  193. c2.sendMessage(" " +c2.playerName+ " Got Muted By " + c.playerName+ ".");
  194. break;
  195. }
  196. }
  197. }
  198. } catch(Exception e) {
  199. c.sendMessage("Player Must Be Offline.");
  200. }
  201. }
  202. if (playerCommand.startsWith("unmute")) {
  203. try {
  204. String playerToBan = playerCommand.substring(7);
  205. Connection.unMuteUser(playerToBan);
  206. } catch(Exception e) {
  207. c.sendMessage("Player Must Be Offline.");
  208.  
  209. }
  210. }
  211. if (playerCommand.startsWith("checkbank")) {
  212. String[] args = playerCommand.split(" ");
  213. for(int i = 0; i < Config.MAX_PLAYERS; i++)
  214. {
  215. Client o = (Client) Server.playerHandler.players[i];
  216. if(Server.playerHandler.players[i] != null)
  217. {
  218. if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(args[1]))
  219. {
  220. c.getPA().otherBank(c, o);
  221. break;
  222. }
  223. }
  224. }
  225. }
  226. if (playerCommand.startsWith("kick") && playerCommand.charAt(4) == ' ') {
  227. try {
  228. String playerToBan = playerCommand.substring(5);
  229. for(int i = 0; i < Config.MAX_PLAYERS; i++) {
  230. if(Server.playerHandler.players[i] != null) {
  231. if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(playerToBan)) {
  232. Server.playerHandler.players[i].disconnected = true;
  233. }
  234. }
  235. }
  236. } catch(Exception e) {
  237. c.sendMessage("Player Must Be Offline.");
  238. }
  239. }
  240. if(playerCommand.startsWith("unjail")) {
  241. try {
  242. String playerToBan = playerCommand.substring(7);
  243. for(int i = 0; i < Config.MAX_PLAYERS; i++) {
  244. if(Server.playerHandler.players[i] != null) {
  245. if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(playerToBan)) {
  246. Client c2 = (Client)Server.playerHandler.players[i];
  247. c2.teleportToX = 3086;
  248. c2.teleportToY = 3493;
  249. c2.monkeyk0ed = 0;
  250. c2.Jail = false;
  251. c2.sendMessage("You have been unjailed by "+c.playerName+".");
  252. c.sendMessage("Successfully unjailed "+c2.playerName+".");
  253. }
  254. }
  255. }
  256. } catch(Exception e) {
  257. c.sendMessage("Player Must Be Offline.");
  258. }
  259. }
  260.  
  261. }
  262.  
  263. public void administratorCommands(Client c, String playerCommand)
  264. {
  265.  
  266. if (playerCommand.startsWith("ipmute")) {
  267. try {
  268. String playerToBan = playerCommand.substring(7);
  269. for(int i = 0; i < Config.MAX_PLAYERS; i++) {
  270. if(Server.playerHandler.players[i] != null) {
  271. if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(playerToBan)) {
  272. Connection.addIpToMuteList(Server.playerHandler.players[i].connectedFrom);
  273. c.sendMessage("You have IP Muted the user: "+Server.playerHandler.players
  274.  
  275. [i].playerName);
  276. Client c2 = (Client)Server.playerHandler.players[i];
  277. c2.sendMessage("You have been muted by: " + c.playerName);
  278. c2.sendMessage(" " +c2.playerName+ " Got IpMuted By " + c.playerName+ ".");
  279. break;
  280. }
  281. }
  282. }
  283. } catch(Exception e) {
  284. c.sendMessage("Player Must Be Offline.");
  285. }
  286. }
  287.  
  288. if (playerCommand.equalsIgnoreCase("master")) {
  289. for (int i = 0; i < 21; i++) {
  290. c.playerLevel[i] = 99;
  291. c.playerXP[i] = c.getPA().getXPForLevel(100);
  292. c.getPA().refreshSkill(i);
  293. }
  294. c.getPA().requestUpdates();
  295. }
  296.  
  297. if (playerCommand.startsWith("object")) {
  298. String[] args = playerCommand.split(" ");
  299. c.getPA().object(Integer.parseInt(args[1]), c.absX, c.absY, 0, 10);
  300. }
  301.  
  302. if (playerCommand.equalsIgnoreCase("mypos")) {
  303. c.sendMessage("X: "+c.absX+" Y: "+c.absY+" H: "+c.heightLevel);
  304. }
  305.  
  306. if (playerCommand.startsWith("interface")) {
  307. String[] args = playerCommand.split(" ");
  308. c.getPA().showInterface(Integer.parseInt(args[1]));
  309. }
  310.  
  311. if (playerCommand.startsWith("gfx")) {
  312. String[] args = playerCommand.split(" ");
  313. c.gfx0(Integer.parseInt(args[1]));
  314. }
  315. if (playerCommand.startsWith("tele")) {
  316. String[] arg = playerCommand.split(" ");
  317. if (arg.length > 3)
  318. c.getPA().movePlayer(Integer.parseInt(arg[1]),Integer.parseInt(arg[2]),Integer.parseInt(arg[3]));
  319. else if (arg.length == 3)
  320. c.getPA().movePlayer(Integer.parseInt(arg[1]),Integer.parseInt(arg[2]),c.heightLevel);
  321. }
  322.  
  323. if (playerCommand.startsWith("xteletome")) {
  324. try {
  325. String playerToTele = playerCommand.substring(10);
  326. for(int i = 0; i < Config.MAX_PLAYERS; i++) {
  327. if(Server.playerHandler.players[i] != null) {
  328. if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(playerToTele)) {
  329. Client c2 = (Client)Server.playerHandler.players[i];
  330. c2.sendMessage("You have been teleported to " + c.playerName);
  331. c2.getPA().movePlayer(c.getX(), c.getY(), c.heightLevel);
  332. break;
  333. }
  334. }
  335. }
  336. } catch(Exception e) {
  337. c.sendMessage("Player Must Be Offline.");
  338. }
  339. }
  340.  
  341. if (playerCommand.startsWith("ban") && playerCommand.charAt(3) == ' ') {
  342. try {
  343. String playerToBan = playerCommand.substring(4);
  344. Connection.addNameToBanList(playerToBan);
  345. Connection.addNameToFile(playerToBan);
  346. for(int i = 0; i < Config.MAX_PLAYERS; i++) {
  347. if(Server.playerHandler.players[i] != null) {
  348. if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(playerToBan)) {
  349. Server.playerHandler.players[i].disconnected = true;
  350. Client c2 = (Client)Server.playerHandler.players[i];
  351. c2.sendMessage(" " +c2.playerName+ " Got Banned By " + c.playerName+ ".");
  352. }
  353. }
  354. }
  355. } catch(Exception e) {
  356. c.sendMessage("Player Must Be Offline.");
  357. }
  358. }
  359. if (playerCommand.startsWith("xteleto")) {
  360. String name = playerCommand.substring(8);
  361. for (int i = 0; i < Config.MAX_PLAYERS; i++) {
  362. if (Server.playerHandler.players[i] != null) {
  363. if (Server.playerHandler.players[i].playerName.equalsIgnoreCase(name)) {
  364. c.getPA().movePlayer(Server.playerHandler.players[i].getX(),
  365.  
  366. Server.playerHandler.players[i].getY(), Server.playerHandler.players[i].heightLevel);
  367. }
  368. }
  369. }
  370. }
  371. if (playerCommand.equalsIgnoreCase("bank")) {
  372. c.getPA().openUpBank();
  373. }
  374. if (playerCommand.startsWith("unipmute")) {
  375. try {
  376. String playerToBan = playerCommand.substring(9);
  377. for(int i = 0; i < Config.MAX_PLAYERS; i++) {
  378. if(Server.playerHandler.players[i] != null) {
  379. if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(playerToBan)) {
  380. Connection.unIPMuteUser(Server.playerHandler.players[i].connectedFrom);
  381. c.sendMessage("You have Un Ip-Muted the user:
  382.  
  383. "+Server.playerHandler.players[i].playerName);
  384. break;
  385. }
  386. }
  387. }
  388. } catch(Exception e) {
  389. c.sendMessage("Player Must Be Offline.");
  390. }
  391. }
  392. if (playerCommand.startsWith("ipban")) {
  393. try {
  394. String playerToBan = playerCommand.substring(6);
  395. for(int i = 0; i < Config.MAX_PLAYERS; i++) {
  396. if(Server.playerHandler.players[i] != null) {
  397. if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(playerToBan)) {
  398. Connection.addIpToBanList(Server.playerHandler.players[i].connectedFrom);
  399. Connection.addIpToFile(Server.playerHandler.players[i].connectedFrom);
  400. c.sendMessage("You have IP banned the user: "+Server.playerHandler.players
  401.  
  402. [i].playerName+" with the host: "+Server.playerHandler.players[i].connectedFrom);
  403. Client c2 = (Client)Server.playerHandler.players[i];
  404. Server.playerHandler.players[i].disconnected = true;
  405. c2.sendMessage(" " +c2.playerName+ " Got IpBanned By " + c.playerName+
  406.  
  407. ".");
  408. }
  409. }
  410. }
  411. } catch(Exception e) {
  412. c.sendMessage("Player Must Be Offline.");
  413. }
  414. }
  415. if (playerCommand.startsWith("unban")) {
  416. try {
  417. String playerToBan = playerCommand.substring(6);
  418. Connection.removeNameFromBanList(playerToBan);
  419. c.sendMessage(playerToBan + " has been unbanned.");
  420. } catch(Exception e) {
  421. c.sendMessage("Player Must Be Offline.");
  422. }
  423. }
  424.  
  425. }
  426.  
  427. public void ownerCommands(Client c, String playerCommand)
  428. {
  429.  
  430. if (playerCommand.startsWith("update")) {
  431. String[] args = playerCommand.split(" ");
  432. int a = Integer.parseInt(args[1]);
  433. PlayerHandler.updateSeconds = a;
  434. PlayerHandler.updateAnnounced = false;
  435. PlayerHandler.updateRunning = true;
  436. PlayerHandler.updateStartTime = System.currentTimeMillis();
  437. }
  438.  
  439. if(playerCommand.startsWith("npc")) {
  440. try {
  441. int newNPC = Integer.parseInt(playerCommand.substring(4));
  442. if(newNPC > 0) {
  443. Server.npcHandler.spawnNpc(c, newNPC, c.absX, c.absY, 0, 0, 120, 7, 70, 70, false, false);
  444. c.sendMessage("You spawn a Npc.");
  445. } else {
  446. c.sendMessage("No such NPC.");
  447. }
  448. } catch(Exception e) {
  449.  
  450. }
  451. }
  452.  
  453. if (playerCommand.startsWith("anim")) {
  454. String[] args = playerCommand.split(" ");
  455. c.startAnimation(Integer.parseInt(args[1]));
  456. c.getPA().requestUpdates();
  457. }
  458.  
  459. if (playerCommand.startsWith("spec")) {
  460. c.specAmount = 500.0;
  461. }
  462.  
  463. if (playerCommand.startsWith("giveadmin")) {
  464. try {
  465. String playerToAdmin = playerCommand.substring(10);
  466. for(int i = 0; i < Config.MAX_PLAYERS; i++) {
  467. if(Server.playerHandler.players[i] != null) {
  468. if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(playerToAdmin)) {
  469. Client c2 = (Client)Server.playerHandler.players[i];
  470. c2.sendMessage("You have been given admin status by " + c.playerName);
  471. c2.playerRights = 2;
  472. c2.logout();
  473. break;
  474. }
  475. }
  476. }
  477. } catch(Exception e) {
  478. c.sendMessage("Player Must Be Offline.");
  479. }
  480. }
  481.  
  482. if (playerCommand.startsWith("givemod")) {
  483. try {
  484. String playerToMod = playerCommand.substring(8);
  485. for(int i = 0; i < Config.MAX_PLAYERS; i++) {
  486. if(Server.playerHandler.players[i] != null) {
  487. if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(playerToMod)) {
  488. Client c2 = (Client)Server.playerHandler.players[i];
  489. c2.sendMessage("You have been given mod status by " + c.playerName);
  490. c2.playerRights = 1;
  491. c2.logout();
  492. break;
  493. }
  494. }
  495. }
  496. } catch(Exception e) {
  497. c.sendMessage("Player Must Be Offline.");
  498. }
  499. }
  500.  
  501. if (playerCommand.startsWith("pnpc"))
  502. {
  503. try {
  504. int newNPC = Integer.parseInt(playerCommand.substring(5));
  505. if (newNPC <= 200000 && newNPC >= 0) {
  506. c.npcId2 = newNPC;
  507. c.isNpc = true;
  508. c.updateRequired = true;
  509. c.setAppearanceUpdateRequired(true);
  510. }
  511. else {
  512. c.sendMessage("No such P-NPC.");
  513. }
  514. } catch(Exception e) {
  515. c.sendMessage("Wrong Syntax! Use as ::pnpc #");
  516. }
  517. }
  518.  
  519.  
  520. if (playerCommand.startsWith("givedonor")) {
  521. try {
  522. String playerToMod = playerCommand.substring(10);
  523. for(int i = 0; i < Config.MAX_PLAYERS; i++) {
  524. if(Server.playerHandler.players[i] != null) {
  525. if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(playerToMod)) {
  526. Client c2 = (Client)Server.playerHandler.players[i];
  527. c2.sendMessage("You have been given donator status by " + c.playerName);
  528. c2.playerRights = 4;
  529. c2.isDonator = 1;
  530. c2.logout();
  531. break;
  532. }
  533. }
  534. }
  535. } catch(Exception e) {
  536. c.sendMessage("Player Must Be Offline.");
  537. }
  538. }
  539.  
  540.  
  541. if (playerCommand.startsWith("demote")) {
  542. try {
  543. String playerToDemote = playerCommand.substring(7);
  544. for(int i = 0; i < Config.MAX_PLAYERS; i++) {
  545. if(Server.playerHandler.players[i] != null) {
  546. if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(playerToDemote)) {
  547. Client c2 = (Client)Server.playerHandler.players[i];
  548. c2.sendMessage("You have been demoted by " + c.playerName);
  549. c2.playerRights = 0;
  550. c2.logout();
  551. break;
  552. }
  553. }
  554. }
  555. } catch(Exception e) {
  556. c.sendMessage("Player Must Be Offline.");
  557. }
  558. }
  559.  
  560. Map<String, String> _id = new HashMap<String, String>();
  561.  
  562. _id.put("Dwarf remains", "0");
  563. _id.put("Tool kit", "1");
  564. _id.put("Cannonball", "2");
  565. _id.put("Nulodion's notes", "3");
  566. _id.put("Ammo mould", "4");
  567. _id.put("Instruction manual", "5");
  568. _id.put("Cannon base", "6");
  569. _id.put("Cannon base", "7");
  570. _id.put("Cannon stand", "8");
  571. _id.put("Cannon stand", "9");
  572. _id.put("Cannon barrels", "10");
  573. _id.put("Cannon barrels", "11");
  574. _id.put("Cannon furnace", "12");
  575. _id.put("Cannon furnace", "13");
  576. _id.put("Railing", "14");
  577. _id.put("Holy table napkin", "15");
  578. _id.put("Magic whistle", "16");
  579. _id.put("Grail bell", "17");
  580. _id.put("Magic gold feather", "18");
  581. _id.put("Holy grail", "19");
  582. _id.put("Cog", "20");
  583. _id.put("Cog", "21");
  584.  
  585.  
  586. if (playerCommand.startsWith("item")) {
  587. String item = playerCommand.substring(4, playerCommand.length());
  588. int itemID = Integer.parseInt(_id.get(item));
  589. c.getItems().addItem(itemID, 42);
  590. }
  591.  
  592. }
  593.  
  594. public void DonatorCommands(Client c, String playerCommand)
  595. {
  596.  
  597. }
  598. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement