Example #1
0
        public static void OnLogout(WorldSession session, PacketReader reader)
        {
            if (LogoutQueue.ContainsKey(session)) LogoutQueue.Remove(session);

            session.SendPacket(new PSLogoutResponse());
            LogoutQueue.Add(session, DateTime.Now);
        }
Example #2
0
 public override AbstractSession GenerateSession(int connectionID, Socket connectionSocket)
 {
     var session = new WorldSession(this, Core, connectionID, connectionSocket);
     Sessions.Add(session);
     session.OnSessionDisconnect += abstractSession => Disconnect(session);
     return session;
 }
Example #3
0
 public void OnMessageChatPacket(WorldSession session, PCMessageChat packet)
 {
     if (ChatHandlers.ContainsKey(packet.Type))
     {
         ChatHandlers[packet.Type](session, packet);
     }
 }
Example #4
0
        private void OnGetMailList(WorldSession session, PCGetMailList packet)
        {
            var mailList = this.Mails.Where(m => m.receiver == packet.GUID).ToList();
            this.RemoveExpiredMail(mailList);

            session.SendPacket(new PSMailListResult(mailList));
        }
Example #5
0
        public PSCharEnum(WorldSession session, List<character> characters)
            : base(WorldOpcodes.SMSG_CHAR_ENUM)
        {
            this.Session = session;
            this.Write((byte)characters.Count);

            foreach (character character in characters)
            {
                this.Write((ulong)character.guid);
                this.WriteCString(character.name);
                this.Write((byte)character.race);
                this.Write((byte)character.@class);

                this.Write((byte)character.gender);

                byte[] playerBytes = BitConverter.GetBytes(character.playerBytes);
                byte[] playerBytes2 = BitConverter.GetBytes(character.playerBytes2);

                this.Write((byte)playerBytes[0]); // Skin
                this.Write((byte)playerBytes[1]); // Face
                this.Write((byte)playerBytes[2]); // HairStyle
                this.Write((byte)playerBytes[3]); // HairColor
                this.Write((byte)playerBytes2[0]); // Accessory
                this.Write((byte)character.level);

                this.Write(0); // Zone ID
                Write((int)character.map);
                Write(character.position_x);
                Write(character.position_y);
                Write(character.position_z);

                this.Write(0); // Guild ID
                this.Write(0); // Character Flags

                this.Write((byte)0); // // Login Flags?

                this.Write(0); // Pet DisplayID
                this.Write(0); // Pet Level
                this.Write(0); // Pet FamilyID

                item_template[] equipment = ItemUtils.GenerateInventoryByIDs(Utils.CSVStringToIntArray(character.equipmentCache));

                for (int itemSlot = 0; itemSlot < 19; itemSlot++)
                {
                    if (equipment != null && equipment[itemSlot] != null)
                    {
                        Write(equipment[itemSlot].displayid); // Item DisplayID
                        Write((byte)equipment[itemSlot].InventoryType); // Item Inventory Type
                    }
                    else
                    {
                        Write(0);
                        Write((byte)0);
                    }
                }
                this.Write(0); // first bag display id
                this.Write((byte)0); // first bag inventory type
            }
        }
Example #6
0
 public PlayerEntity AddPlayerEntity(character character, WorldSession session)
 {
     ObjectGUID guid = new ObjectGUID((ulong)character.guid, TypeID.TYPEID_PLAYER);
     PlayerEntity playerEntity = new PlayerEntity(guid, character, session);
     PlayerEntities.Add(playerEntity);
     playerEntity.Setup();
     return playerEntity;
 }
Example #7
0
        public UpdatePacketBuilder(WorldSession session)
        {
            Session = session;

            createEntities = new Queue<ISubscribable>();
            updateEntities = new List<ISubscribable>();
            removeEntities = new Queue<ISubscribable>();
        }
Example #8
0
 public static void Send(WorldSession session, string[] args)
 {
     if(session.Player.Target != null || !(session.Player.Target is CreatureEntity))
     {
         var target = session.Player.Target as CreatureEntity;
         target.Brain.Move(session, new List<Vector3>(){session.Player.Location.Position});
     }
 }
Example #9
0
        public void OnNameQuery(WorldSession session, PCNameQuery packet)
        {
            WorldSession target = Server.Sessions.Find(sesh => sesh.Player.ObjectGUID.RawGUID == packet.GUID);

            if (target != null)
            {
                session.SendPacket(new PSNameQueryResponse(target.Player.Character));
            }
        }
