Exemplo n.º 1
0
        public static void CleanBadges(uint Rank, Session Session)
        {
            Boolean changed = false;

            foreach (String badge in mRightsBages.Values)
            {
                if (mRightsBages.ContainsValue(badge) && !mRightsBages.ContainsKey(Rank) || mRightsBages[Rank] != badge)
                {
                    Session.BadgeCache.RemoveBadge(badge);
                    changed = true;
                }

                if (mRightsBages.ContainsKey(Rank) && mRightsBages[Rank] == badge && !Session.BadgeCache.ContainsCode(badge))
                {
                    Session.BadgeCache.AddBadge(badge);
                    changed = true;
                }
            }

            if (changed)
            {
                using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
                {
                    Session.BadgeCache.ReloadCache(MySqlClient, Session.AchievementCache);
                }
            }
        }
Exemplo n.º 2
0
        public static ServerMessage Compose(Session Session, Dictionary<int, CatalogPage> Pages)
        {
            ServerMessage Message = new ServerMessage(OpcodesOut.CATALOG_INDEX);
            SerializePage(Message, Pages[-1], CalcTreeSize(Session, Pages, -1));

            foreach (CatalogPage Page in Pages.Values)
            {
                if (Page.ParentId != -1 || (Page.RequiredRight.Length > 0 && !Session.HasRight(Page.RequiredRight)))
                {
                    continue;
                }

                SerializePage(Message, Page, CalcTreeSize(Session, Pages, Page.Id));

                foreach (CatalogPage ChildPage in Pages.Values)
                {
                    if (ChildPage.ParentId != Page.Id || (ChildPage.RequiredRight.Length > 0 && !Session.HasRight(ChildPage.RequiredRight)))
                    {
                        continue;
                    }

                    SerializePage(Message, ChildPage, 0);
                }
            }

            return Message;
        }
Exemplo n.º 3
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.º 4
0
        private static void SubmitAnswer(Session Session, ClientMessage Message)
        {
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

            if (Instance == null)
            {
                return;
            }

            RoomActor Actor = Instance.GetActorByReferenceId(Session.CharacterId);

            if (Actor == null)
            {
                return;
            }

            int AnswerId = Message.PopWiredInt32();

            lock (mInfobusQuestions)
            {
                if (mInfobusQuestions.ContainsKey(Instance.RoomId))
                {
                    mInfobusQuestions[Instance.RoomId].SubmitAnswer(Actor.Id, AnswerId);
                }
            }
        }
Exemplo n.º 5
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.º 6
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.º 7
0
        public static ServerMessage Compose(Session Session, ReadOnlyCollection<Achievement> Achievements)
        {
            ServerMessage Message = new ServerMessage(OpcodesOut.ACHIEVEMENTS_LIST);
            Message.AppendInt32(Achievements.Count);

            foreach (Achievement Achievement in Achievements)
            {
                UserAchievement UserData = Session.AchievementCache.GetAchievementData(Achievement.GroupName);
                int TargetLevel = (UserData != null ? UserData.Level + 1 : 1);
                int TotalLevels = Achievement.Levels.Count;

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

                AchievementLevel TargetLevelData = Achievement.Levels[TargetLevel];

                Message.AppendUInt32(Achievement.Id);                                                           // Unknown (ID?)
                Message.AppendInt32(TargetLevel);                                                   // Target level
                Message.AppendStringWithBreak(Achievement.GroupName + TargetLevel);                 // Target name/desc/badge
                Message.AppendInt32(TargetLevelData.Requirement);                                   // Progress req/target
                Message.AppendInt32(TargetLevelData.PixelReward);                                   // Pixel reward
                Message.AppendInt32(TargetLevelData.PointsReward);                                  // Unknown(??)
                Message.AppendInt32(UserData != null ? UserData.Progress : 0);                      // Current progress
                Message.AppendBoolean(UserData != null ? (UserData.Level >= TotalLevels) : false);  // Set 100% completed(??)
                Message.AppendStringWithBreak(Achievement.Category);                                // Category
                Message.AppendInt32(TotalLevels);                                                   // Total amount of levels
            }

            return Message;
        }
