Exemple #1
0
        public void BroadcastMessage(ServerMessage Message, bool UsersWithRightsOnly = false)
        {
            lock (mActors)
            {
                foreach (RoomActor Actor in mActors.Values)
                {
                    if (Actor.Type == RoomActorType.UserCharacter)
                    {
                        Session Session = SessionManager.GetSessionByCharacterId(Actor.ReferenceId);

                        if (Session == null || (UsersWithRightsOnly && !CheckUserRights(Session)))
                        {
                            continue;
                        }

                        Session.SendData(Message);
                    }
                }
            }
        }
        public void BroadcastToFriends(ServerMessage ServerMessage)
        {
            List<uint> Copy = new List<uint>();

            lock (mInner)
            {
                Copy.AddRange(mInner);
            }

            foreach (uint FriendId in Copy)
            {
                Session SessionObject = SessionManager.GetSessionByCharacterId(FriendId);

                if (SessionObject == null)
                {
                    continue;
                }

                SessionObject.SendData(ServerMessage);
            }
        }
Exemple #3
0
        private static void AddToCacheIfNeeded(uint GroupId, ClientMessage Request, ServerMessage Response)
        {
            if (!CacheEnabled)
            {
                return;
            }

            mCacheController.AddIfNeeded(GroupId, Request, Response);
        }
Exemple #4
0
        public void TryAuthenticate(string Ticket, string RemoteAddress)
        {
            using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
            {
                uint AuthedUid = SingleSignOnAuthenticator.TryAuthenticate(MySqlClient, Ticket, RemoteAddress);

                if (AuthedUid <= 0)
                {
                    SessionManager.StopSession(mId);
                    return;
                }

                CharacterInfo Info = CharacterInfoLoader.GetCharacterInfo(MySqlClient, AuthedUid, mId, true);

                if (Info == null || !Info.HasLinkedSession) // not marked online = CharacterInfoLoader failed somehow
                {
                    SessionManager.StopSession(mId);
                    return;
                }

                mCharacterInfo = Info;

                mAchieventCache = new AchievementCache(MySqlClient, CharacterId);
                mBadgeCache = new BadgeCache(MySqlClient, CharacterId, mAchieventCache);

                RightsManager.CleanBadges(mCharacterInfo.Rank, this);

                if (!HasRight("login"))
                {
                    SessionManager.StopSession(mId);
                    return;
                }

                mCharacterInfo.TimestampLastOnline = UnixTimestamp.GetCurrent();

                CharacterResolverCache.AddToCache(mCharacterInfo.Id, mCharacterInfo.Username, true);

                mMessengerFriendCache = new SessionMessengerFriendCache(MySqlClient, CharacterId);
                mFavoriteRoomsCache = new FavoriteRoomsCache(MySqlClient, CharacterId);
                mRatedRoomsCache = new RatedRoomsCache();
                mInventoryCache = new InventoryCache(MySqlClient, CharacterId);
                mIgnoreCache = new UserIgnoreCache(MySqlClient, CharacterId);
                mNewItemsCache = new NewItemsCache(MySqlClient, CharacterId);
                mAvatarEffectCache = new AvatarEffectCache(MySqlClient, CharacterId);
                mQuestCache = new QuestCache(MySqlClient, CharacterId);
                mPetCache = new PetInventoryCache(MySqlClient, CharacterId);

                // Subscription manager
                MySqlClient.SetParameter("userid", CharacterId);
                DataRow Row = MySqlClient.ExecuteQueryRow("SELECT * FROM user_subscriptions WHERE user_id = @userid");

                mSubscriptionManager = (Row != null ? new ClubSubscription(CharacterId,
                    (ClubSubscriptionLevel)int.Parse((Row["subscription_level"].ToString())), (double)Row["timestamp_created"],
                    (double)Row["timestamp_expire"], (double)Row["past_time_hc"], (double)Row["past_time_vip"]) :
                    new ClubSubscription(CharacterId, ClubSubscriptionLevel.None, 0, 0, 0, 0));

                if (mSubscriptionManager.SubscriptionLevel < ClubSubscriptionLevel.VipClub)
                {
                    mBadgeCache.DisableSubscriptionBadge("ACH_VipClub");
                }

                if (mSubscriptionManager.SubscriptionLevel < ClubSubscriptionLevel.BasicClub)
                {
                    mBadgeCache.DisableSubscriptionBadge("ACH_BasicClub");
                }

                if (mCharacterInfo.IsPremium)
                {
                    ServerMessage Welcome = new ServerMessage(575);
                    Welcome.AppendInt32(1);
                    Welcome.AppendInt32(0);
                    Welcome.AppendInt32(1);
                    SendData(Welcome);
                }

                mAvatarEffectCache.CheckEffectExpiry(this);

                mAuthProcessed = true;

                SendData(AuthenticationOkComposer.Compose());
                SendData(FuseRightsListComposer.Compose(this));
                SendData(UserHomeRoomComposer.Compose(mCharacterInfo.HomeRoom));
                SendData(UserEffectListComposer.Compose(AvatarEffectCache.Effects));
                SendData(NavigatorFavoriteRoomsComposer.Compose(FavoriteRoomsCache.FavoriteRooms));
                SendData(InventoryNewItemsComposer.Compose(NewItemsCache.NewItems));
                SendData(AchievementDataListComposer.Compose(AchievementManager.Achievements.Values.ToList()));

                SendData(AvailabilityStatusMessageComposer.Compose());
                SendData(InfoFeedEnableMessageComposer.Compose(1));
                SendData(ActivityPointsMessageComposer.Compose());

                if (HasRight("moderation_tool"))
                {
                    SendData(ModerationToolComposer.Compose(this, ModerationPresets.UserMessagePresets,
                        ModerationPresets.UserActionPresets, ModerationPresets.RoomMessagePresets));

                    foreach (ModerationTicket ModTicket in ModerationTicketManager.ActiveTickets)
                    {
                        SendData(ModerationTicketComposer.Compose(ModTicket));
                    }
                }

                MessengerHandler.MarkUpdateNeeded(this, 0, true);
            }
        }
Exemple #5
0
 public void SendData(ServerMessage Message)
 {
     SendData(Message.GetBytes());
 }
Exemple #6
0
        private void ProcessData(byte[] Data)
        {
            if (Data.Length == 0)
            {
                return;
            }

            ASCIIEncoding enc = new ASCIIEncoding();
            String command = enc.GetString(Data);

            command = command.Replace("\r\n", "").Trim();
            String[] bits = command.Split(Convert.ToChar(1));

            command = bits[0];
            Session Target = null;

            switch (command)
            {
                case "status":
                    SendData("1");
                    break;

                case "human":
                    is_human = true;
                    SendData("Welcome. To get a list of commands type commands.");
                    break;

                case "close":
                case "exit":
                    SendData("Bye");
                    stop(mId);
                    break;

                case "ha":
                    if (bits.Length < 2)
                    {
                        SendData("Command must be ha <message>");
                        break;
                    }
                    string Alert = UserInputFilter.FilterString(bits[1]);
                     SessionManager.BroadcastPacket(UserAlertModernComposer.Compose("Important notice from Hotel Management", Alert));
                    break;

                case "update_catalog":
                    using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
                    {
                        CatalogManager.RefreshCatalogData(MySqlClient);
                    }
                    break;

                case "update_items":
                    using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
                    {
                        ItemDefinitionManager.Initialize(MySqlClient);
                    }
                    break;

                case "premium":
                    if (bits.Length < 3 || (bits[1] != "enable" && bits[1] != "disable"))
                    {
                        SendData("Command must be premium (enable|disable) <userid>");
                        break;
                    }

                        Target = SessionManager.GetSessionByCharacterId(Convert.ToUInt32(bits[2]));

                        if (Target == null)
                        {
                            SendData("User not online");
                            break;
                        }

                        if (bits[1] == "enable" && !Target.CharacterInfo.IsPremium)
                        {
                            Target.CharacterInfo.IsPremium = true;
                            Target.SendData(UserAlertModernComposer.Compose("Premium", "Your premium was activated"));

                            ServerMessage Welcome = new ServerMessage(575);
                            Welcome.AppendInt32(1);
                            Welcome.AppendInt32(0);
                            Welcome.AppendInt32(1);
                            Target.SendData(Welcome);
                        }
                        else if(bits[1] == "disable" && Target.CharacterInfo.IsPremium)
                        {
                            ServerMessage Welcome = new ServerMessage(575);
                            Welcome.AppendInt32(0);
                            Welcome.AppendInt32(1);
                            Welcome.AppendInt32(0);
                            Target.SendData(Welcome);

                            Target.CharacterInfo.IsPremium = false;
                            Target.SendData(UserAlertModernComposer.Compose("Premium", "Your premium was deactivated"));
                        }

                        Target.SendData(CatalogUpdatedNotificationComposer.Compose());

                        SendData("OK");

                    break;
                case "update_badges":
                    if (bits.Length < 2)
                    {
                        SendData("Command must be update_badges <userid>");
                        break;
                    }
                        Target = SessionManager.GetSessionByCharacterId(Convert.ToUInt32(bits[1]));

                        if (Target == null)
                        {
                            SendData("User not online");
                            break;
                        }

                      using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient()) {
                          Target.AchievementCache.ReloadCache(MySqlClient);
                          Target.BadgeCache.ReloadCache(MySqlClient, Target.AchievementCache);

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

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

                      }
                      SendData("OK");
                        break;

                case "":
                    break;
                default:
                    SendData("Unknown Command.");
                    break;
            }

            if (!is_human)
            {
                stop(mId);
            }
        }
