Ejemplo n.º 1
0
        public void Execute(GameClient Session, Room Room, RoomUser UserRoom, string[] Params)
        {
            if (Params.Length < 2)
            {
                return;
            }

            string   PhotoId     = Params[1];
            int      ItemPhotoId = 4581;
            ItemData ItemData    = null;

            if (!ButterflyEnvironment.GetGame().GetItemManager().GetItem(ItemPhotoId, out ItemData))
            {
                return;
            }

            int    Time      = ButterflyEnvironment.GetUnixTimestamp();
            string ExtraData = "{\"w\":\"" + "/photos/" + PhotoId + ".png" + "\", \"n\":\"" + Session.GetHabbo().Username + "\", \"s\":\"" + Session.GetHabbo().Id + "\", \"u\":\"" + "0" + "\", \"t\":\"" + Time + "000" + "\"}";

            Item Item = ItemFactory.CreateSingleItemNullable(ItemData, Session.GetHabbo(), ExtraData);

            Session.GetHabbo().GetInventoryComponent().TryAddItem(Item);
            //Session.SendPacket(new FurniListUpdateComposer());

            using (IQueryAdapter queryreactor = ButterflyEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                queryreactor.SetQuery("INSERT INTO user_photos (user_id,photo,time) VALUES ('" + Session.GetHabbo().Id + "', @photoid, '" + Time + "');");
                queryreactor.AddParameter("photoid", PhotoId);
                queryreactor.RunQuery();
            }

            Session.SendNotification(ButterflyEnvironment.GetLanguageManager().TryGetValue("notif.buyphoto.valide", Session.Langue));
        }
Ejemplo n.º 2
0
 internal void AddBan(uint pId)
 {
     if (!Bans.ContainsKey(pId))
     {
         Bans.Add(pId, ButterflyEnvironment.GetUnixTimestamp());
     }
 }
Ejemplo n.º 3
0
        public ProfileInformationComposer(Habbo habbo, GameClient session, List <Group> groups, int friendCount)
            : base(ServerPacketHeader.ProfileInformationMessageComposer)
        {
            DateTime origin = new DateTime(1970, 1, 1, 0, 0, 0, 0).AddSeconds(habbo.AccountCreated);

            WriteInteger(habbo.Id);
            WriteString(habbo.Username);
            WriteString(habbo.Look);
            WriteString(habbo.Motto);
            WriteString(origin.ToString("dd/MM/yyyy"));
            WriteInteger(habbo.AchievementPoints);
            WriteInteger(friendCount);                                                                                                                                                    // Friend Count
            WriteBoolean(habbo.Id != session.GetHabbo().Id&& session.GetHabbo().GetMessenger().FriendshipExists(habbo.Id));                                                               //  Is friend
            WriteBoolean(habbo.Id != session.GetHabbo().Id&& !session.GetHabbo().GetMessenger().FriendshipExists(habbo.Id) && session.GetHabbo().GetMessenger().RequestExists(habbo.Id)); // Sent friend request
            WriteBoolean((ButterflyEnvironment.GetGame().GetClientManager().GetClientByUserID(habbo.Id)) != null);

            WriteInteger(groups.Count);
            foreach (Group group in groups)
            {
                WriteInteger(group.Id);
                WriteString(group.Name);
                WriteString(group.Badge);
                WriteString(ButterflyEnvironment.GetGame().GetGroupManager().GetColourCode(group.Colour1, true));
                WriteString(ButterflyEnvironment.GetGame().GetGroupManager().GetColourCode(group.Colour2, false));
                WriteBoolean(habbo.FavouriteGroupId == group.Id);        // todo favs
                WriteInteger(0);                                         //what the f**k
                WriteBoolean(group != null ? group.ForumEnabled : true); //HabboTalk
            }

            WriteInteger(Convert.ToInt32(ButterflyEnvironment.GetUnixTimestamp() - habbo.LastOnline)); // Last online
            WriteBoolean(true);                                                                        // Show the profile
        }
Ejemplo n.º 4
0
 public void AddMute(int pId, int Time)
 {
     if (this.Mutes.ContainsKey(pId))
     {
         return;
     }
     this.Mutes.Add(pId, (double)(ButterflyEnvironment.GetUnixTimestamp() + Time));
 }
