Beispiel #1
0
        internal void OnDisconnect()
        {
            if (this.Disconnected)
            {
                return;
            }

            this.Disconnected = true;

            ButterflyEnvironment.GetGame().GetClientManager().UnregisterClient(Id, Username);
            SessionManagement.IncreaseDisconnection();
            Logging.WriteLine(Username + " has logged out.");


            if (!HabboinfoSaved)
            {
                HabboinfoSaved = true;
                using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().getQueryreactor())
                {
                    dbClient.runFastQuery("UPDATE users SET users.last_online = '" + DateTime.Now.ToString() + "', activity_points = " + ActivityPoints + ", activity_points_lastupdate = '" + LastActivityPointsUpdate + "', credits = " + Credits + ", achievement_points = " + AchievementPoints + " WHERE id = " + Id + " ;");
                }
            }

            if (InRoom && CurrentRoom != null)
            {
                CurrentRoom.GetRoomUserManager().RemoveUserFromRoom(mClient, false, false);
            }

            if (Messenger != null)
            {
                Messenger.AppearOffline = true;
                Messenger.Destroy();
            }

            if (SubscriptionManager != null)
            {
                SubscriptionManager.Clear();
            }

            if (AvatarEffectsInventoryComponent != null)
            {
                AvatarEffectsInventoryComponent.Dispose();
            }

            if (InventoryComponent != null)
            {
                InventoryComponent.SetIdleState();
                InventoryComponent.RunDBUpdate();
            }

            this.mClient = null;
        }
Beispiel #2
0
        public void Dispose()
        {
            if (InventoryComponent != null)
            {
                InventoryComponent.SetIdleState();
            }

            if (InRoom && CurrentRoom != null)
            {
                CurrentRoom.GetRoomUserManager().RemoveUserFromRoom(_client, false, false);
            }

            if (Messenger != null)
            {
                Messenger.AppearOffline = true;
                Messenger.Destroy();
            }

            if (_fx != null)
            {
                _fx.Dispose();
            }

            if (_clothing != null)
            {
                _clothing.Dispose();
            }

            if (_permissions != null)
            {
                _permissions.Dispose();
            }

            if (_ignores != null)
            {
                _permissions.Dispose();
            }
        }
Beispiel #3
0
        /// <summary>
        ///     Called when [disconnect].
        /// </summary>
        /// <param name="reason">The reason.</param>
        internal void OnDisconnect(string reason)
        {
            if (Disconnected)
            {
                return;
            }

            Disconnected = true;

            if (_inventoryComponent != null)
            {
                lock (_inventoryComponent)
                {
                    _inventoryComponent?.RunDbUpdate();
                    _inventoryComponent?.SetIdleState();
                }
            }

            string navilogs = string.Empty;

            if (NavigatorLogs.Any())
            {
                navilogs = NavigatorLogs.Values.Aggregate(navilogs,
                                                          (current, navi) => current + $"{navi.Id},{navi.Value1},{navi.Value2};");
                navilogs = navilogs.Remove(navilogs.Length - 1);
            }

            Yupi.GetGame().GetClientManager().UnregisterClient(Id, UserName);

            YupiWriterManager.WriteLine(UserName + " left game. Reason: " + reason, "Yupi.Users",
                                        ConsoleColor.DarkYellow);

            TimeSpan getOnlineSeconds = DateTime.Now - TimeLoggedOn;

            int secondsToGive = getOnlineSeconds.Seconds;

            if (!_habboinfoSaved)
            {
                _habboinfoSaved = true;
                using (IQueryAdapter queryReactor = Yupi.GetDatabaseManager().GetQueryReactor())
                {
                    queryReactor.SetQuery("UPDATE users SET activity_points = " + Duckets +
                                          ", credits = " +
                                          Credits + ", diamonds = " + Diamonds +
                                          ", online='0', last_online = '" +
                                          Yupi.GetUnixTimeStamp() + "', builders_items_used = " +
                                          BuildersItemsUsed +
                                          ", navigator_logs = @navilogs  WHERE id = " + Id +
                                          " LIMIT 1;UPDATE users_stats SET achievement_score=" +
                                          AchievementPoints +
                                          " WHERE id=" + Id + " LIMIT 1;");
                    queryReactor.AddParameter("navilogs", navilogs);
                    queryReactor.RunQuery();
                    queryReactor.RunFastQuery("UPDATE users_stats SET online_seconds = online_seconds + " +
                                              secondsToGive + " WHERE id = " + Id);

                    if (Rank >= 4)
                    {
                        queryReactor.RunFastQuery(
                            $"UPDATE moderation_tickets SET status='open', moderator_id=0 WHERE status='picked' AND moderator_id={Id}");
                    }

                    queryReactor.RunFastQuery("UPDATE users SET block_newfriends = '" +
                                              Convert.ToInt32(HasFriendRequestsDisabled) +
                                              "', hide_online = '" +
                                              Convert.ToInt32(AppearOffline) + "', hide_inroom = '" +
                                              Convert.ToInt32(HideInRoom) + "' WHERE id = " + Id);
                }
            }

            if (InRoom)
            {
                CurrentRoom?.GetRoomUserManager().RemoveUserFromRoom(_mClient, false, false);
            }

            if (_messenger != null)
            {
                _messenger.AppearOffline = true;
                _messenger.Destroy();
                _messenger = null;
            }

            _avatarEffectComponent?.Dispose();

            _mClient = null;
        }
