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

namespace core {
   
   ConsoleServer::ConsoleServer(EPoll &ePoll, Service service, IPAddress address) 
     : TCPServerSocket(ePoll, service, address) {
		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();       
   }
   
}