Ejemplo n.º 5
0
        internal static void GivePixels(GameClient Client, int amount)
        {
            Double Timestamp = ButterflyEnvironment.GetUnixTimestamp();

            Client.GetHabbo().LastActivityPointsUpdate = Timestamp;
            Client.GetHabbo().ActivityPoints          += amount;
            Client.GetHabbo().UpdateActivityPointsBalance(0);
        }
Ejemplo n.º 6
0
        internal static ServerMessage SerializeUserInfo(uint UserId)
        {
            using (IQueryAdapter dbClient = ButterflyEnvironment.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((ButterflyEnvironment.GetUnixTimestamp() - (Double)Info["reg_timestamp"]) / 60));
                    Message.AppendInt32((int)Math.Ceiling((ButterflyEnvironment.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);
            }
        }
Ejemplo n.º 7
0
        internal DatabaseClientOld(uint Handle, string connectionString, DatabaseManagerOld pManager)
        {
            handleID = Handle;
            manager  = pManager;

            connection            = new MySqlConnection(connectionString);
            sqlCommand            = connection.CreateCommand();
            lastActivityTimestamp = ButterflyEnvironment.GetUnixTimestamp();
        }
Ejemplo n.º 8
0
        internal Boolean IsValid()
        {
            if (TimeExpire <= ButterflyEnvironment.GetUnixTimestamp())
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 9
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 = ButterflyEnvironment.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);
                        }
                    }
                }
            }
        }
Ejemplo n.º 10
0
 public void Pick(int pModeratorId, bool UpdateInDb)
 {
     this.Status      = TicketStatus.PICKED;
     this.ModeratorId = pModeratorId;
     this.Timestamp   = (double)ButterflyEnvironment.GetUnixTimestamp();
     if (!UpdateInDb)
     {
         return;
     }
     using (IQueryAdapter queryreactor = ButterflyEnvironment.GetDatabaseManager().GetQueryReactor())
         queryreactor.RunQuery("UPDATE moderation_tickets SET status = 'picked', moderator_id = " + pModeratorId + ", timestamp = '" + ButterflyEnvironment.GetUnixTimestamp() + "' WHERE id = " + this.Id);
 }
Ejemplo n.º 11
0
        public bool TryExecute(string[] parameters)
        {
            if (parameters.Length != 3)
            {
                return(false);
            }

            int Userid = 0;

            if (!int.TryParse(parameters[1], out Userid))
            {
                return(false);
            }
            if (Userid == 0)
            {
                return(false);
            }

            GameClient Client = ButterflyEnvironment.GetGame().GetClientManager().GetClientByUserID(Userid);

            if (Client == null)
            {
                return(false);
            }

            string PhotoId = parameters[2];

            ItemData ItemData = null;

            if (!ButterflyEnvironment.GetGame().GetItemManager().GetItem(4581, out ItemData))
            {
                return(false);
            }

            int    Time      = ButterflyEnvironment.GetUnixTimestamp();
            string ExtraData = "{\"w\":\"" + "/photos/" + PhotoId + ".png" + "\", \"n\":\"" + Client.GetHabbo().Username + "\", \"s\":\"" + Client.GetHabbo().Id + "\", \"u\":\"" + "0" + "\", \"t\":\"" + Time + "000" + "\"}";

            Item Item = ItemFactory.CreateSingleItemNullable(ItemData, Client.GetHabbo(), ExtraData);

            Client.GetHabbo().GetInventoryComponent().TryAddItem(Item);

            using (IQueryAdapter queryreactor = ButterflyEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                queryreactor.SetQuery("INSERT INTO user_photos (user_id,photo,time) VALUES ('" + Client.GetHabbo().Id + "', @photoid, '" + Time + "');");
                queryreactor.AddParameter("photoid", PhotoId);
                queryreactor.RunQuery();
            }

            Client.SendNotification(ButterflyEnvironment.GetLanguageManager().TryGetValue("notif.buyphoto.valide", Client.Langue));

            return(true);
        }
Ejemplo n.º 12
0
        internal Boolean HasBanExpired(uint pId)
        {
            if (!UserIsBanned(pId))
            {
                return(true);
            }

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

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

            return(false);
        }
