예제 #1
0
 internal void AddBan(uint pId)
 {
     if (!Bans.ContainsKey(pId))
     {
         Bans.Add(pId, PiciEnvironment.GetUnixTimestamp());
     }
 }
예제 #2
0
        internal static void GivePixels(GameClient Client, int amount)
        {
            Double Timestamp = PiciEnvironment.GetUnixTimestamp();

            Client.GetHabbo().LastActivityPointsUpdate = Timestamp;
            Client.GetHabbo().ActivityPoints          += amount;
            Client.GetHabbo().UpdateActivityPointsBalance(0);
        }
예제 #3
0
        internal static ServerMessage SerializeUserInfo(uint UserId)
        {
            using (IQueryAdapter dbClient = PiciEnvironment.GetDatabaseManager().getQueryreactor())
            {
                dbClient.setQuery("SELECT id, username, online 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(533);

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

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

                if (User["online"].ToString() == "1")
                {
                    Message.AppendBoolean(true);
                }
                else
                {
                    Message.AppendBoolean(false);
                }

                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
                }

                return(Message);
            }
        }
예제 #4
0
        internal Boolean IsValid()
        {
            if (TimeExpire <= PiciEnvironment.GetUnixTimestamp())
            {
                return(false);
            }

            return(true);
        }
예제 #5
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 = PiciEnvironment.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);
                        }
                    }
                }
            }
        }
예제 #6
0
        internal Boolean HasBanExpired(uint pId)
        {
            if (!UserIsBanned(pId))
            {
                return(true);
            }

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

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

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

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

            mSong = mPlaylist[mSongQueuePosition];
            mStartedPlayingTimestamp = PiciEnvironment.GetUnixTimestamp();
            mBroadcastNeeded         = true;
        }
예제 #8
0
        internal void GetSubscriptionData()
        {
            string SubscriptionId = Request.PopFixedString();

            GetResponse().Init(7);
            GetResponse().Append(SubscriptionId.ToLower());

            if (Session.GetHabbo().GetSubscriptionManager().HasSubscription(SubscriptionId))
            {
                Double Expire        = Session.GetHabbo().GetSubscriptionManager().GetSubscription(SubscriptionId).ExpireTime;
                Double TimeLeft      = Expire - PiciEnvironment.GetUnixTimestamp();
                int    TotalDaysLeft = (int)Math.Ceiling(TimeLeft / 86400);
                int    MonthsLeft    = TotalDaysLeft / 31;

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

                GetResponse().AppendInt32(TotalDaysLeft - (MonthsLeft * 31));
                GetResponse().AppendBoolean(true);
                GetResponse().AppendInt32(MonthsLeft);

                if (Session.GetHabbo().Rank >= 2)
                {
                    GetResponse().AppendInt32(1);
                    GetResponse().AppendInt32(1);
                    GetResponse().AppendInt32(2);
                }
                else
                {
                    GetResponse().AppendInt32(1);
                }
            }
            else
            {
                for (int i = 0; i < 3; i++)
                {
                    GetResponse().AppendInt32(0);
                }
            }

            SendResponse();
        }
예제 #9
0
        internal static void ProcessThread()
        {
            double CurrentTime = PiciEnvironment.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);
            }
        }
예제 #10
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)PiciEnvironment.GetUnixTimestamp() + DurationSeconds));
                }

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

                return;
            }

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

            Subscription NewSub = new Subscription(SubscriptionId, TimeExpire);

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

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

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

                if (PassedMins >= RCV_EVERY_MINS)
                {
                    return(true);
                }
            }
            catch (Exception e)
            {
                Logging.HandleException(e, "PixelManager.NeedsUpdate");
            }
            return(false);
        }
