Exemplo n.º 1
0
        private static void AlertRoom(Session Session, ClientMessage Message)
        {
            if (!Session.HasRight("moderation_tool"))
            {
                return;
            }

            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

            if (Instance == null)
            {
                Session.SendData(NotificationMessageComposer.Compose("Could not send room alert."));
                return;
            }

            int Unknown1 = Message.PopWiredInt32();
            int AlertMode = Message.PopWiredInt32();
            string AlertMessage = Message.PopString();
            bool IsCaution = AlertMode != 3;

            Instance.SendModerationAlert(AlertMessage, IsCaution);

            using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
            {
                ModerationLogs.LogModerationAction(MySqlClient, Session, "Sent room " + (IsCaution ? "caution" : "message"),
                    "Room " + Instance.Info.Name + " (ID " + Instance.RoomId + "): '" + AlertMessage + "'");
            }
        }
Exemplo n.º 2
0
        private static void BanUser(Session Session, ClientMessage Message)
        {
            if (!Session.HasRight("moderation_tool"))
            {
                return;
            }

            uint UserId = Message.PopWiredUInt32();
            string MessageText = Message.PopString();
            double Length = (Message.PopWiredInt32() * 3600);

            Session TargetSession = SessionManager.GetSessionByCharacterId(UserId);

            if (TargetSession == null || TargetSession.HasRight("moderation_tool"))
            {
                Session.SendData(NotificationMessageComposer.Compose("This user is not online or you do not have permission to ban them.\nPlease use housekeeping to ban users that are offline."));
                return;
            }

            SessionManager.StopSession(TargetSession.Id);

            using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
            {
                ModerationBanManager.BanUser(MySqlClient, UserId, MessageText, Session.CharacterId, Length);
                ModerationLogs.LogModerationAction(MySqlClient, Session, "Banned user",
                    "User '" + TargetSession.CharacterInfo.Username + "' (ID " + TargetSession.CharacterId + ") for " +
                    Length + " hours: '" + MessageText + "'");
            }
        }
Exemplo n.º 3
0
        private static void ExecuteLatencyMonitor(object state)
        {
            ServerMessage PingMessage = PingComposer.Compose();

            lock (mSessions)
            {
                lock (mSessionsToStop)
                {
                    foreach (Session Session in mSessions.Values)
                    {
                        if (Session.Stopped || mSessionsToStop.Contains(Session.Id))
                        {
                            continue;
                        }

                        if (!Session.LatencyTestOk)
                        {
                            mSessionsToStop.Add(Session.Id);
                            continue;
                        }

                        Session.LatencyTestOk = false;
                        Session.SendData(PingMessage);
                    }
                }
            }
        }
Exemplo n.º 4
0
        private static bool HandleExchangeRedemption(Session Session, Item Item, RoomInstance Instance, ItemEventType Event, int RequestData)
        {
            switch (Event)
            {
                case ItemEventType.Interact:

                    int ItemValue = 0;
                    int.TryParse(Item.Flags, out ItemValue);

                    using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
                    {
                        if (ItemValue != 0)
                        {
                            Session.CharacterInfo.UpdateCreditsBalance(MySqlClient, ItemValue);
                            Session.SendData(CreditsBalanceComposer.Compose(Session.CharacterInfo.CreditsBalance));
                        }

                        Item.RemovePermanently(MySqlClient);
                    }

                    Instance.TakeItem(Item.Id);
                    Instance.RegenerateRelativeHeightmap();
                    break;
            }

            return true;
        }
Exemplo n.º 5
0
        private static void OnSessionLatencyTest(Session Session, ClientMessage Message)
        {
            // Sesion timer sends a number to the server and expects it right back.
            // Maybe something to do with latency testing... or a keepalive?
            // Seems like a waste of bandwith since we're using pinging

            Session.SendData(LatencyTestResponseComposer.Compose(Message.PopWiredInt32()));
        }
