Esempio n. 1
0
        public static void HandleLogoutComplete(ref PacketReader packet, ref WorldClass session)
        {
            WorldMgr.DeleteSession(session.Character.Guid);

            PacketWriter logoutComplete = new PacketWriter(LegacyMessage.LogoutComplete);
            session.Send(logoutComplete);
        }
Esempio n. 2
0
        public static void AddNpc(string[] args, WorldClass session)
        {
            var level = CommandParser.Read<byte>(args, 1);
            var chatMessage = new ChatMessageValues(0, "Please enter a level between 0 and 91.");

            if (level > 90 || level < 1)
            {
                ChatHandler.SendMessage(ref session, chatMessage);
                return;
            }

            var pChar = session.Character;

            if (SmartGuid.GetGuidType(pChar.TargetGuid) == HighGuidType.Player)
            {
               if (DB.Characters.Execute("UPDATE Characters SET Level = ? WHERE Guid = ?", level, pChar.Guid))
               {
                   pChar.SetUpdateField<uint>((int)UnitFields.Level, level);

                   ObjectHandler.HandleUpdateObjectValues(ref session);
               }
            }
            else
            {
                chatMessage.Message = "Please select a player.";

                ChatHandler.SendMessage(ref session, chatMessage);
            }
        }
Esempio n. 3
0
        public static void FlightSpeed(string[] args, WorldClass session)
        {
            ChatMessageValues chatMessage = new ChatMessageValues(0, "");

            if (args.Length == 1)
                MoveHandler.HandleMoveSetFlightSpeed(ref session);
            else
            {
                var speed = CommandParser.Read<float>(args, 1);

                if (speed <= 50 && speed > 0)
                {
                    chatMessage.Message = "Flight speed set to " + speed + "!";

                    MoveHandler.HandleMoveSetFlightSpeed(ref session, speed);
                    ChatHandler.SendMessage(ref session, chatMessage);
                }
                else
                {
                    chatMessage.Message = "Please enter a value between 0.0 and 50.0!";

                    ChatHandler.SendMessage(ref session, chatMessage);
                }

                return;
            }

            chatMessage.Message = "Flight speed set to default.";

            ChatHandler.SendMessage(ref session, chatMessage);
        }
Esempio n. 4
0
        public static void HandleSendKnownSpells(ref WorldClass session)
        {
            Character pChar = session.Character;

            var specializationSpells = SpecializationMgr.GetSpecializationSpells(pChar);
            var specializationSpellCount = ((specializationSpells != null) ? specializationSpells.Count : 0);

            var talentSpells = SpecializationMgr.GetTalentSpells(pChar, pChar.ActiveSpecGroup);
            var talentSpellCount = ((talentSpells != null) ? talentSpells.Count : 0);

            int count = pChar.SpellList.Count + specializationSpellCount + talentSpellCount;

            PacketWriter writer = new PacketWriter(ServerMessage.SendKnownSpells);
            BitPack BitPack = new BitPack(writer);

            BitPack.Write(1);
            BitPack.Write(count, 22);
            BitPack.Flush();

            pChar.SpellList.ForEach(spell =>
                writer.WriteUInt32(spell.SpellId));

            if (specializationSpells != null)
                specializationSpells.ForEach(spell => writer.WriteUInt32(spell.Spell));

            if (talentSpells != null)
                talentSpells.ForEach(spell => writer.WriteUInt32(spell));

            session.Send(ref writer);
        }
        public static void HandleCliSetSpecialization(ref PacketReader packet, ref WorldClass session)
        {
            var pChar = session.Character;

            uint specGroupId = packet.Read<uint>();

            uint specId = SpecializationMgr.GetSpecIdByGroup(pChar, (byte)specGroupId);

            // check if new spec is primary or secondary
            if (pChar.SpecGroupCount == 1 && pChar.PrimarySpec == 0)
            {
                pChar.ActiveSpecGroup = 0;
                pChar.PrimarySpec = (ushort)specId;
            }
            else
            {
                pChar.ActiveSpecGroup = 1;
                pChar.SecondarySpec = (ushort)specId;
                pChar.SpecGroupCount = (byte)(pChar.SpecGroupCount + 1);
            }

            SpecializationMgr.SaveSpecInfo(pChar);

            SendSpecializationSpells(ref session);
            HandleUpdateTalentData(ref session);

            pChar.SetUpdateField<Int32>((int)PlayerFields.CurrentSpecID, (int)pChar.GetActiveSpecId());
            ObjectHandler.HandleUpdateObjectValues(ref session);

            Log.Message(LogType.Debug, "Character (Guid: {0}) choosed specialization {1} for spec group {2}.", pChar.Guid, pChar.GetActiveSpecId(), pChar.ActiveSpecGroup);
        }
