Exemplo n.º 1
0
 /// <summary>
 /// Send <see cref="ServerGenericUnlock"/> with supplied id.
 /// </summary>
 public void SendUnlock(ushort genericUnlockEntryId)
 {
     session.EnqueueMessageEncrypted(new ServerGenericUnlock
     {
         GenericUnlockEntryId = genericUnlockEntryId
     });
 }
 /// <summary>
 /// Sends information about all the player's <see cref="AccountCurrency"/> during Character Select
 /// </summary>
 public void SendCharacterListPacket()
 {
     session.EnqueueMessageEncrypted(new ServerAccountCurrencySet
     {
         AccountCurrencies = currencies.Values.Select(c => c.BuildServerPacket()).ToList()
     });
 }
Exemplo n.º 3
0
 public void SendInitialPackets()
 {
     session.EnqueueMessageEncrypted(new ServerRewardPropertySet
     {
         Properties = rewardProperties.Values
                      .SelectMany(e => e.Build())
                      .ToList()
     });
 }
Exemplo n.º 4
0
        public static void HandleRequestActionSetChanges(WorldSession session, ClientRequestActionSetChanges requestActionSetChanges)
        {
            // TODO: check for client validity, e.g. Level & Spell4TierRequirements

            ActionSet actionSet = session.Player.SpellManager.GetActionSet(requestActionSetChanges.ActionSetIndex);

            List <ActionSetShortcut> shortcuts = actionSet.Actions.ToList();

            for (UILocation i = 0; i < (UILocation)requestActionSetChanges.Actions.Count; i++)
            {
                ActionSetShortcut shortcut = actionSet.GetShortcut(i);
                if (shortcut != null)
                {
                    actionSet.RemoveShortcut(i);
                }

                uint spell4BaseId = requestActionSetChanges.Actions[(int)i];
                if (spell4BaseId != 0u)
                {
                    ActionSetShortcut existingShortcut = shortcuts.SingleOrDefault(s => s.ObjectId == spell4BaseId);
                    byte tier = existingShortcut?.Tier ?? 1;
                    actionSet.AddShortcut(i, ShortcutType.Spell, spell4BaseId, tier);
                }
            }

            foreach (ClientRequestActionSetChanges.ActionTier actionTier in requestActionSetChanges.ActionTiers)
            {
                session.Player.SpellManager.UpdateSpell(actionTier.Action, actionTier.Tier, requestActionSetChanges.ActionSetIndex);
            }

            session.EnqueueMessageEncrypted(actionSet.BuildServerActionSet());
            if (requestActionSetChanges.ActionTiers.Count > 0)
            {
                session.Player.SpellManager.SendServerAbilityPoints();
            }

            // only new AMP can be added with this packet, filter out existing ones
            List <ushort> newAmps = requestActionSetChanges.Amps
                                    .Except(actionSet.Amps
                                            .Select(a => (ushort)a.Entry.Id))
                                    .ToList();

            if (newAmps.Count > 0)
            {
                foreach (ushort id in newAmps)
                {
                    actionSet.AddAmp(id);
                }

                session.EnqueueMessageEncrypted(actionSet.BuildServerAmpList());
            }
        }
Exemplo n.º 5
0
 /// <summary>
 /// Send communicator message to <see cref="WorldSession"/>.
 /// </summary>
 public void Send(WorldSession session)
 {
     session.EnqueueMessageEncrypted(new ServerCommunicatorMessage
     {
         CommunicatorId = (ushort)entry.Id
     });
 }
Exemplo n.º 6
0
        public static void HandleRealmList(WorldSession session, ClientRealmList realmList)
        {
            var serverRealmList = new ServerRealmList
            {
                Messages = ServerManager.ServerMessages
                           .Select(m => new NetworkMessage
                {
                    Index    = m.Index,
                    Messages = m.Messages
                })
                           .ToList()
            };

            foreach (ServerInfo server in ServerManager.Servers)
            {
                serverRealmList.Realms.Add(new ServerRealmList.RealmInfo
                {
                    RealmId          = server.Model.Id,
                    RealmName        = server.Model.Name,
                    Type             = (RealmType)server.Model.Type,
                    Status           = RealmStatus.Up,
                    Population       = RealmPopulation.Low,
                    Unknown8         = new byte[16],
                    AccountRealmInfo = new ServerRealmList.RealmInfo.AccountRealmData
                    {
                        RealmId = server.Model.Id
                    }
                });
            }

            session.EnqueueMessageEncrypted(serverRealmList);
        }
