Guest User

Untitled

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