Esempio n. 6
0
        public static void AddNpc(string[] args, WorldClass session)
        {
            var pChar = session.Character;

            int creatureId = CommandParser.Read<int>(args, 1);

            Creature creature = DataMgr.FindCreature(creatureId);
            if (creature != null)
            {
                ChatMessageValues chatMessage = new ChatMessageValues(0, "");

                CreatureSpawn spawn = new CreatureSpawn()
                {
                    Guid     = CreatureSpawn.GetLastGuid() + 1,
                    Id       = creatureId,
                    Creature = creature,
                    Position = pChar.Position,
                    Map      = pChar.Map
                };

                if (spawn.AddToDB())
                {
                    chatMessage.Message = "Spawn successfully added.";

                    spawn.AddToWorld();
                    ChatHandler.SendMessage(ref session, chatMessage);
                }
                else
                {
                    chatMessage.Message = "Spawn can't be added.";
                    ChatHandler.SendMessage(ref session, chatMessage);
                }
            }
        }
        public static void HandleLearnTalents(ref PacketReader packet, ref WorldClass session)
        {
            var pChar = session.Character;
            var talentSpells = new List<uint>();

            BitUnpack BitUnpack = new BitUnpack(packet);

            uint talentCount = BitUnpack.GetBits<uint>(23);

            for (int i = 0; i < talentCount; i++)
            {
                var talentId = packet.Read<ushort>();

                SpecializationMgr.AddTalent(pChar, pChar.ActiveSpecGroup, talentId, true);

                talentSpells.Add(CliDB.Talent.Single(talent => talent.Id == talentId).SpellId);
            }

            HandleUpdateTalentData(ref session);

            pChar.SetUpdateField<Int32>((int)PlayerFields.SpellCritPercentage + 0, SpecializationMgr.GetUnspentTalentRowCount(pChar), 0);
            ObjectHandler.HandleUpdateObjectValues(ref session);

            foreach (var talentSpell in talentSpells)
                SpellHandler.HandleLearnedSpells(ref session, new List<uint>(1) { talentSpell });

            Log.Message(LogType.Debug, "Character (Guid: {0}) learned {1} talents.", pChar.Guid, talentCount);
        }
Esempio n. 8
0
        public static void AddObject(string[] args, WorldClass session)
        {
            var pChar = session.Character;

            int objectId = CommandParser.Read<int>(args, 1);

            GameObject gObject = DataMgr.FindGameObject(objectId);
            if (gObject != null)
            {
                ChatMessageValues chatMessage = new ChatMessageValues(0, "");

                GameObjectSpawn spawn = new GameObjectSpawn()
                {
                    Guid = GameObjectSpawn.GetLastGuid() + 1,
                    Id = objectId,
                    GameObject = gObject,
                    Position = pChar.Position,
                    Map = pChar.Map
                };

                if (spawn.AddToDB())
                {
                    chatMessage.Message = "Spawn successfully added.";

                    spawn.AddToWorld();
                    ChatHandler.SendMessage(ref session, chatMessage);
                }
                else
                {
                    chatMessage.Message = "Spawn can't be added.";

                    ChatHandler.SendMessage(ref session, chatMessage);
                }
            }
        }
Esempio n. 9
0
        //[Opcode(ClientMessage.LearnTalents, "16357")]
        public static void HandleLearnTalents(ref PacketReader packet, ref WorldClass session)
        {
            var pChar = session.Character;
            var talentSpells = new List<uint>();

            BitUnpack BitUnpack = new BitUnpack(packet);

            uint talentCount = BitUnpack.GetBits<uint>(25);

            for (int i = 0; i < talentCount; i++)
            {
                var talentId = packet.ReadUInt16();
                SpecializationMgr.AddTalent(pChar, pChar.ActiveSpecGroup, talentId, true);

                talentSpells.Add(DBCStorage.TalentStorage.LookupByKey(talentId).SpellId);
            }

            HandleTalentUpdate(ref session);

            pChar.SetUpdateField<Int32>((int)PlayerFields.SpellCritPercentage + 0, SpecializationMgr.GetUnspentTalentRowCount(pChar), 0);
            ObjectHandler.HandleUpdateObjectValues(ref session);

            // we need to send a single packet for every talent spell - stupid blizz
            foreach (var talentSpell in talentSpells)
                SpellHandler.HandleLearnedSpells(ref session, new List<uint>(1) { talentSpell });

            Log.Message(LogType.DEBUG, "Character (Guid: {0}) learned {1} talents.", pChar.Guid, talentCount);
        }
