예제 #1
0
파일: Room.cs 프로젝트: TheNaked/Firewind
 internal void AddBan(uint pId)
 {
     if (!Bans.ContainsKey(pId))
     {
         Bans.Add(pId, FirewindEnvironment.GetUnixTimestamp());
     }
 }
예제 #2
0
        internal static void GivePixels(GameClient Client, int amount)
        {
            Double Timestamp = FirewindEnvironment.GetUnixTimestamp();

            Client.GetHabbo().LastActivityPointsUpdate = Timestamp;
            Client.GetHabbo().ActivityPoints          += amount;
            Client.GetHabbo().UpdateActivityPointsBalance(0);
        }
예제 #3
0
        internal DatabaseClientOld(uint Handle, string connectionString, DatabaseManagerOld pManager)
        {
            handleID = Handle;
            manager  = pManager;

            connection            = new MySqlConnection(connectionString);
            sqlCommand            = connection.CreateCommand();
            lastActivityTimestamp = FirewindEnvironment.GetUnixTimestamp();
        }
예제 #4
0
        internal Boolean IsValid()
        {
            if (TimeExpire <= FirewindEnvironment.GetUnixTimestamp())
            {
                return false;
            }

            return true;
        }
예제 #5
0
        internal void DeliverInstantMessage(string message, int convoID)
        {
            ServerMessage InstantMessage = new ServerMessage(Outgoing.InstantChat);

            InstantMessage.AppendInt32(convoID);
            InstantMessage.AppendString(message);
            InstantMessage.AppendString(FirewindEnvironment.GetUnixTimestamp() + string.Empty);
            GetClient().SendMessage(InstantMessage);
        }
예제 #6
0
        internal static ServerMessage SerializeUserInfo(uint UserId)
        {
            using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor())
            {
                dbClient.setQuery("SELECT id, username, online, mail FROM users WHERE id = " + UserId + "");
                DataRow User = dbClient.getRow();

                dbClient.setQuery("SELECT reg_timestamp, login_timestamp, cfhs, cfhs_abusive, cautions, bans FROM user_info WHERE user_id = " + UserId + "");
                DataRow Info = dbClient.getRow();

                if (User == null)
                {
                    throw new NullReferenceException("No user found in database");
                }

                ServerMessage Message = new ServerMessage(Outgoing.UserTool);

                Message.AppendUInt(Convert.ToUInt32(User["id"]));
                Message.AppendString((string)User["username"]);

                if (Info != null)
                {
                    Message.AppendInt32((int)Math.Ceiling((FirewindEnvironment.GetUnixTimestamp() - (Double)Info["reg_timestamp"]) / 60));
                    Message.AppendInt32((int)Math.Ceiling((FirewindEnvironment.GetUnixTimestamp() - (Double)Info["login_timestamp"]) / 60));
                }
                else
                {
                    Message.AppendInt32(0);
                    Message.AppendInt32(0);
                }

                Message.AppendBoolean(FirewindEnvironment.GetGame().GetClientManager().GetClientByUserID(Convert.ToUInt32(User["id"])) != null);

                if (Info != null)
                {
                    Message.AppendInt32((int)Info["cfhs"]);
                    Message.AppendInt32((int)Info["cfhs_abusive"]);
                    Message.AppendInt32((int)Info["cautions"]);
                    Message.AppendInt32((int)Info["bans"]);
                }
                else
                {
                    Message.AppendInt32(0);                 // cfhs
                    Message.AppendInt32(0);                 // abusive cfhs
                    Message.AppendInt32(0);                 // cautions
                    Message.AppendInt32(0);                 // bans
                }
                Message.AppendString("hallo");              // last_purchase_txt
                Message.AppendInt32(0);                     // identityinformationtool.url + this
                Message.AppendInt32(0);                     // id_bans_txt
                Message.AppendString((string)User["mail"]); // email_address_txt
                return(Message);
            }
        }
예제 #7
0
 internal void SerializeClub(ServerMessage Message, GameClients.GameClient Session)
 {
     try
     {
         Message.AppendUInt(Id);
         Message.AppendString(Name);
         Message.AppendInt32(CreditsCost);
         Message.AppendBoolean(true); // don't know
         int Days   = 0;
         int Months = 0;
         if (Name.Contains("HABBO_CLUB_VIP_"))
         {
             if (Name.Contains("_DAY"))
             {
                 Days = int.Parse(Name.Split('_')[3]);
             }
             else if (Name.Contains("_MONTH"))
             {
                 Months = int.Parse(Name.Split('_')[3]);
                 Days   = 31 * Months;
             }
         }
         else if (Name.Equals("deal_vip_1_year_and_badge"))
         {
             Months = 12;
             Days   = 31 * Months;
         }
         else if (Name.Equals("HABBO_CLUB_VIP_5_YEAR"))
         {
             Months = 5 * 12;
             Days   = 31 * Months;
         }
         DateTime future = DateTime.Now;
         if (Session.GetHabbo().GetSubscriptionManager().HasSubscription("habbo_vip"))
         {
             Double Expire        = Session.GetHabbo().GetSubscriptionManager().GetSubscription("habbo_vip").ExpireTime;
             Double TimeLeft      = Expire - FirewindEnvironment.GetUnixTimestamp();
             int    TotalDaysLeft = (int)Math.Ceiling(TimeLeft / 86400);
             future = DateTime.Now.AddDays(TotalDaysLeft);
         }
         future = future.AddDays(Days);
         Message.AppendInt32(Months);       // months
         Message.AppendInt32(Days);         // days
         Message.AppendInt32(Days);         // wtf
         Message.AppendInt32(future.Year);  // year
         Message.AppendInt32(future.Month); // month
         Message.AppendInt32(future.Day);   // day
     }
     catch
     {
         //Logging.WriteLine("Unable to load club item " + Id + ": " + Name);
     }
 }