Exemplo n.º 6
0
        private static void InitCrypto(Session Session, ClientMessage Message)
        {
            if (Session.Authenticated)
            {
                return;
            }

            Session.SendData(SessionParamsComposer.Compose());
        }
Exemplo n.º 7
0
        private static bool HandleWired(Session Session, Item Item, RoomInstance Instance, ItemEventType Event, int RequestData, uint Opcode)
        {
            switch (Event) {
            case ItemEventType.Interact:
                switch (Item.Definition.Behavior) {
                case ItemBehavior.WiredTrigger:
                    Session.SendData (WiredFurniTriggerComposer.Compose (Item, Instance));
                    break;

                case ItemBehavior.WiredEffect:
                    Session.SendData (WiredFurniActionComposer.Compose (Item, Instance));
                    break;
                }
                break;
            case ItemEventType.Placed:
                Item.WiredData = Instance.WiredManager.LoadWired (Item.Id, Item.Definition.BehaviorData);
                break;
            case ItemEventType.Removing:
                using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient()) {
                    Instance.WiredManager.RemoveWired (Item.Id, MySqlClient);
                }

                Instance.WiredManager.DeRegisterWalkItem(Item.Id);
                break;
            case ItemEventType.UpdateTick:
                if (Item.Definition.Behavior == ItemBehavior.WiredTrigger) {
                    switch (WiredTypesUtil.TriggerFromInt (Item.Definition.BehaviorData)) {
                    case WiredTriggerTypes.periodically:
                        Instance.WiredManager.ExecuteActions (Item, null);
                        Item.RequestUpdate (Item.WiredData.Data2);
                        break;
                    case WiredTriggerTypes.at_given_time:
                        Instance.WiredManager.ExecuteActions (Item, null);
                        break;
                    }
                    return true;
                }
                Item.BroadcastStateUpdate (Instance);
                break;
            }
            return true;
        }
Exemplo n.º 8
0
        private static void TradeAccept(Session Session, ClientMessage Message)
        {
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

            if (Instance == null)
            {
                return;
            }

            Trade Trade = Instance.TradeManager.GetTradeForUser(Session.CharacterId);

            if (Trade == null || !Trade.AcceptTrade(Trade.UserOne == Session.CharacterId))
            {
                return;
            }

            ServerMessage TradeAcceptState = TradeAcceptStateComposer.Compose(Session.CharacterId, true);
            ServerMessage TradeFinalizing = (Trade.TradeStage == TradeStage.Finalizing ? TradeFinalizingComposer.Compose()
                : null);

            Session.SendData(TradeAcceptState);

            if (TradeFinalizing != null)
            {
                Session.SendData(TradeFinalizing);
            }

            Session TargetSession = SessionManager.GetSessionByCharacterId(Trade.UserOne == Session.CharacterId ?
                Trade.UserTwo : Trade.UserOne);

            if (TargetSession != null)
            {
                TargetSession.SendData(TradeAcceptState);

                if (TradeFinalizing != null)
                {
                    TargetSession.SendData(TradeFinalizing);
                }
            }
        }
Exemplo n.º 9
0
        private static void ActivateEffect(Session Session, ClientMessage Message)
        {
            AvatarEffect Effect = Session.AvatarEffectCache.GetEffect(Message.PopWiredInt32(), false, true);

            // If we do not have an effect that needs activating OR if we already have an effect
            // of this sort which IS activated, stop.
            if (Effect == null || Session.AvatarEffectCache.HasEffect(Effect.SpriteId, true))
            {
                return;
            }

            Effect.Activate();
            Session.SendData(UserEffectActivatedComposer.Compose(Effect));
        }
