#include "ConsoleServer.h"
#include "ConsoleSession.h"
#include "Command.h"
#include "Log.h"

namespace core {
   
   ConsoleServer::ConsoleServer(EPoll &ePoll, std::string url, short int port) 
     : TCPServerSocket(ePoll, url, port) {
	Log(this); 
     }
   
   ConsoleServer::~ConsoleServer() {}
   
   void ConsoleServer::sendToConnectedConsoles(std::string out) {
      for(auto *session : service->sessions) 
	((ConsoleSession *)session)->writeLog(out);
   }
   
   Session * ConsoleServer::getSocketAccept() {
      return new ConsoleSession(ePoll, *this->service);
   }
   
   void ConsoleServer::output(Session *session) {      
      session->out << "|" << session->ipAddress.getClientAddressAndPort();       
   }
   
}
