try {
invitedPlayerIp = Inet4Address.getByName(networkInput.split(" ")[3]);
} catch (UnknownHostException ex) {
Logger.getLogger(GatheringLoungeModel.class.getName()).log(Level.SEVERE, null, ex);
}
FriendStatus invitedPlayerStatus = FriendStatus.valueOf(networkInput.split(" ")[4]);
Player player = new Player(invitedPlayerName, invitedPlayerAlias, invitedPlayerIp);
player.setStatus(invitedPlayerStatus);
invitedPlayerList.add(player);
} else if (networkInput.startsWith(RECEIVE_PROFILE_TOKEN)) {
String[] input = networkInput.split(" ");
String deel = input[1];
if (deel.equals("begin")) {
playerName = input[2];
playerAlias = input[3];
} else if (deel.equals("score")) {
playerScore += input[2];
for (int i = 3; i < input.length; i++) {
playerScore += " " + input[i];
}
playerScore += "\n";
} else { // Einde
showProfile(playerName, playerAlias, playerScore);
}
} 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);
}
}