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 }
static void Animation_load (LIScrArgs* args) { char* file; const char* path; const char* name; LIMdlAnimation* self; LIExtAnimationModule* module; LIScrData* data; /* Get arguments. */ module = liscr_script_get_userdata (args->script, LIEXT_SCRIPT_ANIMATION); if (!liscr_args_geti_string (args, 0, &name)) return; /* Create the path. */ file = lisys_string_concat (name, ".lani"); if (file == NULL) return; path = lipth_paths_find_file (module->program->paths, file); lisys_free (file); if (path == NULL) return; /* Allocate the animation. */ self = limdl_animation_new_from_file (path); if (self == NULL) { lisys_error_report (); return; } /* Allocate the userdata. */ data = liscr_data_new (args->script, args->lua, self, LIEXT_SCRIPT_ANIMATION, limdl_animation_free); if (data == NULL) { limdl_animation_free (self); return; } liscr_args_seti_stack (args); }
static int private_init ( LIRenImage21* self, const char* name) { char* file; /* Allocate name. */ self->name = lisys_string_dup (name); if (self->name == NULL) return 0; /* Allocate path. */ file = lisys_string_concat (name, ".dds"); if (file == NULL) return 0; self->path = lipth_paths_get_graphics (self->render->paths, file); free (file); if (self->path == NULL) return 0; return 1; }
static void Model_load (LIScrArgs* args) { int mesh = 1; char* file; const char* name; const char* path; LIMdlModel* tmpmdl; LIMaiProgram* program; program = liscr_script_get_userdata (args->script, LISCR_SCRIPT_PROGRAM); if (!liscr_args_geti_string (args, 0, &name) && !liscr_args_gets_string (args, "file", &name)) return; if (!liscr_args_geti_bool (args, 1, &mesh)) liscr_args_gets_bool (args, "mesh", &mesh); /* Find the absolute path. */ file = lisys_string_concat (name, ".lmdl"); if (file == NULL) return; path = lipth_paths_find_file (program->paths, file); if (path == NULL) { lisys_free (file); return; } lisys_free (file); /* Load the new model data. */ tmpmdl = limdl_model_new_from_file (path, mesh); if (tmpmdl == NULL) return; /* Replace the old model data. */ if (limdl_model_replace (args->self, tmpmdl)) liscr_args_seti_bool (args, 1); limdl_model_free (tmpmdl); }
static void Lobby_download_server_list (LIScrArgs* args) { #ifdef HAVE_CURL int ret; int port = 0; int players = 0; char* url; char* desc; char* ip; char* name; const char* master; char error_buffer[CURL_ERROR_SIZE]; LIArcReader* reader; LIArcWriter* writer; CURL* curl; /* Get arguments. */ if (!liscr_args_gets_string (args, "master", &master)) return; liscr_args_set_output (args, LISCR_ARGS_OUTPUT_TABLE_FORCE); /* Format the script URL. */ url = lisys_string_concat (master, "/lossrvapi.php"); if (url == NULL) return; /* GET from the master server. */ curl = curl_easy_init(); if (curl != NULL) { writer = liarc_writer_new (); curl_easy_setopt (curl, CURLOPT_URL, url); curl_easy_setopt (curl, CURLOPT_WRITEDATA, writer); curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, private_write); 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); liarc_writer_free (writer); lisys_free (url); return; } curl_easy_cleanup (curl); liarc_writer_append_nul (writer); reader = liarc_reader_new ( liarc_writer_get_buffer (writer), liarc_writer_get_length (writer)); while (!liarc_reader_check_end (reader)) { ip = NULL; name = NULL; desc = NULL; ret = liarc_reader_get_text (reader, "\t", &ip) && liarc_reader_get_text_int (reader, &port) && liarc_reader_skip_bytes (reader, 1) && liarc_reader_get_text_int (reader, &players) && liarc_reader_skip_bytes (reader, 1) && liarc_reader_get_text (reader, "\t", &name) && liarc_reader_get_text (reader, "\n", &desc); if (ret) { lua_newtable (args->lua); lua_pushstring (args->lua, ip); lua_setfield (args->lua, -2, "ip"); lua_pushnumber (args->lua, port); lua_setfield (args->lua, -2, "port"); lua_pushnumber (args->lua, players); lua_setfield (args->lua, -2, "players"); lua_pushstring (args->lua, name); lua_setfield (args->lua, -2, "name"); lua_pushstring (args->lua, desc); lua_setfield (args->lua, -2, "desc"); liscr_args_seti_stack (args); } lisys_free (ip); lisys_free (name); lisys_free (desc); if (!ret) break; } liarc_reader_free (reader); liarc_writer_free (writer); } lisys_free (url); #endif }