private void parse(String line) {
if (line.toUpperCase().equals("AUTHED")) {
Controller.getInstance().dispatchEvent(
new OutputTextEvent(Localizor.getInstance().get("AUTHED"),
Formatter.getInfoFormat()));
return;
}
if (line.toUpperCase().equals("BEGINUSERS")) {
userList = new LinkedList<User>();
return;
}
if (line.toUpperCase().equals("DEREGISTERED")) {
Controller.getInstance().dispatchEvent(
new OutputTextEvent(Localizor.getInstance().get(
"DEREGISTERED"), Formatter.getInfoFormat()));
return;
}
if (line.toUpperCase().equals("ENDUSERS")) {
Controller.getInstance().dispatchEvent(
new UserListReceivedEvent(new LinkedList<User>(userList)));
return;
}
if (line.toUpperCase().startsWith("ENCRYPT ")) {
Controller.getInstance().dispatchEvent(
new CompleteEncryptionEvent(line.substring("ENCRYPT "
.length())));
return;
}
if (line.toUpperCase().startsWith("ERROR ")) {
Controller.getInstance().dispatchEvent(
new OutputTextEvent(line.substring("ERROR ".length()),
Formatter.getServerErrorFormat()));
return;
}
if (line.toUpperCase().startsWith("INDIRECT ")) {
String user = line.substring("INDIRECT ".length(), line
.indexOf(':'));
String text = line.substring(line.indexOf(':') + 2);
Controller.getInstance().dispatchEvent(
new OutputTextEvent(user + " " + text));
return;
}
if (line.toUpperCase().startsWith("INFO ")) {
Controller.getInstance().dispatchEvent(
new OutputTextEvent(line.substring("INFO ".length()),
Formatter.getInfoFormat()));
return;
}
if (line.toUpperCase().startsWith("ISAUTHED ")) {
String user = line.substring("ISAUTHED ".length(), line
.indexOf(':'));
String bool = line.substring(line.indexOf(':') + 2);
if (bool.toUpperCase().equals("TRUE")) {
Controller.getInstance().dispatchEvent(
new AuthedEvent(user, true));
return;
} else if (bool.toUpperCase().equals("FALSE")) {
Controller.getInstance().dispatchEvent(
new AuthedEvent(user, false));
return;
}
}
if (line.toUpperCase().startsWith("ISENCRYPTED ")) {
String user = line.substring("ISENCRYPTED ".length(), line
.indexOf(':'));
String bool = line.substring(line.indexOf(':') + 2);
if (bool.toUpperCase().equals("TRUE")) {
Controller.getInstance().dispatchEvent(
new EncryptedEvent(user, true));
return;
} else if (bool.toUpperCase().equals("FALSE")) {
Controller.getInstance().dispatchEvent(
new EncryptedEvent(user, false));
return;
}
}
if (line.toUpperCase().startsWith("JOIN ")) {
Controller.getInstance().dispatchEvent(
new UserJoinedEvent(line.substring("JOIN ".length())));
return;
}
if (line.toUpperCase().startsWith("NEWNICK ")) {
String oldNick = line.substring("NEWNICK ".length(), line
.indexOf(':'));
String newNick = line.substring(line.indexOf(':') + 2);
Controller.getInstance().dispatchEvent(
new NickChangeEvent(oldNick, newNick));
return;
}
if (line.toUpperCase().startsWith("NEWTOPIC ")) {
String user = line.substring("NEWTOPIC ".length(), line
.indexOf(':'));
String topic = line.substring(line.indexOf(':') + 2);
Controller.getInstance().dispatchEvent(
new TopicChangedEvent(user, topic));
return;
}
if (line.toUpperCase().startsWith("NICKINUSE ")) {
String nick = line.substring("NICKINUSE ".length());
Controller.getInstance().dispatchEvent(new NickInUseEvent(nick));
return;
}
if (line.toUpperCase().equals("PING")) {
Connection.send("PONG");
return;
}
if (line.toUpperCase().equals("PLAIN")) {
Controller.getInstance().dispatchEvent(new CompletePlainEvent());
return;
}
if (line.toUpperCase().equals("PONG")) {
Controller.getInstance().dispatchEvent(new PongEvent());
return;
}
if (line.toUpperCase().startsWith("PM ")) {
String user = line.substring("PM ".length(), line.indexOf(':'));
String text = line.substring(line.indexOf(':') + 2);
Controller.getInstance().dispatchEvent(
new OutputTextEvent(user + ": " + text, Formatter
.getPMFormat()));
return;
}
if (line.toUpperCase().startsWith("QUIT ") && line.contains(":")) {
String user = line.substring("QUIT ".length(), line.indexOf(':'));
String message = line.substring(line.indexOf(':') + 2);
Controller.getInstance().dispatchEvent(
new UserQuitEvent(user, message));
return;
}
if (line.toUpperCase().startsWith("QUIT ") && !line.contains(":")) {
String user = line.substring("QUIT ".length());
Controller.getInstance().dispatchEvent(new UserQuitEvent(user));
return;
}
if (line.toUpperCase().equals("REGISTERED")) {
Controller.getInstance().dispatchEvent(
new OutputTextEvent(Localizor.getInstance().get(
"REGISTERED"), Formatter.getInfoFormat()));
return;
}
if (line.toUpperCase().startsWith("TEXT ")) {
String user = line.substring("TEXT ".length(), line.indexOf(':'));
String text = line.substring(line.indexOf(':') + 2);
Controller.getInstance().dispatchEvent(
new OutputTextEvent(user + ": " + text));
return;
}
if (line.toUpperCase().startsWith("TOPIC ")) {
String user = line.substring("TOPIC ".length(), line.indexOf(':'));
String rest = line.substring(line.indexOf(':') + 2);
String date = rest.substring(0, "dd.mm.yyyy hh:mm".length());
String topic = rest.substring("dd.mm.yyyy hh:mm: ".length());
Controller.getInstance().dispatchEvent(
new OutputTextEvent(Localizor.getInstance().get("TOPIC",
date, user, topic), Formatter.getInfoFormat()));
return;
}
if (line.toUpperCase().startsWith("UPTIME ")) {
String date = line.substring("UPTIME ".length());
Controller.getInstance().dispatchEvent(
new OutputTextEvent(Localizor.getInstance().get("UPTIME",
date), Formatter.getInfoFormat()));
return;
}
if (line.toUpperCase().startsWith("USER ")) {
String authed = line.substring("USER ".length(),
"USER ".length() + 1);
String encrypted = line.substring("USER A".length(), "USER A"
.length() + 1);
String nick = line.substring("USER AE ".length());
boolean a, e;
if (authed.equals("T")) {
a = true;
} else if (authed.equals("F")) {
a = false;
} else {
Logger.warning(this, "Could not parse user flags!");
a = false;
}
if (encrypted.equals("T")) {
e = true;
} else if (encrypted.equals("F")) {
e = false;
} else {
Logger.warning(this, "Could not parse user flags!");
e = false;
}
userList.add(new User(nick, a, e));
return;
}
Controller.getInstance().dispatchEvent(
new OutputTextEvent(Localizor.getInstance().get(
"SERVER_CMD_NOT_UNDERSTOOD", line), Formatter
.getWarningFormat()));
}