package server.commands.methods;
import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import org.quickserver.net.server.ClientHandler;
import server.protocol.ClientInfo;
import server.protocol.GameRoom;
import server.protocol.PlayerList;
/**
* The Class SendPlayersList. Handles sending the playerlist.
*/
public class SendPlayersList {
private HashMap<String, Date> clients;
private ClientInfo data;
/**
* Sends the playerlist.
*
* @param handler the handler
* @param room the room
* @throws IOException Signals that an I/O exception has occurred.
*/
public void send(ClientHandler handler, GameRoom room) throws IOException {
clients = new HashMap<String, Date>();
Iterator<ClientHandler> iterator = room.getClients().iterator();
ClientHandler toHandler = null;
while (iterator.hasNext()) {
toHandler = (ClientHandler) iterator.next();
data = (ClientInfo) toHandler.getClientData();
clients.put(data.getName(), data.getJoinTime());
}
iterator = room.getClients().iterator();
while (iterator.hasNext()){
toHandler = (ClientHandler) iterator.next();
toHandler.sendClientObject(new PlayerList(clients));
}
}
}