예제 #1
0
        private void Server_PeerConnected(object sender, PeerEventArgs e)
        {
            LogInfo("connected: " + e.peer.IPAddress, true);

            foreach (var cmd in Commands)
            {
                cmd.OnPeerConnected(this, e.peer);
            }
        }
예제 #2
0
 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);
 }
예제 #3
0
 private void Peer_Disconnected(object sender, PeerEventArgs e)
 {
     if (peers.Remove(e.peer))
     {
         PeerDisconnected(this, e);
     }
     pendingPeers.Remove(e.peer);
     GC.Collect();
 }
예제 #4
0
        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 { }
                    }
                }
            }
        }
예제 #5
0
 private void Server_PeerDisconnected(object sender, PeerEventArgs e)
 {
     listBox_player.Items.Remove(e.peer);
     LogInfo("left: " + e.peer, true);
 }
예제 #6
0
 private void Peer_DataReceived(object sender, PeerEventArgs e)
 {
     PeerDataReceived(this, e);
 }
예제 #7
0
 internal void EventPeerDisconnected(object sender, PeerEventArgs e)
 {
     PeerDisconnected(sender, e);
 }
예제 #8
0
 internal void EventPeerDataReceived(object sender, PeerEventArgs e)
 {
     PeerDataReceived(sender, e);
 }
예제 #9
0
 internal void EventPeerAccepted(object sender, PeerEventArgs e)
 {
     PeerAccepted(sender, e);
 }