Exemplo n.º 7
0
        public static void HandleSelectRealm(WorldSession session, ClientSelectRealm selectRealm)
        {
            ServerInfo server = ServerManager.Servers.SingleOrDefault(s => s.Model.Id == selectRealm.RealmId);

            if (server == null)
            {
                throw new InvalidPacketValueException();
            }

            // clicking back or selecting the current realm also triggers this packet, client crashes if we don't ignore it
            if (server.Model.Id == WorldServer.RealmId)
            {
                return;
            }

            byte[] sessionKey = RandomProvider.GetBytes(16u);
            session.EnqueueEvent(new TaskEvent(AuthDatabase.UpdateAccountSessionKey(session.Account, sessionKey),
                                               () =>
            {
                session.EnqueueMessageEncrypted(new ServerNewRealm
                {
                    SessionKey  = sessionKey,
                    GatewayData = new ServerNewRealm.Gateway
                    {
                        Address = server.Address,
                        Port    = server.Model.Port
                    },
                    RealmName = server.Model.Name,
                    Type      = (RealmType)server.Model.Type
                });
            }));
        }
Exemplo n.º 8
0
        public static void HandlePlayerInfoRequest(WorldSession session, ClientPlayerInfoRequest request)
        {
            ICharacter character = CharacterManager.Instance.GetCharacterInfo(request.Identity.CharacterId);

            if (character == null)
            {
                throw new InvalidPacketValueException();
            }

            session.EnqueueMessageEncrypted(new ServerPlayerInfoFullResponse
            {
                BaseData = new ServerPlayerInfoFullResponse.Base
                {
                    ResultCode = 0,
                    Identity   = new TargetPlayerIdentity
                    {
                        RealmId     = WorldServer.RealmId,
                        CharacterId = character.CharacterId
                    },
                    Name    = character.Name,
                    Faction = character.Faction1
                },
                IsClassPathSet          = true,
                Path                    = character.Path,
                Class                   = character.Class,
                Level                   = character.Level,
                IsLastLoggedOnInDaysSet = true,
                LastLoggedInDays        = character.GetOnlineStatus()
            });
        }
Exemplo n.º 9
0
        public static void HandlePlayerInfoRequest(WorldSession session, ClientPlayerInfoRequest request)
        {
            session.EnqueueEvent(new TaskGenericEvent <Character>(CharacterDatabase.GetCharacterById(request.Identity.CharacterId),
                                                                  character =>
            {
                if (character == null)
                {
                    throw new InvalidPacketValueException();
                }

                session.EnqueueMessageEncrypted(new ServerPlayerInfoFullResponse
                {
                    BaseData = new ServerPlayerInfoFullResponse.Base
                    {
                        ResultCode = 0,
                        Identity   = new TargetPlayerIdentity
                        {
                            RealmId     = WorldServer.RealmId,
                            CharacterId = character.Id
                        },
                        Name    = character.Name,
                        Faction = (Faction)character.FactionId
                    },
                    IsClassPathSet          = true,
                    Path                    = (Path)character.ActivePath,
                    Class                   = (Class)character.Class,
                    Level                   = character.Level,
                    IsLastLoggedOnInDaysSet = false,
                    LastLoggedInDays        = -1f
                });
            }));
        }
Exemplo n.º 10
0
        public static void HandleHousingPlacedResidencesList(WorldSession session, ClientHousingPlacedResidencesList _)
        {
            if (session.Player.Map is not ResidenceMapInstance)
            {
                throw new InvalidPacketValueException();
            }

            Community community = session.Player.GuildManager.GetGuild <Community>(GuildType.Community);

            if (community?.Residence == null)
            {
                throw new InvalidPacketValueException();
            }

            var housingPlacedResidencesList = new ServerHousingPlacedResidencesList();

            foreach (ResidenceChild residenceChild in community.Residence.GetChildren())
            {
                string owner = null;
                if (residenceChild.Residence.OwnerId.HasValue)
                {
                    owner = CharacterManager.Instance.GetCharacterInfo(residenceChild.Residence.OwnerId.Value)?.Name;
                }

                housingPlacedResidencesList.Residences.Add(new ServerHousingPlacedResidencesList.Residence
                {
                    RealmId       = WorldServer.RealmId,
                    ResidenceId   = residenceChild.Residence.Id,
                    PlayerName    = owner ?? "",
                    PropertyIndex = (uint)residenceChild.Residence.PropertyInfoId - 100
                });
            }

            session.EnqueueMessageEncrypted(housingPlacedResidencesList);
        }