예제 #12
0
        internal static void Process()
        {
            TimeSpan sinceLastTime = DateTime.Now - processLastExecution;

            if (sinceLastTime.TotalMilliseconds >= 30000)
            {
                processLastExecution = DateTime.Now;
                try
                {
                    TimeSpan Uptime = DateTime.Now - PiciEnvironment.ServerStarted;
                    mColdTitle = PiciEnvironment.Title + " " + PiciEnvironment.Version + " | Uptime: " + Uptime.Minutes + " minutes, " + Uptime.Hours + " hours and " + Uptime.Days + " day | " +
                                 "Online users: " + PiciEnvironment.GetGame().GetClientManager().ClientCount + " | Loaded rooms: " + PiciEnvironment.GetGame().GetRoomManager().LoadedRoomsCount;

                    #region Garbage Collection
                    //GC.Collect();
                    //GC.WaitForPendingFinalizers();
                    #endregion

                    #region Statistics
                    int Status      = 1;
                    int UsersOnline = PiciEnvironment.GetGame().GetClientManager().ClientCount;

                    if (UsersOnline > UserPeak)
                    {
                        UserPeak = UsersOnline;
                    }

                    int RoomsLoaded = PiciEnvironment.GetGame().GetRoomManager().LoadedRoomsCount;

                    using (IQueryAdapter dbClient = PiciEnvironment.GetDatabaseManager().getQueryreactor())
                    {
                        dbClient.runFastQuery("UPDATE server_status SET stamp = '" + PiciEnvironment.GetUnixTimestamp() + "', status = " + Status + ", users_online = " + UsersOnline + ", rooms_loaded = " + RoomsLoaded + ", server_ver = '" + PiciEnvironment.Build + "', userpeak = " + UserPeak + "");
                    }
                    #endregion
                }
                catch (Exception e) { Logging.LogThreadException(e.ToString(), "Server status update task"); }
            }
        }
예제 #13
0
 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 = '" + PiciEnvironment.Build + "', stamp = '" + PiciEnvironment.GetUnixTimestamp() + "' ");
 }
예제 #14
0
 internal void Activate()
 {
     this.Activated      = true;
     this.StampActivated = PiciEnvironment.GetUnixTimestamp();
 }
예제 #15
0
 internal static Double FormatTimestamp()
 {
     return(PiciEnvironment.GetUnixTimestamp() - 172800);
 }
예제 #16
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 = PiciEnvironment.GetDatabaseManager().getQueryreactor())
            {
                if (dbClient.dbType == DatabaseType.MSSQL)
                {
                    dbClient.setQuery("INSERT INTO catalog_marketplace_offers (item_id,user_id,asking_price,total_price,public_name,sprite_id,item_type,timestamp,extra_data,state) VALUES (" + Item.BaseItem + "," + Session.GetHabbo().Id + "," + SellingPrice + "," + TotalPrice + ",@public_name," + Item.GetBaseItem().SpriteId + "," + ItemType + "," + PiciEnvironment.GetUnixTimestamp() + ",@extra_data, '1')");
                }
                else
                {
                    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 + "," + PiciEnvironment.GetUnixTimestamp() + ",@extra_data)");
                }
                dbClient.addParameter("public_name", Item.GetBaseItem().PublicName);
                dbClient.addParameter("extra_data", Item.ExtraData);
                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();
        }
예제 #17
0
        internal static ServerMessage SerializeOwnOffers(uint HabboId)
        {
            int       Profits = 0;
            DataTable Data;
            String    RawProfit;

            using (IQueryAdapter dbClient = PiciEnvironment.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) - PiciEnvironment.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.AppendStringWithBreak("");                           // Extra Chr (R52)
                    Message.AppendInt32((int)Row["total_price"]);                // ??
                    Message.AppendInt32(MinutesLeft);
                    Message.AppendInt32((int)Row["sprite_id"]);
                }
            }
            else
            {
                Message.AppendInt32(0);
            }

            return(Message);
        }
예제 #18
0
        internal void EnableEffect(int EffectId)
        {
            AvatarEffect Effect = GetEffect(EffectId, false);

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

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

            Effect.Activate();

            GetClient().GetMessageHandler().GetResponse().Init(462);
            GetClient().GetMessageHandler().GetResponse().AppendInt32(Effect.EffectId);
            GetClient().GetMessageHandler().GetResponse().AppendInt32(Effect.TotalDuration);
            GetClient().GetMessageHandler().SendResponse();
        }
예제 #19
0
        internal static ServerMessage SerializeUserChatlog(UInt32 UserId)
        {
            GameClient client = PiciEnvironment.GetGame().GetClientManager().GetClientByUserID(UserId);

            if (client == null || client.GetHabbo() == null)
            {
                ServerMessage Message = new ServerMessage(536);
                Message.AppendUInt(UserId);
                Message.AppendStringWithBreak("User not online");
                Message.AppendInt32(0);

                return(Message);
            }
            else
            {
                using (IQueryAdapter dbClient = PiciEnvironment.GetDatabaseManager().getQueryreactor())
                {
                    dbClient.setQuery("SELECT room_id,entry_timestamp,exit_timestamp FROM user_roomvisits WHERE user_id = " + UserId + " ORDER BY entry_timestamp DESC LIMIT 5");
                    DataTable Visits = dbClient.getTable();

                    ServerMessage Message = new ServerMessage(536);
                    Message.AppendUInt(UserId);
                    Message.AppendStringWithBreak(PiciEnvironment.GetGame().GetClientManager().GetNameById(UserId));

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

                        foreach (DataRow Visit in Visits.Rows)
                        {
                            if ((Double)Visit["exit_timestamp"] <= 0.0)
                            {
                                Visit["exit_timestamp"] = PiciEnvironment.GetUnixTimestamp();
                            }

                            dbClient.setQuery("SELECT user_id,user_name,hour,minute,message FROM chatlogs WHERE room_id = " + (uint)Visit["room_id"] + " AND timestamp > " + (Double)Visit["entry_timestamp"] + " AND timestamp < " + (Double)Visit["exit_timestamp"] + " ORDER BY timestamp DESC");
                            DataTable Chatlogs = dbClient.getTable();


                            RoomData RoomData = PiciEnvironment.GetGame().GetRoomManager().GenerateNullableRoomData((UInt32)Visit["room_id"]);

                            Message.AppendBoolean(RoomData.IsPublicRoom);
                            Message.AppendUInt(RoomData.Id);
                            Message.AppendStringWithBreak(RoomData.Name);

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

                                foreach (DataRow Log in Chatlogs.Rows)
                                {
                                    Message.AppendInt32((int)Log["hour"]);
                                    Message.AppendInt32((int)Log["minute"]);
                                    Message.AppendUInt((UInt32)Log["user_id"]);
                                    Message.AppendStringWithBreak((string)Log["user_name"]);
                                    Message.AppendStringWithBreak((string)Log["message"]);
                                }
                            }
                            else
                            {
                                Message.AppendInt32(0);
                            }
                        }
                    }
                    else
                    {
                        Message.AppendInt32(0);
                    }

                    return(Message);
                }
            }
        }
예제 #20
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 = PiciEnvironment.GetUnixTimestamp() + LengthSeconds;

            if (Reason == null)
            {
                Client.SendNotif("Please fill in a reason to ban a user.");
                return;
            }

            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 = PiciEnvironment.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 = PiciEnvironment.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 = PiciEnvironment.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 = PiciEnvironment.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();
            }
        }
예제 #21
0
        internal void SendNewTicket(GameClient Session, int Category, uint ReportedUser, String Message)
        {
            if (Session.GetHabbo().CurrentRoomId <= 0)
            {
                return;
            }

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

            uint TicketId = 0;

            using (IQueryAdapter dbClient = PiciEnvironment.GetDatabaseManager().getQueryreactor())
            {
                if (dbClient.dbType == Pici.Storage.Database.DatabaseType.MSSQL)
                {
                    dbClient.setQuery("INSERT INTO moderation_tickets (score,type,status,sender_id,reported_id,moderator_id,message,room_id,room_name,timestamp) OUTPUT INSERTED.* VALUES (1,'" + Category + "','open','" + Session.GetHabbo().Id + "','" + ReportedUser + "','0',@message,'" + Data.Id + "',@name,'" + PiciEnvironment.GetUnixTimestamp() + "')");
                }
                else
                {
                    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,'" + PiciEnvironment.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, PiciEnvironment.GetUnixTimestamp());

            Tickets.Add(Ticket);

            SendTicketToModerators(Ticket);
        }
예제 #22
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 dQuests;
            //DataTable dSongs;
            DataRow dGroups = null;

            UInt32 userID;

            using (IQueryAdapter dbClient = PiciEnvironment.GetDatabaseManager().getQueryreactor())
            {
                if (PiciEnvironment.useSSO)
                {
                    dbClient.setQuery("SELECT * FROM users WHERE auth_ticket = @sso " +
                                      "AND ip_last = @ipaddress ");
                }
                else
                {
                    dbClient.setQuery("SELECT * FROM users WHERE auth_ticket = @sso " +
                                      "AND ip_last = @ipaddress ");
                }

                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, PiciEnvironment.useSSO.ToString()));
                }


                userID = Convert.ToUInt32(dUserInfo["id"]);
                if (PiciEnvironment.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();

                if (dbClient.dbType == Pici.Storage.Database.DatabaseType.MySQL)
                {
                    dbClient.setQuery("CALL getuseritems(" + userID + ")");
                }
                else
                {
                    dbClient.setQuery("EXECUTE 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_quests WHERE user_id = " + userID + "");
                dQuests = dbClient.getTable();

                if (PiciEnvironment.groupsEnabled)
                {
                    dbClient.setQuery("SELECT groups_memberships.*, groups_details.* FROM groups_memberships " +
                                      "LEFT JOIN groups_details " +
                                      "ON groups_memberships.groupid = groups_details.id " +
                                      "WHERE groups_memberships.userid = " + userID + " AND groups_memberships.is_current = '1'");

                    dGroups = dbClient.getRow();
                }

                //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 = '" + PiciEnvironment.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 = '" + PiciEnvironment.GetUnixTimestamp() + "' WHERE user_id = " + userID + " ; " +
                                  "");
                dbClient.addParameter("ip", ip);
                dbClient.runQuery();

                if (dbClient.dbType == Pici.Storage.Database.DatabaseType.MySQL)
                {
                    dbClient.runFastQuery("REPLACE INTO user_online VALUES (" + userID + ")");
                }
                else
                {
                    dbClient.runFastQuery("IF NOT EXISTS (SELECT userid FROM user_online WHERE userid = " + userID + ") " +
                                          "INSERT 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 <uint> ignores = new List <uint>();

            uint ignoredUserID;

            foreach (DataRow dRow in dIgnores.Rows)
            {
                ignoredUserID = Convert.ToUInt32(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;
            string extraData;

            foreach (DataRow dRow in dInventory.Rows)
            {
                itemID   = Convert.ToUInt32(dRow[0]);
                baseItem = Convert.ToUInt32(dRow[1]);
                if (!DBNull.Value.Equals(dRow[2]))
                {
                    extraData = (string)dRow[2];
                }
                else
                {
                    extraData = string.Empty;
                }

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


            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        = PiciEnvironment.EnumToBool((string)dRow["is_activated"]);
                activatedTimeStamp = (double)dRow["activated_stamp"];

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


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

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

            UInt32 friendID;
            string friendName;
            string friendLook;
            string friendMotto;
            string friendLastOnline;

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


                if (friendID == userID)
                {
                    continue;
                }


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

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

            uint   receiverID;
            uint   senderID;
            string requestUsername;

            foreach (DataRow dRow in dRequests.Rows)
            {
                receiverID = Convert.ToUInt32(dRow["sender"]);
                senderID   = Convert.ToUInt32(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(PiciEnvironment.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 <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, dGroups);

            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));
        }