From 8fd75f88d2c9fc3be927c620cf57bd47bb8984ef Mon Sep 17 00:00:00 2001 From: bigfoot547 Date: Thu, 11 Jan 2024 04:40:31 -0600 Subject: add launch command --- src/cmd-launch.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 src/cmd-launch.c (limited to 'src/cmd-launch.c') diff --git a/src/cmd-launch.c b/src/cmd-launch.c new file mode 100644 index 0000000..4c445d5 --- /dev/null +++ b/src/cmd-launch.c @@ -0,0 +1,77 @@ +#include "commands.h" +#include "command.h" +#include "l2su.h" +#include "launch.h" +#include "user.h" +#include "version.h" + +#include + +unsigned cmd_launch2(struct l2_context_node *ctx, char **args) +{ + unsigned ures; + int res; + + if (*args) { + CMD_FATAL0("sorry launch settings aren't implemented yet"); + } + + char *instancename = NULL; + char *versionname = NULL; + char *username = NULL; + + l2_cmd_collect_args(ctx, 3, "instance", &instancename, "version", &versionname, "user", &username); + + if ((ures = l2_instance_load_all()) != INSTANCE_SUCCESS) { + CMD_FATAL("Failed to load instance: %s", l2_instance_errormsg[ures]); + } + + if ((ures = l2_version_load_remote()) != VERSION_SUCCESS) { + CMD_FATAL("Failed to load versions: %s", l2_version_strerror(ures)); + } + + if ((res = l2_user_load()) < 0) { + CMD_FATAL0("Failed to load users"); + } + + struct l2_instance *inst = NULL; + + for (struct l2_instance *cur = l2_state.instance_head; cur; cur = cur->next) { + if (!strcmp(cur->name, instancename)) { + inst = cur; + break; + } + } + + if (!inst) { + CMD_FATAL("Could not find an instance by the name '%s'.", instancename); + } + + struct l2_user *user = l2_user_search(username); + if (!user) { + CMD_FATAL0("Failed to load user"); + } + + struct l2_launch launch = { 0 }; + if (l2_launch_init(&launch, versionname, inst) < 0) { + CMD_FATAL0("Failed to initialize launch context"); + } + + launch.user = user; + + if (l2_launch_init_substitutor(&launch) < 0) { + CMD_FATAL0("Failed to initialize argument substitutor"); + } + + if (l2_launch_init_args(&launch) < 0) { + CMD_FATAL0("Failed to set JVM and game arguments"); + } + + if (l2_launch_jni(&launch) < 0) { + CMD_FATAL0("Failed to launch the game"); + } + + l2_launch_free_contents(&launch); + + return CMD_RESULT_SUCCESS; +} -- cgit v1.2.3-70-g09d2