/
intif.cpp
3817 lines (3329 loc) · 98.5 KB
/
intif.cpp
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
// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
// For more information, see LICENCE in the main folder
#include "intif.hpp"
#include <stdlib.h>
#include "../common/showmsg.h"
#include "../common/socket.h"
#include "../common/nullpo.h"
#include "../common/malloc.h"
#include "../common/strlib.h"
#include "../common/mmo.h"
#include "../common/timer.h"
#include "map.hpp"
#include "battle.hpp"
#include "chrif.hpp"
#include "clan.hpp"
#include "guild.hpp"
#include "clif.hpp"
#include "pc.hpp"
#include "storage.hpp"
#include "party.hpp"
#include "pet.hpp"
#include "mercenary.hpp"
#include "homunculus.hpp"
#include "elemental.hpp"
#include "mail.hpp"
#include "quest.hpp"
#include "status.hpp"
#include "achievement.hpp"
#include "log.hpp"
/// Received packet Lengths from inter-server
static const int packet_len_table[] = {
-1,-1,27,-1, -1, 0,37,-1, 10+NAME_LENGTH,-1, 0, 0, 0, 0, 0, 0, //0x3800-0x380f
0, 0, 0, 0, 0, 0, 0, 0, -1,11, 0, 0, 0, 0, 0, 0, //0x3810
39,-1,15,15, 15+NAME_LENGTH,19, 7,-1, 0, 0, 0, 0, 0, 0, 0, 0, //0x3820
10,-1,15, 0, 79,19, 7,-1, 0,-1,-1,-1, 14,67,186,-1, //0x3830
-1, 0, 0,18, 0, 0, 0, 0, -1,75,-1,11, 11,-1, 38, 0, //0x3840
-1,-1, 7, 7, 7,11, 8,-1, 0, 0, 0, 0, 0, 0, 0, 0, //0x3850 Auctions [Zephyrus] itembound[Akinari]
-1, 7,-1, 7, 14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //0x3860 Quests [Kevin] [Inkfish] / Achievements [Aleos]
-1, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 3, 3, 0, //0x3870 Mercenaries [Zephyrus] / Elemental [pakpil]
12,-1, 7, 3, 0, 0, 0, 0, 0, 0,-1, 9, -1, 0, 0, 0, //0x3880 Pet System, Storages
-1,-1, 7, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //0x3890 Homunculus [albator]
-1,-1, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //0x38A0 Clans
};
extern int char_fd; // inter server Fd used for char_fd
#define inter_fd char_fd // alias
//-----------------------------------------------------------------
// Send to inter server
/**
* Verify the char-serv is up and running
* @return 0=no, 1=ok
*/
int CheckForCharServer(void)
{
return ((char_fd <= 0) || session[char_fd] == NULL || session[char_fd]->wdata == NULL);
}
/**
* Get sd from pc_db (map_id2db) or auth_db (in case if parsing packet from inter-server when sd not added to pc_db yet)
* @param account_id
* @param char_id
* @return sd Found sd or NULL if not found
*/
struct map_session_data *inter_search_sd(uint32 account_id, uint32 char_id)
{
struct map_session_data *sd = NULL;
struct auth_node *node = chrif_auth_check(account_id, char_id, ST_LOGIN);
if (node)
sd = node->sd;
else
sd = map_id2sd(account_id);
return sd;
}
/**
* Request the char-serv to create a pet (to register it actually)
* @param account_id
* @param char_id
* @param pet_class
* @param pet_lv
* @param pet_egg_id
* @param pet_equip
* @param intimate
* @param hungry
* @param rename_flag
* @param incubate
* @param pet_name
* @return
*/
int intif_create_pet(uint32 account_id,uint32 char_id,short pet_class,short pet_lv, unsigned short pet_egg_id, unsigned short pet_equip,short intimate,short hungry,char rename_flag,char incubate,char *pet_name)
{
if (CheckForCharServer())
return 0;
WFIFOHEAD(inter_fd, 24 + NAME_LENGTH);
WFIFOW(inter_fd,0) = 0x3080;
WFIFOL(inter_fd,2) = account_id;
WFIFOL(inter_fd,6) = char_id;
WFIFOW(inter_fd,10) = pet_class;
WFIFOW(inter_fd,12) = pet_lv;
WFIFOW(inter_fd,14) = pet_egg_id;
WFIFOW(inter_fd,16) = pet_equip;
WFIFOW(inter_fd,18) = intimate;
WFIFOW(inter_fd,20) = hungry;
WFIFOB(inter_fd,22) = rename_flag;
WFIFOB(inter_fd,23) = incubate;
memcpy(WFIFOP(inter_fd,24),pet_name,NAME_LENGTH);
WFIFOSET(inter_fd,24+NAME_LENGTH);
return 1;
}
/**
* Request char-serv to load a pet from persistence (SQL)
* @param account_id
* @param char_id
* @param pet_id
* @return
*/
int intif_request_petdata(uint32 account_id,uint32 char_id,int pet_id)
{
if (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 1;
}
/**
* Request char-serv to save a pet in persistence (SQL)
* @param account_id
* @param p
* @return
*/
int intif_save_petdata(uint32 account_id,struct s_pet *p)
{
if (CheckForCharServer())
return 0;
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 1;
}
/**
* Request char-serv to delete the entry for this pet-char association
* @param pet_id
* @return
*/
int intif_delete_petdata(int pet_id)
{
if (CheckForCharServer())
return 0;
WFIFOHEAD(inter_fd,6);
WFIFOW(inter_fd,0) = 0x3083;
WFIFOL(inter_fd,2) = pet_id;
WFIFOSET(inter_fd,6);
return 1;
}
/**
* Ask char-serv to rename a CHAR (PC|PET|HOM)
* @param sd
* @param type
* @param name
* @return
*/
int intif_rename(struct map_session_data *sd, int type, char *name)
{
if (CheckForCharServer())
return 0;
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 1;
}
/**
* Request to broadcast a message via char-serv to reach all map-serv connected
* @param mes : Message to send
* @param len ; Size of the message
* @param type : Color of msg
* @return 0=error occured, 1=msg sent
*/
int intif_broadcast(const char* mes, int len, int type)
{
int lp = (type|BC_COLOR_MASK) ? 4 : 0;
// Send to the local players
clif_broadcast(NULL, mes, len, type, ALL_CLIENT);
if (CheckForCharServer())
return 0;
if (other_mapserver_count < 1)
return 0; //No need to send.
WFIFOHEAD(inter_fd, 16 + lp + len);
WFIFOW(inter_fd,0) = 0x3000;
WFIFOW(inter_fd,2) = 16 + lp + len;
WFIFOL(inter_fd,4) = 0xFF000000; // 0xFF000000 color signals standard broadcast
WFIFOW(inter_fd,8) = 0; // fontType not used with standard broadcast
WFIFOW(inter_fd,10) = 0; // fontSize not used with standard broadcast
WFIFOW(inter_fd,12) = 0; // fontAlign not used with standard broadcast
WFIFOW(inter_fd,14) = 0; // fontY not used with standard broadcast
if (type|BC_BLUE)
WFIFOL(inter_fd,16) = 0x65756c62; //If there's "blue" at the beginning of the message, game client will display it in blue instead of yellow.
else if (type|BC_WOE)
WFIFOL(inter_fd,16) = 0x73737373; //If there's "ssss", game client will recognize message as 'WoE broadcast'.
memcpy(WFIFOP(inter_fd,16 + lp), mes, len);
WFIFOSET(inter_fd, WFIFOW(inter_fd,2));
return 1;
}
/**
* Request to char-serv to broadcast a message to all map-serv
* @param mes : Message to brodcast
* @param len : Size of message
* @param fontColor : color to display message
* @param fontType :
* @param fontSize :
* @param fontAlign :
* @param fontY :
* @return 0=not send to char-serv, 1=send to char-serv
*/
int intif_broadcast2(const char* mes, int len, unsigned long fontColor, short fontType, short fontSize, short fontAlign, short fontY)
{
// Send to the local players
clif_broadcast2(NULL, mes, len, fontColor, fontType, fontSize, fontAlign, fontY, ALL_CLIENT);
if (CheckForCharServer())
return 0;
if (other_mapserver_count < 1)
return 0; //No need to send.
WFIFOHEAD(inter_fd, 16 + len);
WFIFOW(inter_fd,0) = 0x3000;
WFIFOW(inter_fd,2) = 16 + len;
WFIFOL(inter_fd,4) = fontColor;
WFIFOW(inter_fd,8) = fontType;
WFIFOW(inter_fd,10) = fontSize;
WFIFOW(inter_fd,12) = fontAlign;
WFIFOW(inter_fd,14) = fontY;
memcpy(WFIFOP(inter_fd,16), mes, len);
WFIFOSET(inter_fd, WFIFOW(inter_fd,2));
return 1;
}
/**
* send a message using the main chat system
* @param sd : Player source of message
* @param message : the message to sent
* @return
*/
int intif_main_message(struct map_session_data* sd, const char* message)
{
char output[256];
nullpo_ret(sd);
// format the message for main broadcasting
snprintf( output, sizeof(output), msg_txt(sd,386), sd->status.name, message );
// send the message using the inter-server broadcast service
intif_broadcast2( output, strlen(output) + 1, 0xFE000000, 0, 0, 0, 0 );
// log the chat message
log_chat( LOG_CHAT_MAINCHAT, 0, sd->status.char_id, sd->status.account_id, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, NULL, message );
return 1;
}
/**
* Request char-serv to transmit a whisper message. (Private message from one player to another)
* (player not found on this server)
* @param sd : Player ending message
* @param nick : Name of receiver
* @param mes : Message to send
* @param mes_len : Size of message
* @return 0=Message not send, 1=Message send
*/
int intif_wis_message(struct map_session_data *sd, char *nick, char *mes, int mes_len)
{
nullpo_ret(sd);
if (CheckForCharServer())
return 0;
if (other_mapserver_count < 1)
{ //Character not found.
clif_wis_end(sd->fd, 1);
return 0;
}
WFIFOHEAD(inter_fd,mes_len + 52);
WFIFOW(inter_fd,0) = 0x3001;
WFIFOW(inter_fd,2) = mes_len + 52;
memcpy(WFIFOP(inter_fd,4), sd->status.name, NAME_LENGTH);
memcpy(WFIFOP(inter_fd,4+NAME_LENGTH), nick, NAME_LENGTH);
memcpy(WFIFOP(inter_fd,4+2*NAME_LENGTH), mes, mes_len);
WFIFOSET(inter_fd, WFIFOW(inter_fd,2));
if (battle_config.etc_log)
ShowInfo("intif_wis_message from %s to %s (message: '%s')\n", sd->status.name, nick, mes);
return 1;
}
/**
* Inform the char-serv of the result of the whisper
* @param id : Character ID
* @param flag : 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target
* @return 0=no char-serv connected, 1=msg sent
*/
int intif_wis_replay(int id, int flag)
{
if (CheckForCharServer())
return 0;
WFIFOHEAD(inter_fd,7);
WFIFOW(inter_fd,0) = 0x3002;
WFIFOL(inter_fd,2) = id;
WFIFOB(inter_fd,6) = flag; // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target
WFIFOSET(inter_fd,7);
if (battle_config.etc_log)
ShowInfo("intif_wis_replay: id: %d, flag:%d\n", id, flag);
return 1;
}
/**
* Whisper message from player to all GM from map-server to inter-server (@request)
* @param wisp_name
* @param permission
* @param mes
* @return 0:no char-serv connected, 1:transfered
*/
int intif_wis_message_to_gm(char *wisp_name, int permission, char *mes)
{
int mes_len;
if (CheckForCharServer())
return 0;
mes_len = strlen(mes) + 1; // + null
WFIFOHEAD(inter_fd, mes_len + 8 + NAME_LENGTH);
WFIFOW(inter_fd,0) = 0x3003;
WFIFOW(inter_fd,2) = mes_len + 32;
memcpy(WFIFOP(inter_fd,4), wisp_name, NAME_LENGTH);
WFIFOL(inter_fd,4+NAME_LENGTH) = permission;
memcpy(WFIFOP(inter_fd,8+NAME_LENGTH), mes, mes_len);
WFIFOSET(inter_fd, WFIFOW(inter_fd,2));
if (battle_config.etc_log)
ShowNotice("intif_wis_message_to_gm: from: '%s', required permission: %d, message: '%s'.\n", wisp_name, permission, mes);
return 1;
}
/**
* Request for saving registry values.
* @param sd : Player to save registry
* @return 1=msg sent, -1=error
*/
int intif_saveregistry(struct map_session_data *sd)
{
DBIterator *iter;
DBKey key;
DBData *data;
int plen = 0;
size_t len;
if (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;
bool lValid = false;
if( data->type != DB_DATA_PTR ) // it's a @number
continue;
varname = get_str(script_getvarid(key.i64));
if( varname[0] == '@' ) // @string$ can get here, so we skip
continue;
src = (struct script_reg_state *)db_data2ptr(data);
if( !src->update )
continue;
src->update = false;
lValid = script_check_RegistryVariableLength(0,varname,&len);
++len;
if (!lValid) { //this is sql colum size, must be retrive from config
ShowError("intif_saveregistry: Variable name length is too long (aid: %d, cid: %d): '%s' sz=%d\n", sd->status.account_id, sd->status.char_id, varname, len);
continue;
}
WFIFOB(inter_fd, plen) = (unsigned char)len; // won't be higher; the column size is 32
plen += 1;
safestrncpy(WFIFOCP(inter_fd,plen), varname, len); //the key
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; //var type
plen += 1;
if( p->value ) {
lValid = script_check_RegistryVariableLength(1,p->value,&len);
++len;
if ( !lValid ) { // error can't be higher; the column size is 254. (nb the transmission limit with be fixed with protobuf revamp)
ShowDebug( "intif_saveregistry: Variable value length is too long (aid: %d, cid: %d): '%s' sz=%d to be saved with current system and will be truncated\n",sd->status.account_id, sd->status.char_id,p->value,len);
len = 254;
p->value[len - 1] = '\0'; //this is backward for old char-serv but new one doesn't need this
}
WFIFOB(inter_fd, plen) = (uint8)len;
plen += 1;
safestrncpy(WFIFOCP(inter_fd,plen), p->value, len);
plen += len;
} 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);
WFIFOW(inter_fd, 2) = plen;
WFIFOSET(inter_fd, plen);
sd->vars_dirty = false;
return 0;
}
/**
* Request the registries for this player.
* @param sd : Player to load registry
* @param flag : Type of registry to load, &1=acc (login-serv), &2=acc (char-serv), &4=char
* @return
*/
int intif_request_registry(struct map_session_data *sd, int flag)
{
nullpo_ret(sd);
if (CheckForCharServer())
return 0;
WFIFOHEAD(inter_fd,13);
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 (from login-serv))
WFIFOB(inter_fd,11) = (flag&2?1:0); //Request Acc Reg (from char-serv)
WFIFOB(inter_fd,12) = (flag&4?1:0); //Request Char Reg
WFIFOSET(inter_fd,13);
return 1;
}
/**
* Request to load guild storage from char-serv
* @param account_id: Player account identification
* @param guild_id: Guild of player
* @return false - error, true - message sent
*/
bool intif_request_guild_storage(uint32 account_id, int guild_id)
{
if (CheckForCharServer())
return false;
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 true;
}
/**
* Request to save guild storage
* @param account_id: account requesting the save
* @param gstor: Guild storage struct to save
* @return false - error, true - message sent
*/
bool intif_send_guild_storage(uint32 account_id, struct s_storage *gstor)
{
if (CheckForCharServer())
return false;
WFIFOHEAD(inter_fd,sizeof(struct s_storage)+12);
WFIFOW(inter_fd,0) = 0x3019;
WFIFOW(inter_fd,2) = (unsigned short)sizeof(struct s_storage)+12;
WFIFOL(inter_fd,4) = account_id;
WFIFOL(inter_fd,8) = gstor->id;
memcpy( WFIFOP(inter_fd,12),gstor, sizeof(struct s_storage) );
WFIFOSET(inter_fd,WFIFOW(inter_fd,2));
return true;
}
/**
* Party creation request
* @param member : Struct of 1 party member
* @param name : Party name
* @param item : item pickup rule
* @param item2 : item share rule
* @return 0=error, 1=msg sent
*/
int intif_create_party(struct party_member *member,char *name,int item,int item2)
{
if (CheckForCharServer())
return 0;
nullpo_ret(member);
WFIFOHEAD(inter_fd, 6+NAME_LENGTH+sizeof(struct party_member));
WFIFOW(inter_fd,0) = 0x3020;
WFIFOW(inter_fd,2) = 6+NAME_LENGTH+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 1;
}
/**
* Party information request
* @param party_id : Party id to request info
* @param char_id : Player id requesting
* @return 0=error, 1=msg sent
*/
int intif_request_partyinfo(int party_id, uint32 char_id)
{
if (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 1;
}
/**
* Request to add a member to party
* @param party_id : Party to add member to
* @param member : member to add to party
* @return
*/
int intif_party_addmember(int party_id,struct party_member *member)
{
if (CheckForCharServer())
return 0;
WFIFOHEAD(inter_fd,8+sizeof(struct party_member));
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)
* @param party_id : Party to alter
* @param account_id : account requesting change
* @param exp : sharing exp option
* @param item : sharing item option
* @return 0=error, 1=msg sent
*/
int intif_party_changeoption(int party_id,uint32 account_id,int exp,int item)
{
if (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 1;
}
/**
* Ask the char-serv to make aid,cid quit party
* @param party_id : Party to leave
* @param account_id : aid of player to leave
* @param char_id : cid of player to leave
* @return 0:char-serv disconected, 1=msg sent
*/
int intif_party_leave(int party_id, uint32 account_id, uint32 char_id, const char *name, enum e_party_member_withdraw type)
{
if (CheckForCharServer())
return 0;
WFIFOHEAD(inter_fd,15+NAME_LENGTH);
WFIFOW(inter_fd,0) = 0x3024;
WFIFOL(inter_fd,2) = party_id;
WFIFOL(inter_fd,6) = account_id;
WFIFOL(inter_fd,10) = char_id;
memcpy(WFIFOCP(inter_fd,14), name, NAME_LENGTH);
WFIFOB(inter_fd,14+NAME_LENGTH) = type;
WFIFOSET(inter_fd,15+NAME_LENGTH);
return 1;
}
/**
* Inform char-serv that a member as quit/lvlup change map, therefore changing party state
* @param sd : Player that moved
* @param online : If the player will stay online or no
* @return 0=error, 1=msg sent
*/
int intif_party_changemap(struct map_session_data *sd,int online)
{
int16 m, mapindex;
if (CheckForCharServer())
return 0;
if(!sd)
return 0;
if( (m=map_mapindex2mapid(sd->mapindex)) >= 0 && map[m].instance_id )
mapindex = map[map[m].instance_src_map].index;
else
mapindex = 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)=mapindex;
WFIFOB(inter_fd,16)=online;
WFIFOW(inter_fd,17)=sd->status.base_level;
WFIFOSET(inter_fd,19);
return 1;
}
/**
* Request breaking party
* @param party_id : Party to delete
* @return 0=error, 1=msg sent
*/
int intif_break_party(int party_id)
{
if (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 sending party chat
* (we using this in case we have multiple map-serv attached
* to be sure all party get the message)
* @param party_id : Party identification
* @param account_id : Player sending the message
* @param mes : Message to send
* @param len : Size of the message
* @return 0=error, 1=msg sent
*/
int intif_party_message(int party_id,uint32 account_id,const char *mes,int len)
{
if (CheckForCharServer())
return 0;
if (other_mapserver_count < 1)
return 0; //No need to send.
WFIFOHEAD(inter_fd,len + 12);
WFIFOW(inter_fd,0)=0x3027;
WFIFOW(inter_fd,2)=len+12;
WFIFOL(inter_fd,4)=party_id;
WFIFOL(inter_fd,8)=account_id;
memcpy(WFIFOP(inter_fd,12),mes,len);
WFIFOSET(inter_fd,len+12);
return 1;
}
/**
* Request a new leader for party
* @param party_id : Party to alter
* @param account_id : player to set as new leader
* @param char_id : player to set as new leader
* @return 0=error, 1=msg sent
*/
int intif_party_leaderchange(int party_id,uint32 account_id,uint32 char_id)
{
if (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 1;
}
/**
* Request to update party share level
* @param share_lvl : Max level number of difference to share exp
* @return 0=error, 1=msg sent
*/
int intif_party_sharelvlupdate(unsigned int share_lvl)
{
if (CheckForCharServer())
return 0;
WFIFOHEAD(inter_fd,6);
WFIFOW(inter_fd,0)=0x302A;
WFIFOL(inter_fd,2)=share_lvl;
WFIFOSET(inter_fd,6);
return 1;
}
/**
* Request a Guild creation
* @param name : Name of the guild
* @param master : Guild_member info of master
* @return 0=error, 1=msg_sent
*/
int intif_guild_create(const char *name,const struct guild_member *master)
{
if (CheckForCharServer())
return 0;
nullpo_ret(master);
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 1;
}
/**
* Request Guild information
* @param guild_id : guild to get info from
* @return 0=error, 1=msg_sent
*/
int intif_guild_request_info(int guild_id)
{
if (CheckForCharServer())
return 0;
WFIFOHEAD(inter_fd,6);
WFIFOW(inter_fd,0) = 0x3031;
WFIFOL(inter_fd,2) = guild_id;
WFIFOSET(inter_fd,6);
return 1;
}
/**
* Request to add member to the guild
* @param guild_id : Guild to alter
* @param m : Member to add to the guild
* @return 0=error, 1=msg_sent
*/
int intif_guild_addmember(int guild_id,struct guild_member *m)
{
if (CheckForCharServer())
return 0;
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 1;
}
/**
* Request a new leader for guild
* @param guild_id : guild to alter
* @param name : name of the new master
* @param len : size of the name
* @return 0=error, 1=msg_sent
*/
int intif_guild_change_gm(int guild_id, const char* name, int len)
{
if (CheckForCharServer())
return 0;
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 1;
}
/**
* Request to make a player leave a guild
* @param guild_id : guild to alter
* @param account_id : player aid to kick
* @param char_id : player cid to kick
* @param flag : 0:normal quit, 1=expulsion
* @param mes : quitting message (max 40)
* @return 0=error, 1=msg_sent
*/
int intif_guild_leave(int guild_id,uint32 account_id,uint32 char_id,int flag,const char *mes)
{
if (CheckForCharServer())
return 0;
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(WFIFOCP(inter_fd,15),mes,40);
WFIFOSET(inter_fd,55);
return 1;
}
/**
* Update request / Lv online status of the guild members
* @param guild_id : guild to alter
* @param account_id : player aid to alter
* @param char_id : player cid to alter
* @param online : does the player is online (or will stay online)
* @param lv : player lv
* @param class_ : player class
* @return 0=error, 1=msg_sent
*/
int intif_guild_memberinfoshort(int guild_id,uint32 account_id,uint32 char_id,int online,int lv,int class_)
{
if (CheckForCharServer())
return 0;
WFIFOHEAD(inter_fd, 19);
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;
WFIFOW(inter_fd,15) = lv;
WFIFOW(inter_fd,17) = class_;
WFIFOSET(inter_fd,19);
return 1;
}
/**
* Guild disbanded notification
* @param guild_id : guild to disband
* @return 0=error, 1=msg_sent
*/
int intif_guild_break(int guild_id)
{
if (CheckForCharServer())
return 0;
WFIFOHEAD(inter_fd, 6);
WFIFOW(inter_fd, 0) = 0x3036;
WFIFOL(inter_fd, 2) = guild_id;
WFIFOSET(inter_fd,6);
return 1;
}
/**
* Send a guild message
* (This is goign throught char-serv in case of multi-map setup)
* @param guild_id : Guild id to send the message to
* @param account_id : Player sending the msg
* @param mes : Message to send
* @param len : Size of the message
* @return 0=error, 1=msg_sent
*/
int intif_guild_message(int guild_id,uint32 account_id,const char *mes,int len)
{
if (CheckForCharServer())
return 0;
if (other_mapserver_count < 1)
return 0; //No need to send.
WFIFOHEAD(inter_fd, len + 12);
WFIFOW(inter_fd,0)=0x3037;
WFIFOW(inter_fd,2)=len+12;
WFIFOL(inter_fd,4)=guild_id;
WFIFOL(inter_fd,8)=account_id;
memcpy(WFIFOP(inter_fd,12),mes,len);
WFIFOSET(inter_fd,len+12);
return 1;
}
/**
* Request a change of Guild basic information
* @param guild_id : Guild to alter
* @param type : type of data to change (currently only guildlv)
* @param data : new value for type
* @param len : size of data
* @return 0=error, 1=msg_sent
*/
int intif_guild_change_basicinfo(int guild_id,int type,const void *data,int len)
{
if (CheckForCharServer())
return 0;
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 1;
}
/**
* Request a change of Guild member information
* @param guild_id : Guild to alter
* @param account_id : Player aid to alter
* @param char_id : Player cid to alter
* @param type : Type of modification
* @param data : Value of modification
* @param len : Size of value
* @return 0=error, 1=msg_sent
*/
int intif_guild_change_memberinfo(int guild_id,uint32 account_id,uint32 char_id,
int type,const void *data,int len)
{
if (CheckForCharServer())
return 0;
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;