/
intif.c
3073 lines (2638 loc) · 85.2 KB
/
intif.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
/**
* This file is part of Hercules.
* http://herc.ws - http://github.com/HerculesWS/Hercules
*
* Copyright (C) 2012-2024 Hercules Dev Team
* Copyright (C) Athena Dev Teams
*
* 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/>.
*/
#define HERCULES_CORE
#include "config/core.h" // GP_BOUND_ITEMS
#include "intif.h"
#include "map/atcommand.h"
#include "map/battle.h"
#include "map/chrif.h"
#include "map/clan.h"
#include "map/clif.h"
#include "map/elemental.h"
#include "map/guild.h"
#include "map/homunculus.h"
#include "map/log.h"
#include "map/mail.h"
#include "map/map.h"
#include "map/mapiif.h"
#include "map/mercenary.h"
#include "map/party.h"
#include "map/pc.h"
#include "map/pet.h"
#include "map/quest.h"
#include "map/rodex.h"
#include "map/storage.h"
#include "map/achievement.h"
#include "common/apipackets.h"
#include "common/charmappackets.h"
#include "common/mapcharpackets.h"
#include "common/memmgr.h"
#include "common/msgtable.h"
#include "common/nullpo.h"
#include "common/packets_struct.h"
#include "common/showmsg.h"
#include "common/socket.h"
#include "common/strlib.h"
#include "common/timer.h"
#include "common/packets.h"
#include "common/chunked/wfifo.h"
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
static struct intif_interface intif_s;
struct intif_interface *intif;
#define inter_fd (chrif->fd) // alias
//-----------------------------------------------------------------
// Send to inter server
static int CheckForCharServer(void)
{
return ((chrif->fd <= 0) || sockt->session[chrif->fd] == NULL || sockt->session[chrif->fd]->wdata == NULL);
}
// pet
static int intif_create_pet(int account_id, int char_id, int pet_class, int pet_lv, int pet_egg_id,
int pet_equip, short intimate, short hungry, char rename_flag, char incubate, char *pet_name)
{
if (intif->CheckForCharServer())
return 0;
nullpo_ret(pet_name);
WFIFOHEAD(inter_fd, sizeof(struct PACKET_INTER_CREATE_PET));
struct PACKET_INTER_CREATE_PET *p = WFIFOP(inter_fd, 0);
p->packet_id = HEADER_INTER_CREATE_PET;
p->account_id = account_id;
p->char_id = char_id;
p->pet_class = pet_class;
p->pet_lv = pet_lv;
p->pet_egg_id = pet_egg_id;
p->pet_equip = pet_equip;
p->intimate = intimate;
p->hungry = hungry;
p->rename_flag = rename_flag;
p->incubate = incubate;
safestrncpy(p->pet_name, pet_name, NAME_LENGTH);
WFIFOSET(inter_fd, sizeof(struct PACKET_INTER_CREATE_PET));
return 0;
}
static int intif_request_petdata(int account_id, int char_id, int pet_id)
{
if (intif->CheckForCharServer())
return 0;
WFIFOHEAD(inter_fd, 14);
WFIFOW(inter_fd,0) = 0x3081;
WFIFOL(inter_fd,2) = account_id;
WFIFOL(inter_fd,6) = char_id;
WFIFOL(inter_fd,10) = pet_id;
WFIFOSET(inter_fd,14);
return 0;
}
static int intif_save_petdata(int account_id, struct s_pet *p)
{
if (intif->CheckForCharServer())
return 0;
nullpo_ret(p);
WFIFOHEAD(inter_fd, sizeof(struct s_pet) + 8);
WFIFOW(inter_fd,0) = 0x3082;
WFIFOW(inter_fd,2) = sizeof(struct s_pet) + 8;
WFIFOL(inter_fd,4) = account_id;
memcpy(WFIFOP(inter_fd,8),p,sizeof(struct s_pet));
WFIFOSET(inter_fd,WFIFOW(inter_fd,2));
return 0;
}
static int intif_delete_petdata(int pet_id)
{
if (intif->CheckForCharServer())
return 0;
WFIFOHEAD(inter_fd,6);
WFIFOW(inter_fd,0) = 0x3083;
WFIFOL(inter_fd,2) = pet_id;
WFIFOSET(inter_fd,6);
return 1;
}
static int intif_rename(struct map_session_data *sd, int type, const char *name)
{
if (intif->CheckForCharServer())
return 1;
nullpo_ret(sd);
nullpo_ret(name);
WFIFOHEAD(inter_fd,NAME_LENGTH+12);
WFIFOW(inter_fd,0) = 0x3006;
WFIFOL(inter_fd,2) = sd->status.account_id;
WFIFOL(inter_fd,6) = sd->status.char_id;
WFIFOB(inter_fd,10) = type; //Type: 0 - PC, 1 - PET, 2 - HOM
memcpy(WFIFOP(inter_fd,11),name, NAME_LENGTH);
WFIFOSET(inter_fd,NAME_LENGTH+12);
return 0;
}
//Request for saving registry values.
static int intif_saveregistry(struct map_session_data *sd)
{
struct DBIterator *iter;
union DBKey key;
struct DBData *data;
int plen = 0;
size_t len;
nullpo_ret(sd);
if (intif->CheckForCharServer() || !sd->regs.vars)
return -1;
WFIFOHEAD(inter_fd, 60000 + 300);
WFIFOW(inter_fd,0) = 0x3004;
/* 0x2 = length (set later) */
WFIFOL(inter_fd,4) = sd->status.account_id;
WFIFOL(inter_fd,8) = sd->status.char_id;
WFIFOW(inter_fd,12) = 0;/* count */
plen = 14;
iter = db_iterator(sd->regs.vars);
for( data = iter->first(iter,&key); iter->exists(iter); data = iter->next(iter,&key) ) {
const char *varname = NULL;
struct script_reg_state *src = NULL;
if( data->type != DB_DATA_PTR ) /* its a @number */
continue;
varname = script->get_str(script_getvarid(key.i64));
if( varname[0] == '@' ) /* @string$ can get here, so we skip */
continue;
if (strlen(varname) > SCRIPT_VARNAME_LENGTH) {
ShowError("Variable name too big: %s\n", varname);
continue;
}
src = DB->data2ptr(data);
/* no need! */
if( !src->update )
continue;
src->update = false;
len = strlen(varname)+1;
WFIFOB(inter_fd, plen) = (unsigned char)len;/* won't be higher; the column size is 32 */
plen += 1;
safestrncpy(WFIFOP(inter_fd,plen), varname, len);
plen += len;
WFIFOL(inter_fd, plen) = script_getvaridx(key.i64);
plen += 4;
if( src->type ) {
struct script_reg_str *p = (struct script_reg_str *)src;
WFIFOB(inter_fd, plen) = p->value ? 2 : 3;
plen += 1;
if( p->value ) {
len = strlen(p->value);
WFIFOB(inter_fd, plen) = (unsigned char)len; // Won't be higher; the column size is 255.
plen += 1;
safestrncpy(WFIFOP(inter_fd, plen), p->value, len + 1);
plen += len + 1;
} else {
script->reg_destroy_single(sd,key.i64,&p->flag);
}
} else {
struct script_reg_num *p = (struct script_reg_num *)src;
WFIFOB(inter_fd, plen) = p->value ? 0 : 1;
plen += 1;
if( p->value ) {
WFIFOL(inter_fd, plen) = p->value;
plen += 4;
} else {
script->reg_destroy_single(sd,key.i64,&p->flag);
}
}
WFIFOW(inter_fd,12) += 1;
if( plen > 60000 ) {
WFIFOW(inter_fd, 2) = plen;
WFIFOSET(inter_fd, plen);
/* prepare follow up */
WFIFOHEAD(inter_fd, 60000 + 300);
WFIFOW(inter_fd,0) = 0x3004;
/* 0x2 = length (set later) */
WFIFOL(inter_fd,4) = sd->status.account_id;
WFIFOL(inter_fd,8) = sd->status.char_id;
WFIFOW(inter_fd,12) = 0;/* count */
plen = 14;
}
}
dbi_destroy(iter);
/* mark & go. */
WFIFOW(inter_fd, 2) = plen;
WFIFOSET(inter_fd, plen);
sd->vars_dirty = false;
return 0;
}
//Request the registries for this player.
static int intif_request_registry(struct map_session_data *sd, int flag)
{
nullpo_ret(sd);
/* if char server ain't online it doesn't load, shouldn't we kill the session then? */
if (intif->CheckForCharServer())
return 0;
WFIFOHEAD(inter_fd,6);
WFIFOW(inter_fd,0) = 0x3005;
WFIFOL(inter_fd,2) = sd->status.account_id;
WFIFOL(inter_fd,6) = sd->status.char_id;
WFIFOB(inter_fd,10) = (flag&1) ? 1 : 0; //Request Acc Reg 2
WFIFOB(inter_fd,11) = (flag&2) ? 1 : 0; //Request Acc Reg
WFIFOB(inter_fd,12) = (flag&4) ? 1 : 0; //Request Char Reg
WFIFOSET(inter_fd,13);
return 0;
}
//=================================================================
// Account Storage
//-----------------------------------------------------------------
/**
* Request the inter-server for a character's storage data.
* @packet 0x3010 [out] <account_id>.L
* @param sd [in] pointer to session data.
*/
static void intif_request_account_storage(const struct map_session_data *sd)
{
nullpo_retv(sd);
/* Check for character server availability */
if (intif->CheckForCharServer())
return;
WFIFOHEAD(inter_fd, 6);
WFIFOW(inter_fd, 0) = 0x3010;
WFIFOL(inter_fd, 2) = sd->status.account_id;
WFIFOSET(inter_fd, 6);
}
/**
* Parse the reception of account storage from the inter-server.
* @packet 0x3805 [in] <packet_len>.W <account_id>.L <struct item[]>.P
* @param fd [in] file/socket descriptor.
*/
static void intif_parse_account_storage(int fd)
{
int account_id = 0, payload_size = 0, storage_count = 0;
int i = 0;
struct map_session_data *sd = NULL;
Assert_retv(fd > 0);
payload_size = RFIFOW(fd, 2) - 8;
if ((account_id = RFIFOL(fd, 4)) == 0 || (sd = map->id2sd(account_id)) == NULL) {
ShowError("intif_parse_account_storage: Session pointer was null for account id %d!\n", account_id);
return;
}
if (sd->storage.received == true) {
ShowError("intif_parse_account_storage: Multiple calls from the inter-server received.\n");
return;
}
storage_count = (payload_size/sizeof(struct item));
VECTOR_ENSURE(sd->storage.item, storage_count, 1);
sd->storage.aggregate = storage_count; // Total items in storage.
for (i = 0; i < storage_count; i++) {
const struct item *it = RFIFOP(fd, 8 + i * sizeof(struct item));
VECTOR_PUSH(sd->storage.item, *it);
}
sd->storage.received = true; // Mark the storage state as received.
sd->storage.save = false; // Initialize the save flag as false.
pc->checkitem(sd); // re-check remaining items.
}
/**
* Sends account storage information for saving to the character server.
*
* @code{.unparsed}
* @packet 0x3011 [out] <packet_len>.W <account_id>.L <struct item[]>.P
* @endcode
*
* @attention If the size of packet 0x3011 changes,
* @ref MAX_STORAGE_ASSERT "the related static assertion check"
* in mmo.h needs to be adjusted, too.
*
* @see mapif_parse_AccountStorageSave()
*
* @param[in] sd Pointer to the session data containing the account storage information to save.
*
**/
static void intif_send_account_storage(struct map_session_data *sd)
{
int len = 0, i = 0, c = 0;
nullpo_retv(sd);
// Assert that at this point in the code, both flags are true.
Assert_retv(sd->storage.save == true);
Assert_retv(sd->storage.received == true);
if (intif->CheckForCharServer())
return;
len = 8 + sd->storage.aggregate * sizeof(struct item);
WFIFOHEAD(inter_fd, len);
WFIFOW(inter_fd, 0) = 0x3011;
WFIFOW(inter_fd, 2) = (uint16) len;
WFIFOL(inter_fd, 4) = sd->status.account_id;
for (i = 0, c = 0; i < VECTOR_LENGTH(sd->storage.item); i++) {
if (VECTOR_INDEX(sd->storage.item, i).nameid == 0)
continue;
memcpy(WFIFOP(inter_fd, 8 + c * sizeof(struct item)), &VECTOR_INDEX(sd->storage.item, i), sizeof(struct item));
c++;
}
WFIFOSET(inter_fd, len);
sd->storage.save = false; // Save request has been sent
}
/**
* Parse acknowledgement packet for the saving of an account's storage.
* @packet 0x3808 [in] <account_id>.L <saved_flag>.B
* @param fd [in] file/socket descriptor.
*/
static void intif_parse_account_storage_save_ack(int fd)
{
int account_id = RFIFOL(fd, 2);
uint8 saved = RFIFOB(fd, 6);
struct map_session_data *sd = NULL;
Assert_retv(account_id > 0);
Assert_retv(fd > 0);
if ((sd = map->id2sd(account_id)) == NULL)
return; // character is most probably offline.
if (saved == 0) {
ShowError("intif_parse_account_storage_save_ack: Storage has not been saved! (AID: %d)\n", account_id);
sd->storage.save = true; // Flag it as unsaved, to re-attempt later
return;
}
}
//=================================================================
// Guild Storage
//-----------------------------------------------------------------
static int intif_request_guild_storage(int account_id, int guild_id)
{
if (intif->CheckForCharServer())
return 0;
WFIFOHEAD(inter_fd,10);
WFIFOW(inter_fd,0) = 0x3018;
WFIFOL(inter_fd,2) = account_id;
WFIFOL(inter_fd,6) = guild_id;
WFIFOSET(inter_fd,10);
return 0;
}
/**
* Sends guild storage information for saving to the character server.
*
* @code{.unparsed}
* @packet 0x3019 [out] <packet_len>.W <account_id>.L <guild_id>.L {<struct item>.P} * <capacity>
* @endcode
*
* @attention If the size of packet 0x3019 changes,
* @ref MAX_GUILD_STORAGE_ASSERT "the related static assertion check"
* in mmo.h needs to be adjusted, too.
*
* @see mapif_parse_SaveGuildStorage()
*
* @param[in] account_id The account ID of the character who initiated saving the guild storage information.
* @param[in] gstor Pointer to the guild storage data containing the information to save.
* @return Always 0.
*
*/
static int intif_send_guild_storage(int account_id, struct guild_storage *gstor)
{
int size;
if (intif->CheckForCharServer())
return 1;
nullpo_retr(1, gstor);
size = 20 + sizeof(gstor->items.data[0])*gstor->items.capacity;
WFIFOHEAD(inter_fd, size);
WFIFOW(inter_fd,0) = 0x3019;
WFIFOW(inter_fd,2) = size;
WFIFOL(inter_fd,4) = account_id;
WFIFOL(inter_fd,8) = gstor->guild_id;
WFIFOL(inter_fd,12) = gstor->items.capacity;
WFIFOL(inter_fd,16) = gstor->items.amount;
if (gstor->items.data != NULL)
memcpy(WFIFOP(inter_fd, 20), gstor->items.data, sizeof(gstor->items.data[0])*gstor->items.capacity);
WFIFOSET(inter_fd, size);
return 0;
}
// Party creation request
static int intif_create_party(struct party_member *member, const char *name, int item, int item2)
{
if (intif->CheckForCharServer())
return 0;
nullpo_ret(member);
nullpo_ret(name);
WFIFOHEAD(inter_fd,64);
WFIFOW(inter_fd,0) = 0x3020;
WFIFOW(inter_fd,2) = 30+sizeof(struct party_member);
memcpy(WFIFOP(inter_fd,4),name, NAME_LENGTH);
WFIFOB(inter_fd,28)= item;
WFIFOB(inter_fd,29)= item2;
memcpy(WFIFOP(inter_fd,30), member, sizeof(struct party_member));
WFIFOSET(inter_fd,WFIFOW(inter_fd, 2));
return 0;
}
// Party information request
static int intif_request_partyinfo(int party_id, int char_id)
{
if (intif->CheckForCharServer())
return 0;
WFIFOHEAD(inter_fd,10);
WFIFOW(inter_fd,0) = 0x3021;
WFIFOL(inter_fd,2) = party_id;
WFIFOL(inter_fd,6) = char_id;
WFIFOSET(inter_fd,10);
return 0;
}
// Request to add a member to party
static int intif_party_addmember(int party_id, struct party_member *member)
{
if (intif->CheckForCharServer())
return 0;
nullpo_ret(member);
WFIFOHEAD(inter_fd,42);
WFIFOW(inter_fd,0)=0x3022;
WFIFOW(inter_fd,2)=8+sizeof(struct party_member);
WFIFOL(inter_fd,4)=party_id;
memcpy(WFIFOP(inter_fd,8),member,sizeof(struct party_member));
WFIFOSET(inter_fd,WFIFOW(inter_fd, 2));
return 1;
}
// Request to change party configuration (exp,item share)
static int intif_party_changeoption(int party_id, int account_id, int exp, int item)
{
if (intif->CheckForCharServer())
return 0;
WFIFOHEAD(inter_fd,14);
WFIFOW(inter_fd,0)=0x3023;
WFIFOL(inter_fd,2)=party_id;
WFIFOL(inter_fd,6)=account_id;
WFIFOW(inter_fd,10)=exp;
WFIFOW(inter_fd,12)=item;
WFIFOSET(inter_fd,14);
return 0;
}
// Request to leave party
static int intif_party_leave(int party_id, int account_id, int char_id)
{
if (intif->CheckForCharServer())
return 0;
WFIFOHEAD(inter_fd,14);
WFIFOW(inter_fd,0)=0x3024;
WFIFOL(inter_fd,2)=party_id;
WFIFOL(inter_fd,6)=account_id;
WFIFOL(inter_fd,10)=char_id;
WFIFOSET(inter_fd,14);
return 0;
}
// Request keeping party for new map ??
static int intif_party_changemap(struct map_session_data *sd, int online)
{
int16 m, map_index;
if (intif->CheckForCharServer())
return 0;
if(!sd)
return 0;
if( (m=map->mapindex2mapid(sd->mapindex)) >= 0 && map->list[m].instance_id >= 0 )
map_index = map_id2index(map->list[m].instance_src_map);
else
map_index = sd->mapindex;
WFIFOHEAD(inter_fd,19);
WFIFOW(inter_fd,0)=0x3025;
WFIFOL(inter_fd,2)=sd->status.party_id;
WFIFOL(inter_fd,6)=sd->status.account_id;
WFIFOL(inter_fd,10)=sd->status.char_id;
WFIFOW(inter_fd,14)=map_index;
WFIFOB(inter_fd,16)=online;
WFIFOW(inter_fd,17)=sd->status.base_level;
WFIFOSET(inter_fd,19);
return 1;
}
// Request breaking party
static int intif_break_party(int party_id)
{
if (intif->CheckForCharServer())
return 0;
WFIFOHEAD(inter_fd,6);
WFIFOW(inter_fd,0)=0x3026;
WFIFOL(inter_fd,2)=party_id;
WFIFOSET(inter_fd,6);
return 0;
}
// Request a new leader for party
static int intif_party_leaderchange(int party_id, int account_id, int char_id)
{
if (intif->CheckForCharServer())
return 0;
WFIFOHEAD(inter_fd,14);
WFIFOW(inter_fd,0)=0x3029;
WFIFOL(inter_fd,2)=party_id;
WFIFOL(inter_fd,6)=account_id;
WFIFOL(inter_fd,10)=char_id;
WFIFOSET(inter_fd,14);
return 0;
}
//=========================
// Clan System
//-------------------------
/**
* Request clan member count
*
* @param clan_id Id of the clan to have members counted
* @param kick_interval Interval of the inactivity kick
*/
static int intif_clan_membercount(int clan_id, int kick_interval)
{
if (intif->CheckForCharServer() || clan_id == 0 || kick_interval <= 0)
return 0;
WFIFOHEAD(inter_fd, 10);
WFIFOW(inter_fd, 0) = 0x3044;
WFIFOL(inter_fd, 2) = clan_id;
WFIFOL(inter_fd, 6) = kick_interval;
WFIFOSET(inter_fd, 10);
return 1;
}
static int intif_clan_kickoffline(int clan_id, int kick_interval)
{
if (intif->CheckForCharServer() || clan_id == 0 || kick_interval <= 0)
return 0;
WFIFOHEAD(inter_fd, 10);
WFIFOW(inter_fd, 0) = 0x3045;
WFIFOL(inter_fd, 2) = clan_id;
WFIFOL(inter_fd, 6) = kick_interval;
WFIFOSET(inter_fd, 10);
return 1;
}
static void intif_parse_RecvClanMemberAction(int fd)
{
struct clan *c;
int clan_id = RFIFOL(fd, 2);
int count = RFIFOL(fd, 6);
if ((c = clan->search(clan_id)) == NULL) {
ShowError("intif_parse_RecvClanMemberAction: Received invalid clan_id '%d'\n", clan_id);
return;
}
if (count < 0) {
ShowError("intif_parse_RecvClanMemberAction: Received invalid member count value '%d'\n", count);
return;
}
c->received = true;
if (c->req_count_tid != INVALID_TIMER) {
timer->delete(c->req_count_tid, clan->request_membercount);
c->req_count_tid = INVALID_TIMER;
}
c->member_count = count;
switch (c->req_state) {
case CLAN_REQ_AFTER_KICK:
if (c->req_kick_tid != INVALID_TIMER) {
timer->delete(c->req_kick_tid, clan->request_kickoffline);
c->req_kick_tid = INVALID_TIMER;
}
break;
case CLAN_REQ_RELOAD:
map->foreachpc(clan->rejoin);
break;
default:
break;
}
c->req_state = CLAN_REQ_NONE;
}
// Request a Guild creation
static int intif_guild_create(const char *name, const struct guild_member *master)
{
if (intif->CheckForCharServer())
return 0;
nullpo_ret(master);
nullpo_ret(name);
WFIFOHEAD(inter_fd,sizeof(struct guild_member)+(8+NAME_LENGTH));
WFIFOW(inter_fd,0)=0x3030;
WFIFOW(inter_fd,2)=sizeof(struct guild_member)+(8+NAME_LENGTH);
WFIFOL(inter_fd,4)=master->account_id;
memcpy(WFIFOP(inter_fd,8),name,NAME_LENGTH);
memcpy(WFIFOP(inter_fd,8+NAME_LENGTH),master,sizeof(struct guild_member));
WFIFOSET(inter_fd,WFIFOW(inter_fd,2));
return 0;
}
// Request Guild information
static int intif_guild_request_info(int guild_id)
{
if (intif->CheckForCharServer())
return 0;
WFIFOHEAD(inter_fd,6);
WFIFOW(inter_fd,0) = 0x3031;
WFIFOL(inter_fd,2) = guild_id;
WFIFOSET(inter_fd,6);
return 0;
}
// Request to add member to the guild
static int intif_guild_addmember(int guild_id, struct guild_member *m)
{
if (intif->CheckForCharServer())
return 0;
nullpo_ret(m);
WFIFOHEAD(inter_fd,sizeof(struct guild_member)+8);
WFIFOW(inter_fd,0) = 0x3032;
WFIFOW(inter_fd,2) = sizeof(struct guild_member)+8;
WFIFOL(inter_fd,4) = guild_id;
memcpy(WFIFOP(inter_fd,8),m,sizeof(struct guild_member));
WFIFOSET(inter_fd,WFIFOW(inter_fd,2));
return 0;
}
// Request a new leader for guild
static int intif_guild_change_gm(int guild_id, const char *name, int len)
{
if (intif->CheckForCharServer())
return 0;
nullpo_ret(name);
Assert_ret(len > 0 && len < 32000);
WFIFOHEAD(inter_fd, len + 8);
WFIFOW(inter_fd, 0)=0x3033;
WFIFOW(inter_fd, 2)=len+8;
WFIFOL(inter_fd, 4)=guild_id;
memcpy(WFIFOP(inter_fd,8),name,len);
WFIFOSET(inter_fd,len+8);
return 0;
}
// Request to leave guild
static int intif_guild_leave(int guild_id, int account_id, int char_id, int flag, const char *mes)
{
if (intif->CheckForCharServer())
return 0;
nullpo_ret(mes);
WFIFOHEAD(inter_fd, 55);
WFIFOW(inter_fd, 0) = 0x3034;
WFIFOL(inter_fd, 2) = guild_id;
WFIFOL(inter_fd, 6) = account_id;
WFIFOL(inter_fd,10) = char_id;
WFIFOB(inter_fd,14) = flag;
safestrncpy(WFIFOP(inter_fd,15),mes,40);
WFIFOSET(inter_fd,55);
return 0;
}
//Update request / Lv online status of the guild members
static int intif_guild_memberinfoshort(int guild_id, int account_id, int char_id, int online, int lv, int class)
{
if (intif->CheckForCharServer())
return 0;
WFIFOHEAD(inter_fd, 23);
WFIFOW(inter_fd, 0) = 0x3035;
WFIFOL(inter_fd, 2) = guild_id;
WFIFOL(inter_fd, 6) = account_id;
WFIFOL(inter_fd,10) = char_id;
WFIFOB(inter_fd,14) = online;
WFIFOL(inter_fd,15) = lv;
WFIFOL(inter_fd,19) = class;
WFIFOSET(inter_fd,23);
return 0;
}
//Guild disbanded notification
static int intif_guild_break(int guild_id)
{
if (intif->CheckForCharServer())
return 0;
WFIFOHEAD(inter_fd, 6);
WFIFOW(inter_fd, 0) = 0x3036;
WFIFOL(inter_fd, 2) = guild_id;
WFIFOSET(inter_fd,6);
return 0;
}
/**
* Requests to change a basic guild information, it is parsed via mapif_parse_GuildBasicInfoChange
* To see the information types that can be changed see mmo.h::guild_basic_info
**/
static int intif_guild_change_basicinfo(int guild_id, int type, const void *data, int len)
{
if (intif->CheckForCharServer())
return 0;
nullpo_ret(data);
Assert_ret(len >= 0 && len < 32000);
WFIFOHEAD(inter_fd, len + 10);
WFIFOW(inter_fd,0)=0x3039;
WFIFOW(inter_fd,2)=len+10;
WFIFOL(inter_fd,4)=guild_id;
WFIFOW(inter_fd,8)=type;
memcpy(WFIFOP(inter_fd,10),data,len);
WFIFOSET(inter_fd,len+10);
return 0;
}
// Request a change of Guild member information
static int intif_guild_change_memberinfo(int guild_id, int account_id, int char_id, int type, const void *data, int len)
{
if (intif->CheckForCharServer())
return 0;
nullpo_ret(data);
Assert_ret(len >= 0 && len < 32000);
WFIFOHEAD(inter_fd, len + 18);
WFIFOW(inter_fd, 0)=0x303a;
WFIFOW(inter_fd, 2)=len+18;
WFIFOL(inter_fd, 4)=guild_id;
WFIFOL(inter_fd, 8)=account_id;
WFIFOL(inter_fd,12)=char_id;
WFIFOW(inter_fd,16)=type;
memcpy(WFIFOP(inter_fd,18),data,len);
WFIFOSET(inter_fd,len+18);
return 0;
}
/**
* Requests a change of Guild title.
*
* @param guild_id The guild ID.
* @param idx The guild position index.
* @param p The edited guild position data.
* @retval false in case of errors.
*/
static bool intif_guild_position(int guild_id, int idx, struct guild_position *p)
{
if (intif->CheckForCharServer())
return false;
nullpo_ret(p);
WFIFOHEAD(inter_fd, sizeof(struct guild_position)+12);
WFIFOW(inter_fd,0)=0x303b;
WFIFOW(inter_fd,2)=sizeof(struct guild_position)+12;
WFIFOL(inter_fd,4)=guild_id;
WFIFOL(inter_fd,8)=idx;
memcpy(WFIFOP(inter_fd,12),p,sizeof(struct guild_position));
WFIFOSET(inter_fd,WFIFOW(inter_fd,2));
return true;
}
// Request an update of Guildskill skill_id
static int intif_guild_skillup(int guild_id, uint16 skill_id, int account_id, int max)
{
if( intif->CheckForCharServer() )
return 0;
WFIFOHEAD(inter_fd, 18);
WFIFOW(inter_fd, 0) = 0x303c;
WFIFOL(inter_fd, 2) = guild_id;
WFIFOL(inter_fd, 6) = skill_id;
WFIFOL(inter_fd, 10) = account_id;
WFIFOL(inter_fd, 14) = max;
WFIFOSET(inter_fd, 18);
return 0;
}
// Request a new guild relationship
static int intif_guild_alliance(int guild_id1, int guild_id2, int account_id1, int account_id2, int flag)
{
if (intif->CheckForCharServer())
return 0;
WFIFOHEAD(inter_fd,19);
WFIFOW(inter_fd, 0)=0x303d;
WFIFOL(inter_fd, 2)=guild_id1;
WFIFOL(inter_fd, 6)=guild_id2;
WFIFOL(inter_fd,10)=account_id1;
WFIFOL(inter_fd,14)=account_id2;
WFIFOB(inter_fd,18)=flag;
WFIFOSET(inter_fd,19);
return 0;
}
// Request to change guild notice
static int intif_guild_notice(int guild_id, const char *mes1, const char *mes2)
{
if (intif->CheckForCharServer())
return 0;
nullpo_ret(mes1);
nullpo_ret(mes2);
WFIFOHEAD(inter_fd,186);
WFIFOW(inter_fd,0)=0x303e;
WFIFOL(inter_fd,2)=guild_id;
safestrncpy(WFIFOP(inter_fd, 6), mes1, MAX_GUILDMES1);
safestrncpy(WFIFOP(inter_fd, 66), mes2, MAX_GUILDMES2);
WFIFOSET(inter_fd,186);
return 0;
}
// Request to change guild emblem
static int intif_guild_emblem(int guild_id, int data_len, const char *data)
{
nullpo_ret(data);
if (intif->CheckForCharServer())
return 0;
if (guild_id <= 0 || data_len < 0)
return 0;
WFIFO_CHUNKED_INIT(p, inter_fd, HEADER_MAPCHAR_GUILD_EMBLEM, PACKET_MAPCHAR_GUILD_EMBLEM, data, data_len) {
WFIFO_CHUNKED_BLOCK_START(p);
p->guild_id = guild_id;
p->unused = 0;
WFIFO_CHUNKED_BLOCK_END();
}
WFIFO_CHUNKED_FINAL_START(p);
p->guild_id = guild_id;
p->unused = 0;
WFIFO_CHUNKED_FINAL_END();
return 0;
}
/**
* Requests guild castles data from char-server.
* @param num Number of castles, size of castle_ids array.
* @param castle_ids Pointer to array of castle IDs.
*/
static int intif_guild_castle_dataload(int num, int *castle_ids)
{
if (intif->CheckForCharServer())
return 0;
nullpo_ret(castle_ids);
WFIFOHEAD(inter_fd, 4 + num * sizeof(int));
WFIFOW(inter_fd, 0) = 0x3040;
WFIFOW(inter_fd, 2) = 4 + num * sizeof(int);
memcpy(WFIFOP(inter_fd, 4), castle_ids, num * sizeof(int));
WFIFOSET(inter_fd, WFIFOW(inter_fd, 2));
return 1;
}
// Request change castle guild owner and save data
static int intif_guild_castle_datasave(int castle_id, int index, int value)
{
if (intif->CheckForCharServer())
return 0;
WFIFOHEAD(inter_fd,9);
WFIFOW(inter_fd,0)=0x3041;
WFIFOW(inter_fd,2)=castle_id;
WFIFOB(inter_fd,4)=index;
WFIFOL(inter_fd,5)=value;
WFIFOSET(inter_fd,9);
return 1;
}
//-----------------------------------------------------------------
// Homunculus Packets send to Inter server [albator]
//-----------------------------------------------------------------
static int intif_homunculus_create(int account_id, struct s_homunculus *sh)
{
if (intif->CheckForCharServer())
return 0;
nullpo_ret(sh);
WFIFOHEAD(inter_fd, sizeof(struct s_homunculus)+8);
WFIFOW(inter_fd,0) = 0x3090;
WFIFOW(inter_fd,2) = sizeof(struct s_homunculus)+8;
WFIFOL(inter_fd,4) = account_id;
memcpy(WFIFOP(inter_fd,8),sh,sizeof(struct s_homunculus));
WFIFOSET(inter_fd, WFIFOW(inter_fd,2));
return 0;
}
static bool intif_homunculus_requestload(int account_id, int homun_id)
{
if (intif->CheckForCharServer())
return false;
WFIFOHEAD(inter_fd, 10);
WFIFOW(inter_fd,0) = 0x3091;
WFIFOL(inter_fd,2) = account_id;
WFIFOL(inter_fd,6) = homun_id;
WFIFOSET(inter_fd, 10);