#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; bool detach = true; for (char **cur = args; *cur; ++cur) { if (!strcmp(*cur, "--nodetach")) { detach = false; } else { CMD_FATAL(CMD_MSG_UNKNOWN_ARGUMENT, *cur); } } 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"); } if (user->session) { if ((res = l2_user_session_refresh(user->session)) < 0) { CMD_FATAL0("Failed to refresh your token."); } else if (!res) { CMD_FATAL("Could not refresh your token. Interactive login required. Please run `l2su user login %s`.", username); } if (l2_user_update_profile(user) < 0) { CMD_FATAL0("Failed to update profile"); } if (l2_user_save() < 0) { CMD_FATAL0("Failed to save user"); } } struct l2_launch launch = { 0 }; if (l2_launch_init(&launch, versionname, inst) < 0) { CMD_FATAL0("Failed to initialize launch context"); } launch.user = user; launch.detach = detach; 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; }