Exemplo n.º 8
0
        private static void DeleteSticky(Session Session, ClientMessage Message)
        {
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

            if (Instance == null || !Instance.CheckUserRights(Session, true))
            {
                return;
            }

            Item Item = Instance.GetItem(Message.PopWiredUInt32());

            if (Item == null || Item.Definition.Behavior != ItemBehavior.StickyNote)
            {
                return;
            }

            if (Instance.TakeItem(Item.Id))
            {
                Instance.RegenerateRelativeHeightmap();

                using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
                {
                    Item.RemovePermanently(MySqlClient);
                }
            }
        }
Exemplo n.º 9
0
        private static void ApplyEffect(Session Session, ClientMessage Message)
        {
            int EffectSpriteId = Message.PopWiredInt32();

            if (EffectSpriteId < 0)
            {
                EffectSpriteId = 0;
            }

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

            if (Instance == null)
            {
                return;
            }

            RoomActor Actor = Instance.GetActorByReferenceId(Session.CharacterId);

            if (Actor == null || (EffectSpriteId != 0 && !Session.AvatarEffectCache.HasEffect(EffectSpriteId, true)))
            {
                return;
            }

            Actor.ApplyEffect(EffectSpriteId);
            Session.CurrentEffect = EffectSpriteId;
        }
Exemplo n.º 10
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.º 11
0
        private static void InitCrypto(Session Session, ClientMessage Message)
        {
            if (Session.Authenticated)
            {
                return;
            }

            Session.SendData(SessionParamsComposer.Compose());
        }
Exemplo n.º 12
0
        private static void SsoLogin(Session Session, ClientMessage Message)
        {
            if (Session.Authenticated)
            {
                return;
            }

            string Ticket = UserInputFilter.FilterString(Message.PopString());
            Session.TryAuthenticate(Ticket, Session.RemoteAddress.ToString());
        }
Exemplo n.º 13
0
        private static void OnUserAgent(Session Session, ClientMessage Message)
        {
            string UserAgent = Message.PopString();

            if (UserAgent.Length > 2000)
            {
                UserAgent = UserAgent.Substring(0, 2000);
            }

            Session.UserAgent = UserAgent;
        }
Exemplo n.º 14
0
        public bool CheckUserRights(Session Session, bool RequireOwnership = false)
        {
            bool IsOwner = (Session.HasRight("room_rights_owner") || Session.CharacterId == Info.OwnerId);

            if (RequireOwnership)
            {
                return IsOwner;
            }

            return (IsOwner || Session.HasRight("room_rights") || mUsersWithRights.Contains(Session.CharacterId));
        }
Exemplo n.º 15
0
        private static void TradeComplete(Session Session, ClientMessage Message)
        {
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

            if (Instance == null)
            {
                return;
            }

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

            if (Trade == null)
            {
                return;
            }

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

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

            if (Trade.TradeStage == TradeStage.Finalized)
            {
                Session User1 = (TargetSession.CharacterId == Trade.UserOne ? TargetSession : Session);
                Session User2 = (TargetSession.CharacterId == Trade.UserTwo ? TargetSession : Session);

                Trade.DeliverItems(User1, User2);

                Session.SendData(TradeFinalizedComposer.Compose());
                TargetSession.SendData(TradeFinalizedComposer.Compose());

                Instance.TradeManager.StopTradeForUser(Session.CharacterId);
                Instance.TradeManager.StopTradeForUser(TargetSession.CharacterId);

                RoomActor Actor1 = Instance.GetActorByReferenceId(Session.CharacterId);
                RoomActor Actor2 = Instance.GetActorByReferenceId(TargetSession.CharacterId);

                if (Actor1 != null)
                {
                    Actor1.RemoveStatus("trd");
                    Actor1.UpdateNeeded = true;
                }

                if (Actor2 != null)
                {
                    Actor2.RemoveStatus("trd");
                    Actor2.UpdateNeeded = true;
                }
            }
        }
Exemplo n.º 16
0
 public static void InvokeItemEventHandler(Session Session, Item Item, RoomInstance Instance, ItemEventType Type, int RequestData = 0, uint Opcode = 0, bool checkrights = true)
 {
     if (mEventHandlers.ContainsKey(Item.Definition.Behavior))
     {
         foreach (ItemEventHandler EventHandler in mEventHandlers[Item.Definition.Behavior])
         {
             if (!EventHandler.Invoke(Session, Item, Instance, Type, RequestData, Opcode))
             {
                 return;
             }
         }
     }
 }
Exemplo n.º 17
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.º 18
0
 public static ServerMessage Compose(CharacterInfo Info, Session Session)
 {
     ServerMessage Message = new ServerMessage(OpcodesOut.MODERATION_USER_INFO);
     Message.AppendUInt32(Info.Id);
     Message.AppendStringWithBreak(Info.Username);
     Message.AppendInt32((int)(UnixTimestamp.GetCurrent() - Info.TimestampRegistered) / 60);
     Message.AppendInt32((int)(UnixTimestamp.GetCurrent() - Info.TimestampLastOnline) / 60);
     Message.AppendBoolean(Session != null);
     Message.AppendInt32(Info.ModerationTickets);
     Message.AppendInt32(Info.ModerationTicketsAbusive);
     Message.AppendInt32(Info.ModerationCautions);
     Message.AppendInt32(Info.ModerationBans);
     return Message;
 }
Exemplo n.º 19
0
        public static int GetWardrobeSlotAmountForSession(Session Session)
        {
            int WardrobeSlots = 0;

            if (Session.HasRight("club_regular"))
            {
                WardrobeSlots += 5;
            }

            if (Session.HasRight("club_vip"))
            {
                WardrobeSlots += 5;
            }

            return WardrobeSlots;
        }
Exemplo n.º 20
0
 public static void InvokeItemEventHandler(Session Session, Item Item, RoomInstance Instance, ItemEventType Type, int RequestData = 0)
 {
     lock (mSyncRoot)
     {
         if (mEventHandlers.ContainsKey(Item.Definition.Behavior))
         {
             foreach (ItemEventHandler EventHandler in mEventHandlers[Item.Definition.Behavior])
             {
                 if (!EventHandler.Invoke(Session, Item, Instance, Type, RequestData))
                 {
                     return;
                 }
             }
         }
     }
 }
Exemplo n.º 21
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.º 22
0
        private static void OnClientConfig(Session Session, ClientMessage Message)
        {
            int Volume = Message.PopWiredInt32();
            bool Something = Message.PopWiredBoolean();

            if (Volume < 0)
            {
                Volume = 0;
            }

            if (Volume > 100)
            {
                Volume = 100;
            }

            Session.CharacterInfo.ConfigVolume = Volume;
        }
Exemplo n.º 23
0
        public static ServerMessage Compose(Session Session)
        {
            List<Item> Disks = Session.InventoryCache.GetSongDisks();

            ServerMessage Message = new ServerMessage(OpcodesOut.JUKEBOX_DISKS);
            Message.AppendInt32(Disks.Count);

            foreach (Item SongDisk in Disks)
            {
                uint SongId = 0;
                uint.TryParse(SongDisk.DisplayFlags, out SongId);

                Message.AppendUInt32(SongDisk.Id);
                Message.AppendUInt32(SongId);
            }

            return Message;
        }
Exemplo n.º 24
0
        private static void GetMoodlightInfo(Session Session, ClientMessage Message)
        {
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

            if (Instance == null || !Instance.CheckUserRights(Session, true))
            {
                return;
            }

            Item Item = Instance.MoodlightItem;

            if (Item == null)
            {
                return;
            }

            Session.SendData(MoodlightDataComposer.Compose(MoodlightData.GenerateFromFlags(Item.Flags)));
        }
