intif.c 54 KB

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