Exemplo n.º 1
0
        public void Disconnect()
        {
            try
            {
                if (GetHabbo() != null)
                {
                    using (IQueryAdapter DbClient = ProjectHub.GetDatabaseManager().GetQueryReactor())
                    {
                        DbClient.RunQuery(GetHabbo().GetQueryString);
                    }

                    GetHabbo().OnDisconnect();
                }
            }
            catch (Exception Error)
            {
                Logging.LogError(Error.ToString());
            }


            if (!Disconnected)
            {
                if (Connection != null)
                {
                    Connection.Dispose();
                }

                Disconnected = true;
            }
        }
Exemplo n.º 2
0
        public void handlePacketData(byte[] data)
        {
            int pos = 0;

            while (pos < data.Length)
            {
                try
                {
                    int MessageLength = Base64Encoding.DecodeInt32(new byte[] { data[pos++], data[pos++], data[pos++] });
                    int MessageId     = Base64Encoding.DecodeInt32(new byte[] { data[pos++], data[pos++] });

                    byte[] Content = new byte[MessageLength - 2];

                    for (int i = 0; i < Content.Length && pos < data.Length; i++)
                    {
                        Content[i] = data[pos++];
                    }
                    if (onNewPacket != null)
                    {
                        using (ClientMessage message = ClientMessageFactory.GetClientMessage(MessageId, Content))
                        {
                            onNewPacket.Invoke(message);
                        }
                    }
                }
                catch (Exception e)
                {
                    Logging.HandleException(e, "packet handling");
                    con.Dispose();
                }
            }
        }
Exemplo n.º 3
0
        public void Disconnect()
        {
            try
            {
                if (GetHabbo() != null)
                {
                    using (IQueryAdapter dbClient = QuasarEnvironment.GetDatabaseManager().GetQueryReactor())
                    {
                        dbClient.RunQuery(GetHabbo().GetQueryString);
                    }

                    GetHabbo().OnDisconnect();
                }
            }
            catch (Exception e)
            {
                Logging.LogException(e.ToString());
            }


            if (!_disconnected)
            {
                if (_connection != null)
                {
                    _connection.Dispose();
                }
                _disconnected = true;

                Console.WriteLine("Client has disconnected.");
            }
        }
        public void ConnectionInformation_WithLoginInformation()
        {
            // Arrange
            var userName         = "******";
            var passwordUnsecure = "admin";
            var password         = passwordUnsecure.ToSecureString();
            var serverUri        = new Uri("http://localhost/");
            var testSubject      = new ConnectionInformation(serverUri, userName, password);

            // Act
            password.Dispose(); // Connection information should maintain it's own copy of the password

            // Assert
            testSubject.Password.ToUnsecureString().Should().Be(passwordUnsecure, "Password doesn't match");
            testSubject.UserName.Should().Be(userName, "UserName doesn't match");
            testSubject.ServerUri.Should().Be(serverUri, "ServerUri doesn't match");

            // Act clone
            var testSubject2 = (ConnectionInformation)((ICloneable)testSubject).Clone();

            // Now dispose the test subject
            testSubject.Dispose();

            // Assert testSubject
            Exceptions.Expect <ObjectDisposedException>(() => testSubject.Password.ToUnsecureString());

            // Assert testSubject2
            testSubject2.Password.ToUnsecureString().Should().Be(passwordUnsecure, "Password doesn't match");
            testSubject2.UserName.Should().Be(userName, "UserName doesn't match");
            testSubject2.ServerUri.Should().Be(serverUri, "ServerUri doesn't match");
        }
Exemplo n.º 5
0
        public void Disconnect()
        {
            try
            {
                if (GetHabbo() != null)
                {
                    using (IQueryAdapter dbClient = RocketEmulador.GetDatabaseManager().GetQueryReactor())
                    {
                        dbClient.RunQuery(GetHabbo().GetQueryString);
                    }

                    GetHabbo().OnDisconnect();
                }
            }
            catch (Exception e)
            {
                Logging.LogException(e.ToString());
            }


            if (!_disconnected)
            {
                if (_connection != null)
                {
                    _connection.Dispose();
                }
                _disconnected = true;
            }
        }
