public void setUserList(List<IrcUser> userList) {
    if (userList != null && userList.size() > 0) {
      for (IrcUser user : userList) {
        user.deleteObserver(this);
      }
    }
    this.userList = userList;
    nickUserMap.clear();
    for (IrcUser user : userList) {
      nickUserMap.put(user.nick, user);
      user.addObserver(this);
    }

    updateTopic();
  }
  public void onUserJoined(IrcUser user) {
    userList.add(user);
    nickUserMap.put(user.nick, user);
    user.addObserver(this);

    updateTopic();
  }
  /*
   * This module's responsibility is simply to make sure the manager is up
   * to date.
   */
  public String[] run(IrcMessage m) {
    if (m.command.equals("JOIN") && m.nick.equals(IrcConfig.nick)) {
      this.chanManager.join(m.argument);
    } else if (m.command.equals("JOIN")) {
      this.chanManager.userJoin(m.argument, m.nick);
    } else if (m.command.equals("PART") && m.nick.equals(IrcConfig.nick)) {
      this.chanManager.part(m.target);
    } else if (m.command.equals("PART")) {
      this.chanManager.userPart(m.target, m.nick);
    } else if (m.command.equals("QUIT")) {
      this.chanManager.userQuit(m.nick);
    } else if (m.command.equals("KICK")
        && m.target.substring(m.target.indexOf(" ") + 1).equals(IrcConfig.nick)) {
      this.chanManager.part(m.target.substring(0, m.target.indexOf(" ")));
    } else if (m.command.equals("KICK")) {
      this.chanManager.userPart(
          m.target.substring(0, m.target.indexOf(" ")),
          m.target.substring(m.target.indexOf(" ") + 1));
    } else if (m.command.equals("NICK")) {
      this.chanManager.changeNick(m.nick, m.argument);
    } else if (m.command.equals("MODE")) {
      String[] parts = m.target.split("\\s");

      if (parts.length > 2) {
        return new String[] {"WHOIS " + parts[2]};
      }
    } else if (m.command.equals("319")) {
      String nick = m.target.substring(m.target.indexOf(" ") + 1);
      String[] parts = m.argument.split("\\s");
      char prefix;

      for (int i = 0; i < parts.length; i++) {
        prefix = IrcUser.getPrefix(parts[i]);
        this.chanManager.updatePrefix(IrcUser.stripPrefix(parts[i]), nick, prefix);
      }
    } else if (m.command.equals("353")) {
      String[] users = m.argument.split("\\s");
      String chan = m.target.substring(m.target.indexOf("#"));

      for (int i = 0; i < users.length; i++) {
        this.chanManager.userJoin(chan, users[i]);
      }
    }

    return null;
  }
  public void onUserQuit(String nick) {
    nickUserMap.remove(nick);
    for (IrcUser user : userList) {
      if (user.nick.equals(nick)) {
        for (Buffer buffer : buffers.getBufferList(true)) {
          if (user.channels.contains(buffer.getInfo().name)) {
            buffer.getUsers().removeUserByNick(nick);
          }
        }
        userList.remove(user);
        user.deleteObserver(this);
        return;
      }
    }

    updateTopic();
  }