示例#1
0
static void request_game_list(const char *s) {
	game_t *g;

	struct iterator it = list_iterator(&public_games);
	while ((g = iterator_next(&it))) {
		g->active = FALSE;
	}

	struct timespec ts;
	clock_gettime(CLOCK_REALTIME, &ts);
	ts.tv_sec += 2;

	pthread_mutex_lock(&pub_m);

	mcp_send(0x05, "%w 00 00 00 00 %s 00", request_id, s);
	request_id++;

	pthread_cond_timedwait(&pub_cv, &pub_m, &ts);

	it = list_iterator(&public_games);
	while ((g = iterator_next(&it))) {
		if (!g->active) {
			iterator_remove(&it);
			plugin_debug("mcp game", "removing inactive game\n");
		}
	}

	dump_game_list(&public_games);

	pthread_mutex_unlock(&pub_m);
}
示例#2
0
bool PluginManager::loadByPath(const std::string& pluginPath,
    PF_PluginType type)
{
    // Only filenames that start with libpdal_plugin are candidates to be loaded
    // at runtime.  PDAL plugins are to be named in a specified form:

    // libpdal_plugin_{stagetype}_{name}

    // For example, libpdal_plugin_writer_text or libpdal_plugin_filter_color

    bool loaded(false);

    boost::filesystem::path path(pluginPath);
    std::string pathname = Utils::tolower(path.filename().string());

    // If we are a valid type, and we're not yet already
    // loaded in the LibraryMap, load it.

    std::string plugin_debug("PDAL_DEBUG");
    std::string plugin_debug_path = Utils::getenv(plugin_debug);

    if (pluginTypeValid(pathname, type) &&
        m_dynamicLibraryMap.find(path.string()) == m_dynamicLibraryMap.end())
    {
        std::string errorString;
        auto completePath(boost::filesystem::complete(path).string());
        if (plugin_debug_path.size())
        {
            std::cerr << "PDAL: attempting to load plugin '" << completePath <<"'"<<std::endl;
        }

        if (DynamicLibrary *d = loadLibrary(completePath, errorString))
        {
            if (plugin_debug_path.size())
            {
                std::cerr << "PDAL: loaded plugin '" << completePath <<"'"<<std::endl;
            }
            if (PF_InitFunc initFunc =
                    (PF_InitFunc)(d->getSymbol("PF_initPlugin")))
            {
                loaded = initializePlugin(initFunc);
                if (plugin_debug_path.size())
                {
                    std::cerr << "PDAL: initialized plugin '" << completePath <<"'"<<std::endl;
                }
            } else
            {
                if (plugin_debug_path.size())
                {
                    std::cerr << "PDAL: failed to initialize plugin '" << completePath <<"'"<<std::endl;
                }
            }
        }
    }

    return loaded;
}
示例#3
0
void moveto(int x, int y) {
	point_t p = { x, y };

	plugin_print("meph", "moving to %i/%i\n", (word) p.x, (word) p.y);

	int t = DISTANCE(bot.location, p) * 80;

	d2gs_send(0x03, "%w %w", (word) p.x, (word) p.y);

	plugin_debug("pes", "sleeping for %ims\n", t);
	
	msleep(t > 3000 ? 3000 : t);
}
示例#4
0
int mcp_gamelist_handler(void *p) {
	mcp_packet_t *packet = MCP_CAST(p);

	game_t g;

	g.index = net_get_data(packet->data, 2, dword);
	g.players  = net_get_data(packet->data, 6, byte);
	net_extract_string(packet->data, g.name, 11);
	net_extract_string(packet->data, g.desc, 11 + strlen(g.name) + 1);

	pthread_mutex_lock(&pub_m);

	game_t *_g;
	if ((_g = list_find(&public_games, (comparator_t) compare_game_index, &g))) {
		_g->players = g.players;
		_g->active = TRUE;
		plugin_debug("mcp game", "refreshing game info\n");
	} else {
		g.joined = FALSE;
		g.active = TRUE;
		
		if (g.index) {
			list_add(&public_games, &g);

			plugin_debug("mcp game", "new game in game list\n");
		} else {
			plugin_debug("mcp game", "end of game list received\n");

			pthread_cond_signal(&pub_cv);
		}
	}

	pthread_mutex_unlock(&pub_m);

	return FORWARD_PACKET;
}
示例#5
0
bool PluginManager::guessLoadByPath(const std::string& driverName)
{
    // parse the driver name into an expected pluginName, e.g.,
    // writers.las => libpdal_plugin_writer_las

    std::vector<std::string> driverNameVec;
    driverNameVec = Utils::split2(driverName, '.');

    std::string pluginName = "libpdal_plugin_" + driverNameVec[0] + "_" +
        driverNameVec[1];

    std::string driver_path("PDAL_DRIVER_PATH");
    std::string pluginDir = Utils::getenv(driver_path);

    // Default path below if not set.
    if (pluginDir.size() == 0)
    {
        std::ostringstream oss;
        oss << PDAL_PLUGIN_INSTALL_PATH <<
            ":/usr/local/lib:./lib:../lib:../bin";
        pluginDir = oss.str();
    }

    std::string plugin_debug("PDAL_DEBUG");
    std::string plugin_debug_path = Utils::getenv(plugin_debug);
    if (plugin_debug_path.size())
    {
        std::cerr << "PDAL: plugin search path '" << pluginDir <<"'"<<std::endl;
    }

    std::vector<std::string> pluginPathVec = Utils::split2(pluginDir, ':');
    for (const auto& pluginPath : pluginPathVec)
    {
        boost::filesystem::path path(pluginPath);

        if (!FileUtils::fileExists(path.string()) ||
            !boost::filesystem::is_directory(path))
            continue;

        boost::filesystem::directory_iterator dir(path), it, end;
        // Looks like directory_iterator doesn't support range-based for loop in
        // Boost v1.55. It fails Travis anyway, so I reverted it.
        for (it = dir; it != end; ++it)
        {
            boost::filesystem::path full_path = it->path();

            if (boost::filesystem::is_directory(full_path))
                continue;

            std::string ext = full_path.extension().string();
            if (ext != dynamicLibraryExtension)
                continue;

            std::string stem = full_path.stem().string();
            std::string::size_type pos = stem.find_last_of('_');
            if (pos == std::string::npos || pos == stem.size() - 1 ||
                    stem.substr(pos + 1) != driverNameVec[1])
                continue;

            PF_PluginType type;
            if (driverNameVec[0] == "readers")
                type = PF_PluginType_Reader;
            else if (driverNameVec[0] == "kernels")
                type = PF_PluginType_Kernel;
            else if (driverNameVec[0] == "filters")
                type = PF_PluginType_Filter;
            else if (driverNameVec[0] == "writers")
                type = PF_PluginType_Writer;
            else
                type = PF_PluginType_Reader;

            if (loadByPath(full_path.string(), type))
            {
                return true;
            }
        }
    }

    return false;
}