コード例 #1
0
        public override void ReceiveJoiningPeerData(IClientContextForState context, CRLFSocket socket, Packet packet)
        {
            IList <PeerData> peerList = new List <PeerData>();

            if (packet.Data != null)
            {
                foreach (string peer in packet.Data)
                {
                    string[] peerData = peer.Split(new char[] { ',' });
                    peerList.Add(new PeerData(peerData[0], int.Parse(peerData[1]), int.Parse(peerData[2])));
                }
            }

            int[] connectedPeerIds = context.PeerConnector.Connect(peerList.ToArray());

            socket.WriteLine("155 1 " + string.Join(":", Array.ConvertAll(connectedPeerIds, delegate(int v) { return(v.ToString()); })));

            if (processType == ClientConst.ProcessType.Join)
            {
                context.State = new RequirePeerIdState();
            }
            else if (processType == ClientConst.ProcessType.Maintain)
            {
                context.State = new RequireProtocolTimeState();
            }
            else
            {
                throw new NotImplementedException();
            }
        }
コード例 #2
0
        public override void Process(IClientContextForState context, CRLFSocket socket)
        {
            IPeerStateForClient peerState = context.PeerState;

            string[] datas = { peerState.PeerId.ToString(), (peerState.Key == null ? "Unknown" : peerState.Key.PublicKey) };

            socket.WriteLine("128 1 " + string.Join(":", datas));
        }
コード例 #3
0
        public override void Process(IClientContextForState context, CRLFSocket socket)
        {
            IPeerStateForClient peerState = context.PeerState;

            string[] datas = { peerState.PeerId.ToString(), context.PeerConfig.Port.ToString(), context.PeerConfig.FormattedAreaCode, peerState.Connections.ToString(), context.PeerConfig.MaxConnections.ToString() };

            socket.WriteLine("116 1 " + string.Join(":", datas));
        }
コード例 #4
0
        public override void Process(IClientContextForState context, CRLFSocket socket)
        {
            if (context.PeerState.PeerId <= 0)
            {
                throw new InvalidOperationException("ピアIDが設定されていません。");
            }

            socket.WriteLine("115 1 " + context.PeerState.PeerId);
        }
コード例 #5
0
        // 634 Client->Server
        public virtual void ReplyProtocolVersion(Manager.Peer peer, CRLFSocket socket, Packet packet)
        {
            if (packet.Data == null || packet.Data.Length != 3)
            {
                return;
            }

            double version = 0.0;

            if (!double.TryParse(packet.Data[0], out version))
            {
                return;
            }

            if (version < Const.ALLOW_PROTOCOL_VERSION)
            {
                socket.WriteLine("694 1 Protocol_version_incompatible");
                socket.Close();
                return;
            }

            socket.WriteLine("612 1");
        }
コード例 #6
0
        // 614 Server->Client
        public virtual void RequireProtocolVersion(Manager.Peer peer, CRLFSocket socket, Packet packet)
        {
            if (packet.Data == null || packet.Data.Length != 3)
            {
                return;
            }

            double version = 0.0;

            if (!double.TryParse(packet.Data[0], out version))
            {
                return;
            }

            if (version < Const.ALLOW_PROTOCOL_VERSION)
            {
                socket.WriteLine("694 1 Protocol_version_incompatible");
                socket.Close();
                return;
            }

            string[] datas = { Const.PROTOCOL_VERSION, Const.SOFTWARE_NAME, Const.SOFTWARE_VERSION };
            socket.WriteLine("634 1 " + string.Join(":", datas));
        }
コード例 #7
0
        public void DisposedExceptionTest()
        {
            var crlfSocket = new CRLFSocket();
            var field      = crlfSocket.GetType().GetField("socket", BindingFlags.SetField | BindingFlags.NonPublic | BindingFlags.Instance);

            var socket     = new Socket(SocketType.Stream, ProtocolType.Tcp);
            var mockSocket = new Mock <SocketAdapter>(socket)
            {
                CallBase = true
            };

            mockSocket.SetupGet(x => x.Connected).Returns(true);
            field.SetValue(crlfSocket, mockSocket.Object);

            socket.Dispose();
            Assert.IsFalse(crlfSocket.WriteLine("611 1"));
        }
コード例 #8
0
ファイル: Peer.cs プロジェクト: p2pquake/epsp-peer-cs
 internal void Send(Packet packet)
 {
     socket.WriteLine(packet.ToPacketString());
 }
コード例 #9
0
 public override void Process(IClientContextForState context, CRLFSocket socket)
 {
     string[] datas = { context.PeerState.PeerId.ToString(), context.PeerConfig.Port.ToString() };
     socket.WriteLine("114 1 " + string.Join(":", datas));
 }
コード例 #10
0
 public virtual void RequirePeerEcho(Manager.Peer peer, CRLFSocket socket, Packet packet)
 {
     socket.WriteLine("631 1");
 }
コード例 #11
0
 // 612 Server->Client
 public virtual void RequirePeerId(Manager.Peer peer, CRLFSocket socket, Packet packet)
 {
     socket.WriteLine("632 1 " + peer.GetParentPeerId());
 }
コード例 #12
0
 public override void Process(IClientContextForState context, CRLFSocket socket)
 {
     socket.WriteLine("113 1");
 }
コード例 #13
0
 public override void Process(IClientContextForState context, CRLFSocket socket)
 {
     string[] datas = { Const.PROTOCOL_VERSION, Const.SOFTWARE_NAME, Const.SOFTWARE_VERSION };
     socket.WriteLine("131 1 " + string.Join(":", datas));
 }
コード例 #14
0
 public override void Process(IClientContextForState context, CRLFSocket socket)
 {
     socket.WriteLine("117 1 " + context.PeerState.PeerId);
 }