Ejemplo n.º 1
0
        public void Send(TryConnectClientCommand tryConnectClientCommand)
        {
            var r1 = new TryConnectClientResponseCommand
            {
                Target       = _connectStore.GetByUserId(tryConnectClientCommand.UserId),
                From         = _connectStore.GetByUserId(tryConnectClientCommand.Target.UserId),
                IsFromServer = true,
                IsFix        = true
            };
            var buf = r1.Serialize();

            _socket.SendTo(buf, r1.From.FromPublic);
            _serverFront.ShowMsg($"通知{r1.From.FromPublic}进行操作,固定的");

            var r2 = new TryConnectClientResponseCommand
            {
                Target       = _connectStore.GetByUserId(tryConnectClientCommand.Target.UserId),
                From         = _connectStore.GetByUserId(tryConnectClientCommand.UserId),
                IsFromServer = true
            };
            var buf2 = r2.Serialize();

            _socket.SendTo(buf2, r2.From.FromPublic);
            _serverFront.ShowMsg($"通知{r2.From.FromPublic}进行操作,非固定的,猜测");
        }
Ejemplo n.º 2
0
 public void Handle(TryConnectClientResponseCommand tryConnectClientResponseCommand, EndPoint endpoint)
 {
     if (tryConnectClientResponseCommand.IsFromServer)
     {
         tryConnectClientResponseCommand.IsFromServer = false;
         if (tryConnectClientResponseCommand.IsFix)
         {
             var buf = tryConnectClientResponseCommand.Serialize();
             for (int i = 0; i < 10; i++)
             {
                 _socket.SendTo(buf, tryConnectClientResponseCommand.Target.FromPublic);
                 _clientFront.ShowMsg($"{_clientEndPoint}=>{tryConnectClientResponseCommand.Target.FromPublic}");
                 //_socket.SendTo(buf, tryConnectClientResponseCommand.Target.FromPrivate);
             }
         }
         else
         {
             var fromip = (IPEndPoint)tryConnectClientResponseCommand.Target.FromPublic;
             var arr    = fromip.Address.ToString().Split('.');
             var baseip = $"{arr[0]}.{arr[1]}.{arr[2]}.";
             var buf    = tryConnectClientResponseCommand.Serialize();
             var mid    = int.Parse(arr[3]);
             for (int i = Math.Max(1, mid - 10); i < Math.Min(255, mid + 10); i++)
             {
                 var newip = new IPEndPoint(IPAddress.Parse(baseip + i), fromip.Port);
                 tryConnectClientResponseCommand.Target.FromPublic = newip;
                 _socket.SendTo(buf, newip);
                 _clientFront.ShowMsg($"{_clientEndPoint}=>{newip}");
                 //_socket.SendTo(buf, tryConnectClientResponseCommand.Target.FromPrivate);
             }
         }
     }
     else
     {
         //客户端之间连接成功
         _clientFront.ClientConnectSuccess(tryConnectClientResponseCommand.From, endpoint);
     }
 }