Ejemplo n.º 1
0
        public static RoomInstance TryCreateRoomInstance(uint InstanceId, uint RoomId)
        {
            RoomInfo Info = RoomInfoLoader.GetRoomInfo(RoomId);

            if (Info == null)
            {
                return(null);
            }

            RoomModel Model = Info.TryGetModel();

            if (Model == null)
            {
                return(null);
            }

            return(new RoomInstance(InstanceId, Info, Model));
        }
Ejemplo n.º 2
0
        private static void OnCreateRoom(Session Session, ClientMessage Message)
        {
            string Name      = UserInputFilter.FilterString(Message.PopString());
            string ModelName = Message.PopString().ToLower();

            if (Name.Length < 3)
            {
                return;
            }

            RoomModel Model = RoomManager.GetModel(ModelName);

            if (Model == null || !Model.IsUsableBySession(Session) || Session.CharacterInfo.GetRoomCount() >= Navigator.MaxRoomsPerUser)
            {
                return;
            }

            uint RoomId = RoomManager.CreateRoom(Session.CharacterId, Name, ModelName);

            if (RoomId > 0)
            {
                Session.SendData(RoomCreateResultComposer.Compose(RoomId, Name));
            }
        }
Ejemplo n.º 3
0
        public RoomInstance(uint InstanceId, RoomInfo Info, RoomModel Model)
        {
            mActorSyncRoot = new object();
            mItemSyncRoot  = new object();

            mInstanceId               = InstanceId;
            mInfo                     = Info;
            mActors                   = new Dictionary <uint, RoomActor>();
            mCachedModel              = Model;
            mRelativeHeightmap        = string.Empty;
            mActorIdGenerator         = 1;
            mActorIdGeneratorSyncLock = new object();
            mTileStates               = new TileState[mCachedModel.Heightmap.SizeX, mCachedModel.Heightmap.SizeY];
            mUsersWithRights          = new List <uint>();
            mBannedUsers              = new Dictionary <uint, double>();
            mItems                    = new Dictionary <uint, Item>();
            mStaticObjects            = new List <StaticObject>();
            mItemLimitCache           = new Dictionary <ItemBehavior, int>();
            mUserGrid                 = new List <RoomActor> [mCachedModel.Heightmap.SizeX, mCachedModel.Heightmap.SizeY];
            mMusicController          = new RoomMusicController();
            mTemporaryStickieRights   = new Dictionary <uint, uint>();
            mTradeManager             = new TradeManager();
            mRollerItems              = new List <Item> [mCachedModel.Heightmap.SizeX, mCachedModel.Heightmap.SizeY];
            mWiredManager             = new WiredManager(this);

            foreach (Bot Bot in BotManager.GenerateBotInstancesForRoom(RoomId))
            {
                AddBotToRoom(Bot);
            }

            using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
            {
                // Items
                MySqlClient.SetParameter("id", RoomId);
                DataTable ItemTable = MySqlClient.ExecuteQueryTable("SELECT * FROM items WHERE room_id = @id");

                foreach (DataRow Row in ItemTable.Rows)
                {
                    Item Item = ItemFactory.CreateFromDatabaseRow(Row, mWiredManager);

                    if (Item.PendingExpiration && Item.ExpireTimeLeft <= 0)
                    {
                        Item.RemovePermanently(MySqlClient);
                        continue;
                    }

                    if (Item.InSoundManager)
                    {
                        continue;
                    }

                    mItems.Add(Item.Id, Item);
                    IncrecementFurniLimitCache(Item.Definition.Behavior);

                    ItemEventDispatcher.InvokeItemEventHandler(null, Item, this, ItemEventType.InstanceLoaded);
                }

                // Static objects
                MySqlClient.SetParameter("id", RoomId);
                DataTable StaticObjectTable = MySqlClient.ExecuteQueryTable("SELECT id,name,position,height,rotation,is_seat FROM static_objects WHERE room_id = @id");

                foreach (DataRow Row in StaticObjectTable.Rows)
                {
                    mStaticObjects.Add(new StaticObject((uint)Row["id"], (string)Row["name"], Vector2.FromString((string)Row["position"]),
                                                        (int)Row["height"], (int)Row["rotation"], (Row["is_seat"].ToString() == "1")));
                }

                // Rights
                MySqlClient.SetParameter("id", RoomId);
                DataTable RightsTable = MySqlClient.ExecuteQueryTable("SELECT user_id FROM room_rights WHERE room_id = @id");

                foreach (DataRow Row in RightsTable.Rows)
                {
                    mUsersWithRights.Add((uint)Row["user_id"]);
                }

                // Pets
                MySqlClient.SetParameter("id", RoomId);
                DataTable PetsTable = MySqlClient.ExecuteQueryTable("SELECT * FROM pets WHERE room_id = @id");

                foreach (DataRow Row in PetsTable.Rows)
                {
                    Pet PetData = PetFactory.GetPetFromDatabaseRow(Row);

                    AddBotToRoom(BotManager.CreateNewInstance(BotManager.GetHandlerDefinitionForPetType(PetData.Type),
                                                              RoomId, Vector3.FromString(Row["room_pos"].ToString()), PetData));
                }
            }

            RegenerateRelativeHeightmap();

            mUpdater = new Timer(new TimerCallback(PerformUpdate), null, TimeSpan.FromMilliseconds(500), TimeSpan.FromMilliseconds(500));
        }
