public Task TeleportSubCommandHandler(CommandContext context, string command, string[] parameters)
        {
            string name = parameters.Length == 0 ? context.Session.Player.Name : string.Join(" ", parameters);

            Residence residence = ResidenceManager.GetResidence(name).GetAwaiter().GetResult();

            if (residence == null)
            {
                if (parameters.Length == 0)
                {
                    residence = ResidenceManager.CreateResidence(context.Session.Player);
                }
                else
                {
                    context.SendMessageAsync("A residence for that character doesn't exist!");
                    return(Task.CompletedTask);
                }
            }

            ResidenceEntrance entrance = ResidenceManager.GetResidenceEntrance(residence);

            context.Session.Player.TeleportTo(entrance.Entry, entrance.Position, 0u, residence.Id);

            return(Task.CompletedTask);
        }
Beispiel #2
0
        public static void HandleItemUseDecor(WorldSession session, ClientItemUseDecor itemUseDecor)
        {
            Item item = session.Player.Inventory.GetItem(itemUseDecor.ItemGuid);

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

            HousingDecorInfoEntry entry = GameTableManager.HousingDecorInfo.GetEntry(item.Entry.HousingDecorInfoId);

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

            Task <Residence> task = ResidenceManager.GetResidence(session.Player.Name);

            session.EnqueueEvent(new TaskGenericEvent <Residence>(task,
                                                                  residence =>
            {
                if (residence == null)
                {
                    residence = ResidenceManager.CreateResidence(session.Player);
                }

                if (session.Player.Inventory.ItemUse(item))
                {
                    residence.DecorCreate(entry);
                }
            }));
        }
Beispiel #3
0
        private static void Main()
        {
            Directory.SetCurrentDirectory(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location));

            Console.Title = Title;
            log.Info("Initialising...");

            ConfigurationManager <WorldServerConfiguration> .Initialise("WorldServer.json");

            DatabaseManager.Initialise(ConfigurationManager <WorldServerConfiguration> .Config.Database);

            GameTableManager.Initialise();
            MapManager.Initialise();
            SearchManager.Initialise();
            EntityManager.Initialise();
            EntityCommandManager.Initialise();
            GlobalMovementManager.Initialise();

            AssetManager.Initialise();
            GlobalSpellManager.Initialise();
            ServerManager.Initialise();

            ResidenceManager.Initialise();

            // make sure the assigned realm id in the configuration file exists in the database
            RealmId = ConfigurationManager <WorldServerConfiguration> .Config.RealmId;
            if (ServerManager.Servers.All(s => s.Model.Id != RealmId))
            {
                throw new ConfigurationException($"Realm id {RealmId} in configuration file doesn't exist in the database!");
            }

            MessageManager.Initialise();
            SocialManager.Initialise();
            CommandManager.Initialise();
            NetworkManager <WorldSession> .Initialise(ConfigurationManager <WorldServerConfiguration> .Config.Network);

            WorldManager.Initialise(lastTick =>
            {
                NetworkManager <WorldSession> .Update(lastTick);
                MapManager.Update(lastTick);
                ResidenceManager.Update(lastTick);
                BuybackManager.Update(lastTick);
            });

            using (WorldServerEmbeddedWebServer.Initialise())
            {
                log.Info("Ready!");

                while (true)
                {
                    Console.Write(">> ");
                    string line = Console.ReadLine();
                    if (!CommandManager.HandleCommand(new ConsoleCommandContext(), line, false))
                    {
                        Console.WriteLine("Invalid command");
                    }
                }
            }
        }
        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;
            }
            }
        }
Beispiel #5
0
        public static void HandleHousingVisit(WorldSession session, ClientHousingVisit housingVisit)
        {
            if (!(session.Player.Map is ResidenceMap))
            {
                throw new InvalidPacketValueException();
            }

            Task <Residence> residenceTask;

            if (housingVisit.TargetResidenceName != "")
            {
                residenceTask = ResidenceManager.GetResidence(housingVisit.TargetResidenceName);
            }
            else if (housingVisit.TargetResidence.ResidenceId != 0ul)
            {
                residenceTask = ResidenceManager.GetResidence(housingVisit.TargetResidence.ResidenceId);
            }
            else
            {
                throw new NotImplementedException();
            }

            session.EnqueueEvent(new TaskGenericEvent <Residence>(residenceTask,
                                                                  residence =>
            {
                if (residence == null)
                {
                    // TODO: show error
                    return;
                }

                switch (residence.PrivacyLevel)
                {
                case ResidencePrivacyLevel.Private:
                    {
                        // TODO: show error
                        return;
                    }

                // TODO: check if player is either a neighbour or roommate
                case ResidencePrivacyLevel.NeighborsOnly:
                    break;

                case ResidencePrivacyLevel.RoommatesOnly:
                    break;
                }

                // teleport player to correct residence instance
                ResidenceEntrance entrance = ResidenceManager.GetResidenceEntrance(residence);
                session.Player.TeleportTo(entrance.Entry, entrance.Position, 0u, residence.Id);
            }));
        }
Beispiel #6
0
        public static void HandleHousingRandomResidenceList(WorldSession session, ClientHousingRandomResidenceList housingRandomResidenceList)
        {
            var serverHousingRandomResidenceList = new ServerHousingRandomResidenceList();

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

            session.EnqueueMessageEncrypted(serverHousingRandomResidenceList);
        }
Beispiel #7
0
        /// <summary>
        /// Set <see cref="ResidencePrivacyLevel"/>, this is called directly from a packet hander.
        /// </summary>
        public void SetPrivacyLevel(Player player, ClientHousingSetPrivacyLevel housingSetPrivacyLevel)
        {
            if (!residence.CanModifyResidence(player.CharacterId))
            {
                throw new InvalidPacketValueException();
            }

            if (housingSetPrivacyLevel.PrivacyLevel == ResidencePrivacyLevel.Public)
            {
                ResidenceManager.RegisterResidenceVists(residence.Id, residence.OwnerName, residence.Name);
            }
            else
            {
                ResidenceManager.DeregisterResidenceVists(residence.Id);
            }

            residence.PrivacyLevel = housingSetPrivacyLevel.PrivacyLevel;
            SendHousingPrivacy();
        }
Beispiel #8
0
        public override void Initialise(MapInfo info, Player player)
        {
            base.Initialise(info, player);

            if (info.ResidenceId != 0u)
            {
                residence = ResidenceManager.GetCachedResidence(info.ResidenceId);
                if (residence == null)
                {
                    throw new InvalidOperationException();
                }
            }
            else
            {
                residence = ResidenceManager.CreateResidence(player);
            }

            // initialise plug entities
            foreach (Plot plot in residence.GetPlots().Where(p => p.PlugEntry != null))
            {
                var plug = new Plug(plot.PlotEntry, plot.PlugEntry);
                EnqueueAdd(plug, Vector3.Zero);
            }
        }