Ejemplo n.º 13
0
        public void PlaySong()
        {
            if (mSongQueuePosition >= mPlaylist.Count)
            {
                mSongQueuePosition = 0;
            }

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

            mSong = mPlaylist[mSongQueuePosition];
            mStartedPlayingTimestamp = ButterflyEnvironment.GetUnixTimestamp();
            mBroadcastNeeded         = true;
        }
Ejemplo n.º 14
0
        public void BanUser(GameClient Client, string Moderator, double LengthSeconds, string Reason, bool IpBan, bool MachineBan)
        {
            if (string.IsNullOrEmpty(Reason))
            {
                Reason = "Ne respect pas les régles";
            }

            string Variable = Client.GetHabbo().Username.ToLower();
            string str      = "user";
            double Expire   = (double)ButterflyEnvironment.GetUnixTimestamp() + LengthSeconds;

            if (IpBan)
            {
                //Variable = Client.GetConnection().getIp();
                Variable = Client.GetHabbo().IP;
                str      = "ip";
            }

            if (MachineBan)
            {
                Variable = Client.MachineId;
                str      = "machine";
            }

            using (IQueryAdapter queryreactor = ButterflyEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                queryreactor.SetQuery("INSERT INTO bans (bantype,value,reason,expire,added_by,added_date) VALUES (@rawvar, @var, @reason, '" + Expire + "', @mod, UNIX_TIMESTAMP())");
                queryreactor.AddParameter("rawvar", str);
                queryreactor.AddParameter("var", Variable);
                queryreactor.AddParameter("reason", Reason);
                queryreactor.AddParameter("mod", Moderator);
                queryreactor.RunQuery();
            }
            if (MachineBan)
            {
                this.BanUser(Client, Moderator, LengthSeconds, Reason, true, false);
            }
            else if (IpBan)
            {
                this.BanUser(Client, Moderator, LengthSeconds, Reason, false, false);
            }
            else
            {
                Client.Disconnect();
            }
        }
Ejemplo n.º 15
0
        public void TryAuthenticate(string AuthTicket)
        {
            if (string.IsNullOrEmpty(AuthTicket))
            {
                return;
            }

            string ip = this.GetConnection().getIp();

            using (IQueryAdapter queryreactor = ButterflyEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                queryreactor.SetQuery("SELECT id FROM bans WHERE expire > @nowtime AND (bantype = 'ip' AND value = @IP1) LIMIT 1");
                queryreactor.AddParameter("nowtime", ButterflyEnvironment.GetUnixTimestamp());
                queryreactor.AddParameter("IP1", ip);

                DataRow IsBanned = queryreactor.GetRow();
                if (IsBanned != null)
                {
                    return;
                }

                queryreactor.SetQuery("SELECT user_id, is_staff, langue FROM user_websocket WHERE auth_ticket = @sso");
                queryreactor.AddParameter("sso", AuthTicket);

                DataRow dUserInfo = queryreactor.GetRow();
                if (dUserInfo == null)
                {
                    return;
                }

                this.UserId   = Convert.ToInt32(dUserInfo["user_id"]);
                this._isStaff = ButterflyEnvironment.EnumToBool((string)dUserInfo["is_staff"]);
                this.Langue   = LanguageManager.ParseLanguage(Convert.ToString(dUserInfo["langue"]));
                queryreactor.RunQuery("UPDATE user_websocket SET auth_ticket = '' WHERE user_id = '" + UserId + "'");

                this._sendSettingSound(queryreactor);
            }

            ButterflyEnvironment.GetGame().GetClientWebManager().LogClonesOut(UserId);
            ButterflyEnvironment.GetGame().GetClientWebManager().RegisterClient(this, UserId);

            this.SendPacket(new AuthOkComposer());
            this.SendPacket(new UserIsStaffComposer(this._isStaff));
            //this.SendPacket(new NotifTopInitComposer(ButterflyEnvironment.GetGame().GetNotifTopManager().GetAllMessages()));
        }