Exemplo n.º 25
0
        private static bool HandleBottle(Session Session, Item Item, RoomInstance Instance, ItemEventType Event, int RequestData)
        {
            switch (Event)
            {
                case ItemEventType.Placed:
                case ItemEventType.Removing:

                    if (Item.Flags != "0")
                    {
                        Item.Flags = "0";
                        Item.DisplayFlags = "0";

                        RoomManager.MarkWriteback(Item, true);
                    }

                    break;

                case ItemEventType.Interact:

                    if (Item.Flags != "-1")
                    {
                        Item.Flags = "-1";
                        Item.DisplayFlags = "-1";

                        Item.BroadcastStateUpdate(Instance);
                        Item.RequestUpdate(4);
                    }

                    break;

                case ItemEventType.UpdateTick:

                    Item.Flags = RandomGenerator.GetNext(0, 7).ToString();
                    Item.DisplayFlags = Item.Flags;

                    Item.BroadcastStateUpdate(Instance);

                    RoomManager.MarkWriteback(Item, true);

                    break;
            }

            return true;
        }
Exemplo n.º 26
0
        private static int CalcTreeSize(Session Session, Dictionary<int, CatalogPage> Pages, int ParentId)
        {
            int Num = 0;

            foreach (CatalogPage Page in Pages.Values)
            {
                if (Page.RequiredRight.Length > 0 && !Session.HasRight(Page.RequiredRight))
                {
                    continue;
                }

                if (Page.ParentId == ParentId)
                {
                    Num++;
                }
            }

            return Num;
        }
Exemplo n.º 27
0
 public static ServerMessage Compose(Session Session)
 {
     ServerMessage Message = new ServerMessage(OpcodesOut.USER_OBJECT);
     Message.AppendStringWithBreak(Session.CharacterId.ToString());
     Message.AppendStringWithBreak(Session.CharacterInfo.Username);
     Message.AppendStringWithBreak(Session.CharacterInfo.Figure);
     Message.AppendStringWithBreak(Session.CharacterInfo.Gender == CharacterGender.Male ? "M" : "F");
     Message.AppendStringWithBreak(Session.CharacterInfo.Motto);
     Message.AppendStringWithBreak(Session.CharacterInfo.RealName);
     Message.AppendInt32(0);
     Message.AppendStringWithBreak("");
     Message.AppendInt32(0);
     Message.AppendInt32(0);
     Message.AppendInt32(Session.CharacterInfo.RespectPoints);
     Message.AppendInt32(Session.CharacterInfo.RespectCreditHuman);
     Message.AppendInt32(Session.CharacterInfo.RespectCreditPets);
     Message.AppendUInt32(24708);
     return Message;
 }
Exemplo n.º 28
0
        private static bool HandleAlert(Session Session, Item Item, RoomInstance Instance, ItemEventType Event, int RequestData)
        {
            switch (Event)
            {
                case ItemEventType.InstanceLoaded:
                case ItemEventType.Placed:
                case ItemEventType.Removing:

                    Item.Flags = "0";
                    Item.DisplayFlags = "0";
                    break;

                case ItemEventType.Interact:

                    if (!Instance.CheckUserRights(Session) || Item.Flags == "1")
                    {
                        break;
                    }

                    Item.Flags = "1";
                    Item.DisplayFlags = "1";

                    Item.RequestUpdate(4);
                    Item.BroadcastStateUpdate(Instance);
                    break;

                case ItemEventType.UpdateTick:

                    if (Item.Flags != "1")
                    {
                        break;
                    }

                    Item.Flags = "0";
                    Item.DisplayFlags = "0";

                    Item.BroadcastStateUpdate(Instance);
                    break;
            }

            return true;
        }
Exemplo n.º 29
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.º 30
0
        public static void HandleData(Session Session, ClientMessage Message)
        {
            if (Session == null || Session.Stopped || Message == null)
            {
                return;
            }

            if (!mCallbacks.ContainsKey(Message.Id))
            {
                Output.WriteLine("Unhandled packet: " + Message.Id + " (" + Constants.DefaultEncoding.GetString(Base64Encoding.EncodeUint32(Message.Id, 2)) + "), no suitable handler found.", OutputLevel.Warning);
                return;
            }

            if (!Session.Authenticated && !mCallbacksWithoutAuthentication.Contains(Message.Id))
            {
                return;
            }

            mCallbacks[Message.Id].Invoke(Session, Message);
        }