Exemplo n.º 11
0
 private void SendChatAccept(WorldSession session)
 {
     session.EnqueueMessageEncrypted(new ServerChatAccept
     {
         Name = session.Player.Name,
         Guid = session.Player.Guid
     });
 }
Exemplo n.º 12
0
 private void SendStoreCategories(WorldSession session)
 {
     session.EnqueueMessageEncrypted(new ServerStoreCategories
     {
         StoreCategories = serverStoreCategoryCache.ToList(),
         RealCurrency    = RealCurrency.Usd
     });
 }
Exemplo n.º 13
0
        /// <summary>
        /// Create or update account <see cref="EntitlementType"/> with supplied value.
        /// </summary>
        /// <remarks>
        /// A positive value must be supplied for new entitlements otherwise an <see cref="ArgumentException"/> will be thrown.
        /// For existing entitlements a positive value will increment and a negative value will decrement the entitlement value.
        /// </remarks>
        public void SetAccountEntitlement(EntitlementType type, int value)
        {
            EntitlementEntry entry = GameTableManager.Instance.Entitlement.GetEntry((ulong)type);

            if (entry == null)
            {
                throw new ArgumentException($"Invalid entitlement type {type}!");
            }

            AccountEntitlement entitlement = SetEntitlement(accountEntitlements, entry, value,
                                                            () => new AccountEntitlement(session.Account.Id, entry, (uint)value));

            session.EnqueueMessageEncrypted(new ServerAccountEntitlement
            {
                Entitlement = type,
                Count       = entitlement.Amount
            });
        }
Exemplo n.º 14
0
 public void SendMessage(WorldSession session, string message, string name = "", ChatChannel channel = ChatChannel.System)
 {
     session.EnqueueMessageEncrypted(new ServerChat
     {
         Channel = channel,
         Name    = name,
         Text    = message,
     });
 }
Exemplo n.º 15
0
        public static void HandleRequestAmpReset(WorldSession session, ClientRequestAmpReset requestAmpReset)
        {
            // TODO: check for client validity
            // TODO: handle reset cost

            ActionSet actionSet = session.Player.SpellManager.GetActionSet(requestAmpReset.ActionSetIndex);

            actionSet.RemoveAmp(requestAmpReset.RespecType, requestAmpReset.Value);
            session.EnqueueMessageEncrypted(actionSet.BuildServerAmpList());
        }
Exemplo n.º 16
0
        public static void HandleClientEnteredWorld(WorldSession session, ClientEnteredWorld enteredWorld)
        {
            if (!session.Player.IsLoading)
            {
                throw new InvalidPacketValueException();
            }

            session.EnqueueMessageEncrypted(new ServerPlayerEnteredWorld());
            session.Player.IsLoading = false;
        }
Exemplo n.º 17
0
        public static void HandleChangeActiveActionSet(WorldSession session, ClientChangeActiveActionSet changeActiveActionSet)
        {
            session.EnqueueMessageEncrypted(new ServerChangeActiveActionSet
            {
                SpecError      = session.Player.SpellManager.SetActiveActionSet(changeActiveActionSet.ActionSetIndex),
                ActionSetIndex = session.Player.SpellManager.ActiveActionSet
            });

            session.Player.SpellManager.SendServerAbilityPoints();
        }
Exemplo n.º 18
0
        public static void HandleInnateChange(WorldSession session, ClientInnateChange innateChange)
        {
            // TODO: Validate that index exists and which ability it is

            session.Player.InnateIndex = innateChange.InnateIndex;

            session.EnqueueMessageEncrypted(new ServerPlayerInnate
            {
                InnateIndex = session.Player.InnateIndex
            });
        }
