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)); }
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)); }