public void Disconnect() { this.DisconnectSocket(); this.m_connectionState = ClientConnection <PacketType> .ConnectionState.Disconnected; }
public void Update() { object mMutex = this.m_mutex; Monitor.Enter(mMutex); try { foreach (ClientConnection <PacketType> .ConnectionEvent mConnectionEvent in this.m_connectionEvents) { this.PrintConnectionException(mConnectionEvent); ClientConnection <PacketType> .ConnectionEventTypes type = mConnectionEvent.Type; if (type == ClientConnection <PacketType> .ConnectionEventTypes.OnConnected) { if (mConnectionEvent.Error == BattleNetErrors.ERROR_OK) { this.m_connectionState = ClientConnection <PacketType> .ConnectionState.Connected; } else { this.DisconnectSocket(); this.m_connectionState = ClientConnection <PacketType> .ConnectionState.ConnectionFailed; } ConnectHandler[] array = this.m_connectHandlers.ToArray(); for (int i = 0; i < (int)array.Length; i++) { array[i](mConnectionEvent.Error); } } else if (type == ClientConnection <PacketType> .ConnectionEventTypes.OnDisconnected) { if (mConnectionEvent.Error != BattleNetErrors.ERROR_OK) { this.Disconnect(); } DisconnectHandler[] disconnectHandlerArray = this.m_disconnectHandlers.ToArray(); for (int j = 0; j < (int)disconnectHandlerArray.Length; j++) { disconnectHandlerArray[j](mConnectionEvent.Error); } } else if (type == ClientConnection <PacketType> .ConnectionEventTypes.OnPacketCompleted) { for (int k = 0; k < this.m_listeners.Count; k++) { IClientConnectionListener <PacketType> item = this.m_listeners[k]; object obj = this.m_listenerStates[k]; item.PacketReceived(mConnectionEvent.Packet, obj); } } } this.m_connectionEvents.Clear(); } finally { Monitor.Exit(mMutex); } if (this.m_socket == null || this.m_connectionState != ClientConnection <PacketType> .ConnectionState.Connected) { return; } this.SendQueuedPackets(); }
public void Update() { object mutex = this.m_mutex; lock (mutex) { foreach (ClientConnection <PacketType> .ConnectionEvent connectionEvent in this.m_connectionEvents) { this.PrintConnectionException(connectionEvent); ClientConnection <PacketType> .ConnectionEventTypes type = connectionEvent.Type; if (type != ClientConnection <PacketType> .ConnectionEventTypes.OnConnected) { if (type != ClientConnection <PacketType> .ConnectionEventTypes.OnDisconnected) { if (type == ClientConnection <PacketType> .ConnectionEventTypes.OnPacketCompleted) { for (int i = 0; i < this.m_listeners.Count; i++) { IClientConnectionListener <PacketType> clientConnectionListener = this.m_listeners[i]; object state = this.m_listenerStates[i]; clientConnectionListener.PacketReceived(connectionEvent.Packet, state); } } } else { if (connectionEvent.Error != BattleNetErrors.ERROR_OK) { this.Disconnect(); } foreach (DisconnectHandler disconnectHandler in this.m_disconnectHandlers.ToArray()) { disconnectHandler(connectionEvent.Error); } } } else { if (connectionEvent.Error != BattleNetErrors.ERROR_OK) { this.DisconnectSocket(); this.m_connectionState = ClientConnection <PacketType> .ConnectionState.ConnectionFailed; } else { this.m_connectionState = ClientConnection <PacketType> .ConnectionState.Connected; } foreach (ConnectHandler connectHandler in this.m_connectHandlers.ToArray()) { connectHandler(connectionEvent.Error); } } } this.m_connectionEvents.Clear(); } if (this.m_socket == null || this.m_connectionState != ClientConnection <PacketType> .ConnectionState.Connected) { return; } this.SendQueuedPackets(); }