Ejemplo n.º 4
0
        public static void PrepareRoom(Session Session, uint RoomId, string Password = "", bool BypassAuthentication = false)
        {
            // Remove user from any previous room
            RoomManager.RemoveUserFromRoom(Session, false);

            // Try to retrieve room information
            RoomInfo Info = RoomInfoLoader.GetRoomInfo(RoomId);

            // Room not found, send kick notif and stop
            if (Info == null)
            {
                Session.SendData(RoomKickedComposer.Compose());
                return;
            }

            // Try to retrieve room model information
            RoomModel Model = Info.TryGetModel();

            // Model information not found, send kick notif and stop
            if (Model == null)
            {
                Session.SendData(RoomKickedComposer.Compose());
                return;
            }

            // Load room instance into the server memory if needed
            if (!RoomManager.InstanceIsLoadedForRoom(Info.Id))
            {
                RoomManager.TryLoadRoomInstance(Info.Id);
            }

            // Attempt to retrieve the instance from the server memory
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Info.Id);

            // If the instance was not created or is unavailable, send kick notif and stop
            if (Instance == null)
            {
                Session.SendData(RoomKickedComposer.Compose());
                return;
            }

            // Check if the room capacity has been reached
            if (Info.CurrentUsers >= Info.MaxUsers && !Session.HasRight("enter_full_rooms"))
            {
                Session.SendData(RoomJoinErrorComposer.Compose(1));
                Session.SendData(RoomKickedComposer.Compose());
                return;
            }

            // Check if the user has been banned from this room
            if (Instance.IsUserBanned(Session.CharacterId))
            {
                Session.SendData(RoomJoinErrorComposer.Compose(4));
                Session.SendData(RoomKickedComposer.Compose());
                return;
            }

            // Mark room as loading and check for initial authorization
            Session.AbsoluteRoomId = Info.Id;
            Session.RoomAuthed     = (BypassAuthentication || Info.OwnerId == Session.CharacterId ||
                                      Session.HasRight("enter_locked_rooms"));
            Session.RoomJoined = false;

            // Send confirmation that the initial checks have been passed (if this is a flat)
            if (Info.Type == RoomType.Flat)
            {
                Session.SendData(RoomOpenFlatComposer.Compose());
            }

            // Try to accomplish authorization (if not already initially authorized by character rights)
            if (!Session.RoomAuthed)
            {
                // Check for valid password, if needed
                if (Info.AccessType == RoomAccessType.PasswordProtected)
                {
                    if (Info.Password != Password)
                    {
                        Session.SendData(GenericErrorComposer.Compose(-100002));
                        RoomManager.RemoveUserFromRoom(Session);
                        return;
                    }
                }
                // Send doorbell, if any users are in this room.
                else if (Info.AccessType == RoomAccessType.Locked)
                {
                    if (Instance.HumanActorCount > 0)
                    {
                        Session.SendData(RoomDoorbellComposer.Compose());
                        Instance.BroadcastMessage(RoomDoorbellComposer.Compose(Session.CharacterInfo.Username), true);
                        return;
                    }
                    else
                    {
                        Session.SendData(RoomDoorbellNoResponseComposer.Compose());
                        RoomManager.RemoveUserFromRoom(Session);
                        return;
                    }
                }
            }

            // If all these stages have been passed, mark auth as OK and continue loading
            Session.RoomAuthed = true;
            EnterRoom(Session, Instance);
        }
