Ejemplo n.º 1
0
void Server::execute(){

  /* Enable the server to begin accepting clients */
  setListening(true);

  do{
    handleConnections();
  }while( current_connected_players != max_connected_players );

  /* Randomly assign player ids */
  assignIds();

  /* Signal all players that the game is ready to Begin */
  broadcastPacket(PacketFactory::GAMESTART);

  /* Send out the packets for the Dictionary Data */
  broadcastPacket(PacketFactory::TROOPDEF);

  bool keep_playing = true;


  // send init packet for first turn
  sendPacket(PacketFactory::TURNSTART, 0);

  while( keep_playing ){
     keep_playing = handlePacket();
     // std::cout << "keep_playing" << keep_playing << std::endl;
  }
}
Ejemplo n.º 2
0
int Server::init(int port,  int max_clients,bool threaded,const char address[])
{
	serverPort=port;
	socket_server.initServer(port,address);
	max_num_clients=max_clients;
	closeServer=false;
	
	if(threaded)
		serverThread.Start(&Server::handleConnections,this);	
	else
		handleConnections();

	return 0;
}