Пример #1
0
        public static void ReloadCache(SqlDatabaseClient MySqlClient)
        {
            lock (mSyncRoot)
            {
                mCharacterBlacklist.Clear();
                mRemoteAddressBlacklist.Clear();

                MySqlClient.SetParameter("timestamp", UnixTimestamp.GetCurrent());
                DataTable Table = MySqlClient.ExecuteQueryTable("SELECT * FROM bans WHERE timestamp_expire > @timestamp");

                foreach (DataRow Row in Table.Rows)
                {
                    uint UserId = (uint)Row["user_id"];
                    string RemoteAddr = (string)Row["remote_address"];

                    if (UserId > 0 && !mCharacterBlacklist.Contains(UserId))
                    {
                        mCharacterBlacklist.Add(UserId);
                    }

                    if (RemoteAddr.Length > 0 && !mRemoteAddressBlacklist.Contains(RemoteAddr))
                    {
                        mRemoteAddressBlacklist.Add(RemoteAddr);
                    }
                }
            }
        }
Пример #2
0
        public FavoriteRoomsCache(SqlDatabaseClient MySqlClient, uint CharacterId)
        {
            mCharacterId = CharacterId;
            mInner = new List<uint>();

            ReloadCache(MySqlClient);
        }
Пример #3
0
        public static void ReloadRewards(SqlDatabaseClient MySqlClient)
        {
            lock (mSyncRoot)
            {
                DataTable Table = MySqlClient.ExecuteQueryTable("SELECT * FROM recycler_rewards");

                int UniqueLevels = 0;

                foreach (DataRow Row in Table.Rows)
                {
                    int RewardLevel = (int)Row["chance_level"];

                    if (!mRewards.ContainsKey(RewardLevel))
                    {
                        mRewards.Add(RewardLevel, new List<uint>());
                        UniqueLevels++;
                    }

                    mRewards[RewardLevel].Add((uint)Row["item_id"]);
                }

                if (UniqueLevels != 5)
                {
                    Output.WriteLine("Recycler is not configured correctly and will *not* work properly. Please ensure there are 5 unique reward levels.", OutputLevel.Warning);
                    mEnabled = false;
                }
                else
                {
                    mEnabled = true;
                }
            }
        }
Пример #4
0
        public InventoryCache(SqlDatabaseClient MySqlClient, uint CharacterId)
        {
            mCharacterId = CharacterId;
            mInner = new Dictionary<uint, Item>();

            ReloadCache(MySqlClient);
        }
Пример #5
0
        public static void Initialize(SqlDatabaseClient MySqlClient)
        {
            mBadges = new Dictionary<uint, Badge>();
            mRightSets = new Dictionary<uint,List<string>>();

            RebuildCache(MySqlClient);
        }
Пример #6
0
        public static CharacterInfo GetCharacterInfo(SqlDatabaseClient MySqlClient, uint CharacterId, uint LinkedClientId, bool IgnoreCache)
        {
            if (SessionManager.ContainsCharacterId(CharacterId))
            {
                Session Session = SessionManager.GetSessionByCharacterId(CharacterId);
                return Session.CharacterInfo;
            }

            if (!IgnoreCache)
            {
                CharacterInfo CachedInfo = TryGetInfoFromCache(CharacterId);

                if (CachedInfo != null)
                {
                    return CachedInfo;
                }
            }

            MySqlClient.SetParameter("id", CharacterId);
            DataRow Row = MySqlClient.ExecuteQueryRow("SELECT * FROM characters WHERE id = @id LIMIT 1");

            if (Row != null)
            {
                return GenerateCharacterInfoFromRow(MySqlClient, LinkedClientId, Row);
            }

            return null;
        }