Exemple #7
0
        private static void GetPublicRoomData(Session Session, ClientMessage Message)
        {
            uint RoomId = Message.PopWiredUInt32();
            RoomInfo Info = RoomInfoLoader.GetRoomInfo(RoomId);

            if (Info == null)
            {
                return;
            }

            ServerMessage PubRoomData = new ServerMessage(OpcodesOut.ROOM_PUBLIC_MODELDATA);
            PubRoomData.AppendUInt32(RoomId);
            PubRoomData.AppendStringWithBreak(Info.SWFs);
            PubRoomData.AppendUInt32(Info.Id);
            Session.SendData(PubRoomData);
        }
Exemple #8
0
        private static void GetGroupBadges(Session Session, ClientMessage Message)
        {
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.AbsoluteRoomId);

            if (Instance == null)
            {
                return;
            }

            ServerMessage xMessage = new ServerMessage(OpcodesOut.ROOM_GROUP_BADGES);
            // count
            // foreach => group id
            //         => string/wb badge code
            xMessage.AppendStringWithBreak("Ib[ZCs58116s04078s04072s52074889902cf4440630470f222ad5c6489d7");
            Session.SendData(xMessage);
        }
Exemple #9
0
 private static void GetFurniCampaigns(Session Session, ClientMessage Message)
 {
     ServerMessage FurniCampaigns = new ServerMessage(OpcodesOut.ROOM_FURNI_CAMPAIGNS);
     FurniCampaigns.AppendInt32(0);
     Session.SendData(FurniCampaigns);
 }
Exemple #10
0
 private static void IsNameTaken(Session Session, ClientMessage Message)
 {
     String Username = Message.PopString();
     using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
     {
         MySqlClient.SetParameter("username", Username);
         DataRow Taken = MySqlClient.ExecuteQueryRow("SELECT null FROM characters WHERE username = @username LIMIT 1");
         if (Taken == null)
         {
             ServerMessage awnser = new ServerMessage(571);
             awnser.AppendInt32(0);
             awnser.AppendStringWithBreak(Username);
             awnser.AppendInt32(0);
             Session.SendData(awnser);
         }
         else
         {
             Session.SendData(NameTaken.Compose(Username));
         }
     }
 }
 public static void SendDataToAllModerators(ServerMessage Message)
 {
     SessionManager.BroadcastPacket(Message, "moderation_tickets");
 }
Exemple #12
0
        public void BroadcastDataToParticipants(ServerMessage Message)
        {
            lock (mSyncRoot)
            {
                ReadOnlyCollection<RoomActor> Actors = mInstance.Actors;

                foreach (RoomActor Actor in Actors)
                {
                    if (!mResponses.ContainsKey(Actor.Id))
                    {
                        continue;
                    }

                    Session ActorSession = SessionManager.GetSessionByCharacterId(Actor.ReferenceId);

                    if (ActorSession == null)
                    {
                        continue;
                    }

                    ActorSession.SendData(Message);
                }
            }
        }
Exemple #13
0
 public static void BroadcastPacket(ServerMessage Message, string RequiredRight)
 {
     BroadcastPacket(Message.GetBytes(), RequiredRight);
 }
Exemple #14
0
 public static void BroadcastPacket(ServerMessage Message)
 {
     BroadcastPacket(Message.GetBytes(), string.Empty);
 }