Beispiel #4
0
        /// <summary>
        /// Called when [disconnect].
        /// </summary>
        /// <param name="reason">The reason.</param>
        internal void OnDisconnect(string reason)
        {
            if (Disconnected)
            {
                return;
            }

            Disconnected = true;

            if (_inventoryComponent != null)
            {
                if (_mClient.GetRoleplay().UsingPet&& GetRoomUser().MyPet != null)
                {
                    using (var Adapt = Plus.GetDatabaseManager().GetQueryReactor())
                    {
                        Adapt.RunFastQuery("UPDATE bots SET room_id = '0' WHERE id = ' " + GetRoomUser().MyPet.PetData.PetId + "'");
                    }
                    _mClient.GetMessageHandler().PickUpPet(_mClient, GetRoomUser().MyPet.PetData.PetId, true);
                }
                _inventoryComponent.RunDbUpdate();
                _inventoryComponent.SetIdleState();
            }

            var navilogs = string.Empty;

            if (NavigatorLogs.Any())
            {
                navilogs = NavigatorLogs.Values.Aggregate(navilogs, (current, navi) => current + string.Format("{0},{1},{2};", navi.Id, navi.Value1, navi.Value2));
                navilogs = navilogs.Remove(navilogs.Length - 1);
            }

            Plus.GetGame().GetClientManager().UnregisterClient(Id, UserName);
            SessionManagement.IncreaseDisconnection();

            Out.WriteLine("[" + UserName + "] has logged out! Reason: " + reason, "", ConsoleColor.DarkYellow);

            TimeSpan GetOnlineSeconds = DateTime.Now - TimeLoggedOn;
            int      SecondsToGive    = GetOnlineSeconds.Seconds;
            int      GiveOnlineTime   = Plus.GetUnixTimeStamp() - TimeLoggedOn1;

            if (_mClient.GetRoleplay().IsBoxing&& _mClient.GetRoleplay().BoxingRoom != null && _mClient.GetRoleplay().BoxingRoom.SoloQueue != null)
            {
                if (_mClient.GetRoleplay().BoxingRoom.SoloQueue.PlayerQueue.Contains(_mClient))
                {
                    _mClient.GetRoleplay().BoxingRoom.SoloQueue.PlayerQueue.Remove(_mClient);
                }

                _mClient.GetRoleplay().BoxingRoom.SoloQueue.RemoveBoxer(_mClient, true);
            }

            // If the user is in colour wars
            if (_mClient.GetRoleplay().inColourWars)
            {
                // Remove the user from team
                string team;
                team = _mClient.GetRoleplay().ColourWarTeam.Colour.ToLower().ToString();
                _mClient.GetRoleplay().SaveQuickStat("last_cw_team", team);

                ColourManager.RemovePlayerFromTeam(_mClient, _mClient.GetRoleplay().ColourWarTeam, true, "eat", true);
            }

            if (_mClient.GetRoleplay().InMafiaWars)
            {
                Plus.GetGame().MafiaWars.RemoveUserFromGame(_mClient, _mClient.GetRoleplay().TeamString, true, true);
            }

            if (_mClient.GetRoleplay().Bag != null)
            {
                HabboHotel.Roleplay.Misc.RoleplayManager.PickRock(_mClient.GetRoleplay().Bag, _mClient.GetRoleplay().Bag.RoomId);
            }

            if (!_habboinfoSaved)
            {
                _habboinfoSaved = true;
                using (var queryReactor = Plus.GetDatabaseManager().GetQueryReactor())
                {
                    if (this != null)
                    {
                        if (_mClient != null)
                        {
                            if (_mClient.GetRoleplay() != null)
                            {
                                _mClient.GetRoleplay().SaveStats();
                                _mClient.GetRoleplay().Dispose(); // Dispose of roleplay
                            }
                        }
                    }

                    queryReactor.SetQuery("UPDATE users SET activity_points = " + ActivityPoints + ", credits = " + Credits + ", seasonal_currency = " + BelCredits + ", online='0', last_online = '" + Plus.GetUnixTimeStamp() + "', builders_items_used = " + BuildersItemsUsed + ", navigator = '" + Plus.BoolToEnum(NewNavigator) + "', navilogs = @navilogs  WHERE id = " + Id + " LIMIT 1;UPDATE users_stats SET achievement_score=" + AchievementPoints + " WHERE id=" + Id + " LIMIT 1;");
                    queryReactor.AddParameter("navilogs", navilogs);
                    queryReactor.RunQuery();

                    queryReactor.RunFastQuery("UPDATE users_stats SET online_seconds = online_seconds + " + GiveOnlineTime + " WHERE id = " + Id);

                    if (Rank >= 4u)
                    {
                        queryReactor.RunFastQuery(
                            string.Format(
                                "UPDATE moderation_tickets SET status='open', moderator_id=0 WHERE status='picked' AND moderator_id={0}",
                                Id));
                    }
                }
            }

            if (InRoom && CurrentRoom != null)
            {
                CurrentRoom.GetRoomUserManager().RemoveUserFromRoom(_mClient, false, false);
            }
            if (_messenger != null)
            {
                _messenger.AppearOffline = true;
                _messenger.Destroy();
            }

            if (_avatarEffectsInventoryComponent != null)
            {
                _avatarEffectsInventoryComponent.Dispose();
            }
            _mClient = null;
        }