Exemplo n.º 6
0
 public void Disconnect()
 {
     try
     {
         if (GetHabbo() != null)
         {
             using (var dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
             {
                 dbClient.RunQuery(GetHabbo().GetQueryString);
             }
             GetHabbo().OnDisconnect();
         }
     }
     catch (Exception e)
     {
         ExceptionLogger.LogException(e);
     }
     if (!_disconnected)
     {
         if (_connection != null)
         {
             _connection.Dispose();
         }
         _disconnected = true;
     }
 }
Exemplo n.º 7
0
        /// <summary>
        /// Handles the packet data.
        /// </summary>
        /// <param name="data">The data.</param>
        public void HandlePacketData(byte[] data)
        {
            var i = 0;

            if (data.Length == 0)
            {
                return;
            }
            while (i < data.Length)
            {
                if (data.Length - i < 6)
                {
                    return;
                }
                short messageId = 0;
                try
                {
                    var length = HabboEncoding.DecodeInt32(new[]
                    {
                        data[i++],
                        data[i++],
                        data[i++],
                        data[i++]
                    });
                    if (length < 2 || length > 4096)
                    {
                        return;
                    }
                    messageId = HabboEncoding.DecodeInt16(new[]
                    {
                        data[i++],
                        data[i++]
                    });
                    var packetContent = new byte[length - 2];
                    var num2          = 0;
                    while (num2 < packetContent.Length && i < data.Length)
                    {
                        packetContent[num2] = data[i++];
                        num2++;
                    }
                    if (OnNewPacket == null)
                    {
                        continue;
                    }
                    using (var clientMessage = Factorys.GetClientMessage(messageId, packetContent)) OnNewPacket(clientMessage);
                }
                catch (Exception exception)
                {
                    Logging.HandleException(exception, string.Format("packet handling ----> {0}", messageId));
                    _con.Dispose();
                }
            }
        }
Exemplo n.º 8
0
 private void CloseConnection(ConnectionInformation Connection)
 {
     try
     {
         Connection.Dispose();
         PlusEnvironment.GetGame().GetClientManager().DisposeConnection(Convert.ToInt32(Connection.getConnectionID()));
     }
     catch (Exception e)
     {
         Logging.LogException(e.ToString());
     }
 }
Exemplo n.º 9
0
 private void CloseConnection(ConnectionInformation Connection)
 {
     try
     {
         Connection.Dispose();
         Plus.GetGame().GetClientManager().DisposeConnection((uint)Connection.getConnectionID());
     }
     catch (Exception e)
     {
         Logging.LogException(e.ToString());
     }
 }
Exemplo n.º 10
0
 private void CloseConnection(ConnectionInformation Connection)
 {
     try
     {
         Connection.Dispose();
         CyberEnvironment.GetGame().GetClientManager().DisposeConnection(checked ((uint)Connection.getConnectionID()));
     }
     catch (Exception ex)
     {
         Logging.LogException(ex.ToString());
     }
 }
Exemplo n.º 11
0
 private void CloseConnection(ConnectionInformation Connection)
 {
     try
     {
         ButterflyEnvironment.GetGame().GetClientWebManager().DisposeConnection(Connection.getConnectionID());
         Connection.Dispose();
     }
     catch (Exception ex)
     {
         Logging.LogException((ex).ToString());
     }
 }
        public void Dispose_PasswordIsDisposed()
        {
            var pwd         = "secret".ToSecureString();
            var testSubject = new ConnectionInformation(new Uri("http://any"), "any", pwd);

            testSubject.Dispose();

            testSubject.IsDisposed.Should().BeTrue();

            Action accessPassword = () => _ = testSubject.Password.Length;

            accessPassword.Should().ThrowExactly <ObjectDisposedException>();
        }
Exemplo n.º 13
0
        public void CreateAndStartClient(int clientID, ConnectionInformation connection)
        {
            GameClient Client = new GameClient(clientID, connection);

            if (_clients.TryAdd(Client.ConnectionID, Client))
            {
                Client.StartConnection();
            }
            else
            {
                connection.Dispose();
            }
        }
Exemplo n.º 14
0
        public void CreateAndStartClient(int clientId, ConnectionInformation connection)
        {
            var client = new Player(clientId, connection);

            if (_clients.TryAdd(client.ConnectionId, client))
            {
                client.StartConnection();
            }
            else
            {
                connection.Dispose();
            }
        }
Exemplo n.º 15
0
 internal void Disconnect()
 {
     if (GetHabbo() != null && GetHabbo().GetInventoryComponent() != null)
     {
         GetHabbo().GetInventoryComponent().RunDBUpdate();
     }
     if (!Disconnected)
     {
         if (Connection != null)
         {
             Connection.Dispose();
         }
         Disconnected = true;
     }
 }
        public void Disconnect()
        {
            try
            {
                if (GetHabbo() != null)
                {
                    ICollection <MessengerBuddy> Friends = new List <MessengerBuddy>();
                    foreach (MessengerBuddy Buddy in GetHabbo().GetMessenger().GetFriends().ToList())
                    {
                        if (Buddy == null)
                        {
                            continue;
                        }

                        GameClient Friend = BiosEmuThiago.GetGame().GetClientManager().GetClientByUserID(Buddy.Id);
                        if (Friend == null)
                        {
                            continue;
                        }
                        string figure = this.GetHabbo().Look;

                        Friend.SendMessage(new RoomNotificationComposer("fig/" + figure, 3, this.GetHabbo().Username + ", seu amigo saiu do hotel!", ""));
                    }
                    using (IQueryAdapter dbClient = BiosEmuThiago.GetDatabaseManager().GetQueryReactor())
                    {
                        dbClient.runFastQuery(GetHabbo().GetQueryString);
                    }

                    GetHabbo().OnDisconnect();
                    BiosEmuThiago.GetGame().GetClientManager().DispatchEventDisconnect(this);
                }
            }
            catch (Exception e)
            {
                ExceptionLogger.LogException(e);
            }


            if (!_disconnected)
            {
                if (_connection != null)
                {
                    _connection.Dispose();
                }
                _disconnected = true;
            }
        }
Exemplo n.º 17
0
        public void Disconnect()
        {
            try
            {
                if (GetHabbo() != null)
                {
                    ICollection <MessengerBuddy> Friends = new List <MessengerBuddy>();
                    foreach (MessengerBuddy Buddy in GetHabbo().GetMessenger().GetFriends().ToList())
                    {
                        if (Buddy == null)
                        {
                            continue;
                        }

                        GameClient Friend = CloudServer.GetGame().GetClientManager().GetClientByUserID(Buddy.Id);
                        if (Friend == null)
                        {
                            continue;
                        }
                        string figure = GetHabbo().Look;
                    }
                    using (IQueryAdapter dbClient = CloudServer.GetDatabaseManager().GetQueryReactor())
                    {
                        dbClient.runFastQuery(GetHabbo().GetQueryString);
                    }

                    GetHabbo().OnDisconnect();
                    CloudServer.GetGame().GetClientManager().DispatchEventDisconnect(this);
                }
            }
            catch (Exception e)
            {
                ExceptionLogger.LogException(e);
            }


            if (!_disconnected)
            {
                if (_connection != null)
                {
                    _connection.Dispose();
                }
                _disconnected = true;
            }
        }
Exemplo n.º 18
0
 /// <summary>
 /// Disconnects the specified reason.
 /// </summary>
 /// <param name="reason">The reason.</param>
 internal void Disconnect(string reason)
 {
     if (GetHabbo() != null)
     {
         using (var queryReactor = Plus.GetDatabaseManager().GetQueryReactor())
             queryReactor.RunFastQuery(GetHabbo().GetQueryString);
         GetHabbo().OnDisconnect(reason);
     }
     if (_disconnected)
     {
         return;
     }
     if (_connection != null)
     {
         _connection.Dispose();
     }
     _disconnected = true;
 }
Exemplo n.º 19
0
 internal void CloseConnection(int p)
 {
     try
     {
         Object info = liveConnections[p];
         if (info != null)
         {
             ConnectionInformation con = (ConnectionInformation)info;
             con.Dispose();
             FirewindEnvironment.GetGame().GetClientManager().DisposeConnection((uint)p);
         }
     }
     catch (Exception e)
     {
         Logging.LogException(e.ToString());
         //Logging.WriteLine(e.ToString());
     }
 }
Exemplo n.º 20
0
        public void handlePacketData(byte[] data)
        {
            int pos = 0;

            while (pos < data.Length)
            {
                try
                {
                    int MessageLength = HabboEncoding.DecodeInt32(new byte[] { data[pos++], data[pos++], data[pos++], data[pos++] });
                    if (MessageLength < 2 || MessageLength > 1024)
                    {
                        //Logging.WriteLine("bad size packet!");
                        continue;
                    }
                    int MessageId = HabboEncoding.DecodeInt16(new byte[] { data[pos++], data[pos++] });



                    byte[] Content = new byte[MessageLength - 2];

                    for (int i = 0; i < Content.Length && pos < data.Length; i++)
                    {
                        Content[i] = data[pos++];
                    }

                    //Logging.WriteLine("[REQUEST] [" + MessageId + " / len: " + MessageLength + "] => " + Encoding.Default.GetString(Content).Replace(Convert.ToChar(0).ToString(), "{char0}"));

                    if (onNewPacket != null)
                    {
                        using (ClientMessage message = ClientMessageFactory.GetClientMessage(MessageId, Content))
                        {
                            onNewPacket.Invoke(message);
                        }
                    }
                }
                catch (Exception e)
                {
                    int MessageLength = HabboEncoding.DecodeInt32(new byte[] { data[pos++], data[pos++], data[pos++], data[pos++] });
                    int MessageId     = HabboEncoding.DecodeInt16(new byte[] { data[pos++], data[pos++] });
                    Logging.HandleException(e, "packet handling ----> " + MessageId);
                    con.Dispose();
                }
            }
        }
Exemplo n.º 21
0
        internal void Disconnect()
        {
            if (GetHabbo() != null && GetHabbo().GetInventoryComponent() != null)
            {
                using (IQueryAdapter db = FirewindEnvironment.GetDatabaseManager().getQueryreactor())
                {
                    db.setQuery("UPDATE users SET online = '0' WHERE id = @id");
                    db.addParameter("id", this.GetHabbo().Id);
                    db.runQuery();
                }

                GetHabbo().GetInventoryComponent().RunDBUpdate();
            }
            if (!Disconnected)
            {
                if (Connection != null)
                {
                    Connection.Dispose();
                }
                Disconnected = true;
            }
        }
Exemplo n.º 22
0
        public void Disconnect(bool ForcedDisconnect)
        {
            if (LoggingOut)
            {
                return;
            }

            LoggingOut = true;

            try
            {
                #region WebSocket
                PlusEnvironment.GetGame().GetWebEventManager().CloseSocketByGameClient(((this.GetHabbo() == null) ? 0 : this.GetHabbo().Id));
                if (GetRoleplay() != null)
                {
                    foreach (WebSocketChatRoom ChatRoom in GetRoleplay().ChatRooms.Values)
                    {
                        if (ChatRoom == null)
                        {
                            continue;
                        }
                        WebSocketChatManager.Disconnect(this, ChatRoom.ChatName, false, null);
                    }
                }
                #endregion

                if (GetRoomUser() != null && !ForcedDisconnect)
                {
                    RoleplayManager.Chat(this, GetHabbo().Username + " irá sair em 10 segundos.", 1);
                    GetRoomUser().ApplyEffect(95);

                    if (GetHabbo() != null && GetHabbo().CurrentRoom != null)
                    {
                        GetHabbo().CurrentRoom.SendMessage(new SleepComposer(GetRoomUser(), true));
                    }

                    GetRoomUser().CanWalk = false;
                    GetRoomUser().ClearMovement(true);
                }

                if (GetRoleplay() != null)
                {
                    if (GetRoleplay().UserDataHandler != null)
                    {
                        GetRoleplay().UserDataHandler.SaveFarmingData();
                        GetRoleplay().UserDataHandler.SaveCooldownData();
                        GetRoleplay().UserDataHandler.SaveData();
                        GetRoleplay().UserDataHandler = null;
                    }
                }

                if (GetHabbo() != null)
                {
                    using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
                        dbClient.RunQuery(GetHabbo().GetQueryString);
                }

                if (!ForcedDisconnect)
                {
                    new Thread(() =>
                    {
                        Thread.Sleep(8000);

                        if (GetRoleplay() != null)
                        {
                            GetRoleplay().UserDataHandler = new UserDataHandler(this, GetRoleplay());
                            GetRoleplay().UserDataHandler.SaveFarmingData();
                            GetRoleplay().UserDataHandler.SaveCooldownData();
                            GetRoleplay().UserDataHandler.SaveData();
                            GetRoleplay().UserDataHandler = null;
                        }

                        if (GetHabbo() != null)
                        {
                            using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
                                dbClient.RunQuery(GetHabbo().GetQueryString);
                        }

                        EventManager.TriggerEvent("OnDisconnect", this);

                        Thread.Sleep(1000);

                        if (GetRoomUser() != null)
                        {
                            GetRoomUser().ApplyEffect(108);
                        }

                        Thread.Sleep(1000);

                        if (GetHabbo() != null)
                        {
                            using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
                            {
                                dbClient.RunQuery(GetHabbo().GetQueryString);
                            }

                            GetHabbo().OnDisconnect();
                        }

                        if (!_disconnected)
                        {
                            if (_connection != null)
                            {
                                _connection.Dispose();
                            }
                            _disconnected = true;
                        }
                    }).Start();
                }
                else
                {
                    EventManager.TriggerEvent("OnDisconnect", this);

                    if (GetHabbo() != null)
                    {
                        using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
                        {
                            dbClient.RunQuery(GetHabbo().GetQueryString);
                        }

                        GetHabbo().OnDisconnect();
                    }

                    if (!_disconnected)
                    {
                        if (_connection != null)
                        {
                            _connection.Dispose();
                        }
                        _disconnected = true;
                    }
                }
            }
            catch (Exception e)
            {
                Logging.LogException(e.ToString());
            }
        }