/// <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(); }
/// <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()); } }
/// <summary> /// Disposes this instance. /// </summary> internal void Dispose() { _packet.Clear(); _userConnection = null; }
/// <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>(); }
/// <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(); }
/// <summary> /// Sets the connection. /// </summary> /// <param name="con">The con.</param> public void SetConnection(ConnectionInformation con) { _con = con; }
/// <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; }
/// <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); } }
/// <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); } }
/// <summary> /// Reports the disconnect. /// </summary> /// <param name="gameConnection">The game connection.</param> public void ReportDisconnect(ConnectionInformation gameConnection) { gameConnection.ConnectionChanged -= ConnectionChanged; ReportUserLogout(gameConnection.GetIp()); }
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); }
private void OnChannelDisconnect(ConnectionInformation connection, Exception exception) { connection.Disconnected = null; OnClientDisconnected(connection, exception); connection.Cleanup(); }
/// <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); }
/// <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; }