private void BytesReceived(byte[] bytes, int nBytes, int offset) { while (nBytes > 0) { if (this.m_currentPacket == null) { this.m_currentPacket = new BattleNetPacket(); } int num = this.m_currentPacket.Decode(bytes, offset, nBytes); nBytes -= num; offset += num; if (!this.m_currentPacket.IsLoaded()) { Array.Copy(bytes, offset, this.m_backingBuffer, 0, nBytes); this.m_backingBufferBytes = nBytes; return; } SslClientConnection.ConnectionEvent connectionEvent = new SslClientConnection.ConnectionEvent() { Type = SslClientConnection.ConnectionEventTypes.OnPacketCompleted }; lock (this.m_currentPacket) { this.m_connectionEvents.Add(connectionEvent); } this.m_currentPacket = null; } this.m_backingBufferBytes = 0; }
private void TriggerOnDisconnectHandler(BattleNetErrors error) { SslClientConnection.ConnectionEvent connectionEvent = new SslClientConnection.ConnectionEvent() { Type = SslClientConnection.ConnectionEventTypes.OnDisconnected }; lock (error) { this.m_connectionEvents.Add(connectionEvent); } }
private void TriggerOnDisconnectHandler(BattleNetErrors error) { SslClientConnection.ConnectionEvent connectionEvent = new SslClientConnection.ConnectionEvent(); connectionEvent.Type = SslClientConnection.ConnectionEventTypes.OnDisconnected; connectionEvent.Error = error; object connectionEvents = this.m_connectionEvents; lock (connectionEvents) { this.m_connectionEvents.Add(connectionEvent); } }
public void Update() { SslSocket.Process(); List <SslClientConnection.ConnectionEvent> connectionEvents = this.m_connectionEvents; lock (connectionEvents) { using (List <SslClientConnection.ConnectionEvent> .Enumerator enumerator = this.m_connectionEvents.GetEnumerator()) { while (enumerator.MoveNext()) { SslClientConnection.ConnectionEvent current = enumerator.get_Current(); switch (current.Type) { case SslClientConnection.ConnectionEventTypes.OnConnected: { if (current.Error != BattleNetErrors.ERROR_OK) { this.Disconnect(); this.m_connectionState = SslClientConnection.ConnectionState.ConnectionFailed; } else { this.m_connectionState = SslClientConnection.ConnectionState.Connected; } ConnectHandler[] array = this.m_connectHandlers.ToArray(); for (int i = 0; i < array.Length; i++) { ConnectHandler connectHandler = array[i]; connectHandler(current.Error); } break; } case SslClientConnection.ConnectionEventTypes.OnDisconnected: { if (current.Error != BattleNetErrors.ERROR_OK) { this.Disconnect(); } DisconnectHandler[] array2 = this.m_disconnectHandlers.ToArray(); for (int j = 0; j < array2.Length; j++) { DisconnectHandler disconnectHandler = array2[j]; disconnectHandler(current.Error); } break; } case SslClientConnection.ConnectionEventTypes.OnPacketCompleted: for (int k = 0; k < this.m_listeners.get_Count(); k++) { IClientConnectionListener <BattleNetPacket> clientConnectionListener = this.m_listeners.get_Item(k); object state = this.m_listenerStates.get_Item(k); clientConnectionListener.PacketReceived(current.Packet, state); } break; } } } this.m_connectionEvents.Clear(); } if (this.m_sslSocket == null || this.m_connectionState != SslClientConnection.ConnectionState.Connected) { return; } while (this.m_outQueue.get_Count() > 0) { if (this.OnlyOneSend && !this.m_sslSocket.m_canSend) { return; } BattleNetPacket packet = this.m_outQueue.Dequeue(); this.SendPacket(packet); } }