Advertisement
Guest User

Untitled

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