Пример #7
0
        public CharacterInfo(SqlDatabaseClient MySqlClient, uint SessionId, uint Id, string Username, string RealName, string Figure, 
            CharacterGender Gender, string Motto, int Credits, int ActivityPoints, double ActivityPointsLastUpdate,
            bool PrivacyAcceptFriends, uint HomeRoom, int Score, int ConfigVolume, int ModerationTickets,
            int ModerationTicketsAbusive, double ModerationTicketCooldown, int ModerationBans, int ModerationCautions,
            double TimestampLastOnline, double TimestampRegistered, int RespectPoints, int RespectCreditHuman,
            int RespectCreditPets, double ModerationMutedUntil)
        {
            mSessionId = SessionId;
            mId = Id;
            mUsername = Username;
            mRealName = RealName;
            mFigure = Figure;
            mGender = Gender;
            mMotto = Motto;
            mCredits = Credits;

            mActivityPoints = ActivityPoints;
            mPrivacyAcceptFriends = PrivacyAcceptFriends;
            mHomeRoom = HomeRoom;
            mScore = Score;
            mConfigVolume = ConfigVolume;

            mRespectPoints = RespectPoints;
            mRespectCreditHuman = RespectCreditHuman;
            mRespectCreditPets = RespectCreditPets;

            mModerationTickets = ModerationTickets;
            mModerationTicketsAbusive = ModerationTicketsAbusive;
            mModerationTicketsCooldown = ModerationTicketCooldown;
            mModerationCautions = ModerationCautions;
            mModerationBans = ModerationBans;
            mModerationMutedUntil = ModerationMutedUntil;

            mCacheAge = UnixTimestamp.GetCurrent();
            mTimestampLastActivityPointsUpdate = ActivityPointsLastUpdate;
            mTimestampLastOnline = TimestampLastOnline;
            mTimestampRegistered = TimestampRegistered;

            mWardrobe = new Dictionary<int, WardrobeItem>();
            mTags = new List<string>();

            if (MySqlClient != null)
            {
                MySqlClient.SetParameter("userid", mId);
                DataTable Table = MySqlClient.ExecuteQueryTable("SELECT * FROM wardrobe WHERE user_id = @userid LIMIT 10");

                foreach (DataRow Row in Table.Rows)
                {
                    mWardrobe.Add((int)Row["slot_id"], new WardrobeItem((string)Row["figure"], (Row["gender"].ToString().ToLower() == "m" ? CharacterGender.Male : CharacterGender.Female)));
                }

                MySqlClient.SetParameter("userid", mId);
                DataTable TagsTable = MySqlClient.ExecuteQueryTable("SELECT * FROM tags WHERE user_id = @userid");

                foreach (DataRow Row in TagsTable.Rows)
                {
                    mTags.Add((string)Row["tag"]);
                }
            }
        }
Пример #8
0
        public static void Initialize(SqlDatabaseClient MySqlClient)
        {
            mSets = new Dictionary<int, DrinkSet>();

            DataTable Table = MySqlClient.ExecuteQueryTable("SELECT * FROM drink_sets");

            foreach (DataRow Row in Table.Rows)
            {
                int Id = (int)Row["id"];
                string[] DrinkData = Row["drinks"].ToString().Split(',');

                List<int> Drinks = new List<int>();

                foreach (string Drink in DrinkData)
                {
                    int i = 0;
                    int.TryParse(Drink, out i);

                    if (i > 0)
                    {
                        Drinks.Add(i);
                    }
                }

                if (Drinks.Count > 0)
                {
                    mSets.Add(Id, new DrinkSet(Id, Drinks));
                }
            }
        }
Пример #9
0
        public static bool FriendshipExists(SqlDatabaseClient MySqlClient, uint UserId1, uint UserId2, bool ConfirmedOnly)
        {
            MySqlClient.SetParameter("user1", UserId1);
            MySqlClient.SetParameter("user2", UserId2);
            MySqlClient.SetParameter("confirmed", (ConfirmedOnly ? 0 : 2));

            return (MySqlClient.ExecuteQueryRow("SELECT null FROM messenger_friendships WHERE user_1_id = @user1 AND user_2_id = @user2 AND confirmed != @confirmed OR user_2_id = @user1 AND user_1_id = @user2 AND confirmed != @confirmed LIMIT 1") != null);
        }
