コード例 #1
0
        public override Response Handle(ChatServer server, Request request)
        {
            int    nameLength = User.Client.ReceiveInt(Constants.NAME_LENGTH_SEGMENT);
            string name       = User.Client.ReceiveString(nameLength);
            string password   = User.Client.ReceiveString(request.Length - Constants.NAME_LENGTH_SEGMENT - nameLength);

            if (!Manager.Register(name, password))
            {
                return(new ErrorResponse(new UserAlreadyExistsException()));
            }

            User.Id   = Manager.GetId(name);
            User.Name = name;
            server.AddUser(User);
            return(new RegisterResponse(User));
        }
コード例 #2
0
ファイル: LoginHandler.cs プロジェクト: DvirHatuka56/Chat
        public override Response Handle(ChatServer server, Request request)
        {
            int id = User.Client.ReceiveInt(Constants.ID_SEGMNET);

            if (!Manager.UserExists(id))
            {
                return(new ErrorResponse(new UserNotFoundException()));
            }

            string password = User.Client.ReceiveString(request.Length - Constants.ID_SEGMNET);

            if (!password.Equals(Manager.GetHashedPassword(id)))
            {
                return(new ErrorResponse(new WrongPasswordException()));
            }

            User.Id   = id;
            User.Name = Manager.GetName(id);
            server.AddUser(User);
            return(new LoginResponse(User));
        }