Guest User

Untitled

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