Beispiel #1
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="GameClient" /> class.
 /// </summary>
 /// <param name="clientId">The client identifier.</param>
 /// <param name="connection">The connection.</param>
 internal GameClient(uint clientId, ConnectionInformation connection)
 {
     ConnectionId = clientId;
     _connection = connection;
     CurrentRoomUserId = -1;
     PacketParser = new GamePacketParser();
 }
Beispiel #2
0
 /// <summary>
 /// Closes the connection.
 /// </summary>
 /// <param name="connection">The connection.</param>
 private static void CloseConnection(ConnectionInformation connection)
 {
     try
     {
         connection.Dispose();
         AzureEmulator.GetGame().GetClientManager().DisposeConnection(((uint)connection.GetConnectionId()));
     }
     catch (Exception ex)
     {
         Logging.LogException(ex.ToString());
     }
 }
Beispiel #3
0
 /// <summary>
 /// Disposes this instance.
 /// </summary>
 internal void Dispose()
 {
     _packet.Clear();
     _userConnection = null;
 }
Beispiel #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="QueuedServerMessage"/> class.
 /// </summary>
 /// <param name="connection">The connection.</param>
 public QueuedServerMessage(ConnectionInformation connection)
 {
     _userConnection = connection;
     _packet = new List<byte>();
 }
Beispiel #5
0
 /// <summary>
 /// Creates the and start client.
 /// </summary>
 /// <param name="clientId">The client identifier.</param>
 /// <param name="connection">The connection.</param>
 internal void CreateAndStartClient(uint clientId, ConnectionInformation connection)
 {
     var gameClient = new GameClient(clientId, connection);
     Clients.AddOrUpdate(clientId, gameClient, (key, value) => gameClient);
     gameClient.StartConnection();
 }
Beispiel #6
0
 /// <summary>
 /// Sets the connection.
 /// </summary>
 /// <param name="con">The con.</param>
 public void SetConnection(ConnectionInformation con)
 {
     _con = con;
 }
Beispiel #7
0
        /// <summary>
        ///     Stops this instance.
        /// </summary>
        internal void Stop()
        {
            if (GetMessageHandler() != null)
                GetMessageHandler().Destroy();

            if (GetHabbo() != null)
                GetHabbo().OnDisconnect("disconnect");

            CurrentRoomUserId = -1;
            _messageHandler = null;
            _habbo = null;
            _connection = null;
        }
Beispiel #8
0
 /// <summary>
 /// News the connection request.
 /// </summary>
 /// <param name="iAr">The i ar.</param>
 private void NewConnectionRequest(IAsyncResult iAr)
 {
     if (_connectionListener == null || !_acceptConnections) return;
     Socket socket = ((Socket)iAr.AsyncState).EndAccept(iAr);
     socket.NoDelay = _disableNagleAlgorithm;
     try
     {
         if (SocketConnectionCheck.CheckConnection(socket, MaxIpConnectionCount, AntiDDosStatus))
         {
             string ip = socket.RemoteEndPoint.ToString().Split(':')[0];
             _acceptedConnections++;
             var connectionInformation = new ConnectionInformation(socket, _acceptedConnections,
                 _parser.Clone() as IDataParser, ip);
             ReportUserLogin(ip);
             connectionInformation.ConnectionChanged += ConnectionChanged;
             if (Connection != null)
                 Connection(connectionInformation);
         }
         else
         {
             try
             {
                 socket.Dispose();
                 socket.Close();
             }
             catch { }
         }
     }
     catch { }
     finally
     {
         _connectionListener.BeginAccept(NewConnectionRequest, _connectionListener);
     }
 }
Beispiel #9
0
 /// <summary>
 /// cs the connection changed.
 /// </summary>
 /// <param name="information">The information.</param>
 /// <param name="state">The state.</param>
 private void ConnectionChanged(ConnectionInformation information, ConnectionState state)
 {
     if (state == ConnectionState.Closed)
     {
         ReportDisconnect(information);
     }
 }
Beispiel #10
0
 /// <summary>
 /// Reports the disconnect.
 /// </summary>
 /// <param name="gameConnection">The game connection.</param>
 public void ReportDisconnect(ConnectionInformation gameConnection)
 {
     gameConnection.ConnectionChanged -= ConnectionChanged;
     ReportUserLogout(gameConnection.GetIp());
 }
Beispiel #11
0
        private void OnAcceptSocket(IAsyncResult ar)
        {
            try
            {
                Socket socket = _listener.EndAcceptSocket(ar);
                if (socket.Connected)
                {
                    if (SocketConnectionCheck.CheckConnection(socket, MaxIpConnectionCount, AntiDDosStatus))
                    {
                        socket.NoDelay = _disableNagleAlgorithm;
                        AcceptedConnections++;
                        var connectionInfo = new ConnectionInformation(socket, _parser.Clone() as IDataParser, AcceptedConnections);
                        connectionInfo.Disconnected = OnChannelDisconnect;
                        OnClientConnected(connectionInfo);
                    }
                }
            }
            catch (Exception) { }

            _listener.BeginAcceptSocket(OnAcceptSocket, _listener);
        }
Beispiel #12
0
 private void OnChannelDisconnect(ConnectionInformation connection, Exception exception)
 {
     connection.Disconnected = null;
     OnClientDisconnected(connection, exception);
     connection.Cleanup();
 }
Beispiel #13
0
 /// <summary>
 /// Managers the connection event.
 /// </summary>
 /// <param name="connection">The connection.</param>
 private static void ManagerConnectionEvent(ConnectionInformation connection)
 {
     connection.ConnectionChanged += ConnectionChanged;
     AzureEmulator.GetGame().GetClientManager().CreateAndStartClient(((uint)connection.GetConnectionId()), connection);
 }
Beispiel #14
0
 /// <summary>
 /// Connections the changed.
 /// </summary>
 /// <param name="information">The information.</param>
 /// <param name="state">The state.</param>
 private static void ConnectionChanged(ConnectionInformation information, ConnectionState state)
 {
     if (state == ConnectionState.Closed)
         CloseConnection(information);
 }
 /// <summary>
 /// Sets the connection.
 /// </summary>
 /// <param name="con">The con.</param>
 /// <param name="me">Me.</param>
 public void SetConnection(ConnectionInformation con, GameClient me)
 {
     _currentClient = me;
 }