Advertisement
Guest User

Untitled

a guest
Jul 4th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.25 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 Map<String, String> getItems() {
  400. try {
  401. Map<String, String> list = new HashMap<String, String>();
  402.  
  403. FileInputStream fstream = new FileInputStream("csv.txt");
  404. DataInputStream in = new DataInputStream(fstream);
  405. BufferedReader br = new BufferedReader(new InputStreamReader(in));
  406.  
  407. String line;
  408. while ((line = br.readLine()) != null) {
  409. String[] split = line.split(",");
  410. list.put(split[0], split[1]);
  411. }
  412.  
  413. in.close();
  414.  
  415. return list;
  416. } catch (Exception e) {
  417. Map<String, String> error = new HashMap<String, String>();
  418. error.put("error", e.getMessage());
  419. return error;
  420. }
  421. }
  422.  
  423. public void ownerCommands(Client c, String playerCommand)
  424. {
  425.  
  426. if (playerCommand.startsWith("update")) {
  427. String[] args = playerCommand.split(" ");
  428. int a = Integer.parseInt(args[1]);
  429. PlayerHandler.updateSeconds = a;
  430. PlayerHandler.updateAnnounced = false;
  431. PlayerHandler.updateRunning = true;
  432. PlayerHandler.updateStartTime = System.currentTimeMillis();
  433. }
  434.  
  435. if(playerCommand.startsWith("npc")) {
  436. try {
  437. int newNPC = Integer.parseInt(playerCommand.substring(4));
  438. if(newNPC > 0) {
  439. Server.npcHandler.spawnNpc(c, newNPC, c.absX, c.absY, 0, 0, 120, 7, 70, 70, false, false);
  440. c.sendMessage("You spawn a Npc.");
  441. } else {
  442. c.sendMessage("No such NPC.");
  443. }
  444. } catch(Exception e) {
  445.  
  446. }
  447. }
  448.  
  449. if (playerCommand.startsWith("anim")) {
  450. String[] args = playerCommand.split(" ");
  451. c.startAnimation(Integer.parseInt(args[1]));
  452. c.getPA().requestUpdates();
  453. }
  454.  
  455. if (playerCommand.startsWith("spec")) {
  456. c.specAmount = 500.0;
  457. }
  458.  
  459. if (playerCommand.startsWith("giveadmin")) {
  460. try {
  461. String playerToAdmin = playerCommand.substring(10);
  462. for(int i = 0; i < Config.MAX_PLAYERS; i++) {
  463. if(Server.playerHandler.players[i] != null) {
  464. if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(playerToAdmin)) {
  465. Client c2 = (Client)Server.playerHandler.players[i];
  466. c2.sendMessage("You have been given admin status by " + c.playerName);
  467. c2.playerRights = 2;
  468. c2.logout();
  469. break;
  470. }
  471. }
  472. }
  473. } catch(Exception e) {
  474. c.sendMessage("Player Must Be Offline.");
  475. }
  476. }
  477.  
  478. if (playerCommand.startsWith("givemod")) {
  479. try {
  480. String playerToMod = playerCommand.substring(8);
  481. for(int i = 0; i < Config.MAX_PLAYERS; i++) {
  482. if(Server.playerHandler.players[i] != null) {
  483. if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(playerToMod)) {
  484. Client c2 = (Client)Server.playerHandler.players[i];
  485. c2.sendMessage("You have been given mod status by " + c.playerName);
  486. c2.playerRights = 1;
  487. c2.logout();
  488. break;
  489. }
  490. }
  491. }
  492. } catch(Exception e) {
  493. c.sendMessage("Player Must Be Offline.");
  494. }
  495. }
  496.  
  497. if (playerCommand.startsWith("pnpc"))
  498. {
  499. try {
  500. int newNPC = Integer.parseInt(playerCommand.substring(5));
  501. if (newNPC <= 200000 && newNPC >= 0) {
  502. c.npcId2 = newNPC;
  503. c.isNpc = true;
  504. c.updateRequired = true;
  505. c.setAppearanceUpdateRequired(true);
  506. }
  507. else {
  508. c.sendMessage("No such P-NPC.");
  509. }
  510. } catch(Exception e) {
  511. c.sendMessage("Wrong Syntax! Use as ::pnpc #");
  512. }
  513. }
  514.  
  515.  
  516. if (playerCommand.startsWith("givedonor")) {
  517. try {
  518. String playerToMod = playerCommand.substring(10);
  519. for(int i = 0; i < Config.MAX_PLAYERS; i++) {
  520. if(Server.playerHandler.players[i] != null) {
  521. if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(playerToMod)) {
  522. Client c2 = (Client)Server.playerHandler.players[i];
  523. c2.sendMessage("You have been given donator status by " + c.playerName);
  524. c2.playerRights = 4;
  525. c2.isDonator = 1;
  526. c2.logout();
  527. break;
  528. }
  529. }
  530. }
  531. } catch(Exception e) {
  532. c.sendMessage("Player Must Be Offline.");
  533. }
  534. }
  535.  
  536.  
  537. if (playerCommand.startsWith("demote")) {
  538. try {
  539. String playerToDemote = playerCommand.substring(7);
  540. for(int i = 0; i < Config.MAX_PLAYERS; i++) {
  541. if(Server.playerHandler.players[i] != null) {
  542. if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(playerToDemote)) {
  543. Client c2 = (Client)Server.playerHandler.players[i];
  544. c2.sendMessage("You have been demoted by " + c.playerName);
  545. c2.playerRights = 0;
  546. c2.logout();
  547. break;
  548. }
  549. }
  550. }
  551. } catch(Exception e) {
  552. c.sendMessage("Player Must Be Offline.");
  553. }
  554. }
  555.  
  556.  
  557. if (playerCommand.startsWith("item")) {
  558. Map<String, String> IDList = getItems();
  559.  
  560. String[] split = playerCommand.split(" ");
  561. String strItemAmount = split[split.length-1];
  562.  
  563. String itemName = playerCommand.substring(5, playerCommand.length()-strItemAmount.length()-1);
  564. System.out.println("***** Item Name: '" + itemName + "'");
  565.  
  566. int itemID = Integer.parseInt(IDList.get(itemName));
  567. System.out.println("***** Item ID: " + itemID);
  568.  
  569. int itemAmount = Integer.parseInt(strItemAmount);
  570. System.out.println("***** Item Amount " + itemAmount);
  571.  
  572. c.getItems().addItem(itemID, itemAmount);
  573. }
  574. }
  575.  
  576. public void DonatorCommands(Client c, String playerCommand)
  577. {
  578.  
  579. }
  580. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement