if (!user.getPassword().equals(request.getPassword())) { reply.setError("password", "password.html"); return reply;
finally { userList.discardAll();
  public ServerDatabase processRequest(ServerDatabase request) {    ServerDatabase reply = new ServerDatabase();    System.out.println("User " + request.getUserName() + " " + request.getNoOfTracks());    ServerDatabase user = userList.getUser(request.getUserName());      // If the user doesn't exist or the password is incorrect the return a       // blank response.    if (user == null) {        // If the user already has tracks      if (request.getNoOfTracks() != 0 || request.getUserName().length() == 0 || request.getPassword().length() == 0) {        reply.setError("user", "user.html");        return reply;      }      user = userList.createUser(request.getUserName(), request.getPassword());    }    if (!user.getPassword().equals(request.getPassword())) {      reply.setError("password", "password.html");      return reply;    }      // Update the users ratings.     user.update(request);    if (user.getNoOfTracks() * userRate >= getNoOfTracks()) {      reply.setError("gotnone", "getstuffed.html");      return reply;    }    if (!user.hasRatedEnoughTracks()) {      reply.setError("notenoughratings", "http://www.irateradio.org/irate/client/help/notenoughratings.html");      return reply;    }    for (int i = 0; i < compulsoryTracks.length; i++) {      Track track = compulsoryTracks[i];      if (user.getTrack(track) == null) {        System.out.println("Compulsory: " + track.getName());        reply.add(track);      }    }    if (user.getNoOfTracks() >= initialPeerTracks) {      if ((random.nextInt() % orphanChance) == 0) {          // If there are any orphans then we add one here        Track track = orphans.randomTrack(random);        if (track != null) {          System.out.println("Orphan: " + track.getName());              reply.add(track);        }      }        // See if we can correlate a track      ServerDatabase corel = getBest(user);      System.out.println("Correlated tracks: " + corel.getNoOfTracks());      for (int i = 0; i < correlateNoOfTracks; i++) {        Track track = corel.chooseTrack(random);        if (track != null) {          System.out.println("Correlation: " + track.getName() + " " + track.getRating() + " " + track.getWeight());          reply.add(track);          corel.remove(track);        }      }    }      // Correlate tracks for new users    if (reply.getNoOfTracks() == 0 && user.getNoOfTracks() < peerThreshhold) {      for (int i = 0; i < peerRetries; i++) {        ServerDatabase peer = userList.randomUser(random, user);        if (peer != null) {          System.out.println("Peer: " + peer.getUserName());          Track track = peer.chooseTrack(random);          if (track != null && user.getTrack(track) == null) {            System.out.println("Peer track: " + track.getName() + " " + track.getRating());            reply.add(track);            break;          }        }      }    }              // Do this randomly or if we couldn't correlate    if (reply.getNoOfTracks() == 0 || (random.nextInt() % randomChance) == 0) {      Track track = randomTrack(random);      if (track == null || user.getTrack(track) != null) {          // Just pick any random track that we don't already have        ServerDatabase spares = getSpares(user);        track = spares.randomTrack(random);      }      if (track != null) {        System.out.println("Random: " + track.getName());        reply.add(track);      }    }      // Search for tracks which the user hasn't downloaded    {      Track[] tracks = user.getTracks();      for (int i = 0; i < tracks.length; i++) {        Track track = tracks[i];        if (!track.isRated() && track.getFile() != null && !track.isBroken())          reply.add(track);      }    }          // If we couldn't find any tracks to add then show a dialog.    if (reply.getNoOfTracks() == 0)      reply.setError("empty", "empty.html");          // Save the user database    purge(reply);    try {      user.add(reply);      user.save();    }    catch (IOException e) {      e.printStackTrace();    }        return reply;  } 