public static byte[] CreateItem(Account acct, ushort itemGraphicId, ushort color, string name = "") { PacketWriter w = new PacketWriter(); w.WriteByte(1); w.WriteUShort(itemGraphicId); uint id = ServerGlobals.GetNextAvailableID(); w.WriteUInt32(id); ServerGlobals.CharacterIDsInUse.Add(id); w.WriteUShort(color); if (name != "") { w.WriteByte(1); w.WriteString(name); w.WriteByte(0x4A); w.WriteByte(0xFF); } else { w.WriteBytes(new byte[] { 0x00, 0xFF }); } w.WriteShort(0); w.WriteByte(1); w.WriteByte(0); // not equiped w.WriteShort(0); w.WriteUInt32(0); return(w.ToArray()); }
public void Init(short graphicID, bool isEquipable) { Begin = 0x01; GraphicID = graphicID; GameID = (int)ServerGlobals.GetNextAvailableID(); Color = 0x4A; // add id ? Enchants = new byte[] { 0x20 }; EndEnchants = 0xFF; IsEquipable = (byte)(isEquipable ? 0x01 : 0x00); }
public override byte[] Serialize(out uint itemid) { // we want to turn this item into a game packet from a item PacketWriter w = new PacketWriter(); w.WriteByte(1); w.WriteUShort(this.GraphicID); itemid = ServerGlobals.GetNextAvailableID(); // this.SetCharSlotID(itemid); //Console.WriteLine("(Serialize):Set item with graphic id of {0} to {1}", this.GraphicID, this.ID); w.WriteUInt32(itemid); w.WriteUShort(this.Color); if (!string.IsNullOrEmpty(this.Name)) { w.WriteByte(1); w.WriteString(Name); w.WriteByte(0x4A); w.WriteByte(0x00); w.WriteByte(0xFF); } else { w.WriteBytes(new byte[] { 0x00, 0x00, 0xFF }); } w.WriteByte(0x00); if (this.Location != null) { if (this.Location.CurrentRoom.RoomID < 65534) { w.WriteByte(0x01); w.WriteShort((short)this.Location.CurrentRoom.RoomID); } else { w.WriteByte(0x02); w.WriteUInt32(this.Location.CurrentRoom.RoomID); } w.WriteUShort(this.Location.X); w.WriteUShort(this.Location.Y); w.WriteShort(0x01); } else { w.WriteByte(0x00); // if this has a value, than item is in a room } w.WriteByte(0x01); w.WriteByte((byte)(this.isEquipable ? 1:0)); // not equiped w.WriteShort(0); // hmm ? stats ? w.WriteShort(0); // hmm ? //w.WriteShort(0); return(w.GetRawPacket()); }
public void AddDoor(ushort graphicID, ushort atLocX, ushort atLocY, ushort atFace, uint doorExit, ushort exitX, ushort exitY) { Door d = new Door(); d.ExitRoom = doorExit; d.Location = new RoomLocation(this.RoomID, atLocX, atLocY, atFace); d.Location.CurrentRoom = this; d.ExitWalkToX = exitX; d.ExitWalkToY = exitY; d.GraphicID = graphicID; d.GameID = ServerGlobals.GetNextAvailableID(); this.RoomsIDsInUse.Add(d.GameID); d.IsOpen = false; // default closed this.Items.Add(d); }
public override byte[] Serialize(out uint mobileID) { PacketWriter w = new PacketWriter(); w.WriteByte(0x01); w.WriteUShort(this.GraphicID); mobileID = ServerGlobals.GetNextAvailableID(); this.GameID = mobileID; w.WriteUInt32(this.GameID); // Spells w.WriteUShort(0x00); w.WriteByte(0xFF); w.WriteBytes(new byte[] { 0x00, 0x0C, 0x08 }); w.WriteByte(this.Girth); w.WriteByte(this.Height); w.WriteByte(0x01); w.WriteShort(0x00); // 3 more bytes here w.WriteBytes(new byte[3]); w.WriteInt32(this.CurrentHitPoints); w.WriteInt32(this.MaxHitPoints); // w.WriteBytes(new byte[3]); not here if (this.Location.CurrentRoom.RoomID > 65534) { w.WriteByte(0x01); w.WriteShort((short)this.Location.CurrentRoom.RoomID); } else { w.WriteByte(0x02); w.WriteUInt32(this.Location.CurrentRoom.RoomID); } w.WriteUShort(this.Location.X); w.WriteUShort(this.Location.Y); w.WriteUShort(this.Location.Facing); // always south // now inventory // w.WriteUShort(0x00); // skin color ? //w.WriteByte(0x00); // w.WriteBytes(new byte[7]); // w.WriteByte(0xFF); w.WriteUShort(0x02); w.WriteUInt32(0x00); w.WriteShort(0x00); w.WriteByte(0x00); return(w.GetRawPacket()); }
public static Door FromCode(ushort graphicID, uint roomNumber, ushort LocX, ushort LocY, uint exitRoomNumber, ushort exitX, ushort exitY, Room inRoom, bool isOpen = false) { Door d = new Door(); d.GraphicID = graphicID; d.GameID = ServerGlobals.GetNextAvailableID(); d.IsContainer = isOpen; d.Location = new RoomLocation(roomNumber, LocX, LocY, 0); inRoom.RoomsIDsInUse.Add(d.GameID); d.Location.CurrentRoom = inRoom; d.ExitRoom = exitRoomNumber; d.ExitWalkToX = exitX; d.ExitWalkToY = exitY; d.LookAt = "You see a door."; return(d); }
public static byte[] WrapCloud(Account a, short graphicid, out uint id) { PacketWriter wrap = new PacketWriter(); wrap.WriteByte(0x3F); // wrapped animation #region Object PacketWriter ob = new PacketWriter(); // now the object ob.WriteByte(0x01); ob.WriteShort(graphicid); uint newid = ServerGlobals.GetNextAvailableID(); id = newid; ob.WriteUInt32(id); ob.WriteBytes(new byte[3]); ob.WriteShort(0xFF); // Now room stuff if (a.CurrentCharacter.Location.CurrentRoom.RoomID < 65534) { ob.WriteByte(0x01); ob.WriteShort((short)a.CurrentCharacter.Location.CurrentRoom.RoomID); } else { ob.WriteByte(0x02); ob.WriteUInt32(a.CurrentCharacter.Location.CurrentRoom.RoomID); } ob.WriteUShort(a.CurrentCharacter.Location.X); ob.WriteUShort(a.CurrentCharacter.Location.Y); ob.WriteUShort(a.CurrentCharacter.Location.Facing); ob.WriteBytes(new byte[5]); ob.WriteByte(0xFF); #endregion byte[] obp = ob.GetRawPacket(); wrap.WriteShort((short)obp.Length); wrap.WriteUInt32(0x00); wrap.WriteBytes(obp); return(wrap.GetRawPacket()); }
public override byte[] Serialize(out uint id) { id = ServerGlobals.GetNextAvailableID(); this.GameID = id; Packets.PacketWriter w = new Packets.PacketWriter(); w.WriteByte(0x01); w.WriteUShort(this.GraphicID); w.WriteUInt32(this.GameID); w.WriteUShort(this.Color); // color if (string.IsNullOrEmpty(this.Name)) { w.WriteByte(0x00); // 1 here if name follows, then followed by 2 bytes with length of naem } else { w.WriteByte(0x01); w.WriteString(this.Name); // prefixes the string with a short length } // right after name, if this item is engraved with a custom name // the spell byte is 0x4A if (!string.IsNullOrEmpty(this.Name)) { w.WriteByte(0x4A); } else { w.WriteByte(0x00); } // identified, added later ? yes // how to handle buffs ? if (this.Enchantments.Count == 0) { w.WriteUShort(0x00); } else { foreach (byte b in this.Enchantments) { w.WriteByte(b); //Console.WriteLine("Wrote {0} for {1}.", b.ToString("X2"), this.GameID); } } w.WriteByte(0xFF); // buff end w.WriteByte(0x00); // i do not know if this byte holds a value // Roomlocation, if in a room #region Room and Location bytes if (this.Location == null) { w.WriteByte(0x00); // no location } else { if (this.Location.CurrentRoom != null) { if (this.Location.CurrentRoom.RoomID <= 65535) { w.WriteByte(0x01); w.WriteUShort((ushort)this.Location.CurrentRoom.RoomID); } else { w.WriteByte(0x02); w.WriteUInt32(this.Location.CurrentRoom.RoomID); } w.WriteUShort(this.Location.X); w.WriteUShort(this.Location.Y); w.WriteUShort(this.Location.Facing); } else { w.WriteByte(0x00); // we do not know what happened, a locations room should never be null } } // Ok locations done #endregion int i = this.IsInventoryItem ? 1 : 0; w.WriteByte((byte)i); // Not sure most items have this int e = this.Equipped ? 1 : 0; w.WriteByte((byte)e); w.WriteByte(0x00); // Do not know // Starts info for containers if (this.IsContainer) { w.WriteShort((short)this.ContainedItems.Count); // Followed by items contained } else { w.WriteShort(0x00); } // w.WriteByte(0x00); w.WriteUInt32(0x00); return(w.GetRawPacket()); }
public virtual MemoryStream ToStream() { MemoryStream _stream = new MemoryStream(); BinaryWriter _writer = new BinaryWriter(_stream); _writer.Write((byte)0x01); _writer.Write(GraphicID); _writer.Write(GameID); if (this is GameMobile == false) { _writer.Write(Color); } // empty byte here ? _writer.Write((byte)Name.Length > 0); if (this is GameItem) { // Custom Engraved name ? if (!string.IsNullOrEmpty(Name)) { _writer.Write(LengthPrefixedString(Name)); } } if (this is GameCharacter) { _writer.Write((byte)0x00); _writer.Write((byte)0x53); _writer.Write((byte)0x54); } foreach (byte a in affectedStates) { _writer.Write(a); } _writer.Write((byte)0xFF); if (Value == 0) { _writer.Write((byte)0x00); // Money section } else if (Value < 0xFFFF) { _writer.Write((byte)0x01); _writer.Write((ushort)Value); } else { _writer.Write((byte)0x02); _writer.Write(Value); } if (this is GameMobile || this is GameCharacter) { // Now only NPC's need this data // Mobs do not _writer.Write(XSpeed); //0C _writer.Write(YSpeed); // 08 _writer.Write(Width); _writer.Write(Height); _writer.Write(Profession); _writer.Write(Race); _writer.Write(Gender); _writer.Write(LengthPrefixedString(Name)); _writer.Write(Peaceful); _writer.Write(CurrentHealth); _writer.Write(MaximumHealth); } if (Location == null) { _writer.Write((byte)0x00); // isinroom } else { byte roomStatus = 0x00; //if (!Location.DoScaler) roomStatus |= 0x10; if (Location.RoomNumber <= 0xFFFF) { roomStatus |= 0x01; } else { roomStatus |= 0x02; } _writer.Write(roomStatus); if (Location.RoomNumber <= 0xFFFF) { _writer.Write((ushort)Location.RoomNumber); } else { _writer.Write(Location.RoomNumber); } _writer.Write(Location.X); _writer.Write(Location.Y); _writer.Write(Location.Facing); } if (this is GameCarryable) { GameCarryable o = this as GameCarryable; _writer.Write(o.isVisible); } else if (this is GameMobile == false) { _writer.Write((byte)0x00); } if (this is GameWeapon) { GameWeapon o = this as GameWeapon; _writer.Write(o.isWorn); } if (this is GameMobile) { // _writer.Write((byte)0x00); GameMobile o = this as GameMobile; if (o.Inventory != null) { _writer.Write((ushort)(o.Inventory.Count + 1)); _writer.Write((byte)0x01); _writer.Write((ushort)0x04); _writer.Write(ServerGlobals.GetNextAvailableID()); _writer.Write((ushort)0x00); _writer.Write((byte)0x00); _writer.Write((byte)0xFF); _writer.Write((ushort)0x00); _writer.Write((byte)0x00); } else { _writer.Write((ushort)0x00); } } if (Head != null) { _writer.Write(Head.ToArray()); // _writer.Write((byte)0x00); // wont appear on screen unless i do this } // 6 bytes after head start inventory if (this is GameWearable) { GameWearable o = this as GameWearable; _writer.Write(o.isWorn); } else { _writer.Write((byte)0x00); } if (this is GameDescribed) { GameDescribed o = this as GameDescribed; _writer.Write(o.isBook); } else { _writer.Write((byte)0x00); } if (this is GameContainer) { GameContainer o = this as GameContainer; _writer.Write((ushort)o.Items.Count); foreach (GameEntity e in o.Items) { _writer.Write(e.ToByteArray()); } } /* * // do we have a inventory ? * * if (this is GameMobile) * { * GameMobile o = this as GameMobile; * * if (o.Inventory != null) * { * * // _writer.Write((ushort)0x01);//(o.Inventory.Count)); // works if it has 00 inventory * _writer.Write((byte)0x01); * _writer.Write((ushort)0x04); * _writer.Write(ServerGlobals.GetNextAvailableID()); * _writer.Write((ushort)0x00); * _writer.Write((byte)0x00); * _writer.Write((byte)0xFF); * _writer.Write((ushort)0x00); * _writer.Write((byte)0x00); * } * } */ if (this is GameOpenable) { GameOpenable o = this as GameOpenable; _writer.Write(o.isOpen); } if (this is GameSwitch) { GameSwitch o = this as GameSwitch; _writer.Write(o.SwitchState); } byte lockState = 0; _writer.Write(lockState); byte sitState = 0; _writer.Write(sitState); _writer.Write(CanTalk); _writer.Write(IsInvisible); byte combatState = 0; _writer.Write(combatState); if (this is GameMobile) { // _writer.Write((ushort)0x00); // _writer.Write((byte)0xFF); } _stream.Position = 0; return(_stream); }
public override byte[] Serialize(out uint itemid) { // we want to turn this item into a game packet from a item PacketWriter w = new PacketWriter(); w.WriteByte(1); w.WriteUShort(this.GraphicID); itemid = ServerGlobals.GetNextAvailableID(); this.SetCharSlotID(itemid); //Console.WriteLine("(Serialize):Set item with graphic id of {0} to {1}", this.GraphicID, this.ID); w.WriteUInt32(itemid); w.WriteUShort(this.Color); if (!string.IsNullOrEmpty(this.Name)) { w.WriteByte(1); w.WriteString(this.Name); } if (this.Enchantments.Count == 0) { w.WriteUShort(0x00); } else { w.WriteByte(0x00); foreach (byte b in this.Enchantments) { w.WriteByte(b); } } w.WriteByte(0xFF); if (this.IsGoldOrMana) { w.WriteByte(0x02); w.WriteInt32(this.Value); } else { w.WriteByte(0x00); } if (this.IsInRoom) { if (this.Location.CurrentRoom.RoomID < 65534) { w.WriteByte(0x01); w.WriteShort((short)this.Location.CurrentRoom.RoomID); } else { w.WriteByte(0x02); w.WriteUInt32(this.Location.CurrentRoom.RoomID); } w.WriteUShort(this.Location.X); w.WriteUShort(this.Location.Y); w.WriteShort(0x01); } else { w.WriteByte(0x00); // if this has a value, than item is in a room } int i = this.IsInventoryItem ? 1 : 0; w.WriteByte((byte)i); int e = this.Equipped ? 1 : 0; w.WriteByte((byte)e); // not equiped w.WriteShort(0); // hmm ? stats ? w.WriteShort(0); // hmm ? //w.WriteShort(0); return(w.GetRawPacket()); }
public override byte[] Serialize(out uint itemid) { itemid = ServerGlobals.GetNextAvailableID(); this.GameID = itemid; Packets.PacketWriter w = new Packets.PacketWriter(); w.WriteByte(0x01); w.WriteUShort(this.GraphicID); w.WriteUInt32(this.GameID); w.WriteShort(0x73); // color if (string.IsNullOrEmpty(this.Name)) { w.WriteByte(0x00); // 1 here if name follows, then followed by 2 bytes with length of naem } else { w.WriteByte(0x01); w.WriteString(this.Name); // prefixes the string with a short length } if (this.Enchantments.Count == 0) { w.WriteShort(0x00); w.WriteByte(0x00); } else { int totalenchants = this.Enchantments.Count; // must be 2 0x00 and 1 buff, if the item only has 1 buff. if (totalenchants == 1) { w.WriteShort(0x00); w.WriteByte(this.Enchantments[0]); } else if (totalenchants == 2) { w.WriteByte(0x00); w.WriteByte(this.Enchantments[0]); w.WriteByte(this.Enchantments[1]); } else { foreach (byte b in this.Enchantments) { w.WriteByte(b); } } } w.WriteByte(0xFF); w.WriteByte(0x00); if (this.Location == null) { w.WriteByte(0x00); } // 0x01 if in a room with loc else { // Add room location if (this.Location.RoomNumber < 65534) { w.WriteByte(0x01); w.WriteUShort((ushort)this.Location.RoomNumber); } else { w.WriteByte(0x02); w.WriteUInt32(this.Location.RoomNumber); } w.WriteUShort(this.Location.X); w.WriteUShort(this.Location.Y); w.WriteUShort(this.Location.Facing); } w.WriteByte(0x01); // Not sure most items have this w.WriteByte((byte)(this.Equipped ? 1:0)); // Not sure on all this w.WriteByte(0x00); // dunno w.WriteShort((short)this.ContainedItems.Count); w.WriteByte(0x00); // w.WriteUShort(0x00); w.WriteUInt32(0x00); // w.WriteBytes(new byte[3]); //w.WriteByte(0x00); // items in backpack just after this ? return(w.GetRawPacket()); }
public void WaitForCommands() { string input = null; this.Start(); LoadScripts(); InitGameData(); while (!IsConsoleShuttingDown) { Console.ForegroundColor = ConsoleColor.Magenta; Console.Write("\n[{Realm World Server}] "); Console.ResetColor(); input = Console.ReadLine(); string[] args = input.Split(' '); switch (args[0].ToLower()) { case "sam": { int Index = 0; byte[] Data = new byte[] { 0x01, 0x02 }; UInt16 PacketLen = (UInt16)(Data[Index + 1] << 8 | Data[Index + 0]); Console.WriteLine(PacketLen.ToString()); } break; case "r": { string file = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "npcappear.txt"); string data = File.ReadAllText(file); data = RemoveWhitespace(data); Console.WriteLine(data); } break; case "1": { GameMobile m = new GameMobile(); m.GraphicID = 2204; m.GameID = ServerGlobals.GetNextAvailableID(); m.Width = 100; m.Height = 100; m.CurrentHealth = 12345; m.MaximumHealth = 12399; m.Location = new GameLocation(4056, 110, 110, 0); PacketWriter add = new PacketWriter(0x2A); add.WriteUInt32(2041); add.WriteUInt32(0); add.WriteInt32(-1); add.WriteUInt32(4056); add.WriteByte(0x40); PacketWriter wrap = new PacketWriter(); wrap.WriteShort((short)m.ToByteArray().Length); wrap.WriteUInt32(m.GameID); wrap.WriteBytes(m.ToByteArray()); add.WriteBytes(wrap.GetRawPacket()); byte[] packet = add.ToArray(); //Player.Socket.Send(ref packet); string fileLocation1 = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "bptest.txt"); File.WriteAllText(fileLocation1, BitConverter.ToString(packet)); Console.WriteLine("Sent Data"); } break; case "pass": { // we gonna hash passwords here man !! string password = string.Empty; if (args.Length >= 2) { // get the pass password = args[1]; string hash = RealmOffline.Accounts.PasswordHash.CreateHash(password); bool back = RealmOffline.Accounts.PasswordHash.ValidatePassword(password, hash); Console.WriteLine("We got password ({0}) and hash ({1}), they {2} match.", password, hash, back ? "do":" do not"); } } break; case "/mob": { if (args.Length >= 2) { short id = 0; if (short.TryParse(args[1], out id)) { MobileType type = MobileType.None; string name = BaseMobile.MobNameFromID(id, out type); Console.WriteLine("We found {0} for MobID {1}, its type is {2}", name, id, type); } } } break; case "/sm": { if (args.Length >= 3) { //1 = topic 2 on = message string topic = input.Split('|').First(); string msg = input.Split('|').Last(); Console.WriteLine("Topic ({0}) Message ({1})", topic, msg); } } break; case "terd": { BaseMobile.Init(); string[] m = BaseMobile.NonHumanoid.Select(x => x.Value).ToArray(); foreach (string c in m) { Console.WriteLine(c); } } break; case "fight": { // We want stats 2 stats 2 skills for attack //1 = str 2 = dex 3 = CS 4 = wepskill if (args.Length >= 5) { int str = 0; int dex = 0; int cs = 0; int wep = 0; if (int.TryParse(args[1], out str) && int.TryParse(args[2], out dex) && int.TryParse(args[3], out cs) && int.TryParse(args[4], out wep)) { Console.WriteLine("We got STR:({0}) DEX:({1}) CS:({2}) Wep:({3})", str, dex, cs, wep); // Lets formulate a chance int[] attacker = { str, dex, cs, wep }; int[] oppn = { 12, 12, 5, 5 }; // int hitpoints = 3000; // both have 3k hp int aper = attacker.Sum(); int oper = oppn.Sum(); Console.WriteLine("We start with {0}% for Attacker and {1}% for opponent.", aper, oper); } } } break; case "id": { if (args.Length == 2) { short id = 0; if (short.TryParse(args[1], out id)) { bool vali = Mob.IsValidID(id); Console.WriteLine("{0} {1} a valid id.", id, vali ? "is" : "is not"); } } } break; case "ts": { byte[] t = new byte[] { 0x21, 0xFF, 0x00, 0x9C }; Array.Reverse(t); double d = (double)BitConverter.ToInt32(t, 0); DateTime dt = MagicMail.UnixTimeStampToDateTime(d); Console.WriteLine(dt); } break; #region Account Creation and Deletion case "account": { string useage = "[Create an Account]\naccount create username password emailaddress secretword 3 \n" + "Last value is User Priv's\n" + "5 = Player, 4 = EventHost 3 = Guide 2 = Moderator 1 = Admin 0 = Owner \n" + "\n" + "[Delete an Account]\n" + "account delete username"; string createUseage = "[Create an Account]\naccount create username password emailaddress secretword 3 \n" + "Last value is User Priv's\n" + "5 = Player, 4 = EventHost 3 = Guide 2 = Moderator 1 = Admin 0 = Owner \n"; string deleteUsage = "[Delete an Account]\n" + "account delete username"; // create or delete if (args.Length > 2) { if (args[1].ToLower() == "create") { if (args[2].ToLower() == "help" || args[2] == string.Empty) { Console.WriteLine(createUseage); } else { string error = string.Empty; if (!MySqlManager.ValidateAccount(args, out error)) { if (error.Trim() != string.Empty) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(error); Console.ResetColor(); } } else { Console.WriteLine("Account {0} Created.", args[2]); } } } else if (args[1].ToLower() == "delete") { if (args.Length != 3) { Console.WriteLine(deleteUsage); } else { bool delete = MySqlManager.DeleteUserAccount(args[2].ToLower()); if (delete) { Console.WriteLine("Removed Account {0}.", args[2].ToLower()); } else { Console.WriteLine("Account {0} not found.", args[2].ToLower()); } } } else { Console.WriteLine("create or delete are the only valid options."); } } else { Console.WriteLine(useage); } // Ok this will be the command to create a new account /* * We need * 2: Username * 3: Password * 4: email address * 5: secret word * 6: Priv Level * string string string string int */ } #endregion break; case "spell": { List <Account> accts = ServerGlobals.GetAccountsInRoom(1310); Console.WriteLine("Total in room 1310 {0}", accts.Count); } break; case "online": { int online = 0; if (ServerGlobals.LoggedInAccounts != null) { online = ServerGlobals.LoggedInAccounts.Count; } Console.WriteLine("Currently {0} accounts online.", online); } break; case "clear": Console.Clear(); break; case "mem": { // Returns the current memory usage Console.WriteLine(MemoryUseDisplay); } break; case "q": { TestObject t = new TestObject(); string fileloc = Path.Combine(ServerGlobals.BaseDirectory, "TestSerialize.xml"); SerializedObject.Serialize(t, fileloc); TestObject t1 = SerializedObject.Deserialize <TestObject>(fileloc); Console.WriteLine(t1.ID); } break; case "touint16": { if (args.Length == 2) { // should be 4 letters / numbers string toParse = args[1].Trim(); // split string in half if (toParse.Length == 4) { string b1 = toParse.Substring(0, 2); string b2 = toParse.Substring(2); List <byte> blist = new List <byte>(); try { byte a; byte b; a = Byte.Parse(b1, NumberStyles.HexNumber); b = Byte.Parse(b2, NumberStyles.HexNumber); blist.Add(a); blist.Add(b); byte[] f1 = blist.ToArray(); ushort result = BitConverter.ToUInt16(f1, 0); Console.WriteLine("UInt16 result of bytes [{0}] [{1}] = {2}", BitConverter.ToString(new byte[] { a }), BitConverter.ToString(new byte[] { b }), result); } catch { Console.WriteLine("Bad Parse"); } } } } break; case "toint32": { if (args.Length == 2) { // should be 8 letters / numbers string toParse = args[1].Trim(); // split string in half if (toParse.Length == 8) { string b1 = toParse.Substring(0, 2); string b2 = toParse.Substring(2, 2); string b3 = toParse.Substring(4, 2); string b4 = toParse.Substring(6); List <byte> blist = new List <byte>(); try { byte a; byte b; byte c; byte d; a = Byte.Parse(b1, NumberStyles.HexNumber); b = Byte.Parse(b2, NumberStyles.HexNumber); c = Byte.Parse(b3, NumberStyles.HexNumber); d = Byte.Parse(b4, NumberStyles.HexNumber); blist.Add(a); blist.Add(b); blist.Add(c); blist.Add(d); byte[] f1 = blist.ToArray(); f1.Reverse(); Int32 result = BitConverter.ToInt32(f1, 0); Console.WriteLine("Int32 result of bytes [{0}] [{1}] [{2}] [{3}]= {4}", BitConverter.ToString(new byte[] { a }), BitConverter.ToString(new byte[] { b }), BitConverter.ToString(new byte[] { c }), BitConverter.ToString(new byte[] { d }), result); } catch { Console.WriteLine("Bad Parse"); } } } } break; case "touint32": { if (args.Length == 2) { // should be 8 letters / numbers string toParse = args[1].Trim(); // split string in half if (toParse.Length == 8) { string b1 = toParse.Substring(0, 2); string b2 = toParse.Substring(2, 2); string b3 = toParse.Substring(4, 2); string b4 = toParse.Substring(6); List <byte> blist = new List <byte>(); try { byte a; byte b; byte c; byte d; a = Byte.Parse(b1, NumberStyles.HexNumber); b = Byte.Parse(b2, NumberStyles.HexNumber); c = Byte.Parse(b3, NumberStyles.HexNumber); d = Byte.Parse(b4, NumberStyles.HexNumber); blist.Add(a); blist.Add(b); blist.Add(c); blist.Add(d); byte[] f1 = blist.ToArray(); f1.Reverse(); UInt32 result = BitConverter.ToUInt32(f1, 0); Console.WriteLine("Int32 result of bytes [{0}] [{1}] [{2}] [{3}]= {4}", BitConverter.ToString(new byte[] { a }), BitConverter.ToString(new byte[] { b }), BitConverter.ToString(new byte[] { c }), BitConverter.ToString(new byte[] { d }), result); } catch { Console.WriteLine("Bad Parse"); } } } } break; case "tobytes32": { // the next value is a number if (args.Length == 2) { int value = 0; if (int.TryParse(args[1], out value)) { byte[] conv = BitConverter.GetBytes(value); Console.WriteLine(BitConverter.ToString(conv)); } } } break; case "m2ushort": { // we have 2 bytes space 2 bytes 0 1 2 args or 3 total if (args.Length == 3) { try { string firstushort = args[1].Trim(); string secondushort = args[2].Trim(); string b1 = firstushort.Substring(0, 2); string b2 = firstushort.Substring(2, 2); string b3 = secondushort.Substring(0, 2); string b4 = secondushort.Substring(2, 2); List <byte> blist = new List <byte>(); byte a; byte b; byte c; byte d; a = Byte.Parse(b1, NumberStyles.HexNumber); b = Byte.Parse(b2, NumberStyles.HexNumber); c = Byte.Parse(b3, NumberStyles.HexNumber); d = Byte.Parse(b4, NumberStyles.HexNumber); byte[] fArg = { a, b }; byte[] sArg = { c, d }; ushort vone = BitConverter.ToUInt16(fArg, 0); ushort vtwo = BitConverter.ToUInt16(sArg, 0); Console.WriteLine("We got {0} and {1} for a difference of {2} or {3}", vone, vtwo, vone - vtwo, vtwo - vone); } catch { Console.WriteLine("Bad Parse"); } } } break; case "bc": { if (args.Length > 2) { // get the rest of this string StringBuilder build = new StringBuilder(); foreach (string s in args) { build.Append(s + " "); } string first = build.ToString().Remove(0, 3); string[] parse2 = first.Split(' '); // whats the color ? int color = -1; if (int.TryParse(parse2[0], out color)) { // Fix the last string again then build.Clear(); foreach (string s in parse2) { build.Append(s + " "); } string message = build.ToString().Remove(0, parse2[0].Length + 1); byte[] messagePacket = RealmPacketIO.BuildGossipPacket(color, message, "SERVER"); ServerGlobals.SendToAllClients(messagePacket); byte[] messagePacket2 = Packet.ChatPacket(color, 1, message, "SERVER"); ServerGlobals.SendToAllClients(messagePacket2); //Console.WriteLine(message); } else { Console.WriteLine("Bad color argument of {0}", parse2[0]); } } else { Console.WriteLine("Usage: bc 10 I want to say hi !!"); } } break; case "sta": { //string fileLocation = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "ServerPacket24Message.txt"); byte[] fake0 = RealmPacketIO.ServerMessageType1( "A Topic Test", "A Very Nice Message, we couldnt have much nicer, so dont be a dick!"); //RealmPacketIO.GetByteArrayFromFile(fileLocation); if (args.Length == 2) { if (args[1].ToLower() == "len") { Console.WriteLine("Message Packet Length {0}", BitConverter.ToString(BitConverter.GetBytes(fake0.Length - 8))); } } else { //ServerPacket24Message.txt ServerGlobals.SendToAllClients(fake0); } } break; case "sta2": { // ServerMessagePacket81.txt string fileLocation = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "ServerMessagePacket81.txt"); byte[] fake0 = RealmPacketIO.ServerMessageType2( "F**k you and da horse you roded in on foo!"); //RealmPacketIO.GetByteArrayFromFile(fileLocation); if (args.Length == 2) { if (args[1].ToLower() == "len") { Console.WriteLine("Message Packet Length {0}", BitConverter.ToString(BitConverter.GetBytes(fake0.Length - 8))); } } else { // ServerMessagePacket81.txt ServerGlobals.SendToAllClients(fake0); } } break; case "switch": { if (ServerGlobals.LoadFromSql) { ServerGlobals.LoadFromSql = false; Console.WriteLine("Loading from CharData.txt File."); } else { ServerGlobals.LoadFromSql = true; Console.WriteLine("Loading from MySql."); } } break; case "croom": { // Sends a packet derived from a filename in our debug dir // args[1] is the filename string fileLocation = string.Empty; if (args.Length != 2) { Console.WriteLine("Please supply a filename with extention."); } else { if (args[1].Trim() == "off") { RealmPacketIO.CustomRoomLoad = false; RealmPacketIO.CustomRoomFile = string.Empty; } else { fileLocation = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), args[1].Trim()); if (!File.Exists(fileLocation)) { Console.WriteLine("Unable to find file {0}", fileLocation); } else { RealmPacketIO.CustomRoomLoad = true; RealmPacketIO.CustomRoomFile = args[1].Trim(); Console.WriteLine("CustomFile Atrrib = {0} for file {1}", RealmPacketIO.CustomRoomLoad, RealmPacketIO.CustomRoomFile); } } } } break; case "to": { } break; case "itempacket": { for (int f = 0; f < 2001; f++) { Item i = new Item(); i.GraphicID = 1444; i.Color = 0x69; //uint id = 0; // byte[] r = i.Ser(); //byte[] item = i.Serialize(out id); Console.Write("\rItem:{0}. ", f); } } break; case "send": { // Sends a packet derived from a filename in our debug dir // args[1] is the filename string fileLocation = string.Empty; if (args.Length != 2) { Console.WriteLine("Please supply a filename with extention."); } else { fileLocation = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), args[1].Trim()); if (!File.Exists(fileLocation)) { Console.WriteLine("Unable to find file {0}", fileLocation); } else { byte[] fileToArray = null; try { fileToArray = RealmPacketIO.GetByteArrayFromFile(fileLocation); } catch (Exception ex) { Console.WriteLine(ex.Message); } if (fileToArray != null) { ServerGlobals.SendToAllClients(fileToArray); Console.WriteLine("Sent {0}", fileLocation); } } } } break; case "a": { } break; case "x": { //byte[] p = RealmPacketIO.Test; // ServerGlobals.SendToAllClients(p); } break; case "w": { /* * string fileLocation = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Lookat.txt"); * byte[] fake0 = RealmPacketIO.GetByteArrayFromFile(fileLocation); * byte[] len = BitConverter.GetBytes(fake0.Length); * Console.WriteLine(BitConverter.ToString(len)); */ } break; case "t": { // try to get this room Room found = null; if (ScriptResolver.ImportedRooms.TryGetRoom(213, out found)) { Console.WriteLine("Found room {0}", 213); Console.WriteLine(BitConverter.ToString(found.GetRoomPacket(3))); } } break; case "tt": { // messin wit commands if (ScriptResolver.ImportedCommands.Count == 0) { Console.WriteLine("WTF ?"); } else { Console.WriteLine("{0} commands found.", ScriptResolver.ImportedCommands.Count); foreach (Command cmd in ScriptResolver.ImportedCommands) { Console.WriteLine("Command Name {0}", cmd.CommandName); Command[] cmds = ScriptResolver.ImportedCommands.CommandsByPrefix('/'); Console.WriteLine("Commands by Prefix returned {0}", cmds.Length); } } } break; case "lmob": { string fileLocation = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "mobtest.txt"); byte[] fake0 = RealmPacketIO.GetByteArrayFromFile(fileLocation); byte[] len = BitConverter.GetBytes(fake0.Length); Console.WriteLine(BitConverter.ToString(len)); } break; case "mob": { string fileLocation = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "mobtest.txt"); byte[] fake0 = RealmPacketIO.GetByteArrayFromFile(fileLocation); Console.WriteLine("We have a packet {0} in length.", fake0.Length); ServerGlobals.SendToAllClients(fake0); } break; case "s": { string fileLocation = Path.Combine(ServerGlobals.BaseDirectory, "Test.log"); RLog log = new RLog(fileLocation); StringBuilder b = new StringBuilder(); for (int i = 2000; i != 0; i--) { b.AppendLine(i.ToString()); } log.LogMessage(b.ToString(), MessageType.Warning); } break; case "start": { this.Start(); } break; case "stop": ThreadMgr.Stop(); srv.Stop(); break; case "exit": this.Stop(); break; default: Console.WriteLine("No Such Command: " + input + "\r\n"); break; } } }