Advertisement
Guest User

Untitled

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