public static ServerMessage Compose(ModerationTicket Ticket, RoomInfo Info, ReadOnlyCollection<ModerationChatlogEntry> Entries)
        {
            ServerMessage Message = new ServerMessage(OpcodesOut.MODERATION_CHATLOGS_TICKET);
            Message.AppendUInt32(Ticket.Id);
            Message.AppendUInt32(Ticket.ReporteeUserId);
            Message.AppendUInt32(Ticket.ReportedUserId);
            Message.AppendUInt32(Ticket.Id); // Number to display in title. Chatlog ID?
            Message.AppendBoolean(Info != null ? Info.Type == RoomType.Public : false);
            Message.AppendUInt32(Info != null ? Info.Id : 0);
            Message.AppendStringWithBreak(Info != null ? Info.Name : "(Unknown room)");

            Message.AppendInt32(Entries.Count);

            foreach (ModerationChatlogEntry Entry in Entries)
            {
                DateTime Time = UnixTimestamp.GetDateTimeFromUnixTimestamp(Entry.Timestamp);

                Message.AppendInt32(Time.Hour);
                Message.AppendInt32(Time.Minute);
                Message.AppendUInt32(Entry.UserId);
                Message.AppendStringWithBreak(Entry.UserName);
                Message.AppendStringWithBreak(Entry.Message);
            }

            return Message;
        }
 public static ServerMessage Compose(RoomInfo Info)
 {
     ServerMessage Message = new ServerMessage(OpcodesOut.MESSENGER_FOLLOW_RESULT);
     Message.AppendBoolean(Info.Type == RoomType.Public);
     Message.AppendUInt32(Info.Id);
     return Message;
 }
        public static ServerMessage Compose(RoomInfo Info, ReadOnlyCollection<ModerationChatlogEntry> Entries)
        {
            ServerMessage Message = new ServerMessage(OpcodesOut.MODERATION_CHATLOGS_ROOM);
            Message.AppendBoolean(Info.Type == RoomType.Public);
            Message.AppendUInt32(Info.Id);
            Message.AppendStringWithBreak(Info.Name);
            Message.AppendInt32(Entries.Count);

            foreach (ModerationChatlogEntry Entry in Entries)
            {
                DateTime Time = UnixTimestamp.GetDateTimeFromUnixTimestamp(Entry.Timestamp);

                Message.AppendInt32(Time.Hour);
                Message.AppendInt32(Time.Minute);
                Message.AppendUInt32(Entry.UserId);
                Message.AppendStringWithBreak(CharacterResolverCache.GetNameFromUid(Entry.UserId));
                Message.AppendStringWithBreak(Entry.Message);
            }

            return Message;
        }
Пример #4
0
        public static ServerMessage Compose(RoomInfo Info, bool IsLoading = true, bool CheckEntry = false)
        {
            ServerMessage Message = new ServerMessage(OpcodesOut.ROOM_INFO);
            Message.AppendBoolean(IsLoading); // UPDATE=FALSE, DURINGLOAD=TRUE, STALKING=FALSE
            Message.AppendUInt32(Info.Id);
            Message.AppendInt32(0); // Nothing else has ever been logged
            Message.AppendStringWithBreak(Info.Name);
            Message.AppendStringWithBreak(Info.OwnerName);
            Message.AppendInt32((int)Info.AccessType);
            Message.AppendInt32(Info.CurrentUsers);
            Message.AppendInt32(Info.MaxUsers);
            Message.AppendStringWithBreak(Info.Description);
            Message.AppendInt32(0); // Nothing else has ever been logged
            Message.AppendBoolean(Info.CanTrade); // Allow trading
            Message.AppendInt32(0); // Nothing else has ever been logged
            Message.AppendInt32(Info.CategoryId);
            Message.AppendStringWithBreak(string.Empty); // Nothing else has ever been logged
            Message.AppendInt32(Info.Tags.Count);

            foreach (string Tag in Info.Tags)
            {
                Message.AppendStringWithBreak(Tag);
            }

            Message.AppendInt32(Info.Icon.BackgroundImageId);
            Message.AppendInt32(Info.Icon.OverlayImageId);
            Message.AppendInt32(Info.Icon.Objects.Count);

            foreach (KeyValuePair<int, int> Object in Info.Icon.Objects)
            {
                Message.AppendInt32(Object.Key);
                Message.AppendInt32(Object.Value);
            }

            Message.AppendBoolean(Info.AllowPets);
            Message.AppendBoolean(true); // Always
            Message.AppendBoolean(CheckEntry); // stuff
            Message.AppendBoolean(false); // Always
            return Message;
        }
