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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
|
/**
* This file is part of Hercules.
* http://herc.ws - http://github.com/HerculesWS/Hercules
*
* Copyright (C) 2016 Hercules Dev Team
*
* Hercules is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef LOGIN_LCLIF_P_H
#define LOGIN_LCLIF_P_H
/** @file
* Private header for the login client interface.
*/
#include "login/lclif.h"
#include "common/hercules.h"
#include "common/mmo.h"
/* Definitions and macros */
/// Maximum amount of packets processed at once from the same client
#define MAX_PROCESSED_PACKETS (3)
// Packet DB
#define MIN_PACKET_DB 0x0064
#define MAX_PACKET_DB 0x0acf
/* Enums */
/// Packet IDs
enum login_packet_id {
// CA (Client to Login)
PACKET_ID_CA_LOGIN = 0x0064,
PACKET_ID_CA_LOGIN2 = 0x01dd,
PACKET_ID_CA_LOGIN3 = 0x01fa,
PACKET_ID_CA_CONNECT_INFO_CHANGED = 0x0200,
PACKET_ID_CA_EXE_HASHCHECK = 0x0204,
PACKET_ID_CA_LOGIN_PCBANG = 0x0277,
PACKET_ID_CA_LOGIN4 = 0x027c,
PACKET_ID_CA_LOGIN_HAN = 0x02b0,
PACKET_ID_CA_SSO_LOGIN_REQ = 0x0825,
PACKET_ID_CA_LOGIN_OTP = 0x0acf,
PACKET_ID_CA_REQ_HASH = 0x01db,
PACKET_ID_CA_CHARSERVERCONNECT = 0x2710, // Custom Hercules Packet
//PACKET_ID_CA_SSO_LOGIN_REQa = 0x825a, /* unused */
// AC (Login to Client)
PACKET_ID_AC_ACCEPT_LOGIN = 0x0069,
PACKET_ID_AC_ACCEPT_LOGIN2 = 0x0ac4,
PACKET_ID_AC_REFUSE_LOGIN = 0x006a,
PACKET_ID_SC_NOTIFY_BAN = 0x0081,
PACKET_ID_AC_ACK_HASH = 0x01dc,
PACKET_ID_AC_REFUSE_LOGIN_R2 = 0x083e,
PACKET_ID_AC_REFUSE_LOGIN_R3 = 0x0b02,
};
/* Packets Structs */
#if !defined(sun) && (!defined(__NETBSD__) || __NetBSD_Version__ >= 600000000) // NetBSD 5 and Solaris don't like pragma pack but accept the packed attribute
#pragma pack(push, 1)
#endif // not NetBSD < 6 / Solaris
/**
* Packet structure for CA_LOGIN.
*/
struct packet_CA_LOGIN {
int16 packet_id; ///< Packet ID (#PACKET_ID_CA_LOGIN)
uint32 version; ///< Client Version
char id[24]; ///< Username
char password[24]; ///< Password
uint8 clienttype; ///< Client Type
} __attribute__((packed));
/**
* Packet structure for CA_LOGIN2.
*/
struct packet_CA_LOGIN2 {
int16 packet_id; ///< Packet ID (#PACKET_ID_CA_LOGIN2)
uint32 version; ///< Client Version
char id[24]; ///< Username
uint8 password_md5[16]; ///< Password hash
uint8 clienttype; ///< Client Type
} __attribute__((packed));
/**
* Packet structure for CA_LOGIN3.
*/
struct packet_CA_LOGIN3 {
int16 packet_id; ///< Packet ID (#PACKET_ID_CA_LOGIN3)
uint32 version; ///< Client Version
char id[24]; ///< Username
uint8 password_md5[16]; ///< Password hash
uint8 clienttype; ///< Client Type
uint8 clientinfo; ///< Index of the connection in the clientinfo file (+10 if the command-line contains "pc")
} __attribute__((packed));
/**
* Packet structure for CA_LOGIN4.
*/
struct packet_CA_LOGIN4 {
int16 packet_id; ///< Packet ID (#PACKET_ID_CA_LOGIN4)
uint32 version; ///< Client Version
char id[24]; ///< Username
uint8 password_md5[16]; ///< Password hash
uint8 clienttype; ///< Client Type
char mac_address[13]; ///< MAC Address
} __attribute__((packed));
/**
* Packet structure for CA_LOGIN_PCBANG.
*/
struct packet_CA_LOGIN_PCBANG {
int16 packet_id; ///< Packet ID (#PACKET_ID_CA_LOGIN_PCBANG)
uint32 version; ///< Client Version
char id[24]; ///< Username
char password[24]; ///< Password
uint8 clienttype; ///< Client Type
char ip[16]; ///< IP Address
char mac_address[13]; ///< MAC Address
} __attribute__((packed));
/**
* Packet structure for CA_LOGIN_HAN.
*/
struct packet_CA_LOGIN_HAN {
int16 packet_id; ///< Packet ID (#PACKET_ID_CA_LOGIN_HAN)
uint32 version; ///< Client Version
char id[24]; ///< Username
char password[24]; ///< Password
uint8 clienttype; ///< Client Type
char ip[16]; ///< IP Address
char mac_address[13]; ///< MAC Address
uint8 is_han_game_user; ///< 'isGravityID'
} __attribute__((packed));
/**
* Packet structure for CA_SSO_LOGIN_REQ.
*
* Variable-length packet.
*/
struct packet_CA_SSO_LOGIN_REQ {
int16 packet_id; ///< Packet ID (#PACKET_ID_CA_SSO_LOGIN_REQ)
int16 packet_len; ///< Length (variable length)
uint32 version; ///< Clientver
uint8 clienttype; ///< Clienttype
char id[24]; ///< Username
char password[27]; ///< Password
int8 mac_address[17]; ///< MAC Address
char ip[15]; ///< IP Address
char t1[]; ///< SSO Login Token (variable length)
} __attribute__((packed));
/**
* Packet structure for CA_LOGIN_OTP.
*/
struct packet_CA_LOGIN_OTP {
int16 packet_id; ///< Packet ID (#PACKET_ID_CA_LOGIN_OTP)
#if PACKETVER >= 20171113
uint32 devFlags; ///< flags including dev flag
#endif
char login[25]; ///< Username
char password[32]; ///< Password encrypted by rijndael
char flagsStr[5]; ///< Unknown flags. Normally string: G000
} __attribute__((packed));
#if 0 // Unused
struct packet_CA_SSO_LOGIN_REQa {
int16 packet_id;
int16 packet_len;
uint32 version;
uint8 clienttype;
char id[24];
int8 mac_address[17];
char ip[15];
char t1[];
} __attribute__((packed));
#endif // unused
/**
* Packet structure for CA_CONNECT_INFO_CHANGED.
*
* New alive packet. Used to verify if client is always alive.
*/
struct packet_CA_CONNECT_INFO_CHANGED {
int16 packet_id; ///< Packet ID (#PACKET_ID_CA_CONNECT_INFO_CHANGED)
char id[24]; ///< account.userid
} __attribute__((packed));
/**
* Packet structure for CA_EXE_HASHCHECK.
*
* (kRO 2004-05-31aSakexe langtype 0 and 6)
*/
struct packet_CA_EXE_HASHCHECK {
int16 packet_id; ///< Packet ID (#PACKET_ID_CA_EXE_HASHCHECK)
uint8 hash_value[16]; ///< Client MD5 hash
} __attribute__((packed));
/**
* Packet structure for CA_REQ_HASH.
*/
struct packet_CA_REQ_HASH {
int16 packet_id; ///< Packet ID (#PACKET_ID_CA_REQ_HASH)
} __attribute__((packed));
/**
* Packet structure for CA_CHARSERVERCONNECT.
*
* This packet is used internally, to signal a char-server connection.
*/
struct packet_CA_CHARSERVERCONNECT {
int16 packet_id; ///< Packet ID (#PACKET_ID_CA_CHARSERVERCONNECT)
char userid[24]; ///< Username
char password[24]; ///< Password
int32 unknown;
int32 ip; ///< Charserver IP
int16 port; ///< Charserver port
char name[20]; ///< Charserver name
int16 unknown2;
int16 type; ///< Charserver type
int16 new; ///< Whether charserver is to be marked as new
} __attribute__((packed));
/**
* Packet structure for SC_NOTIFY_BAN.
*/
struct packet_SC_NOTIFY_BAN {
int16 packet_id; ///< Packet ID (#PACKET_ID_SC_NOTIFY_BAN)
uint8 error_code; ///< Error code
} __attribute__((packed));
/**
* Packet structure for AC_REFUSE_LOGIN.
*/
struct packet_AC_REFUSE_LOGIN {
int16 packet_id; ///< Packet ID (#PACKET_ID_AC_REFUSE_LOGIN)
uint8 error_code; ///< Error code
char block_date[20]; ///< Ban expiration date
} __attribute__((packed));
/**
* Packet structure for AC_REFUSE_LOGIN_R2.
*/
struct packet_AC_REFUSE_LOGIN_R2 {
int16 packet_id; ///< Packet ID (#PACKET_ID_AC_REFUSE_LOGIN_R2)
uint32 error_code; ///< Error code
char block_date[20]; ///< Ban expiration date
} __attribute__((packed));
/**
* Packet structure for AC_ACCEPT_LOGIN.
*
* Variable-length packet.
*/
struct packet_AC_ACCEPT_LOGIN {
int16 packet_id; ///< Packet ID (#PACKET_ID_AC_ACCEPT_LOGIN)
int16 packet_len; ///< Packet length (variable length)
int32 auth_code; ///< Authentication code
uint32 aid; ///< Account ID
uint32 user_level; ///< User level
uint32 last_login_ip; ///< Last login IP
char last_login_time[26]; ///< Last login timestamp
uint8 sex; ///< Account sex
#if PACKETVER >= 20170315
char twitter_auth_token[16];
uint8 twitter_flag;
#endif
struct {
uint32 ip; ///< Server IP address
int16 port; ///< Server port
char name[20]; ///< Server name
uint16 usercount; ///< Online users
uint16 state; ///< Server state
uint16 property; ///< Server property
#if PACKETVER >= 20170315
char unknown2[128];
#endif
} server_list[]; ///< List of charservers
} __attribute__((packed));
/**
* Packet structure for AC_ACK_HASH.
*
* Variable-length packet
*/
struct packet_AC_ACK_HASH {
int16 packet_id; ///< Packet ID (#PACKET_ID_AC_ACK_HASH)
int16 packet_len; ///< Packet length (variable length)
uint8 secret[]; ///< Challenge string
} __attribute__((packed));
#if !defined(sun) && (!defined(__NETBSD__) || __NetBSD_Version__ >= 600000000) // NetBSD 5 and Solaris don't like pragma pack but accept the packed attribute
#pragma pack(pop)
#endif // not NetBSD < 6 / Solaris
/**
* Login Client Interface additional data
*/
struct lclif_interface_dbs {
struct login_packet_db packet_db[MAX_PACKET_DB + 1]; ///< Packet database.
};
/**
* Login Client Interface Private Interface
*/
struct lclif_interface_private {
struct lclif_interface_dbs *dbs;
/**
* Populates the packet database.
*/
void (*packetdb_loaddb)(void);
/**
* Attempts to validate and parse a received packet.
*
* @param fd Client connection file descriptor.
* @param sd Session data.
* @return Parse result error code.
*/
enum parsefunc_rcode (*parse_sub)(int fd, struct login_session_data *sd);
LoginParseFunc *parse_CA_CONNECT_INFO_CHANGED; ///< Packet handler for #packet_CA_CONNECT_INFO_CHANGED.
LoginParseFunc *parse_CA_EXE_HASHCHECK; ///< Packet handler for #packet_CA_EXE_HASHCHECK.
LoginParseFunc *parse_CA_LOGIN; ///< Packet handler for #packet_CA_LOGIN.
LoginParseFunc *parse_CA_LOGIN2; ///< Packet handler for #packet_CA_LOGIN2.
LoginParseFunc *parse_CA_LOGIN3; ///< Packet handler for #packet_CA_LOGIN3.
LoginParseFunc *parse_CA_LOGIN4; ///< Packet handler for #packet_CA_LOGIN4.
LoginParseFunc *parse_CA_LOGIN_PCBANG; ///< Packet handler for #packet_CA_LOGIN_PCBANG.
LoginParseFunc *parse_CA_LOGIN_HAN; ///< Packet handler for #packet_CA_LOGIN_HAN.
LoginParseFunc *parse_CA_SSO_LOGIN_REQ; ///< Packet handler for #packet_CA_SSO_LOGIN_REQ.
LoginParseFunc *parse_CA_LOGIN_OTP; ///< Packet handler for #packet_CA_LOGIN_OTP.
LoginParseFunc *parse_CA_REQ_HASH; ///< Packet handler for #packet_CA_REQ_HASH.
LoginParseFunc *parse_CA_CHARSERVERCONNECT; ///< Packet handler for #packet_CA_CHARSERVERCONNECT.
};
#endif // LOGIN_LCLIF_P_H
|