예제 #8
0
        internal void LoadBans(IQueryAdapter dbClient)
        {
            bannedUsernames.Clear();
            bannedIPs.Clear();

            dbClient.setQuery("SELECT bantype,value,reason,expire FROM bans");
            DataTable BanData = dbClient.getTable();

            double timestmp = FirewindEnvironment.GetUnixTimestamp();

            string value;
            string reason;
            string type;
            double expires;

            foreach (DataRow dRow in BanData.Rows)
            {
                value   = (string)dRow["value"];
                reason  = (string)dRow["reason"];
                expires = (double)dRow["expire"];
                type    = (string)dRow["bantype"];


                ModerationBanType banType;
                if (type == "user")
                {
                    banType = ModerationBanType.USERNAME;
                }
                else
                {
                    banType = ModerationBanType.IP;
                }


                ModerationBan ban = new ModerationBan(banType, value, reason, expires);

                if (expires > timestmp)
                {
                    if (ban.Type == ModerationBanType.USERNAME)
                    {
                        if (!bannedUsernames.ContainsKey(value))
                        {
                            bannedUsernames.Add(value, ban);
                        }
                        else
                        if (!bannedIPs.ContainsKey(value))
                        {
                            bannedIPs.Add(value, ban);
                        }
                    }
                }
            }
        }
예제 #9
0
 internal void Pick(UInt32 pModeratorId, Boolean UpdateInDb)
 {
     this.Status      = TicketStatus.PICKED;
     this.ModeratorId = pModeratorId;
     this.Timestamp   = FirewindEnvironment.GetUnixTimestamp();
     if (UpdateInDb)
     {
         using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor())
         {
             dbClient.runFastQuery("UPDATE moderation_tickets SET status = 'picked', moderator_id = " + pModeratorId + ", timestamp = '" + FirewindEnvironment.GetUnixTimestamp() + "' WHERE id = " + Id + "");
         }
     }
 }
예제 #10
0
파일: Room.cs 프로젝트: TheNaked/Firewind
        internal Boolean HasBanExpired(uint pId)
        {
            if (!UserIsBanned(pId))
            {
                return(true);
            }

            Double diff = FirewindEnvironment.GetUnixTimestamp() - Bans[pId];

            if (diff > 900)
            {
                return(true);
            }

            return(false);
        }
예제 #11
0
        public void PlaySong()
        {
            if (mSongQueuePosition >= mPlaylist.Count)
            {
                mSongQueuePosition = 0;
            }

            if (mPlaylist.Count == 0)
            {
                Stop();
                return;
            }

            mSong = mPlaylist[mSongQueuePosition];
            mStartedPlayingTimestamp = FirewindEnvironment.GetUnixTimestamp();
            mBroadcastNeeded         = true;
        }
예제 #12
0
        internal void ScrGetUserInfo()
        {
            GetResponse().Init(Outgoing.SerializeClub);
            GetResponse().AppendString("club_habbo");

            if (Session.GetHabbo().GetSubscriptionManager().HasSubscription("habbo_vip"))
            {
                Double Expire        = Session.GetHabbo().GetSubscriptionManager().GetSubscription("habbo_vip").ExpireTime;
                Double TimeLeft      = Expire - FirewindEnvironment.GetUnixTimestamp();
                int    TotalDaysLeft = (int)Math.Ceiling(TimeLeft / 86400);

                /*Double Initialized = Session.GetHabbo().GetSubscriptionManager().GetSubscription("habbo_vip").ini;
                 * Double TimeLeft = Expire - FirewindEnvironment.GetUnixTimestamp();
                 * int TotalDaysLeft = (int)Math.Ceiling(TimeLeft / 86400);*/
                int MonthsLeft = TotalDaysLeft / 31;

                if (MonthsLeft >= 1)
                {
                    MonthsLeft--;
                }

                GetResponse().AppendInt32(TotalDaysLeft - (MonthsLeft * 31)); // days left
                GetResponse().AppendInt32(2);                                 // days multiplier
                GetResponse().AppendInt32(MonthsLeft);                        // months left
                GetResponse().AppendInt32(1);                                 // ???
                GetResponse().AppendBoolean(true);                            // HC PRIVILEGE
                GetResponse().AppendBoolean(true);                            // VIP PRIVILEGE
                GetResponse().AppendInt32(0);                                 // days i have on hc
                GetResponse().AppendInt32(0);                                 // days i've purchased
                GetResponse().AppendInt32(495);                               // value 4 groups
            }
            else
            {
                GetResponse().AppendInt32(0);
                GetResponse().AppendInt32(0); // ??
                GetResponse().AppendInt32(0);
                GetResponse().AppendInt32(0); // type
                GetResponse().AppendBoolean(false);
                GetResponse().AppendBoolean(true);
                GetResponse().AppendInt32(0);
                GetResponse().AppendInt32(0); // days i have on hc
                GetResponse().AppendInt32(0); // days i have on vip
            }

            SendResponse();
        }
예제 #13
0
        internal static void ProcessThread()
        {
            double CurrentTime = FirewindEnvironment.GetUnixTimestamp();

            List <uint> ToRemove = new List <uint>();

            foreach (KeyValuePair <uint, double> CacheData in cacheTimer)
            {
                if (CurrentTime - CacheData.Value >= CACHE_LIFETIME)
                {
                    ToRemove.Add(CacheData.Key);
                }
            }

            foreach (uint RemoveId in ToRemove)
            {
                songs.Remove(RemoveId);
                cacheTimer.Remove(RemoveId);
            }
        }