Ejemplo n.º 16
0
        public ServerPacket Serialize()
        {
            ServerPacket serverMessage = new ServerPacket(ServerPacketHeader.ModeratorSupportTicketMessageComposer);

            serverMessage.WriteInteger(this.Id);
            serverMessage.WriteInteger(this.TabId);
            serverMessage.WriteInteger(3);
            serverMessage.WriteInteger(this.Type);
            serverMessage.WriteInteger((int)(ButterflyEnvironment.GetUnixTimestamp() - this.Timestamp) * 1000);
            serverMessage.WriteInteger(this.Score);
            serverMessage.WriteInteger(this.SenderId);
            serverMessage.WriteInteger(this.SenderId);
            if (ButterflyEnvironment.GetHabboById(this.SenderId) != null)
            {
                serverMessage.WriteString(this.SenderName.Equals("") ? ButterflyEnvironment.GetHabboById(this.SenderId).Username : this.SenderName);
            }
            else
            {
                serverMessage.WriteString(this.SenderName);
            }
            serverMessage.WriteInteger(this.ReportedId);
            if (ButterflyEnvironment.GetHabboById(this.ReportedId) != null)
            {
                serverMessage.WriteString(this.ReportedName.Equals("") ? ButterflyEnvironment.GetHabboById(this.ReportedId).Username : this.ReportedName);
            }
            else
            {
                serverMessage.WriteString(this.ReportedName);
            }
            serverMessage.WriteInteger(this.Status == TicketStatus.PICKED ? this.ModeratorId : 0);
            if (ButterflyEnvironment.GetHabboById(this.ModeratorId) != null)
            {
                serverMessage.WriteString(this.Status == TicketStatus.PICKED ? (this.ModName.Equals("") ? ButterflyEnvironment.GetHabboById(this.ModeratorId).Username : this.ModName) : "");
            }
            else
            {
                serverMessage.WriteString(this.ModName);
            }
            serverMessage.WriteString(this.Message);
            serverMessage.WriteInteger(0);
            serverMessage.WriteInteger(0);

            return(serverMessage);
        }
Ejemplo n.º 17
0
        internal void GetSubscriptionData()
        {
            string SubscriptionId = Request.PopFixedString();

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

            if (Session.GetHabbo().GetSubscriptionManager().HasSubscription(SubscriptionId))
            {
                Double Expire        = Session.GetHabbo().GetSubscriptionManager().GetSubscription(SubscriptionId).ExpireTime;
                Double TimeLeft      = Expire - ButterflyEnvironment.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();
        }
Ejemplo n.º 18
0
        internal static void Process()
        {
            TimeSpan sinceLastTime = DateTime.Now - processLastExecution;

            if (sinceLastTime.TotalMilliseconds >= 30000)
            {
                processLastExecution = DateTime.Now;
                try
                {
                    TimeSpan Uptime = DateTime.Now - ButterflyEnvironment.ServerStarted;
                    string   addOn  = string.Empty;
                    if (System.Diagnostics.Debugger.IsAttached)
                    {
                        addOn = "[DEBUG] ";
                    }
                    mColdTitle = addOn + "Butterfly | Uptime: " + Uptime.Minutes + " minutes, " + Uptime.Hours + " hours and " + Uptime.Days + " day | " +
                                 "Online users: " + ButterflyEnvironment.GetGame().GetClientManager().ClientCount + " | Loaded rooms: " + ButterflyEnvironment.GetGame().GetRoomManager().LoadedRoomsCount;

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

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

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

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

                    using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().getQueryreactor())
                    {
                        dbClient.runFastQuery("UPDATE server_status SET stamp = '" + ButterflyEnvironment.GetUnixTimestamp() + "', status = " + Status + ", users_online = " + UsersOnline + ", rooms_loaded = " + RoomsLoaded + ", server_ver = '" + ButterflyEnvironment.PrettyVersion + "', userpeak = " + UserPeak + "");
                    }
                    #endregion
                }
                catch (Exception e) { Logging.LogThreadException(e.ToString(), "Server status update task"); }
            }
        }
