void GameConfig::loadSettings(const INI::Section& section,
        std::vector<ConfigVariable*>& settings)
{
    try {
        std::vector<ConfigVariable*>::iterator i;
        for(i = settings.begin(); i != settings.end(); i++) {
            ConfigVariable* var = *i;

            try {
                ConfigInt* confint = dynamic_cast<ConfigInt*> (var);
                if(confint) {
                    *confint = section.getIntValue(confint->getName());
                    continue;
                }

                ConfigXY* confxy = dynamic_cast<ConfigXY*> (var);
                if(confxy) {
                    confxy->set(section.getIntValue(confxy->getName() + "_x"),
                            section.getIntValue(confxy->getName() + "_y"));
                    continue;
                }

                ConfigBool* confbool = dynamic_cast<ConfigBool*> (var);
                if(confbool) {
                    std::string str =
                        section.getValue(confbool->getName());
                    if(str == "yes" || str == "1" || str == "on")
                        *confbool = true;
                    else if(str == "no" || str == "0" || str == "off")
                        *confbool = false;
                    else
                        throw Exception("No boolean value for setting '%s'.",
                                        confbool->getName().c_str());
                    continue;
                }

                ConfigStringSpecialChars* confstringspecial = dynamic_cast<ConfigStringSpecialChars*> (var);
                if(confstringspecial) {
                    *confstringspecial = section.getValue(confstringspecial->getName());
                    continue;
                }
                
                ConfigString* confstring = dynamic_cast<ConfigString*> (var);
                if(confstring)
                    *confstring = section.getValue(confstring->getName());


                // we have a value from config file in the variable now
                //var->setNonDefaultValue();
                // now each subclass changethis if the value has been changed
            } catch(std::exception& e) {
                LOG(("Skipping config '%s': %s", var->getName().c_str(),
                            e.what()));
            }
        }
    } catch(std::exception& e) {
        LOG(("Couldn't find config section '%s', skipping...",
                    section.getName().c_str()));
    }
}
Exemple #2
0
    SociSQLDatabase(ConfigNode dbeconfig, doid_t min_id, doid_t max_id) :
        OldDatabaseBackend(dbeconfig, min_id, max_id), m_min_id(min_id), m_max_id(max_id),
        m_backend(database_driver.get_rval(dbeconfig)),
        m_db_name(database_name.get_rval(dbeconfig)),
        m_sess_user(database_username.get_rval(dbeconfig)),
        m_sess_passwd(database_password.get_rval(dbeconfig))
    {
        stringstream log_name;
        log_name << "Database-" << m_backend << "(Range: [" << min_id << ", " << max_id << "])";
        m_log = new LogCategory(m_backend, log_name.str());

        string server = database_address.get_rval(dbeconfig);
        int col_index = server.find_last_of(":");
        int sqr_index = server.find_last_of("]");
        if(col_index != string::npos && col_index > sqr_index) {
            m_db_host = server.substr(0, col_index);
            m_db_port = stoi(server.substr(col_index + 1));
        } else {
            m_db_host = server;
        }

        connect();
        check_tables();
        check_classes();
        check_ids();
    }
Exemple #3
0
EventLogger::EventLogger(RoleConfig roleconfig) : Role(roleconfig),
    m_log("eventlogger", "Event Logger"), m_file(nullptr)
{
    bind(bind_addr.get_rval(roleconfig));

    m_file_format = output_format.get_rval(roleconfig);
    open_log();

    LoggedEvent event("log-opened", "EventLogger");
    event.add("msg", "Log opened upon Event Logger startup.");
    process_packet(event.make_datagram(), m_local);
}
Exemple #4
0
DBStateServer::DBStateServer(RoleConfig roleconfig) : StateServer(roleconfig),
    m_db_channel(database_channel.get_rval(m_roleconfig)), m_next_context(0)
{
    ConfigNode ranges = dbss_config.get_child_node(ranges_config, roleconfig);
    for(const auto& it : ranges) {
        channel_t min = range_min.get_rval(it);
        channel_t max = range_max.get_rval(it);
        subscribe_range(min, max);
    }

    std::stringstream name;
    name << "DBSS(Database: " << m_db_channel << ")";
    m_log = std::unique_ptr<LogCategory>(new LogCategory("dbss", name.str()));
    set_con_name(name.str());
}
DBStateServer::DBStateServer(RoleConfig roleconfig) : StateServer(roleconfig),
    m_db_channel(database_channel.get_rval(m_roleconfig)), m_next_context(0)
{
    ConfigNode ranges = dbss_config.get_child_node(ranges_config, roleconfig);
    for(auto it = ranges.begin(); it != ranges.end(); ++it) {
        channel_t min = range_min.get_rval(*it);
        channel_t max = range_max.get_rval(*it);
        MessageDirector::singleton.subscribe_range(this, min, max);
    }

    std::stringstream name;
    name << "DBSS(Database: " << m_db_channel << ")";
    m_log = new LogCategory("dbss", name.str());
    set_con_name(name.str());
}
Exemple #6
0
		SociSQLEngine(DBEngineConfig dbeconfig, uint32_t min_id, uint32_t max_id) :
			IDatabaseEngine(dbeconfig, min_id, max_id), m_min_id(min_id), m_max_id(max_id),
			m_backend(engine_type.get_rval(dbeconfig)),
			m_db_name(database_name.get_rval(dbeconfig)),
			m_sess_user(session_user.get_rval(dbeconfig)),
			m_sess_passwd(session_passwd.get_rval(dbeconfig))
		{
			stringstream log_name;
			log_name << "Database-" << m_backend << "(Range: [" << min_id << ", " << max_id << "])";
			m_log = new LogCategory(m_backend, log_name.str());

			connect();
			check_tables();
			check_classes();
			check_ids();
		}