예제 #14
0
        internal void AddOrExtendSubscription(string SubscriptionId, int DurationSeconds)
        {
            SubscriptionId = SubscriptionId.ToLower();

            if (Subscriptions.ContainsKey(SubscriptionId))
            {
                Subscription Sub = Subscriptions[SubscriptionId];
                if (Sub.IsValid())
                {
                    Sub.ExtendSubscription(DurationSeconds);
                }
                else
                {
                    Sub.SetEndTime(((int)FirewindEnvironment.GetUnixTimestamp() + DurationSeconds));
                }

                using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor())
                {
                    dbClient.setQuery("UPDATE user_subscriptions SET timestamp_expire = " + Sub.ExpireTime + " WHERE user_id = " + UserId + " AND subscription_id = 'habbo_vip'");
                    //dbClient.addParameter("subcrbr", SubscriptionId);
                    dbClient.runQuery();
                }

                return;
            }

            int TimeCreated = (int)FirewindEnvironment.GetUnixTimestamp();
            int TimeExpire  = ((int)FirewindEnvironment.GetUnixTimestamp() + DurationSeconds);

            Subscription NewSub = new Subscription(SubscriptionId, TimeExpire);

            using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor())
            {
                dbClient.setQuery("INSERT INTO user_subscriptions (user_id,subscription_id,timestamp_activated,timestamp_expire) VALUES (" + UserId + ",'habbo_vip'," + TimeCreated + "," + TimeExpire + ")");
                //dbClient.addParameter("subcrbr", SubscriptionId);
                dbClient.runQuery();
            }

            Subscriptions.Add(NewSub.SubscriptionId.ToLower(), NewSub);
        }
예제 #15
0
        internal static Boolean NeedsUpdate(GameClient Client)
        {
            try
            {
                if (Client.GetHabbo() == null)
                {
                    return(false);
                }

                Double PassedMins = (FirewindEnvironment.GetUnixTimestamp() - Client.GetHabbo().LastActivityPointsUpdate) / 60;

                if (PassedMins >= RCV_EVERY_MINS)
                {
                    return(true);
                }
            }
            catch (Exception e)
            {
                Logging.HandleException(e, "PixelManager.NeedsUpdate");
            }
            return(false);
        }
예제 #16
0
        private void MonitorConnections()
        {
            while (!FirewindEnvironment.ShutdownStarted)
            {
                try
                {
                    lockObject.EnterReadLock();

                    int timeStamp = FirewindEnvironment.GetUnixTimestamp();
                    foreach (DatabaseClientOld client in databaseClients.Values.Where(p => (timeStamp - p.ActivityStamp) >= 60 && !p.isWorking && p.State == ConnectionState.Open))
                    {
                        client.Disconnect();
                    }

                    lockObject.ExitReadLock();
                }
                catch (Exception ex)
                {
                    Logging.LogThreadException(ex.ToString(), "DatabaseManager task");
                }
                Thread.Sleep(10000); // 10 seconds
            }
        }
예제 #17
0
 internal void Activate()
 {
     this.Activated      = true;
     this.StampActivated = FirewindEnvironment.GetUnixTimestamp();
 }
예제 #18
0
        internal static Pet CreatePet(int UserId, string Name, int Type, string Race, string Color)
        {
            Pet pet = new Pet(404, UserId, 0, Name, (uint)Type, Race, Color, 0, 100, 100, 0, FirewindEnvironment.GetUnixTimestamp(), 0, 0, 0.0, false);

            pet.DBState = DatabaseUpdateState.NeedsUpdate;

            using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor())
            {
                dbClient.setQuery("INSERT INTO user_pets (user_id,name,type,race,color,expirience,energy,createstamp) VALUES (" + pet.OwnerId + ",@" + pet.PetId + "name," + pet.Type + ",@" + pet.PetId + "race,@" + pet.PetId + "color,0,100,'" + pet.CreationStamp + "')");
                dbClient.addParameter(pet.PetId + "name", pet.Name);
                dbClient.addParameter(pet.PetId + "race", pet.Race);
                dbClient.addParameter(pet.PetId + "color", pet.Color);
                pet.PetId = (uint)dbClient.insertQuery();
            }
            return(pet);
        }
예제 #19
0
        internal static void Process()
        {
            try
            {
                DateTime startTaskTime;
                TimeSpan spentTime;
                startTaskTime = DateTime.Now;

                TimeSpan sinceLastTime = DateTime.Now - processLastExecution;

                if (sinceLastTime.TotalMilliseconds >= _runFrequency)
                {
                    processLastExecution = DateTime.Now;
                    try
                    {
                        int Status      = 1;
                        int UsersOnline = FirewindEnvironment.GetGame().GetClientManager().ClientCount;
                        int RoomsLoaded = FirewindEnvironment.GetGame().GetRoomManager().LoadedRoomsCount;

                        TimeSpan Uptime = DateTime.Now - FirewindEnvironment.ServerStarted;
                        string   addOn  = string.Empty;
                        if (System.Diagnostics.Debugger.IsAttached)
                        {
                            addOn = "[DEBUG] ";
                        }
                        Console.Title = addOn + "Firewind | Uptime: " + Uptime.Minutes + " minutes, " + Uptime.Hours + " hours and " + Uptime.Days + " day(s) | " +
                                        "Online users: " + UsersOnline + " | Loaded rooms: " + RoomsLoaded;

                        #region Statistics
                        if (UsersOnline > UserPeak)
                        {
                            UserPeak = UsersOnline;
                        }

                        using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor())
                        {
                            dbClient.runFastQuery("UPDATE server_status SET stamp = '" + FirewindEnvironment.GetUnixTimestamp() + "', status = " + Status + ", users_online = " + UsersOnline + ", rooms_loaded = " + RoomsLoaded + ", server_ver = '" + FirewindEnvironment.PrettyVersion + "', userpeak = " + UserPeak + "");
                        }
                        #endregion
                    }
                    catch (Exception e) { Logging.LogThreadException(e.ToString(), "Server status update task"); }
                }
                spentTime = DateTime.Now - startTaskTime;

                if (spentTime.TotalSeconds > 3)
                {
                    Logging.WriteLine("LowPriorityWorker.Process spent: " + spentTime.TotalSeconds + " seconds in working.");
                }
                FirewindEnvironment.GetGame().LowPriorityWorker_ended = true;
            }
            catch (Exception e) { Logging.LogThreadException(e.ToString(), "LowPriorityWorker.Process Exception --> Not inclusive"); }
        }
예제 #20
0
        internal void SerializeClub()
        {
            GameClient    Client = GetClient();
            ServerMessage club   = new ServerMessage(Outgoing.SerializeClub);

            club.AppendString("club_habbo");

            if (GetSubscriptionManager().HasSubscription("habbo_vip"))
            {
                Double Expire        = GetSubscriptionManager().GetSubscription("habbo_vip").ExpireTime;
                Double TimeLeft      = Expire - FirewindEnvironment.GetUnixTimestamp();
                int    TotalDaysLeft = (int)Math.Ceiling(TimeLeft / 86400);
                int    MonthsLeft    = TotalDaysLeft / 31;

                if (MonthsLeft >= 1)
                {
                    MonthsLeft--;
                }

                club.AppendInt32(TotalDaysLeft - (MonthsLeft * 31));
                club.AppendInt32(2); // ??
                club.AppendInt32(MonthsLeft);
                club.AppendInt32(1); // type
                club.AppendBoolean(true);
                club.AppendBoolean(true);
                club.AppendInt32(0);
                club.AppendInt32(0); // days i have on hc
                club.AppendInt32(0); // days i have on vip
            }
            else
            {
                club.AppendInt32(0);
                club.AppendInt32(0); // ??
                club.AppendInt32(0);
                club.AppendInt32(0); // type
                club.AppendBoolean(false);
                club.AppendBoolean(true);
                club.AppendInt32(0);
                club.AppendInt32(0); // days i have on hc
                club.AppendInt32(0); // days i have on vip
            }

            Client.SendMessage(club);

            ServerMessage fuserights = new ServerMessage(Outgoing.Fuserights);

            if (GetSubscriptionManager().HasSubscription("habbo_vip")) // VIP
            {
                fuserights.AppendInt32(2);
            }
            else if (GetSubscriptionManager().HasSubscription("habbo_club")) // HC
            {
                fuserights.AppendInt32(1);
            }
            else
            {
                fuserights.AppendInt32(0);
            }
            fuserights.AppendUInt(Rank);

            Client.SendMessage(fuserights);
        }
예제 #21
0
        internal static void SellItem(GameClient Session, uint ItemId, int SellingPrice)
        {
            UserItem Item = Session.GetHabbo().GetInventoryComponent().GetItem(ItemId);

            if (Item == null || SellingPrice > 10000 || !CanSellItem(Item))
            {
                Session.GetMessageHandler().GetResponse().Init(610);
                Session.GetMessageHandler().GetResponse().AppendBoolean(false);
                Session.GetMessageHandler().GetResponse();
                Session.GetMessageHandler().SendResponse();
                return;
            }



            int Comission  = CalculateComissionPrice(SellingPrice);
            int TotalPrice = SellingPrice + Comission;
            int ItemType   = 1;

            if (Item.GetBaseItem().Type == 'i')
            {
                ItemType++;
            }

            using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor())
            {
                dbClient.setQuery("INSERT INTO catalog_marketplace_offers (item_id,user_id,asking_price,total_price,public_name,sprite_id,item_type,timestamp,extra_data) VALUES (" + Item.BaseItem + "," + Session.GetHabbo().Id + "," + SellingPrice + "," + TotalPrice + ",@public_name," + Item.GetBaseItem().SpriteId + "," + ItemType + "," + FirewindEnvironment.GetUnixTimestamp() + ",@extra_data)");
                dbClient.addParameter("public_name", "NEEDS REPLACMENT HERE");
                dbClient.addParameter("extra_data", Item.Data);
                dbClient.runQuery();
            }

            Session.GetHabbo().GetInventoryComponent().RemoveItem(ItemId, false);
            Session.GetHabbo().GetInventoryComponent().RunDBUpdate();

            Session.GetMessageHandler().GetResponse().Init(610);
            Session.GetMessageHandler().GetResponse().AppendBoolean(true);
            Session.GetMessageHandler().SendResponse();
        }
예제 #22
0
 internal void UpdateLastActivity()
 {
     isWorking             = true;
     lastActivityTimestamp = FirewindEnvironment.GetUnixTimestamp();
 }
예제 #23
0
        internal static UserData GetUserData(string sessionTicket, string ip, out byte errorCode)
        {
            DataRow dUserInfo;

            DataTable dAchievements;
            DataTable dFavouriteRooms;
            DataTable dIgnores;
            DataTable dTags;
            DataTable dSubscriptions;
            DataTable dBadges;
            DataTable dInventory;
            DataTable dEffects;
            DataTable dFriends;
            DataTable dRequests;
            DataTable dRooms;
            DataTable dPets;
            DataTable dBots;
            DataTable dQuests;
            //DataTable dSongs;

            int userID;

            using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor())
            {
                dbClient.setQuery("SELECT * " +
                                  "FROM users " +
                                  "WHERE auth_ticket = @sso ");

                dbClient.addParameter("sso", sessionTicket);
                //dbClient.addParameter("ipaddress", ip);
                dUserInfo = dbClient.getRow();


                if (dUserInfo == null)
                {
                    errorCode = 1;
                    return(null);
                    //Logging.LogException("No user found. Debug data: [" + sessionTicket + "], [" + ip + "]");
                    //throw new UserDataNotFoundException(string.Format("No user found with ip {0} and sso {1}. Use SSO: {2} ", ip, sessionTicket, FirewindEnvironment.useSSO.ToString()));
                }


                userID = Convert.ToInt32(dUserInfo["id"]);
                if (FirewindEnvironment.GetGame().GetClientManager().GetClientByUserID(userID) != null)
                {
                    errorCode = 2;
                    return(null);
                }

                string creditsTimestamp = (string)dUserInfo["lastdailycredits"];
                string todayTimestamp   = DateTime.Today.ToString("MM/dd");
                if (creditsTimestamp != todayTimestamp)
                {
                    dbClient.runFastQuery(
                        "UPDATE users SET credits = credits + 3000, daily_respect_points = 3, lastdailycredits = '" +
                        todayTimestamp + "' WHERE id = " + userID);
                    dUserInfo["credits"] = (int)dUserInfo["credits"] + 3000;
                }

                dbClient.setQuery("SELECT * FROM user_achievement WHERE userid = " + userID);
                dAchievements = dbClient.getTable();

                dbClient.setQuery("SELECT room_id FROM user_favorites WHERE user_id = " + userID);
                dFavouriteRooms = dbClient.getTable();

                dbClient.setQuery("SELECT ignore_id FROM user_ignores WHERE user_id = " + userID);
                dIgnores = dbClient.getTable();

                dbClient.setQuery("SELECT tag FROM user_tags WHERE user_id = " + userID);
                dTags = dbClient.getTable();

                dbClient.setQuery("SELECT * FROM user_subscriptions WHERE user_id = " + userID);
                dSubscriptions = dbClient.getTable();

                dbClient.setQuery("SELECT * FROM user_badges WHERE user_id = " + userID);
                dBadges = dbClient.getTable();

                dbClient.setQuery("CALL getuseritems(" + userID + ")");
                dInventory = dbClient.getTable();

                dbClient.setQuery("SELECT * FROM user_effects WHERE user_id =  " + userID);
                dEffects = dbClient.getTable();

                dbClient.setQuery("SELECT users.id,users.username,users.motto,users.look,users.last_online " +
                                  "FROM users " +
                                  "JOIN messenger_friendships " +
                                  "ON users.id = messenger_friendships.sender " +
                                  "WHERE messenger_friendships.receiver = " + userID + " " +
                                  "UNION ALL " +
                                  "SELECT users.id,users.username,users.motto,users.look,users.last_online " +
                                  "FROM users " +
                                  "JOIN messenger_friendships " +
                                  "ON users.id = messenger_friendships.receiver " +
                                  "WHERE messenger_friendships.sender = " + userID);
                dFriends = dbClient.getTable();

                dbClient.setQuery("SELECT messenger_requests.sender,messenger_requests.receiver,users.username " +
                                  "FROM users " +
                                  "JOIN messenger_requests " +
                                  "ON users.id = messenger_requests.sender " +
                                  "WHERE messenger_requests.receiver = " + userID);
                dRequests = dbClient.getTable();

                dbClient.setQuery(
                    "SELECT rooms.*, room_active.active_users FROM rooms LEFT JOIN room_active ON (room_active.roomid = rooms.id) WHERE owner = @name");
                dbClient.addParameter("name", (string)dUserInfo["username"]);
                dRooms = dbClient.getTable();

                dbClient.setQuery("SELECT * FROM user_pets WHERE user_id = " + userID + " AND room_id = 0");
                dPets = dbClient.getTable();

                dbClient.setQuery("SELECT * FROM user_bots WHERE user_id = " + userID + "");
                dBots = dbClient.getTable();

                dbClient.setQuery("SELECT * FROM user_quests WHERE user_id = " + userID + "");
                dQuests = dbClient.getTable();

                //dbClient.setQuery("SELECT item_id, song_id FROM user_items_songs WHERE user_id = " + userID);
                //dSongs = dbClient.getTable();


                /* dbClient.setQuery("UPDATE users SET ip_last = @ip WHERE id = " + userID + " LIMIT 1; " +
                 *                     "UPDATE user_info SET login_timestamp = '" + FirewindEnvironment.GetUnixTimestamp() + "' WHERE user_id = " + userID + " LIMIT 1; " +
                 *                     "REPLACE INTO user_online VALUES (" + userID + "); " +
                 *                     "DELETE FROM user_tickets WHERE userid = " + userID + ";");*/

                dbClient.setQuery("UPDATE users SET ip_last = @ip WHERE id = " + userID + "; " +
                                  "UPDATE user_info SET login_timestamp = '" + FirewindEnvironment.GetUnixTimestamp() +
                                  "' WHERE user_id = " + userID + " ; " +
                                  "");
                dbClient.addParameter("ip", ip);
                dbClient.runQuery();

                dbClient.runFastQuery("REPLACE INTO user_online VALUES (" + userID + ")");
            }

            Dictionary <string, UserAchievement> achievements = new Dictionary <string, UserAchievement>();

            string achievementGroup;
            int    achievementLevel;
            int    achievementProgress;

            foreach (DataRow dRow in dAchievements.Rows)
            {
                achievementGroup    = (string)dRow["group"];
                achievementLevel    = (int)dRow["level"];
                achievementProgress = (int)dRow["progress"];

                UserAchievement achievement = new UserAchievement(achievementGroup, achievementLevel, achievementProgress);
                achievements.Add(achievementGroup, achievement);
            }

            List <uint> favouritedRooms = new List <uint>();

            uint favoritedRoomID;

            foreach (DataRow dRow in dFavouriteRooms.Rows)
            {
                favoritedRoomID = Convert.ToUInt32(dRow["room_id"]);
                favouritedRooms.Add(favoritedRoomID);
            }


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

            int ignoredUserID;

            foreach (DataRow dRow in dIgnores.Rows)
            {
                ignoredUserID = Convert.ToInt32(dRow["ignore_id"]);
                ignores.Add(ignoredUserID);
            }


            List <string> tags = new List <string>();

            string tag;

            foreach (DataRow dRow in dTags.Rows)
            {
                tag = (string)dRow["tag"];
                tags.Add(tag);
            }

            Dictionary <string, Subscription> subscriptions = new Dictionary <string, Subscription>();

            string subscriptionID;
            int    expireTimestamp;

            foreach (DataRow dRow in dSubscriptions.Rows)
            {
                subscriptionID  = (string)dRow["subscription_id"];
                expireTimestamp = (int)dRow["timestamp_expire"];

                subscriptions.Add(subscriptionID, new Subscription(subscriptionID, expireTimestamp));
            }

            List <Badge> badges = new List <Badge>();

            string badgeID;
            int    slotID;

            foreach (DataRow dRow in dBadges.Rows)
            {
                badgeID = (string)dRow["badge_id"];
                slotID  = (int)dRow["badge_slot"];
                badges.Add(new Badge(badgeID, slotID));
            }


            List <UserItem> inventory = new List <UserItem>();

            uint   itemID;
            uint   baseItem;
            int    dataType;
            string extradata;
            int    extra;

            foreach (DataRow Row in dInventory.Rows)
            {
                itemID   = Convert.ToUInt32(Row[0]);
                baseItem = Convert.ToUInt32(Row[1]);

                IRoomItemData data;
                if (DBNull.Value.Equals(Row[2]))
                {
                    data  = new StringData("");
                    extra = 0;
                }
                else
                {
                    dataType  = Convert.ToInt32(Row[2]);
                    extradata = (string)Row[3];
                    extra     = Convert.ToInt32(Row[4]);
                    switch (dataType)
                    {
                    case 0:
                        data = new StringData(extradata);
                        break;

                    case 1:
                        data = new MapStuffData();
                        break;

                    case 2:
                        data = new StringArrayStuffData();
                        break;

                    case 3:
                        data = new StringIntData();
                        break;

                    default:
                        data = new StringData(extradata);
                        break;
                    }
                    try
                    {
                        data.Parse(extradata);
                    }
                    catch
                    {
                        Logging.LogException(string.Format("Error in furni data! Item ID: \"{0}\" and data: \"{1}\"", itemID, extradata.Replace(Convert.ToChar(1).ToString(), "[1]")));
                    }
                }

                inventory.Add(new UserItem(itemID, baseItem, data, extra));
            }


            List <AvatarEffect> effects = new List <AvatarEffect>();

            int    effectID;
            int    duration;
            bool   isActivated;
            double activatedTimeStamp;

            foreach (DataRow dRow in dEffects.Rows)
            {
                effectID           = (int)dRow["effect_id"];
                duration           = (int)dRow["total_duration"];
                isActivated        = Convert.ToInt32(dRow["is_activated"]) == 1;
                activatedTimeStamp = (double)dRow["activated_stamp"];

                effects.Add(new AvatarEffect(effectID, duration, isActivated, activatedTimeStamp));
            }


            Dictionary <int, MessengerBuddy> friends = new Dictionary <int, MessengerBuddy>();

            string username = (string)dUserInfo["username"];

            int    friendID;
            string friendName;
            string friendLook;
            string friendMotto;
            string friendLastOnline;

            foreach (DataRow dRow in dFriends.Rows)
            {
                friendID         = Convert.ToInt32(dRow["id"]);
                friendName       = (string)dRow["username"];
                friendLook       = (string)dRow["look"];
                friendMotto      = (string)dRow["motto"];
                friendLastOnline = Convert.ToString(dRow["last_online"]);


                if (friendID == userID)
                {
                    continue;
                }



                if (!friends.ContainsKey(friendID))
                {
                    friends.Add(friendID, new MessengerBuddy(friendID, friendName, friendLook, friendMotto, friendLastOnline));
                }
            }

            Dictionary <int, MessengerRequest> requests = new Dictionary <int, MessengerRequest>();

            int    receiverID;
            int    senderID;
            string requestUsername;

            foreach (DataRow dRow in dRequests.Rows)
            {
                receiverID = Convert.ToInt32(dRow["sender"]);
                senderID   = Convert.ToInt32(dRow["receiver"]);

                requestUsername = (string)dRow["username"];

                if (receiverID != userID)
                {
                    if (!requests.ContainsKey(receiverID))
                    {
                        requests.Add(receiverID, new MessengerRequest(userID, receiverID, requestUsername));
                    }
                }
                else
                {
                    if (!requests.ContainsKey(senderID))
                    {
                        requests.Add(senderID, new MessengerRequest(userID, senderID, requestUsername));
                    }
                }
            }

            List <RoomData> rooms = new List <RoomData>();

            uint roomID;

            foreach (DataRow dRow in dRooms.Rows)
            {
                roomID = Convert.ToUInt32(dRow["id"]);
                rooms.Add(FirewindEnvironment.GetGame().GetRoomManager().FetchRoomData(roomID, dRow));
            }


            Dictionary <uint, Pet> pets = new Dictionary <uint, Pet>();

            Pet pet;

            foreach (DataRow dRow in dPets.Rows)
            {
                pet = Catalog.GeneratePetFromRow(dRow);
                pets.Add(pet.PetId, pet);
            }

            Dictionary <int, RentableBot> bots = new Dictionary <int, RentableBot>();

            RentableBot bot;

            foreach (DataRow row in dBots.Rows)
            {
                bot = new RentableBot();

                bot.OwnerID  = Convert.ToInt32(row["user_id"]);
                bot.ID       = Convert.ToInt32(row["id"]);
                bot.Name     = Convert.ToString(row["name"]);
                bot.Gender   = Convert.ToChar(row["gender"]);
                bot.Figure   = Convert.ToString(row["figure"]);
                bot.Motto    = "1 week SpyBot";
                bot.TimeLeft = 604800; // 1 week

                bots.Add(bot.ID, bot);
            }

            Dictionary <uint, int> quests = new Dictionary <uint, int>();

            uint questId;
            int  progress;

            foreach (DataRow dRow in dQuests.Rows)
            {
                questId  = Convert.ToUInt32(dRow["quest_id"]);
                progress = (int)dRow["progress"];
                quests.Add(questId, progress);
            }

            Hashtable songs = new Hashtable();

            //uint songItemID;
            //uint songID;
            //foreach (DataRow dRow in dSongs.Rows)
            //{
            //    songItemID = (uint)dRow[0];
            //    songID = (uint)dRow[1];

            //    SongItem song = new SongItem(songItemID, songID);
            //    songs.Add(songItemID, song);
            //}

            Habbo user = HabboFactory.GenerateHabbo(dUserInfo);

            dUserInfo       = null;
            dAchievements   = null;
            dFavouriteRooms = null;
            dIgnores        = null;
            dTags           = null;
            dSubscriptions  = null;
            dBadges         = null;
            dInventory      = null;
            dEffects        = null;
            dFriends        = null;
            dRequests       = null;
            dRooms          = null;
            dPets           = null;

            errorCode = 0;
            return(new UserData(userID, achievements, favouritedRooms, ignores, tags, subscriptions, badges, inventory, effects, friends, requests, rooms, pets, quests, songs, user, bots));
        }
예제 #24
0
        internal static ChatMessage CreateMessage(string message, GameClient user, Room room)
        {
            int      userID     = user.GetHabbo().Id;
            string   username   = user.GetHabbo().Username;
            uint     roomID     = room.RoomId;
            string   roomName   = room.Name;
            DateTime timeSpoken = DateTime.Now;

            ChatMessage chatMessage = new ChatMessage(userID, username, roomID, roomName, message, timeSpoken);

            using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor())
            {
                dbClient.setQuery("INSERT into `chatlogs`(`user_id`, `room_id`, `hour`, `minute`, `full_date`, `timestamp`, `message`, `user_name`) VALUES(" + userID + ", " + roomID + ", " + timeSpoken.Hour + ", " + timeSpoken.Minute + ", '" + timeSpoken.ToString() + "', " + FirewindEnvironment.GetUnixTimestamp() + ", @msg, '" + user.GetHabbo().Username + "');");
                dbClient.addParameter("msg", message);
                dbClient.runQuery();
            }

            return(chatMessage);
        }
예제 #25
0
 internal static Double FormatTimestamp()
 {
     return(FirewindEnvironment.GetUnixTimestamp() - 172800);
 }
예제 #26
0
        internal void EnableEffect(int EffectId)
        {
            AvatarEffect Effect = GetEffect(EffectId, false);

            if (Effect == null || Effect.HasExpired || Effect.Activated)
            {
                return;
            }

            using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor())
            {
                dbClient.runFastQuery("UPDATE user_effects SET is_activated = '1', activated_stamp = " + FirewindEnvironment.GetUnixTimestamp() + " WHERE user_id = " + UserId + " AND effect_id = " + EffectId + "");
            }

            Effect.Activate();

            GetClient().GetMessageHandler().GetResponse().Init(Outgoing.EnableEffect);
            GetClient().GetMessageHandler().GetResponse().AppendInt32(Effect.EffectId);
            GetClient().GetMessageHandler().GetResponse().AppendInt32(Effect.TotalDuration);
            GetClient().GetMessageHandler().SendResponse();
        }