Exemplo n.º 10
0
        public static void EnterRoom(Session Session, RoomInstance Instance)
        {
            if (!Session.RoomAuthed || Session.RoomJoined || Session.AbsoluteRoomId != Instance.RoomId)
            {
                return;
            }

            Session.SendData(RoomUrlComposer.Compose("http://www.meth0d.org/snowlight"));
            Session.SendData(RoomEntryModelComposer.Compose(Instance.Model.Id, Instance.Info.Id));

            if (Instance.Info.Type == RoomType.Flat)
            {
                Dictionary<string, string> Decorations = Instance.Info.Decorations;

                foreach (KeyValuePair<string, string> Decoration in Decorations)
                {
                    Session.SendData(RoomDecorationComposer.Compose(Decoration.Key, Decoration.Value));
                }

                Session.SendData(RoomRatingInfoComposer.Compose((Session.RatedRoomsCache.HasRatedRoom(Instance.RoomId) || Instance.CheckUserRights(Session, true)) ? Instance.Info.Score : -1));
                Session.SendData(RoomEventInfoComposer.Compose(Instance.Event));
            }
        }
Exemplo n.º 11
0
        public static void BroadcastPacket(byte[] Data, string RequiredRight)
        {
            lock (mSessions)
            {
                foreach (Session Session in mSessions.Values)
                {
                    if (Session == null || Session.Stopped || !Session.Authenticated ||
                        (RequiredRight.Length > 0 && !Session.HasRight(RequiredRight)))
                    {
                        continue;
                    }

                    Session.SendData(Data);
                }
            }
        }
Exemplo n.º 12
0
        private static void GetIgnoredUsers(Session Session, ClientMessage Message)
        {
            ReadOnlyCollection<uint> IgnoredUsers = Session.IgnoreCache.List;
            List<string> Names = new List<string>();

            foreach (uint IgnoredUser in IgnoredUsers)
            {
                string Name = CharacterResolverCache.GetNameFromUid(IgnoredUser);

                if (Name != "Unknown User" && !Names.Contains(Name))
                {
                    Names.Add(Name);
                }
            }

            Session.SendData(IgnoredUserListComposer.Compose(Names));
        }
Exemplo n.º 13
0
        private static void ExecuteLatencyMonitor()
        {
            try
            {
                while (Program.Alive)
                {
                    ServerMessage PingMessage = PingComposer.Compose();

                    lock (mSessions)
                    {
                        lock (mSessionsToStop)
                        {
                            foreach (Session Session in mSessions.Values)
                            {
                                if (Session.Stopped || mSessionsToStop.Contains(Session.Id))
                                {
                                    continue;
                                }

                                if (!Session.LatencyTestOk)
                                {
                                    mSessionsToStop.Add(Session.Id);
                                    continue;
                                }

                                Session.LatencyTestOk = false;
                                Session.SendData(PingMessage);
                            }
                        }
                    }

                    Thread.Sleep(45000);
                }
            }
            catch (ThreadAbortException) { }
            catch (ThreadInterruptedException) { }
        }
Exemplo n.º 14
0
        private static void GetFriendsRooms(Session Session, ClientMessage Message)
        {
            ServerMessage Response = TryGetResponseFromCache(Session.CharacterId, Message);

            if (Response != null)
            {
                Session.SendData(Response);
                return;
            }

            List<RoomInfo> Rooms = new List<RoomInfo>();
            ReadOnlyCollection<uint> Friends = Session.MessengerFriendCache.Friends;

            if (Friends.Count > 0)
            {
                using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
                {
                    StringBuilder QueryBuilder = new StringBuilder("SELECT * FROM rooms WHERE ");

                    int i = 0;

                    foreach (uint FriendId in Friends)
                    {
                        if (i >= 1)
                        {
                            QueryBuilder.Append("OR ");
                        }

                        QueryBuilder.Append("owner_id = " + FriendId + " ");
                        i++;
                    }

                    QueryBuilder.Append("ORDER BY current_users DESC LIMIT 50");

                    DataTable Table = MySqlClient.ExecuteQueryTable(QueryBuilder.ToString());

                    foreach (DataRow Row in Table.Rows)
                    {
                        Rooms.Add(RoomInfoLoader.GenerateRoomInfoFromRow(Row));
                    }
                }
            }

            Response = NavigatorRoomListComposer.Compose(0, 3, string.Empty, Rooms);
            AddToCacheIfNeeded(Session.CharacterId, Message, Response);
            Session.SendData(Response);
        }