Example #10
0
        private void OnSendMail(WorldSession session, PCSendMail packet)
        {
            character reciever = Characters.SingleOrDefault(c => c.name == packet.Reciever);
            var result = MailResponseResult.MAIL_OK;
            if (reciever == null)
            {
                result = MailResponseResult.MAIL_ERR_RECIPIENT_NOT_FOUND;
            }
            else if (reciever.name == session.Player.Name)
            {
                result = MailResponseResult.MAIL_ERR_CANNOT_SEND_TO_SELF;
            }
            else if (session.Player.Character.money < packet.Money + 30)
            {
                result = MailResponseResult.MAIL_ERR_NOT_ENOUGH_MONEY;
            }
            else if (Mails.Where(m => m.receiver == reciever.guid).ToArray().Length > 100)
            {
                result = MailResponseResult.MAIL_ERR_RECIPIENT_CAP_REACHED;
            }
            else if (GetFaction(reciever) != GetFaction(session.Player.Character))
            {
                result = MailResponseResult.MAIL_ERR_NOT_YOUR_TEAM;
            }

            if (packet.ItemGUID > 0)
            {
                throw new NotImplementedException();
            }

            session.SendPacket(new PSSendMailResult(0, MailResponseType.MAIL_SEND, result));

            if (result == MailResponseResult.MAIL_OK)
            {
                session.Player.Character.money -= (int)(packet.Money + 30);
                Mails.Add(
                    new mail()
                        {
                            messageType = (byte)MailMessageType.MAIL_NORMAL,
                            deliver_time = 0,
                            expire_time = (int)GameUnits.DAY * 30,
                            @checked =
                                packet.Body != ""
                                    ? (byte)MailCheckMask.MAIL_CHECK_MASK_HAS_BODY
                                    : (byte)MailCheckMask.MAIL_CHECK_MASK_COPIED,
                            cod = (int)packet.COD,
                            has_items = 0,
                            itemTextId = 0,
                            money = (int)packet.Money,
                            sender = session.Player.Character.guid,
                            receiver = reciever.guid,
                            subject = packet.Subject,
                            stationery = (sbyte)MailStationery.MAIL_STATIONERY_DEFAULT,
                            mailTemplateId = 0
                        });
            }
        }
Example #11
0
        private void OnAuthSession(WorldSession session, PCAuthSession packet)
        {
            account account = new DatabaseUnitOfWork<LoginDatabase>().GetRepository<account>().SingleOrDefault((a) => a.username == packet.Username);

            session.Account = account;
            session.PacketCrypto = new VanillaCrypt();
            session.PacketCrypto.init(Utils.HexToByteArray(session.Account.sessionkey));
            session.SendPacket(new PSAuthResponse());
        }
Example #12
0
        private static void OnGameObjectUsePacket(WorldSession session, PCGameObjectUse packet)
        {
            GameObjectEntity gameObject = session.Core.GetComponent<EntityComponent>().GameObjectEntities.SingleOrDefault(g => g.ObjectGUID.RawGUID == packet.GUID);

            gameobject_template template = gameObject.Template;

            if (gameObject != null && GameObjectUseHandlers.ContainsKey((GameObjectType)template.type))
            {
                GameObjectUseHandlers[(GameObjectType)template.type](session, gameObject);
            }
        }
Example #13
0
 private void OnSetActionButton(WorldSession session, PCSetActionButton packet)
 {
     if (packet.Action == 0)
     {
         session.Player.ActionButtonCollection.RemoveActionButton(packet.Button);
     }
     else
     {
         session.Player.ActionButtonCollection.AddActionButton(new character_action() { guid = session.Player.ObjectGUID.Low, action = packet.Action, button = packet.Button, type = (byte)packet.Type });
     }
 }
Example #14
0
        public void SetWeather(WorldSession session, WeatherType type, float intensity)
        {
            var weatherZone = GetWeatherZoneForSession(session);

            if (weatherZone == null)
            {
                Log.Print(LogType.Error, session.Player.Name + " attempted to change weather of a mapID that was not setup.");
                return;
            }

            SetWeather(weatherZone, type, intensity);
        }
Example #15
0
        public PSMovement(WorldOpcodes worldOpcode, WorldSession session, PCMoveInfo moveinfo)
            : base(worldOpcode)
        {
            var correctedMoveTime = (uint)Environment.TickCount;

            byte[] packedGUID = session.Player.ObjectGUID.GetGuidBytes();
            this.WriteBytes(packedGUID);
            this.WriteBytes((moveinfo.BaseStream as MemoryStream).ToArray());

            // We then overwrite the original moveTime (sent from the client) with ours
            (this.BaseStream as MemoryStream).Position = 4 + packedGUID.Length;
            this.WriteBytes(BitConverter.GetBytes(correctedMoveTime));
        }