Пример #10
0
        public NewItemsCache(SqlDatabaseClient MySqlClient, uint UserId)
        {
            mUserId = UserId;
            mInner = new Dictionary<int, List<uint>>();
            mSyncRoot = new object();

            ReloadCache(MySqlClient);
        }
Пример #11
0
        public static void Initialize(SqlDatabaseClient MySqlClient)
        {
            mRaces = new Dictionary<int, List<PetRaceData>>();
            mTricks = new Dictionary<int, List<string>>();
            mSyncRoot = new object();

            ReloadData(MySqlClient);
        }
Пример #12
0
        public PetInventoryCache(SqlDatabaseClient MySqlClient, uint CharacterId)
        {
            mCharacterId = CharacterId;
            mInner = new Dictionary<uint, Pet>();
            mSyncRoot = new object();

            ReloadCache(MySqlClient);
        }
Пример #13
0
        public QuestCache(SqlDatabaseClient MySqlClient, uint UserId)
        {
            mUserId = UserId;
            mInner = new Dictionary<uint, int>();
            mSyncRoot = new object();

            ReloadCache(MySqlClient);
        }
Пример #14
0
        public SessionMessengerFriendCache(SqlDatabaseClient MySqlClient, uint UserId)
        {
            mCharacterId = UserId;
            mInner = new List<uint>();
            mInnerUpdates = new Dictionary<uint, int>();

            ReloadCache(MySqlClient);
        }
Пример #15
0
        public AchievementCache(SqlDatabaseClient MySqlClient, uint UserId)
        {
            mUserId = UserId;
            mInner = new Dictionary<string, UserAchievement>();
            mSyncRoot = new object();

            ReloadCache(MySqlClient);
        }
Пример #16
0
        public UserIgnoreCache(SqlDatabaseClient MySqlClient, uint UserId)
        {
            mUserId = UserId;
            mInner = new List<uint>();
            mSyncRoot = new object();

            ReloadCache(MySqlClient);
        }
Пример #17
0
        public static void Initialize(SqlDatabaseClient MySqlClient)
        {
            mUserMessagePresets = new List<string>();
            mRoomMessagePresets = new List<string>();
            mUserActionPresetCategories = new Dictionary<uint, string>();
            mUserActionPresetMessages = new Dictionary<uint, Dictionary<string, string>>();

            Reload(MySqlClient);
        }
Пример #18
0
        public static void Initialize(SqlDatabaseClient MySqlClient)
        {
            mAchievements = new Dictionary<string, Achievement>();
            mSyncRoot = new object();

            ReloadAchievements(MySqlClient);

            DataRouter.RegisterHandler(OpcodesIn.ACHIEVEMENTS_GET_LIST, new ProcessRequestCallback(GetList));
        }
Пример #19
0
        public static void Reload(SqlDatabaseClient MySqlClient)
        {
            int i = 0;

            mUserMessagePresets.Clear();
            mRoomMessagePresets.Clear();
            mUserActionPresetCategories.Clear();
            mUserActionPresetMessages.Clear();

            DataTable BasicPresetTable = MySqlClient.ExecuteQueryTable("SELECT type,message FROM moderation_presets");

            foreach (DataRow Row in BasicPresetTable.Rows)
            {
                string Message = (string)Row["message"];

                switch ((string)Row["type"])
                {
                    case "room":

                        mRoomMessagePresets.Add(Message);
                        break;

                    case "user":

                        mUserMessagePresets.Add(Message);
                        break;
                }

                i++;
            }

            DataTable UserActionCategoryTable = MySqlClient.ExecuteQueryTable("SELECT id,caption FROM moderation_preset_action_categories");

            foreach (DataRow Row in UserActionCategoryTable.Rows)
            {
                mUserActionPresetCategories.Add((uint)Row["id"], (string)Row["caption"]);
                i++;
            }

            DataTable UserActionMsgTable = MySqlClient.ExecuteQueryTable("SELECT id,parent_id,caption,message_text FROM moderation_preset_action_messages");

            foreach (DataRow Row in UserActionMsgTable.Rows)
            {
                uint ParentId = (uint)Row["parent_id"];

                if (!mUserActionPresetMessages.ContainsKey(ParentId))
                {
                    mUserActionPresetMessages.Add(ParentId, new Dictionary<string, string>());
                }

                mUserActionPresetMessages[ParentId].Add((string)Row["caption"], (string)Row["message_text"]);
                i++;
            }

            Output.WriteLine("Loaded " + i + " moderation categories and presets.", OutputLevel.DebugInformation);
        }
