-
Notifications
You must be signed in to change notification settings - Fork 756
/
clif.c
17688 lines (14990 loc) · 497 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) Hercules Dev Team, licensed under GNU GPL.
// See the LICENSE file
// Portions Copyright (c) Athena Dev Teams
#include "../common/cbasetypes.h"
#include "../common/socket.h"
#include "../common/timer.h"
#include "../common/grfio.h"
#include "../common/malloc.h"
#include "../common/nullpo.h"
#include "../common/random.h"
#include "../common/showmsg.h"
#include "../common/strlib.h"
#include "../common/utils.h"
#include "../common/ers.h"
#include "../common/conf.h"
#include "map.h"
#include "chrif.h"
#include "pc.h"
#include "status.h"
#include "npc.h"
#include "itemdb.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 "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 "packets_struct.h"
#include "irc-bot.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <time.h>
//#define DUMP_UNKNOWN_PACKET
//#define DUMP_INVALID_PACKET
//Converts item type in case of pet eggs.
static inline int itemtype(int type) {
return ( type == IT_PETEGG ) ? IT_WEAPON : type;
}
static inline void WBUFPOS(uint8* p, unsigned short pos, short x, short y, unsigned char dir) {
p += pos;
p[0] = (uint8)(x>>2);
p[1] = (uint8)((x<<6) | ((y>>4)&0x3f));
p[2] = (uint8)((y<<4) | (dir&0xf));
}
// client-side: x0+=sx0*0.0625-0.5 and y0+=sy0*0.0625-0.5
static inline void WBUFPOS2(uint8* p, unsigned short pos, short x0, short y0, short x1, short y1, unsigned char sx0, unsigned char sy0) {
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));
}
static inline void WFIFOPOS(int fd, unsigned short pos, short x, short y, unsigned char dir) {
WBUFPOS(WFIFOP(fd,pos), 0, x, y, dir);
}
static inline void WFIFOPOS2(int fd, unsigned short pos, short x0, short y0, short x1, short y1, unsigned char sx0, unsigned char sy0) {
WBUFPOS2(WFIFOP(fd,pos), 0, x0, y0, x1, y1, sx0, sy0);
}
static inline void RBUFPOS(const uint8* p, unsigned short pos, short* x, short* y, unsigned char* dir) {
p += pos;
if( x ) {
x[0] = ( ( p[0] & 0xff ) << 2 ) | ( p[1] >> 6 );
}
if( y ) {
y[0] = ( ( p[1] & 0x3f ) << 4 ) | ( p[2] >> 4 );
}
if( dir ) {
dir[0] = ( p[2] & 0x0f );
}
}
static inline void RBUFPOS2(const uint8* p, unsigned short pos, short* x0, short* y0, short* x1, short* y1, unsigned char* sx0, unsigned char* sy0) {
p += pos;
if( x0 ) {
x0[0] = ( ( p[0] & 0xff ) << 2 ) | ( p[1] >> 6 );
}
if( y0 ) {
y0[0] = ( ( p[1] & 0x3f ) << 4 ) | ( p[2] >> 4 );
}
if( x1 ) {
x1[0] = ( ( p[2] & 0x0f ) << 6 ) | ( p[3] >> 2 );
}
if( y1 ) {
y1[0] = ( ( p[3] & 0x03 ) << 8 ) | ( p[4] >> 0 );
}
if( sx0 ) {
sx0[0] = ( p[5] & 0xf0 ) >> 4;
}
if( sy0 ) {
sy0[0] = ( p[5] & 0x0f ) >> 0;
}
}
static inline void RFIFOPOS(int fd, unsigned short pos, short* x, short* y, unsigned char* dir) {
RBUFPOS(RFIFOP(fd,pos), 0, x, y, dir);
}
static inline void RFIFOPOS2(int fd, unsigned short pos, short* x0, short* y0, short* x1, short* y1, unsigned char* sx0, unsigned char* sy0) {
RBUFPOS2(WFIFOP(fd,pos), 0, x0, y0, x1, y1, sx0, sy0);
}
//To idenfity disguised characters.
static inline bool disguised(struct block_list* bl) {
return (bool)( 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]
static inline unsigned int mes_len_check(char* mes, unsigned int len, unsigned int max) {
if( len > max )
len = max;
mes[len-1] = '\0';
return len;
}
/*==========================================
* Ip setting of map-server
*------------------------------------------*/
int clif_setip(const char* ip) {
char ip_str[16];
clif->map_ip = host2ip(ip);
if (!clif->map_ip) {
ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
return 0;
}
safestrncpy(clif->map_ip_str, ip, sizeof(clif->map_ip_str));
ShowInfo("Map Server IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(clif->map_ip, ip_str));
return 1;
}
void clif_setbindip(const char* ip) {
clif->bind_ip = host2ip(ip);
if (clif->bind_ip) {
char ip_str[16];
ShowInfo("Map Server Bind IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(clif->bind_ip, ip_str));
} else {
ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
}
}
/*==========================================
* Sets map port to 'port'
* is run from map.c upon loading map server configuration
*------------------------------------------*/
void clif_setport(uint16 port)
{
clif->map_port = port;
}
/*==========================================
* Returns map server IP
*------------------------------------------*/
uint32 clif_getip(void)
{
return clif->map_ip;
}
/*==========================================
* Returns map port which is set by clif_setport()
*------------------------------------------*/
uint16 clif_getport(void)
{
return clif->map_port;
}
uint32 clif_refresh_ip(void) {
uint32 new_ip;
new_ip = host2ip(clif->map_ip_str);
if (new_ip && new_ip != clif->map_ip) {
clif->map_ip = new_ip;
ShowInfo("Updating IP resolution of [%s].\n", clif->map_ip_str);
return clif->map_ip;
}
return 0;
}
#if PACKETVER >= 20071106
static inline unsigned char clif_bl_type(struct block_list *bl) {
switch (bl->type) {
case BL_PC: return (disguised(bl) && !pcdb_checkid(status_get_viewdata(bl)->class_))? 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(status_get_viewdata(bl)->class_)?0x0:0x5; //NPC_MOB_TYPE
case BL_NPC: return 0x6; //NPC_EVT_TYPE
case BL_PET: return pcdb_checkid(status_get_viewdata(bl)->class_)?0x0: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
/*==========================================
* sub process of clif_send
* Called from a map_foreachinarea (grabs all players in specific area and subjects them to this function)
* In order to send area-wise packets, such as:
* - AREA : everyone nearby your area
* - AREA_WOSC (AREA WITHOUT SAME CHAT) : Not run for people in the same chat as yours
* - AREA_WOC (AREA WITHOUT CHAT) : Not run for people inside a chat
* - AREA_WOS (AREA WITHOUT SELF) : Not run for self
* - AREA_CHAT_WOC : Everyone in the area of your chat without a chat
*------------------------------------------*/
int clif_send_sub(struct block_list *bl, va_list ap) {
struct block_list *src_bl;
struct map_session_data *sd;
void *buf;
int len, type, fd;
nullpo_ret(bl);
nullpo_ret(sd = (struct map_session_data *)bl);
fd = sd->fd;
if (!fd || session[fd] == NULL) //Don't send to disconnected clients.
return 0;
buf = va_arg(ap,void*);
len = va_arg(ap,int);
nullpo_ret(src_bl = va_arg(ap,struct block_list*));
type = va_arg(ap,int);
switch(type) {
case AREA_WOS:
if (bl == src_bl)
return 0;
break;
case AREA_WOC:
if (sd->chatID || bl == src_bl)
return 0;
break;
case AREA_WOSC: {
if(src_bl->type == BL_PC){
struct map_session_data *ssd = (struct map_session_data *)src_bl;
if (ssd && sd->chatID && (sd->chatID == ssd->chatID))
return 0;
}
else if(src_bl->type == BL_NPC) {
struct npc_data *nd = (struct npc_data *)src_bl;
if (nd && sd->chatID && (sd->chatID == nd->chat_id))
return 0;
}
}
break;
}
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;
}
memcpy(WFIFOP(fd,0), buf, len);
WFIFOSET(fd,len);
return 0;
}
/*==========================================
* Packet Delegation (called on all packets that require data to be sent to more than one client)
* functions that are sent solely to one use whose ID it posses use WFIFOSET
*------------------------------------------*/
int clif_send(const void* 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_ret(bl);
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 ) {
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
iter = mapit_getallusers();
while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL ) {
if( bl->m == tsd->bl.m ) {
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 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 ((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:
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 && 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;
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 ) {
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 ) {
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) ) {
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 = sd->guild;
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->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;
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 ) {
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->bg_id && (bg = bg_team_search(sd->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;
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;
}
/// Notifies the client, that it's connection attempt was accepted.
/// 0073 <start time>.L <position>.3B <x size>.B <y size>.B (ZC_ACCEPT_ENTER)
/// 02eb <start time>.L <position>.3B <x size>.B <y size>.B <font>.W (ZC_ACCEPT_ENTER2)
void clif_authok(struct map_session_data *sd)
{
struct packet_authok p;
p.PacketType = authokType;
p.startTime = gettick();
WBUFPOS(&p.PosDir[0],0,sd->bl.x,sd->bl.y,sd->ud.dir); /* do the stupid client math */
p.xSize = p.ySize = 5; /* not-used */
#if PACKETVER >= 20080102
p.font = sd->user_font; // FIXME: Font is currently not saved.
#endif
clif->send(&p,sizeof(p),&sd->bl,SELF);
}
/// Notifies the client, that it's connection attempt was refused (ZC_REFUSE_ENTER).
/// 0074 <error code>.B
/// error code:
/// 0 = client type mismatch
/// 1 = ID mismatch
/// 2 = mobile - out of available time
/// 3 = mobile - already logged in
/// 4 = mobile - waiting state
void clif_authrefuse(int fd, uint8 error_code)
{
WFIFOHEAD(fd,packet_len(0x74));
WFIFOW(fd,0) = 0x74;
WFIFOB(fd,2) = error_code;
WFIFOSET(fd,packet_len(0x74));
}
/// Notifies the client of a ban or forced disconnect (SC_NOTIFY_BAN).
/// 0081 <error code>.B
/// error code:
/// 0 = BAN_UNFAIR
/// 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]
/// 11 = BAN_PAY_SUSPEND
/// 12 = BAN_PAY_CHANGE
/// 13 = BAN_PAY_WRONGIP
/// 14 = BAN_PAY_PNGAMEROOM
/// 15 = disconnected by a GM -> if( servicetype == taiwan ) MsgStringTable[579]
/// 16 = BAN_JAPAN_REFUSE1
/// 17 = BAN_JAPAN_REFUSE2
/// 18 = BAN_INFORMATION_REMAINED_ANOTHER_ACCOUNT
/// 100 = BAN_PC_IP_UNFAIR
/// 101 = BAN_PC_IP_COUNT_ALL
/// 102 = BAN_PC_IP_COUNT
/// 103 = BAN_GRAVITY_MEM_AGREE
/// 104 = BAN_GAME_MEM_AGREE
/// 105 = BAN_HAN_VALID
/// 106 = BAN_PC_IP_LIMIT_ACCESS
/// 107 = BAN_OVER_CHARACTER_LIST
/// 108 = BAN_IP_BLOCK
/// 109 = BAN_INVALID_PWD_CNT
/// 110 = BAN_NOT_ALLOWED_JOBCLASS
/// ? = disconnected -> MsgStringTable[3]
void 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;
WFIFOHEAD(fd, packet_len(0x81));
WFIFOW(fd,0) = 0x81;
WFIFOB(fd,2) = type;
WFIFOSET(fd,packet_len(0x81));
set_eof(fd);
}
/// Notifies the client, whether it can disconnect and change servers (ZC_RESTART_ACK).
/// 00b3 <type>.B
/// type:
/// 1 = disconnect, char-select
/// ? = nothing
void clif_charselectok(int id, uint8 ok)
{
struct map_session_data* sd;
int fd;
if ((sd = map_id2sd(id)) == NULL || !sd->fd)
return;
fd = sd->fd;
WFIFOHEAD(fd,packet_len(0xb3));
WFIFOW(fd,0) = 0xb3;
WFIFOB(fd,2) = ok;
WFIFOSET(fd,packet_len(0xb3));
}
/// Makes an item appear on the ground.
/// 009e <id>.L <name id>.W <identified>.B <x>.W <y>.W <subX>.B <subY>.B <amount>.W (ZC_ITEM_FALL_ENTRY)
/// 084b (ZC_ITEM_FALL_ENTRY4)
void clif_dropflooritem(struct flooritem_data* fitem) {
struct packet_dropflooritem p;
int view;
nullpo_retv(fitem);
if (fitem->item_data.nameid <= 0)
return;
p.PacketType = dropflooritemType;
p.ITAID = fitem->bl.id;
p.ITID = ((view = itemdb_viewid(fitem->item_data.nameid)) > 0) ? view : fitem->item_data.nameid;
#if PACKETVER >= 20130000 /* not sure date */
p.type = itemtype(itemdb_type(fitem->item_data.nameid));
#endif
p.IsIdentified = fitem->item_data.identify;
p.xPos = fitem->bl.x;
p.yPos = fitem->bl.y;
p.subX = fitem->subx;
p.subY = fitem->suby;
p.count = fitem->item_data.amount;
clif->send(&p, sizeof(p), &fitem->bl, AREA);
}
/// Makes an item disappear from the ground.
/// 00a1 <id>.L (ZC_ITEM_DISAPPEAR)
void clif_clearflooritem(struct flooritem_data *fitem, int fd)
{
unsigned char buf[16];
nullpo_retv(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));
}
}
/// Makes a unit (char, npc, mob, homun) disappear to one client (ZC_NOTIFY_VANISH).
/// 0080 <id>.L <type>.B
/// type:
/// 0 = out of sight
/// 1 = died
/// 2 = logged out
/// 3 = teleport
/// 4 = trickdead
void clif_clearunit_single(int id, clr_type 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));
}
/// Makes a unit (char, npc, mob, homun) disappear to all clients in area (ZC_NOTIFY_VANISH).
/// 0080 <id>.L <type>.B
/// type:
/// 0 = out of sight
/// 1 = died
/// 2 = logged out
/// 3 = teleport
/// 4 = trickdead
void clif_clearunit_area(struct block_list* bl, clr_type type)
{
unsigned char buf[8];
nullpo_retv(bl);
WBUFW(buf,0) = 0x80;
WBUFL(buf,2) = bl->id;
WBUFB(buf,6) = type;
clif->send(buf, packet_len(0x80), bl, type == CLR_DEAD ? AREA : AREA_WOS);
if(disguised(bl)) {
WBUFL(buf,2) = -bl->id;
clif->send(buf, packet_len(0x80), bl, SELF);
}
}
/// Used to make monsters with player-sprites disappear after dying
/// like normal monsters, because the client does not remove those
/// automatically.
int clif_clearunit_delayed_sub(int tid, unsigned int tick, int id, intptr_t data) {
struct block_list *bl = (struct block_list *)data;
clif->clearunit_area(bl, (clr_type) id);
ers_free(clif->delay_clearunit_ers,bl);
return 0;
}
void clif_clearunit_delayed(struct block_list* bl, clr_type type, unsigned int tick)
{
struct block_list *tbl = ers_alloc(clif->delay_clearunit_ers, struct block_list);
memcpy (tbl, bl, sizeof (struct block_list));
add_timer(tick, clif->clearunit_delayed_sub, (int)type, (intptr_t)tbl);
}
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|OPTION_HANBOK)) {
*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_sub(int lv) {
if( lv < battle_config.max_lv ) {
;
} else if( lv < battle_config.aura_lv ) {
lv = battle_config.max_lv - 1;
} else {
lv = battle_config.max_lv;
}
return lv;
}
static int clif_setlevel(struct block_list* bl) {
int lv = status_get_lv(bl);
if( battle_config.client_limit_unit_lv&bl->type )
return clif_setlevel_sub(lv);
switch( bl->type ) {
case BL_NPC:
case BL_PET:
// npcs and pets do not have level
return 0;
}
return lv;
}
/*==========================================
* Prepares 'unit standing' packet
*------------------------------------------*/
void clif_set_unit_idle(struct block_list* bl, struct map_session_data *tsd, enum send_target target) {
struct map_session_data* sd;
struct status_change* sc = status_get_sc(bl);
struct view_data* vd = status_get_viewdata(bl);
struct packet_idle_unit p;
int g_id = status_get_guild_id(bl);
sd = BL_CAST(BL_PC, bl);
p.PacketType = idle_unitType;
#if PACKETVER >= 20091103
p.PacketLength = sizeof(p);
p.objecttype = clif_bl_type(bl);
#endif
p.GID = bl->id;
p.speed = status_get_speed(bl);
p.bodyState = (sc) ? sc->opt1 : 0;
p.healthState = (sc) ? sc->opt2 : 0;
p.effectState = (sc) ? sc->option : 0;
p.job = vd->class_;
p.head = vd->hair_style;
p.weapon = vd->weapon;
p.accessory = vd->head_bottom;
#if PACKETVER < 7
p.shield = vd->shield;
#endif
p.accessory2 = vd->head_top;
p.accessory3 = vd->head_mid;
if( bl->type == BL_NPC && vd->class_ == FLAG_CLASS ) { //The hell, why flags work like this?
p.accessory = g_id;
p.accessory2 = GetWord(g_id, 1);
p.accessory3 = GetWord(g_id, 0);
}
p.headpalette = vd->hair_color;
p.bodypalette = vd->cloth_color;
p.headDir = (sd)? sd->head_dir : 0;
#if PACKETVER >= 20101124
p.robe = vd->robe;
#endif
p.GUID = g_id;
p.GEmblemVer = status_get_emblem_id(bl);
p.honor = (sd) ? sd->status.manner : 0;
p.virtue = (sc) ? sc->opt3 : 0;
p.isPKModeON = (sd) ? sd->status.karma : 0;
p.sex = vd->sex;
WBUFPOS(&p.PosDir[0],0,bl->x,bl->y,unit_getdir(bl));
p.xSize = p.ySize = (sd) ? 5 : 0;
p.state = vd->dead_sit;
p.clevel = clif_setlevel(bl);
#if PACKETVER >= 20080102
p.font = (sd) ? sd->user_font : 0;
#endif
#if PACKETVER >= 20140000 //actual 20120221
if( bl->type == BL_MOB ) {
p.maxHP = status_get_max_hp(bl);
p.HP = status_get_hp(bl);
p.isBoss = ( ((TBL_MOB*)bl)->spawn && ((TBL_MOB*)bl)->spawn->state.boss ) ? 1 : 0;
} else {
p.maxHP = -1;
p.HP = -1;
p.isBoss = 0;
}
#endif
clif->send(&p,sizeof(p),tsd?&tsd->bl:bl,target);
if( disguised(bl) ) {
#if PACKETVER >= 20071106
p.objecttype = pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
p.GID = -bl->id;
#else
p.GID = -bl->id;
#endif
clif->send(&p,sizeof(p),tsd?&tsd->bl:bl,SELF);
}
}
/* todo for packetver 20091103 0x7c non-pc-looking unit handling */
int clif_spawn_unit2(struct block_list* bl, enum send_target target) {
return 0;
/*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
unsigned short offset = 0;
#if PACKETVER >= 20091103
const char *name;
#endif
sd = BL_CAST(BL_PC, bl);
#if PACKETVER < 20091103
if(type)
WBUFW(buf,0) = 0x7c;
else
#endif
#if PACKETVER < 4
WBUFW(buf,0) = 0x79;
#elif PACKETVER < 7
WBUFW(buf,0) = 0x1d9;
#elif PACKETVER < 20080102
WBUFW(buf,0) = 0x22b;
#elif PACKETVER < 20091103
WBUFW(buf,0) = 0x2ed;
#elif PACKETVER < 20101124
WBUFW(buf,0) = 0x7f8;
#else
WBUFW(buf,0) = 0x858;
#endif
#if PACKETVER >= 20091103
name = status_get_name(bl);
#if PACKETVER < 20110111
WBUFW(buf,2) = (spawn?62:63)+strlen(name);
#else
WBUFW(buf,2) = (spawn?64:65)+strlen(name);
#endif
WBUFB(buf,4) = clif_bl_type(bl);
offset+=3;
buf = WBUFP(buffer,offset);
#elif PACKETVER >= 20071106
if (type) { //Non-player packets
WBUFB(buf,2) = clif_bl_type(bl);
offset++;
buf = WBUFP(buffer,offset);
}
#endif
WBUFL(buf, 2) = bl->id;
WBUFW(buf, 6) = status_get_speed(bl);
WBUFW(buf, 8) = (sc)? sc->opt1 : 0;
WBUFW(buf,10) = (sc)? sc->opt2 : 0;
#if PACKETVER < 20091103
if (type&&spawn) { //uses an older and different packet structure
WBUFW(buf,12) = (sc)? sc->option : 0;
WBUFW(buf,14) = vd->hair_style;
WBUFW(buf,16) = vd->weapon;
WBUFW(buf,18) = vd->head_bottom;
WBUFW(buf,20) = vd->class_; //Pet armor (ignored by client)
WBUFW(buf,22) = vd->shield;
} else {
#endif
#if PACKETVER >= 20091103
WBUFL(buf,12) = (sc)? sc->option : 0;
offset+=2;
buf = WBUFP(buffer,offset);
#elif PACKETVER >= 7
if (!type) {
WBUFL(buf,12) = (sc)? sc->option : 0;
offset+=2;
buf = WBUFP(buffer,offset);
} else
WBUFW(buf,12) = (sc)? sc->option : 0;
#else
WBUFW(buf,12) = (sc)? sc->option : 0;
#endif
WBUFW(buf,14) = vd->class_;
WBUFW(buf,16) = vd->hair_style;
WBUFW(buf,18) = vd->weapon;
#if PACKETVER < 4
WBUFW(buf,20) = vd->head_bottom;
WBUFW(buf,22) = vd->shield;
#else
WBUFW(buf,20) = vd->shield;
WBUFW(buf,22) = vd->head_bottom;