diff options
| -rw-r--r-- | src/cmd-version.c | 21 | ||||
| -rw-r--r-- | src/instance.h | 4 | ||||
| -rw-r--r-- | src/l2su.c | 2 | ||||
| -rw-r--r-- | src/launcherutil.c | 1 | ||||
| -rw-r--r-- | src/macros.h | 2 | ||||
| -rw-r--r-- | src/version.c | 11 | ||||
| -rw-r--r-- | src/version.h | 108 |
7 files changed, 143 insertions, 6 deletions
diff --git a/src/cmd-version.c b/src/cmd-version.c index 62baa3f..260be7d 100644 --- a/src/cmd-version.c +++ b/src/cmd-version.c @@ -2,21 +2,40 @@ #include "commands.h" #include "digest/digest.h" #include "version.h" +#include "l2su.h" +#include "macros.h" #include <stdio.h> unsigned cmd_version_list_remote(struct l2_context_node *ctx, char **args) { - printf("%s\n", l2_version_strerror(l2_version_load_remote())); + unsigned res; + L2_UNUSED(ctx); + + if (*args) { + CMD_FATAL(CMD_MSG_UNKNOWN_ARGUMENT, *args); + } + + res = l2_version_load_remote(); + if (res != VERSION_SUCCESS) { + CMD_FATAL("Failed to load versions: %s", l2_version_strerror(res)); + } + + for (struct l2_version_remote *rv = l2_state.ver_remote_head; rv; rv = rv->next) { + printf("%s\n", rv->id); + } + return CMD_RESULT_SUCCESS; } unsigned cmd_version_list_local(struct l2_context_node *ctx, char **args) { + return CMD_RESULT_SUCCESS; } unsigned cmd_version_install(struct l2_context_node *ctx, char **args) { + return CMD_RESULT_SUCCESS; } diff --git a/src/instance.h b/src/instance.h index bcded1c..76d249e 100644 --- a/src/instance.h +++ b/src/instance.h @@ -2,6 +2,8 @@ #define L2SU_INSTANCE_H_INCLUDED #include "uuid/uuid.h" +#include "digest/digest.h" +#include <stddef.h> struct l2_instance { uuid_t uuid; @@ -12,6 +14,8 @@ struct l2_instance { struct l2_instance *prev; }; +#define L2_DOWNLOAD_NO_SIZE ((size_t)0) + enum { INSTANCE_SUCCESS, /* instance operation succeeded */ INSTANCE_ERRNO, /* instance operation failed (error code in errno) */ @@ -64,5 +64,3 @@ int main(int argc, char **argv) return res == CMD_RESULT_SUCCESS ? EXIT_SUCCESS : EXIT_FAILURE; } - - diff --git a/src/launcherutil.c b/src/launcherutil.c index 446bff9..38dddaa 100644 --- a/src/launcherutil.c +++ b/src/launcherutil.c @@ -222,6 +222,7 @@ CURLcode l2_launcher_download(CURL *cd, const char *url, void **odata, size_t *o curl_easy_setopt(cd, CURLOPT_URL, url); curl_easy_setopt(cd, CURLOPT_WRITEDATA, &db); curl_easy_setopt(cd, CURLOPT_WRITEFUNCTION, l2_dlcb); + curl_easy_setopt(cd, CURLOPT_USERAGENT, L2_USER_AGENT); if ((code = curl_easy_perform(cd)) != CURLE_OK) { l2_launcher_download_cleanup(&db); diff --git a/src/macros.h b/src/macros.h index 5487b12..8be48dd 100644 --- a/src/macros.h +++ b/src/macros.h @@ -17,6 +17,8 @@ (_var)[((_len1) + (_len2))] = '\0'; \ } while (0) +#define L2_USER_AGENT PROJECT_NAME "/0.1.0 <[email protected]>" + #define L2_URL_META_BASE "https://piston-meta.mojang.com" #define L2_URL_META_VERSION_MANIFEST L2_URL_META_BASE "/mc/game/version_manifest_v2.json" diff --git a/src/version.c b/src/version.c index 1f7911b..d8f264c 100644 --- a/src/version.c +++ b/src/version.c @@ -35,14 +35,20 @@ unsigned l2_version__add_remote(json_t *obj); unsigned l2_version_load_remote(void) { - json_t *vers; + json_t *vers = NULL; unsigned r = l2_version__load_manifest(&vers); + if (r != VERSION_SUCCESS) goto done; + + r = l2_version__load_all_from_json(vers); + +done: json_decref(vers); return r; } -unsigned l2_version_load_local(void) +unsigned l2_version_load_local(const char *name) { + return VERSION_SUCCESS; } @@ -362,6 +368,7 @@ unsigned l2_version__add_remote(json_t *js) if (l2_state.ver_remote_tail) { l2_state.ver_remote_tail->next = ver; ver->prev = l2_state.ver_remote_tail; + l2_state.ver_remote_tail = ver; } else { l2_state.ver_remote_head = l2_state.ver_remote_tail = ver; } diff --git a/src/version.h b/src/version.h index 2c92796..01dcbb8 100644 --- a/src/version.h +++ b/src/version.h @@ -29,11 +29,117 @@ struct l2_version_remote { time_t release_time; }; +enum { + VERSION_ARG_ACTION_ALLOW, + VERSION_ARG_ACTION_DISALLOW +}; + +#define FEATURE_DEMO (1u << 0) +#define FEATURE_CUSTOM_RES (1u << 1) +#define FEATURE_QUICK_PLAY_SUPPORTED (1u << 2) +#define FEATURE_QUICK_PLAY_SINGLEPLAYER (1u << 3) +#define FEATURE_QUICK_PLAY_MULTIPLAYER (1u << 4) +#define FEATURE_QUICK_PLAY_REALMS (1u << 5) + +struct l2_version_download { + char *url; + l2_sha1_digest_t sha1; + size_t size; +}; + +struct l2_version_rule { + unsigned action; + unsigned features; + + struct l2_version_argument_rule_os { + char *name; /* exact match */ + char *arch; /* regex */ + char *version; /* regex */ + } os; + + struct l2_version_argument_rule *next; +}; + +struct l2_version_argument { + char **value; /* ends with NULL */ + + struct l2_version_rule *rules; + + struct l2_version_argument *next; +}; + +struct l2_version { + struct l2_version_argument *game; + struct l2_version_argument *jvm; + + struct l2_version_asset_index { + char *id; + struct l2_version_download download; + size_t total_size; + } asset_index; + + char *assets; /* should equal asset_index.id */ + json_int_t compliance_level; + + struct l2_version_jar_download { + char *id; + struct l2_version_jar { + char *name; + struct l2_version_download download; + struct l2_version_jar *next; + } *jars; + } downloads; + + struct l2_version_java_version { + char *component; + json_int_t major_version; + } java_version; + + struct l2_version_library { + char *name; + + struct l2_version_library_download { + struct l2_version_library_artifact { + char *path; + struct l2_version_download download; + } *artifact; + + struct l2_version_download_classifier { + char *name; + char *path; + struct l2_version_download download; + struct l2_version_download_classifier *next; + } *classifiers; + } downloads; + + struct l2_version_library_extract { + char **exclude; /* ends with NULL */ + } *extract; + + struct l2_version_rule *rules; + + struct l2_version_native { + char *os; + char *name; + struct l2_version_native *next; + } *natives; + } *libraries; + + char *main_class; + char *type; + time_t release_time; + time_t time; + + struct l2_version *inherits; + /* minecraftArguments, */ +}; + extern const char *const l2_version__messages[]; #define l2_version_strerror(_en) l2_version__messages[(_en)] unsigned l2_version_load_remote(void); -unsigned l2_version_load_local(void); + +unsigned l2_version_load_local(const char *name); #endif /* include guard */ |