Exemplo n.º 15
0
        private static void GetCategories(Session Session, ClientMessage Message)
        {
            ServerMessage Response = TryGetResponseFromCache(0, Message);

            if (Response != null)
            {
                Session.SendData(Response);
                return;
            }

            Response = NavigatorFlatCategoriesComposer.Compose(mFlatCategories);
            AddToCacheIfNeeded(0, Message, Response);
            Session.SendData(Response);
        }
Exemplo n.º 16
0
        private static void GetEventRooms(Session Session, ClientMessage Message)
        {
            ServerMessage Response = TryGetResponseFromCache(0, Message);

            if (Response != null)
            {
                Session.SendData(Response);
                return;
            }

            int Category = -1;
            int.TryParse(Message.PopString(), out Category);

            IEnumerable<RoomInstance> Rooms =
                (from RoomInstance in RoomManager.RoomInstances
                 where (RoomInstance.Value.HasOngoingEvent &&
                     (Category == -1 || RoomInstance.Value.Event.CategoryId == Category))
                 orderby RoomInstance.Value.Event.TimestampStarted descending
                 select RoomInstance.Value).Take(50);

            Response = NavigatorRoomListComposer.Compose(Category, 12, string.Empty, Rooms.ToList(), true);
            AddToCacheIfNeeded(0, Message, Response);
            Session.SendData(Response);
        }
Exemplo n.º 17
0
        public static void FindNewFriends(Session Session, ClientMessage Message)
        {
            IEnumerable<RoomInstance> SelectedInstance =
                (from RoomInstance in RoomManager.RoomInstances
                 where (RoomInstance.Value.HumanActorCount > 0 &&
                    RoomInstance.Value.Info.AccessType == RoomAccessType.Open &&
                    RoomInstance.Value.HumanActorCount < RoomInstance.Value.Info.MaxUsers &&
                    RoomInstance.Value.Info.Type == RoomType.Flat)
                 orderby RoomInstance.Value.HumanActorCount descending
                 select RoomInstance.Value).Take(1);

            if (SelectedInstance.Count() != 1)
            {
                Session.SendData(FriendBarResultComposer.Compose(false));
                return;
            }

            Session.SendData(FriendBarResultComposer.Compose(true));
            Session.SendData(MessengerFollowResultComposer.Compose(SelectedInstance.First().Info));
        }
Exemplo n.º 18
0
        public static void GetUserRooms(Session Session, ClientMessage Message)
        {
            ServerMessage Response = TryGetResponseFromCache(Session.CharacterId, Message);

            if (Response != null)
            {
                Session.SendData(Response);
                return;
            }

            List<RoomInfo> Rooms = new List<RoomInfo>();

            using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
            {
                MySqlClient.SetParameter("ownerid", Session.CharacterId);
                MySqlClient.SetParameter("limit", MaxRoomsPerUser);
                DataTable Table = MySqlClient.ExecuteQueryTable("SELECT * FROM rooms WHERE owner_id = @ownerid ORDER BY name ASC LIMIT @limit");

                foreach (DataRow Row in Table.Rows)
                {
                    Rooms.Add(RoomInfoLoader.GenerateRoomInfoFromRow(Row));
                }
            }

            Response = NavigatorRoomListComposer.Compose(0, 5, string.Empty, Rooms);
            AddToCacheIfNeeded(Session.CharacterId, Message, Response);
            Session.SendData(Response);
        }
Exemplo n.º 19
0
 private static void GetList(Session Session, ClientMessage Message)
 {
     Session.SendData(AchievementListComposer.Compose(Session, mAchievements.Values.ToList().AsReadOnly()));
 }
