Browse Source

add UNMAINTAINED notice as well as commit last changes

master
Shokara Kou 3 months ago
parent
commit
b731538f63
  1. 8
      README
  2. 4
      somc.c
  3. 121
      versions.c

8
README

@ -2,6 +2,10 @@ somc - shokara's own minecraft launcher
=======================================
A simple Minecraft launcher, written in ANSI C.
UNMAINTAINED: I pretty much stopped playing Minecraft so I don't really
have a reason to work on this, considering I could just use a simpler Golang
launcher (https://github.com/YAWAL/minimal-minecraft-launcher)
OSes somc is tested on:
- OpenBSD 6.9
- pledge(2) is run (TODO)
@ -9,7 +13,6 @@ OSes somc is tested on:
Minecraft versions tested:
- beta 1.7.3
- release 1.8.9
Usage
-----
@ -41,7 +44,8 @@ NAQ (not asked questions)
Q. Why does Minecraft release 1.12 (or above) not run?
A. I can't check if those releases work or run as java complains that OpenBSD
is an unsupported operating system. If you're not on OpenBSD and these
versions don't work, I suggest emailing me a patch via git-send-email(1).
versions don't work, I suggest emailing me a patch via git-send-email(1) if
you do get them working.
Q. Are legacy jar mods supported?
A. Not yet, but they are planned.

4
somc.c

@ -58,8 +58,8 @@ int main(int argc, char **argv)
}
if (instance_create(argv[2], argv[3]) < 0) {
fprintf(stderr, "instance %s with version %s failed to create",
argv[3], argv[4]);
fprintf(stderr, "instance %s with version %s failed to create\n",
argv[2], argv[3]);
}
} else {
usage(argv[0]);

121
versions.c

@ -11,21 +11,21 @@
#define VERSION_MANIFEST_URL "https://launchermeta.mojang.com/mc/game/version_manifest.json"
static char manifest_path[32];
static char version_json_path[64];
static char version_path[32];
static int get_version_manifest(int overwrite);
static int get_version_json(char *version_id, int overwrite);
static int get_manifest_csv(int overwrite);
static int get_version_csv(char *version_id, int overwrite);
/*
* get_version_manifest() fetches version_manifest.json from VERSION_MANIFEST_URL
* get_manifest_csv() fetches version_manifest.json from VERSION_MANIFEST_URL
* via curl and then parses that json into a csv file.
* The csv file's lines are formatted as:
* id, type, url
*
* An example is:
* b1.7.3, old_beta, https://url.to.minecraft/b1.7.3.json
* b1.7.3,old_beta,https://url.to.minecraft/b1.7.3.json
*/
static int get_versions_csv(int overwrite)
static int get_manifest_csv(int overwrite)
{
FILE *fp;
char path[32];
@ -52,7 +52,7 @@ static int get_versions_csv(int overwrite)
}
if (fetch_file(VERSION_MANIFEST_URL, path, overwrite) != 0) {
fprintf(stderr, "minecraft version manifest failed to download");
fprintf(stderr, "minecraft version manifest failed to download\n");
return -1;
}
@ -110,19 +110,109 @@ static int get_versions_csv(int overwrite)
return 0;
}
static int get_version_json(char *version_id, int overwrite)
static int get_version_csv(char *version_id, int overwrite)
{
char version_json_url[32];
FILE *fp;
char version_json_path[32], path[32], line[256];
char *url = NULL, *data;
size_t len;
cJSON *json, *mainClass, *libraries, *library;
strncpy(version_json_path, version_id, sizeof(version_json_path));
strncat(version_json_path, ".json", sizeof(version_json_path)
strncpy(version_json_path, ".somc.version.json", sizeof(version_json_path));
strncpy(path, "versions/", sizeof(version_json_path));
strncat(path, version_id, sizeof(version_json_path)
- strlen(version_json_path) - 1);
strncat(path, ".csv", sizeof(version_json_path)
- strlen(version_json_path) - 1);
if (fetch_file(VERSION_MANIFEST_URL, manifest_path, overwrite) != 0) {
fprintf(stderr, "minecraft version manifest failed to download");
if (get_manifest_csv(0) < 0)
return -1;
if ((fp = fopen(manifest_path, "r")) == NULL)
return -2;
/* get the version's json url */
while (fgets(line, sizeof(line), fp) != NULL) {
size_t len;
if (strstr(line, version_id) == NULL)
continue;
strtok(line, ",");
strtok(NULL, ",");
if ((url = strtok(NULL, ",")) == NULL) {
fclose(fp);
return -3;
}
len = strlen(url);
if (url[len - 1] == '\n')
url[len - 1] = '\0';
break;
}
if (url == NULL)
return -3;
if (fetch_file(url, version_json_path, overwrite) != 0) {
fprintf(stderr, "minecraft version json failed to download\n");
return -1;
}
if ((fp = fopen(version_json_path, "r")) == NULL) {
perror("fopen for version manifest failed");
return -2;
}
fseek(fp, 0, SEEK_END);
len = ftell(fp);
rewind(fp);
if ((data = malloc(len)) == NULL) {
perror("malloc for data failed");
fclose(fp);
return -3;
}
fread(data, 1, len, fp);
fclose(fp);
unlink(version_json_path);
json = cJSON_ParseWithLength(data, len);
free(data);
if (json == NULL) {
const char *error = cJSON_GetErrorPtr();
if (error != NULL)
fprintf(stderr, "json error before: %s\n", error);
cJSON_Delete(json);
return -4;
}
if ((fp = fopen(manifest_path, "w")) == NULL) {
perror("fopen for versions.csv failed");
return -2;
}
libraries = cJSON_GetObjectItemCaseSensitive(json, "versions");
cJSON_ArrayForEach(version_obj, versions_arr) {
cJSON *id, *type, *url;
id = cJSON_GetObjectItemCaseSensitive(version_obj, "id");
type = cJSON_GetObjectItemCaseSensitive(version_obj, "type");
url = cJSON_GetObjectItemCaseSensitive(version_obj, "url");
fprintf(stdout, "%s,%s,%s\n", id->valuestring, type->valuestring,
url->valuestring);
}
cJSON_Delete(json);
fclose(fp);
return 0;
}
@ -131,7 +221,7 @@ int list_versions(void)
FILE *fp;
char line[256];
if (get_versions_csv(0) < 0)
if (get_manifest_csv(0) < 0)
return -1;
if ((fp = fopen(manifest_path, "r")) == NULL) {
@ -159,6 +249,9 @@ int instance_create(char *name, char *version_id)
char *manifest_data;
size_t manifest_len;
if (get_version_csv(version_id, 0) < 0)
return -1;
strncpy(instances_dir, "instances/", sizeof(instances_dir));
mkdir(instances_dir, 0755);