public bool PumpEvents() { _incomingMessages.Clear(); _peer.ReadMessages(_incomingMessages); foreach (NetIncomingMessage incomingMessage in _incomingMessages) { switch (incomingMessage.MessageType) { case NetIncomingMessageType.VerboseDebugMessage: case NetIncomingMessageType.DebugMessage: Log.Debug(incomingMessage.ReadString()); break; case NetIncomingMessageType.WarningMessage: Log.Warn(incomingMessage.ReadString()); break; case NetIncomingMessageType.ErrorMessage: Log.Error(incomingMessage.ReadString()); break; case NetIncomingMessageType.StatusChanged: var status = (NetConnectionStatus)incomingMessage.ReadByte(); switch (status) { case NetConnectionStatus.InitiatedConnect: break; case NetConnectionStatus.ReceivedInitiation: break; case NetConnectionStatus.RespondedAwaitingApproval: break; case NetConnectionStatus.RespondedConnect: break; case NetConnectionStatus.Connected: var channel = new LidgrenNetChannel(incomingMessage.SenderConnection, _bufferManager); INetChannelListener listener = _peerFactory.OnNetConnect(channel); channel.Listener = listener; _channels.Add(incomingMessage.SenderConnection.RemoteUniqueIdentifier, channel); break; case NetConnectionStatus.Disconnecting: Log.Debug("Channel #{0} is disconnecting", incomingMessage.SenderConnection.RemoteUniqueIdentifier); break; case NetConnectionStatus.Disconnected: Log.Debug("Channel #{0} has been disconnected", incomingMessage.SenderConnection.RemoteUniqueIdentifier); LidgrenNetChannel netChannel; if (_channels.TryGetValue(incomingMessage.SenderConnection.RemoteUniqueIdentifier, out netChannel)) { netChannel.Listener.OnDisconnected(); _channels.Remove(incomingMessage.SenderConnection.RemoteUniqueIdentifier); netChannel.Dispose(); } break; default: throw new ArgumentOutOfRangeException(); } break; case NetIncomingMessageType.Data: int numBytes = incomingMessage.ReadInt32(); incomingMessage.ReadBytes(_buffer, 0, numBytes); _stream.Position = 0; _channels[incomingMessage.SenderConnection.RemoteUniqueIdentifier].Listener.OnNetData(_reader); break; default: Log.Debug("Received "+ incomingMessage.MessageType); break; } _peer.Recycle(incomingMessage); } return false; }
public bool PumpEvents() { _incomingMessages.Clear(); _peer.ReadMessages(_incomingMessages); foreach (NetIncomingMessage incomingMessage in _incomingMessages) { switch (incomingMessage.MessageType) { case NetIncomingMessageType.VerboseDebugMessage: case NetIncomingMessageType.DebugMessage: Log.Debug(incomingMessage.ReadString()); break; case NetIncomingMessageType.WarningMessage: Log.Warn(incomingMessage.ReadString()); break; case NetIncomingMessageType.ErrorMessage: Log.Error(incomingMessage.ReadString()); break; case NetIncomingMessageType.StatusChanged: var status = (NetConnectionStatus)incomingMessage.ReadByte(); switch (status) { case NetConnectionStatus.InitiatedConnect: break; case NetConnectionStatus.ReceivedInitiation: break; case NetConnectionStatus.RespondedAwaitingApproval: break; case NetConnectionStatus.RespondedConnect: break; case NetConnectionStatus.Connected: var channel = new LidgrenNetChannel(incomingMessage.SenderConnection, _bufferManager); INetChannelListener listener = _peerFactory.OnNetConnect(channel); channel.Listener = listener; _channels.Add(incomingMessage.SenderConnection.RemoteUniqueIdentifier, channel); break; case NetConnectionStatus.Disconnecting: Log.Debug("Channel #{0} is disconnecting", incomingMessage.SenderConnection.RemoteUniqueIdentifier); break; case NetConnectionStatus.Disconnected: Log.Debug("Channel #{0} has been disconnected", incomingMessage.SenderConnection.RemoteUniqueIdentifier); LidgrenNetChannel netChannel; if (_channels.TryGetValue(incomingMessage.SenderConnection.RemoteUniqueIdentifier, out netChannel)) { netChannel.Listener.OnDisconnected(); _channels.Remove(incomingMessage.SenderConnection.RemoteUniqueIdentifier); netChannel.Dispose(); } break; default: throw new ArgumentOutOfRangeException(); } break; case NetIncomingMessageType.Data: int numBytes = incomingMessage.ReadInt32(); incomingMessage.ReadBytes(_buffer, 0, numBytes); _stream.Position = 0; _channels[incomingMessage.SenderConnection.RemoteUniqueIdentifier].Listener.OnNetData(_reader); break; default: Log.Debug("Received " + incomingMessage.MessageType); break; } _peer.Recycle(incomingMessage); } return(false); }