Exemplo n.º 20
0
        public static bool ProgressUserAchievement(SqlDatabaseClient MySqlClient, Session Session, string AchievementGroup, int ProgressAmount)
        {
            if (!mAchievements.ContainsKey(AchievementGroup))
            {
                return false;
            }

            Achievement AchievementData = null;

            lock (mSyncRoot)
            {
                AchievementData = mAchievements[AchievementGroup];
            }

            UserAchievement UserData = Session.AchievementCache.GetAchievementData(AchievementGroup);

            int TotalLevels = AchievementData.Levels.Count;

            if (UserData != null && UserData.Level == TotalLevels)
            {
                return false; // done, no more.
            }

            int TargetLevel = (UserData != null ? UserData.Level + 1 : 1);

            if (TargetLevel > TotalLevels)
            {
                TargetLevel = TotalLevels;
            }

            AchievementLevel TargetLevelData = AchievementData.Levels[TargetLevel];

            int NewProgress = (UserData != null ? UserData.Progress + ProgressAmount : ProgressAmount);
            int NewLevel = (UserData != null ? UserData.Level : 0);
            int NewTarget = NewLevel + 1;

            if (NewTarget > TotalLevels)
            {
                NewTarget = TotalLevels;
            }

            if (NewProgress >= TargetLevelData.Requirement)
            {
                NewLevel++;
                NewTarget++;

                int ProgressRemainder = NewProgress - TargetLevelData.Requirement;
                NewProgress = 0;

                Badge BadgeData = RightsManager.GetBadgeByCode(AchievementGroup + TargetLevel);

                if (NewTarget > TotalLevels)
                {
                    NewTarget = TotalLevels;
                }

                Session.BadgeCache.UpdateAchievementBadge(MySqlClient, AchievementGroup, BadgeData);
                Session.NewItemsCache.MarkNewItem(MySqlClient, 4, BadgeData.Id);
                Session.SendData(InventoryNewItemsComposer.Compose(4, BadgeData.Id));

                Session.CharacterInfo.UpdateActivityPointsBalance(MySqlClient, TargetLevelData.PixelReward);
                Session.SendData(ActivityPointsBalanceComposer.Compose(Session.CharacterInfo.ActivityPointsBalance,
                    TargetLevelData.PixelReward));

                Session.SendData(AchievementUnlockedComposer.Compose(AchievementData, TargetLevel, TargetLevelData.PointsReward,
                    TargetLevelData.PixelReward));

                Session.AchievementCache.AddOrUpdateData(MySqlClient, AchievementGroup, NewLevel, NewProgress);

                Session.CharacterInfo.UpdateScore(MySqlClient, TargetLevelData.PointsReward);
                Session.SendData(AchievementScoreUpdateComposer.Compose(Session.CharacterInfo.Score));

                AchievementLevel NewLevelData = AchievementData.Levels[NewTarget];
                Session.SendData(AchievementProgressComposer.Compose(AchievementData, NewTarget, NewLevelData,
                    TotalLevels, Session.AchievementCache.GetAchievementData(AchievementGroup)));

                Session.SendInfoUpdate();

                Session.MessengerFriendCache.BroadcastToFriends(MessengerFriendEventComposer.Compose(Session.CharacterId,
                    MessengerFriendEventType.AchievementUnlocked, BadgeData.Code));

                RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

                if (Instance != null)
                {
                    Instance.BroadcastMessage(RoomUserBadgesComposer.Compose(Session.CharacterId,
                        Session.BadgeCache.EquippedBadges));
                }

                if (ProgressRemainder > 0)
                {
                    ProgressUserAchievement(MySqlClient, Session, AchievementGroup, ProgressRemainder);
                }

                return true;
            }

            Session.AchievementCache.AddOrUpdateData(MySqlClient, AchievementGroup, NewLevel, NewProgress);
            Session.SendData(AchievementProgressComposer.Compose(AchievementData, TargetLevel, TargetLevelData,
            TotalLevels, Session.AchievementCache.GetAchievementData(AchievementGroup)));
            return false;
        }