Exemplo n.º 19
0
        public static void HandleSelectRealm(WorldSession session, ClientSelectRealm selectRealm)
        {
            ServerInfo server = ServerManager.Instance.Servers.SingleOrDefault(s => s.Model.Id == selectRealm.RealmId);

            if (server == null)
            {
                throw new InvalidPacketValueException();
            }

            // clicking back or selecting the current realm also triggers this packet, client crashes if we don't ignore it
            if (server.Model.Id == WorldServer.RealmId)
            {
                return;
            }

            // TODO: Return proper error packet if server is not online
            if (!server.IsOnline)
            {
                session.EnqueueMessageEncrypted(new ServerForceKick());
                return;
            }

            byte[] sessionKeyBytes  = RandomProvider.GetBytes(16u);
            string sessionKeyString = BitConverter.ToString(sessionKeyBytes).Replace("-", "");

            session.EnqueueEvent(new TaskEvent(DatabaseManager.Instance.AuthDatabase.UpdateAccountSessionKey(session.Account, sessionKeyString),
                                               () =>
            {
                session.EnqueueMessageEncrypted(new ServerNewRealm
                {
                    SessionKey  = sessionKeyBytes,
                    GatewayData = new ServerNewRealm.Gateway
                    {
                        Address = server.Address,
                        Port    = server.Model.Port
                    },
                    RealmName = server.Model.Name,
                    Type      = (RealmType)server.Model.Type
                });
            }));
        }
Exemplo n.º 20
0
        public static void HandleCharacterSelect(WorldSession session, ClientCharacterSelect characterSelect)
        {
            Character character = session.Characters.SingleOrDefault(c => c.Id == characterSelect.CharacterId);

            if (character == null)
            {
                session.EnqueueMessageEncrypted(new ServerCharacterSelectFail
                {
                    Result = CharacterSelectResult.Failed
                });
                return;
            }

            session.Player = new Player(session, character);

            WorldEntry entry = GameTableManager.World.GetEntry(character.WorldId);

            if (entry == null)
            {
                throw new ArgumentOutOfRangeException();
            }

            switch (entry.Type)
            {
            // housing map
            case 5:
            {
                // characters logging in to a housing map are returned to their own residence
                session.EnqueueEvent(new TaskGenericEvent <Residence>(ResidenceManager.GetResidence(session.Player.Name),
                                                                      residence =>
                    {
                        if (residence == null)
                        {
                            residence = ResidenceManager.CreateResidence(session.Player);
                        }

                        ResidenceEntrance entrance = ResidenceManager.GetResidenceEntrance(residence);
                        var mapInfo = new MapInfo(entrance.Entry, 0u, residence.Id);
                        MapManager.AddToMap(session.Player, mapInfo, entrance.Position);
                    }));

                break;
            }

            default:
            {
                var mapInfo = new MapInfo(entry);
                var vector3 = new Vector3(character.LocationX, character.LocationY, character.LocationZ);
                MapManager.AddToMap(session.Player, mapInfo, vector3);
                break;
            }
            }
        }
Exemplo n.º 21
0
        public static void HandleClientEntityInteraction(WorldSession session, ClientEntityInteract entityInteraction)
        {
            switch (entityInteraction.Event)
            {
            case 37:     // Quest NPC
            {
                session.EnqueueMessageEncrypted(new Server0357
                    {
                        UnitId = entityInteraction.Guid
                    });
                break;
            }

            case 49:     // Handle Vendor
                VendorHandler.HandleClientVendor(session, entityInteraction);
                break;

            case 68:     // "MailboxActivate"
                var mailboxEntity = session.Player.Map.GetEntity <Mailbox>(entityInteraction.Guid);
                break;

            case 8:     // "HousingGuildNeighborhoodBrokerOpen"
            case 40:
            case 41:    // "ResourceConversionOpen"
            case 42:    // "ToggleAbilitiesWindow"
            case 43:    // "InvokeTradeskillTrainerWindow"
            case 45:    // "InvokeShuttlePrompt"
            case 46:
            case 47:
            case 48:     // "InvokeTaxiWindow"
            case 65:     // "MannequinWindowOpen"
            case 66:     // "ShowBank"
            case 67:     // "ShowRealmBank"
            case 69:     // "ShowDye"
            case 70:     // "GuildRegistrarOpen"
            case 71:     // "WarPartyRegistrarOpen"
            case 72:     // "GuildBankerOpen"
            case 73:     // "WarPartyBankerOpen"
            case 75:     // "ToggleMarketplaceWindow"
            case 76:     // "ToggleAuctionWindow"
            case 79:     // "TradeskillEngravingStationOpen"
            case 80:     // "HousingMannequinOpen"
            case 81:     // "CityDirectionsList"
            case 82:     // "ToggleCREDDExchangeWindow"
            case 84:     // "CommunityRegistrarOpen"
            case 85:     // "ContractBoardOpen"
            case 86:     // "BarberOpen"
            case 87:     // "MasterCraftsmanOpen"
            default:
                log.Warn($"Received unhandled interaction event {entityInteraction.Event} from Entity {entityInteraction.Guid}");
                break;
            }
        }