Ejemplo n.º 19
0
        public void Parse(GameClient Session, ClientPacket Packet)
        {
            string PhotoId = Packet.PopString();

            if (string.IsNullOrEmpty(PhotoId) || !ButterflyEnvironment.IsValidAlphaNumeric(PhotoId) || PhotoId.Length != 32)
            {
                Session.SendNotification(ButterflyEnvironment.GetLanguageManager().TryGetValue("notif.buyphoto.error", Session.Langue) + " ( " + PhotoId + " ) ");
                return;
            }

            if (!ButterflyEnvironment.GetGame().GetItemManager().GetItem(4581, out ItemData ItemData))
            {
                return;
            }

            if (!ButterflyEnvironment.GetGame().GetItemManager().GetItem(4597, out ItemData ItemDataSmall))
            {
                return;
            }

            int    Time      = ButterflyEnvironment.GetUnixTimestamp();
            string ExtraData = "{\"w\":\"" + "/photos/" + PhotoId + ".png" + "\", \"n\":\"" + Session.GetHabbo().Username + "\", \"s\":\"" + Session.GetHabbo().Id + "\", \"u\":\"" + "0" + "\", \"t\":\"" + Time + "000" + "\"}";


            Item ItemSmall = ItemFactory.CreateSingleItemNullable(ItemDataSmall, Session.GetHabbo(), ExtraData);

            Session.GetHabbo().GetInventoryComponent().TryAddItem(ItemSmall);

            Item Item = ItemFactory.CreateSingleItemNullable(ItemData, Session.GetHabbo(), ExtraData);

            Session.GetHabbo().GetInventoryComponent().TryAddItem(Item);

            Session.SendPacket(new CameraPurchaseSuccesfullComposer());

            /*using (IQueryAdapter queryreactor = ButterflyEnvironment.GetDatabaseManager().GetQueryReactor())
             * {
             *  queryreactor.SetQuery("INSERT INTO user_photos (user_id,photo,time) VALUES ('" + Session.GetHabbo().Id + "', @photoid, '" + Time + "');");
             *  queryreactor.AddParameter("photoid", PhotoId);
             *  queryreactor.RunQuery();
             * }*/

            //Session.SendNotification(ButterflyEnvironment.GetLanguageManager().TryGetValue("notif.buyphoto.valide", Session.Langue));
        }
Ejemplo n.º 20
0
        internal static void ProcessThread()
        {
            double CurrentTime = ButterflyEnvironment.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);
            }
        }
Ejemplo n.º 21
0
        public bool TryCreateGroup(Habbo Player, string Name, string Description, int RoomId, string Badge, int Colour1, int Colour2, out Group Group)
        {
            Group = new Group(0, Name, Description, Badge, RoomId, Player.Id, (int)ButterflyEnvironment.GetUnixTimestamp(), 0, Colour1, Colour2, 0, false);
            if (string.IsNullOrWhiteSpace(Name) || string.IsNullOrWhiteSpace(Badge))
            {
                return(false);
            }

            using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                dbClient.SetQuery("INSERT INTO `groups` (`name`, `desc`, `badge`, `owner_id`, `created`, `room_id`, `state`, `colour1`, `colour2`, `admindeco`) VALUES (@name, @desc, @badge, @owner, UNIX_TIMESTAMP(), @room, '0', @colour1, @colour2, '1')");
                dbClient.AddParameter("name", Group.Name);
                dbClient.AddParameter("desc", Group.Description);
                dbClient.AddParameter("owner", Group.CreatorId);
                dbClient.AddParameter("badge", Group.Badge);
                dbClient.AddParameter("room", Group.RoomId);
                dbClient.AddParameter("colour1", Group.Colour1);
                dbClient.AddParameter("colour2", Group.Colour2);
                Group.Id = Convert.ToInt32(dbClient.InsertQuery());

                Group.AddMember(Player.Id);
                Group.MakeAdmin(Player.Id);

                Player.MyGroups.Add(Group.Id);

                if (!this._groups.TryAdd(Group.Id, Group))
                {
                    return(false);
                }
                else
                {
                    dbClient.SetQuery("UPDATE `rooms` SET `groupId` = @gid WHERE `id` = @rid LIMIT 1");
                    dbClient.AddParameter("gid", Group.Id);
                    dbClient.AddParameter("rid", Group.RoomId);
                    dbClient.RunQuery();

                    dbClient.RunQuery("DELETE FROM `room_rights` WHERE `room_id` = '" + RoomId + "'");
                }
            }
            return(true);
        }