Exemple #15
0
        public void TryAuthenticate(string Ticket, string RemoteAddress)
        {
            using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
            {
                uint AuthedUid = SingleSignOnAuthenticator.TryAuthenticate(MySqlClient, Ticket, RemoteAddress);

                if (AuthedUid <= 0)
                {
                    SessionManager.StopSession(mId);
                    return;
                }

                CharacterInfo Info = CharacterInfoLoader.GetCharacterInfo(MySqlClient, AuthedUid, mId, true);

                if (Info == null || !Info.HasLinkedSession) // not marked online = CharacterInfoLoader failed somehow
                {
                    SessionManager.StopSession(mId);
                    return;
                }

                mCharacterInfo = Info;

                mAchieventCache = new AchievementCache(MySqlClient, CharacterId);
                mBadgeCache = new BadgeCache(MySqlClient, CharacterId, mAchieventCache);

                if (!HasRight("login"))
                {
                    SessionManager.StopSession(mId);
                    return;
                }

                mCharacterInfo.TimestampLastOnline = UnixTimestamp.GetCurrent();

                CharacterResolverCache.AddToCache(mCharacterInfo.Id, mCharacterInfo.Username, true);

                mMessengerFriendCache = new SessionMessengerFriendCache(MySqlClient, CharacterId);
                mFavoriteRoomsCache = new FavoriteRoomsCache(MySqlClient, CharacterId);
                mRatedRoomsCache = new RatedRoomsCache();
                mInventoryCache = new InventoryCache(MySqlClient, CharacterId);
                mIgnoreCache = new UserIgnoreCache(MySqlClient, CharacterId);
                mNewItemsCache = new NewItemsCache(MySqlClient, CharacterId);
                mAvatarEffectCache = new AvatarEffectCache(MySqlClient, CharacterId);
                mQuestCache = new QuestCache(MySqlClient, CharacterId);
                mPetCache = new PetInventoryCache(MySqlClient, CharacterId);

                // Subscription manager
                MySqlClient.SetParameter("userid", CharacterId);
                DataRow Row = MySqlClient.ExecuteQueryRow("SELECT * FROM user_subscriptions WHERE user_id = @userid");

                mSubscriptionManager = (Row != null ? new ClubSubscription(CharacterId,
                    (ClubSubscriptionLevel)int.Parse((Row["subscription_level"].ToString())), (double)Row["timestamp_created"],
                    (double)Row["timestamp_expire"], (double)Row["past_time_hc"], (double)Row["past_time_vip"]) :
                    new ClubSubscription(CharacterId, ClubSubscriptionLevel.None, 0, 0, 0, 0));

                if (mSubscriptionManager.SubscriptionLevel < ClubSubscriptionLevel.VipClub)
                {
                    mBadgeCache.DisableSubscriptionBadge("ACH_VipClub");
                }

                if (mSubscriptionManager.SubscriptionLevel < ClubSubscriptionLevel.BasicClub)
                {
                    mBadgeCache.DisableSubscriptionBadge("ACH_BasicClub");
                }

                mAvatarEffectCache.CheckEffectExpiry(this);

                mAuthProcessed = true;

                SendData(AuthenticationOkComposer.Compose());
                SendData(FuseRightsListComposer.Compose(this));
                SendData(UserHomeRoomComposer.Compose(mCharacterInfo.HomeRoom));
                SendData(UserEffectListComposer.Compose(AvatarEffectCache.Effects));
                SendData(NavigatorFavoriteRoomsComposer.Compose(FavoriteRoomsCache.FavoriteRooms));
                SendData(InventoryNewItemsComposer.Compose(NewItemsCache.NewItems));
                SendData(MessageOfTheDayComposer.Compose("Welcome to uberHotel.org BETA.\n\n\nThank you for participating in the uberHotel.org BETA test. We hope to gather relevant feedback and ideas to help make this hotel into a success.\n\nPlease submit any bugs, feedback, or ideas via:\nhttp://snowlight.uservoice.com\n\n\nHave fun, and thank you for joining us!"));
                SendData(AchievementDataListComposer.Compose(AchievementManager.Achievements.Values.ToList()));

                // This is available status packet (AvailabilityStatusMessageComposer)
                ServerMessage UnkMessage2 = new ServerMessage(290);
                UnkMessage2.AppendInt32(1);
                UnkMessage2.AppendInt32(0);
                SendData(UnkMessage2);

                // This is info feed packet (InfoFeedEnableMessageComposer)
                ServerMessage UnkMessage3 = new ServerMessage(517);
                UnkMessage3.AppendInt32(1); // 1 = enabled     0 = disabled  (true/false)
                SendData(UnkMessage3);

                // This is activity points message (ActivityPointsMessageComposer)  not sure how this is handled...
                ServerMessage UnkMessage4 = new ServerMessage(628);
                UnkMessage4.AppendInt32(1);
                UnkMessage4.AppendInt32(0);
                UnkMessage4.AppendInt32(2971);
                SendData(UnkMessage4);

                SendData(ClientConfigComposer.Compose(CharacterInfo.ConfigVolume, false));

                if (HasRight("moderation_tool"))
                {
                    SendData(ModerationToolComposer.Compose(this, ModerationPresets.UserMessagePresets,
                        ModerationPresets.UserActionPresets, ModerationPresets.RoomMessagePresets));

                    foreach (ModerationTicket ModTicket in ModerationTicketManager.ActiveTickets)
                    {
                        SendData(ModerationTicketComposer.Compose(ModTicket));
                    }
                }

                MessengerHandler.MarkUpdateNeeded(this, 0, true);
            }
        }