Пример #20
0
        public static void Initialize(SqlDatabaseClient MySqlClient)
        {
            mCharacterBlacklist = new List<uint>();
            mRemoteAddressBlacklist = new List<string>();
            mSyncRoot = new object();

            mWorker = new Timer(new TimerCallback(ProcessThread), null, TimeSpan.FromMinutes(5), TimeSpan.FromMinutes(5));

            ReloadCache(MySqlClient);
        }
Пример #21
0
 public static void CreateFriendship(SqlDatabaseClient MySqlClient, uint UserId1, uint UserId2, bool Confirmed)
 {
     for (int i = 0; i < (Confirmed ? 2 : 1); i++)
     {
         MySqlClient.SetParameter("user1", (i == 1 ? UserId1 : UserId2));
         MySqlClient.SetParameter("user2", (i == 1 ? UserId2 : UserId1));
         MySqlClient.SetParameter("accepted", (int)(Confirmed ? 1 : 0));
         MySqlClient.ExecuteNonQuery("INSERT INTO messenger_friendships (user_1_id,user_2_id,confirmed) VALUES (@user1,@user2,@accepted)");
     }
 }
Пример #22
0
 public static void ReloadCache(SqlDatabaseClient MySqlClient)
 {
     mBlockedWords = new List<String>();
     DataTable words = MySqlClient.ExecuteQueryTable("SELECT word FROM wordfilter");
     foreach (DataRow Row in words.Rows)
     {
         if(!mBlockedWords.Contains((string)Row["word"])) {
             mBlockedWords.Add((string)Row["word"]);
         }
     }
 }
Пример #23
0
        public static void DeleteRoom(SqlDatabaseClient MySqlClient, uint RoomId)
        {
            MySqlClient.SetParameter("id", RoomId);
            MySqlClient.ExecuteNonQuery("DELETE FROM rooms WHERE id = @id LIMIT 1");

            MySqlClient.SetParameter("id", RoomId);
            MySqlClient.ExecuteNonQuery("DELETE FROM navigator_frontpage WHERE room_id = @id");

            RoomInfoLoader.RemoveFromCache(RoomId);
            Navigator.ReloadOfficialItems(MySqlClient);
        }
Пример #24
0
        public static void Initialize(SqlDatabaseClient MySqlClient)
        {
            mRewards = new Dictionary<int, List<uint>>();
            mSyncRoot = new object();

            ReloadRewards(MySqlClient);

            DataRouter.RegisterHandler(OpcodesIn.CATALOG_GET_RECYCLER_REWARDS, new ProcessRequestCallback(GetRewardsList));
            DataRouter.RegisterHandler(OpcodesIn.CATALOG_GET_RECYCLER_CONFIG, new ProcessRequestCallback(GetConfig));
            DataRouter.RegisterHandler(OpcodesIn.CATALOG_RECYCLE_ITEMS, new ProcessRequestCallback(RecycleItems));
        }
Пример #25
0
        public BadgeCache(SqlDatabaseClient MySqlClient, uint UserId, AchievementCache UserAchievementCache)
        {
            mUserId = UserId;
            mSyncRoot = new object();

            mEquippedBadges = new Dictionary<int, Badge>();
            mStaticBadges = new List<Badge>();
            mAchievementBadges = new Dictionary<string, Badge>();
            mIndexCache = new List<string>();

            ReloadCache(MySqlClient, UserAchievementCache);
        }