Esempio n. 10
0
        public Character(UInt64 guid, ref WorldClass session)
            : base((int)PlayerFields.End)
        {
            SQLResult result = DB.Characters.Select("SELECT * FROM characters WHERE guid = {0}", guid);

            Guid           = result.Read<UInt64>(0, "Guid");
            AccountId      = result.Read<UInt32>(0, "AccountId");
            Name           = result.Read<String>(0, "Name");
            Race           = result.Read<Byte>(0, "Race");
            Class          = result.Read<Byte>(0, "Class");
            Gender         = result.Read<Byte>(0, "Gender");
            Skin           = result.Read<Byte>(0, "Skin");
            Face           = result.Read<Byte>(0, "Face");
            HairStyle      = result.Read<Byte>(0, "HairStyle");
            HairColor      = result.Read<Byte>(0, "HairColor");
            FacialHair     = result.Read<Byte>(0, "FacialHair");
            Level          = result.Read<Byte>(0, "Level");
            Zone           = result.Read<UInt32>(0, "Zone");
            Map            = result.Read<UInt32>(0, "Map");
            X              = result.Read<Single>(0, "X");
            Y              = result.Read<Single>(0, "Y");
            Z              = result.Read<Single>(0, "Z");
            O              = result.Read<Single>(0, "O");
            GuildGuid      = result.Read<UInt64>(0, "GuildGuid");
            PetDisplayInfo = result.Read<UInt32>(0, "PetDisplayId");
            PetLevel       = result.Read<UInt32>(0, "PetLevel");
            PetFamily      = result.Read<UInt32>(0, "PetFamily");
            CharacterFlags = result.Read<UInt32>(0, "CharacterFlags");
            CustomizeFlags = result.Read<UInt32>(0, "CustomizeFlags");

            // Set current session of the character
            Globals.SetSession(ref session);

            SetCharacterFields();
        }
Esempio n. 11
0
        public static void DeleteNpc(string[] args, WorldClass session)
        {
            ChatMessageValues chatMessage = new ChatMessageValues(MessageType.ChatMessageSystem, "");

            var pChar = session.Character;
            var spawn = SpawnMgr.FindSpawn(pChar.TargetGuid);

            if (spawn != null)
            {
                SpawnMgr.RemoveSpawn(spawn);

                var destroyObject = ObjectHandler.HandleDestroyObject(ref session, pChar.TargetGuid);

                session.Send(ref destroyObject);
                WorldMgr.SendToInRangeCharacter(pChar, destroyObject);

                chatMessage.Message = "Selected Spawn successfully removed.";

                ChatHandler.SendMessage(ref session, chatMessage);
            }
            else
            {
                chatMessage.Message = "Not a creature.";

                ChatHandler.SendMessage(ref session, chatMessage);
            }
        }
Esempio n. 12
0
        public static void AddTele(string[] args, WorldClass session)
        {
            var pChar = session.Character;

            string location = CommandParser.Read<string>(args, 1);
            SQLResult result = DB.World.Select("SELECT * FROM teleport_locations WHERE location = ?", location);

            ChatMessageValues chatMessage = new ChatMessageValues(0, "");

            if (result.Count == 0)
            {
                if (DB.World.Execute("INSERT INTO teleport_locations (location, x, y, z, o, map) " +
                    "VALUES (?, ?, ?, ?, ?, ?)", location, pChar.Position.X, pChar.Position.Y, pChar.Position.Z, pChar.Position.O, pChar.Map))
                {
                    chatMessage.Message = string.Format("Teleport location '{0}' successfully added.", location);

                    ChatHandler.SendMessage(ref session, chatMessage);
                }
            }
            else
            {
                chatMessage.Message = string.Format("Teleport location '{0}' already exist.", location);

                ChatHandler.SendMessage(ref session, chatMessage);
            }
        }
Esempio n. 13
0
        public static void HandleRequestUITime(ref PacketReader packet, ref WorldClass session)
        {
            PacketWriter uiTime = new PacketWriter(LegacyMessage.UITime);

            uiTime.WriteUnixTime();
            session.Send(uiTime);
        }
