Exemple #1
0
static void Lobby_upload_server_info (LIScrArgs* args)
{
#ifdef HAVE_CURL
	int port = 0;
	int players = 0;
	char* url;
	char* decoded;
	const char* desc = NULL;
	const char* master = NULL;
	const char* name = NULL;
	char error_buffer[CURL_ERROR_SIZE];
	CURL* curl;

	/* Get arguments. */
	if (!liscr_args_gets_string (args, "desc", &desc) ||
	    !liscr_args_gets_string (args, "master", &master) ||
	    !liscr_args_gets_string (args, "name", &name) ||
	    !liscr_args_gets_int (args, "players", &players) ||
	    !liscr_args_gets_int (args, "port", &port))
		return;
	players = LIMAT_CLAMP (players, 0, 256);
	port = LIMAT_CLAMP (port, 1, 65535);

	/* Format the script URL. */
	url = lisys_string_concat (master, "/lossrvapi.php");
	if (url == NULL)
		return;

	/* POST to the master server. */
	curl = curl_easy_init();
	if (curl != NULL)
	{
		decoded = lisys_string_format ("u=%d|%d|%s|%s", port, players, name, desc);
		curl_easy_setopt (curl, CURLOPT_URL, url);
		curl_easy_setopt (curl, CURLOPT_POSTFIELDS, decoded);
		curl_easy_setopt (curl, CURLOPT_ERRORBUFFER, error_buffer);
		if (curl_easy_perform (curl))
		{
			lisys_error_set (EINVAL, "lobby: %s", error_buffer);
			lisys_error_report ();
		}
		curl_easy_cleanup (curl);
		lisys_free (decoded);
	}
	lisys_free (url);
#endif
}
Exemple #2
0
static void Time_get_time (LIScrArgs* args)
{
	char* str;
	time_t time;
	LISysTimeinfo info;

	/* Get the time. */
	lisys_time (&time);
	lisys_time_get_components (time, &info);

	/* Format the string. */
	str = lisys_string_format ("%02d:%02d:%02d",
		info.tm_hour, info.tm_min, info.tm_sec);
	if (str == NULL)
		return;
	liscr_args_seti_string (args, str);
	lisys_free (str);
}
Exemple #3
0
static void Time_get_date (LIScrArgs* args)
{
	char* str;
	time_t time;
	LISysTimeinfo info;

	/* Get the time. */
	lisys_time (&time);
	lisys_time_get_components (time, &info);

	/* Format the string. */
	str = lisys_string_format ("%4d-%02d-%02d",
		info.tm_year + 1900, info.tm_mon + 1, info.tm_mday);
	if (str == NULL)
		return;
	liscr_args_seti_string (args, str);
	lisys_free (str);
}
Exemple #4
0
static int private_parse_arguments (
	int    argc,
	char** argv,
	char** name,
	char** args)
{
	int i;
	char* tmp;

	for (i = 1 ; i < argc ; i++)
	{
		if (i == 1 && argv[i][0] != '-')
		{
			/* The first argument is the module name unless it begins with '-'. */
			*name = argv[i];
		}
		else if (*args == NULL)
		{
			/* Copy the first switch to the argument list. */
			*args = lisys_string_dup (argv[i]);
			if (*args == NULL)
				return 0;
		}
		else
		{
			/* Append the remaining switches to the argument list. */
			tmp = lisys_string_format ("%s %s", *args, argv[i]);
			if (tmp == NULL)
			{
				lisys_free (*args);
				return 0;
			}
			lisys_free (*args);
			*args = tmp;
		}
	}

	return 1;
}
Exemple #5
0
/**
 * \brief Loads an extension.
 * \param self Program.
 * \param name Extensions name.
 * \return Nonzero on success.
 */
int limai_program_insert_extension (
	LIMaiProgram* self,
	const char*   name)
{
	char* ptr;
	char* path;
	char* ident;
	LISysModule* module = NULL;
	LIMaiExtension* extension;
	LIMaiExtensionInfo* info;

	/* Check if already loaded. */
	extension = limai_program_find_extension (self, name);
	if (extension != NULL)
		return 1;

	/* Determine extension info struct name. We restrict the
	 * name of the extension to [a-z_] for security reasons. */
	ident = lisys_string_format ("liext_%s_info", name);
	if (ident == NULL)
		return 0;
	for (ptr = ident ; *ptr != '\0' ; ptr++)
	{
		if (*ptr < 'a' || *ptr > 'z')
			*ptr = '_';
	}

	/* Open an external library if the extension isn't built-in. */
	info = limai_extension_get_builtin (name);
	if (info == NULL)
	{
		if (self->paths->global_exts != NULL)
		{
			lisys_error_set (EINVAL, "cannot open extension `%s'", name);
			lisys_free (ident);
			return 0;
		}
		path = lisys_path_format (self->paths->global_exts, LISYS_PATH_SEPARATOR,
			"lib", name, ".", LISYS_EXTENSION_DLL, NULL);
		if (path == NULL)
		{
			lisys_free (ident);
			return 0;
		}
		module = lisys_module_new (path, 0);
		lisys_free (path);
		if (module == NULL)
		{
			path = lisys_path_format (self->paths->global_exts, LISYS_PATH_SEPARATOR,
				name, ".", LISYS_EXTENSION_DLL, NULL);
			if (path == NULL)
			{
				lisys_free (ident);
				return 0;
			}
			module = lisys_module_new (path, 0);
			lisys_free (path);
			if (module == NULL)
			{
				lisys_error_set (EINVAL, "cannot open extension `%s'", name);
				lisys_free (ident);
				return 0;
			}
		}
		info = lisys_module_symbol (module, ident);
	}
	lisys_free (ident);

	/* Check for valid module info. */
	if (info == NULL)
	{
		lisys_error_set (EINVAL, "cannot load extension `%s': no module info");
		if (module != NULL)
			lisys_module_free (module);
		return 0;
	}
	if (info->version != LIMAI_EXTENSION_VERSION)
	{
		lisys_error_set (EINVAL, "cannot load extension `%s': invalid module version");
		if (module != NULL)
			lisys_module_free (module);
		return 0;
	}
	if (info->name == NULL || info->init == NULL || info->free == NULL)
	{
		lisys_error_set (EINVAL, "cannot load extension `%s': invalid module format");
		if (module != NULL)
			lisys_module_free (module);
		return 0;
	}

	/* Allocate extension. */
	extension = lisys_calloc (1, sizeof (LIMaiExtension));
	if (extension == NULL)
	{
		if (module != NULL)
			lisys_module_free (module);
		return 0;
	}
	strncpy (extension->name, name, sizeof (extension->name) - 1);
	extension->info = info;
	extension->module = module;

	/* Call module initializer. */
	extension->object = ((void* (*)(LIMaiProgram*)) info->init)(self);
	if (extension->object == NULL)
	{
		if (module != NULL)
			lisys_module_free (module);
		lisys_free (extension);
		return 0;
	}

	/* Insert to extension list. */
	/* We prepend to the beginning of the list so that the extensions will be
	   freed in the reverse order. This allows extensions to be cleaned up
	   correctly when they have non-circular dependencies. */
	extension->next = self->extensions;
	self->extensions = extension;

	return 1;
}