root/src/map/intif.c @ 13

Revision 1, 55.1 kB (checked in by jinshiro, 17 years ago)
Line 
1// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
2// For more information, see LICENCE in the main folder
3
4#include "../common/showmsg.h"
5#include "../common/socket.h"
6#include "../common/timer.h"
7#include "../common/nullpo.h"
8#include "../common/malloc.h"
9#include "../common/strlib.h"
10#include "map.h"
11#include "battle.h"
12#include "chrif.h"
13#include "clif.h"
14#include "pc.h"
15#include "intif.h"
16#include "storage.h"
17#include "party.h"
18#include "guild.h"
19#include "pet.h"
20#include "atcommand.h"
21#include "mercenary.h" //albator
22#include "mail.h"
23#include "quest.h"
24
25#include <sys/types.h>
26#include <stdio.h>
27#include <stdlib.h>
28#include <signal.h>
29#include <fcntl.h>
30#include <string.h>
31
32
33static const int packet_len_table[]={
34        -1,-1,27,-1, -1, 0,37, 0,  0, 0, 0, 0,  0, 0,  0, 0, //0x3800-0x380f
35        -1, 7, 0, 0,  0, 0, 0, 0, -1,11, 0, 0,  0, 0,  0, 0, //0x3810
36        39,-1,15,15, 14,19, 7,-1,  0, 0, 0, 0,  0, 0,  0, 0, //0x3820
37        10,-1,15, 0, 79,19, 7,-1,  0,-1,-1,-1, 14,67,186,-1, //0x3830
38         9, 9,-1,14,  0, 0, 0, 0, -1,74,-1,11, 11,-1,  0, 0, //0x3840
39        -1,-1, 7, 7,  7,11, 0, 0,  0, 0, 0, 0,  0, 0,  0, 0, //0x3850  Auctions [Zephyrus]
40        -1,11,11, 0,  0, 0, 0, 0,  0, 0, 0, 0,  0, 0,  0, 0, //0x3860  Quests [Kevin]
41         0, 0, 0, 0,  0, 0, 0, 0,  0, 0, 0, 0,  0, 0,  0, 0,
42        11,-1, 7, 3,  0, 0, 0, 0,  0, 0, 0, 0,  0, 0,  0, 0, //0x3880
43        -1,-1, 7, 3,  0, 0, 0, 0,  0, 0, 0, 0,  0, 0,  0, 0, //0x3890  Homunculus [albator]
44};
45
46extern int char_fd;             // inter server‚Ìfd‚Íchar_fd‚ðŽg‚€
47#define inter_fd char_fd        // ƒGƒCƒŠƒAƒX
48
49//-----------------------------------------------------------------
50// inter server‚Ö‚Ì‘—M
51
52int CheckForCharServer(void)
53{
54        return ((char_fd <= 0) || session[char_fd] == NULL || session[char_fd]->wdata == NULL);
55}
56
57// pet
58int intif_create_pet(int account_id,int char_id,short pet_class,short pet_lv,short pet_egg_id,
59        short pet_equip,short intimate,short hungry,char rename_flag,char incuvate,char *pet_name)
60{
61        if (CheckForCharServer())
62                return 0;
63        WFIFOHEAD(inter_fd, 24 + NAME_LENGTH);
64        WFIFOW(inter_fd,0) = 0x3080;
65        WFIFOL(inter_fd,2) = account_id;
66        WFIFOL(inter_fd,6) = char_id;
67        WFIFOW(inter_fd,10) = pet_class;
68        WFIFOW(inter_fd,12) = pet_lv;
69        WFIFOW(inter_fd,14) = pet_egg_id;
70        WFIFOW(inter_fd,16) = pet_equip;
71        WFIFOW(inter_fd,18) = intimate;
72        WFIFOW(inter_fd,20) = hungry;
73        WFIFOB(inter_fd,22) = rename_flag;
74        WFIFOB(inter_fd,23) = incuvate;
75        memcpy(WFIFOP(inter_fd,24),pet_name,NAME_LENGTH);
76        WFIFOSET(inter_fd,24+NAME_LENGTH);
77
78        return 0;
79}
80
81int intif_request_petdata(int account_id,int char_id,int pet_id)
82{
83        if (CheckForCharServer())
84                return 0;
85        WFIFOHEAD(inter_fd, 14);
86        WFIFOW(inter_fd,0) = 0x3081;
87        WFIFOL(inter_fd,2) = account_id;
88        WFIFOL(inter_fd,6) = char_id;
89        WFIFOL(inter_fd,10) = pet_id;
90        WFIFOSET(inter_fd,14);
91
92        return 0;
93}
94
95int intif_save_petdata(int account_id,struct s_pet *p)
96{
97        if (CheckForCharServer())
98                return 0;
99        WFIFOHEAD(inter_fd, sizeof(struct s_pet) + 8);
100        WFIFOW(inter_fd,0) = 0x3082;
101        WFIFOW(inter_fd,2) = sizeof(struct s_pet) + 8;
102        WFIFOL(inter_fd,4) = account_id;
103        memcpy(WFIFOP(inter_fd,8),p,sizeof(struct s_pet));
104        WFIFOSET(inter_fd,WFIFOW(inter_fd,2));
105
106        return 0;
107}
108
109int intif_delete_petdata(int pet_id)
110{
111        if (CheckForCharServer())
112                return 0;
113        WFIFOHEAD(inter_fd,6);
114        WFIFOW(inter_fd,0) = 0x3083;
115        WFIFOL(inter_fd,2) = pet_id;
116        WFIFOSET(inter_fd,6);
117
118        return 1;
119}
120
121int intif_rename(struct map_session_data *sd, int type, char *name)
122{
123        if (CheckForCharServer())
124                return 1;
125
126        WFIFOHEAD(inter_fd,NAME_LENGTH+12);
127        WFIFOW(inter_fd,0) = 0x3006;
128        WFIFOL(inter_fd,2) = sd->status.account_id;
129        WFIFOL(inter_fd,6) = sd->status.char_id;
130        WFIFOB(inter_fd,10) = type;  //Type: 0 - PC, 1 - PET, 2 - HOM
131        memcpy(WFIFOP(inter_fd,11),name, NAME_LENGTH);
132        WFIFOSET(inter_fd,NAME_LENGTH+12);
133        return 0;
134}
135
136// GMƒƒbƒZ[ƒW‚𑗐M
137int intif_GMmessage(const char* mes,int len,int flag)
138{
139        int lp = (flag&0x10) ? 8 : 4;
140
141        // Send to the local players
142        clif_GMmessage(NULL, mes, len, flag);
143
144        if (CheckForCharServer())
145                return 0;
146
147        if (other_mapserver_count < 1)
148                return 0; //No need to send.
149
150        WFIFOHEAD(inter_fd,lp + len + 4);
151        WFIFOW(inter_fd,0) = 0x3000;
152        WFIFOW(inter_fd,2) = lp + len + 4;
153        WFIFOL(inter_fd,4) = 0xFF000000; //"invalid" color signals standard broadcast.
154        WFIFOL(inter_fd,8) = 0x65756c62;
155        memcpy(WFIFOP(inter_fd,4+lp), mes, len);
156        WFIFOSET(inter_fd, WFIFOW(inter_fd,2));
157        return 0;
158}
159
160int intif_announce(const char* mes,int len, unsigned long color, int flag)
161{
162        // Send to the local players
163        if(color == 0xFE000000) // This is main chat message [LuzZza]
164                clif_MainChatMessage(mes);
165        else
166                clif_announce(NULL, mes, len, color, flag);
167
168        if (CheckForCharServer())
169                return 0;
170
171        if (other_mapserver_count < 1)
172                return 0; //No need to send.
173
174        WFIFOHEAD(inter_fd, 8 + len);
175        WFIFOW(inter_fd,0) = 0x3000;
176        WFIFOW(inter_fd,2) = 8 + len;
177        WFIFOL(inter_fd,4) = color;
178        memcpy(WFIFOP(inter_fd,8), mes, len);
179        WFIFOSET(inter_fd, WFIFOW(inter_fd,2));
180        return 0;
181}
182
183// The transmission of Wisp/Page to inter-server (player not found on this server)
184int intif_wis_message(struct map_session_data *sd, char *nick, char *mes, int mes_len)
185{
186        nullpo_retr(0, sd);
187        if (CheckForCharServer())
188                return 0;
189
190        if (other_mapserver_count < 1)
191        {       //Character not found.
192                clif_wis_end(sd->fd, 1);
193                return 0;
194        }
195
196        WFIFOHEAD(inter_fd,mes_len + 52);
197        WFIFOW(inter_fd,0) = 0x3001;
198        WFIFOW(inter_fd,2) = mes_len + 52;
199        memcpy(WFIFOP(inter_fd,4), sd->status.name, NAME_LENGTH);
200        memcpy(WFIFOP(inter_fd,4+NAME_LENGTH), nick, NAME_LENGTH);
201        memcpy(WFIFOP(inter_fd,4+2*NAME_LENGTH), mes, mes_len);
202        WFIFOSET(inter_fd, WFIFOW(inter_fd,2));
203
204        if (battle_config.etc_log)
205                ShowInfo("intif_wis_message from %s to %s (message: '%s')\n", sd->status.name, nick, mes);
206
207        return 0;
208}
209
210// The reply of Wisp/page
211int intif_wis_replay(int id, int flag)
212{
213        if (CheckForCharServer())
214                return 0;
215        WFIFOHEAD(inter_fd,7);
216        WFIFOW(inter_fd,0) = 0x3002;
217        WFIFOL(inter_fd,2) = id;
218        WFIFOB(inter_fd,6) = flag; // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target
219        WFIFOSET(inter_fd,7);
220
221        if (battle_config.etc_log)
222                ShowInfo("intif_wis_replay: id: %d, flag:%d\n", id, flag);
223
224        return 0;
225}
226
227// The transmission of GM only Wisp/Page from server to inter-server
228int intif_wis_message_to_gm(char *Wisp_name, int min_gm_level, char *mes)
229{
230        int mes_len;
231        if (CheckForCharServer())
232                return 0;
233        mes_len = strlen(mes) + 1; // + null
234        WFIFOHEAD(inter_fd, mes_len + 30);
235        WFIFOW(inter_fd,0) = 0x3003;
236        WFIFOW(inter_fd,2) = mes_len + 30;
237        memcpy(WFIFOP(inter_fd,4), Wisp_name, NAME_LENGTH);
238        WFIFOW(inter_fd,4+NAME_LENGTH) = (short)min_gm_level;
239        memcpy(WFIFOP(inter_fd,6+NAME_LENGTH), mes, mes_len);
240        WFIFOSET(inter_fd, WFIFOW(inter_fd,2));
241
242        if (battle_config.etc_log)
243                ShowNotice("intif_wis_message_to_gm: from: '%s', min level: %d, message: '%s'.\n", Wisp_name, min_gm_level, mes);
244
245        return 0;
246}
247
248int intif_regtostr(char* str, struct global_reg *reg, int qty)
249{
250        int len =0, i;
251
252        for (i = 0; i < qty; i++) {
253                len+= sprintf(str+len, "%s", reg[i].str)+1; //We add 1 to consider the '\0' in place.
254                len+= sprintf(str+len, "%s", reg[i].value)+1;
255        }
256        return len;
257}
258
259//Request for saving registry values.
260int intif_saveregistry(struct map_session_data *sd, int type)
261{
262        struct global_reg *reg;
263        int count;
264        int i, p;
265
266        if (CheckForCharServer())
267                return -1;
268
269        switch (type) {
270        case 3: //Character reg
271                reg = sd->save_reg.global;
272                count = sd->save_reg.global_num;
273                sd->state.reg_dirty &= ~0x4;
274        break;
275        case 2: //Account reg
276                reg = sd->save_reg.account;
277                count = sd->save_reg.account_num;
278                sd->state.reg_dirty &= ~0x2;
279        break;
280        case 1: //Account2 reg
281                reg = sd->save_reg.account2;
282                count = sd->save_reg.account2_num;
283                sd->state.reg_dirty &= ~0x1;
284        break;
285        default: //Broken code?
286                ShowError("intif_saveregistry: Invalid type %d\n", type);
287                return -1;
288        }
289        WFIFOHEAD(inter_fd, 288 * MAX_REG_NUM+13);
290        WFIFOW(inter_fd,0)=0x3004;
291        WFIFOL(inter_fd,4)=sd->status.account_id;
292        WFIFOL(inter_fd,8)=sd->status.char_id;
293        WFIFOB(inter_fd,12)=type;
294        for( p = 13, i = 0; i < count; i++ ) {
295                if (reg[i].str[0] && reg[i].value != 0) {
296                        p+= sprintf((char*)WFIFOP(inter_fd,p), "%s", reg[i].str)+1; //We add 1 to consider the '\0' in place.
297                        p+= sprintf((char*)WFIFOP(inter_fd,p), "%s", reg[i].value)+1;
298                }
299        }
300        WFIFOW(inter_fd,2)=p;
301        WFIFOSET(inter_fd,WFIFOW(inter_fd,2));
302        return 0;
303}
304
305//Request the registries for this player.
306int intif_request_registry(struct map_session_data *sd, int flag)
307{
308        nullpo_retr(0, sd);
309
310        sd->save_reg.account2_num = -1;
311        sd->save_reg.account_num = -1;
312        sd->save_reg.global_num = -1;
313
314        if (CheckForCharServer())
315                return 0;
316
317        WFIFOHEAD(inter_fd,6);
318        WFIFOW(inter_fd,0) = 0x3005;
319        WFIFOL(inter_fd,2) = sd->status.account_id;
320        WFIFOL(inter_fd,6) = sd->status.char_id;
321        WFIFOB(inter_fd,10) = (flag&1?1:0); //Request Acc Reg 2
322        WFIFOB(inter_fd,11) = (flag&2?1:0); //Request Acc Reg
323        WFIFOB(inter_fd,12) = (flag&4?1:0); //Request Char Reg
324        WFIFOSET(inter_fd,13);
325
326        return 0;
327}
328
329// ‘qŒÉƒf[ƒ^—v‹
330int intif_request_storage(int account_id)
331{
332        if (CheckForCharServer())
333                return 0;
334        WFIFOHEAD(inter_fd,6);
335        WFIFOW(inter_fd,0) = 0x3010;
336        WFIFOL(inter_fd,2) = account_id;
337        WFIFOSET(inter_fd,6);
338        return 0;
339}
340// ‘qŒÉƒf[ƒ^‘—M
341int intif_send_storage(struct storage *stor)
342{
343        if (CheckForCharServer())
344                return 0;
345        nullpo_retr(0, stor);
346        WFIFOHEAD(inter_fd,sizeof(struct storage)+8);
347        WFIFOW(inter_fd,0) = 0x3011;
348        WFIFOW(inter_fd,2) = sizeof(struct storage)+8;
349        WFIFOL(inter_fd,4) = stor->account_id;
350        memcpy( WFIFOP(inter_fd,8),stor, sizeof(struct storage) );
351        WFIFOSET(inter_fd,WFIFOW(inter_fd,2));
352        return 0;
353}
354
355int intif_request_guild_storage(int account_id,int guild_id)
356{
357        if (CheckForCharServer())
358                return 0;
359        WFIFOHEAD(inter_fd,10);
360        WFIFOW(inter_fd,0) = 0x3018;
361        WFIFOL(inter_fd,2) = account_id;
362        WFIFOL(inter_fd,6) = guild_id;
363        WFIFOSET(inter_fd,10);
364        return 0;
365}
366int intif_send_guild_storage(int account_id,struct guild_storage *gstor)
367{
368        if (CheckForCharServer())
369                return 0;
370        WFIFOHEAD(inter_fd,sizeof(struct guild_storage)+12);
371        WFIFOW(inter_fd,0) = 0x3019;
372        WFIFOW(inter_fd,2) = (unsigned short)sizeof(struct guild_storage)+12;
373        WFIFOL(inter_fd,4) = account_id;
374        WFIFOL(inter_fd,8) = gstor->guild_id;
375        memcpy( WFIFOP(inter_fd,12),gstor, sizeof(struct guild_storage) );
376        WFIFOSET(inter_fd,WFIFOW(inter_fd,2));
377        return 0;
378}
379
380// ƒp[ƒeƒBì¬—v‹
381int intif_create_party(struct party_member *member,char *name,int item,int item2)
382{
383        if (CheckForCharServer())
384                return 0;
385        nullpo_retr(0, member);
386
387        WFIFOHEAD(inter_fd,64);
388        WFIFOW(inter_fd,0) = 0x3020;
389        WFIFOW(inter_fd,2) = 30+sizeof(struct party_member);
390        memcpy(WFIFOP(inter_fd,4),name, NAME_LENGTH);
391        WFIFOB(inter_fd,28)= item;
392        WFIFOB(inter_fd,29)= item2;
393        memcpy(WFIFOP(inter_fd,30), member, sizeof(struct party_member));
394        WFIFOSET(inter_fd,WFIFOW(inter_fd, 2));
395        return 0;
396}
397// ƒp[ƒeƒBî•ñ—v‹
398int intif_request_partyinfo(int party_id)
399{
400        if (CheckForCharServer())
401                return 0;
402        WFIFOHEAD(inter_fd,6);
403        WFIFOW(inter_fd,0) = 0x3021;
404        WFIFOL(inter_fd,2) = party_id;
405        WFIFOSET(inter_fd,6);
406        return 0;
407}
408// ƒp[ƒeƒB’ljÁ—v‹
409int intif_party_addmember(int party_id,struct party_member *member)
410{
411        if (CheckForCharServer())
412                return 0;
413        WFIFOHEAD(inter_fd,42);
414        WFIFOW(inter_fd,0)=0x3022;
415        WFIFOW(inter_fd,2)=8+sizeof(struct party_member);
416        WFIFOL(inter_fd,4)=party_id;
417        memcpy(WFIFOP(inter_fd,8),member,sizeof(struct party_member));
418        WFIFOSET(inter_fd,WFIFOW(inter_fd, 2));
419        return 1;
420}
421// ƒp[ƒeƒBÝ’è•ύX
422int intif_party_changeoption(int party_id,int account_id,int exp,int item)
423{
424        if (CheckForCharServer())
425                return 0;
426        WFIFOHEAD(inter_fd,14);
427        WFIFOW(inter_fd,0)=0x3023;
428        WFIFOL(inter_fd,2)=party_id;
429        WFIFOL(inter_fd,6)=account_id;
430        WFIFOW(inter_fd,10)=exp;
431        WFIFOW(inter_fd,12)=item;
432        WFIFOSET(inter_fd,14);
433        return 0;
434}
435// ƒp[ƒeƒB’E‘Þ—v‹
436int intif_party_leave(int party_id,int account_id, int char_id)
437{
438        if (CheckForCharServer())
439                return 0;
440        WFIFOHEAD(inter_fd,14);
441        WFIFOW(inter_fd,0)=0x3024;
442        WFIFOL(inter_fd,2)=party_id;
443        WFIFOL(inter_fd,6)=account_id;
444        WFIFOL(inter_fd,10)=char_id;
445        WFIFOSET(inter_fd,14);
446        return 0;
447}
448// ƒp[ƒeƒBˆÚ“®—v‹
449int intif_party_changemap(struct map_session_data *sd,int online)
450{
451        if (CheckForCharServer())
452                return 0;
453        if(!sd)
454                return 0;
455
456        WFIFOHEAD(inter_fd,19);
457        WFIFOW(inter_fd,0)=0x3025;
458        WFIFOL(inter_fd,2)=sd->status.party_id;
459        WFIFOL(inter_fd,6)=sd->status.account_id;
460        WFIFOL(inter_fd,10)=sd->status.char_id;
461        WFIFOW(inter_fd,14)=sd->mapindex;
462        WFIFOB(inter_fd,16)=online;
463        WFIFOW(inter_fd,17)=sd->status.base_level;
464        WFIFOSET(inter_fd,19);
465        return 1;
466}
467// ƒp[ƒeƒB[‰ðŽU—v‹
468int intif_break_party(int party_id)
469{
470        if (CheckForCharServer())
471                return 0;
472        WFIFOHEAD(inter_fd,6);
473        WFIFOW(inter_fd,0)=0x3026;
474        WFIFOL(inter_fd,2)=party_id;
475        WFIFOSET(inter_fd,6);
476        return 0;
477}
478// ƒp[ƒeƒB‰ï˜b‘—M
479int intif_party_message(int party_id,int account_id,const char *mes,int len)
480{
481        if (CheckForCharServer())
482                return 0;
483
484        if (other_mapserver_count < 1)
485                return 0; //No need to send.
486
487        WFIFOHEAD(inter_fd,len + 12);
488        WFIFOW(inter_fd,0)=0x3027;
489        WFIFOW(inter_fd,2)=len+12;
490        WFIFOL(inter_fd,4)=party_id;
491        WFIFOL(inter_fd,8)=account_id;
492        memcpy(WFIFOP(inter_fd,12),mes,len);
493        WFIFOSET(inter_fd,len+12);
494        return 0;
495}
496// ƒp[ƒeƒB‹£‡ƒ`ƒFƒbƒN—v‹
497int intif_party_checkconflict(int party_id,int account_id,int char_id)
498{
499        if (CheckForCharServer())
500                return 0;
501        WFIFOHEAD(inter_fd,10 + NAME_LENGTH);
502        WFIFOW(inter_fd,0)=0x3028;
503        WFIFOL(inter_fd,2)=party_id;
504        WFIFOL(inter_fd,6)=account_id;
505        WFIFOL(inter_fd,10)=char_id;
506        WFIFOSET(inter_fd,14);
507        return 0;
508}
509
510int intif_party_leaderchange(int party_id,int account_id,int char_id)
511{
512        if (CheckForCharServer())
513                return 0;
514        WFIFOHEAD(inter_fd,14);
515        WFIFOW(inter_fd,0)=0x3029;
516        WFIFOL(inter_fd,2)=party_id;
517        WFIFOL(inter_fd,6)=account_id;
518        WFIFOL(inter_fd,10)=char_id;
519        WFIFOSET(inter_fd,14);
520        return 0;
521}
522
523
524// ƒMƒ‹ƒhì¬—v‹
525int intif_guild_create(const char *name,const struct guild_member *master)
526{
527        if (CheckForCharServer())
528                return 0;
529        nullpo_retr(0, master);
530
531        WFIFOHEAD(inter_fd,sizeof(struct guild_member)+(8+NAME_LENGTH));
532        WFIFOW(inter_fd,0)=0x3030;
533        WFIFOW(inter_fd,2)=sizeof(struct guild_member)+(8+NAME_LENGTH);
534        WFIFOL(inter_fd,4)=master->account_id;
535        memcpy(WFIFOP(inter_fd,8),name,NAME_LENGTH);
536        memcpy(WFIFOP(inter_fd,8+NAME_LENGTH),master,sizeof(struct guild_member));
537        WFIFOSET(inter_fd,WFIFOW(inter_fd,2));
538        return 0;
539}
540// ƒMƒ‹ƒhî•ñ—v‹
541int intif_guild_request_info(int guild_id)
542{
543        if (CheckForCharServer())
544                return 0;
545        WFIFOHEAD(inter_fd,6);
546        WFIFOW(inter_fd,0) = 0x3031;
547        WFIFOL(inter_fd,2) = guild_id;
548        WFIFOSET(inter_fd,6);
549        return 0;
550}
551// ƒMƒ‹ƒhƒƒ“ƒo’ljÁ—v‹
552int intif_guild_addmember(int guild_id,struct guild_member *m)
553{
554        if (CheckForCharServer())
555                return 0;
556        WFIFOHEAD(inter_fd,sizeof(struct guild_member)+8);
557        WFIFOW(inter_fd,0) = 0x3032;
558        WFIFOW(inter_fd,2) = sizeof(struct guild_member)+8;
559        WFIFOL(inter_fd,4) = guild_id;
560        memcpy(WFIFOP(inter_fd,8),m,sizeof(struct guild_member));
561        WFIFOSET(inter_fd,WFIFOW(inter_fd,2));
562        return 0;
563}
564
565int intif_guild_change_gm(int guild_id, const char* name, int len)
566{
567        if (CheckForCharServer())
568                return 0;
569        WFIFOHEAD(inter_fd, len + 8);
570        WFIFOW(inter_fd, 0)=0x3033;
571        WFIFOW(inter_fd, 2)=len+8;
572        WFIFOL(inter_fd, 4)=guild_id;
573        memcpy(WFIFOP(inter_fd,8),name,len);
574        WFIFOSET(inter_fd,len+8);
575        return 0;
576}
577
578// ƒMƒ‹ƒhƒƒ“ƒo’E‘Þ/’Ç•ú—v‹
579int intif_guild_leave(int guild_id,int account_id,int char_id,int flag,const char *mes)
580{
581        if (CheckForCharServer())
582                return 0;
583        WFIFOHEAD(inter_fd, 55);
584        WFIFOW(inter_fd, 0) = 0x3034;
585        WFIFOL(inter_fd, 2) = guild_id;
586        WFIFOL(inter_fd, 6) = account_id;
587        WFIFOL(inter_fd,10) = char_id;
588        WFIFOB(inter_fd,14) = flag;
589        safestrncpy((char*)WFIFOP(inter_fd,15),mes,40);
590        WFIFOSET(inter_fd,55);
591        return 0;
592}
593// ƒMƒ‹ƒhƒƒ“ƒo‚̃Iƒ“ƒ‰ƒCƒ“ó‹µ/LvXV—v‹
594int intif_guild_memberinfoshort(int guild_id,int account_id,int char_id,int online,int lv,int class_)
595{
596        if (CheckForCharServer())
597                return 0;
598        WFIFOHEAD(inter_fd, 19);
599        WFIFOW(inter_fd, 0) = 0x3035;
600        WFIFOL(inter_fd, 2) = guild_id;
601        WFIFOL(inter_fd, 6) = account_id;
602        WFIFOL(inter_fd,10) = char_id;
603        WFIFOB(inter_fd,14) = online;
604        WFIFOW(inter_fd,15) = lv;
605        WFIFOW(inter_fd,17) = class_;
606        WFIFOSET(inter_fd,19);
607        return 0;
608}
609// ƒMƒ‹ƒh‰ðŽU’Ê’m
610int intif_guild_break(int guild_id)
611{
612        if (CheckForCharServer())
613                return 0;
614        WFIFOHEAD(inter_fd, 6);
615        WFIFOW(inter_fd, 0) = 0x3036;
616        WFIFOL(inter_fd, 2) = guild_id;
617        WFIFOSET(inter_fd,6);
618        return 0;
619}
620// ƒMƒ‹ƒh‰ï˜b‘—M
621int intif_guild_message(int guild_id,int account_id,const char *mes,int len)
622{
623        if (CheckForCharServer())
624                return 0;
625
626        if (other_mapserver_count < 1)
627                return 0; //No need to send.
628
629        WFIFOHEAD(inter_fd, len + 12);
630        WFIFOW(inter_fd,0)=0x3037;
631        WFIFOW(inter_fd,2)=len+12;
632        WFIFOL(inter_fd,4)=guild_id;
633        WFIFOL(inter_fd,8)=account_id;
634        memcpy(WFIFOP(inter_fd,12),mes,len);
635        WFIFOSET(inter_fd,len+12);
636
637        return 0;
638}
639// ƒMƒ‹ƒhŠî–{î•ñ•ύX—v‹
640int intif_guild_change_basicinfo(int guild_id,int type,const void *data,int len)
641{
642        if (CheckForCharServer())
643                return 0;
644        WFIFOHEAD(inter_fd, len + 10);
645        WFIFOW(inter_fd,0)=0x3039;
646        WFIFOW(inter_fd,2)=len+10;
647        WFIFOL(inter_fd,4)=guild_id;
648        WFIFOW(inter_fd,8)=type;
649        memcpy(WFIFOP(inter_fd,10),data,len);
650        WFIFOSET(inter_fd,len+10);
651        return 0;
652}
653// ƒMƒ‹ƒhƒƒ“ƒoî•ñ•ύX—v‹
654int intif_guild_change_memberinfo(int guild_id,int account_id,int char_id,
655        int type,const void *data,int len)
656{
657        if (CheckForCharServer())
658                return 0;
659        WFIFOHEAD(inter_fd, len + 18);
660        WFIFOW(inter_fd, 0)=0x303a;
661        WFIFOW(inter_fd, 2)=len+18;
662        WFIFOL(inter_fd, 4)=guild_id;
663        WFIFOL(inter_fd, 8)=account_id;
664        WFIFOL(inter_fd,12)=char_id;
665        WFIFOW(inter_fd,16)=type;
666        memcpy(WFIFOP(inter_fd,18),data,len);
667        WFIFOSET(inter_fd,len+18);
668        return 0;
669}
670// ƒMƒ‹ƒh–ðE•ύX—v‹
671int intif_guild_position(int guild_id,int idx,struct guild_position *p)
672{
673        if (CheckForCharServer())
674                return 0;
675        WFIFOHEAD(inter_fd, sizeof(struct guild_position)+12);
676        WFIFOW(inter_fd,0)=0x303b;
677        WFIFOW(inter_fd,2)=sizeof(struct guild_position)+12;
678        WFIFOL(inter_fd,4)=guild_id;
679        WFIFOL(inter_fd,8)=idx;
680        memcpy(WFIFOP(inter_fd,12),p,sizeof(struct guild_position));
681        WFIFOSET(inter_fd,WFIFOW(inter_fd,2));
682        return 0;
683}
684// ƒMƒ‹ƒhƒXƒLƒ‹ƒAƒbƒv—v‹
685int intif_guild_skillup(int guild_id, int skill_num, int account_id)
686{
687        if( CheckForCharServer() )
688                return 0;
689        WFIFOHEAD(inter_fd, 14);
690        WFIFOW(inter_fd, 0)  = 0x303c;
691        WFIFOL(inter_fd, 2)  = guild_id;
692        WFIFOL(inter_fd, 6)  = skill_num;
693        WFIFOL(inter_fd, 10) = account_id;
694        WFIFOSET(inter_fd, 14);
695        return 0;
696}
697// ƒMƒ‹ƒh“¯–¿/“G‘Ηv‹
698int intif_guild_alliance(int guild_id1,int guild_id2,int account_id1,int account_id2,int flag)
699{
700        if (CheckForCharServer())
701                return 0;
702        WFIFOHEAD(inter_fd,19);
703        WFIFOW(inter_fd, 0)=0x303d;
704        WFIFOL(inter_fd, 2)=guild_id1;
705        WFIFOL(inter_fd, 6)=guild_id2;
706        WFIFOL(inter_fd,10)=account_id1;
707        WFIFOL(inter_fd,14)=account_id2;
708        WFIFOB(inter_fd,18)=flag;
709        WFIFOSET(inter_fd,19);
710        return 0;
711}
712// ƒMƒ‹ƒh’m•ύX—v‹
713int intif_guild_notice(int guild_id,const char *mes1,const char *mes2)
714{
715        if (CheckForCharServer())
716                return 0;
717        WFIFOHEAD(inter_fd,186);
718        WFIFOW(inter_fd,0)=0x303e;
719        WFIFOL(inter_fd,2)=guild_id;
720        memcpy(WFIFOP(inter_fd,6),mes1,60);
721        memcpy(WFIFOP(inter_fd,66),mes2,120);
722        WFIFOSET(inter_fd,186);
723        return 0;
724}
725// ƒMƒ‹ƒhƒGƒ“ƒuƒŒƒ€•ύX—v‹
726int intif_guild_emblem(int guild_id,int len,const char *data)
727{
728        if (CheckForCharServer())
729                return 0;
730        if(guild_id<=0 || len<0 || len>2000)
731                return 0;
732        WFIFOHEAD(inter_fd,len + 12);
733        WFIFOW(inter_fd,0)=0x303f;
734        WFIFOW(inter_fd,2)=len+12;
735        WFIFOL(inter_fd,4)=guild_id;
736        WFIFOL(inter_fd,8)=0;
737        memcpy(WFIFOP(inter_fd,12),data,len);
738        WFIFOSET(inter_fd,len+12);
739        return 0;
740}
741//Œ»Ý‚̃Mƒ‹ƒhéè—̃Mƒ‹ƒh‚𒲂ׂé
742int intif_guild_castle_dataload(int castle_id,int index)
743{
744        if (CheckForCharServer())
745                return 0;
746        WFIFOHEAD(inter_fd,5);
747        WFIFOW(inter_fd,0)=0x3040;
748        WFIFOW(inter_fd,2)=castle_id;
749        WFIFOB(inter_fd,4)=index;
750        WFIFOSET(inter_fd,5);
751        return 0;
752}
753
754//ƒMƒ‹ƒhéè—̃Mƒ‹ƒh•ύX—v‹
755int intif_guild_castle_datasave(int castle_id,int index, int value)
756{
757        if (CheckForCharServer())
758                return 0;
759        WFIFOHEAD(inter_fd,9);
760        WFIFOW(inter_fd,0)=0x3041;
761        WFIFOW(inter_fd,2)=castle_id;
762        WFIFOB(inter_fd,4)=index;
763        WFIFOL(inter_fd,5)=value;
764        WFIFOSET(inter_fd,9);
765        return 0;
766}
767
768//-----------------------------------------------------------------
769// Homunculus Packets send to Inter server [albator]
770//-----------------------------------------------------------------
771
772int intif_homunculus_create(int account_id, struct s_homunculus *sh)
773{
774        if (CheckForCharServer())
775                return 0;
776        WFIFOHEAD(inter_fd, sizeof(struct s_homunculus)+8);
777        WFIFOW(inter_fd,0) = 0x3090;
778        WFIFOW(inter_fd,2) = sizeof(struct s_homunculus)+8;
779        WFIFOL(inter_fd,4) = account_id;
780        memcpy(WFIFOP(inter_fd,8),sh,sizeof(struct s_homunculus));
781        WFIFOSET(inter_fd, WFIFOW(inter_fd,2));
782        return 0;
783}
784
785int intif_homunculus_requestload(int account_id, int homun_id)
786{
787        if (CheckForCharServer())
788                return 0;
789        WFIFOHEAD(inter_fd, 10);
790        WFIFOW(inter_fd,0) = 0x3091;
791        WFIFOL(inter_fd,2) = account_id;
792        WFIFOL(inter_fd,6) = homun_id;
793        WFIFOSET(inter_fd, 10);
794        return 1;
795}
796
797int intif_homunculus_requestsave(int account_id, struct s_homunculus* sh)
798{
799        if (CheckForCharServer())
800                return 0;
801        WFIFOHEAD(inter_fd, sizeof(struct s_homunculus)+8);
802        WFIFOW(inter_fd,0) = 0x3092;
803        WFIFOW(inter_fd,2) = sizeof(struct s_homunculus)+8;
804        WFIFOL(inter_fd,4) = account_id;
805        memcpy(WFIFOP(inter_fd,8),sh,sizeof(struct s_homunculus));
806        WFIFOSET(inter_fd, WFIFOW(inter_fd,2));
807        return 0;
808
809}
810
811int intif_homunculus_requestdelete(int homun_id)
812{
813        if (CheckForCharServer())
814                return 0;
815        WFIFOHEAD(inter_fd, 6);
816        WFIFOW(inter_fd, 0) = 0x3093;
817        WFIFOL(inter_fd,2) = homun_id;
818        WFIFOSET(inter_fd,6);
819        return 0;
820
821}
822
823
824//-----------------------------------------------------------------
825// Packets receive from inter server
826
827// Wisp/Page reception // rewritten by [Yor]
828int intif_parse_WisMessage(int fd)
829{ 
830        struct map_session_data* sd;
831        char *wisp_source;
832        char name[NAME_LENGTH];
833        int id, i;
834
835        id=RFIFOL(fd,4);
836
837        safestrncpy(name, (char*)RFIFOP(fd,32), NAME_LENGTH);
838        sd = map_nick2sd(name);
839        if(sd == NULL || strcmp(sd->status.name, name) != 0)
840        {       //Not found
841                intif_wis_replay(id,1);
842                return 0;
843        }
844        if(sd->state.ignoreAll) {
845                intif_wis_replay(id, 2);
846                return 0;
847        }
848        wisp_source = (char *) RFIFOP(fd,8); // speed up [Yor]
849        for(i=0; i < MAX_IGNORE_LIST &&
850                sd->ignore[i].name[0] != '\0' &&
851                strcmp(sd->ignore[i].name, wisp_source) != 0
852                ; i++);
853       
854        if (i < MAX_IGNORE_LIST && sd->ignore[i].name[0] != '\0')
855        {       //Ignored
856                intif_wis_replay(id, 2);
857                return 0;
858        }
859        //Success to send whisper.
860        clif_wis_message(sd->fd, wisp_source, (char*)RFIFOP(fd,56),RFIFOW(fd,2)-56);
861        intif_wis_replay(id,0);   // ‘—M¬Œ÷
862        return 0;
863}
864
865// Wisp/page transmission result reception
866int intif_parse_WisEnd(int fd)
867{
868        struct map_session_data* sd;
869
870        if (battle_config.etc_log)
871                ShowInfo("intif_parse_wisend: player: %s, flag: %d\n", RFIFOP(fd,2), RFIFOB(fd,26)); // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target
872        sd = (struct map_session_data *)map_nick2sd((char *) RFIFOP(fd,2));
873        if (sd != NULL)
874                clif_wis_end(sd->fd, RFIFOB(fd,26));
875
876        return 0;
877}
878
879static int mapif_parse_WisToGM_sub(struct map_session_data* sd,va_list va)
880{
881        int min_gm_level = va_arg(va, int);
882        char *wisp_name;
883        char *message;
884        int len;
885        if (pc_isGM(sd) < min_gm_level) return 0;
886        wisp_name = va_arg(va, char*);
887        message = va_arg(va, char*);
888        len = va_arg(va, int);
889        clif_wis_message(sd->fd, wisp_name, message, len);
890        return 1;
891}
892
893// Received wisp message from map-server via char-server for ALL gm
894// 0x3003/0x3803 <packet_len>.w <wispname>.24B <min_gm_level>.w <message>.?B
895int mapif_parse_WisToGM(int fd)
896{
897        int min_gm_level, mes_len;
898        char Wisp_name[NAME_LENGTH];
899        char mbuf[255];
900        char *message;
901
902        mes_len =  RFIFOW(fd,2) - 30;
903        message = (char *) (mes_len >= 255 ? (char *) aMallocA(mes_len) : mbuf);
904
905        min_gm_level = (int)RFIFOW(fd,28);
906        safestrncpy(Wisp_name, (char*)RFIFOP(fd,4), NAME_LENGTH);
907        safestrncpy(message, (char*)RFIFOP(fd,30), mes_len);
908        // information is sended to all online GM
909        map_foreachpc(mapif_parse_WisToGM_sub, min_gm_level, Wisp_name, message, mes_len);
910
911        if (message != mbuf)
912                aFree(message);
913        return 0;
914}
915
916// ƒAƒJƒEƒ“ƒg•ϐ”’Ê’m
917int intif_parse_Registers(int fd)
918{
919        int j,p,len,max, flag;
920        struct map_session_data *sd;
921        struct global_reg *reg;
922        int *qty;
923        int account_id = RFIFOL(fd,4), char_id = RFIFOL(fd,8);
924        struct auth_node *node = chrif_auth_check(account_id, char_id, ST_LOGIN);
925        if (node)
926                sd = node->sd;
927        else { //Normally registries should arrive for in log-in chars.
928                sd = map_id2sd(account_id);
929                if (sd && RFIFOB(fd,12) == 3 && sd->status.char_id != char_id)
930                        sd = NULL; //Character registry from another character.
931        }
932        if (!sd) return 1;
933
934        flag = (sd->save_reg.global_num == -1 || sd->save_reg.account_num == -1 || sd->save_reg.account2_num == -1);
935
936        switch (RFIFOB(fd,12)) {
937                case 3: //Character Registry
938                        reg = sd->save_reg.global;
939                        qty = &sd->save_reg.global_num;
940                        max = GLOBAL_REG_NUM;
941                break;
942                case 2: //Account Registry
943                        reg = sd->save_reg.account;
944                        qty = &sd->save_reg.account_num;
945                        max = ACCOUNT_REG_NUM;
946                break;
947                case 1: //Account2 Registry
948                        reg = sd->save_reg.account2;
949                        qty = &sd->save_reg.account2_num;
950                        max = ACCOUNT_REG2_NUM;
951                break;
952                default:
953                        ShowError("intif_parse_Registers: Unrecognized type %d\n",RFIFOB(fd,12));
954                        return 0;
955        }
956        for(j=0,p=13;j<max && p<RFIFOW(fd,2);j++){
957                sscanf((char*)RFIFOP(fd,p), "%31c%n", reg[j].str,&len);
958                reg[j].str[len]='\0';
959                p += len+1; //+1 to skip the '\0' between strings.
960                sscanf((char*)RFIFOP(fd,p), "%255c%n", reg[j].value,&len);
961                reg[j].value[len]='\0';
962                p += len+1;
963        }
964        *qty = j;
965
966        if (flag && sd->save_reg.global_num > -1 && sd->save_reg.account_num > -1 && sd->save_reg.account2_num > -1)
967                pc_reg_received(sd); //Received all registry values, execute init scripts and what-not. [Skotlex]
968        return 1;
969}
970
971// ‘qŒÉƒf[ƒ^ŽóM
972int intif_parse_LoadStorage(int fd)
973{
974        struct storage *stor;
975        struct map_session_data *sd;
976
977        sd=map_id2sd( RFIFOL(fd,4) );
978        if(sd==NULL){
979                ShowError("intif_parse_LoadStorage: user not found %d\n",RFIFOL(fd,4));
980                return 1;
981        }
982
983        stor = account2storage( RFIFOL(fd,4));
984
985        if (stor->storage_status == 1) { // Already open.. lets ignore this update
986                ShowWarning("intif_parse_LoadStorage: storage received for a client already open (User %d:%d)\n", sd->status.account_id, sd->status.char_id);
987                return 1;
988        }
989        if (stor->dirty) { // Already have storage, and it has been modified and not saved yet! Exploit! [Skotlex]
990                ShowWarning("intif_parse_LoadStorage: received storage for an already modified non-saved storage! (User %d:%d)\n", sd->status.account_id, sd->status.char_id);
991                return 1;
992        }
993        if (RFIFOW(fd,2)-8 != sizeof(struct storage)) {
994                ShowError("intif_parse_LoadStorage: data size error %d %d\n", RFIFOW(fd,2)-8, sizeof(struct storage));
995                return 1;
996        }
997        if(battle_config.save_log)
998                ShowInfo("intif_openstorage: %d\n",RFIFOL(fd,4) );
999        memcpy(stor,RFIFOP(fd,8),sizeof(struct storage));
1000        stor->dirty=0;
1001        stor->storage_status=1;
1002        sd->state.storage_flag = 1;
1003        clif_storagelist(sd,stor);
1004        clif_updatestorageamount(sd,stor);
1005
1006        return 0;
1007}
1008
1009// ‘qŒÉƒf[ƒ^‘—M¬Œ÷
1010int intif_parse_SaveStorage(int fd)
1011{
1012        if(battle_config.save_log)
1013                ShowInfo("intif_savestorage: done %d %d\n",RFIFOL(fd,2),RFIFOB(fd,6) );
1014        storage_storage_saved(RFIFOL(fd,2));
1015        return 0;
1016}
1017
1018int intif_parse_LoadGuildStorage(int fd)
1019{
1020        struct guild_storage *gstor;
1021        struct map_session_data *sd;
1022        int guild_id;
1023       
1024        guild_id = RFIFOL(fd,8);
1025        if(guild_id <= 0)
1026                return 1;
1027        sd=map_id2sd( RFIFOL(fd,4) );
1028        if(sd==NULL){
1029                ShowError("intif_parse_LoadGuildStorage: user not found %d\n",RFIFOL(fd,4));
1030                return 1;
1031        }
1032        gstor=guild2storage(guild_id);
1033        if(!gstor) {
1034                ShowWarning("intif_parse_LoadGuildStorage: error guild_id %d not exist\n",guild_id);
1035                return 1;
1036        }
1037        if (gstor->storage_status == 1) { // Already open.. lets ignore this update
1038                ShowWarning("intif_parse_LoadGuildStorage: storage received for a client already open (User %d:%d)\n", sd->status.account_id, sd->status.char_id);
1039                return 1;
1040        }
1041        if (gstor->dirty) { // Already have storage, and it has been modified and not saved yet! Exploit! [Skotlex]
1042                ShowWarning("intif_parse_LoadGuildStorage: received storage for an already modified non-saved storage! (User %d:%d)\n", sd->status.account_id, sd->status.char_id);
1043                return 1;
1044        }
1045        if( RFIFOW(fd,2)-12 != sizeof(struct guild_storage) ){
1046                ShowError("intif_parse_LoadGuildStorage: data size error %d %d\n",RFIFOW(fd,2)-12 , sizeof(struct guild_storage));
1047                gstor->storage_status = 0;
1048                return 1;
1049        }
1050        if(battle_config.save_log)
1051                ShowInfo("intif_open_guild_storage: %d\n",RFIFOL(fd,4) );
1052        memcpy(gstor,RFIFOP(fd,12),sizeof(struct guild_storage));
1053        gstor->storage_status = 1;
1054        sd->state.storage_flag = 2;
1055        clif_guildstoragelist(sd,gstor);
1056        clif_updateguildstorageamount(sd,gstor);
1057        return 0;
1058}
1059int intif_parse_SaveGuildStorage(int fd)
1060{
1061        if(battle_config.save_log) {
1062                ShowInfo("intif_save_guild_storage: done %d %d %d\n",RFIFOL(fd,2),RFIFOL(fd,6),RFIFOB(fd,10) );
1063        }
1064        storage_guild_storagesaved(/*RFIFOL(fd,2), */RFIFOL(fd,6));
1065        return 0;
1066}
1067
1068// ƒp[ƒeƒBì¬‰Â”Û
1069int intif_parse_PartyCreated(int fd)
1070{
1071        if(battle_config.etc_log)
1072                ShowInfo("intif: party created by account %d\n\n", RFIFOL(fd,2));
1073        party_created(RFIFOL(fd,2), RFIFOL(fd,6),RFIFOB(fd,10),RFIFOL(fd,11), (char *)RFIFOP(fd,15));
1074        return 0;
1075}
1076// ƒp[ƒeƒBî•ñ
1077int intif_parse_PartyInfo(int fd)
1078{
1079        if( RFIFOW(fd,2)==8){
1080                ShowWarning("intif: party noinfo %d\n",RFIFOL(fd,4));
1081                party_recv_noinfo(RFIFOL(fd,4));
1082                return 0;
1083        }
1084
1085        if( RFIFOW(fd,2)!=sizeof(struct party)+4 )
1086                ShowError("intif: party info : data size error %d %d %d\n",RFIFOL(fd,4),RFIFOW(fd,2),sizeof(struct party)+4);
1087        party_recv_info((struct party *)RFIFOP(fd,4));
1088        return 0;
1089}
1090// ƒp[ƒeƒB’ljÁ’Ê’m
1091int intif_parse_PartyMemberAdded(int fd)
1092{
1093        if(battle_config.etc_log)
1094                ShowInfo("intif: party member added Party (%d), Account(%d), Char(%d)\n",RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10));
1095        party_member_added(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10), RFIFOB(fd, 14));
1096        return 0;
1097}
1098// ƒp[ƒeƒBÝ’è•ύX’Ê’m
1099int intif_parse_PartyOptionChanged(int fd)
1100{
1101        party_optionchanged(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOW(fd,10),RFIFOW(fd,12),RFIFOB(fd,14));
1102        return 0;
1103}
1104// ƒp[ƒeƒB’E‘Þ’Ê’m
1105int intif_parse_PartyMemberLeaved(int fd)
1106{
1107        if(battle_config.etc_log)
1108                ShowInfo("intif: party member leaved: Party(%d), Account(%d), Char(%d)\n",RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10));
1109        party_member_leaved(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10));
1110        return 0;
1111}
1112// ƒp[ƒeƒB‰ðŽU’Ê’m
1113int intif_parse_PartyBroken(int fd)
1114{
1115        party_broken(RFIFOL(fd,2));
1116        return 0;
1117}
1118// ƒp[ƒeƒBˆÚ“®’Ê’m
1119int intif_parse_PartyMove(int fd)
1120{
1121        party_recv_movemap(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),RFIFOW(fd,14),RFIFOB(fd,16),RFIFOW(fd,17));
1122        return 0;
1123}
1124// ƒp[ƒeƒBƒƒbƒZ[ƒW
1125int intif_parse_PartyMessage(int fd)
1126{
1127        party_recv_message(RFIFOL(fd,4),RFIFOL(fd,8),(char *) RFIFOP(fd,12),RFIFOW(fd,2)-12);
1128        return 0;
1129}
1130
1131// ƒMƒ‹ƒhì¬‰Â”Û
1132int intif_parse_GuildCreated(int fd)
1133{
1134        guild_created(RFIFOL(fd,2),RFIFOL(fd,6));
1135        return 0;
1136}
1137// ƒMƒ‹ƒhî•ñ
1138int intif_parse_GuildInfo(int fd)
1139{
1140        if(RFIFOW(fd,2) == 8) {
1141                ShowWarning("intif: guild noinfo %d\n",RFIFOL(fd,4));
1142                guild_recv_noinfo(RFIFOL(fd,4));
1143                return 0;
1144        }
1145
1146        if( RFIFOW(fd,2)!=sizeof(struct guild)+4 )
1147                ShowError("intif: guild info : data size error Gid: %d recv size: %d Expected size: %d\n",RFIFOL(fd,4),RFIFOW(fd,2),sizeof(struct guild)+4);
1148        guild_recv_info((struct guild *)RFIFOP(fd,4));
1149        return 0;
1150}
1151// ƒMƒ‹ƒhƒƒ“ƒo’ljÁ’Ê’m
1152int intif_parse_GuildMemberAdded(int fd)
1153{
1154        if(battle_config.etc_log)
1155                ShowInfo("intif: guild member added %d %d %d %d\n",RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),RFIFOB(fd,14));
1156        guild_member_added(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),RFIFOB(fd,14));
1157        return 0;
1158}
1159// ƒMƒ‹ƒhƒƒ“ƒo’E‘Þ/’Ç•ú’Ê’m
1160int intif_parse_GuildMemberLeaved(int fd)
1161{
1162        guild_member_leaved(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),RFIFOB(fd,14),(char *)RFIFOP(fd,55),(char *)RFIFOP(fd,15));
1163        return 0;
1164}
1165
1166// ƒMƒ‹ƒhƒƒ“ƒoƒIƒ“ƒ‰ƒCƒ“ó‘Ô/Lv•ύX’Ê’m
1167int intif_parse_GuildMemberInfoShort(int fd)
1168{
1169        guild_recv_memberinfoshort(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),RFIFOB(fd,14),RFIFOW(fd,15),RFIFOW(fd,17));
1170        return 0;
1171}
1172// ƒMƒ‹ƒh‰ðŽU’Ê’m
1173int intif_parse_GuildBroken(int fd)
1174{
1175        guild_broken(RFIFOL(fd,2),RFIFOB(fd,6));
1176        return 0;
1177}
1178
1179// basic guild info change notice
1180// 0x3839 <packet len>.w <guild id>.l <type>.w <data>.?b
1181int intif_parse_GuildBasicInfoChanged(int fd)
1182{
1183        //int len = RFIFOW(fd,2) - 10;
1184        int guild_id = RFIFOL(fd,4);
1185        int type = RFIFOW(fd,8);
1186        //void* data = RFIFOP(fd,10);
1187
1188        struct guild* g = guild_search(guild_id);
1189        if( g == NULL )
1190                return 0;
1191
1192        switch(type) {
1193        case GBI_EXP:        g->exp = RFIFOL(fd,10); break;
1194        case GBI_GUILDLV:    g->guild_lv = RFIFOW(fd,10); break;
1195        case GBI_SKILLPOINT: g->skill_point = RFIFOL(fd,10); break;
1196        }
1197
1198        return 0;
1199}
1200
1201// guild member info change notice
1202// 0x383a <packet len>.w <guild id>.l <account id>.l <char id>.l <type>.w <data>.?b
1203int intif_parse_GuildMemberInfoChanged(int fd)
1204{
1205        //int len = RFIFOW(fd,2) - 18;
1206        int guild_id = RFIFOL(fd,4);
1207        int account_id = RFIFOL(fd,8);
1208        int char_id = RFIFOL(fd,12);
1209        int type = RFIFOW(fd,16);
1210        void* data = RFIFOP(fd,18);
1211        int dd = *((int *)data);
1212
1213        struct guild* g;
1214        int idx;
1215
1216        g = guild_search(guild_id);
1217        if( g == NULL )
1218                return 0;
1219
1220        idx = guild_getindex(g,account_id,char_id);
1221        if( idx == -1 )
1222                return 0;
1223
1224        switch( type ) {
1225        case GMI_POSITION:   g->member[idx].position = dd; guild_memberposition_changed(g,idx,dd); break;
1226        case GMI_EXP:        g->member[idx].exp = dd; break;
1227        case GMI_HAIR:       g->member[idx].hair = dd; break;
1228        case GMI_HAIR_COLOR: g->member[idx].hair_color = dd; break;
1229        case GMI_GENDER:     g->member[idx].gender = dd; break;
1230        case GMI_CLASS:      g->member[idx].class_ = dd; break;
1231        case GMI_LEVEL:      g->member[idx].lv = dd; break;
1232        }
1233        return 0;
1234}
1235
1236// ƒMƒ‹ƒh–ðE•ύX’Ê’m
1237int intif_parse_GuildPosition(int fd)
1238{
1239        if( RFIFOW(fd,2)!=sizeof(struct guild_position)+12 )
1240                ShowError("intif: guild info : data size error\n %d %d %d",RFIFOL(fd,4),RFIFOW(fd,2),sizeof(struct guild_position)+12);
1241        guild_position_changed(RFIFOL(fd,4),RFIFOL(fd,8),(struct guild_position *)RFIFOP(fd,12));
1242        return 0;
1243}
1244// ƒMƒ‹ƒhƒXƒLƒ‹Š„‚èU‚è’Ê’m
1245int intif_parse_GuildSkillUp(int fd)
1246{
1247        guild_skillupack(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10));
1248        return 0;
1249}
1250// ƒMƒ‹ƒh“¯–¿/“G‘Î’Ê’m
1251int intif_parse_GuildAlliance(int fd)
1252{
1253        guild_allianceack(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),RFIFOL(fd,14),RFIFOB(fd,18),(char *) RFIFOP(fd,19),(char *) RFIFOP(fd,43));
1254        return 0;
1255}
1256// ƒMƒ‹ƒh’m•ύX’Ê’m
1257int intif_parse_GuildNotice(int fd)
1258{
1259        guild_notice_changed(RFIFOL(fd,2),(char *) RFIFOP(fd,6),(char *) RFIFOP(fd,66));
1260        return 0;
1261}
1262// ƒMƒ‹ƒhƒGƒ“ƒuƒŒƒ€•ύX’Ê’m
1263int intif_parse_GuildEmblem(int fd)
1264{
1265        guild_emblem_changed(RFIFOW(fd,2)-12,RFIFOL(fd,4),RFIFOL(fd,8), (char *)RFIFOP(fd,12));
1266        return 0;
1267}
1268// ƒMƒ‹ƒh‰ï˜bŽóM
1269int intif_parse_GuildMessage(int fd)
1270{
1271        guild_recv_message(RFIFOL(fd,4),RFIFOL(fd,8),(char *) RFIFOP(fd,12),RFIFOW(fd,2)-12);
1272        return 0;
1273}
1274// ƒMƒ‹ƒhéƒf[ƒ^—v‹•ԐM
1275int intif_parse_GuildCastleDataLoad(int fd)
1276{
1277        return guild_castledataloadack(RFIFOW(fd,2),RFIFOB(fd,4),RFIFOL(fd,5));
1278}
1279// ƒMƒ‹ƒhéƒf[ƒ^•ύX’Ê’m
1280int intif_parse_GuildCastleDataSave(int fd)
1281{
1282        return guild_castledatasaveack(RFIFOW(fd,2),RFIFOB(fd,4),RFIFOL(fd,5));
1283}
1284
1285// ƒMƒ‹ƒhéƒf[ƒ^ˆêЇŽóM(‰Šú‰»Žž)
1286int intif_parse_GuildCastleAllDataLoad(int fd)
1287{
1288        return guild_castlealldataload(RFIFOW(fd,2),(struct guild_castle *)RFIFOP(fd,4));
1289}
1290
1291int intif_parse_GuildMasterChanged(int fd)
1292{
1293        return guild_gm_changed(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10));
1294}
1295
1296// pet
1297int intif_parse_CreatePet(int fd)
1298{
1299        pet_get_egg(RFIFOL(fd,2),RFIFOL(fd,7),RFIFOB(fd,6));
1300        return 0;
1301}
1302
1303int intif_parse_RecvPetData(int fd)
1304{
1305        struct s_pet p;
1306        int len;
1307        len=RFIFOW(fd,2);
1308        if(sizeof(struct s_pet)!=len-9) {
1309                if(battle_config.etc_log)
1310                        ShowError("intif: pet data: data size error %d %d\n",sizeof(struct s_pet),len-9);
1311        }
1312        else{
1313                memcpy(&p,RFIFOP(fd,9),sizeof(struct s_pet));
1314                pet_recv_petdata(RFIFOL(fd,4),&p,RFIFOB(fd,8));
1315        }
1316
1317        return 0;
1318}
1319int intif_parse_SavePetOk(int fd)
1320{
1321        if(RFIFOB(fd,6) == 1)
1322                ShowError("pet data save failure\n");
1323
1324        return 0;
1325}
1326
1327int intif_parse_DeletePetOk(int fd)
1328{
1329        if(RFIFOB(fd,2) == 1)
1330                ShowError("pet data delete failure\n");
1331
1332        return 0;
1333}
1334
1335int intif_parse_ChangeNameOk(int fd)
1336{
1337        struct map_session_data *sd = NULL;
1338        if((sd=map_id2sd(RFIFOL(fd,2)))==NULL ||
1339                sd->status.char_id != RFIFOL(fd,6))
1340                return 0;
1341
1342        switch (RFIFOB(fd,10)) {
1343        case 0: //Players [NOT SUPPORTED YET]
1344                break;
1345        case 1: //Pets
1346                pet_change_name_ack(sd, (char*)RFIFOP(fd,12), RFIFOB(fd,11));
1347                break;
1348        case 2: //Hom
1349                merc_hom_change_name_ack(sd, (char*)RFIFOP(fd,12), RFIFOB(fd,11));
1350                break;
1351        }
1352        return 0;
1353}
1354
1355//----------------------------------------------------------------
1356// Homunculus recv packets [albator]
1357
1358int intif_parse_CreateHomunculus(int fd)
1359{
1360        int len;
1361        len=RFIFOW(fd,2)-9;
1362        if(sizeof(struct s_homunculus)!=len) {
1363                if(battle_config.etc_log)
1364                        ShowError("intif: create homun data: data size error %d != %d\n",sizeof(struct s_homunculus),len);
1365                return 0;
1366        }
1367        merc_hom_recv_data(RFIFOL(fd,4), (struct s_homunculus*)RFIFOP(fd,9), RFIFOB(fd,8)) ;
1368        return 0;
1369}
1370
1371int intif_parse_RecvHomunculusData(int fd)
1372{
1373        int len;
1374
1375        len=RFIFOW(fd,2)-9;
1376
1377        if(sizeof(struct s_homunculus)!=len) {
1378                if(battle_config.etc_log)
1379                        ShowError("intif: homun data: data size error %d %d\n",sizeof(struct s_homunculus),len);
1380                return 0;
1381        }
1382        merc_hom_recv_data(RFIFOL(fd,4), (struct s_homunculus*)RFIFOP(fd,9), RFIFOB(fd,8));
1383        return 0;
1384}
1385
1386int intif_parse_SaveHomunculusOk(int fd)
1387{
1388        if(RFIFOB(fd,6) != 1)
1389                ShowError("homunculus data save failure for account %d\n", RFIFOL(fd,2));
1390
1391        return 0;
1392}
1393
1394int intif_parse_DeleteHomunculusOk(int fd)
1395{
1396        if(RFIFOB(fd,2) != 1)
1397                ShowError("Homunculus data delete failure\n");
1398
1399        return 0;
1400}
1401
1402/**************************************
1403
1404QUESTLOG SYSTEM FUNCTIONS
1405
1406***************************************/
1407
1408int intif_request_questlog(TBL_PC *sd)
1409{
1410        WFIFOHEAD(inter_fd,6);
1411        WFIFOW(inter_fd,0) = 0x3060;
1412        WFIFOL(inter_fd,2) = sd->status.char_id;
1413        WFIFOSET(inter_fd,6);
1414        return 0;
1415}
1416
1417int intif_parse_questlog(int fd)
1418{
1419
1420        int num_quests = (RFIFOB(fd, 2)-8)/sizeof(struct quest);
1421        int char_id = RFIFOL(fd, 4);
1422        int i;
1423        TBL_PC * sd = map_charid2sd(char_id);
1424
1425        //User not online anymore
1426        if(!sd)
1427                return 0;
1428
1429        for(i=0; i<num_quests; i++)
1430        {
1431                memcpy(&sd->quest_log[i], RFIFOP(fd, i*sizeof(struct quest)+8), sizeof(struct quest));
1432        }
1433        sd->num_quests = num_quests;
1434
1435        return 0;
1436}
1437
1438int intif_parse_questDelete(int fd)
1439{
1440        quest_delete_ack(RFIFOL(fd, 2), RFIFOL(fd, 6), RFIFOB(fd, 10));
1441        return 0;
1442}
1443
1444int intif_quest_delete(int char_id, int quest_id)
1445{
1446        if(CheckForCharServer())
1447                return 0;
1448
1449        WFIFOHEAD(inter_fd, 10);
1450        WFIFOW(inter_fd,0) = 0x3062;
1451        WFIFOL(inter_fd,2) = char_id;
1452        WFIFOL(inter_fd,6) = quest_id;
1453        WFIFOSET(inter_fd, 10);
1454
1455        return 0;
1456}
1457
1458int intif_parse_questAdd(int fd)
1459{
1460        quest_add_ack(RFIFOL(fd, 2), RFIFOL(fd, 6), RFIFOB(fd, 10));
1461        return 0;
1462}
1463
1464int intif_quest_add(int char_id, struct quest * qd)
1465{
1466
1467        if(CheckForCharServer())
1468                return 0;
1469
1470        WFIFOHEAD(inter_fd, sizeof(struct quest) + 8);
1471        WFIFOW(inter_fd,0) = 0x3061;
1472        WFIFOW(inter_fd,2) = sizeof(struct quest) + 8;
1473        WFIFOL(inter_fd,4) = char_id;
1474        memcpy(WFIFOP(inter_fd,8), qd, sizeof(struct quest));
1475        WFIFOSET(inter_fd,  WFIFOW(inter_fd,2));
1476
1477        return 0;
1478}
1479
1480#ifndef TXT_ONLY
1481
1482/*==========================================
1483 * MAIL SYSTEM
1484 * By Zephyrus
1485 *==========================================*/
1486
1487/*------------------------------------------
1488 * Inbox Request
1489 * flag: 0 Update Inbox | 1 OpenMail
1490 *------------------------------------------*/
1491int intif_Mail_requestinbox(int char_id, unsigned char flag)
1492{
1493        if (CheckForCharServer())
1494                return 0;
1495
1496        WFIFOHEAD(inter_fd,7);
1497        WFIFOW(inter_fd,0) = 0x3048;
1498        WFIFOL(inter_fd,2) = char_id;
1499        WFIFOB(inter_fd,6) = flag;
1500        WFIFOSET(inter_fd,7);
1501
1502        return 0;
1503}
1504
1505int intif_parse_Mail_inboxreceived(int fd)
1506{
1507        struct map_session_data *sd;
1508        unsigned char flag = RFIFOB(fd,8);
1509
1510        sd = map_charid2sd(RFIFOL(fd,4));
1511
1512        if (sd == NULL)
1513        {
1514                ShowError("intif_parse_Mail_inboxreceived: char not found %d\n",RFIFOL(fd,4));
1515                return 1;
1516        }
1517
1518        if (RFIFOW(fd,2) - 9 != sizeof(struct mail_data))
1519        {
1520                ShowError("intif_parse_Mail_inboxreceived: data size error %d %d\n", RFIFOW(fd,2) - 9, sizeof(struct mail_data));
1521                return 1;
1522        }
1523
1524        //FIXME: this operation is not safe [ultramage]
1525        memcpy(&sd->mail.inbox, RFIFOP(fd,9), sizeof(struct mail_data));
1526
1527        if (flag)
1528                clif_Mail_refreshinbox(sd);
1529        else
1530        {
1531                char output[128];
1532                sprintf(output, "You have %d new emails (%d unread)", sd->mail.inbox.unchecked, sd->mail.inbox.unread + sd->mail.inbox.unchecked);
1533                clif_disp_onlyself(sd, output, strlen(output));
1534        }
1535        return 0;
1536}
1537/*------------------------------------------
1538 * Mail Readed
1539 *------------------------------------------*/
1540int intif_Mail_read(int mail_id)
1541{
1542        if (CheckForCharServer())
1543                return 0;
1544
1545        WFIFOHEAD(inter_fd,6);
1546        WFIFOW(inter_fd,0) = 0x3049;
1547        WFIFOL(inter_fd,2) = mail_id;
1548        WFIFOSET(inter_fd,6);
1549
1550        return 0;
1551}
1552/*------------------------------------------
1553 * Get Attachment
1554 *------------------------------------------*/
1555int intif_Mail_getattach(int char_id, int mail_id)
1556{
1557        if (CheckForCharServer())
1558                return 0;
1559
1560        WFIFOHEAD(inter_fd,10);
1561        WFIFOW(inter_fd,0) = 0x304a;
1562        WFIFOL(inter_fd,2) = char_id;
1563        WFIFOL(inter_fd,6) = mail_id;
1564        WFIFOSET(inter_fd, 10);
1565
1566        return 0;
1567}
1568
1569int intif_parse_Mail_getattach(int fd)
1570{
1571        struct map_session_data *sd;
1572        struct item item;
1573        int zeny = RFIFOL(fd,8);
1574
1575        sd = map_charid2sd( RFIFOL(fd,4) );
1576
1577        if (sd == NULL)
1578        {
1579                ShowError("intif_parse_Mail_getattach: char not found %d\n",RFIFOL(fd,4));
1580                return 1;
1581        }
1582
1583        if (RFIFOW(fd,2) - 12 != sizeof(struct item))
1584        {
1585                ShowError("intif_parse_Mail_getattach: data size error %d %d\n", RFIFOW(fd,2) - 16, sizeof(struct item));
1586                return 1;
1587        }
1588
1589        memcpy(&item, RFIFOP(fd,12), sizeof(struct item));
1590
1591        mail_getattachment(sd, zeny, &item);
1592        return 0;
1593}
1594/*------------------------------------------
1595 * Delete Message
1596 *------------------------------------------*/
1597int intif_Mail_delete(int char_id, int mail_id)
1598{
1599        if (CheckForCharServer())
1600                return 0;
1601
1602        WFIFOHEAD(inter_fd,10);
1603        WFIFOW(inter_fd,0) = 0x304b;
1604        WFIFOL(inter_fd,2) = char_id;
1605        WFIFOL(inter_fd,6) = mail_id;
1606        WFIFOSET(inter_fd,10);
1607
1608        return 0;
1609}
1610
1611int intif_parse_Mail_delete(int fd)
1612{
1613        int char_id = RFIFOL(fd,2);
1614        int mail_id = RFIFOL(fd,6);
1615        bool failed = RFIFOB(fd,10);
1616
1617        struct map_session_data *sd = map_charid2sd(char_id);
1618        if (sd == NULL)
1619        {
1620                ShowError("intif_parse_Mail_delete: char not found %d\n", char_id);
1621                return 1;
1622        }
1623
1624        if (!failed)
1625        {
1626                int i;
1627                ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
1628                if( i < MAIL_MAX_INBOX )
1629                {
1630                        memset(&sd->mail.inbox.msg[i], 0, sizeof(struct mail_message));
1631                        sd->mail.inbox.amount--;
1632                }
1633
1634                if( sd->mail.inbox.full )
1635                        intif_Mail_requestinbox(sd->status.char_id, 1); // Free space is available for new mails
1636        }
1637
1638        clif_Mail_delete(sd->fd, mail_id, failed);
1639        return 0;
1640}
1641/*------------------------------------------
1642 * Return Message
1643 *------------------------------------------*/
1644int intif_Mail_return(int char_id, int mail_id)
1645{
1646        if (CheckForCharServer())
1647                return 0;
1648
1649        WFIFOHEAD(inter_fd,10);
1650        WFIFOW(inter_fd,0) = 0x304c;
1651        WFIFOL(inter_fd,2) = char_id;
1652        WFIFOL(inter_fd,6) = mail_id;
1653        WFIFOSET(inter_fd,10);
1654
1655        return 0;
1656}
1657
1658int intif_parse_Mail_return(int fd)
1659{
1660        struct map_session_data *sd = map_charid2sd(RFIFOL(fd,2));
1661        int mail_id = RFIFOL(fd,6);
1662        short fail = RFIFOB(fd,10);
1663
1664        if( sd == NULL )
1665        {
1666                ShowError("intif_parse_Mail_return: char not found %d\n",RFIFOL(fd,2));
1667                return 1;
1668        }
1669
1670        if( !fail )
1671        {
1672                int i;
1673                ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
1674                if( i < MAIL_MAX_INBOX )
1675                {
1676                        memset(&sd->mail.inbox.msg[i], 0, sizeof(struct mail_message));
1677                        sd->mail.inbox.amount--;
1678                }
1679
1680                if( sd->mail.inbox.full )
1681                        intif_Mail_requestinbox(sd->status.char_id, 1); // Free space is available for new mails
1682        }
1683
1684        clif_Mail_return(sd->fd, mail_id, fail);
1685        return 0;
1686}
1687/*------------------------------------------
1688 * Send Mail
1689 *------------------------------------------*/
1690int intif_Mail_send(int account_id, struct mail_message *msg)
1691{
1692        int len = sizeof(struct mail_message) + 8;
1693
1694        if (CheckForCharServer())
1695                return 0;
1696
1697        WFIFOHEAD(inter_fd,len);
1698        WFIFOW(inter_fd,0) = 0x304d;
1699        WFIFOW(inter_fd,2) = len;
1700        WFIFOL(inter_fd,4) = account_id;
1701        memcpy(WFIFOP(inter_fd,8), msg, sizeof(struct mail_message));
1702        WFIFOSET(inter_fd,len);
1703
1704        return 1;
1705}
1706
1707static void intif_parse_Mail_send(int fd)
1708{
1709        struct mail_message msg;
1710        struct map_session_data *sd;
1711        bool fail;
1712
1713        if( RFIFOW(fd,2) - 4 != sizeof(struct mail_message) )
1714        {
1715                ShowError("intif_parse_Mail_send: data size error %d %d\n", RFIFOW(fd,2) - 4, sizeof(struct mail_message));
1716                return;
1717        }
1718
1719        memcpy(&msg, RFIFOP(fd,4), sizeof(struct mail_message));
1720        fail = (msg.id == 0);
1721
1722        if( (sd = map_charid2sd(msg.send_id)) )
1723        {
1724                if( fail )
1725                        mail_deliveryfail(sd, &msg);
1726                else
1727                {
1728                        clif_Mail_send(sd->fd, false);
1729                        if( save_settings&16 )
1730                                chrif_save(sd, 0);
1731                }
1732        }
1733
1734        if( fail )
1735                return;
1736
1737        if( (sd = map_charid2sd(msg.dest_id)) )
1738        {
1739                sd->mail.inbox.changed = true;
1740                clif_Mail_new(sd->fd, msg.id, msg.send_name, msg.title);
1741        }
1742}
1743
1744static void intif_parse_Mail_new(int fd)
1745{
1746        struct map_session_data *sd = map_charid2sd(RFIFOL(fd,2));
1747        int mail_id = RFIFOL(fd,6);
1748        const char* sender_name = (char*)RFIFOP(fd,10);
1749        const char* title = (char*)RFIFOP(fd,34);
1750
1751        if( sd == NULL )
1752                return;
1753
1754        sd->mail.inbox.changed = true;
1755        clif_Mail_new(sd->fd, mail_id, sender_name, title);
1756}
1757
1758/*==========================================
1759 * AUCTION SYSTEM
1760 * By Zephyrus
1761 *==========================================*/
1762int intif_Auction_requestlist(int char_id, short type, int price, const char* searchtext, short page)
1763{
1764        int len = NAME_LENGTH + 16;
1765
1766        if( CheckForCharServer() )
1767                return 0;
1768
1769        WFIFOHEAD(inter_fd,len);
1770        WFIFOW(inter_fd,0) = 0x3050;
1771        WFIFOW(inter_fd,2) = len;
1772        WFIFOL(inter_fd,4) = char_id;
1773        WFIFOW(inter_fd,8) = type;
1774        WFIFOL(inter_fd,10) = price;
1775        WFIFOW(inter_fd,14) = page;
1776        memcpy(WFIFOP(inter_fd,16), searchtext, NAME_LENGTH);
1777        WFIFOSET(inter_fd,len);
1778
1779        return 0;
1780}
1781
1782static void intif_parse_Auction_results(int fd)
1783{
1784        struct map_session_data *sd = map_charid2sd(RFIFOL(fd,4));
1785        short count = RFIFOW(fd,8);
1786        short pages = RFIFOW(fd,10);
1787        uint8* data = RFIFOP(fd,12);
1788
1789        if( sd == NULL )
1790                return;
1791
1792        clif_Auction_results(sd, count, pages, data);
1793}
1794
1795int intif_Auction_register(struct auction_data *auction)
1796{
1797        int len = sizeof(struct auction_data) + 4;
1798       
1799        if( CheckForCharServer() )
1800                return 0;
1801
1802        WFIFOHEAD(inter_fd,len);
1803        WFIFOW(inter_fd,0) = 0x3051;
1804        WFIFOW(inter_fd,2) = len;
1805        memcpy(WFIFOP(inter_fd,4), auction, sizeof(struct auction_data));
1806        WFIFOSET(inter_fd,len);
1807       
1808        return 1;
1809}
1810
1811static void intif_parse_Auction_register(int fd)
1812{
1813        struct map_session_data *sd;
1814        struct auction_data auction;
1815
1816        if( RFIFOW(fd,2) - 4 != sizeof(struct auction_data) )
1817        {
1818                ShowError("intif_parse_Auction_register: data size error %d %d\n", RFIFOW(fd,2) - 4, sizeof(struct auction_data));
1819                return;
1820        }
1821
1822        memcpy(&auction, RFIFOP(fd,4), sizeof(struct auction_data));
1823        if( (sd = map_charid2sd(auction.seller_id)) == NULL )
1824                return;
1825
1826        if( auction.auction_id > 0 )
1827        {
1828                clif_Auction_message(sd->fd, 1); // Confirmation Packet ??
1829                if( save_settings&32 )
1830                        chrif_save(sd,0);
1831        }
1832        else
1833        {
1834                clif_Auction_message(sd->fd, 4);
1835                pc_additem(sd, &auction.item, auction.item.amount);
1836                pc_getzeny(sd, auction.hours * battle_config.auction_feeperhour);
1837        }
1838}
1839
1840int intif_Auction_cancel(int char_id, unsigned int auction_id)
1841{
1842        if( CheckForCharServer() )
1843                return 0;
1844
1845        WFIFOHEAD(inter_fd,10);
1846        WFIFOW(inter_fd,0) = 0x3052;
1847        WFIFOL(inter_fd,2) = char_id;
1848        WFIFOL(inter_fd,6) = auction_id;
1849        WFIFOSET(inter_fd,10);
1850
1851        return 0;
1852}
1853
1854static void intif_parse_Auction_cancel(int fd)
1855{
1856        struct map_session_data *sd = map_charid2sd(RFIFOL(fd,2));
1857        int result = RFIFOB(fd,6);
1858
1859        if( sd == NULL )
1860                return;
1861
1862        switch( result )
1863        {
1864        case 0: clif_Auction_message(sd->fd, 2); break;
1865        case 1: clif_Auction_close(sd->fd, 2); break;
1866        case 2: clif_Auction_close(sd->fd, 1); break;
1867        case 3: clif_Auction_message(sd->fd, 3); break;
1868        }
1869}
1870
1871int intif_Auction_close(int char_id, unsigned int auction_id)
1872{
1873        if( CheckForCharServer() )
1874                return 0;
1875
1876        WFIFOHEAD(inter_fd,10);
1877        WFIFOW(inter_fd,0) = 0x3053;
1878        WFIFOL(inter_fd,2) = char_id;
1879        WFIFOL(inter_fd,6) = auction_id;
1880        WFIFOSET(inter_fd,10);
1881
1882        return 0;
1883}
1884
1885static void intif_parse_Auction_close(int fd)
1886{
1887        struct map_session_data *sd = map_charid2sd(RFIFOL(fd,2));
1888        unsigned char result = RFIFOB(fd,6);
1889
1890        if( sd == NULL )
1891                return;
1892
1893        clif_Auction_close(sd->fd, result);
1894        if( result == 0 )
1895        {
1896                clif_parse_Auction_cancelreg(fd, sd);
1897                intif_Auction_requestlist(sd->status.char_id, 6, 0, "", 1);
1898        }
1899}
1900
1901int intif_Auction_bid(int char_id, const char* name, unsigned int auction_id, int bid)
1902{
1903        int len = 16 + NAME_LENGTH;
1904
1905        if( CheckForCharServer() )
1906                return 0;
1907
1908        WFIFOHEAD(inter_fd,len);
1909        WFIFOW(inter_fd,0) = 0x3055;
1910        WFIFOW(inter_fd,2) = len;
1911        WFIFOL(inter_fd,4) = char_id;
1912        WFIFOL(inter_fd,8) = auction_id;
1913        WFIFOL(inter_fd,12) = bid;
1914        memcpy(WFIFOP(inter_fd,16), name, NAME_LENGTH);
1915        WFIFOSET(inter_fd,len);
1916
1917        return 0;
1918}
1919
1920static void intif_parse_Auction_bid(int fd)
1921{
1922        struct map_session_data *sd = map_charid2sd(RFIFOL(fd,2));
1923        int bid = RFIFOL(fd,6);
1924        unsigned char result = RFIFOB(fd,10);
1925
1926        if( sd == NULL )
1927                return;
1928
1929        clif_Auction_message(sd->fd, result);
1930        if( bid > 0 )
1931                pc_getzeny(sd, bid);
1932        if( result == 1 )
1933        { // To update the list, display your buy list
1934                clif_parse_Auction_cancelreg(fd, sd);
1935                intif_Auction_requestlist(sd->status.char_id, 7, 0, "", 1);
1936        }
1937}
1938
1939// Used to send 'You have won the auction' and 'You failed to won the auction' messages
1940static void intif_parse_Auction_message(int fd)
1941{
1942        struct map_session_data *sd = map_charid2sd(RFIFOL(fd,2));
1943        unsigned char result = RFIFOB(fd,6);
1944
1945        if( sd == NULL )
1946                return;
1947
1948        clif_Auction_message(sd->fd, result);
1949}
1950
1951#endif
1952
1953//-----------------------------------------------------------------
1954// inter server‚©‚ç‚̒ʐM
1955// ƒGƒ‰[‚ª‚ ‚ê‚Î0(false)‚ð•Ô‚·‚±‚Æ
1956// ƒpƒPƒbƒg‚ªˆ—‚Å‚«‚ê‚Î1,ƒpƒPƒbƒg’·‚ª‘«‚è‚È‚¯‚ê‚Î2‚ð•Ô‚·‚±‚Æ
1957int intif_parse(int fd)
1958{
1959        int packet_len, cmd;
1960        cmd = RFIFOW(fd,0);
1961        // ƒpƒPƒbƒg‚ÌIDŠm”F
1962        if(cmd<0x3800 || cmd>=0x3800+(sizeof(packet_len_table)/sizeof(packet_len_table[0])) ||
1963           packet_len_table[cmd-0x3800]==0){
1964                return 0;
1965        }
1966        // ƒpƒPƒbƒg‚Ì’·‚³Šm”F
1967        packet_len = packet_len_table[cmd-0x3800];
1968        if(packet_len==-1){
1969                if(RFIFOREST(fd)<4)
1970                        return 2;
1971                packet_len = RFIFOW(fd,2);
1972        }
1973        if((int)RFIFOREST(fd)<packet_len){
1974                return 2;
1975        }
1976        // ˆ—•ªŠò
1977        switch(cmd){
1978        case 0x3800:
1979                if (RFIFOL(fd,4) == 0xFF000000) //Normal announce.
1980                        clif_GMmessage(NULL,(char *) RFIFOP(fd,8),packet_len-8,0);
1981                else if (RFIFOL(fd,4) == 0xFE000000) //Main chat message [LuzZza]
1982                        clif_MainChatMessage((char *)RFIFOP(fd,8));
1983                else //Color announce.
1984                        clif_announce(NULL,(char *) RFIFOP(fd,8),packet_len-8,RFIFOL(fd,4),0);
1985                break;
1986        case 0x3801:    intif_parse_WisMessage(fd); break;
1987        case 0x3802:    intif_parse_WisEnd(fd); break;
1988        case 0x3803:    mapif_parse_WisToGM(fd); break;
1989        case 0x3804:    intif_parse_Registers(fd); break;
1990        case 0x3806:    intif_parse_ChangeNameOk(fd); break;
1991        case 0x3810:    intif_parse_LoadStorage(fd); break;
1992        case 0x3811:    intif_parse_SaveStorage(fd); break;
1993        case 0x3818:    intif_parse_LoadGuildStorage(fd); break;
1994        case 0x3819:    intif_parse_SaveGuildStorage(fd); break;
1995        case 0x3820:    intif_parse_PartyCreated(fd); break;
1996        case 0x3821:    intif_parse_PartyInfo(fd); break;
1997        case 0x3822:    intif_parse_PartyMemberAdded(fd); break;
1998        case 0x3823:    intif_parse_PartyOptionChanged(fd); break;
1999        case 0x3824:    intif_parse_PartyMemberLeaved(fd); break;
2000        case 0x3825:    intif_parse_PartyMove(fd); break;
2001        case 0x3826:    intif_parse_PartyBroken(fd); break;
2002        case 0x3827:    intif_parse_PartyMessage(fd); break;
2003        case 0x3830:    intif_parse_GuildCreated(fd); break;
2004        case 0x3831:    intif_parse_GuildInfo(fd); break;
2005        case 0x3832:    intif_parse_GuildMemberAdded(fd); break;
2006        case 0x3834:    intif_parse_GuildMemberLeaved(fd); break;
2007        case 0x3835:    intif_parse_GuildMemberInfoShort(fd); break;
2008        case 0x3836:    intif_parse_GuildBroken(fd); break;
2009        case 0x3837:    intif_parse_GuildMessage(fd); break;
2010        case 0x3839:    intif_parse_GuildBasicInfoChanged(fd); break;
2011        case 0x383a:    intif_parse_GuildMemberInfoChanged(fd); break;
2012        case 0x383b:    intif_parse_GuildPosition(fd); break;
2013        case 0x383c:    intif_parse_GuildSkillUp(fd); break;
2014        case 0x383d:    intif_parse_GuildAlliance(fd); break;
2015        case 0x383e:    intif_parse_GuildNotice(fd); break;
2016        case 0x383f:    intif_parse_GuildEmblem(fd); break;
2017        case 0x3840:    intif_parse_GuildCastleDataLoad(fd); break;
2018        case 0x3841:    intif_parse_GuildCastleDataSave(fd); break;
2019        case 0x3842:    intif_parse_GuildCastleAllDataLoad(fd); break;
2020        case 0x3843:    intif_parse_GuildMasterChanged(fd); break;
2021
2022        //Quest system
2023        case 0x3860:    intif_parse_questlog(fd); break;
2024        case 0x3861:    intif_parse_questAdd(fd); break;
2025        case 0x3862:    intif_parse_questDelete(fd); break;
2026
2027#ifndef TXT_ONLY
2028// Mail System
2029        case 0x3848:    intif_parse_Mail_inboxreceived(fd); break;
2030        case 0x3849:    intif_parse_Mail_new(fd); break;
2031        case 0x384a:    intif_parse_Mail_getattach(fd); break;
2032        case 0x384b:    intif_parse_Mail_delete(fd); break;
2033        case 0x384c:    intif_parse_Mail_return(fd); break;
2034        case 0x384d:    intif_parse_Mail_send(fd); break;
2035// Auction System
2036        case 0x3850:    intif_parse_Auction_results(fd); break;
2037        case 0x3851:    intif_parse_Auction_register(fd); break;
2038        case 0x3852:    intif_parse_Auction_cancel(fd); break;
2039        case 0x3853:    intif_parse_Auction_close(fd); break;
2040        case 0x3854:    intif_parse_Auction_message(fd); break;
2041        case 0x3855:    intif_parse_Auction_bid(fd); break;
2042#endif
2043        case 0x3880:    intif_parse_CreatePet(fd); break;
2044        case 0x3881:    intif_parse_RecvPetData(fd); break;
2045        case 0x3882:    intif_parse_SavePetOk(fd); break;
2046        case 0x3883:    intif_parse_DeletePetOk(fd); break;
2047        case 0x3890:    intif_parse_CreateHomunculus(fd); break;
2048        case 0x3891:    intif_parse_RecvHomunculusData(fd); break;
2049        case 0x3892:    intif_parse_SaveHomunculusOk(fd); break;
2050        case 0x3893:    intif_parse_DeleteHomunculusOk(fd); break;
2051        default:
2052                ShowError("intif_parse : unknown packet %d %x\n",fd,RFIFOW(fd,0));
2053                return 0;
2054        }
2055        // ƒpƒPƒbƒg“ǂݔò‚΂µ
2056        RFIFOSKIP(fd,packet_len);
2057        return 1;
2058}
Note: See TracBrowser for help on using the browser.