Esempio n. 14
0
        public static void HandleCreateCharacter(ref PacketReader packet, WorldClass session)
        {
            BitUnpack BitUnpack = new BitUnpack(packet);

            packet.Skip(1);

            var facialHair = packet.ReadByte();
            var skin = packet.ReadByte();
            var race = packet.ReadByte();
            var hairStyle = packet.ReadByte();
            var pClass = packet.ReadByte();
            var face = packet.ReadByte();
            var gender = packet.ReadByte();
            var hairColor = packet.ReadByte();

            var nameLength  = BitUnpack.GetBits<uint>(6);
            var hasUnknown = BitUnpack.GetBit();
            var name        = Character.NormalizeName(packet.ReadString(nameLength));

            if (hasUnknown)
                packet.ReadUInt32();

            var result      = DB.Characters.Select("SELECT * from characters WHERE name = ?", name);
            var createChar  = new PacketWriter(ServerMessage.CreateChar);

            if (result.Count != 0)
            {
                // Name already in use
                createChar.WriteUInt8(0x32);
                session.Send(ref createChar);
                return;
            }

            result = DB.Characters.Select("SELECT map, zone, posX, posY, posZ, posO FROM character_creation_data WHERE race = ? AND class = ?", race, pClass);
            if (result.Count == 0)
            {
                createChar.WriteUInt8(0x31);
                session.Send(ref createChar);
                return;
            }

            var map  = result.Read<uint>(0, "map");
            var zone = result.Read<uint>(0, "zone");
            var posX = result.Read<float>(0, "posX");
            var posY = result.Read<float>(0, "posY");
            var posZ = result.Read<float>(0, "posZ");
            var posO = result.Read<float>(0, "posO");

            // Allow declined names for now
            var characterFlags = CharacterFlag.Decline;

            DB.Characters.Execute("INSERT INTO characters (name, accountid, realmId, race, class, gender, skin, zone, map, x, y, z, o, face, hairstyle, haircolor, facialhair, characterFlags) VALUES (" +
                                  "?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
                                  name, session.Account.Id, WorldConfig.RealmId, race, pClass, gender, skin, zone, map, posX, posY, posZ, posO, face, hairStyle, hairColor, facialHair, characterFlags);

            // Success
            createChar.WriteUInt8(0x2F);
            session.Send(ref createChar);
        }
Esempio n. 15
0
        public static void Save(string[] args, WorldClass session)
        {
            ObjectMgr.SavePositionToDB(session.Character);

            ChatMessageValues chatMessage = new ChatMessageValues(0, "Your character is successfully saved to the database!");

            ChatHandler.SendMessage(ref session, chatMessage);
        }
Esempio n. 16
0
        public static void HandleUITimeRequest(ref PacketReader packet, WorldClass session)
        {
            PacketWriter uiTime = new PacketWriter(ServerMessage.UITime);

            uiTime.WriteUnixTime();

            session.Send(ref uiTime);
        }
Esempio n. 17
0
        public static void HandleTutorialFlags(ref WorldClass session)
        {
            PacketWriter tutorialFlags = new PacketWriter(LegacyMessage.TutorialFlags);
            for (int i = 0; i < 8; i++)
                tutorialFlags.WriteUInt32(0);

            session.Send(ref tutorialFlags);
        }
Esempio n. 18
0
        public static void DelTele(string[] args, ref WorldClass session)
        {
            var pChar = session.Character;

            string location = CommandParser.Read<string>(args, 1);
            if (DB.World.Execute("DELETE FROM teleport_locations WHERE location = ?", location))
                ChatHandler.SendMessageByType(ref session, 0, 0, String.Format("Teleport location '{0}' successfully deleted.", location));
        }
Esempio n. 19
0
        public static void HandleUpdateClientCacheVersion(ref WorldClass session)
        {
            PacketWriter cacheVersion = new PacketWriter(LegacyMessage.UpdateClientCacheVersion);

            cacheVersion.WriteUInt32(0);

            session.Send(cacheVersion);
        }
Esempio n. 20
0
        public static void Money(string[] args, ref WorldClass session)
        {
            UInt64 moneyValue = CommandParser.Read<UInt64>(args, 1);
            // Temp disabled
            //session.Character.ModifyMoney(moneyValue);

            ChatHandler.SendMessageByType(ref session, 0, 0, string.Format("You added {0} copper to your character.", moneyValue));
        }
Esempio n. 21
0
        public static void HandleCacheVersion(ref WorldClass session)
        {
            PacketWriter cacheVersion = new PacketWriter(ServerMessage.CacheVersion);

            cacheVersion.WriteUInt32(0);

            session.Send(ref cacheVersion);
        }
