1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
#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;
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;
}
|