Exemplo n.º 21
0
 private static void GetUserInfo(Session Session, ClientMessage Message)
 {
     Session.SendData(UserObjectComposer.Compose(Session));
     Session.SendData(AchievementScoreUpdateComposer.Compose(Session.CharacterInfo.Score));
 }
Exemplo n.º 22
0
        private static void GetOfficialRooms(Session Session, ClientMessage Message)
        {
            ServerMessage Response = TryGetResponseFromCache(0, Message);

            if (Response != null)
            {
                Session.SendData(Response);
                return;
            }

            Response = NavigatorOfficialRoomsComposer.Message(mOfficialItems);
            AddToCacheIfNeeded(0, Message, Response);
            Session.SendData(Response);
        }
Exemplo n.º 23
0
        private static void PerformSearch(Session Session, ClientMessage Message)
        {
            ServerMessage Response = TryGetResponseFromCache(0, Message);

            if (Response != null)
            {
                Session.SendData(Response);
                return;
            }

            Dictionary<uint, RoomInfo> Rooms = new Dictionary<uint, RoomInfo>();
            string Query = UserInputFilter.FilterString(Message.PopString()).ToLower().Trim();
            int SearchEventCatId = 0;

            if (mEventSearchQueries.ContainsKey(Query.ToLower()))
            {
                SearchEventCatId = mEventSearchQueries[Query.ToLower()];
            }

            // Limit query length. just a precaution.
            if (Query.Length > 64)
            {
                Query = Query.Substring(0, 64);
            }

            if (Query.Length > 0)
            {
                IEnumerable<RoomInstance> InstanceMatches =
                    (from RoomInstance in RoomManager.RoomInstances
                    where RoomInstance.Value.HumanActorCount > 0 &&
                        RoomInstance.Value.Info.Type == RoomType.Flat &&
                        (RoomInstance.Value.Info.OwnerName.StartsWith(Query) ||
                        RoomInstance.Value.SearchableTags.Contains(Query) ||
                        RoomInstance.Value.Info.Name.Contains(Query) ||
                        (RoomInstance.Value.HasOngoingEvent &&
                        (RoomInstance.Value.Event.Name.StartsWith(Query) ||
                        (SearchEventCatId > 0 && RoomInstance.Value.Event.CategoryId == SearchEventCatId))))
                    orderby RoomInstance.Value.HumanActorCount descending
                    select RoomInstance.Value).Take(50);

                foreach (RoomInstance Instance in InstanceMatches)
                {
                    Rooms.Add(Instance.RoomId, Instance.Info);
                }

                if (Rooms.Count < 50) // need db results?
                {
                    using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
                    {
                        MySqlClient.SetParameter("query", Query + "%");
                        MySqlClient.SetParameter("fquery", "%" + Query + "%");

                        uint ToUid = CharacterResolverCache.GetUidFromName(Query);

                        if (ToUid > 0)
                        {
                            MySqlClient.SetParameter("owneruid", ToUid);
                        }

                        DataTable Table = MySqlClient.ExecuteQueryTable("SELECT * FROM rooms WHERE name LIKE @query AND type = 'flat' OR tags LIKE @fquery AND type = 'flat'" + (ToUid > 0 ? " OR owner_id = @owneruid AND type = 'flat'" : string.Empty) + " LIMIT 50");

                        foreach (DataRow Row in Table.Rows)
                        {
                            uint RoomId = (uint)Row["id"];

                            if (!Rooms.ContainsKey(RoomId))
                            {
                                Rooms.Add(RoomId, RoomInfoLoader.GenerateRoomInfoFromRow(Row));
                            }
                        }
                    }
                }
            }

            Response = NavigatorRoomListComposer.Compose(1, 9, Query, Rooms.Values.Take(50).ToList());
            AddToCacheIfNeeded(0, Message, Response);
            Session.SendData(Response);
        }
