public static void SetFame(MartialClient c, InCommand cmd) { if(cmd.commandArgs == null) { StaticPackets.sendSystemMessageToClient(c, 1, "/setfame [name] [amount]"); return; } Character player = WMap.Instance.findPlayerByName(cmd.commandArgs[0]); if(player == null) { StaticPackets.sendSystemMessageToClient(c, 1, "Wrong player name has been given."); return; } int fameAmount; if(!Int32.TryParse(cmd.commandArgs[1], out fameAmount)) { StaticPackets.sendSystemMessageToClient(c, 1, "Parameters must be values!"); return; } if(fameAmount < 0 || fameAmount > 2147483647) { StaticPackets.sendSystemMessageToClient(c, 1, "Setfame range goes from 0 - 2147483647."); return; } StaticPackets.setCharacterFame(player, fameAmount); StaticPackets.sendSystemMessageToClient(c, 1, player.getName() + "'s fame has been set up to: " + fameAmount + "!"); return; }
public static void SetMHP(MartialClient c, InCommand cmd) { if(cmd.commandArgs.Length != 2) { StaticPackets.sendSystemMessageToClient(c, 1, "/setmhp [name] [amount]"); return; } Character player = WMap.Instance.findPlayerByName(cmd.commandArgs[0]); if(player == null) { StaticPackets.sendSystemMessageToClient(c, 1, "Player wasn't found."); return; } int amount = -1; if(!Int32.TryParse(cmd.commandArgs[1], out amount)) { StaticPackets.sendSystemMessageToClient(c, 1, "Server wasn't able to parse amount of MHPoints."); return; } player.getAccount().MHPoints = amount; StaticPackets.setMHPoints(player.getAccount().mClient, amount); return; }
public static void SetMHP(MartialClient c, InCommand cmd) { if (cmd.commandArgs.Length != 2) { StaticPackets.sendSystemMessageToClient(c, 1, "/setmhp [name] [amount]"); return; } Character player = WMap.Instance.findPlayerByName(cmd.commandArgs[0]); if (player == null) { StaticPackets.sendSystemMessageToClient(c, 1, "Player wasn't found."); return; } int amount = -1; if (!Int32.TryParse(cmd.commandArgs[1], out amount)) { StaticPackets.sendSystemMessageToClient(c, 1, "Server wasn't able to parse amount of MHPoints."); return; } player.getAccount().MHPoints = amount; StaticPackets.setMHPoints(player.getAccount().mClient, amount); return; }
public static void SetLevel(MartialClient c, InCommand cmd) { if(cmd.commandArgs.Length < 2) { StaticPackets.sendSystemMessageToClient(c, 1, "/setlevel [name] [amount]"); return; } Character player = WMap.Instance.findPlayerByName(cmd.commandArgs[0]); if(player == null) { StaticPackets.sendSystemMessageToClient(c, 1, "Wrong player name has been given."); return; } byte level; if(!Byte.TryParse(cmd.commandArgs[1], out level)) { StaticPackets.sendSystemMessageToClient(c, 1, "Parameters must be values!"); return; } if(level < 0 || level > 255) { StaticPackets.sendSystemMessageToClient(c, 1, "Setlevel range goes from 0 - 255."); return; } StaticPackets.setCharacterLevel(player, level); StaticPackets.sendSystemMessageToClient(c, 1, player.getName() + "'s level has been set up to: " + level + "!"); return; }
public static void SetFame(MartialClient c, InCommand cmd) { if (cmd.commandArgs == null) { StaticPackets.sendSystemMessageToClient(c, 1, "/setfame [name] [amount]"); return; } Character player = WMap.Instance.findPlayerByName(cmd.commandArgs[0]); if (player == null) { StaticPackets.sendSystemMessageToClient(c, 1, "Wrong player name has been given."); return; } int fameAmount; if (!Int32.TryParse(cmd.commandArgs[1], out fameAmount)) { StaticPackets.sendSystemMessageToClient(c, 1, "Parameters must be values!"); return; } if (fameAmount < 0 || fameAmount > 2147483647) { StaticPackets.sendSystemMessageToClient(c, 1, "Setfame range goes from 0 - 2147483647."); return; } StaticPackets.setCharacterFame(player, fameAmount); StaticPackets.sendSystemMessageToClient(c, 1, player.getName() + "'s fame has been set up to: " + fameAmount + "!"); return; }
public static void SetLevel(MartialClient c, InCommand cmd) { if (cmd.commandArgs.Length < 2) { StaticPackets.sendSystemMessageToClient(c, 1, "/setlevel [name] [amount]"); return; } Character player = WMap.Instance.findPlayerByName(cmd.commandArgs[0]); if (player == null) { StaticPackets.sendSystemMessageToClient(c, 1, "Wrong player name has been given."); return; } byte level; if (!Byte.TryParse(cmd.commandArgs[1], out level)) { StaticPackets.sendSystemMessageToClient(c, 1, "Parameters must be values!"); return; } if (level < 0 || level > 255) { StaticPackets.sendSystemMessageToClient(c, 1, "Setlevel range goes from 0 - 255."); return; } StaticPackets.setCharacterLevel(player, level); StaticPackets.sendSystemMessageToClient(c, 1, player.getName() + "'s level has been set up to: " + level + "!"); return; }
public static void ListCommands(MartialClient c, InCommand cmd) { StaticPackets.sendSystemMessageToClient(c, 1, "Available commands: "); foreach (string cmdName in CommandProcessor.getCommandHandlers().Keys) { StaticPackets.sendSystemMessageToClient(c, 1, cmdName); } }
public static void Announce(MartialClient c, InCommand cmd) { if(cmd.commandArgs == null) { StaticPackets.sendSystemMessageToClient(c, 1, "/announce [text]"); return; } string announcing = string.Join(" ", cmd.commandArgs); StaticPackets.sendWorldAnnounce(announcing); return; }
public static void Announce(MartialClient c, InCommand cmd) { if (cmd.commandArgs == null) { StaticPackets.sendSystemMessageToClient(c, 1, "/announce [text]"); return; } string announcing = string.Join(" ", cmd.commandArgs); StaticPackets.sendWorldAnnounce(announcing); return; }
public static void ItemCreate(MartialClient c, InCommand cmd) { if (cmd.commandArgs == null) { StaticPackets.sendSystemMessageToClient(c, 1, "/item [itemid] [*amount]"); return; } if (c.getAccount().activeCharacter == null) { Logger.LogCheat(Logger.HackTypes.NullActive, c, "Null activity in command handler"); c.Close(); return; } Character chr = c.getAccount().activeCharacter; int itemID = 0; Int32.TryParse(cmd.commandArgs[0], out itemID); if (itemID < 200000000 || itemID > 299999999) { StaticPackets.sendSystemMessageToClient(c, 1, "Item ID range goes from 200.000.000 - 299.999.999."); return; } if (ItemDataCache.Instance.getItemData(itemID).getID() == 0) { StaticPackets.sendSystemMessageToClient(c, 1, "Selected item wasn't found."); return; } short itemQuantity = 1; Int16.TryParse(cmd.commandArgs[1], out itemQuantity); if (itemQuantity > short.MaxValue) { StaticPackets.sendSystemMessageToClient(c, 1, "Items amount, can't be bigger than 100!"); return; } c.WriteRawPacket(ItemPackets.createDroppedItem(WMap.Instance.items.Count, chr.getPosition()[0], chr.getPosition()[1], itemID, itemQuantity)); StaticPackets.sendSystemMessageToClient(c, 1, "Item of ID: " + itemID + "|" + WMap.Instance.items.Count + "|" + itemQuantity + ", has been created at coords: "); StaticPackets.sendSystemMessageToClient(c, 1, chr.getPosition()[0] + ":" + chr.getPosition()[1] + ":" + chr.getMap() + "!"); WMap.Instance.items.Add(WMap.Instance.items.Count, new Item(itemID, itemQuantity)); return; }
public static void ItemCreate(MartialClient c, InCommand cmd) { if(cmd.commandArgs == null) { StaticPackets.sendSystemMessageToClient(c, 1, "/item [itemid] [*amount]"); return; } if(c.getAccount().activeCharacter == null) { Logger.LogCheat(Logger.HackTypes.NullActive, c, "Null activity in command handler"); c.Close(); return; } Character chr = c.getAccount().activeCharacter; int itemID = 0; Int32.TryParse(cmd.commandArgs[0], out itemID); if(itemID < 200000000 || itemID > 299999999) { StaticPackets.sendSystemMessageToClient(c, 1, "Item ID range goes from 200.000.000 - 299.999.999."); return; } if(ItemDataCache.Instance.getItemData(itemID).getID() == 0) { StaticPackets.sendSystemMessageToClient(c, 1, "Selected item wasn't found."); return; } short itemQuantity = 1; Int16.TryParse(cmd.commandArgs[1], out itemQuantity); if(itemQuantity > short.MaxValue) { StaticPackets.sendSystemMessageToClient(c, 1, "Items amount, can't be bigger than 100!"); return; } c.WriteRawPacket(ItemPackets.createDroppedItem(WMap.Instance.items.Count, chr.getPosition()[0], chr.getPosition()[1], itemID, itemQuantity)); StaticPackets.sendSystemMessageToClient(c, 1, "Item of ID: " + itemID + "|" + WMap.Instance.items.Count + "|" + itemQuantity + ", has been created at coords: "); StaticPackets.sendSystemMessageToClient(c, 1, chr.getPosition()[0] + ":" + chr.getPosition()[1] + ":" + chr.getMap() + "!"); WMap.Instance.items.Add(WMap.Instance.items.Count, new Item(itemID, itemQuantity)); return; }
public static void Message(MartialClient c, InCommand cmd) { }
public void Post(InCommand command) { _buffers.QueueInCommand(command); }
bool ExecuteCommand(Command c) { c = SetFromToDirect(c); c = SetWarriorsToRushes(c); if (c.toType == Command.ToType.Direct && c.fromType == Command.FromType.Direct && c.warriorsType == Command.WarriorsType.Rushes) { c.from.SendUnit(c.to); return(true); } return(false); Command SetFromToDirect(Command InCommand) { Command outCommand = (Command)InCommand.Clone(); List <Tuple <BasicCity, int> > paths = new List <Tuple <BasicCity, int> >(lp.ControlInfoForParts[this.PlayerId].Keys.Count); foreach (var fromCity in lp.ControlInfoForParts[this.PlayerId].Keys) { var currPath = fromCity.BuildOptimalPath(outCommand.to, out BasicCity real); if (real == outCommand.to) { paths.Add(new Tuple <BasicCity, int>(fromCity, currPath.Count)); } } if (paths.Count == 0) { return(InCommand); } int minId = 0; for (int i = 1; i < paths.Count; ++i) { if (paths[i].Item2 < paths[minId].Item2) { minId = i; } } outCommand.fromType = Command.FromType.Direct; outCommand.from = paths[minId].Item1; return(outCommand); } Command SetWarriorsToRushes(Command InCommand) { Command outCommand = (Command)InCommand.Clone(); if (outCommand.warriorsType == Command.WarriorsType.Count) { if (outCommand.warriors < outCommand.from.currWarriors) { ushort rushes = 1; while (GetSendByRushesCnt(outCommand.from, rushes) < outCommand.warriors) { ++rushes; } outCommand.warriorsType = Command.WarriorsType.Rushes; outCommand.warriors = rushes; } } return(outCommand); int GetSendByRushesCnt(BasicCity city, ushort rushesCnt) { ushort sendWarriors = 0, currWarriors = city.currWarriors; while (rushesCnt-- != 0) { sendWarriors += (ushort)Math.Round(currWarriors * city.sendPersent * city.atkPersent); currWarriors -= (ushort)(currWarriors * city.sendPersent); } return(sendWarriors); } } }
public void ProccesBytes(byte[] bytes) { Logger.Log("Proccessing"); while (!Encoding.ASCII.GetString(bytes).IsNullOrWhitespace()) { Logger.Log(System.Text.Encoding.ASCII.GetString(bytes.Take(4).ToArray())); for (int i = 0; i < 3; i++) { Logger.Log(bytes[i].ToString()); } Logger.Log("Checking header!"); if (bytes[0] != 0x43 || bytes[1] != 0x4D) { throw new Exception("Wrong header"); } Logger.Log("Header correct"); bytes = bytes.Skip(2).ToArray(); Data currentData = new Data(); byte side = bytes[1]; InCommand id = (InCommand)bytes[0]; bytes = bytes.Skip(2).ToArray(); switch (id) { case InCommand.Empty: Logger.Log("No command"); break; case InCommand.ResultsVirtual: Logger.Log("Main params"); currentData.Angles[0] = BitConverter.ToSingle(bytes, 0); bytes = bytes.Skip(4).ToArray(); for (int i = 0; i < 4; i++) { currentData.Quad[i] = BitConverter.ToSingle(bytes, 0); bytes = bytes.Skip(4).ToArray(); } currentData.Angles[1] = BitConverter.ToSingle(bytes, 0); bytes = bytes.Skip(4).ToArray(); currentData.Angles[2] = BitConverter.ToSingle(bytes, 0); bytes = bytes.Skip(4).ToArray(); break; case InCommand.InResultsCam: Logger.Log("Got 0x4D"); break; case InCommand.Acc: Logger.Log("Got acc"); currentData.Acc = BitConverter.ToSingle(bytes, 0); bytes = bytes.Skip(4).ToArray(); break; case InCommand.Vel: Logger.Log("Got vel"); currentData.Vel = BitConverter.ToSingle(bytes, 0); bytes = bytes.Skip(4).ToArray(); break; case InCommand.Osc: Logger.Log("Got osc"); currentData.Osc = BitConverter.ToSingle(bytes, 0); bytes = bytes.Skip(4).ToArray(); break; case InCommand.Dist: Logger.Log("Got dist"); currentData.Dist = BitConverter.ToSingle(bytes, 0); bytes = bytes.Skip(4).ToArray(); break; case InCommand.ClampsS: Logger.Log("Clamps_S"); currentData.ClampsS = BitConverter.ToSingle(bytes, 0); bytes = bytes.Skip(4).ToArray(); break; case InCommand.Clamps: Logger.Log("Clamps"); currentData.Clamps = BitConverter.ToSingle(bytes, 0); bytes = bytes.Skip(4).ToArray(); break; //IN_INFO, convert to hex case InCommand.Info: Logger.Log("Got info"); bytes = bytes.Skip(35).ToArray(); break; default: Logger.Log("Got unkown command: " + bytes[0]); break; } if (id == InCommand.ResultsVirtual) { switch (side) { case (byte)'L': leftData = currentData; break; case (byte)'R': rightData = currentData; break; } } //We need to skip CRC bytes = bytes.Skip(1).ToArray(); Logger.Log("After switch"); } }
public static void Warp(MartialClient c, InCommand cmd) { if (cmd.commandArgs.Length < 2) { StaticPackets.sendSystemMessageToClient(c, 1, "/goto [x] [y] [map] | [Mob|NPC|Player] [uID/name] | [map] true"); return; } if (c.getAccount().activeCharacter == null) { Logger.LogCheat(Logger.HackTypes.NullActive, c, "Null activity in command handler"); c.Close(); return; } Character chr = c.getAccount().activeCharacter; short goMap = -1; float goX = -1; float goY = -1; if (cmd.commandArgs.Length == 2) { switch (cmd.commandArgs[0].ToLower()) { case "npc": { int npcID = -1; if (!Int32.TryParse(cmd.commandArgs[1], out npcID)) { StaticPackets.sendSystemMessageToClient(c, 1, "Server wasn't able to parse NPC's ID."); return; } if (WMap.Instance.getNpcs().ElementAtOrDefault(npcID) == null) { StaticPackets.sendSystemMessageToClient(c, 1, "Server wasn't able to find NPC of ID " + npcID + "!"); return; } NPC npc = WMap.Instance.getNpcs()[npcID]; goMap = npc.getMap(); goX = npc.getPosition()[0]; goY = npc.getPosition()[1]; break; } /*case "mob": * { * int mobID = -1; * if(!Int32.TryParse(cmd.commandArgs[1], out mobID)) * { * StaticPackets.sendSystemMessageToClient(c, 1, "Server wasn't able to parse Mob's ID."); * return; * } * * Mob mob = WMap.Instance.getGrid(chr.getMap()).findMobByuID(mobID); * if(mob == null) * { * StaticPackets.sendSystemMessageToClient(c, 1, "Server wasn't able to find Mob of ID " + mobID + "!"); * return; * } * * goMap = mob.getMap(); * goX = mob.getPosition()[0]; * goY = mob.getPosition()[1]; * break; * }*/ case "player": { Character player = WMap.Instance.findPlayerByName(cmd.commandArgs[1]); if (player == null) { StaticPackets.sendSystemMessageToClient(c, 1, "Player wasn't found."); return; } goMap = player.getMap(); goX = player.getPosition()[0]; goY = player.getPosition()[1]; break; } default: { if (!MiscFunctions.IsNumeric(cmd.commandArgs[0]) || cmd.commandArgs[1] != "true" && !MiscFunctions.IsNumeric(cmd.commandArgs[1])) { StaticPackets.sendSystemMessageToClient(c, 1, "/goto [x] [y] [map] | [Mob|NPC|Player] [uID/name] | [map] true"); return; } Waypoint closestTown = null; short _desiredMap = -1; if (!Int16.TryParse(cmd.commandArgs[0], out _desiredMap)) { StaticPackets.sendSystemMessageToClient(c, 1, "Server wasn't able to parse your desired map's ID!"); return; } if (cmd.commandArgs[1] == "true") { closestTown = TownCoordsCache.Instance.getClosestWaypointForMap(_desiredMap, new Waypoint(0, 0)); if (closestTown == null) { StaticPackets.sendSystemMessageToClient(c, 1, "There's not any town on map " + _desiredMap + "!"); return; } } else if (MiscFunctions.IsNumeric(cmd.commandArgs[1])) { int _desiredTown = -1; if (!Int32.TryParse(cmd.commandArgs[1], out _desiredTown)) { StaticPackets.sendSystemMessageToClient(c, 1, "Server wasn't able to parse your desired town's index!"); return; } closestTown = TownCoordsCache.Instance.getWaypointAtIndexForMap(_desiredMap, _desiredTown); if (closestTown == null) { StaticPackets.sendSystemMessageToClient(c, 1, "There's not any town on map " + _desiredMap + " with index " + _desiredTown + "!"); return; } } goMap = Convert.ToInt16(cmd.commandArgs[0]); goX = closestTown.getX(); goY = closestTown.getY(); break; } } } else if (cmd.commandArgs.Length == 3) { foreach (string parser in cmd.commandArgs) { if (!MiscFunctions.IsNumeric(parser)) { StaticPackets.sendSystemMessageToClient(c, 1, "Parameters must be values!"); return; } } goMap = Convert.ToInt16(cmd.commandArgs[2]); goX = Convert.ToSingle(cmd.commandArgs[0]); goY = Convert.ToSingle(cmd.commandArgs[1]); } else { return; } CharacterFunctions.setPlayerPosition(c.getAccount().activeCharacter, goX, goY, goMap); return; }
public static void Warp(MartialClient c, InCommand cmd) { if(cmd.commandArgs.Length < 2) { StaticPackets.sendSystemMessageToClient(c, 1, "/goto [x] [y] [map] | [Mob|NPC|Player] [uID/name] | [map] true"); return; } if(c.getAccount().activeCharacter == null) { Logger.LogCheat(Logger.HackTypes.NullActive, c, "Null activity in command handler"); c.Close(); return; } Character chr = c.getAccount().activeCharacter; short goMap = -1; float goX = -1; float goY = -1; if(cmd.commandArgs.Length == 2) { switch(cmd.commandArgs[0].ToLower()) { case "npc": { int npcID = -1; if(!Int32.TryParse(cmd.commandArgs[1], out npcID)) { StaticPackets.sendSystemMessageToClient(c, 1, "Server wasn't able to parse NPC's ID."); return; } if(WMap.Instance.getNpcs().ElementAtOrDefault(npcID) == null) { StaticPackets.sendSystemMessageToClient(c, 1, "Server wasn't able to find NPC of ID " + npcID + "!"); return; } NPC npc = WMap.Instance.getNpcs()[npcID]; goMap = npc.getMap(); goX = npc.getPosition()[0]; goY = npc.getPosition()[1]; break; } /*case "mob": { int mobID = -1; if(!Int32.TryParse(cmd.commandArgs[1], out mobID)) { StaticPackets.sendSystemMessageToClient(c, 1, "Server wasn't able to parse Mob's ID."); return; } Mob mob = WMap.Instance.getGrid(chr.getMap()).findMobByuID(mobID); if(mob == null) { StaticPackets.sendSystemMessageToClient(c, 1, "Server wasn't able to find Mob of ID " + mobID + "!"); return; } goMap = mob.getMap(); goX = mob.getPosition()[0]; goY = mob.getPosition()[1]; break; }*/ case "player": { Character player = WMap.Instance.findPlayerByName(cmd.commandArgs[1]); if(player == null) { StaticPackets.sendSystemMessageToClient(c, 1, "Player wasn't found."); return; } goMap = player.getMap(); goX = player.getPosition()[0]; goY = player.getPosition()[1]; break; } default: { if(!MiscFunctions.IsNumeric(cmd.commandArgs[0]) || cmd.commandArgs[1] != "true" && !MiscFunctions.IsNumeric(cmd.commandArgs[1])) { StaticPackets.sendSystemMessageToClient(c, 1, "/goto [x] [y] [map] | [Mob|NPC|Player] [uID/name] | [map] true"); return; } Waypoint closestTown = null; short _desiredMap = -1; if(!Int16.TryParse(cmd.commandArgs[0], out _desiredMap)) { StaticPackets.sendSystemMessageToClient(c, 1, "Server wasn't able to parse your desired map's ID!"); return; } if(cmd.commandArgs[1] == "true") { closestTown = TownCoordsCache.Instance.getClosestWaypointForMap(_desiredMap, new Waypoint(0, 0)); if(closestTown == null) { StaticPackets.sendSystemMessageToClient(c, 1, "There's not any town on map " + _desiredMap + "!"); return; } } else if(MiscFunctions.IsNumeric(cmd.commandArgs[1])) { int _desiredTown = -1; if(!Int32.TryParse(cmd.commandArgs[1], out _desiredTown)) { StaticPackets.sendSystemMessageToClient(c, 1, "Server wasn't able to parse your desired town's index!"); return; } closestTown = TownCoordsCache.Instance.getWaypointAtIndexForMap(_desiredMap, _desiredTown); if(closestTown == null) { StaticPackets.sendSystemMessageToClient(c, 1, "There's not any town on map " + _desiredMap + " with index " + _desiredTown + "!"); return; } } goMap = Convert.ToInt16(cmd.commandArgs[0]); goX = closestTown.getX(); goY = closestTown.getY(); break; } } } else if(cmd.commandArgs.Length == 3) { foreach(string parser in cmd.commandArgs) if(!MiscFunctions.IsNumeric(parser)) { StaticPackets.sendSystemMessageToClient(c, 1, "Parameters must be values!"); return; } goMap = Convert.ToInt16(cmd.commandArgs[2]); goX = Convert.ToSingle(cmd.commandArgs[0]); goY = Convert.ToSingle(cmd.commandArgs[1]); } else return; CharacterFunctions.setPlayerPosition(c.getAccount().activeCharacter, goX, goY, goMap); return; }