Package server.commands.methods

Source Code of server.commands.methods.SendPlayersList

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));
    }
  }

}
TOP

Related Classes of server.commands.methods.SendPlayersList

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.