Exemplo n.º 22
0
        public static void HandleClientRequestPlayed(WorldSession session, ClientRequestPlayed requestPlayed)
        {
            double diff = session.Player.GetTimeSinceLastSave();

            session.EnqueueMessageEncrypted(new ServerPlayerPlayed
            {
                CreateTime        = session.Player.CreateTime,
                TimePlayedSession = (uint)(session.Player.TimePlayedSession + diff),
                TimePlayedTotal   = (uint)(session.Player.TimePlayedTotal + diff),
                TimePlayedLevel   = (uint)(session.Player.TimePlayedLevel + diff)
            });
        }
Exemplo n.º 23
0
 public static void HandleCharacterLogout(WorldSession session, ClientCharacterLogout characterLogout)
 {
     if (characterLogout.Initiated)
     {
         session.EnqueueMessageEncrypted(new ServerCharacterLogoutStart
         {
             TimeTillLogout = 30000u
         });
     }
     else
     {
         // cancel
     }
 }
Exemplo n.º 24
0
        public static void HandleClientVendor(WorldSession session, ClientEntityInteract vendor)
        {
            var vendorEntity = session.Player.Map.GetEntity <NonPlayer>(vendor.Guid);

            if (vendorEntity == null)
            {
                return;
            }

            if (vendorEntity.VendorInfo == null)
            {
                return;
            }

            session.Player.SelectedVendorInfo = vendorEntity.VendorInfo;
            var serverVendor = new ServerVendorItemsUpdated
            {
                Guid = vendor.Guid,
                SellPriceMultiplier = vendorEntity.VendorInfo.SellPriceMultiplier,
                BuyPriceMultiplier  = vendorEntity.VendorInfo.BuyPriceMultiplier,
                Unknown2            = true,
                Unknown3            = true,
                Unknown4            = false
            };

            foreach (EntityVendorCategoryModel category in vendorEntity.VendorInfo.Categories)
            {
                serverVendor.Categories.Add(new ServerVendorItemsUpdated.Category
                {
                    Index           = category.Index,
                    LocalisedTextId = category.LocalisedTextId
                });
            }
            foreach (EntityVendorItemModel item in vendorEntity.VendorInfo.Items)
            {
                serverVendor.Items.Add(new ServerVendorItemsUpdated.Item
                {
                    Index         = item.Index,
                    ItemId        = item.ItemId,
                    CategoryIndex = item.CategoryIndex,
                    Unknown6      = 0,
                    UnknownB      = new[]
                    {
                        new ServerVendorItemsUpdated.Item.UnknownItemStructure(),
                        new ServerVendorItemsUpdated.Item.UnknownItemStructure()
                    }
                });
            }
            session.EnqueueMessageEncrypted(serverVendor);
        }
Exemplo n.º 25
0
 public static void HandleHousingRandomCommunityList(WorldSession session, ClientHousingRandomCommunityList housingRandomCommunityList)
 {
     session.EnqueueMessageEncrypted(new ServerHousingRandomCommunityList
     {
         Communities =
         {
             new ServerHousingRandomCommunityList.Community
             {
                 RealmId        = WorldServer.RealmId,
                 NeighborhoodId = 123,
                 Name           = "Blame Maxtor for working on WoW instead",
                 Owner          = "Not Yet Implemented!"
             }
         }
     });
 }
