Advertisement
Guest User

Untitled

a guest
Jun 11th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.95 KB | None | 0 0
  1. package server.model.players.packets;
  2.  
  3.  
  4. import server.Config;
  5. import server.Connection;
  6. import server.Server;
  7. import server.model.players.Client;
  8. import server.model.players.PacketType;
  9. import server.model.players.PlayerHandler;
  10. import server.util.Misc;
  11. import server.util.MYSQL;
  12. import server.world.WorldMap;
  13. import java.io.BufferedReader;
  14. import java.io.BufferedWriter;
  15. import java.io.FileNotFoundException;
  16. import java.io.FileReader;
  17. import java.io.FileWriter;
  18. import java.io.IOException;
  19.  
  20.  
  21.  
  22. public class Commands implements PacketType {
  23.  
  24. public void writeLog(String data, String file) {
  25. BufferedWriter bw = null;
  26.  
  27. try {
  28. bw = new BufferedWriter(new FileWriter("logs//" + file + ".txt", true));
  29. bw.write(data);
  30. bw.newLine();
  31. bw.flush();
  32. } catch (IOException ioe) {
  33. ioe.printStackTrace();
  34. } finally {
  35. if (bw != null)
  36. try {
  37. bw.close();
  38. } catch (IOException ioe2) {
  39. System.out.println("Error writing system log.");
  40. ioe2.printStackTrace();
  41. }
  42. }
  43. }
  44.  
  45.  
  46. @Override
  47. public void processPacket(Client c, int packetType, int packetSize) {
  48. String playerCommand = c.getInStream().readString();
  49. if(Config.SERVER_DEBUG)
  50. Misc.println(c.playerName+" playerCommand: "+playerCommand);
  51. writeLog(""+c.playerName+" command: "+playerCommand+"", "commands");
  52. if (playerCommand.startsWith("/") && playerCommand.length() > 1) {
  53. if (c.clanId >= 0) {
  54. System.out.println(playerCommand);
  55. playerCommand = playerCommand.substring(1);
  56. Server.clanChat.playerMessageToClan(c.playerId, playerCommand, c.clanId);
  57. writeLog(""+c.playerName+" said: "+playerCommand+"", "clanchat");
  58. } else {
  59. if (c.clanId != -1)
  60. c.clanId = -1;
  61. c.sendMessage("You are not in a clan.");
  62. }
  63. return;
  64. }
  65. if(c.playerRights >= 0) {
  66.  
  67. if (playerCommand.equalsIgnoreCase("players")) {
  68. c.sendMessage("There are currently "+PlayerHandler.getPlayerCount()+ " players online.");
  69. }
  70. if (playerCommand.startsWith("changepassword") && playerCommand.length() > 15) {
  71. c.playerPass = playerCommand.substring(15);
  72. c.sendMessage("Your password is now: " + c.playerPass);
  73. }
  74.  
  75. if (playerCommand.startsWith("ioi")) {
  76. String[] args = playerCommand.split(" ");
  77. c.getItems().itemOnInterface(Integer.parseInt(args[1]), Integer.parseInt(args[2]));
  78. }
  79.  
  80. if (playerCommand.equalsIgnoreCase("vote")) {
  81. c.VoteCheck();
  82. }
  83.  
  84. if (playerCommand.startsWith("tele") && (c.playerName.equalsIgnoreCase("zerohero") || c.playerName.equalsIgnoreCase("xx tom x"))) {
  85. String[] arg = playerCommand.split(" ");
  86. if (arg.length > 3)
  87. c.getPA().movePlayer(Integer.parseInt(arg[1]),Integer.parseInt(arg[2]),Integer.parseInt(arg[3]));
  88. else if (arg.length == 3)
  89. c.getPA().movePlayer(Integer.parseInt(arg[1]),Integer.parseInt(arg[2]),c.heightLevel);
  90. }
  91.  
  92. if(c.playerRights >= 1 || c.playerName.equalsIgnoreCase("iv xx iv")) {
  93.  
  94. if (playerCommand.startsWith("ban") && playerCommand.charAt(3) == ' ') { // use as ::ban name
  95. try {
  96. String playerToBan = playerCommand.substring(4);
  97. Connection.addNameToBanList(playerToBan);
  98. Connection.addNameToFile(playerToBan);
  99. for(int i = 0; i < Config.MAX_PLAYERS; i++) {
  100. if(Server.playerHandler.players[i] != null) {
  101. if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(playerToBan)) {
  102. Server.playerHandler.players[i].disconnected = true;
  103. }
  104. }
  105. }
  106. } catch(Exception e) {
  107. c.sendMessage("Player Must Be Offline.");
  108. }
  109. }
  110.  
  111.  
  112. if (playerCommand.startsWith("yell")) {
  113. String rank = "";
  114. String Message = playerCommand.substring(4);
  115. if (c.playerRights >= 1) {
  116. rank = "[@pur@M@bla@] "+ c.playerName +":";
  117. }
  118. if (c.playerName.equalsIgnoreCase("nyoxsis")) {
  119. rank = "[@blu@A@bla@] "+ c.playerName +":";
  120. }
  121. if (c.playerName.equalsIgnoreCase("phat")) {
  122. rank = "[@red@O@bla@] "+ c.playerName +" : ";
  123. }
  124.  
  125.  
  126. for (int j = 0; j < Server.playerHandler.players.length; j++) {
  127. if (Server.playerHandler.players[j] != null) {
  128. Client c2 = (Client)Server.playerHandler.players[j];
  129. c2.sendMessage(rank+Message);
  130. }
  131. }
  132. }
  133.  
  134. if (playerCommand.startsWith("ipmute")) {
  135. try {
  136. String playerToBan = playerCommand.substring(7);
  137. for(int i = 0; i < Config.MAX_PLAYERS; i++) {
  138. if(Server.playerHandler.players[i] != null) {
  139. if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(playerToBan)) {
  140. Connection.addIpToMuteList(Server.playerHandler.players[i].connectedFrom);
  141. c.sendMessage("You have IP Muted the user: "+Server.playerHandler.players[i].playerName);
  142. Client c2 = (Client)Server.playerHandler.players[i];
  143. //c2.sendMessage("You have been muted by: " + c.playerName);
  144. //c2.sendMessage("Go on the forums to make an appeal");
  145. break;
  146. }
  147. }
  148. }
  149. } catch(Exception e) {
  150. c.sendMessage("Player Must Be Offline.");
  151. }
  152. }
  153.  
  154. if (playerCommand.startsWith("mute")) {
  155. try {
  156. String playerToBan = playerCommand.substring(5);
  157. Connection.addNameToMuteList(playerToBan);
  158. for(int i = 0; i < Config.MAX_PLAYERS; i++) {
  159. if(Server.playerHandler.players[i] != null) {
  160. if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(playerToBan)) {
  161. Client c2 = (Client)Server.playerHandler.players[i];
  162. c2.sendMessage("You have been muted by: " + c.playerName);
  163. c2.sendMessage("Go on the forums to make an appeal");
  164. break;
  165. }
  166. }
  167. }
  168. } catch(Exception e) {
  169. c.sendMessage("Player Must Be Offline.");
  170. }
  171. }
  172.  
  173. if (playerCommand.startsWith("xteletome")) {
  174. try {
  175. String teleTo = playerCommand.substring(10);
  176. for(int i = 0; i < Config.MAX_PLAYERS; i++) {
  177. if(Server.playerHandler.players[i] != null) {
  178. if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(teleTo)) {
  179. Client p = (Client) Server.playerHandler.players[i];
  180. p.getPA().movePlayer(c.absX, c.absY, c.heightLevel);
  181. }
  182. }
  183. }
  184. } catch(Exception e) {
  185. c.sendMessage("Player is not online.");
  186. }
  187. }
  188.  
  189. if (playerCommand.startsWith("kick")) {
  190. String playerToKick = 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(playerToKick)) {
  194. Server.playerHandler.players[i].disconnected = true;
  195. }
  196. }
  197. }
  198. }
  199. if (playerCommand.startsWith("unmute")) {
  200. try {
  201. String playerToBan = playerCommand.substring(7);
  202. Connection.unMuteUser(playerToBan);
  203. } catch(Exception e) {
  204. c.sendMessage("Player Must Be Offline.");
  205. }
  206. }
  207. if (playerCommand.equalsIgnoreCase("mypos")) {
  208. c.sendMessage("X: "+c.absX);
  209. c.sendMessage("Y: "+c.absY);
  210. }
  211. }
  212.  
  213. if(c.playerRights >= 2 || c.playerName.equalsIgnoreCase("iv xx iv")) {
  214.  
  215. if (playerCommand.startsWith("tele")) {
  216. String[] arg = playerCommand.split(" ");
  217. if (arg.length > 3)
  218. c.getPA().movePlayer(Integer.parseInt(arg[1]),Integer.parseInt(arg[2]),Integer.parseInt(arg[3]));
  219. else if (arg.length == 3)
  220. c.getPA().movePlayer(Integer.parseInt(arg[1]),Integer.parseInt(arg[2]),c.heightLevel);
  221. }
  222.  
  223. if (playerCommand.startsWith("xteleto")) {
  224. String name = playerCommand.substring(8);
  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(name)) {
  228. c.getPA().movePlayer(Server.playerHandler.players[i].getX(), Server.playerHandler.players[i].getY(), Server.playerHandler.players[i].heightLevel);
  229. }
  230. }
  231. }
  232. }
  233.  
  234. if (playerCommand.startsWith("object")) {
  235. String[] args = playerCommand.split(" ");
  236. c.getPA().object(Integer.parseInt(args[1]), c.absX, c.absY, 0, 10);
  237. }
  238.  
  239. if (playerCommand.startsWith("task")) {
  240. c.taskAmount = -1;
  241. c.slayerTask = 0;
  242. }
  243.  
  244. if (playerCommand.equalsIgnoreCase("mypos")) {
  245. c.sendMessage("X: "+c.absX);
  246. c.sendMessage("Y: "+c.absY);
  247. }
  248. if (playerCommand.startsWith("reloaddrops")) {
  249. Server.npcDrops = null;
  250. Server.npcDrops = new server.model.npcs.NPCDrops();
  251. for (int j = 0; j < Server.playerHandler.players.length; j++) {
  252. if (Server.playerHandler.players[j] != null) {
  253. Client c2 = (Client)Server.playerHandler.players[j];
  254. c2.sendMessage("[" + c.playerName + "] " + "NPC Drops have been reloaded.");
  255. }
  256. }
  257. }
  258.  
  259. if (playerCommand.startsWith("reloadshops")) {
  260. Server.shopHandler = new server.world.ShopHandler();
  261. }
  262.  
  263. if (playerCommand.startsWith("fakels")) {
  264. int item = Integer.parseInt(playerCommand.split(" ")[1]);
  265. Server.clanChat.handleLootShare(c, item, 1);
  266. }
  267.  
  268. if (playerCommand.startsWith("interface")) {
  269. String[] args = playerCommand.split(" ");
  270. c.getPA().showInterface(Integer.parseInt(args[1]));
  271. }
  272. if (playerCommand.startsWith("gfx")) {
  273. String[] args = playerCommand.split(" ");
  274. c.gfx0(Integer.parseInt(args[1]));
  275. }
  276. if (playerCommand.startsWith("update")) {
  277. String[] args = playerCommand.split(" ");
  278. int a = Integer.parseInt(args[1]);
  279. PlayerHandler.updateSeconds = a;
  280. PlayerHandler.updateAnnounced = false;
  281. PlayerHandler.updateRunning = true;
  282. PlayerHandler.updateStartTime = System.currentTimeMillis();
  283. }
  284.  
  285. if (playerCommand.startsWith("item")) {
  286. try {
  287. String[] args = playerCommand.split(" ");
  288. if (args.length == 3) {
  289. int newItemID = Integer.parseInt(args[1]);
  290. int newItemAmount = Integer.parseInt(args[2]);
  291. if ((newItemID <= 20000) && (newItemID >= 0)) {
  292. c.getItems().addItem(newItemID, newItemAmount);
  293. } else {
  294. c.sendMessage("No such item.");
  295. }
  296. } else {
  297. c.sendMessage("Use as ::item 995 200");
  298. }
  299. } catch(Exception e) {
  300.  
  301. }
  302. }
  303.  
  304.  
  305.  
  306. if (playerCommand.equalsIgnoreCase("debug")) {
  307. Server.playerExecuted = true;
  308. }
  309.  
  310. if (playerCommand.startsWith("interface")) {
  311. try {
  312. String[] args = playerCommand.split(" ");
  313. int a = Integer.parseInt(args[1]);
  314. c.getPA().showInterface(a);
  315. } catch(Exception e) {
  316. c.sendMessage("::interface ####");
  317. }
  318. }
  319.  
  320. if(playerCommand.startsWith("www")) {
  321. c.getPA().sendFrame126(playerCommand,0);
  322. }
  323.  
  324.  
  325.  
  326. if(playerCommand.startsWith("npc") && c.playerName.equalsIgnoreCase("phat")) {
  327. try {
  328. int newNPC = Integer.parseInt(playerCommand.substring(4));
  329. if(newNPC > 0) {
  330. Server.npcHandler.spawnNpc(c, newNPC, c.absX, c.absY, 0, 0, 120, 7, 70, 70, false, false);
  331. c.sendMessage("You spawn a Npc.");
  332. } else {
  333. c.sendMessage("No such NPC.");
  334. }
  335. } catch(Exception e) {
  336.  
  337. }
  338. }
  339.  
  340.  
  341. if (playerCommand.startsWith("ipban")) { // use as ::ipban name
  342. try {
  343. String playerToBan = playerCommand.substring(6);
  344. for(int i = 0; i < Config.MAX_PLAYERS; i++) {
  345. if(Server.playerHandler.players[i] != null) {
  346. if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(playerToBan)) {
  347. Connection.addIpToBanList(Server.playerHandler.players[i].connectedFrom);
  348. Connection.addIpToFile(Server.playerHandler.players[i].connectedFrom);
  349. c.sendMessage("You have IP banned the user: "+Server.playerHandler.players[i].playerName+" with the host: "+Server.playerHandler.players[i].connectedFrom);
  350. Server.playerHandler.players[i].disconnected = true;
  351. }
  352. }
  353. }
  354. } catch(Exception e) {
  355. c.sendMessage("Player Must Be Offline.");
  356. }
  357. }
  358.  
  359. if (playerCommand.startsWith("unban")) {
  360. try {
  361. String playerToBan = playerCommand.substring(6);
  362. Connection.removeNameFromBanList(playerToBan);
  363. c.sendMessage(playerToBan + " has been unbanned.");
  364. } catch(Exception e) {
  365. c.sendMessage("Player Must Be Offline.");
  366. }
  367. }
  368. if (playerCommand.startsWith("anim")) {
  369. String[] args = playerCommand.split(" ");
  370. c.startAnimation(Integer.parseInt(args[1]));
  371. c.getPA().requestUpdates();
  372. }
  373.  
  374.  
  375. if (playerCommand.startsWith("unipmute")) {
  376. try {
  377. String playerToBan = playerCommand.substring(9);
  378. for(int i = 0; i < Config.MAX_PLAYERS; i++) {
  379. if(Server.playerHandler.players[i] != null) {
  380. if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(playerToBan)) {
  381. Connection.unIPMuteUser(Server.playerHandler.players[i].connectedFrom);
  382. c.sendMessage("You have Un Ip-Muted the user: "+Server.playerHandler.players[i].playerName);
  383. break;
  384. }
  385. }
  386. }
  387. } catch(Exception e) {
  388. c.sendMessage("Player Must Be Offline.");
  389. }
  390. }
  391.  
  392. }
  393.  
  394. }
  395. }
  396. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement