Example #1
0
Bot::Bot(uint32_t id)
: m_id(id)
, m_forceStop(false)
{
	#ifdef USE_SSL
		m_protocol = ProtocolPtr(new Protocol(
			g_config->getString(id, "server"),
			g_config->getInteger(id, "port"),
			g_config->getBool(id, "ssl")
		));
	#else
		m_protocol = ProtocolPtr(new Protocol(
			g_config->getString(id, "server"),
			g_config->getInteger(id, "port")
		));
	#endif

	m_logfile = g_config->getString(id, "logfile");
	if(!m_logfile.size())
		m_logfile = "nvsk.log";

	m_logflag = LogType::None;
	std::string flag = g_config->getString(id, "logflag");

	if(flag == "none")      m_logflag = LogType::None;
	else if(flag == "echo") m_logflag = LogType::Echo;
	else if(flag == "file") m_logflag = LogType::File;
	else if(flag == "both") m_logflag = LogType::Both;
	else Logger::Echo("Bot #" + std::to_string(id), "Unknown loglag, defaulting to 'none'.");
}
Example #2
0
///////////////////////////////////////////////////////////////////////////////
/// @fn CConnection::CConnection
/// @description Constructor for the CConnection object. Since the change to
///   udp, this object can act either as a listener or sender (but not both)
///   to have the object behave as a listener, Start() should be called on it.
/// @pre An initialized socket is ready to be converted to a connection.
/// @post A new CConnection object is initialized.
/// @param p_ioService The socket to use for the connection.
/// @param p_manager The related connection manager that tracks this object.
/// @param p_dispatch The dispatcher responsible for applying read/write 
///   handlers to messages.
/// @param uuid The uuid this node connects to, or what listener.
///////////////////////////////////////////////////////////////////////////////
CConnection::CConnection(boost::asio::io_service& p_ioService,
  CConnectionManager& p_manager, CBroker& p_broker, std::string uuid)
  : CReliableConnection(p_ioService,p_manager,p_broker,uuid)
{
    Logger.Debug << __PRETTY_FUNCTION__ << std::endl;
    m_protocols.insert(ProtocolMap::value_type(CSUConnection::Identifier(),
        ProtocolPtr(new CSUConnection(this))));
    m_protocols.insert(ProtocolMap::value_type(CSRConnection::Identifier(),
        ProtocolPtr(new CSRConnection(this))));
    m_defaultprotocol = CSRConnection::Identifier();
}
 ProtocolPtr ProtocolManager::protocol(const QString& name)
 {
     foreach(const ProtocolPtr& proto, m_protocols)
     {
         if(proto->name() == name)
             return proto;
     }
     return ProtocolPtr();
 }
 ProtocolPtr ProtocolIterator::operator ++()
 {
     if(m_index < getProtocolManager()->protocolCount())
     {
         ProtocolPtr proto = getProtocolManager()->protocol(m_index);
         m_index++;
         return proto;
     }
     return ProtocolPtr();
 }