private void Server_PeerConnected(object sender, PeerEventArgs e) { LogInfo("connected: " + e.peer.IPAddress, true); foreach (var cmd in Commands) { cmd.OnPeerConnected(this, e.peer); } }
private void Server_PeerAccepted(object sender, PeerEventArgs e) { foreach (var cmd in Commands) { cmd.OnPeerAccepted(this, e.peer); } listBox_player.Items.Add(e.peer); LogInfo("joined: " + e.peer, true); }
private void Peer_Disconnected(object sender, PeerEventArgs e) { if (peers.Remove(e.peer)) { PeerDisconnected(this, e); } pendingPeers.Remove(e.peer); GC.Collect(); }
private void Server_PeerDataReceived(object sender, PeerEventArgs e) { if (e.isTcp) { var dataType = BitConverter.ToInt32(e.data, 0); var cmd = Commands.Find(c => c.ExecDataTypes.Contains(dataType)); if (cmd != null) { try { LogInfo(cmd.GetType().Name, true); var res = cmd.OnDataReceived(this, true, e.peer, dataType, e.data.Skip(4).ToArray()); } catch (Exception ex) { LogError(ex.ToString(), true); } } } else { using (var ms = new MemoryStream(e.data)) { using (var br = new BinaryReader(ms)) { try { while (ms.Position < ms.Length) { var dataType = br.ReadInt32(); var l = br.ReadInt32(); if (l == 0) { break; } var data = br.ReadBytes(l); var cmd = Commands.Find(c => c.ExecDataTypes.Contains(dataType)); if (cmd != null) { try { cmd.OnDataReceived(this, false, e.peer, dataType, data); } catch (Exception ex) { LogError(ex.ToString(), true); } } } } catch { } } } } }
private void Server_PeerDisconnected(object sender, PeerEventArgs e) { listBox_player.Items.Remove(e.peer); LogInfo("left: " + e.peer, true); }
private void Peer_DataReceived(object sender, PeerEventArgs e) { PeerDataReceived(this, e); }
internal void EventPeerDisconnected(object sender, PeerEventArgs e) { PeerDisconnected(sender, e); }
internal void EventPeerDataReceived(object sender, PeerEventArgs e) { PeerDataReceived(sender, e); }
internal void EventPeerAccepted(object sender, PeerEventArgs e) { PeerAccepted(sender, e); }