Ejemplo n.º 22
0
        public ServerPacket Serialize(ServerPacket message)
        {
            message.WriteInteger(Id);                                                                // id
            message.WriteInteger(TabId);                                                             // state
            message.WriteInteger(4);                                                                 // type (3 or 4 for new style)
            message.WriteInteger(Type);                                                              // priority
            message.WriteInteger((int)(ButterflyEnvironment.GetUnixTimestamp() - Timestamp) * 1000); // -->> timestamp
            message.WriteInteger(Score);                                                             // priority
            message.WriteInteger(SenderId);
            message.WriteInteger(SenderId);                                                          // sender id 8 ints
            message.WriteString(SenderName);                                                         // sender name
            message.WriteInteger(ReportedId);
            message.WriteString(ReportedName);
            message.WriteInteger((Status == TicketStatus.PICKED) ? ModeratorId : 0); // mod id
            message.WriteString(ModName);                                            // mod name
            message.WriteString(this.Message);                                       // issue message
            message.WriteInteger(0);
            message.WriteInteger(0);

            return(message);
        }
Ejemplo n.º 23
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)ButterflyEnvironment.GetUnixTimestamp() + DurationSeconds));
                }

                using (IQueryAdapter dbClient = ButterflyEnvironment.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)ButterflyEnvironment.GetUnixTimestamp();
            int TimeExpire  = ((int)ButterflyEnvironment.GetUnixTimestamp() + DurationSeconds);

            Subscription NewSub = new Subscription(SubscriptionId, TimeExpire);

            using (IQueryAdapter dbClient = ButterflyEnvironment.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);
        }
Ejemplo n.º 24
0
        internal static Boolean NeedsUpdate(GameClient Client)
        {
            try
            {
                if (Client.GetHabbo() == null)
                {
                    return(false);
                }

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

                if (PassedMins >= RCV_EVERY_MINS)
                {
                    return(true);
                }
            }
            catch (Exception e)
            {
                Logging.HandleException(e, "PixelManager.NeedsUpdate");
            }
            return(false);
        }
