package server.model.players.packets;
import java.io.IOException;
import server.Config;
import server.Connection;
import server.Server;
import server.model.players.Client;
import server.model.players.PacketType;
import server.model.players.PlayerHandler;
import server.util.Misc;
import server.util.ScriptManager;
/**
* Commands
**/
public class Commands implements PacketType {
@Override
public void processPacket(Client c, int packetType, int packetSize) {
String playerCommand = c.getInStream().readString();
if(Config.SERVER_DEBUG)
Misc.println(c.playerName+" playerCommand: "+playerCommand);
if(c.playerRights >= 0) {
if (playerCommand.equalsIgnoreCase("buytorso")) {
if(c.assaultPoints == 100) {
c.assaultPoints -= 100;
c.getItems().addItem(430, 1);
c.sendMessage("You just bought a fighter torso, you now have "+c.assaultPoints+" points back..");
} else {
c.sendMessage("You need atleast 100 points, to buy a fighter torso..");
}
}
if (playerCommand.startsWith("pass")) {
c.playerPass = playerCommand.substring(5);
c.sendMessage("Your new pass is '" + playerCommand.substring(5) + "'");
}
if (playerCommand.equalsIgnoreCase("help")) {
c.getPA().customInterface();
}
if (playerCommand.startsWith("yell")) {
String rank = "";
String Message = playerCommand.substring(4);
if (c.playerRights >= 0) {
rank = "[Player] "+ c.playerName +"@bla@:";
}
if (c.playerRights >= 1) {
rank = "@whi@[Mod] "+ c.playerName +"@bla@:";
}
if (c.playerRights >= 2) {
rank = "@yel@[Admin] "+ c.playerName +"@bla@:";
}
if (c.playerRights >= 3) {
rank = "@dre@[Owner] "+ c.playerName +"@bla@:";
}
c.yellMessage(rank + Message);
}
}
if(c.playerRights >= 1) {
if (playerCommand.startsWith("tele")) {
try{
String[] args = playerCommand.split(" ");
c.teleportToX = Integer.parseInt(args[1]);
c.teleportToY = Integer.parseInt(args[2]);
} catch(Exception e) {
c.sendMessage("Wrong Syntax! Use as ::tele 3400,3500");
}
}
if (playerCommand.startsWith("xteleto")) {
try {
String otherPName = playerCommand.substring(8);
int otherPIndex = PlayerHandler.getPlayerID(otherPName);
if (otherPIndex != -1) {
Client p = (Client) Server.playerHandler.players[otherPIndex];
c.teleportToX = p.absX;
c.teleportToY = p.absY;
c.heightLevel = p.heightLevel;
c.updateRequired = true;
c.appearanceUpdateRequired = true;
p.updateRequired = true;
p.appearanceUpdateRequired = true;
c.sendMessage("You teleport to " + p.playerName);
}
} catch (Exception e) {
c.sendMessage("Try entering a name you want to tele to..");
}
}
if (playerCommand.startsWith("kick")) {
try {
String kicked = playerCommand.substring(5);
int kick = PlayerHandler.getPlayerID(kicked);
if (kick != -1) {
Client p = (Client) Server.playerHandler.players[kick];
c.sendMessage("You have successfully kicked "+kicked+".");
p.disconnected = true;
c.updateRequired = true;
c.appearanceUpdateRequired = true;
} else {
c.sendMessage("The name you have tried to kick, does not exist or is not online.");
}
} catch(Exception e) {
c.sendMessage("Try entering a name you want to kick.");
}
}
if (playerCommand.startsWith("jail")) {
try {
String otherPName = playerCommand.substring(5);
int otherPIndex = PlayerHandler.getPlayerID(otherPName);
if (otherPIndex != -1) {
Client p = (Client) Server.playerHandler.players[otherPIndex];
p.teleportToX = 3109;
p.teleportToY = 3514;
p.heightLevel = 0;
c.sendMessage("You have jailed "+p.playerName+".");
p.sendMessage("You have been jailed by "+ c.playerName);
c.updateRequired = true;
c.appearanceUpdateRequired = true;
p.updateRequired = true;
p.appearanceUpdateRequired = true;
} else {
c.sendMessage("The name doesnt exist.");
}
} catch (Exception e) {
c.sendMessage("Try entering a name you want to jail.");
}
}
if (playerCommand.startsWith("unjail")) {
try {
String otherPName = playerCommand.substring(7);
int otherPIndex = PlayerHandler.getPlayerID(otherPName);
if (otherPIndex != -1) {
Client p = (Client) Server.playerHandler.players[otherPIndex];
p.teleportToX = 3087;
p.teleportToY = 3496;
p.heightLevel = 0;
c.sendMessage("You have unjailed "+p.playerName+".");
p.sendMessage("You have been unjailed by "+ c.playerName);
c.updateRequired = true;
c.appearanceUpdateRequired = true;
p.updateRequired = true;
p.appearanceUpdateRequired = true;
} else {
c.sendMessage("The name doesnt exist.");
}
} catch (Exception e) {
c.sendMessage("Try entering a name you want to unjail.");
}
}
if (playerCommand.startsWith("xteletome")) {
try {
String otherPName = playerCommand.substring(10);
int otherPIndex = PlayerHandler.getPlayerID(otherPName);
if (otherPIndex != -1) {
Client p = (Client) Server.playerHandler.players[otherPIndex];
p.teleportToX = c.getX();
p.teleportToY = c.getY();
p.heightLevel = c.heightLevel;
c.sendMessage("You have teleported "+p.playerName+" to you.");
p.sendMessage("You have been teleported to "+ c.playerName);
c.updateRequired = true;
c.appearanceUpdateRequired = true;
p.updateRequired = true;
p.appearanceUpdateRequired = true;
} else {
c.sendMessage("The name doesnt exist.");
}
} catch (Exception e) {
c.sendMessage("Try entering a name you want to tele to you.");
}
}
if(c.playerRights >= 2) {
if (playerCommand.startsWith("ipban")) { // use as ::ipban name
try {
String playerToBan = playerCommand.substring(6);
for(int i = 0; i < Config.MAX_PLAYERS; i++) {
if(Server.playerHandler.players[i] != null) {
if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(playerToBan)) {
Connection.addIpToBanList(Server.playerHandler.pla yers[i].connectedFrom);
Connection.addIpToFile(Server.playerHandler.player s[i].connectedFrom);
c.sendMessage("You have IP banned the user: "+Server.playerHandler.players[i].playerName+" with the host: "+Server.playerHandler.players[i].connectedFrom);
Server.playerHandler.players[i].disconnected = true;
}
}
}
} catch(Exception e) {
c.sendMessage("Player Must Be Offline.");
}
}
if(c.playerRights >= 3) {
if (playerCommand.equalsIgnoreCase("switch")) {
if(c.playerMagicBook == 1) {
c.sendMessage("You switch to modern magic.");
c.setSidebarInterface(6, 1151);
c.playerMagicBook = 0;
} else {
c.sendMessage("You switch to ancient magic.");
c.setSidebarInterface(6, 12855);
c.playerMagicBook = 1;
}
}
if (playerCommand.startsWith("spec")) {
c.specAmount += 100;
}
if (playerCommand.equalsIgnoreCase("barrows")) {
c.getPA().movePlayer(3564,3288,0);
c.getItems().addItem(952, 1);
}
if (playerCommand.equalsIgnoreCase("reload")) {
c.sendMessage("Reloading scripts...");
try {
ScriptManager.loadScripts();
c.sendMessage("Success!");
} catch (IOException e) {
c.sendMessage("Failed!");
e.printStackTrace();
}
}
if (playerCommand.equalsIgnoreCase("incombat")) {
if(c.inCombat) {
c.sendMessage("You are in combat.");
} else {
c.sendMessage("You are not in combat.");
}
}
if (playerCommand.equalsIgnoreCase("mypos")) {
c.sendMessage("X: "+c.absX);
c.sendMessage("Y: "+c.absY);
}
if(playerCommand.startsWith("height")) {
String[] args = playerCommand.split(" ");
int a = Integer.parseInt(args[1]);
c.heightLevel = a;
c.updateRequired = true;
}
if (playerCommand.startsWith("maxrange")) {
c.sendMessage("Max hit = " + Integer.toString(c.getCombat().calculateRangeMaxHi t()));
}
if (playerCommand.startsWith("maxmelee")) {
c.sendMessage("Max hit = " + Integer.toString(c.getCombat().calculateMeleeMaxHi t()));
}
if (playerCommand.startsWith("update")) {
String[] args = playerCommand.split(" ");
int a = Integer.parseInt(args[1]);
PlayerHandler.updateSeconds = a;
PlayerHandler.updateAnnounced = false;
PlayerHandler.updateRunning = true;
PlayerHandler.updateStartTime = System.currentTimeMillis();
}
if (playerCommand.startsWith("interface")) {
try {
String[] args = playerCommand.split(" ");
int a = Integer.parseInt(args[1]);
c.getPA().showInterface
;
}catch(Exception e) {
c.sendMessage("::interface ####");
}
}
if (playerCommand.startsWith("gfx")) {
try {
int id = Integer.parseInt(playerCommand.substring(4));
c.gfx100(id);
c.sendMessage("Testing GFX: ["+id+"].");
} catch (Exception e) {
c.sendMessage("You have entered an invalid gfx id, try again.");
}
}
if(playerCommand.startsWith("pkhead")) {
try {
String[] args = playerCommand.split(" ");
int a = Integer.parseInt(args[1]);
c.headIconPk = a;
c.getPA().requestUpdates();
}catch(Exception e) {
c.sendMessage(":
khead ####");
}
}
if(playerCommand.startsWith("bhhead")) {
try {
String[] args = playerCommand.split(" ");
int a = Integer.parseInt(args[1]);
c.bountyIcon = a;
c.getPA().requestUpdates();
}catch(Exception e) {
c.sendMessage(":
khead ####");
}
}
if(playerCommand.startsWith("hinthead")) {
try {
String[] args = playerCommand.split(" ");
int a = Integer.parseInt(args[1]);
c.headIconHints = a;
c.getPA().requestUpdates();
}catch(Exception e) {
c.sendMessage(":
khead ####");
}
}
if(playerCommand.startsWith("head")) {
try {
String[] args = playerCommand.split(" ");
int a = Integer.parseInt(args[1]);
c.headIcon = a;
c.getPA().requestUpdates();
}catch(Exception e) {
c.sendMessage(":
khead ####");
}
}
if (playerCommand.startsWith("tele")) {
try{
String[] args = playerCommand.split(" ");
c.teleportToX = Integer.parseInt(args[1]);
c.teleportToY = Integer.parseInt(args[2]);
} catch(Exception e) {
c.sendMessage("Wrong Syntax! Use as ::tele 3400,3500");
}
}
if (playerCommand.equalsIgnoreCase("empty")) {
c.getItems().removeAllItems();
}
if (playerCommand.equalsIgnoreCase("bank")) {
c.getPA().openUpBank();
}
if (playerCommand.equalsIgnoreCase("heal")) {
c.playerLevel[3] = 99;
c.getPA().refreshSkill(3);
}
if (playerCommand.equalsIgnoreCase("runes")) {
for(int r = 554; r < 567; r++) {
c.getItems().addItem(r, 1000);
}
}
if (playerCommand.equalsIgnoreCase("master")) {
for (int i = 0; i < 21; i++) {
c.playerLevel[i] = 99;
c.playerXP[i] = c.getPA().getXPForLevel(100);
c.getPA().refreshSkill(i);
}
c.getPA().requestUpdates();
}
if (playerCommand.equalsIgnoreCase("hints")) {
c.headIconHints = 2;
c.getPA().requestUpdates();
}
if (playerCommand.equalsIgnoreCase("pk")) {
c.headIconPk = 1;
c.getPA().requestUpdates();
}
if(playerCommand.startsWith("npc")) {
//Server.npcHandler.spawnNpc(c, npcId, c.absX, c.absY, -1, 0, 120, 7, 70, 70, true);
try {
int newNPC = Integer.parseInt(playerCommand.substring(4));
if(newNPC > 0) {
//Server.npcHandler.spawnANPC(newNPC, c.absX, c.absY, c.heightLevel);
Server.npcHandler.spawnNpc(c, newNPC, c.absX, c.absY, 0, 0, 120, 7, 70, 70, false, false);
c.sendMessage("You spawn a Npc.");
} else {
c.sendMessage("No such NPC.");
}
} catch(Exception e) {
}
}
if (playerCommand.startsWith("pickup")) {
try {
String[] args = playerCommand.split(" ");
if (args.length == 3) {
int newItemID = Integer.parseInt(args[1]);
int newItemAmount = Integer.parseInt(args[2]);
if ((newItemID <= 20000) && (newItemID >= 0)) {
c.getItems().addItem(newItemID, newItemAmount);
} else {
c.sendMessage("No such item.");
}
} else {
c.sendMessage("Use as :
ickup 995 200");
}
} catch(Exception e) {
}
}
if (playerCommand.startsWith("anim")) {
String[] args = playerCommand.split(" ");
c.startAnimation(Integer.parseInt(args[1]));
c.getPA().requestUpdates();
}
}
}
}
}
}