예제 #27
0
파일: Game.cs 프로젝트: TheNaked/Firewind
 internal static void DatabaseCleanup(IQueryAdapter dbClient)
 {
     //dbClient.runFastQuery("TRUNCATE TABLE user_tickets");
     dbClient.runFastQuery("TRUNCATE TABLE user_online");
     dbClient.runFastQuery("TRUNCATE TABLE room_active");
     dbClient.runFastQuery("UPDATE server_status SET status = 1, users_online = 0, rooms_loaded = 0, server_ver = '" + FirewindEnvironment.PrettyVersion + "', stamp = '" + FirewindEnvironment.GetUnixTimestamp() + "' ");
 }
예제 #28
0
        // PENDING REWRITE
        internal void BanUser(GameClient Client, string Moderator, Double LengthSeconds, string Reason, Boolean IpBan)
        {
            ModerationBanType Type   = ModerationBanType.USERNAME;
            string            Var    = Client.GetHabbo().Username;
            string            RawVar = "user";
            Double            Expire = FirewindEnvironment.GetUnixTimestamp() + LengthSeconds;

            if (IpBan)
            {
                Type   = ModerationBanType.IP;
                Var    = Client.GetConnection().getIp();
                RawVar = "ip";
            }

            ModerationBan ban = new ModerationBan(Type, Var, Reason, Expire);

            if (ban.Type == ModerationBanType.IP)
            {
                if (bannedIPs.ContainsKey(Var))
                {
                    bannedIPs[Var] = ban;
                }
                else
                {
                    bannedIPs.Add(Var, ban);
                }
            }
            else
            {
                if (bannedUsernames.ContainsKey(Var))
                {
                    bannedUsernames[Var] = ban;
                }
                else
                {
                    bannedUsernames.Add(Var, ban);
                }
            }

            using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor())
            {
                dbClient.setQuery("INSERT INTO bans (bantype,value,reason,expire,added_by,added_date) VALUES (@rawvar,@var,@reason,'" + Expire + "',@mod,'" + DateTime.Now.ToLongDateString() + "')");
                dbClient.addParameter("rawvar", RawVar);
                dbClient.addParameter("var", Var);
                dbClient.addParameter("reason", Reason);
                dbClient.addParameter("mod", Moderator);
                dbClient.runQuery();
            }

            if (IpBan)
            {
                DataTable UsersAffected = null;

                using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor())
                {
                    dbClient.setQuery("SELECT id FROM users WHERE ip_last = @var");
                    dbClient.addParameter("var", Var);
                    UsersAffected = dbClient.getTable();
                }

                if (UsersAffected != null)
                {
                    using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor())
                    {
                        foreach (DataRow Row in UsersAffected.Rows)
                        {
                            dbClient.runFastQuery("UPDATE user_info SET bans = bans + 1 WHERE user_id = " + Convert.ToUInt32(Row["id"]));
                        }
                    }
                }


                BanUser(Client, Moderator, LengthSeconds, Reason, false);
            }
            else
            {
                using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor())
                {
                    dbClient.runFastQuery("UPDATE user_info SET bans = bans + 1 WHERE user_id = " + Client.GetHabbo().Id);
                }

                Client.SendBanMessage(LanguageLocale.GetValue("moderation.banned") + " " + Reason);
                Client.Disconnect();
            }
        }