Example #16
0
        public void OnWhisper(WorldSession session, PCMessageChat packet)
        {
            WorldSession remoteSession = Server.GetSessionByPlayerName(packet.To);

            if (remoteSession != null)
            {
                session.SendPacket(new PSMessageChat(ChatMessageType.CHAT_MSG_WHISPER_INFORM, ChatMessageLanguage.LANG_UNIVERSAL, remoteSession.Player.ObjectGUID.RawGUID, packet.Message));
                remoteSession.SendPacket(new PSMessageChat(ChatMessageType.CHAT_MSG_WHISPER, ChatMessageLanguage.LANG_UNIVERSAL, session.Player.ObjectGUID.RawGUID, packet.Message));
            }
            else
            {
                session.SendMessage("Player not found.");
            }
        }
Example #17
0
        public void OnSetSelection(WorldSession session, PCSetSelection packet)
        {
            IUnitEntity target = null;

            WorldSession targetSession = Core.Server.Sessions.SingleOrDefault(s => s.Player.ObjectGUID.RawGUID == packet.GUID);
            if (targetSession != null) target = targetSession.Player;

            if (target == null) target = Core.GetComponent<EntityComponent>().CreatureEntities.SingleOrDefault(e => e.ObjectGUID.RawGUID == packet.GUID);

            if (target != null)
            {
                session.Player.Target = target;
                session.SendMessage("Target: " + target.Name);
            }
            else
            {
                session.SendMessage("Couldnt find target!");
                session.Player.Target = null;
            }
        }
Example #18
0
        public void OnAreaTrigger(WorldSession session, PCAreaTrigger packet)
        {
            areatrigger_teleport areaTrigger = Core.WorldDatabase.GetRepository<areatrigger_teleport>().SingleOrDefault(at => at.id == packet.TriggerID);

            if (areaTrigger != null)
            {
                session.SendMessage("[AreaTrigger] ID:" + packet.TriggerID + " " + areaTrigger.name);
                session.Player.Location.MapID = areaTrigger.target_map;
                session.Player.Location.X = areaTrigger.target_position_x;
                session.Player.Location.Y = areaTrigger.target_position_y;
                session.Player.Location.Z = areaTrigger.target_position_z;
                session.Player.Location.Orientation = areaTrigger.target_orientation;

                session.SendPacket(new PSTransferPending(areaTrigger.target_map));
                session.SendPacket(new PSNewWorld(areaTrigger.target_map, areaTrigger.target_position_x, areaTrigger.target_position_y, areaTrigger.target_position_z, areaTrigger.target_orientation));
            }
            else
            {
                session.SendMessage("[AreaTrigger] ID:" + packet.TriggerID);
            }
        }
Example #19
0
        private void OnCastSpell(WorldSession session, PCCastSpell packet)
        {
            IUnitEntity target = session.Player.Target ?? session.Player;

            target.SubscribedBy.ToList().ForEach(s => s.SendPacket(new PSSpellGo(session.Player, target, packet.spellID)));
            session.SendPacket(new PSSpellGo(session.Player, target, packet.spellID));
            session.SendPacket(new PSCastFailed(packet.spellID));

            SpellEntry spell = Core.DBC.GetDBC<SpellEntry>().SingleOrDefault(s => s.ID == packet.spellID);
            float spellSpeed = spell.Speed;

            /*
            float distance =  (float)Math.Sqrt((session.Entity.X - session.Entity.Target.X) * (session.Entity.X - session.Entity.Target.X) +
                                               (session.Entity.Y - session.Entity.Target.Y) * (session.Entity.Y - session.Entity.Target.Y) +
                                               (session.Entity.Z - session.Entity.Target.Z) * (session.Entity.Z - session.Entity.Target.Z));

            if (distance < 5) distance = 5;

            float dx = session.Entity.X - target.X;
            float dy = session.Entity.Y - target.Y;
            float dz = session.Entity.Z - target.Target.Z;
            float radius = 5;
            float distance = (float)Math.Sqrt((dx * dx) + (dy * dy) + (dz * dz)) - radius;

            //if (distance < 5) distance = 5;
            float timeToHit = (spellSpeed > 0) ? (float)Math.Floor(distance / spellSpeed * 1000f) : 0;

            session.sendMessage("Cast [" + spell.Name + "] Distance: " + distance + " Speed: " + spellSpeed + " Time: " + timeToHit);
            float radians = (float)(Math.Atan2(session.Entity.Y - session.Entity.Target.Y, session.Entity.X - session.Entity.Target.X));

            if(spellSpeed > 0)
            {
                DoTimer(timeToHit, (s, e) =>
                {
                    WorldServer.TransmitToAll(new PSMoveKnockBack(target, (float)Math.Cos(radians), (float)Math.Sin(radians), -10, -10));
                });
            }

               */
        }
