aboutsummaryrefslogtreecommitdiffstats
path: root/src/cmd-launch.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd-launch.c')
-rw-r--r--src/cmd-launch.c77
1 files changed, 77 insertions, 0 deletions
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 <string.h>
+
+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;
+}