예제 #29
0
        internal void SendNewTicket(GameClient Session, int Category, uint ReportedUser, String Message)
        {
            if (Session.GetHabbo().CurrentRoomId <= 0)
            {
                return;
            }

            RoomData Data = FirewindEnvironment.GetGame().GetRoomManager().GenerateNullableRoomData(Session.GetHabbo().CurrentRoomId);

            uint TicketId = 0;

            using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor())
            {
                dbClient.setQuery("INSERT INTO moderation_tickets (score,type,status,sender_id,reported_id,moderator_id,message,room_id,room_name,timestamp) VALUES (1,'" + Category + "','open','" + Session.GetHabbo().Id + "','" + ReportedUser + "','0',@message,'" + Data.Id + "',@name,'" + FirewindEnvironment.GetUnixTimestamp() + "')");
                dbClient.addParameter("message", Message);
                dbClient.addParameter("name", Data.Name);
                TicketId = (uint)dbClient.insertQuery();

                dbClient.runFastQuery("UPDATE user_info SET cfhs = cfhs + 1 WHERE user_id = " + Session.GetHabbo().Id + "");

                //dbClient.setQuery("SELECT id FROM moderation_tickets WHERE sender_id = " + Session.GetHabbo().Id + " ORDER BY id DESC LIMIT 1");
                //TicketId = (uint)dbClient.getRow()[0];
            }

            SupportTicket Ticket = new SupportTicket(TicketId, 1, Category, Session.GetHabbo().Id, ReportedUser, Message, Data.Id, Data.Name, FirewindEnvironment.GetUnixTimestamp());

            Tickets.Add(Ticket);

            SendTicketToModerators(Ticket);
        }
예제 #30
0
        internal static ServerMessage SerializeOwnOffers(uint HabboId)
        {
            int       Profits = 0;
            DataTable Data;
            String    RawProfit;

            using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor())
            {
                dbClient.setQuery("SELECT timestamp, state, offer_id, item_type, sprite_id, total_price FROM catalog_marketplace_offers WHERE user_id = " + HabboId);
                Data = dbClient.getTable();

                dbClient.setQuery("SELECT SUM(asking_price) FROM catalog_marketplace_offers WHERE state = '2' AND user_id = " + HabboId);
                RawProfit = dbClient.getRow()[0].ToString();
            }

            if (RawProfit.Length > 0)
            {
                Profits = int.Parse(RawProfit);
            }

            ServerMessage Message = new ServerMessage(616);

            Message.AppendInt32(Profits);

            if (Data != null)
            {
                Message.AppendInt32(Data.Rows.Count);

                foreach (DataRow Row in Data.Rows)
                {
                    int MinutesLeft = (int)Math.Floor((((Double)Row["timestamp"] + 172800) - FirewindEnvironment.GetUnixTimestamp()) / 60);
                    int state       = int.Parse(Row["state"].ToString());

                    if (MinutesLeft <= 0)
                    {
                        state       = 3;
                        MinutesLeft = 0;
                    }

                    Message.AppendUInt(Convert.ToUInt32(Row["offer_id"]));
                    Message.AppendInt32(state);                                  // 1 = active, 2 = sold, 3 = expired
                    Message.AppendInt32(int.Parse(Row["item_type"].ToString())); // always 1 (??)
                    Message.AppendInt32((int)Row["sprite_id"]);
                    Message.AppendString("");                                    // Extra Chr (R52)
                    Message.AppendInt32((int)Row["total_price"]);                // ??
                    Message.AppendInt32(MinutesLeft);
                    Message.AppendInt32((int)Row["sprite_id"]);
                }
            }
            else
            {
                Message.AppendInt32(0);
            }

            return(Message);
        }