Exemplo n.º 24
0
        private static void GetRecentRooms(Session Session, ClientMessage Message)
        {
            ServerMessage Response = TryGetResponseFromCache(Session.CharacterId, Message);

            if (Response != null)
            {
                Session.SendData(Response);
                return;
            }

            List<uint> VisitedUids = new List<uint>();
            List<RoomInfo> Rooms = new List<RoomInfo>();

            using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
            {
                MySqlClient.SetParameter("userid", Session.CharacterId);
                DataTable Table = MySqlClient.ExecuteQueryTable("SELECT room_id FROM room_visits WHERE user_id = @userid ORDER BY timestamp_entered DESC LIMIT 50");

                foreach (DataRow Row in Table.Rows)
                {
                    uint Id = (uint)Row["room_id"];

                    if (VisitedUids.Contains(Id))
                    {
                        continue;
                    }

                    RoomInfo Info = RoomInfoLoader.GetRoomInfo(Id);

                    if (Info == null || Info.Type == RoomType.Public)
                    {
                        continue;
                    }

                    Rooms.Add(Info);
                    VisitedUids.Add(Info.Id);
                }
            }

            Response = NavigatorRoomListComposer.Compose(0, 7, string.Empty, Rooms);
            AddToCacheIfNeeded(Session.CharacterId, Message, Response);
            Session.SendData(Response);
        }
Exemplo n.º 25
0
        private static void GetPopularTags(Session Session, ClientMessage Message)
        {
            ServerMessage Response = TryGetResponseFromCache(0, Message);

            if (Response != null)
            {
                Session.SendData(Response);
                return;
            }

            IEnumerable<List<string>> Tags =
                (from RoomInstance in RoomManager.RoomInstances
                 where RoomInstance.Value.HumanActorCount > 0
                 orderby RoomInstance.Value.HumanActorCount descending
                 select RoomInstance.Value.SearchableTags).Take(50);

            Dictionary<string, int> TagValues = new Dictionary<string, int>();

            foreach (List<string> TagList in Tags)
            {
                foreach (string Tag in TagList)
                {
                    if (!TagValues.ContainsKey(Tag))
                    {
                        TagValues.Add(Tag, 1);
                    }
                    else
                    {
                        TagValues[Tag]++;
                    }
                }
            }

            List<KeyValuePair<string, int>> SortedTags = new List<KeyValuePair<string, int>>(TagValues);

            SortedTags.Sort((FirstPair, NextPair) =>
            {
                return FirstPair.Value.CompareTo(NextPair.Value);
            });

            SortedTags.Reverse();

            Response = NavigatorPopularTagListComposer.Compose(SortedTags);
            AddToCacheIfNeeded(0, Message, Response);
            Session.SendData(Response);
        }
Exemplo n.º 26
0
        private static void GetPopularRooms(Session Session, ClientMessage Message)
        {
            ServerMessage Response = TryGetResponseFromCache(0, Message);

            if (Response != null)
            {
                Session.SendData(Response);
                return;
            }

            int Category = -1;
            int.TryParse(Message.PopString(), out Category);

            IEnumerable<RoomInstance> Rooms =
                (from RoomInstance in RoomManager.RoomInstances
                 where RoomInstance.Value.Info.Type == RoomType.Flat &&
                    RoomInstance.Value.CachedNavigatorUserCount > 0 &&
                    (Category == -1 || RoomInstance.Value.Info.CategoryId == Category)
                 orderby RoomInstance.Value.CachedNavigatorUserCount descending
                 select RoomInstance.Value).Take(50);

            Response = NavigatorRoomListComposer.Compose(Category, 1, string.Empty, Rooms.ToList());
            AddToCacheIfNeeded(0, Message, Response);
            Session.SendData(Response);
        }
Exemplo n.º 27
0
 private static void GetBadgeInventory(Session Session, ClientMessage Message)
 {
     Session.SendData(UserBadgeInventoryComposer.Compose(Session.BadgeCache.Badges, Session.BadgeCache.EquippedBadges));
 }