Ejemplo n.º 25
0
        private void MonitorConnections()
        {
            while (!ButterflyEnvironment.ShutdownStarted)
            {
                try
                {
                    lockObject.EnterReadLock();

                    int timeStamp = ButterflyEnvironment.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
            }
        }
Ejemplo n.º 26
0
        public void Parse(GameClient Session, ClientPacket Packet)
        {
            if (Session.GetHabbo() == null || Session == null)
            {
                return;
            }
            Room Room = ButterflyEnvironment.GetGame().GetRoomManager().GetRoom(Session.GetHabbo().CurrentRoomId);

            if (Room == null)
            {
                return;
            }
            RoomUser User = Room.GetRoomUserManager().GetRoomUserByHabbo(Session.GetHabbo().Username);

            if (User == null)
            {
                return;
            }
            string NewUsername = Packet.PopString();

            if (!Session.GetHabbo().CanChangeName&& Session.GetHabbo().Rank == 1)
            {
                Session.SendNotification(ButterflyEnvironment.GetLanguageManager().TryGetValue("notif.changename.error.1", Session.Langue));
                return;
            }

            if (NewUsername == Session.GetHabbo().Username)
            {
                Session.SendPacket(new UpdateUsernameComposer(Session.GetHabbo().Username));
                return;
            }

            if (this.NameAvailable(NewUsername) != 1)
            {
                Session.SendNotification(ButterflyEnvironment.GetLanguageManager().TryGetValue("notif.changename.error.2", Session.Langue));
                return;
            }

            using (IQueryAdapter queryreactor = ButterflyEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                queryreactor.SetQuery("UPDATE rooms SET owner = @newname WHERE owner = @oldname");
                queryreactor.AddParameter("newname", NewUsername);
                queryreactor.AddParameter("oldname", Session.GetHabbo().Username);
                queryreactor.RunQuery();

                queryreactor.SetQuery("UPDATE users SET username = @newname WHERE id = @userid");
                queryreactor.AddParameter("newname", NewUsername);
                queryreactor.AddParameter("userid", Session.GetHabbo().Id);
                queryreactor.RunQuery();

                queryreactor.SetQuery("INSERT INTO `logs_flagme` (`user_id`, `oldusername`, `newusername`, `time`) VALUES (@userid, @oldusername, @newusername, '" + ButterflyEnvironment.GetUnixTimestamp() + "');");
                queryreactor.AddParameter("userid", Session.GetHabbo().Id);
                queryreactor.AddParameter("oldusername", Session.GetHabbo().Username);
                queryreactor.AddParameter("newusername", NewUsername);
                queryreactor.RunQuery();
            }
            ButterflyEnvironment.GetGame().GetClientManager().UpdateClientUsername(Session.ConnectionID, Session.GetHabbo().Username, NewUsername);
            Room.GetRoomUserManager().UpdateClientUsername(User, Session.GetHabbo().Username, NewUsername);
            Session.GetHabbo().Username      = NewUsername;
            Session.GetHabbo().CanChangeName = false;

            Session.SendPacket(new UpdateUsernameComposer(NewUsername));
            Session.SendPacket(new UserObjectComposer(Session.GetHabbo()));

            Session.GetHabbo().UpdateRooms();
            foreach (RoomData roomData in Session.GetHabbo().UsersRooms)
            {
                roomData.OwnerName = NewUsername;

                Room roomowner = ButterflyEnvironment.GetGame().GetRoomManager().GetRoom(roomData.Id);
                if (roomowner != null)
                {
                    roomowner.RoomData.OwnerName = NewUsername;
                }
            }

            Room.SendPacket(new UserNameChangeMessageComposer(NewUsername, User.VirtualId));

            if (Session.GetHabbo().Id != Room.RoomData.OwnerId)
            {
                return;
            }
            Room.SendPacket(new RoomInfoUpdatedMessageComposer(Room.Id));
        }
Ejemplo n.º 27
0
        public void Parse(HabboHotel.GameClients.GameClient Session, ClientPacket Packet)
        {
            int SellingPrice   = Packet.PopInt();
            int ComissionPrice = Packet.PopInt();
            int ItemId         = Packet.PopInt();

            Item Item = Session.GetHabbo().GetInventoryComponent().GetItem(ItemId);

            if (Item == null)
            {
                Session.SendPacket(new MarketplaceMakeOfferResultComposer(0));
                return;
            }

            if (!ItemUtility.IsRare(Item))
            {
                return;
            }

            if (SellingPrice > 99999 || SellingPrice <= 0)
            {
                Session.SendPacket(new MarketplaceMakeOfferResultComposer(0));
                return;
            }

            int Comission  = ButterflyEnvironment.GetGame().GetCatalog().GetMarketplace().CalculateComissionPrice((float)SellingPrice);
            int TotalPrice = SellingPrice + Comission;
            int ItemType   = 1;

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

            using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                dbClient.RunQuery("DELETE items, items_limited FROM items LEFT JOIN items_limited ON(items_limited.item_id = items.id) WHERE `id` = '" + ItemId + "'");

                dbClient.SetQuery("INSERT INTO `catalog_marketplace_offers` (`furni_id`,`item_id`,`user_id`,`asking_price`,`total_price`,`public_name`,`sprite_id`,`item_type`,`timestamp`,`extra_data`,`limited_number`,`limited_stack`) VALUES ('" + ItemId + "','" + Item.BaseItem + "','" + Session.GetHabbo().Id + "','" + SellingPrice + "','" + TotalPrice + "',@public_name,'" + Item.GetBaseItem().SpriteId + "','" + ItemType + "','" + ButterflyEnvironment.GetUnixTimestamp() + "',@extra_data, '" + Item.LimitedNo + "', '" + Item.LimitedTot + "')");
                dbClient.AddParameter("public_name", Item.GetBaseItem().ItemName);
                dbClient.AddParameter("extra_data", Item.ExtraData);
                dbClient.RunQuery();
            }

            Session.GetHabbo().GetInventoryComponent().RemoveItem(ItemId);
            Session.SendPacket(new MarketplaceMakeOfferResultComposer(1));
        }
Ejemplo n.º 28
0
 public double FormatTimestamp()
 {
     return(ButterflyEnvironment.GetUnixTimestamp() - 172800);
 }
Ejemplo n.º 29
0
 public bool HasMuteExpired(int pId)
 {
     return(!this.UserIsMuted(pId) || this.Mutes[pId] - (double)ButterflyEnvironment.GetUnixTimestamp() <= 0.0);
 }
Ejemplo n.º 30
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 = '" + ButterflyEnvironment.PrettyVersion + "', stamp = '" + ButterflyEnvironment.GetUnixTimestamp() + "' ");
 }