-
Notifications
You must be signed in to change notification settings - Fork 107
/
clif.c
16552 lines (14463 loc) · 439 KB
/
clif.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
// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
// For more information, see LICENCE in the main folder
#include "../common/cbasetypes.h"
#include "../common/socket.h"
#include "../common/timer.h"
#include "../common/malloc.h"
#include "../common/version.h"
#include "../common/nullpo.h"
#include "../common/showmsg.h"
#include "../common/strlib.h"
#include "../common/utils.h"
#include "../common/harmony.h"
#include "map.h"
#include "chrif.h"
#include "pc.h"
#include "status.h"
#include "npc.h"
#include "itemdb.h"
#include "channel.h"
#include "chat.h"
#include "trade.h"
#include "storage.h"
#include "script.h"
#include "skill.h"
#include "atcommand.h"
#include "intif.h"
#include "battle.h"
#include "battleground.h"
#include "mob.h"
#include "party.h"
#include "unit.h"
#include "guild.h"
#include "vending.h"
#include "buying.h"
#include "pet.h"
#include "homunculus.h"
#include "instance.h"
#include "mercenary.h"
#include "elemental.h"
#include "log.h"
#include "clif.h"
#include "mail.h"
#include "quest.h"
#include "harmony.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <time.h>
#define DUMP_UNKNOWN_PACKET 0
struct Clif_Config {
int packet_db_ver; //Preferred packet version.
int connect_cmd[MAX_PACKET_VER + 1]; //Store the connect command for all versions. [Skotlex]
} clif_config;
struct s_packet_db packet_db[MAX_PACKET_VER + 1][MAX_PACKET_DB + 1];
//Converts item type in case of pet eggs.
#define itemtype(a) (a == IT_PETEGG)?IT_WEAPON:a
#define WBUFPOS(p,pos,x,y,dir) \
do { \
uint8 *__p = (p); \
__p+=(pos); \
__p[0] = (uint8)((x)>>2); \
__p[1] = (uint8)(((x)<<6) | (((y)>>4)&0x3f)); \
__p[2] = (uint8)(((y)<<4) | ((dir)&0xf)); \
} while(0)
// client-side: x0+=sx0*0.0625-0.5 and y0+=sy0*0.0625-0.5
#define WBUFPOS2(p,pos,x0,y0,x1,y1,sx0,sy0) \
do { \
uint8 *__p = (p); \
__p+=(pos); \
__p[0]=(uint8)((x0)>>2); \
__p[1]=(uint8)(((x0)<<6) | (((y0)>>4)&0x3f)); \
__p[2]=(uint8)(((y0)<<4) | (((x1)>>6)&0x0f)); \
__p[3]=(uint8)(((x1)<<2) | (((y1)>>8)&0x03)); \
__p[4]=(uint8)(y1); \
__p[5]=(uint8)(((sx0)<<4) | ((sy0)&0x0f)); \
} while(0)
#define WFIFOPOS(fd,pos,x,y,dir) WBUFPOS(WFIFOP(fd,pos),0,x,y,dir)
#define WFIFOPOS2(fd,pos,x0,y0,x1,y1,sx0,sy0) WBUFPOS2(WFIFOP(fd,pos),0,x0,y0,x1,y1,sx0,sy0)
//To idenfity disguised characters.
#define disguised(bl) ((bl)->type==BL_PC && ((TBL_PC*)bl)->disguise)
//Guarantees that the given string does not exceeds the allowed size, as well as making sure it's null terminated. [Skotlex\]
#define mes_len_check(mes, len, max) if (len > max) { mes[max-1] = '\0'; len = max; } else mes[len-1] = '\0';
static char map_ip_str[128];
static uint32 map_ip;
static uint32 bind_ip = INADDR_ANY;
static uint16 map_port = 5121;
int map_fd;
int clif_parse (int fd);
/*==========================================
* @aura
*------------------------------------------*/
static int auraTable[][3] = {
{ -1, -1, -1 },
// Reserved for PK Mode
{ 586, -1, -1 }, // LH
{ 586, 362, -1 }, // LH Mvp
{ 586, 362, 240 }, // 1コ PK Place
// Basic Auras
{ 418, -1, -1 }, // Red Fury
{ 486, -1, -1 }, // Blue Fury
{ 485, -1, -1 }, // White Fury
{ 239, -1, -1 }, // Aura Red
{ 240, -1, -1 }, // Aura White
{ 241, -1, -1 }, // Aura Yellow
{ 620, -1, -1 }, // Aura Blue
{ 202, -1, -1 }, // Lvl 99 Bubbles
{ 362, -1, -1 }, // Advanced Lvl 99 Bubbles
{ 678, -1, -1 }, // Brazil Aura Bubbles
{ 679, -1, -1 }, // Brazil Aura
{ 680, -1, -1 }, // Brazil Aura Floor
// 2 Sets
{ 239, 418, -1 },
{ 239, 486, -1 },
{ 239, 485, -1 },
{ 240, 418, -1 },
{ 240, 486, -1 },
{ 240, 485, -1 },
{ 241, 418, -1 },
{ 241, 486, -1 },
{ 241, 485, -1 },
{ 620, 418, -1 },
{ 620, 486, -1 },
{ 620, 485, -1 },
// Full Sets
{ 239, 418, 202 },
{ 239, 486, 202 },
{ 239, 485, 202 },
{ 240, 418, 202 },
{ 240, 486, 202 },
{ 240, 485, 202 },
{ 241, 418, 202 },
{ 241, 486, 202 },
{ 241, 485, 202 },
{ 620, 418, 202 },
{ 620, 486, 202 },
{ 620, 485, 202 },
{ 239, 418, 362 },
{ 239, 486, 362 },
{ 239, 485, 362 },
{ 240, 418, 362 },
{ 240, 486, 362 },
{ 240, 485, 362 },
{ 241, 418, 362 },
{ 241, 486, 362 },
{ 241, 485, 362 },
{ 620, 418, 362 },
{ 620, 486, 362 },
{ 620, 485, 362 },
{ 239, 418, 678 },
{ 239, 486, 678 },
{ 239, 485, 678 },
{ 240, 418, 678 },
{ 240, 486, 678 },
{ 240, 485, 678 },
{ 241, 418, 678 },
{ 241, 486, 678 },
{ 241, 485, 678 },
{ 620, 418, 678 },
{ 620, 486, 678 },
{ 620, 485, 678 },
// Oficial Set
{ 680, 679, 678 },
{ -1, -1, -1 }
};
int aura_getSize()
{
return sizeof(auraTable)/(sizeof(int) * 3) - 1;
}
int aura_getAuraEffect(struct map_session_data *sd, short pos)
{
int aura = sd->state.view_aura;
if( pos < 0 || pos > 2 )
return -1;
if( aura > aura_getSize() || aura < 0 )
return -1;
return auraTable[aura][pos];
}
void clif_sendaurastoone(struct map_session_data *sd, struct map_session_data *dsd)
{
int effect1, effect2, effect3;
if( pc_ishiding(sd) || map_flag_vs(sd->bl.m) )
return;
effect1 = aura_getAuraEffect(sd,0);
effect2 = aura_getAuraEffect(sd,1);
effect3 = aura_getAuraEffect(sd,2);
if( effect1 >= 0 )
clif_specialeffect_single(&sd->bl,effect1,dsd->fd);
if( effect2 >= 0 )
clif_specialeffect_single(&sd->bl,effect2,dsd->fd);
if( effect3 >= 0 )
clif_specialeffect_single(&sd->bl,effect3,dsd->fd);
}
void clif_sendauras(struct map_session_data *sd, enum send_target type)
{
int effect1, effect2, effect3;
if( pc_ishiding(sd) || map_flag_vs(sd->bl.m) )
return;
effect1 = aura_getAuraEffect(sd,0);
effect2 = aura_getAuraEffect(sd,1);
effect3 = aura_getAuraEffect(sd,2);
if( effect1 >= 0 )
clif_specialeffect(&sd->bl,effect1,type);
if( effect2 >= 0 )
clif_specialeffect(&sd->bl,effect2,type);
if( effect3 >= 0 )
clif_specialeffect(&sd->bl,effect3,type);
}
/*==========================================
* map鯖のip設定
*------------------------------------------*/
int clif_setip(const char* ip)
{
char ip_str[16];
map_ip = host2ip(ip);
if (!map_ip) {
ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
return 0;
}
strncpy(map_ip_str, ip, sizeof(map_ip_str));
ShowInfo("Map Server IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(map_ip, ip_str));
return 1;
}
void clif_setbindip(const char* ip)
{
char ip_str[16];
bind_ip = host2ip(ip);
if (bind_ip) {
ShowInfo("Map Server Bind IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(bind_ip, ip_str));
} else {
ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
}
}
/*==========================================
* map鯖のport設定
*------------------------------------------*/
void clif_setport(uint16 port)
{
map_port = port;
}
/*==========================================
* map鯖のip読み出し
*------------------------------------------*/
uint32 clif_getip(void)
{
return map_ip;
}
//Refreshes map_server ip, returns the new ip if the ip changed, otherwise it returns 0.
uint32 clif_refresh_ip(void)
{
uint32 new_ip;
new_ip = host2ip(map_ip_str);
if (new_ip && new_ip != map_ip) {
map_ip = new_ip;
ShowInfo("Updating IP resolution of [%s].\n", map_ip_str);
return map_ip;
}
return 0;
}
/*==========================================
* map鯖のport読み出し
*------------------------------------------*/
uint16 clif_getport(void)
{
return map_port;
}
#if PACKETVER >= 20071106
static inline unsigned char clif_bl_type(struct block_list *bl) {
switch (bl->type) {
case BL_PC: return disguised(bl)?0x1:0x0; //PC_TYPE
case BL_ITEM: return 0x2; //ITEM_TYPE
case BL_SKILL: return 0x3; //SKILL_TYPE
case BL_CHAT: return 0x4; //UNKNOWN_TYPE
case BL_MOB: return pcdb_checkid(((TBL_MOB*)bl)->vd->class_)?0x0:0x5; //NPC_MOB_TYPE
case BL_NPC: return 0x6; //NPC_EVT_TYPE
case BL_PET: return 0x7; //NPC_PET_TYPE
case BL_HOM: return 0x8; //NPC_HOM_TYPE
case BL_MER: return 0x9; //NPC_MERSOL_TYPE
case BL_ELEM: return 0xa; //NPC_ELEMENTAL_TYPE
default: return 0x1; //NPC_TYPE
}
}
#endif
// msgstringtable.txt
// This message must be normalized
// using "unsigned char msg[a][b]"
// so that it can be displayed correctly.
void clif_msgtable(int fd, int line)
{
int a,b;
b = line / 255;
a = line - ( b * 255 ) - b;
WFIFOHEAD(fd, packet_len(0x291));
WFIFOW(fd, 0) = 0x291;
WFIFOB(fd, 2) = a;
WFIFOB(fd, 3) = b;
WFIFOSET(fd, packet_len(0x291));
}
// msgstringtable.txt
// This message must be normalized
// using "unsigned char msg[a][b]"
// so that it can be displayed correctly.
void clif_msgtable_num(int fd, int line, int num)
{
#if PACKETVER >= 20090805
int a,b;
b = line / 255;
a = line - ( b * 255 ) - b;
WFIFOHEAD(fd, packet_len(0x7e2));
WFIFOW(fd, 0) = 0x7e2;
WFIFOB(fd, 2) = a;
WFIFOB(fd, 3) = b;
WFIFOL(fd, 4) = num;
WFIFOSET(fd, packet_len(0x7e2));
#endif
}
/*==========================================
* clif_sendでAREA*指定時用
*------------------------------------------*/
int clif_send_sub(struct block_list *bl, va_list ap)
{
struct block_list *src_bl;
struct map_session_data *sd;
unsigned char *buf;
int len, type, fd;
nullpo_retr(0, bl);
nullpo_retr(0, sd = (struct map_session_data *)bl);
fd = sd->fd;
if (!fd) //Don't send to disconnected clients.
return 0;
buf = va_arg(ap,unsigned char*);
len = va_arg(ap,int);
nullpo_retr(0, src_bl = va_arg(ap,struct block_list*));
type = va_arg(ap,int);
switch(type)
{
case AREA:
if( RBUFW(buf,0) == 0x01c8 && (map[sd->bl.m].flag.gvg || map[sd->bl.m].flag.battleground) && bl != src_bl && sd->state.packet_filter&2 )
return 0; // Ignore other player's item usage
break;
case AREA_WOS:
if (bl == src_bl)
return 0;
break;
case AREA_WOC:
if (sd->chatID || bl == src_bl)
return 0;
if( RBUFW(buf,0) == 0x008d && (map[sd->bl.m].flag.gvg || map[sd->bl.m].flag.battleground) && sd->state.packet_filter&1 )
return 0;
break;
case AREA_WOSC:
{
struct map_session_data *ssd = (struct map_session_data *)src_bl;
if (ssd && (src_bl->type == BL_PC) && sd->chatID && (sd->chatID == ssd->chatID))
return 0;
}
break;
case AREA_IWOS:
if( bl == src_bl )
return 0;
case AREA_IWS:
if( bl != src_bl && !sd->special_state.intravision && !sd->sc.data[SC_INTRAVISION] )
return 0;
break;
case AREA_WOI:
if( bl == src_bl || sd->special_state.intravision || sd->sc.data[SC_INTRAVISION] )
return 0;
break;
}
if (session[fd] == NULL)
return 0;
WFIFOHEAD(fd, len);
if (WFIFOP(fd,0) == buf) {
ShowError("WARNING: Invalid use of clif_send function\n");
ShowError(" Packet x%4x use a WFIFO of a player instead of to use a buffer.\n", WBUFW(buf,0));
ShowError(" Please correct your code.\n");
// don't send to not move the pointer of the packet for next sessions in the loop
//WFIFOSET(fd,0);//## TODO is this ok?
//NO. It is not ok. There is the chance WFIFOSET actually sends the buffer data, and shifts elements around, which will corrupt the buffer.
return 0;
}
if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
memcpy(WFIFOP(fd,0), buf, len);
WFIFOSET(fd,len);
}
return 0;
}
/*==========================================
*
*------------------------------------------*/
int clif_send(const uint8* buf, int len, struct block_list* bl, enum send_target type)
{
int i;
struct map_session_data *sd, *tsd;
struct party_data *p = NULL;
struct guild *g = NULL;
struct battleground_data *bg = NULL;
int x0 = 0, x1 = 0, y0 = 0, y1 = 0, fd;
struct s_mapiterator* iter;
if( type != ALL_CLIENT )
nullpo_retr(0, bl);
if( type == ALL_REGION && map[bl->m].region < 1 )
return 0; // Not on a Region
sd = BL_CAST(BL_PC, bl);
switch(type) {
case ALL_CLIENT: //All player clients.
iter = mapit_getallusers();
while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
{
if( packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
{ // packet must exist for the client version
WFIFOHEAD(tsd->fd, len);
memcpy(WFIFOP(tsd->fd,0), buf, len);
WFIFOSET(tsd->fd,len);
}
}
mapit_free(iter);
break;
case ALL_SAMEMAP: //All players on the same map
case ALL_REGION: // All players on the same region
iter = mapit_getallusers();
while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
{
if( ((type == ALL_SAMEMAP && tsd->bl.m == bl->m) || (type == ALL_REGION && map[tsd->bl.m].region == map[bl->m].region)) && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
{ // packet must exist for the client version
WFIFOHEAD(tsd->fd, len);
memcpy(WFIFOP(tsd->fd,0), buf, len);
WFIFOSET(tsd->fd,len);
}
}
mapit_free(iter);
break;
case AREA:
case AREA_WOSC:
if (sd && bl->prev == NULL) //Otherwise source misses the packet.[Skotlex]
clif_send (buf, len, bl, SELF);
case AREA_WOC:
case AREA_WOS:
map_foreachinarea(clif_send_sub, bl->m, bl->x-AREA_SIZE, bl->y-AREA_SIZE, bl->x+AREA_SIZE, bl->y+AREA_SIZE,
BL_PC, buf, len, bl, type);
break;
case AREA_CHAT_WOC:
map_foreachinarea(clif_send_sub, bl->m, bl->x-(AREA_SIZE-5), bl->y-(AREA_SIZE-5),
bl->x+(AREA_SIZE-5), bl->y+(AREA_SIZE-5), BL_PC, buf, len, bl, AREA_WOC);
break;
case AREA_IWS:
case AREA_IWOS:
case AREA_WOI:
map_foreachinarea(clif_send_sub, bl->m, bl->x-AREA_SIZE, bl->y-AREA_SIZE, bl->x+AREA_SIZE, bl->y+AREA_SIZE,
BL_PC, buf, len, bl, type);
break;
case CHAT:
case CHAT_WOS:
{
struct chat_data *cd;
if (sd) {
cd = (struct chat_data*)map_id2bl(sd->chatID);
} else if (bl->type == BL_CHAT) {
cd = (struct chat_data*)bl;
} else break;
if (cd == NULL)
break;
for(i = 0; i < cd->users; i++) {
if (type == CHAT_WOS && cd->usersd[i] == sd)
continue;
if (packet_db[cd->usersd[i]->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
if ((fd=cd->usersd[i]->fd) >0 && session[fd]) // Added check to see if session exists [PoW]
{
WFIFOHEAD(fd,len);
memcpy(WFIFOP(fd,0), buf, len);
WFIFOSET(fd,len);
}
}
}
}
break;
case PARTY_AREA:
case PARTY_AREA_WOS:
x0 = bl->x - AREA_SIZE;
y0 = bl->y - AREA_SIZE;
x1 = bl->x + AREA_SIZE;
y1 = bl->y + AREA_SIZE;
case PARTY:
case PARTY_WOS:
case PARTY_SAMEMAP:
case PARTY_SAMEMAP_WOS:
case PARTY_BUFF_INFO:
if( sd && sd->status.party_id )
p = party_search(sd->status.party_id);
if( p )
{
for( i = 0; i < MAX_PARTY; i++ )
{
if( (sd = p->data[i].sd) == NULL )
continue;
if( !(fd = sd->fd) )
continue;
if( sd->bl.id == bl->id && (type == PARTY_WOS || type == PARTY_SAMEMAP_WOS || type == PARTY_AREA_WOS) )
continue;
if( type != PARTY_BUFF_INFO && type != PARTY && type != PARTY_WOS && bl->m != sd->bl.m )
continue;
if( (type == PARTY_AREA || type == PARTY_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
continue;
if( type == PARTY_BUFF_INFO && !sd->state.spb )
continue;
if( packet_db[sd->packet_ver][RBUFW(buf,0)].len )
{ // packet must exist for the client version
WFIFOHEAD(fd,len);
memcpy(WFIFOP(fd,0), buf, len);
WFIFOSET(fd,len);
}
}
if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
break;
iter = mapit_getallusers();
while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
{
if( tsd->partyspy == p->party.party_id && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
{ // packet must exist for the client version
WFIFOHEAD(tsd->fd, len);
memcpy(WFIFOP(tsd->fd,0), buf, len);
WFIFOSET(tsd->fd,len);
}
}
mapit_free(iter);
}
break;
case DUEL:
case DUEL_WOS:
if (!sd || !sd->duel_group) break; //Invalid usage.
iter = mapit_getallusers();
while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
{
if( type == DUEL_WOS && bl->id == tsd->bl.id )
continue;
if( sd->duel_group == tsd->duel_group && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
{ // packet must exist for the client version
WFIFOHEAD(tsd->fd, len);
memcpy(WFIFOP(tsd->fd,0), buf, len);
WFIFOSET(tsd->fd,len);
}
}
mapit_free(iter);
break;
case SELF:
if (sd && (fd=sd->fd) && packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
WFIFOHEAD(fd,len);
memcpy(WFIFOP(fd,0), buf, len);
WFIFOSET(fd,len);
}
break;
// New definitions for guilds [Valaris] - Cleaned up and reorganized by [Skotlex]
case GUILD_AREA:
case GUILD_AREA_WOS:
x0 = bl->x - AREA_SIZE;
y0 = bl->y - AREA_SIZE;
x1 = bl->x + AREA_SIZE;
y1 = bl->y + AREA_SIZE;
case GUILD_SAMEMAP:
case GUILD_SAMEMAP_WOS:
case GUILD:
case GUILD_WOS:
case GUILD_NOBG:
if (sd && sd->status.guild_id)
g = guild_search(sd->status.guild_id);
if (g) {
for(i = 0; i < g->max_member; i++) {
if( (sd = g->member[i].sd) != NULL )
{
if( !(fd=sd->fd) )
continue;
if( type == GUILD_NOBG && sd->state.bg_id )
continue;
if( sd->bl.id == bl->id && (type == GUILD_WOS || type == GUILD_SAMEMAP_WOS || type == GUILD_AREA_WOS) )
continue;
if( type != GUILD && type != GUILD_NOBG && type != GUILD_WOS && sd->bl.m != bl->m )
continue;
if( (type == GUILD_AREA || type == GUILD_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
continue;
if( packet_db[sd->packet_ver][RBUFW(buf,0)].len )
{ // packet must exist for the client version
WFIFOHEAD(fd,len);
memcpy(WFIFOP(fd,0), buf, len);
WFIFOSET(fd,len);
}
}
}
if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
break;
iter = mapit_getallusers();
while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
{
if( tsd->guildspy == g->guild_id && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
{ // packet must exist for the client version
WFIFOHEAD(tsd->fd, len);
memcpy(WFIFOP(tsd->fd,0), buf, len);
WFIFOSET(tsd->fd,len);
}
}
mapit_free(iter);
}
break;
case BG_AREA:
case BG_AREA_WOS:
x0 = bl->x - AREA_SIZE;
y0 = bl->y - AREA_SIZE;
x1 = bl->x + AREA_SIZE;
y1 = bl->y + AREA_SIZE;
case BG_SAMEMAP:
case BG_SAMEMAP_WOS:
case BG:
case BG_WOS:
if( sd && sd->state.bg_id && (bg = bg_team_search(sd->state.bg_id)) != NULL )
{
for( i = 0; i < MAX_BG_MEMBERS; i++ )
{
if( (sd = bg->members[i].sd) == NULL || !(fd = sd->fd) )
continue;
if( sd->bl.id == bl->id && (type == BG_WOS || type == BG_SAMEMAP_WOS || type == BG_AREA_WOS) )
continue;
if( type != BG && type != BG_WOS && sd->bl.m != bl->m )
continue;
if( (type == BG_AREA || type == BG_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
continue;
if( packet_db[sd->packet_ver][RBUFW(buf,0)].len )
{ // packet must exist for the client version
WFIFOHEAD(fd,len);
memcpy(WFIFOP(fd,0), buf, len);
WFIFOSET(fd,len);
}
}
}
break;
default:
ShowError("clif_send: Unrecognized type %d\n",type);
return -1;
}
return 0;
}
//
// パケット作って送信
//
/*==========================================
*
*------------------------------------------*/
int clif_authok(struct map_session_data *sd)
{
int fd;
if (!sd->fd)
return 0;
fd = sd->fd;
WFIFOHEAD(fd, packet_len(0x73));
WFIFOW(fd, 0) = 0x73;
WFIFOL(fd, 2) = gettick();
WFIFOPOS(fd, 6, sd->bl.x, sd->bl.y, sd->ud.dir);
WFIFOB(fd, 9) = 5; // ignored
WFIFOB(fd,10) = 5; // ignored
WFIFOSET(fd,packet_len(0x73));
harmony_idcrypt_enable(sd->fd);
return 0;
}
/*==========================================
* Authentication failed/disconnect client.
*------------------------------------------
* The client closes it's socket and displays a message according to type:
* 1 - server closed -> MsgStringTable[4]
* 2 - ID already logged in -> MsgStringTable[5]
* 3 - timeout/too much lag -> MsgStringTable[241]
* 4 - server full -> MsgStringTable[264]
* 5 - underaged -> MsgStringTable[305]
* 8 - Server sill recognizes last connection -> MsgStringTable[441]
* 9 - too many connections from this ip -> MsgStringTable[529]
* 10 - out of available time paid for -> MsgStringTable[530]
* 15 - disconnected by a GM -> if( servicetype == taiwan ) MsgStringTable[579]
* other - disconnected -> MsgStringTable[3]
*/
int clif_authfail_fd(int fd, int type)
{
if (!fd || !session[fd] || session[fd]->func_parse != clif_parse) //clif_authfail should only be invoked on players!
return 0;
WFIFOHEAD(fd, packet_len(0x81));
WFIFOW(fd,0) = 0x81;
WFIFOB(fd,2) = type;
WFIFOSET(fd,packet_len(0x81));
set_eof(fd);
return 0;
}
/*==========================================
*
*------------------------------------------*/
int clif_charselectok(int id)
{
struct map_session_data* sd;
int fd;
if ((sd = map_id2sd(id)) == NULL || !sd->fd)
return 1;
fd = sd->fd;
WFIFOHEAD(fd,packet_len(0xb3));
WFIFOW(fd,0) = 0xb3;
WFIFOB(fd,2) = 1;
WFIFOSET(fd,packet_len(0xb3));
return 0;
}
/*==========================================
* Makes an item appear on the ground
* 009e <ID>.l <name ID>.w <identify flag>.B <X>.w <Y>.w <subX>.B <subY>.B <amount>.w
*------------------------------------------*/
int clif_dropflooritem(struct flooritem_data* fitem)
{
uint8 buf[17];
int view;
nullpo_retr(0, fitem);
if (fitem->item_data.nameid <= 0)
return 0;
WBUFW(buf, 0) = 0x9e;
WBUFL(buf, 2) = fitem->bl.id;
WBUFW(buf, 6) = ((view = itemdb_viewid(fitem->item_data.nameid)) > 0) ? view : fitem->item_data.nameid;
WBUFB(buf, 8) = fitem->item_data.identify;
WBUFW(buf, 9) = fitem->bl.x;
WBUFW(buf,11) = fitem->bl.y;
WBUFB(buf,13) = fitem->subx;
WBUFB(buf,14) = fitem->suby;
WBUFW(buf,15) = fitem->item_data.amount;
clif_send(buf, packet_len(0x9e), &fitem->bl, AREA);
return 0;
}
/*==========================================
*
*------------------------------------------*/
int clif_clearflooritem(struct flooritem_data *fitem, int fd)
{
unsigned char buf[16];
nullpo_retr(0, fitem);
WBUFW(buf,0) = 0xa1;
WBUFL(buf,2) = fitem->bl.id;
if (fd == 0) {
clif_send(buf, packet_len(0xa1), &fitem->bl, AREA);
} else {
WFIFOHEAD(fd,packet_len(0xa1));
memcpy(WFIFOP(fd,0), buf, packet_len(0xa1));
WFIFOSET(fd,packet_len(0xa1));
}
return 0;
}
/*==========================================
* make a unit (char, npc, mob, homun) disappear to one client
* id : the id of the unit
* type: 0 - moved out of sight
* 1 - died
* 2 - respawned
* 3 - teleported / logged out
* fd : the target client
*------------------------------------------*/
int clif_clearunit_single(int id, uint8 type, int fd)
{
WFIFOHEAD(fd, packet_len(0x80));
WFIFOW(fd,0) = 0x80;
WFIFOL(fd,2) = id;
WFIFOB(fd,6) = type;
WFIFOSET(fd, packet_len(0x80));
return 0;
}
/*==========================================
* make a unit (char, npc, mob, homun) disappear to all clients in area
* type: 0 - moved out of sight
* 1 - died
* 2 - respawned
* 3 - teleported / logged out
*------------------------------------------*/
int clif_clearunit_area(struct block_list* bl, uint8 type)
{
unsigned char buf[16];
nullpo_retr(0, bl);
WBUFW(buf,0) = 0x80;
WBUFL(buf,2) = bl->id;
WBUFB(buf,6) = type;
clif_send(buf, packet_len(0x80), bl, type == 1 ? AREA : AREA_WOS);
if(disguised(bl)) {
WBUFL(buf,2) = -bl->id;
clif_send(buf, packet_len(0x80), bl, SELF);
}
return 0;
}
int clif_clearunit_invisible(struct block_list *bl)
{
unsigned char buf[16];
nullpo_retr(0,bl);
WBUFW(buf,0) = 0x80;
WBUFL(buf,2) = bl->id;
WBUFB(buf,6) = 0;
clif_send(buf, packet_len(0x80), bl, AREA_WOI);
return 0;
}
static int clif_clearunit_delayed_sub(int tid, unsigned int tick, int id, intptr data)
{
struct block_list *bl = (struct block_list *)data;
clif_clearunit_area(bl, 0);
aFree(bl);
return 0;
}
int clif_clearunit_delayed(struct block_list* bl, unsigned int tick)
{
struct block_list *tbl;
tbl = (struct block_list*)aMalloc(sizeof (struct block_list));
memcpy (tbl, bl, sizeof (struct block_list));
add_timer(tick, clif_clearunit_delayed_sub, 0, (intptr)tbl);
return 0;
}
void clif_get_weapon_view(struct map_session_data* sd, unsigned short *rhand, unsigned short *lhand)
{
if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER))
{
*rhand = *lhand = 0;
return;
}
#if PACKETVER < 4
*rhand = sd->status.weapon;
*lhand = sd->status.shield;
#else
if (sd->equip_index[EQI_HAND_R] >= 0 &&
sd->inventory_data[sd->equip_index[EQI_HAND_R]])
{
struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_R]];
if (id->view_id > 0)
*rhand = id->view_id;
else
*rhand = id->nameid;
} else
*rhand = 0;
if (sd->equip_index[EQI_HAND_L] >= 0 &&
sd->equip_index[EQI_HAND_L] != sd->equip_index[EQI_HAND_R] &&
sd->inventory_data[sd->equip_index[EQI_HAND_L]])
{
struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_L]];
if (id->view_id > 0)
*lhand = id->view_id;
else
*lhand = id->nameid;
} else
*lhand = 0;
#endif
}
//To make the assignation of the level based on limits clearer/easier. [Skotlex]
static int clif_setlevel(int lv)
{
if( lv < battle_config.max_lv )
return lv;
if( lv < battle_config.aura_lv )
return battle_config.max_lv - 1;
return battle_config.max_lv;
}
/*==========================================
* Prepares 'unit standing/spawning' packet
*------------------------------------------*/
static int clif_set_unit_idle(struct block_list* bl, unsigned char* buffer, bool spawn)
{
struct map_session_data* sd;
struct status_change* sc = status_get_sc(bl);
struct view_data* vd = status_get_viewdata(bl);
unsigned char *buf = WBUFP(buffer,0);
#if PACKETVER < 20091103
bool type = !pcdb_checkid(vd->class_);
#endif
#if PACKETVER >= 7
unsigned short offset = 0;
#endif
#if PACKETVER >= 20091103
const char *name;
#endif
sd = BL_CAST(BL_PC, bl);
#if PACKETVER < 20091103
if(type)
WBUFW(buf,0) = spawn?0x7c:0x78;
else
#endif
#if PACKETVER < 4
WBUFW(buf,0) = spawn?0x79:0x78;
#elif PACKETVER < 7
WBUFW(buf,0) = spawn?0x1d9:0x1d8;
#elif PACKETVER < 20080102
WBUFW(buf,0) = spawn?0x22b:0x22a;
#elif PACKETVER < 20091103