Exemplo n.º 28
0
        private static void GetRatedRooms(Session Session, ClientMessage Message)
        {
            ServerMessage Response = TryGetResponseFromCache(0, Message);

            if (Response != null)
            {
                Session.SendData(Response);
                return;
            }

            List<RoomInfo> Rooms = new List<RoomInfo>();

            using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
            {
                DataTable Table = MySqlClient.ExecuteQueryTable("SELECT * FROM rooms WHERE type = 'flat' AND score > 0 ORDER BY score DESC LIMIT 50");

                foreach (DataRow Row in Table.Rows)
                {
                    Rooms.Add(RoomInfoLoader.GenerateRoomInfoFromRow(Row));
                }
            }

            Response = NavigatorRoomListComposer.Compose(0, 2, string.Empty, Rooms);
            AddToCacheIfNeeded(0, Message, Response);
            Session.SendData(Response);
        }
Exemplo n.º 29
0
 private static void GetObjectInventory(Session Session, ClientMessage Message)
 {
     Session.SendData(InventoryComposer.Compose("S", Session.InventoryCache.GetFloorItems().Values.ToList()));
     Session.SendData(InventoryComposer.Compose("I", Session.InventoryCache.GetWallItems().Values.ToList()));
 }
Exemplo n.º 30
0
        private static void GetRoomsWithFriends(Session Session, ClientMessage Message)
        {
            ServerMessage Response = TryGetResponseFromCache(Session.CharacterId, Message);

            if (Response != null)
            {
                Session.SendData(Response);
                return;
            }

            List<uint> RoomUids = new List<uint>();
            ReadOnlyCollection<uint> Friends = Session.MessengerFriendCache.Friends;

            foreach (uint FriendId in Friends)
            {
                Session FriendSession = SessionManager.GetSessionByCharacterId(FriendId);

                if (FriendSession != null && FriendSession.CurrentRoomId > 0)
                {
                    RoomUids.Add(FriendSession.CurrentRoomId);
                }
            }

            IEnumerable<RoomInstance> Rooms =
                (from RoomInstance in RoomManager.RoomInstances
                 where RoomUids.Contains(RoomInstance.Value.RoomId)
                 select RoomInstance.Value).Take(50);

            Response = NavigatorRoomListComposer.Compose(0, 4, string.Empty, Rooms.ToList());
            AddToCacheIfNeeded(Session.CharacterId, Message, Response);
            Session.SendData(Response);
        }
Exemplo n.º 31
0
 private static void GetPetInventory(Session Session, ClientMessage Message)
 {
     Session.SendData(PetInventoryComposer.Compose(Session.PetInventoryCache.Pets));
 }
Exemplo n.º 32
0
        private static void RemoveFavorite(Session Session, ClientMessage Message)
        {
            uint RoomId = Message.PopWiredUInt32();

            if (Session.FavoriteRoomsCache.RemoveRoomFromFavorites(RoomId))
            {
                Session.SendData(NavigatorFavoriteRoomsChanged.Compose(RoomId, false));
            }

            ClearCacheGroup(Session.CharacterId);
        }
Exemplo n.º 33
0
        private static void GetWardrobe(Session Session, ClientMessage Message)
        {
            int SlotAmount = GetWardrobeSlotAmountForSession(Session);

            if (SlotAmount == 0)
            {
                return;
            }

            Dictionary<int, WardrobeItem> ValidItems = new Dictionary<int, WardrobeItem>();

            foreach (KeyValuePair<int, WardrobeItem> Item in Session.CharacterInfo.Wardrobe)
            {
                if (Item.Key > SlotAmount)
                {
                    continue;
                }

                ValidItems.Add(Item.Key, Item.Value);
            }

            Session.SendData(UserWardrobeComposer.Compose(new Dictionary<int, WardrobeItem>(ValidItems)));
        }