} else if (networkInput.startsWith(NAME_CHANGE_TOKEN)) {
Iterator<Friend> iterator = super.getCurrentUser().getFriends().iterator();
while (iterator.hasNext()) {
Friend friend = iterator.next();
String newAlias = networkInput.split(" ")[1];
if (friend.getName().equals(fromName)) {
Chat.getSingleton().getChatTabbedModel().editChatter(friend, friend.getAlias(), newAlias);
friend.setAlias(newAlias);
}
}
saveUser();
fireStateChanged();
} else if (networkInput.startsWith(FRIEND_REQUEST_TOKEN)) {
Iterator<Friend> iterator = super.getCurrentUser().getFriends().iterator();
boolean exists = false;
String name = networkInput.split(" ")[1];
String alias = networkInput.split(" ")[2];
Friend friend = null;
while (iterator.hasNext() && !exists) {
friend = iterator.next();
if (friend.getName().equals(fromName)) {
exists = true;
}
}
if (!exists) { // maak vriend aan
openAddFriendFrame(name, alias, fromIp, port);
} else {
NetworkAdapter.getSingleton().sendMessage(FRIEND_ACCEPT_TOKEN + " " + getCurrentUser().getName() + " " + getCurrentUser().getAlias(), fromIp, port);
friend.setStatus(FriendStatus.IN_GATHERINGLOUNGE);
Chat.getSingleton().addChatter(GATHERINGLOUNGE_NAME, friend);
fireStateChanged();
}
} else if (networkInput.startsWith("LEFT:")) {
for (Friend friend : getCurrentUser().getFriends()) {
if (friend.getName().equals(fromName)) {
Chat.getSingleton().removeChatter(GATHERINGLOUNGE_NAME, friend);
}
}
} else if (networkInput.startsWith(GameLoungeModel.STATUS_CHANGE_TOKEN)) {
for (Friend friend : getCurrentUser().getFriends()) {
if (friend.getName().equals(fromName)) {
FriendStatus friendStatus = friend.getStatus();
if (friendStatus == FriendStatus.IN_GATHERINGLOUNGE) {
Chat.getSingleton().addChatter(GATHERINGLOUNGE_NAME, friend);
}
}
}
} else if (networkInput.startsWith(FRIEND_ACCEPT_TOKEN)) {
String name = networkInput.split(" ")[1];
String alias = networkInput.split(" ")[2];
String ip = fromIp;
JOptionPane.showMessageDialog(null,
name + " (IP: " + ip + ") has accepted your friend request.", "Friend request accepted",
JOptionPane.INFORMATION_MESSAGE, null);
try {
Friend friend = new Friend(name, alias, Inet4Address.getByName(ip));
Chat.getSingleton().addChatter(GATHERINGLOUNGE_NAME, friend);
getCurrentUser().getFriends().add(friend);
saveUser();
friend.setStatus(FriendStatus.IN_GATHERINGLOUNGE);
fireStateChanged();
} catch (UnknownHostException ex) {
System.out.println("Zou niet mogen gebeuren.");
}