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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
#include "command.h"
#include "commands.h"
#include "digest/digest.h"
#include "runtime.h"
#include "version.h"
#include "l2su.h"
#include "macros.h"
#include "args.h"
#include "assets.h"
#include "launch.h"
#include "instance.h"
#include "user.h"
#include <jansson.h>
#include <stdio.h>
#include <unistd.h>
unsigned cmd_version_list_remote(struct l2_context_node *ctx, char **args)
{
unsigned res;
L2_UNUSED(ctx);
if (*args) {
CMD_FATAL(CMD_MSG_UNKNOWN_ARGUMENT, *args);
}
res = l2_version_load_remote();
if (res != VERSION_SUCCESS) {
CMD_FATAL("Failed to load versions: %s", l2_version_strerror(res));
}
for (struct l2_version_remote *rv = l2_state.ver_remote_head; rv; rv = rv->next) {
printf("%s", rv->id);
if (rv == l2_state.ver_latest) fputs(" (latest)", stdout);
if (rv == l2_state.ver_snapshot) fputs(" (latest snapshot)", stdout);
putchar('\n');
}
return CMD_RESULT_SUCCESS;
}
unsigned cmd_version_list_local(struct l2_context_node *ctx, char **args)
{
int res;
if ((res = l2_user_load()) < 0) {
CMD_FATAL0("Failed to load users.");
}
struct l2_user *user = NULL;
for (struct l2_user *cur = l2_state.users_head; cur; cur = cur->next) {
if (!strcmp(cur->profile.name, *args)) {
user = cur;
break;
}
}
struct l2_user luser;
memset(&luser, 0, sizeof(luser));
if (!user) {
CMD_DEBUG("User %s not found", *args);
user = &luser;
}
l2_user_session_t *session = user->session;
if (!session) {
session = l2_user_session_new();
if (!session) {
CMD_FATAL0("Failed to create session");
}
user->session = session;
}
if ((res = l2_user_session_refresh(session)) < 0) {
CMD_FATAL0("Failed to refresh session");
} else if (res == 0) {
if ((res = l2_user_session_login(session)) <= 0) {
CMD_FATAL0("Failed to login");
}
}
if (l2_user_update_profile(user) < 0) {
CMD_FATAL0("Failed to uhh stuff");
}
if (user == &luser) {
l2_user_add(user);
}
if (l2_user_save() < 0) {
CMD_FATAL0("Failed to save user");
}
return CMD_RESULT_SUCCESS;
}
bool feat_match_cb(const char *name, json_t *js, void *unused) {
L2_UNUSED(name);
L2_UNUSED(js);
L2_UNUSED(unused);
return false;
}
unsigned cmd_version_install(struct l2_context_node *ctx, char **args)
{
unsigned res = l2_version_load_remote();
int ures;
if (res != VERSION_SUCCESS) {
CMD_FATAL("Failed to load versions: %s", l2_version_strerror(res));
}
if ((res = l2_instance_load_all()) != INSTANCE_SUCCESS) {
CMD_FATAL("Failed to load instances: %s", l2_instance_errormsg[res]);
}
if ((ures = l2_user_load()) < 0) {
CMD_FATAL0("Failed to load users");
}
struct l2_launch launch = { 0 };
if (l2_launch_init(&launch, *args, l2_state.instance_head) < 0) {
CMD_FATAL0("Failed to launch the game");
}
struct l2_user *user = NULL;
for (struct l2_user *cur = l2_state.users_head; cur; cur = cur->next) {
if (!strcmp(cur->profile.name, "figboot")) {
user = cur;
break;
}
}
if (!user) CMD_FATAL0("figboot not found");
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;
}
|