コード例 #1
0
        public override Action Handle(Packet packet)
        {
            var authPacket = AuthAction.Parse(packet);

            if (authPacket == null || authPacket.Action == AuthType.Null || authPacket.OpenPort == null)
            {
                return(base.Handle(packet));
            }

            int port     = authPacket.OpenPort ?? 0;
            var responce = resolveAuthAction(authPacket);

            return(() => AuthRequested?.Invoke(responce, new IPEndPoint(packet.Sender.Address, port)));
        }
コード例 #2
0
ファイル: AuthObserver.cs プロジェクト: Optifun/p2p-chat
        public override Action Handle(Packet packet)
        {
            var authPacket = AuthAction.Parse(packet);

            if (authPacket == null || authPacket.Nickname == null)
            {
                return(base.Handle(packet));
            }
            if (authPacket.OpenPort == null)
            {
                return () => { new Exception("Server doesn't provided open port"); }
            }
            ;

            var ip = new IPEndPoint(IPAddress.Loopback, authPacket.OpenPort.Value);

            switch (authPacket.Action)
            {
            case AuthType.UserExisting:
                return(() => { Error?.Invoke("Login is already reeserved"); });

            case AuthType.WrongCredentials:
                return(() => { Error?.Invoke("Wrong password"); });

            case AuthType.Success:
            {
                if (authPacket.Id == null)
                {
                    return () => { new Exception("Server could not generete UUID"); }
                }
                ;
                Guid id = authPacket.Id.Value;
                return(() => { Success?.Invoke(new PublicUser(ip, id, authPacket.Nickname)); });
            }

            default:
                return(() => { });
            }
        }
    }