Пример #26
0
        public static void Initialize(SqlDatabaseClient MySqlClient)
        {
            mQuests = new Dictionary<uint, Quest>();
            mSyncRoot = new object();

            ReloadQuests(MySqlClient);

            DataRouter.RegisterHandler(OpcodesIn.QUESTS_GET_LIST, new ProcessRequestCallback(GetList));
            DataRouter.RegisterHandler(OpcodesIn.QUESTS_ACTIVATE, new ProcessRequestCallback(ActivateQuest));
            DataRouter.RegisterHandler(OpcodesIn.QUESTS_GET_CURRENT, new ProcessRequestCallback(GetCurrentQuest));
            DataRouter.RegisterHandler(OpcodesIn.QUESTS_CANCEL, new ProcessRequestCallback(CancelQuest));
        }
Пример #27
0
 public static CharacterInfo GenerateCharacterInfoFromRow(SqlDatabaseClient MySqlClient, uint LinkedClientId, DataRow Row)
 {
     return new CharacterInfo(MySqlClient, LinkedClientId, (uint)Row["id"], (string)Row["username"], (string)Row["real_name"],
         (string)Row["figure"], (Row["gender"].ToString() == "M" ? CharacterGender.Male : CharacterGender.Female),
         (string)Row["motto"], (int)Row["credits_balance"], (int)Row["activity_points_balance"],
         (double)Row["activity_points_last_update"], (Row["privacy_accept_friends"].ToString() == "1"),
         (uint)Row["home_room"], (int)Row["score"], (int)Row["config_volume"],
         (int)Row["moderation_tickets"], (int)Row["moderation_tickets_abusive"], (double)Row["moderation_tickets_cooldown"],
         (int)Row["moderation_bans"], (int)Row["moderation_cautions"], (double)Row["timestamp_lastvisit"],
         (double)Row["timestamp_created"], (int)Row["respect_points"], (int)Row["respect_credit_humans"],
         (int)Row["respect_credit_pets"], (double)Row["moderation_muted_until_timestamp"]);
 }
Пример #28
0
        public static void Initialize(SqlDatabaseClient MySqlClient)
        {
            mCharacterBlacklist = new List<uint>();
            mRemoteAddressBlacklist = new List<string>();
            mSyncRoot = new object();

            mWorkerThread = new Thread(new ThreadStart(ProcessThread));
            mWorkerThread.Name = "ModerationBanManager";
            mWorkerThread.Priority = ThreadPriority.Lowest;
            mWorkerThread.Start();

            ReloadCache(MySqlClient);
        }
Пример #29
0
        public static bool DestroyFriendship(SqlDatabaseClient MySqlClient, uint UserId1, uint UserId2)
        {
            int aff = 0;

            for (int i = 0; i < 2; i++)
            {
                MySqlClient.SetParameter("user1", (i == 1 ? UserId1 : UserId2));
                MySqlClient.SetParameter("user2", (i == 1 ? UserId2 : UserId1));
                aff += MySqlClient.ExecuteNonQuery("DELETE FROM messenger_friendships WHERE user_1_id = @user1 AND user_2_id = @user2 LIMIT 1");
            }

            return (aff > 0);
        }
Пример #30
0
        public static void BanUser(SqlDatabaseClient MySqlClient, uint UserId, string MessageText, uint ModeratorId, double Length)
        {
            MySqlClient.SetParameter("userid", UserId);
            MySqlClient.SetParameter("reason", MessageText);
            MySqlClient.SetParameter("timestamp", UnixTimestamp.GetCurrent());
            MySqlClient.SetParameter("timestampex", UnixTimestamp.GetCurrent() + Length);
            MySqlClient.SetParameter("moderator", ModeratorId);
            MySqlClient.ExecuteNonQuery("INSERT INTO bans (user_id,reason_text,timestamp_created,timestamp_expire,moderator_id) VALUES (@userid,@reason,@timestamp,@timestampex,@moderator)");

            lock (mSyncRoot)
            {
                mCharacterBlacklist.Add(UserId);
            }
        }