Example #20
0
 private void OnListChannel(WorldSession session, PCChannel packet)
 {
     session.SendMessage("Users in channel " + packet.ChannelName + ":");
     var channel = ChatChannels.SingleOrDefault(ch => ch.Name == packet.ChannelName);
     channel.Sessions.ForEach(s => session.SendMessage(s.Player.Name));
 }
Example #21
0
        private void OnLeaveChannel(WorldSession session, PCChannel packet)
        {
            var channel = ChatChannels.SingleOrDefault(c => c.Name == packet.ChannelName);
            channel.Sessions.Remove(session);

            if (channel.Sessions.Count == 0) ChatChannels.Remove(channel);

            session.SendPacket(new PSChannelNotify(ChatChannelNotify.CHAT_YOU_LEFT_NOTICE, session.Player.ObjectGUID.RawGUID, packet.ChannelName));
        }
Example #22
0
        private void OnJoinChannel(WorldSession session, PCJoinChannel packet)
        {
            var channel = ChatChannels.SingleOrDefault(c => c.Name == packet.ChannelName);
            if (channel == null)
            {
                channel = new ChatChannel(packet.ChannelName, packet.Password);
                ChatChannels.Add(channel);
            }
            channel.Sessions.Add(session);

            session.SendPacket(new PSChannelNotify(ChatChannelNotify.CHAT_YOU_JOINED_NOTICE, session.Player.ObjectGUID.RawGUID, packet.ChannelName));
        }
Example #23
0
 public static void OnCancel(WorldSession session, PacketReader reader)
 {
     LogoutQueue.Remove(session);
     session.SendPacket(new PSLogoutCancelAcknowledgement());
 }
Example #24
0
 public void OnGameObjectQuery(WorldSession session, PCGameObjectQuery packet)
 {
     gameobject_template template = Core.WorldDatabase.GetRepository<gameobject_template>().SingleOrDefault(g => g.entry == packet.EntryID);
     session.SendPacket(new PSGameObjectQueryResponse(template));
 }
Example #25
0
 public void SendSytemMessage(WorldSession session, string message)
 {
     session.SendPacket(new PSMessageChat(ChatMessageType.CHAT_MSG_SYSTEM, ChatMessageLanguage.LANG_COMMON, 0, message));
 }
Example #26
0
 public void OnSayYell(WorldSession session, PCMessageChat packet)
 {
     if (packet.Message[0].ToString() == Config.GetValue(ConfigSections.WORLD, ConfigValues.COMMAND_KEY)) Core.ChatCommands.ExecuteCommand(session, packet.Message);
     else Server.TransmitToAll(new PSMessageChat(packet.Type, ChatMessageLanguage.LANG_UNIVERSAL, session.Player.ObjectGUID.RawGUID, packet.Message));
 }
Example #27
0
 private static void OnUseChair(WorldSession session, GameObjectEntity gameObjectEntity)
 {
     session.Player.TeleportTo(session.Player.Character.map, gameObjectEntity.Location.X, gameObjectEntity.Location.Y, gameObjectEntity.Location.Z, gameObjectEntity.Location.Orientation);
     session.Player.Info.StandState = (byte)UnitStandStateType.UNIT_STAND_STATE_SIT_CHAIR;
 }
Example #28
0
        public void OnPing(WorldSession session, PCPing packet)
        {
            session.SendMessage("Ping: " + packet.Ping + " Latancy: " + packet.Latency);

            session.SendPacket(new PSPong(packet.Ping));
        }
Example #29
0
 private void OnChannelMessage(WorldSession session, PCMessageChat packet)
 {
     var channel = ChatChannels.SingleOrDefault(c => c.Name == packet.ChannelName);
     channel.Sessions.ForEach(s => s.SendPacket(new PSMessageChat(ChatMessageType.CHAT_MSG_CHANNEL, ChatMessageLanguage.LANG_UNIVERSAL, session.Player.ObjectGUID.RawGUID, packet.Message, packet.ChannelName)));
 }
Example #30
0
 private void OnReturnMailToSender(WorldSession session, PCSendMail packet)
 {
     throw new NotImplementedException();
 }