Ejemplo n.º 5
0
        public RoomInstance(uint InstanceId, RoomInfo Info, RoomModel Model)
        {
            mActorSyncRoot = new object();
            mItemSyncRoot = new object();

            mInstanceId = InstanceId;
            mInfo = Info;
            mActors = new Dictionary<uint, RoomActor>();
            mCachedModel = Model;
            mRelativeHeightmap = string.Empty;
            mActorIdGenerator = 1;
            mActorIdGeneratorSyncLock = new object();
            mTileStates = new TileState[mCachedModel.Heightmap.SizeX, mCachedModel.Heightmap.SizeY];
            mUsersWithRights = new List<uint>();
            mBannedUsers = new Dictionary<uint, double>();
            mItems = new Dictionary<uint, Item>();
            mStaticObjects = new List<StaticObject>();
            mItemLimitCache = new Dictionary<ItemBehavior, int>();
            mUserGrid = new List<RoomActor>[mCachedModel.Heightmap.SizeX, mCachedModel.Heightmap.SizeY];
            mMusicController = new RoomMusicController();
            mTemporaryStickieRights = new Dictionary<uint, uint>();
            mTradeManager = new TradeManager();
            mRollerItems = new List<Item>[mCachedModel.Heightmap.SizeX, mCachedModel.Heightmap.SizeY];
            mWiredManager = new WiredManager(this);

            foreach (Bot Bot in BotManager.GenerateBotInstancesForRoom(RoomId))
            {
                AddBotToRoom(Bot);
            }

            using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
            {
                // Items
                MySqlClient.SetParameter("id", RoomId);
                DataTable ItemTable = MySqlClient.ExecuteQueryTable("SELECT * FROM items WHERE room_id = @id");

                foreach (DataRow Row in ItemTable.Rows)
                {
                    Item Item = ItemFactory.CreateFromDatabaseRow(Row, mWiredManager);

                    if (Item.PendingExpiration && Item.ExpireTimeLeft <= 0)
                    {
                        Item.RemovePermanently(MySqlClient);
                        continue;
                    }

                    if (Item.InSoundManager)
                    {
                        continue;
                    }

                    mItems.Add(Item.Id, Item);
                    IncrecementFurniLimitCache(Item.Definition.Behavior);

                    ItemEventDispatcher.InvokeItemEventHandler(null, Item, this, ItemEventType.InstanceLoaded);
                }

                // Static objects
                MySqlClient.SetParameter("id", RoomId);
                DataTable StaticObjectTable = MySqlClient.ExecuteQueryTable("SELECT id,name,position,height,rotation,is_seat FROM static_objects WHERE room_id = @id");

                foreach (DataRow Row in StaticObjectTable.Rows)
                {
                    mStaticObjects.Add(new StaticObject((uint)Row["id"], (string)Row["name"], Vector2.FromString((string)Row["position"]),
                        (int)Row["height"], (int)Row["rotation"], (Row["is_seat"].ToString() == "1")));
                }

                // Rights
                MySqlClient.SetParameter("id", RoomId);
                DataTable RightsTable = MySqlClient.ExecuteQueryTable("SELECT user_id FROM room_rights WHERE room_id = @id");

                foreach (DataRow Row in RightsTable.Rows)
                {
                    mUsersWithRights.Add((uint)Row["user_id"]);
                }

                // Pets
                MySqlClient.SetParameter("id", RoomId);
                DataTable PetsTable = MySqlClient.ExecuteQueryTable("SELECT * FROM pets WHERE room_id = @id");

                foreach (DataRow Row in PetsTable.Rows)
                {
                    Pet PetData = PetFactory.GetPetFromDatabaseRow(Row);

                    AddBotToRoom(BotManager.CreateNewInstance(BotManager.GetHandlerDefinitionForPetType(PetData.Type),
                        RoomId, Vector3.FromString(Row["room_pos"].ToString()), PetData));
                }
            }

            RegenerateRelativeHeightmap();

            mUpdater = new Timer(new TimerCallback(PerformUpdate), null, TimeSpan.FromMilliseconds(500), TimeSpan.FromMilliseconds(500));
        }