Exemple #7
0
		DatabaseServer(RoleConfig roleconfig) : Role(roleconfig),
			m_db_engine(DBEngineFactory::singleton.instantiate(
							engine_type.get_rval(roleconfig),
							roleconfig["engine"],
							min_id.get_rval(roleconfig),
							max_id.get_rval(roleconfig))),
			m_control_channel(control_channel.get_rval(roleconfig)),
			m_min_id(min_id.get_rval(roleconfig)),
			m_max_id(max_id.get_rval(roleconfig))
		{
			// Initialize DatabaseServer log
			std::stringstream log_title;
			log_title << "Database(" << m_control_channel << ")";
			m_log = new LogCategory("db", log_title.str());

			// Check to see the engine was instantiated
			if(!m_db_engine)
			{
				m_log->fatal() << "No database engine of type '" << engine_type.get_rval(roleconfig) << "' exists." << std::endl;
				exit(1);
			}

			// Listen on control channel
			subscribe_channel(m_control_channel);
		}
Exemple #8
0
ClientAgent::ClientAgent(RoleConfig roleconfig) : Role(roleconfig), m_net_acceptor(nullptr),
    m_server_version(server_version.get_rval(roleconfig))
{

    stringstream ss;
    ss << "Client Agent (" << bind_addr.get_rval(roleconfig) << ")";
    m_log = std::unique_ptr<LogCategory>(new LogCategory("clientagent", ss.str()));

    // We need to get the client type...
    ConfigNode client = clientagent_config.get_child_node(ca_client_config, roleconfig);
    m_client_type = ca_client_type.get_rval(client);

    // ... and also the channel range ...
    ConfigNode channels = clientagent_config.get_child_node(channels_config, roleconfig);
    m_ct = ChannelTracker(min_channel.get_rval(channels), max_channel.get_rval(channels));

    // ... then store a copy of the client config.
    m_clientconfig = clientagent_config.get_child_node(ca_client_config, roleconfig);

    // Calculate the DC hash
    const uint32_t config_hash = override_hash.get_rval(roleconfig);
    if(config_hash > 0x0) {
        m_hash = config_hash;
    } else {
        m_hash = dclass::legacy_hash(g_dcf);
    }

    // Load tuning parameters.
    ConfigNode tuning = clientagent_config.get_child_node(tuning_config, roleconfig);
    m_interest_timeout = interest_timeout.get_rval(tuning);

    TcpAcceptorCallback callback = std::bind(&ClientAgent::handle_tcp, this,
                                   std::placeholders::_1,
                                   std::placeholders::_2,
                                   std::placeholders::_3,
                                   std::placeholders::_4);
    AcceptorErrorCallback err_callback = std::bind(&ClientAgent::handle_error, this,
                                            std::placeholders::_1);

    m_net_acceptor = std::unique_ptr<TcpAcceptor>(new TcpAcceptor(callback, err_callback));

    m_net_acceptor->set_haproxy_mode(behind_haproxy.get_rval(m_roleconfig));

    // Begin listening for new Clients
    m_net_acceptor->bind(bind_addr.get_rval(m_roleconfig), 7198);
    m_net_acceptor->start();
}
void MessageDirector::init_network()
{
    if(!m_initialized)
    {
        // Bind to port and listen for downstream servers
        if(bind_addr.get_val() != "unspecified")
        {
            m_log.info() << "Opening listening socket..." << std::endl;

            TcpAcceptorCallback callback = std::bind(&MessageDirector::handle_connection,
                                           this, std::placeholders::_1);
            m_net_acceptor = new TcpAcceptor(io_service, callback);
            boost::system::error_code ec;
            ec = m_net_acceptor->bind(bind_addr.get_val(), 7199);
            if(ec.value() != 0)
            {
                m_log.fatal() << "Could not bind listening port: "
                              << bind_addr.get_val() << std::endl;
                m_log.fatal() << "Error code: " << ec.value()
                              << "(" << ec.category().message(ec.value()) << ")"
                              << std::endl;
                exit(1);
            }
            m_net_acceptor->start();
        }

        // Connect to upstream server and start handling received messages
        if(connect_addr.get_val() != "unspecified")
        {
            m_log.info() << "Connecting upstream..." << std::endl;

            MDNetworkUpstream *upstream = new MDNetworkUpstream(this);

            boost::system::error_code ec;
            upstream->connect(connect_addr.get_val());
            if(ec.value() != 0)
            {
                m_log.fatal() << "Could not connect to remote MD at IP: "
                              << connect_addr.get_val() << std::endl;
                m_log.fatal() << "Error code: " << ec.value()
                              << "(" << ec.category().message(ec.value()) << ")"
                              << std::endl;
                exit(1);
            }

            m_upstream = upstream;
        }

        if(threaded_mode.get_val())
        {
            m_thread = new std::thread(std::bind(&MessageDirector::routing_thread, this));
        }

        m_initialized = true;
    }
}
Exemple #10
0
DatabaseServer::DatabaseServer(RoleConfig roleconfig) : Role(roleconfig),
    m_control_channel(control_channel.get_rval(roleconfig)),
    m_min_id(min_id.get_rval(roleconfig)),
    m_max_id(max_id.get_rval(roleconfig)),
    m_broadcast(broadcast_updates.get_rval(roleconfig))
{
    ConfigNode generate = dbserver_config.get_child_node(generate_config, roleconfig);
    ConfigNode backend = dbserver_config.get_child_node(db_backend_config, roleconfig);
    m_db_backend = DBBackendFactory::singleton().instantiate_backend(
                       db_backend_type.get_rval(backend), backend,
                       min_id.get_rval(generate), max_id.get_rval(generate));

    // Initialize DatabaseServer log
    stringstream log_title;
    log_title << "Database(" << m_control_channel << ")";
    m_log = new LogCategory("db", log_title.str());
    set_con_name(log_title.str());

    // Check to see the backend was instantiated
    if(!m_db_backend) {
        m_log->fatal() << "No database backend of type '"
                       << db_backend_type.get_rval(backend) << "' exists." << endl;
        astron_shutdown(1);
    }

    // Listen on control channel
    subscribe_channel(m_control_channel);
    subscribe_channel(BCHAN_DBSERVERS);
}
Exemple #11
0
    MongoDatabase(ConfigNode dbeconfig, doid_t min_id, doid_t max_id) :
            DatabaseBackend(dbeconfig, min_id, max_id),
            m_shutdown(false),
            m_monotonic_exhausted(false)
    {
        stringstream log_name;
        log_name << "Database-MongoDB" << "(Range: [" << min_id << ", " << max_id << "])";
        m_log = new LogCategory("mongodb", log_name.str());

        // Init connection.
        string error;
        m_connection_string = ConnectionString::parse(db_server.get_rval(m_config), error);

        if(!m_connection_string.isValid()) {
            m_log->fatal() << "Could not parse connection string: " << error << endl;
            exit(1);
        }

        // Init the collection/database names:
        m_db = m_connection_string.getDatabase(); // NOTE: If this line won't compile, install mongo-cxx-driver's 'legacy' branch.
        m_obj_collection = m_db + ".astron.objects";
        m_global_collection = m_db + ".astron.globals";

        // Init the globals collection/document:
        DBClientBase *client = new_connection();
        BSONObj query = BSON("_id" << "GLOBALS");
        BSONObj globals = BSON("$setOnInsert" << BSON(
                                   "doid" << BSON(
                                       "monotonic" << min_id <<
                                       "free" << BSONArray())
                               ));
        client->update(m_global_collection, query, globals, true);
        delete client;

        // Spawn worker threads:
        for(int i = 0; i < num_workers.get_rval(m_config); ++i) {
            m_threads.push_back(new thread(bind(&MongoDatabase::run_thread, this)));
        }
    }
Exemple #12
0
StateServer::StateServer(RoleConfig roleconfig) : Role(roleconfig)
{
    channel_t channel = control_channel.get_rval(m_roleconfig);
    if(channel != INVALID_CHANNEL) {
        MessageDirector::singleton.subscribe_channel(this, channel);
        MessageDirector::singleton.subscribe_channel(this, BCHAN_STATESERVERS);

        std::stringstream name;
        name << "StateServer(" << channel << ")";
        m_log = new LogCategory("stateserver", name.str());
        set_con_name(name.str());
    }
}
Exemple #13
0
ClientAgent::ClientAgent(RoleConfig roleconfig) : Role(roleconfig), m_acceptor(NULL),
	m_server_version(server_version.get_rval(roleconfig))
{
	stringstream ss;
	ss << "Client Agent (" << bind_addr.get_rval(roleconfig) << ")";
	m_log = new LogCategory("clientagent", ss.str());

	// We need to get the client type...
	ConfigNode client = clientagent_config.get_child_node(ca_client_config, roleconfig);
	m_client_type = ca_client_type.get_rval(client);

	// ... and also the channel range ...
	ConfigNode channels = clientagent_config.get_child_node(channels_config, roleconfig);
	m_ct = ChannelTracker(min_channel.get_rval(channels), max_channel.get_rval(channels));

	// ... then store a copy of the client config.
	m_clientconfig = clientagent_config.get_child_node(ca_client_config, roleconfig);

	// Calculate the DC hash
	const uint32_t config_hash = override_hash.get_rval(roleconfig);
	if(config_hash > 0x0)
	{
		m_hash = config_hash;
	}
	else
	{
		m_hash = dclass::legacy_hash(g_dcf);
	}

	//Initialize the network
	string str_ip = bind_addr.get_rval(m_roleconfig);
	string str_port = str_ip.substr(str_ip.find(':', 0) + 1, string::npos);
	str_ip = str_ip.substr(0, str_ip.find(':', 0));
	tcp::resolver resolver(io_service);
	tcp::resolver::query query(str_ip, str_port);
	tcp::resolver::iterator it = resolver.resolve(query);
	m_acceptor = new tcp::acceptor(io_service, *it, true);

	start_accept();
}
Exemple #14
0
		YAMLDatabase(ConfigNode dbeconfig, doid_t min_id, doid_t max_id) :
			DatabaseBackend(dbeconfig, min_id, max_id),
			m_next_id(min_id),
			m_free_ids(),
			m_foldername(foldername.get_rval(m_config))
		{
			stringstream log_name;
			log_name << "Database-YAML" << "(Range: [" << min_id << ", " << max_id << "])";
			m_log = new LogCategory("yamldb", log_name.str());

			// Open database info file
			ifstream infostream(m_foldername + "/info.yaml");
			YAML::Node document = YAML::Load(infostream);

			if(document.IsDefined() && !document.IsNull())
			{
				// Read next available id
				YAML::Node key_next = document["next"];
				if(key_next.IsDefined() && !key_next.IsNull())
				{
					m_next_id = document["next"].as<doid_t>();
				}

				// Read available freed ids
				YAML::Node key_free = document["free"];
				if(key_free.IsDefined() && !key_free.IsNull())
				{
					for(doid_t i = 0; i < key_free.size(); i++)
					{
						m_free_ids.push_back(key_free[i].as<doid_t>());
					}
				}
			}

			// Close database info file
			infostream.close();
		}
Exemple #15
0
ClientAgent::ClientAgent(RoleConfig roleconfig) : Role(roleconfig), m_acceptor(NULL),
	m_client_type(client_type.get_rval(roleconfig)),
	m_server_version(server_version.get_rval(roleconfig)),
	m_ct(min_channel.get_rval(roleconfig), max_channel.get_rval(roleconfig))
{
	std::stringstream ss;
	ss << "Client Agent (" << bind_addr.get_rval(roleconfig) << ")";
	m_log = new LogCategory("clientagent", ss.str());

	//Initialize the network
	std::string str_ip = bind_addr.get_rval(m_roleconfig);
	std::string str_port = str_ip.substr(str_ip.find(':', 0) + 1, std::string::npos);
	str_ip = str_ip.substr(0, str_ip.find(':', 0));
	tcp::resolver resolver(io_service);
	tcp::resolver::query query(str_ip, str_port);
	tcp::resolver::iterator it = resolver.resolve(query);
	m_acceptor = new tcp::acceptor(io_service, *it, true);

	if(g_uberdogs.empty())
	{
		YAML::Node udnodes = g_config->copy_node()["uberdogs"];
		if(!udnodes.IsNull())
		{
			for(auto it = udnodes.begin(); it != udnodes.end(); ++it)
			{
				YAML::Node udnode = *it;
				Uberdog ud;
				ud.dcc = g_dcf->get_class_by_name(udnode["class"].as<std::string>());
				if(!ud.dcc)
				{
					m_log->fatal() << "DCClass " << udnode["class"].as<std::string>()
					               << "Does not exist!" << std::endl;
					exit(1);
				}
				ud.anonymous = udnode["anonymous"].as<bool>();
				g_uberdogs[udnode["id"].as<uint32_t>()] = ud;
			}
		}
	}

	start_accept();
}