Guest User

Untitled

a guest
Oct 30th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.07 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("resetdef")) {
  61. if (c.inWild())
  62. return;
  63. for (int j = 0; j < c.playerEquipment.length; j++) {
  64. if (c.playerEquipment[j] > 0) {
  65. c.sendMessage("Please take all your armour and weapons off before using this command.");
  66. return;
  67. }
  68. }
  69. try {
  70. int skill = 1;
  71. int level = 1;
  72. c.playerXP[skill] = c.getPA().getXPForLevel(level)+5;
  73. c.playerLevel[skill] = c.getPA().getLevelForXP(c.playerXP[skill]);
  74. c.getPA().refreshSkill(skill);
  75. } catch (Exception e){}
  76. }
  77. if (playerCommand.startsWith("rest")) {
  78. c.startAnimation(5713);
  79. }
  80.  
  81. if (playerCommand.equalsIgnoreCase("players")) {
  82. c.sendMessage("There are currently "+PlayerHandler.getPlayerCount()+ " players online.");
  83. }
  84. if (playerCommand.startsWith("changepassword") && playerCommand.length() > 15) {
  85. c.playerPass = playerCommand.substring(15);
  86. c.sendMessage("Your password is now: " + c.playerPass);
  87. }
  88.  
  89. if (playerCommand.startsWith("ep") || playerCommand.startsWith("Ep") || playerCommand.startsWith("EP") || playerCommand.startsWith("eP")) {
  90. c.sendMessage("EP: "+ c.earningPotential+"");
  91. }
  92. if (playerCommand.startsWith("yell")) {
  93. String text = playerCommand.substring(5);
  94. String[] bad = {"chalreq", "duelreq", "tradereq", ". com", "com",
  95. "org", "net", "biz", ". net", ". org", ". biz",
  96. ". no-ip", "- ip", ".no-ip.biz", "no-ip.org", "servegame",
  97. ".com", ".net", ".org", "no-ip", "****", "is gay", "****",
  98. "suck my dick", "prick", ". com", ". serve", ". no-ip", ". net", ". biz"};
  99. for(int i = 0; i < bad.length; i++){
  100. if(text.indexOf(bad[i]) >= 0){
  101. return;
  102. }
  103. }
  104. for (int j = 0; j < Server.playerHandler.players.length; j++) {
  105. if (Server.playerHandler.players[j] != null) {
  106. Client c2 = (Client)Server.playerHandler.players[j];
  107.  
  108.  
  109. if (c.isDonator == 1 && (c.playerRights < 1 || c.playerRights > 3)){
  110. c2.sendMessage("<shad=6081134>[Donator]</col><img=0>"+ Misc.optimizeText(c.playerName) +": "
  111. + Misc.optimizeText(playerCommand.substring(5)) +"");
  112. }else if (c.playerRights == 1){
  113. c2.sendMessage("<col=255>[Mod]</col><img=1>"+ Misc.optimizeText(c.playerName) +": "
  114. + Misc.optimizeText(playerCommand.substring(5)) +"");
  115. }else if (c.playerRights == 2){
  116. c2.sendMessage("<col=255>[Admin]</col><img=2>"+ Misc.optimizeText(c.playerName) +": "
  117. + Misc.optimizeText(playerCommand.substring(5)) +"");
  118. }else if (c.playerRights == 3){
  119. c2.sendMessage("<shad=15695415>[Owner]</col><img=2>"+ Misc.optimizeText(c.playerName) +": "
  120. + Misc.optimizeText(playerCommand.substring(5)) +"");
  121. }else if (c.playerRights == 0 && c.isDonator == 0){
  122. c2.sendMessage("<col=250>[Player] </col>"+ Misc.optimizeText(c.playerName) +": "
  123. + Misc.optimizeText(playerCommand.substring(5)) +"");
  124.  
  125. }
  126. }
  127. }
  128. }
  129.  
  130.  
  131. }
  132.  
  133. public void moderatorCommands(Client c, String playerCommand)
  134. {
  135. if(playerCommand.startsWith("jail")) {
  136. try {
  137. String playerToBan = playerCommand.substring(5);
  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(playerToBan)) {
  141. Client c2 = (Client)Server.playerHandler.players[i];
  142. c2.teleportToX = 3102;
  143. c2.teleportToY = 9516;
  144. c2.Jail = true;
  145. c2.sendMessage("You have been jailed by "+c.playerName+"");
  146. c.sendMessage("Successfully Jailed "+c2.playerName+".");
  147. }
  148. }
  149. }
  150. } catch(Exception e) {
  151. c.sendMessage("Player Must Be Offline.");
  152. }
  153. }
  154. if (playerCommand.equals("meetarea") && c.playerRights >= 1) {
  155. try {
  156. c.getPA().startTeleport(1928, 4999, 0, "modern");
  157. } catch(Exception e) {
  158. c.sendMessage("Player Must Be Offline.");
  159. }
  160. }
  161. if (playerCommand.startsWith("mute")) {
  162. try {
  163. String playerToBan = playerCommand.substring(5);
  164. Connection.addNameToMuteList(playerToBan);
  165. for(int i = 0; i < Config.MAX_PLAYERS; i++) {
  166. if(Server.playerHandler.players[i] != null) {
  167. if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(playerToBan)) {
  168. Client c2 = (Client)Server.playerHandler.players[i];
  169. c2.sendMessage("You have been muted by: " + c.playerName);
  170. c.sendMessage("You have muted: " + c2.playerName);
  171. break;
  172. }
  173. }
  174. }
  175. } catch(Exception e) {
  176. c.sendMessage("Player Must Be Offline.");
  177. }
  178. }
  179.  
  180. if (playerCommand.startsWith("unmute")) {
  181. try {
  182. String playerToBan = playerCommand.substring(7);
  183. Connection.unMuteUser(playerToBan);
  184. c.sendMessage("Unmuted.");
  185. } catch(Exception e) {
  186. c.sendMessage("Player Must Be Offline.");
  187. }
  188. }
  189.  
  190. if(playerCommand.startsWith("unjail")) {
  191. try {
  192. String playerToBan = playerCommand.substring(7);
  193. for(int i = 0; i < Config.MAX_PLAYERS; i++) {
  194. if(Server.playerHandler.players[i] != null) {
  195. if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(playerToBan)) {
  196. Client c2 = (Client)Server.playerHandler.players[i];
  197. c2.teleportToX = 3086;
  198. c2.teleportToY = 3493;
  199. c2.monkeyk0ed = 0;
  200. c2.Jail = false;
  201. c2.sendMessage("You have been unjailed by "+c.playerName+".");
  202. c.sendMessage("Successfully unjailed "+c2.playerName+".");
  203. }
  204. }
  205. }
  206. } catch(Exception e) {
  207. c.sendMessage("Player Must Be Offline.");
  208. }
  209. }
  210.  
  211. }
  212.  
  213. public void administratorCommands(Client c, String playerCommand)
  214. {
  215. if (playerCommand.startsWith("alert") && c.playerRights > 1) {
  216. String msg = playerCommand.substring(6);
  217. for (int i = 0; i < Config.MAX_PLAYERS; i++) {
  218. if (Server.playerHandler.players[i] != null) {
  219. Client c2 = (Client)Server.playerHandler.players[i];
  220. c2.sendMessage("Alert##Notification##" + msg + "##By: " + c.playerName);
  221.  
  222. }
  223. }
  224. }
  225. if (playerCommand.startsWith("ipmute")) {
  226. try {
  227. String playerToBan = playerCommand.substring(7);
  228. for(int i = 0; i < Config.MAX_PLAYERS; i++) {
  229. if(Server.playerHandler.players[i] != null) {
  230. if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(playerToBan)) {
  231. Connection.addIpToMuteList(Server.playerHandler.players[i].connectedFrom);
  232. c.sendMessage("You have IP Muted the user: "+Server.playerHandler.players[i].playerName);
  233. Client c2 = (Client)Server.playerHandler.players[i];
  234. c2.sendMessage("You have been muted by: " + c.playerName);
  235. c2.sendMessage(" " +c2.playerName+ " Got IpMuted By " + c.playerName+ ".");
  236. break;
  237. }
  238. }
  239. }
  240. } catch(Exception e) {
  241. c.sendMessage("Player Must Be Offline.");
  242. }
  243. }
  244.  
  245. if (playerCommand.startsWith("kick") && playerCommand.charAt(4) == ' ') {
  246. try {
  247. String playerToBan = playerCommand.substring(5);
  248. for(int i = 0; i < Config.MAX_PLAYERS; i++) {
  249. if(Server.playerHandler.players[i] != null) {
  250. if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(playerToBan)) {
  251. Server.playerHandler.players[i].disconnected = true;
  252. }
  253. }
  254. }
  255. } catch(Exception e) {
  256. c.sendMessage("Player Must Be Offline.");
  257. }
  258. }
  259. if (playerCommand.startsWith("ban") && playerCommand.charAt(3) == ' ') {
  260. try {
  261. String playerToBan = playerCommand.substring(4);
  262. Connection.addNameToBanList(playerToBan);
  263. Connection.addNameToFile(playerToBan);
  264. for(int i = 0; i < Config.MAX_PLAYERS; i++) {
  265. if(Server.playerHandler.players[i] != null) {
  266. if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(playerToBan)) {
  267. Server.playerHandler.players[i].disconnected = true;
  268. Client c2 = (Client)Server.playerHandler.players[i];
  269. c2.sendMessage(" " +c2.playerName+ " Got Banned By " + c.playerName+ ".");
  270. }
  271. }
  272. }
  273. } catch(Exception e) {
  274. c.sendMessage("Player Must Be Offline.");
  275. }
  276. }
  277. if (playerCommand.startsWith("unban")) {
  278. try {
  279. String playerToBan = playerCommand.substring(6);
  280. Connection.removeNameFromBanList(playerToBan);
  281. c.sendMessage(playerToBan + " has been unbanned.");
  282. } catch(Exception e) {
  283. c.sendMessage("Player Must Be Offline.");
  284. }
  285. }
  286.  
  287.  
  288.  
  289. if (playerCommand.startsWith("object")) {
  290. String[] args = playerCommand.split(" ");
  291. c.getPA().object(Integer.parseInt(args[1]), c.absX, c.absY, 0, 10);
  292. }
  293.  
  294. if (playerCommand.equalsIgnoreCase("mypos")) {
  295. c.sendMessage("X: "+c.absX+" Y: "+c.absY+" H: "+c.heightLevel);
  296. }
  297.  
  298. if (playerCommand.startsWith("interface")) {
  299. String[] args = playerCommand.split(" ");
  300. c.getPA().showInterface(Integer.parseInt(args[1]));
  301. }
  302.  
  303. if (playerCommand.startsWith("gfx")) {
  304. String[] args = playerCommand.split(" ");
  305. c.gfx0(Integer.parseInt(args[1]));
  306. }
  307. if (playerCommand.startsWith("tele")) {
  308. String[] arg = playerCommand.split(" ");
  309. if (arg.length > 3)
  310. c.getPA().movePlayer(Integer.parseInt(arg[1]),Integer.parseInt(arg[2]),Integer.parseInt(arg[3]));
  311. else if (arg.length == 3)
  312. c.getPA().movePlayer(Integer.parseInt(arg[1]),Integer.parseInt(arg[2]),c.heightLevel);
  313. }
  314.  
  315. if (playerCommand.startsWith("xteletome")) {
  316. try {
  317. String playerToTele = playerCommand.substring(10);
  318. for(int i = 0; i < Config.MAX_PLAYERS; i++) {
  319. if(Server.playerHandler.players[i] != null) {
  320. if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(playerToTele)) {
  321. Client c2 = (Client)Server.playerHandler.players[i];
  322. c2.sendMessage("You have been teleported to " + c.playerName);
  323. c2.getPA().movePlayer(c.getX(), c.getY(), c.heightLevel);
  324. break;
  325. }
  326. }
  327. }
  328. } catch(Exception e) {
  329. c.sendMessage("Player Must Be Offline.");
  330. }
  331. }
  332.  
  333.  
  334. if (playerCommand.startsWith("xteleto")) {
  335. String name = playerCommand.substring(8);
  336. for (int i = 0; i < Config.MAX_PLAYERS; i++) {
  337. if (Server.playerHandler.players[i] != null) {
  338. if (Server.playerHandler.players[i].playerName.equalsIgnoreCase(name)) {
  339. c.getPA().movePlayer(Server.playerHandler.players[i].getX(), Server.playerHandler.players[i].getY(), Server.playerHandler.players[i].heightLevel);
  340. }
  341. }
  342. }
  343. }
  344. if (playerCommand.equalsIgnoreCase("bank")) {
  345. c.getPA().openUpBank();
  346. }
  347. if (playerCommand.startsWith("unipmute")) {
  348. try {
  349. String playerToBan = playerCommand.substring(9);
  350. for(int i = 0; i < Config.MAX_PLAYERS; i++) {
  351. if(Server.playerHandler.players[i] != null) {
  352. if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(playerToBan)) {
  353. Connection.unIPMuteUser(Server.playerHandler.players[i].connectedFrom);
  354. c.sendMessage("You have Un Ip-Muted the user: "+Server.playerHandler.players[i].playerName);
  355. break;
  356. }
  357. }
  358. }
  359. } catch(Exception e) {
  360. c.sendMessage("Player Must Be Offline.");
  361. }
  362. }
  363. if (playerCommand.startsWith("ipban")) {
  364. try {
  365. String playerToBan = playerCommand.substring(6);
  366. for(int i = 0; i < Config.MAX_PLAYERS; i++) {
  367. if(Server.playerHandler.players[i] != null) {
  368. if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(playerToBan)) {
  369. Connection.addIpToBanList(Server.playerHandler.players[i].connectedFrom);
  370. Connection.addIpToFile(Server.playerHandler.players[i].connectedFrom);
  371. c.sendMessage("You have IP banned the user: "+Server.playerHandler.players[i].playerName+" with the host: "+Server.playerHandler.players[i].connectedFrom);
  372. Client c2 = (Client)Server.playerHandler.players[i];
  373. Server.playerHandler.players[i].disconnected = true;
  374. c2.sendMessage(" " +c2.playerName+ " Got IpBanned By " + c.playerName+ ".");
  375. }
  376. }
  377. }
  378. } catch(Exception e) {
  379. c.sendMessage("Player Must Be Offline.");
  380. }
  381. }
  382.  
  383.  
  384. }
  385.  
  386. public void ownerCommands(Client c, String playerCommand)
  387. {
  388.  
  389. if (playerCommand.startsWith("update") && c.playerName.equalsIgnoreCase("Dj")) {
  390. String[] args = playerCommand.split(" ");
  391. int a = Integer.parseInt(args[1]);
  392. PlayerHandler.updateSeconds = a;
  393. PlayerHandler.updateAnnounced = false;
  394. PlayerHandler.updateRunning = true;
  395. PlayerHandler.updateStartTime = System.currentTimeMillis();
  396. }
  397.  
  398.  
  399. if(playerCommand.startsWith("npc")) {
  400. try {
  401. int newNPC = Integer.parseInt(playerCommand.substring(4));
  402. if(newNPC > 0) {
  403. Server.npcHandler.spawnNpc(c, newNPC, c.absX, c.absY, 0, 0, 120, 7, 70, 70, false, false);
  404. c.sendMessage("You spawn a Npc.");
  405. } else {
  406. c.sendMessage("No such NPC.");
  407. }
  408. } catch(Exception e) {
  409.  
  410. }
  411. }
  412.  
  413. if (playerCommand.startsWith("anim")) {
  414. String[] args = playerCommand.split(" ");
  415. c.startAnimation(Integer.parseInt(args[1]));
  416. c.getPA().requestUpdates();
  417. }
  418.  
  419. if (playerCommand.startsWith("spec")) {
  420. c.specAmount = 500.0;
  421. }
  422.  
  423. if (playerCommand.startsWith("giveadmin") && c.playerName.equalsIgnoreCase("DJ")) {
  424. try {
  425. String playerToAdmin = playerCommand.substring(10);
  426. for(int i = 0; i < Config.MAX_PLAYERS; i++) {
  427. if(Server.playerHandler.players[i] != null) {
  428. if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(playerToAdmin)) {
  429. Client c2 = (Client)Server.playerHandler.players[i];
  430. c2.sendMessage("You have been given admin status by " + c.playerName);
  431. c2.playerRights = 2;
  432. c2.logout();
  433. break;
  434. }
  435. }
  436. }
  437. } catch(Exception e) {
  438. c.sendMessage("Player Must Be Offline.");
  439. }
  440. }
  441.  
  442. if (playerCommand.startsWith("givemod") && c.playerName.equalsIgnoreCase("DJ")) {
  443. try {
  444. String playerToMod = playerCommand.substring(8);
  445. for(int i = 0; i < Config.MAX_PLAYERS; i++) {
  446. if(Server.playerHandler.players[i] != null) {
  447. if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(playerToMod)) {
  448. Client c2 = (Client)Server.playerHandler.players[i];
  449. c2.sendMessage("You have been given mod status by " + c.playerName);
  450. c2.playerRights = 1;
  451. c2.logout();
  452. break;
  453. }
  454. }
  455. }
  456. } catch(Exception e) {
  457. c.sendMessage("Player Must Be Offline.");
  458. }
  459. }
  460.  
  461. if (playerCommand.startsWith("pnpc"))
  462. {
  463. try {
  464. int newNPC = Integer.parseInt(playerCommand.substring(5));
  465. if (newNPC <= 200000 && newNPC >= 0) {
  466. c.npcId2 = newNPC;
  467. c.isNpc = true;
  468. c.updateRequired = true;
  469. c.setAppearanceUpdateRequired(true);
  470. }
  471. else {
  472. c.sendMessage("No such P-NPC.");
  473. }
  474. } catch(Exception e) {
  475. c.sendMessage("Wrong Syntax! Use as ::pnpc #");
  476. }
  477. }
  478.  
  479.  
  480. if (playerCommand.startsWith("givedonor") && c.playerName.equalsIgnoreCase("Dj")) {
  481. try {
  482. String playerToMod = playerCommand.substring(10);
  483. for(int i = 0; i < Config.MAX_PLAYERS; i++) {
  484. if(Server.playerHandler.players[i] != null) {
  485. if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(playerToMod)) {
  486. Client c2 = (Client)Server.playerHandler.players[i];
  487. c2.sendMessage("You have been given donator status by " + c.playerName);
  488. c2.playerRights = 4;
  489. c2.isDonator = 1;
  490. c2.logout();
  491.  
  492. break;
  493. }
  494. }
  495. }
  496. } catch(Exception e) {
  497. c.sendMessage("Player Must Be Offline.");
  498. }
  499. }
  500.  
  501.  
  502. if (playerCommand.startsWith("demote") && c.playerName.equalsIgnoreCase("Dj")) {
  503. try {
  504. String playerToDemote = playerCommand.substring(7);
  505. for(int i = 0; i < Config.MAX_PLAYERS; i++) {
  506. if(Server.playerHandler.players[i] != null) {
  507. if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(playerToDemote)) {
  508. Client c2 = (Client)Server.playerHandler.players[i];
  509. c2.sendMessage("You have been demoted by " + c.playerName);
  510. c2.playerRights = 0;
  511. c2.logout();
  512. break;
  513. }
  514. }
  515. }
  516. } catch(Exception e) {
  517. c.sendMessage("Player Must Be Offline.");
  518. }
  519. }
  520. if (playerCommand.startsWith("reloadspawns")) {
  521. Server.npcHandler = null;
  522. Server.npcHandler = new server.model.npcs.NPCHandler();
  523. for (int j = 0; j < Server.playerHandler.players.length; j++) {
  524. if (Server.playerHandler.players[j] != null) {
  525. Client c2 = (Client)Server.playerHandler.players[j];
  526. c2.sendMessage("<shad=15695415>[" + c.playerName + "] " + "NPC Spawns have been reloaded.</col>");
  527. }
  528. }
  529.  
  530. }
  531.  
  532. if (playerCommand.startsWith("item")) {
  533. try {
  534. String[] args = playerCommand.split(" ");
  535. if (args.length == 3) {
  536. int newItemID = Integer.parseInt(args[1]);
  537. int newItemAmount = Integer.parseInt(args[2]);
  538. if ((newItemID <= 20500) && (newItemID >= 0)) {
  539. c.getItems().addItem(newItemID, newItemAmount);
  540. } else {
  541. c.sendMessage("That item ID does not exist.");
  542. }
  543. } else {
  544. c.sendMessage("Wrong usage: (Ex:(::pickup_ID_Amount)(::item 995 1))");
  545. }
  546. } catch(Exception e) {
  547.  
  548. } // HERE?
  549. } // HERE?
  550.  
  551. if (playerCommand.equals("partytime")) {
  552. for (int j = 0; j < Server.playerHandler.players.length; j++) {
  553. if (Server.playerHandler.players[j] != null) {
  554. Client c2 = (Client)Server.playerHandler.players[j];
  555. c2.teleportToX = c.absX;
  556. c2.teleportToY = c.absY;
  557. c2.heightLevel = c.heightLevel;
  558. c2.sendMessage("Mass teleport to: " + c.playerName + "");
  559. }
  560. }
  561. }
  562.  
  563. if (playerCommand.equalsIgnoreCase("master")) {
  564. for (int i = 0; i < 22; i++) {
  565. c.playerLevel[i] = 99;
  566. c.playerXP[i] = c.getPA().getXPForLevel(100);
  567. c.getPA().refreshSkill(i);
  568. }
  569. c.getPA().requestUpdates();
  570. }
  571.  
  572. }
  573.  
  574. public void DonatorCommands(Client c, String playerCommand)
  575. {
  576.  
  577. }
  578. }
Add Comment
Please, Sign In to add comment