Exemplo n.º 26
0
        public static void HandleChatJoin(WorldSession session, ClientChatJoin chatJoin)
        {
            ChatResult result = session.Player.ChatManager.CanJoin(chatJoin.Name, chatJoin.Password);

            if (result != ChatResult.Ok)
            {
                session.EnqueueMessageEncrypted(new ServerChatJoinResult
                {
                    Type   = chatJoin.Type,
                    Name   = chatJoin.Name,
                    Result = result
                });
                return;
            }

            session.Player.ChatManager.Join(chatJoin.Name, chatJoin.Password);
        }
Exemplo n.º 27
0
        public static void HandleHousingRandomResidenceList(WorldSession session, ClientHousingRandomResidenceList housingRandomResidenceList)
        {
            var serverHousingRandomResidenceList = new ServerHousingRandomResidenceList();

            foreach (PublicResidence residence in ResidenceManager.Instance.GetRandomVisitableResidences())
            {
                serverHousingRandomResidenceList.Residences.Add(new ServerHousingRandomResidenceList.Residence
                {
                    RealmId     = WorldServer.RealmId,
                    ResidenceId = residence.ResidenceId,
                    Owner       = residence.Owner,
                    Name        = residence.Name
                });
            }

            session.EnqueueMessageEncrypted(serverHousingRandomResidenceList);
        }
Exemplo n.º 28
0
        public static void HandleHousingRandomCommunityList(WorldSession session, ClientHousingRandomCommunityList _)
        {
            var serverHousingRandomCommunityList = new ServerHousingRandomCommunityList();

            foreach (PublicCommunity community in GlobalResidenceManager.Instance.GetRandomVisitableCommunities())
            {
                serverHousingRandomCommunityList.Communities.Add(new ServerHousingRandomCommunityList.Community
                {
                    RealmId        = WorldServer.RealmId,
                    NeighborhoodId = community.NeighbourhoodId,
                    Owner          = community.Owner,
                    Name           = community.Name
                });
            }

            session.EnqueueMessageEncrypted(serverHousingRandomCommunityList);
        }
Exemplo n.º 29
0
        private void SendStoreOffers(WorldSession session)
        {
            var storeOffers = new ServerStoreOffers();

            for (int i = 0; i < serverStoreOfferGroupCache.Count; i++)
            {
                storeOffers.OfferGroups.Add(serverStoreOfferGroupCache[i]);

                // Ensure we only send 20 Offer Groups per packet. This is the same as Live.
                if (i != 0 && i % 20 == 0 ||
                    i == serverStoreOfferGroupCache.Count - 1)
                {
                    session.EnqueueMessageEncrypted(storeOffers);
                    storeOffers.OfferGroups.Clear();
                }
            }
        }
Exemplo n.º 30
0
        /// <summary>
        /// Handle's whisper messages between 2 clients
        /// </summary>
        public void HandleWhisperChat(WorldSession session, ClientChatWhisper whisper)
        {
            ICharacter character = CharacterManager.Instance.GetCharacterInfo(whisper.PlayerName);

            if (character == null || !(character is Player player))
            {
                SendMessage(session, $"Player \"{whisper.PlayerName}\" not found.");
                return;
            }

            if (session.Player.Name == character.Name)
            {
                SendMessage(session, "You cannot send a message to yourself.");
                return;
            }

            bool crossFactionChat = ConfigurationManager <WorldServerConfiguration> .Instance.Config.CrossFactionChat;

            if (session.Player.Faction1 != character.Faction1 && !crossFactionChat)
            {
                SendMessage(session, $"Player \"{whisper.PlayerName}\" not found.", "", ChatChannel.System);
                return;
            }

            // echo message
            session.EnqueueMessageEncrypted(new ServerChat
            {
                Channel      = ChatChannel.Whisper,
                Name         = whisper.PlayerName,
                Text         = whisper.Message,
                Self         = true,
                CrossFaction = session.Player.Faction1 != character.Faction1,
                Formats      = ParseChatLinks(session, whisper.Formats).ToList()
            });

            // target player message
            player.Session.EnqueueMessageEncrypted(new ServerChat
            {
                Channel      = ChatChannel.Whisper,
                Name         = session.Player.Name,
                Text         = whisper.Message,
                CrossFaction = session.Player.Faction1 != character.Faction1,
                Formats      = ParseChatLinks(session, whisper.Formats).ToList(),
            });
        }