Пример #5
0
        public static ServerMessage Compose(RoomInfo Info, RoomInstance Instance)
        {
            ReadOnlyCollection<string> Tags = Info.Tags;
            RoomEvent Event = (Instance == null ? null : Instance.Event);

            ServerMessage Message = new ServerMessage(OpcodesOut.MODERATION_ROOM_INFO);
            Message.AppendUInt32(Info.Id);
            Message.AppendInt32(Info.CurrentUsers);
            Message.AppendBoolean(Instance == null ? false : (Instance.GetActorByReferenceId(Info.OwnerId) != null));
            Message.AppendUInt32(Info.OwnerId);
            Message.AppendStringWithBreak(Info.OwnerName);
            Message.AppendUInt32(Info.Id);
            Message.AppendStringWithBreak(Info.Name);
            Message.AppendStringWithBreak(Info.Description);
            Message.AppendInt32(Tags.Count);

            foreach (string Tag in Tags)
            {
                Message.AppendStringWithBreak(Tag);
            }

            Message.AppendBoolean(Event != null);

            if (Event != null)
            {
                List<string> EventTags = Event.Tags;

                Message.AppendStringWithBreak(Event.Name);
                Message.AppendStringWithBreak(Event.Description);
                Message.AppendInt32(EventTags.Count);

                foreach (string Tag in EventTags)
                {
                    Message.AppendStringWithBreak(Tag);
                }
            }

            return Message;
        }
Пример #6
0
        public static void SerializeRoom(ServerMessage Message, RoomInfo Info, RoomEvent EventData = null)
        {
            bool ShowingEvent = (EventData != null);

            Message.AppendUInt32(Info.Id);                                                  // Actual priv room ID
            Message.AppendBoolean(ShowingEvent);                                         // Unknown
            Message.AppendStringWithBreak(ShowingEvent ? EventData.Name : Info.Name);                                       // Name
            Message.AppendStringWithBreak(Info.OwnerName);                                  // Descr
            Message.AppendInt32((int)Info.AccessType);                                      // Room state
            Message.AppendInt32(Info.CurrentUsers);           // Users now
            Message.AppendInt32(Info.MaxUsers);                                             // Users max
            Message.AppendStringWithBreak(ShowingEvent ? EventData.Description : Info.Description);                                // Descr
            Message.AppendInt32(0);                                                         // Unknown
            Message.AppendBoolean(Info.CanTrade);                                                   // Enable trade
            Message.AppendInt32(Info.Score);                                                // Score
            Message.AppendInt32(ShowingEvent? EventData.CategoryId : Info.CategoryId);                                           // Category
            Message.AppendStringWithBreak(ShowingEvent ? EventData.TimeStartedString : string.Empty);                                              // Unknown, seems no effect
            Message.AppendInt32(Info.Tags.Count);                                           // Tag count

            foreach (string Tag in Info.Tags)
            {
                Message.AppendStringWithBreak(Tag);
            }

            Message.AppendInt32(Info.Icon.BackgroundImageId);                               // Icon bg
            Message.AppendInt32(Info.Icon.OverlayImageId);                                  // Icon overlay
            Message.AppendInt32(Info.Icon.Objects.Count);                           // Icon fg count

            foreach (KeyValuePair<int, int> Data in Info.Icon.Objects)
            {
                Message.AppendInt32(Data.Key);
                Message.AppendInt32(Data.Value);
            }

            Message.AppendInt32(0);                                                         // Added in R63; unknown. Seems to have no effect.
            Message.AppendInt32(1);                                                         // Eof message, unknown
        }
Пример #7
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));
        }
Пример #8
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);
        }
Пример #9
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));
        }
Пример #10
0
        public void Dispose()
        {
            if (!mUnloaded)
            {
                Unload();
            }

            mUpdater.Dispose();
            mUpdater = null;
            mInfo = null;
        }
Пример #11
0
        public void Dispose()
        {
            if (!mUnloaded)
            {
                Unload();
            }

            mInfo = null;
        }