Beispiel #5
0
        internal void OnDisconnect()
        {
            try
            {
                if (Disconnected)
                {
                    return;
                }

                Disconnected = true;

                if (Messenger != null)
                {
                    Messenger.AppearOffline = true;
                    Messenger.Destroy();
                    Messenger = null;
                }

                if (IsPremium())
                {
                    GetPremiumManager().Destroy();
                }

                saveWardrobe();
                SaveBadges();
                //HabboEnvironment.GetGame().GetMuteManager().RemoveUserMute(Id);

                var pollParticipation = "";
                if (this.PollParticipation.Count > 0)
                {
                    foreach (UInt32 value in this.PollParticipation)
                    {
                        pollParticipation += value + ";";
                    }
                    pollParticipation = pollParticipation.Remove(pollParticipation.Length - 1);
                }

                var votedRooms = "";
                if (this.RatedRooms.Count > 0)
                {
                    foreach (UInt32 value in this.RatedRooms)
                    {
                        votedRooms += value + ";";
                    }
                    votedRooms = votedRooms.Remove(votedRooms.Length - 1);
                }

                var actrewards = "";
                if (this.WiredRewards.Count > 0)
                {
                    foreach (WiredActReward wrd in this.WiredRewards.Values)
                    {
                        actrewards += wrd.ItemId + "," + wrd.LastUpdate + "," + wrd.ActualRewards + "," + wrd.OriginalInt + ";";
                    }
                    actrewards = actrewards.Remove(actrewards.Length - 1);
                }

                var navilogs = "";
                if (this.navigatorLogs.Count > 0)
                {
                    foreach (NaviLogs navi in this.navigatorLogs.Values)
                    {
                        navilogs += navi.Id + "," + navi.Value1 + "," + navi.Value2 + ";";
                    }
                    navilogs = navilogs.Remove(navilogs.Length - 1);
                }

                var targetedoffers = "";
                if (this.TargetedOffers.Count > 0)
                {
                    foreach (KeyValuePair <uint, uint> k in this.TargetedOffers)
                    {
                        targetedoffers += k.Key + "-" + k.Value + ";";
                    }
                    targetedoffers = targetedoffers.Remove(targetedoffers.Length - 1);
                }

                using (var dbClient = OtanixEnvironment.GetDatabaseManager().getQueryreactor())
                {
                    dbClient.setQuery("UPDATE users SET namechanges = '" + NameChanges + "', respect = '" + Respect +
                                      "', daily_respect_points = '" + DailyRespectPoints +
                                      "', daily_pet_respect_points = '" + DailyPetRespectPoints + "'," +
                                      " diamonds = '" + Diamonds + "',  machine_last = @machineLast, currentquestid = '" + CurrentQuestId +
                                      "', block_trade = '" + ((BlockTrade) ? "1" : "0") + "'," +
                                      " block_newfriends = '" + ((HasFriendRequestsDisabled) ? "1" : "0") +
                                      "', look = @look, motto = @motto, gender = @gender, last_online = '" + LastOnline.ToString() + "'," +
                                      " achievement_points = '" + AchievementPoints + "', home_room = '" + HomeRoom + "', volumenSystem = '" +
                                      volumenSystem + "', prefer_old_chat = '" + ((preferOldChat) ? "1" : "0") + "'," +
                                      " last_purchase = '" + LastPurchase + "'," +
                                      " poll_participation = '" + pollParticipation + "', voted_rooms = '" + votedRooms + "'," +
                                      " lastfollowinglogin = '******', ignoreRoomInvitations = '" + ((IgnoreRoomInvitations) ? "1" : "0") + "'," +
                                      " citizenship_level = '" + CitizenshipLevel + "', helper_level = '" + HelperLevel + "', actrewards = '" + actrewards + "', dontfocususers = '" + ((DontFocusUser) ? "1" : "0") + "'," +
                                      " navilogs = @navilogs, targeted_offers = @targetedoffers, alertasAtivados = '" + ((alertasAtivados) ? "1" : "0") + "', frankJaApareceu = '" + ((frankJaApareceu) ? "1" : "0") + "', FavoriteGroup = '" + FavoriteGroup + "', moedas = '" + Moedas + "', corAtual = @coratual, coresjaTenho  = '" + coresjaTenho + "', new_identity = '" + NewIdentity + "', new_bot = '" + NewBot + "', coins_purchased = '" + CoinsPurchased + "' WHERE id = " + Id);
                    dbClient.addParameter("look", Look);
                    dbClient.addParameter("coratual", corAtual);
                    dbClient.addParameter("motto", Motto);
                    dbClient.addParameter("gender", Gender);
                    dbClient.addParameter("machineLast", MachineId);
                    dbClient.addParameter("navilogs", navilogs);
                    dbClient.addParameter("targetedoffers", targetedoffers);
                    dbClient.runQuery();

                    dbClient.runFastQuery("DELETE FROM users_online WHERE user_id = '" + Id + "'");
                }

                if (this.AlfaServiceEnabled)
                {
                    if (this.AlfaGuideEnabled)
                    {
                        OtanixEnvironment.GetGame().GetAlfaManager().GetTourManager().RemoveAlfa(this.Id);
                        this.AlfaGuideEnabled = false;
                    }
                    if (this.AlfaHelperEnabled)
                    {
                        Help help = null;
                        if (OtanixEnvironment.GetGame().GetAlfaManager().GetHelpManager().Helps.ContainsKey(AlfaServiceId))
                        {
                            help = OtanixEnvironment.GetGame().GetAlfaManager().GetHelpManager().Helps[AlfaServiceId];
                        }

                        if (help != null)
                        {
                            if (help.helpState == HelpState.TALKING)
                            {
                                help.helpState = HelpState.FINISHED;
                            }
                            else if (help.helpState == HelpState.SEARCHING_USER)
                            {
                                help.NeedUpdate = true;
                            }
                        }

                        OtanixEnvironment.GetGame().GetAlfaManager().GetHelpManager().RemoveAlfa(this.Id);
                        this.AlfaHelperEnabled = false;
                    }
                    if (this.AlfaGuardianEnabled)
                    {
                        Bully bully = null;
                        if (OtanixEnvironment.GetGame().GetAlfaManager().GetBullyManager().Bullies.ContainsKey(AlfaServiceId))
                        {
                            bully = OtanixEnvironment.GetGame().GetAlfaManager().GetBullyManager().Bullies[AlfaServiceId];
                        }

                        if (bully != null)
                        {
                            if (bully.bullyState == BullyState.WAITING_RESPONSE)
                            {
                                bully.bullySolution = BullySolution.EXIT;
                                bully.bullyState    = BullyState.FINISHED;
                            }
                            else if (bully.bullyState == BullyState.SEARCHING_USER)
                            {
                                bully.NeedUpdate = true;
                            }
                        }

                        OtanixEnvironment.GetGame().GetAlfaManager().GetBullyManager().RemoveGuardian(this.Id);
                        this.AlfaGuardianEnabled = false;
                    }
                }

                if (InRoom && CurrentRoom != null && CurrentRoom.GetRoomUserManager() != null)
                {
                    CurrentRoom.GetRoomUserManager().RemoveUserFromRoom(mClient, false, false, false);
                }

                if (AvatarEffectsInventoryComponent != null)
                {
                    AvatarEffectsInventoryComponent.Dispose();
                    AvatarEffectsInventoryComponent = null;
                }

                if (InventoryComponent != null)
                {
                    InventoryComponent.SetIdleState();
                    InventoryComponent.RunDBUpdate();
                    InventoryComponent.Destroy();
                    InventoryComponent = null;
                }

                if (BadgeComponent != null)
                {
                    BadgeComponentLoaded = false;
                    BadgeComponent.Destroy();
                    BadgeComponent = null;
                }

                if (RelationshipComposer != null)
                {
                    RelationsLoaded = false;
                    RelationshipComposer.Destroy();
                    RelationshipComposer = null;
                }

                if (Achievements != null && Achievements.Count > 0)
                {
                    AchievementsLoaded = false;
                    Achievements.Clear();
                    Achievements = null;
                }

                if (quests != null && quests.Count > 0)
                {
                    QuestsLoaded = false;
                    quests.Clear();
                    quests = null;
                }

                if (wardrobes != null && wardrobes.Count > 0)
                {
                    WardrobeLoaded = false;
                    wardrobes.Clear();
                    wardrobes = null;
                }

                if (clubManager != null)
                {
                    clubManager.Clear();
                    clubManager = null;
                }

                if (sanctionManager != null)
                {
                    sanctionManager.Clear();
                    sanctionManager = null;
                }
            }
            catch (Exception e)
            {
                Logging.LogCriticalException("Disconnecting user " + e);
            }
            finally
            {
                OtanixEnvironment.GetGame().GetClientManager().UnregisterClient(Id, Username);
                Logging.WriteLine(Username + " has logged out.");
            }
        }