-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathgame_server_lib.c
2476 lines (2235 loc) · 72.9 KB
/
game_server_lib.c
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
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "game_server_lib.h"
int on_pevent(void **buf, enum pevent event, union ppayload *payload)
{
struct state *state = *(struct state **) buf;
switch (event) {
case pevent_init: {
return on_init(buf);
} break;
case pevent_before_reload: {
wclose(&state->send_responses_worker);
#ifdef _WIN32
TerminateThread(state->timer, 0);
CloseHandle(state->timer);
CloseHandle(state->lock);
#endif
#ifdef __linux__
pthread_cancel(state->timer);
pthread_mutex_destroy(&state->lock);
#endif
} break;
case pevent_after_reload: {
init_threads(state);
} break;
case pevent_socket_connection: {
lock(state);
on_connection(buf, payload->pevent_socket.socket);
unlock(state);
} break;
case pevent_socket_request: {
lock(state);
on_request(buf,
payload->pevent_socket.socket,
payload->pevent_socket.read,
payload->pevent_socket.len);
unlock(state);
} break;
case pevent_socket_disconnected: {
lock(state);
on_disconnect(buf, payload->pevent_socket.socket);
unlock(state);
} break;
default:
break;
}
return 1;
}
static int on_init(void **buf)
{
assert(buf);
size_t to_alloc = 256 mb;
assert(to_alloc > sizeof(struct state));
*buf = calloc(1, to_alloc);
if (!*buf) {
trace("unable to allocate memory for game server" nl);
return 0;
}
init_threads((struct state *) *buf);
setlocale(LC_ALL, "");
return 1;
}
#ifdef _WIN32
static DWORD timer_thread(LPVOID param)
#endif
#ifdef __linux__
static void *timer_thread(void *param)
#endif
{
struct state *state = (struct state *) param;
while (1) {
#ifdef _WIN32
Sleep(1000);
#endif
#ifdef __linux__
sleep(1);
#endif
lock(state);
on_tick(state);
unlock(state);
}
return 0;
}
static void init_threads(struct state *state)
{
assert(state);
#ifdef _WIN32
state->lock = CreateMutex(0, FALSE, 0);
state->timer = CreateThread(0, 0, timer_thread, state, 0, 0);
#endif
#ifdef __linux__
pthread_mutex_init(&state->lock, 0);
pthread_create(&state->timer, 0, timer_thread, state);
#endif
state->send_responses_worker.p = state;
wstart(&state->send_responses_worker, send_responses);
}
static void on_tick(struct state *state)
{
u64 old_ticks = state->ticks;
state->d = 1000.0f;
state->run_time += (double) state->d;
state->ticks = (u64) state->run_time / 100;
if (state->ticks == old_ticks)
return;
for (size_t i = 0; i < countof(state->characters); i++) {
struct character *character = state->characters + i;
if (!character->active)
continue;
character_update(state, character);
}
for (size_t i = 0; i < countof(state->connections); i++) {
struct connection *conn = state->connections + i;
if (!conn->socket)
continue;
if (!conn->character || !conn->character->active)
continue;
if (!conn->to_send_count)
continue;
wpush(&state->send_responses_worker, conn);
}
}
static void on_connection(void **buf, int socket)
{
assert(buf);
struct state *state = *(struct state **) buf;
assert(state);
trace("new connection to game server!" nl);
struct connection *connection = get_connection_from_socket(state, socket);
if (!connection) {
trace("there is no more space to accept new players. dropping new connection" nl);
net_close(socket);
return;
}
memset(connection, 0, sizeof(*connection));
connection->socket = socket;
byte key[] = {0x94, 0x35, 0x00, 0x00, 0xa1, 0x6c, 0x54, 0x87};
memcpy(connection->encrypt_key, key, sizeof(key));
memcpy(connection->decrypt_key, key, sizeof(key));
}
static void on_request(void **buf, int socket, void *request, size_t len)
{
assert(buf);
struct state *state = *(struct state **) buf;
assert(state);
struct connection *conn = get_connection_from_socket(state, socket);
if (!conn) {
trace("request for a non connected client?" nl);
return;
}
memcpy(conn->request + conn->request_count, request, len);
conn->request_count += len;
while (handle_request(state, conn));
wpush(&state->send_responses_worker, conn);
}
static void on_disconnect(void **buf, int socket)
{
assert(buf);
struct state *state = *(struct state **) buf;
assert(state);
struct connection *conn = get_connection_from_socket(state, socket);
if (!conn)
return;
trace("client disconnected" nl);
conn->socket = 0;
if (conn->character) {
conn->character->active = 0;
conn->character = 0;
}
}
static void send_responses(struct wqueue *q, void *w)
{
struct state *state = q->p;
lock(state);
struct connection *conn = (struct connection *) w;
void *head = conn->to_send + conn->sent;
unsigned long long to_send = conn->to_send_count - conn->sent;
trace("sending %d bytes of data to %d" nl, (s32) to_send, conn->socket);
conn->sent += net_send(conn->socket, head, to_send);
// all data has been sent, reset the counters.
if (conn->sent >= conn->to_send_count) {
conn->sent = 0;
conn->to_send_count = 0;
}
unlock(state);
}
static void character_update(struct state *state, struct character *character)
{
switch (character->action_type) {
case idle:
// idle_update(state, character);
break;
case moving:
moving_update(state, character);
break;
case attacking:
attacking_update(state, character);
break;
case dead:
break;
default:
break;
}
}
static void lock(struct state *state)
{
#ifdef _WIN32
WaitForSingleObject(state->lock, INFINITE);
#endif
#ifdef __linux__
pthread_mutex_lock(&state->lock);
#endif
}
static void unlock(struct state *state)
{
#ifdef _WIN32
ReleaseMutex(state->lock);
#endif
#ifdef __linux__
pthread_mutex_unlock(&state->lock);
#endif
}
static byte *bscanf_va(byte *src, size_t n, va_list va)
{
byte *tail = src;
while ((size_t) (tail - src) < n) {
char *fmt = va_arg(va, char *);
if (fmt == 0)
break;
if (fmt[0] == '%' && fmt[1] == 'l' && fmt[2] == 's') {
size_t max_letters = va_arg(va, size_t);
wchar_t *dest = va_arg(va, wchar_t *);
/*
* wchar_t is 2 bytes in windows and 4
* in linux, which means, we can't use
* predefined functions such as wcsncpy,
* we have to do it manually. lineage
* sends us two bytes per character.
*/
for (size_t i = 0; i < max_letters && *(u16 *) tail; i++) {
*dest++ = (wchar_t) ((tail[1] << 8) | tail[0]);
tail += 2;
}
/*
* null terminator.
*/
*dest = 0;
tail += 2;
continue;
}
if (fmt[0] == '%' && fmt[1] == 'l' && fmt[2] == 'f') {
double *dest = va_arg(va, double *);
*dest = *(double *) tail;
tail += sizeof(*dest);
continue;
}
if (fmt[0] == '%' && fmt[1] == 'u') {
u32 *dest = va_arg(va, u32 *);
*dest = *(u32 *) tail;
tail += sizeof(*dest);
continue;
}
if (fmt[0] == '%' && fmt[1] == 'h') {
u16 *dest = va_arg(va, u16 *);
*dest = *(u16 *) tail;
tail += sizeof(*dest);
continue;
}
if (fmt[0] == '%' && fmt[1] == 'c') {
u8 *dest = va_arg(va, u8 *);
*dest = *tail;
tail += sizeof(*dest);
continue;
}
if (fmt[0] == '%' && fmt[1] == 'x') {
size_t bytes_to_skip = va_arg(va, size_t);
tail += bytes_to_skip;
continue;
}
error("unexpected format '%s' in bscanf." nl, fmt);
assert(0);
}
return tail;
}
static byte *bscanf_(byte *src, size_t n, ...)
{
va_list va;
va_start(va, n);
byte *result = bscanf_va(src, n, va);
va_end(va);
return result;
}
static byte *bprintf_va(byte *dest, size_t n, va_list va)
{
byte *tail = dest;
while ((size_t) (tail - dest) < n) {
char *fmt = va_arg(va, char *);
if (fmt == 0)
break;
if (fmt[0] == '%' && fmt[1] == 'l' && fmt[2] == 's') {
size_t max_letters = va_arg(va, size_t);
wchar_t *src = va_arg(va, wchar_t *);
/*
* wchar_t is 2 bytes in windows and 4
* in linux, which means, we can't use
* predefined functions such as wcsncpy.
*/
for (size_t i = 0; i < max_letters && *(u16 *) src; i++) {
*(u16 *) tail = *src++;
tail += 2;
}
/*
* null terminator.
*/
*(u16 *) tail = 0;
tail += 2;
continue;
}
if (fmt[0] == '%' && fmt[1] == 'u') {
u32 src = va_arg(va, u32);
*(u32 *) tail = src;
tail += sizeof(src);
continue;
}
if (fmt[0] == '%' && fmt[1] == 'h') {
u16 src = (u16) va_arg(va, u32);
*(u16 *) tail = src;
tail += sizeof(src);
continue;
}
if (fmt[0] == '%' && fmt[1] == 'c') {
u8 src = (u8) va_arg(va, u32);
*tail = src;
tail += sizeof(src);
continue;
}
if (fmt[0] == '%' && fmt[1] == 'l' && fmt[2] == 'f') {
double src = va_arg(va, double);
*(double *) tail = src;
tail += sizeof(src);
continue;
}
if (fmt[0] == '%' && fmt[1] == 'x') {
size_t bytes_to_skip = va_arg(va, size_t);
memset(tail, 0, bytes_to_skip);
tail += bytes_to_skip;
continue;
}
if (fmt[0] == '%' && fmt[1] == 'b') {
size_t bytes_to_write = va_arg(va, size_t);
byte *src = va_arg(va, byte *);
memcpy(tail, src, bytes_to_write);
tail += bytes_to_write;
continue;
}
error("unexpected format '%s' in bprintf." nl, fmt);
assert(0);
}
return tail;
}
static byte *bprintf_(byte *dest, size_t n, ...)
{
va_list va;
va_start(va, n);
byte *result = bprintf_va(dest, n, va);
va_end(va);
return result;
}
static u16 packet_size(byte *src)
{
u16 size = *(u16 *) src;
return size;
}
static void push_response_va(struct connection *conn, int _encrypt, va_list va)
{
assert(conn);
byte *start = conn->to_send + conn->to_send_count;
size_t max = sizeof(conn->to_send) - (size_t) (start - conn->to_send);
byte *end = bprintf_va(start, max, va);
u16 size = (u16) (end - start);
*(u16 *) start = size;
if (_encrypt)
encrypt(conn, start);
conn->to_send_count += size;
}
static void push_response_(struct connection *conn, int _encrypt, ...)
{
assert(conn);
va_list va;
va_start(va, _encrypt);
push_response_va(conn, _encrypt, va);
va_end(va);
}
static void broadcast_(struct state *state, struct character *character, int _encrypt, ...)
{
assert(state);
assert(character);
for (size_t i = 0; i < countof(state->characters); i++) {
if (!state->characters[i].active)
continue;
struct connection *conn = state->characters[i].conn;
if (!conn)
continue;
va_list va;
va_start(va, _encrypt);
push_response_va(conn, _encrypt, va);
va_end(va);
}
}
static void encrypt(struct connection *conn, byte *packet)
{
assert(conn);
assert(packet);
u16 size = *(u16 *) packet;
if (size > 1)
size -= 2;
byte *body = packet + 2;
u32 temp = 0;
u32 temp2 = 0;
for (u16 i = 0; i < size; i++) {
temp2 = body[i] & 0xff;
body[i] = (byte) (temp2 ^ conn->encrypt_key[i & 7] ^ temp);
temp = body[i];
}
u32 old = ((u32) conn->encrypt_key[0] & 0xff);
old |= ((u32) conn->encrypt_key[1] << 8 & 0xff00);
old |= ((u32) conn->encrypt_key[2] << 0x10 & 0xff0000);
old |= ((u32) conn->encrypt_key[3] << 0x18 & 0xff000000);
old += size;
conn->encrypt_key[0] = (byte) (old & 0xff);
conn->encrypt_key[1] = (byte) (old >> 0x08 & 0xff);
conn->encrypt_key[2] = (byte) (old >> 0x10 & 0xff);
conn->encrypt_key[3] = (byte) (old >> 0x18 & 0xff);
}
static void decrypt(struct connection *conn, byte *request)
{
assert(conn);
assert(request);
u16 size = *(u16 *) request;
if (size > 1)
size -= 2;
byte *body = request + 2;
u32 temp = 0;
u32 temp2 = 0;
for (u16 i = 0; i < size; i++) {
temp2 = body[i];
body[i] = (byte) (temp2 ^ conn->decrypt_key[i & 7] ^ temp);
temp = temp2;
}
u32 old = conn->decrypt_key[0] & 0xff;
old |= conn->decrypt_key[1] << 8 & 0xff00;
old |= conn->decrypt_key[2] << 0x10 & 0xff0000;
old |= conn->decrypt_key[3] << 0x18 & 0xff000000;
old += size;
conn->decrypt_key[0] = (byte) (old & 0xff);
conn->decrypt_key[1] = (byte) (old >> 0x08 & 0xff);
conn->decrypt_key[2] = (byte) (old >> 0x10 & 0xff);
conn->decrypt_key[3] = (byte) (old >> 0x18 & 0xff);
}
static struct connection *get_connection_from_socket(struct state *state, int socket)
{
assert(state);
for (size_t i = 0; i < countof(state->connections); i++) {
if (state->connections[i].socket == socket)
return state->connections + i;
}
// find a free connection to be used for this socket.
for (size_t i = 0; i < countof(state->connections); i++) {
if (!state->connections[i].socket)
return state->connections + i;
}
return 0;
}
static void handle_request_by_type(struct state *state, struct connection *conn)
{
byte *request = conn->request;
byte type = *(request + 2);
trace("received packet is of type %#04x" nl, (int) type);
// check if the received packet matches the expected packet.
// if it doesn't, drop/close the connection.
#define expected_or_close(expected) \
if (type != (expected)) { \
error("expecting packet %d but got %d. the connection will be dropped." nl, \
(expected), \
type); \
net_close(conn->socket); \
conn->socket = 0; \
return; \
}
coroutine(conn->state) {
// expect protocol request.
expected_or_close(0x00);
handle_send_protocol(state, conn);
conn->encrypted = 1;
yield;
// expect auth request.
expected_or_close(0x08);
handle_auth(state, conn, request);
yield;
switch (type) {
// show create character screen.
case 0x0e:
handle_show_create_character_screen(state, conn);
break;
// create character.
case 0x0b:
handle_character_creation(state, conn, request);
break;
// select character
case 0x0d:
handle_select_character(state, conn, request);
break;
// bsps
case 0xd0:
handle_auto_ss_bsps(state, conn);
break;
// quest list
case 0x63:
handle_send_quest_list(state, conn);
break;
// enter world
case 0x03:
handle_enter_world(state, conn);
break;
// quit
case 0x09:
handle_leave_world(state, conn);
break;
// restart
case 0x46:
handle_restart(state, conn);
break;
// move
case 0x01:
handle_movement(state, conn, request);
break;
// validate position
case 0x48:
handle_validate_position(state, conn, request);
break;
// show map
case 0xcd:
handle_show_map(state, conn);
break;
// action
case 0x04:
handle_action(state, conn, request);
break;
// deselect target
case 0x37:
handle_deselect_target(state, conn);
break;
default:
break;
}
}
}
static int handle_request(struct state *state, struct connection *conn)
{
assert(state);
assert(conn);
byte *request = conn->request;
u16 size = *(u16 *) request;
if (size > conn->request_count)
return 0;
if (conn->encrypted)
decrypt(conn, request);
handle_request_by_type(state, conn);
memmove(conn->request, conn->request + size, conn->request_count - size);
conn->request_count -= size;
return 1;
}
static void handle_send_protocol(struct state *state, struct connection *conn)
{
assert(state);
assert(conn);
byte type = 0x00;
byte protocol[] = {
0x01,
// crypt key
0x94,
0x35,
0x00,
0x00,
0xa1,
0x6c,
0x54,
0x87,
};
push_response(conn, 0,
"%h", 0,
"%c", type,
"%b", sizeof(protocol), protocol);
}
static void handle_auth(struct state *state, struct connection *conn, byte *req)
{
assert(state);
assert(conn);
assert(req);
pscanf(req,
"%ls", countof(conn->username), conn->username,
"%u", &conn->play_ok2,
"%u", &conn->play_ok1,
"%u", &conn->login_ok1,
"%u", &conn->login_ok2);
trace("username is %S" nl, conn->username);
char access_path[512] = {0};
snprintf(access_path,
sizeof(access_path) - 1,
"data/accounts/%ls/access.txt",
conn->username);
FILE *access_file = fopen(access_path, "r");
if (!access_file) {
error("unable to read %s. can't check if this is a valid auth."
"the user will be dropped." nl,
access_path);
net_close(conn->socket);
conn->socket = 0;
return;
}
u32 stored_login_ok1 = 0;
u32 stored_login_ok2 = 0;
u32 stored_created_at = 0;
u32 stored_valid_until = 0;
fscanf(access_file,
"login_ok1=%u" nl
"login_ok2=%u" nl
"created_at=%u" nl
"valid_until=%u" nl,
&stored_login_ok1,
&stored_login_ok2,
&stored_created_at,
&stored_valid_until);
if (stored_login_ok1 != conn->login_ok1 || stored_login_ok2 != conn->login_ok2) {
warn("invalid loginok1 or loginok2 from %ls. the connection will be dropped." nl,
conn->username);
net_close(conn->socket);
conn->socket = 0;
return;
}
if (stored_valid_until < time(0)) {
trace("keys expired for %ls. the connection will be dropped." nl,
conn->username);
net_close(conn->socket);
conn->socket = 0;
return;
}
handle_send_character_list(state, conn);
}
static void handle_show_create_character_screen(struct state *state, struct connection *conn)
{
assert(state);
assert(conn);
byte type = 0x17;
u32 count = 0;
push_response(conn, 1,
"%h", 0,
"%c", type,
"%u", count);
}
static void handle_character_creation(struct state *state, struct connection *conn, byte *req)
{
assert(state);
assert(conn);
wchar_t name[32] = {0};
u32 race_id = 0;
u32 sex = 0;
u32 class_id = 0;
u32 ignore = 0;
u32 hair_style_id = 0;
u32 hair_color_id = 0;
u32 face_id = 0;
pscanf(req,
"%ls", countof(name), name,
"%u", &race_id,
"%u", &sex,
"%u", &class_id,
"%u", &ignore,
"%u", &ignore,
"%u", &ignore,
"%u", &ignore,
"%u", &ignore,
"%u", &ignore,
"%u", &hair_style_id,
"%u", &hair_color_id,
"%u", &face_id);
// TODO(fmontenegro): check if name exists
char characters_path[512] = {0};
snprintf(characters_path,
sizeof(characters_path) - 1,
"data/accounts/%ls/characters",
conn->username);
directory_create(characters_path);
char info_path[1024] = {0};
snprintf(info_path,
sizeof(info_path) - 1,
"data/accounts/%ls/characters/%ls.txt",
conn->username,
name);
FILE *info_file = fopen(info_path, "w");
if (!info_file) {
error("failed to store data for new characters in %s" nl,
info_path);
return;
}
s32 x = -83968;
s32 y = 244634;
s32 z = -3730;
u32 level = 1;
u32 xp = 1;
u32 str = 10;
u32 dex = 10;
u32 con = 10;
u32 _int = 10;
u32 wit = 10;
u32 men = 10;
double max_hp = 500.0;
double current_hp = 500.0;
double max_mp = 500.0;
double current_mp = 500.0;
double max_cp = 500.0;
double current_cp = 500.0;
u32 sp = 1;
u32 current_load = 0;
u32 max_load = 100;
u32 p_atk = 10;
u32 p_atk_speed = 10;
u32 p_def = 10;
u32 evasion_rate = 10;
u32 accuracy = 10;
u32 critical_hit = 10;
u32 m_atk = 10;
u32 m_atk_speed = 10;
u32 m_def = 10;
u32 karma = 10;
u32 run_speed = 20;
u32 walk_speed = 10;
double collision_radius = 20.0;
double collision_height = 20.0;
u32 access_level = 1;
wchar_t title[32] = L"l2auth";
u32 clan_id = 0;
u32 crest_id = 0;
u32 ally_id = 0;
u32 ally_crest_id = 0;
u32 pk_kills = 0;
u32 pvp_kills = 0;
u16 recommendations_left = 0;
u16 recommendations_have = 32;
u32 inventory_limit = 10;
u32 clan_crest_large_id = 0;
u8 hero_symbol = 0;
u8 hero = 0;
s32 fish_x = 0;
s32 fish_y = 0;
s32 fish_z = 0;
u32 name_color = 0xffffff;
fprintf(info_file,
"name=%ls" nl
"race_id=%u" nl
"sex=%u" nl
"class_id=%u" nl
"hair_style_id=%u" nl
"hair_color_id=%u" nl
"face_id=%u" nl
"x=%d" nl
"y=%d" nl
"z=%d" nl
"level=%u" nl
"xp=%u" nl
"str=%u" nl
"dex=%u" nl
"con=%u" nl
"int=%u" nl
"wit=%u" nl
"men=%u" nl
"max_hp=%lf" nl
"current_hp=%lf" nl
"max_mp=%lf" nl
"current_mp=%lf" nl
"max_cp=%lf" nl
"current_cp=%lf" nl
"sp=%u" nl
"current_load=%u" nl
"max_load=%u" nl
"p_atk=%u" nl
"p_atk_speed=%u" nl
"p_def=%u" nl
"evasion_rate=%u" nl
"accuracy=%u" nl
"critical_hit=%u" nl
"m_atk=%u" nl
"m_atk_speed=%u" nl
"m_def=%u" nl
"karma=%u" nl
"run_speed=%u" nl
"walk_speed=%u" nl
"collision_radius=%lf" nl
"collision_height=%lf" nl
"access_level=%u" nl
"title=%ls" nl
"clan_id=%u" nl
"crest_id=%u" nl
"ally_id=%u" nl
"ally_crest_id=%u" nl
"pk_kills=%u" nl
"pvp_kills=%u" nl
"recommendations_left=%u" nl
"recommendations_have=%u" nl
"inventory_limit=%u" nl
"clan_crest_large_id=%u" nl
"hero_symbol=%u" nl
"hero=%u" nl
"fish_x=%d" nl
"fish_y=%d" nl
"fish_z=%d" nl
"name_color=%u" nl,
name,
race_id,
sex,
class_id,
hair_style_id,
hair_color_id,
face_id,
x,
y,
z,
level,
xp,
str,
dex,
con,
_int,
wit,
men,
max_hp,
current_hp,
max_mp,
current_mp,
max_cp,
current_cp,
sp,
current_load,
max_load,
p_atk,
p_atk_speed,
p_def,
evasion_rate,
accuracy,
critical_hit,
m_atk,
m_atk_speed,
m_def,
karma,
run_speed,
walk_speed,
collision_radius,
collision_height,
access_level,
title,
clan_id,
crest_id,
ally_id,
ally_crest_id,
pk_kills,
pvp_kills,
recommendations_left,
recommendations_have,
inventory_limit,
clan_crest_large_id,
hero_symbol,
hero,
fish_x,
fish_y,
fish_z,
name_color);
fclose(info_file);
byte type = 0x19;
u32 success = 1;
push_response(conn, 1,
"%h", 0,
"%c", type,
"%u", success);
handle_send_character_list(state, conn);
}
static void handle_send_character_list(struct state *state, struct connection *conn)
{
assert(state);
assert(conn);
byte type = 0x13;
u32 count = 0;
char characters_path[512] = {0};
snprintf(characters_path,
sizeof(characters_path) - 1,
"data/accounts/%ls/characters",
conn->username);
in_directory(characters_path)
count++;