Esempio n. 22
0
        public static void ExecuteChatHandler(string chatCommand, ref WorldClass session)
        {
            var args = chatCommand.Split(new string[] { " " }, StringSplitOptions.None);
            var command = args[0].Remove(0, 1);

            if (ChatCommands.ContainsKey(command))
                ChatCommands[command].Invoke(args, ref session);
        }
Esempio n. 23
0
        public static void HandleChatMessageYell(ref PacketReader packet, ref WorldClass session)
        {
            BitUnpack BitUnpack = new BitUnpack(packet);
            int language = packet.ReadInt32();

            uint messageLength = BitUnpack.GetBits<uint>(9);
            string chatMessage = packet.ReadString(messageLength);
            SendMessageByType(ref session, MessageType.ChatMessageYell, language, chatMessage);
        }
Esempio n. 24
0
        public static PacketWriter HandleObjectDestroy(ref WorldClass session, ulong guid)
        {
            PacketWriter objectDestroy = new PacketWriter(LegacyMessage.ObjectDestroy);

            objectDestroy.WriteUInt64(guid);
            objectDestroy.WriteUInt8(0);

            return objectDestroy;
        }
Esempio n. 25
0
        public static void HandleLoadingScreenNotify(ref PacketReader packet, WorldClass session)
        {
            BitUnpack BitUnpack = new BitUnpack(packet);

            uint mapId = packet.Read<uint>();
            bool loadingScreenState = BitUnpack.GetBit();

            Log.Message(LogType.Debug, "Loading screen for map '{0}' is {1}.", mapId, loadingScreenState ? "enabled" : "disabled");
        }
Esempio n. 26
0
        public static void HandleObjectDestroy(ref WorldClass session)
        {
            PacketWriter objectDestroy = new PacketWriter(LegacyMessage.ObjectDestroy);

            objectDestroy.WriteUInt64(session.Character.Guid);
            objectDestroy.WriteUInt8(0);

            session.Send(objectDestroy);
        }
Esempio n. 27
0
        public static void HandleAreatrigger(ref PacketReader packet, ref WorldClass session)
        {
            var pChar = session.Character;
            uint triggerId = packet.ReadUInt32();

            AreaTrigger areaTrigger = DBCStorage.AreaTriggerStorage[triggerId];

            Log.Message(LogType.DEBUG, "Character (Guid: {0}) reached Areatrigger Id: {1}.", pChar.Guid, areaTrigger.Id);
        }
Esempio n. 28
0
        public static void HandlePong(ref PacketReader packet, ref WorldClass session)
        {
            uint sequence = packet.ReadUInt32();
            uint latency = packet.ReadUInt32();

            PacketWriter pong = new PacketWriter(JAMCCMessage.Pong);
            pong.WriteUInt32(sequence);

            session.Send(ref pong);
        }
Esempio n. 29
0
        public static void HandleObjectUpdateFailed(ref PacketReader packet, WorldClass session)
        {
            byte[] guidMask = { 7, 0, 2, 3, 1, 4, 6, 5 };
            byte[] guidBytes = { 1, 2, 5, 0, 3, 4, 6, 7 };

            BitUnpack GuidUnpacker = new BitUnpack(packet);

            ulong guid = GuidUnpacker.GetPackedValue(guidMask, guidBytes);
            Log.Message(LogType.Debug, "ObjectUpdate failed for object with Guid {0}", guid);
        }
Esempio n. 30
0
        public static void HandleObjectUpdateFailed(ref PacketReader packet, ref WorldClass session)
        {
            byte[] guidMask = { 6, 1, 7, 5, 0, 4, 2, 3 };
            byte[] guidBytes = { 2, 3, 7, 4, 5, 1, 0, 6 };

            BitUnpack GuidUnpacker = new BitUnpack(packet);

            ulong guid = GuidUnpacker.GetGuid(guidMask, guidBytes);
            Log.Message(LogType.DEBUG, "ObjectUpdate failed for object with Guid {0}", guid);
        }
Esempio n. 31
0
        async void AcceptConnection()
        {
            while (listenSocket)
            {
                Thread.Sleep(1);
                if (listener.Pending())
                {
                    WorldClass worldClient = new WorldClass();
                    worldClient.clientSocket = await listener.AcceptSocketAsync();

                    new Thread(worldClient.OnConnect).Start();
                }
            }
        }