char_mapif.c 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586
  1. /**
  2. * @file char_mapif.c
  3. * Module purpose is to handle incoming and outgoing requests with map-server.
  4. * Licensed under GNU GPL.
  5. * For more information, see LICENCE in the main folder.
  6. * @author Athena Dev Teams originally in login.c
  7. * @author rAthena Dev Team
  8. */
  9. #include "../common/socket.h"
  10. #include "../common/sql.h"
  11. #include "../common/malloc.h"
  12. #include "../common/showmsg.h"
  13. #include "../common/strlib.h"
  14. #include "inter.h"
  15. #include "char.h"
  16. #include "char_logif.h"
  17. #include "char_mapif.h"
  18. #include <stdlib.h>
  19. /**
  20. * Packet send to all map-servers, attach to ourself
  21. * @param buf: packet to send in form of an array buffer
  22. * @param len: size of packet
  23. * @return : the number of map-serv the packet was sent to
  24. */
  25. int chmapif_sendall(unsigned char *buf, unsigned int len){
  26. int i, c;
  27. c = 0;
  28. for(i = 0; i < ARRAYLENGTH(map_server); i++) {
  29. int fd;
  30. if ((fd = map_server[i].fd) > 0) {
  31. WFIFOHEAD(fd,len);
  32. memcpy(WFIFOP(fd,0), buf, len);
  33. WFIFOSET(fd,len);
  34. c++;
  35. }
  36. }
  37. return c;
  38. }
  39. /**
  40. * Packet send to all map-servers, except one. (wos: without our self) attach to ourself
  41. * @param sfd: fd to discard sending to
  42. * @param buf: packet to send in form of an array buffer
  43. * @param len: size of packet
  44. * @return : the number of map-serv the packet was sent to
  45. */
  46. int chmapif_sendallwos(int sfd, unsigned char *buf, unsigned int len){
  47. int i, c;
  48. c = 0;
  49. for(i = 0; i < ARRAYLENGTH(map_server); i++) {
  50. int fd;
  51. if ((fd = map_server[i].fd) > 0 && fd != sfd) {
  52. WFIFOHEAD(fd,len);
  53. memcpy(WFIFOP(fd,0), buf, len);
  54. WFIFOSET(fd,len);
  55. c++;
  56. }
  57. }
  58. return c;
  59. }
  60. /**
  61. * Packet send to all char-servers, except one. (wos: without our self)
  62. * @param fd: fd to send packet too
  63. * @param buf: packet to send in form of an array buffer
  64. * @param len: size of packet
  65. * @return : the number of map-serv the packet was sent to (O|1)
  66. */
  67. int chmapif_send(int fd, unsigned char *buf, unsigned int len){
  68. if (fd >= 0) {
  69. int i;
  70. ARR_FIND( 0, ARRAYLENGTH(map_server), i, fd == map_server[i].fd );
  71. if( i < ARRAYLENGTH(map_server) )
  72. {
  73. WFIFOHEAD(fd,len);
  74. memcpy(WFIFOP(fd,0), buf, len);
  75. WFIFOSET(fd,len);
  76. return 1;
  77. }
  78. }
  79. return 0;
  80. }
  81. /**
  82. * Send map-servers fames ranking lists
  83. * Defaut fame list are 32B, (id+point+names)
  84. * S <len>.W <len bs + alchi>.W <len bs>.W <smith_rank>?B <alchi_rank>?B <taek_rank>?B
  85. * @param fd: fd to send packet too (map-serv) if -1 send to all
  86. * @return : 0 success
  87. */
  88. int chmapif_send_fame_list(int fd){
  89. int i, len = 8;
  90. unsigned char buf[32000];
  91. WBUFW(buf,0) = 0x2b1b;
  92. for(i = 0; i < fame_list_size_smith && smith_fame_list[i].id; i++) {
  93. memcpy(WBUFP(buf, len), &smith_fame_list[i], sizeof(struct fame_list));
  94. len += sizeof(struct fame_list);
  95. }
  96. // add blacksmith's block length
  97. WBUFW(buf, 6) = len;
  98. for(i = 0; i < fame_list_size_chemist && chemist_fame_list[i].id; i++) {
  99. memcpy(WBUFP(buf, len), &chemist_fame_list[i], sizeof(struct fame_list));
  100. len += sizeof(struct fame_list);
  101. }
  102. // add alchemist's block length
  103. WBUFW(buf, 4) = len;
  104. for(i = 0; i < fame_list_size_taekwon && taekwon_fame_list[i].id; i++) {
  105. memcpy(WBUFP(buf, len), &taekwon_fame_list[i], sizeof(struct fame_list));
  106. len += sizeof(struct fame_list);
  107. }
  108. // add total packet length
  109. WBUFW(buf, 2) = len;
  110. if (fd != -1)
  111. chmapif_send(fd, buf, len);
  112. else
  113. chmapif_sendall(buf, len);
  114. return 0;
  115. }
  116. /**
  117. * Send to map-servers the updated fame ranking lists
  118. * We actually just send this one when we only need to update rankpoint but pos didn't change
  119. * @param type: ranking type
  120. * @param index: position in the ranking
  121. * @param fame: number of points
  122. */
  123. void chmapif_update_fame_list(int type, int index, int fame) {
  124. unsigned char buf[8];
  125. WBUFW(buf,0) = 0x2b22;
  126. WBUFB(buf,2) = type;
  127. WBUFB(buf,3) = index;
  128. WBUFL(buf,4) = fame;
  129. chmapif_sendall(buf, 8);
  130. }
  131. /**
  132. * Send to map-servers the users count on this char-serv, (meaning the total of all mapserv)
  133. * @param users: number of players on this char-serv
  134. */
  135. void chmapif_sendall_playercount(int users){
  136. uint8 buf[6];
  137. // send number of players to all map-servers
  138. WBUFW(buf,0) = 0x2b00;
  139. WBUFL(buf,2) = users;
  140. chmapif_sendall(buf,6);
  141. }
  142. /**
  143. * Send some misc info to new map-server.
  144. * - Server name for whisper name
  145. * - Default map
  146. * HZ 0x2afb <size>.W <status>.B <name>.24B <mapname>.11B <map_x>.W <map_y>.W
  147. * @param fd
  148. **/
  149. static void chmapif_send_misc(int fd) {
  150. uint16 offs = 5;
  151. unsigned char buf[45];
  152. memset(buf, '\0', sizeof(buf));
  153. WBUFW(buf, 0) = 0x2afb;
  154. // 0 succes, 1:failure
  155. WBUFB(buf, 4) = 0;
  156. // Send name for wisp to player
  157. memcpy(WBUFP(buf, 5), charserv_config.wisp_server_name, NAME_LENGTH);
  158. // Default map
  159. memcpy(WBUFP(buf, (offs+=NAME_LENGTH)), charserv_config.default_map, MAP_NAME_LENGTH); // 29
  160. WBUFW(buf, (offs+=MAP_NAME_LENGTH)) = charserv_config.default_map_x; // 41
  161. WBUFW(buf, (offs+=2)) = charserv_config.default_map_y; // 43
  162. offs+=2;
  163. // Length
  164. WBUFW(buf, 2) = offs;
  165. chmapif_send(fd, buf, offs);
  166. }
  167. /**
  168. * Sends maps to all map-server
  169. * HZ 0x2b04 <size>.W <ip>.L <port>.W { <map>.?B }.?B
  170. * @param fd
  171. * @param map_id
  172. * @param count Number of map from new map-server has
  173. **/
  174. static void chmapif_send_maps(int fd, int map_id, int count, unsigned char *mapbuf) {
  175. uint16 x;
  176. if (count == 0) {
  177. ShowWarning("Map-server %d has NO maps.\n", map_id);
  178. }
  179. else {
  180. unsigned char buf[16384];
  181. // Transmitting maps information to the other map-servers
  182. WBUFW(buf,0) = 0x2b04;
  183. WBUFW(buf,2) = count * 4 + 10;
  184. WBUFL(buf,4) = htonl(map_server[map_id].ip);
  185. WBUFW(buf,8) = htons(map_server[map_id].port);
  186. memcpy(WBUFP(buf,10), mapbuf, count * 4);
  187. chmapif_sendallwos(fd, buf, WBUFW(buf,2));
  188. }
  189. // Transmitting the maps of the other map-servers to the new map-server
  190. for (x = 0; x < ARRAYLENGTH(map_server); x++) {
  191. if (map_server[x].fd > 0 && x != map_id) {
  192. uint16 i, j;
  193. WFIFOHEAD(fd,10 +4*ARRAYLENGTH(map_server[x].map));
  194. WFIFOW(fd,0) = 0x2b04;
  195. WFIFOL(fd,4) = htonl(map_server[x].ip);
  196. WFIFOW(fd,8) = htons(map_server[x].port);
  197. j = 0;
  198. for(i = 0; i < ARRAYLENGTH(map_server[x].map); i++)
  199. if (map_server[x].map[i])
  200. WFIFOW(fd,10+(j++)*4) = map_server[x].map[i];
  201. if (j > 0) {
  202. WFIFOW(fd,2) = j * 4 + 10;
  203. WFIFOSET(fd,WFIFOW(fd,2));
  204. }
  205. }
  206. }
  207. }
  208. /**
  209. * This function is called when the map-serv initialise is chrif interface.
  210. * Map-serv sent us his map indexes so we can transfert a player from a map-serv to another when necessary
  211. * We reply by sending back the char_serv_wisp_name fame list and
  212. * @param fd: wich fd to parse from
  213. * @param id: wich map_serv id
  214. * @return : 0 not enough data received, 1 success
  215. */
  216. int chmapif_parse_getmapname(int fd, int id){
  217. int i = 0, j = 0;
  218. unsigned char *mapbuf;
  219. if (RFIFOREST(fd) < 4 || RFIFOREST(fd) < RFIFOW(fd,2))
  220. return 0;
  221. //Retain what map-index that map-serv contains
  222. memset(map_server[id].map, 0, sizeof(map_server[id].map));
  223. for(i = 4; i < RFIFOW(fd,2); i += 4) {
  224. map_server[id].map[j] = RFIFOW(fd,i);
  225. j++;
  226. }
  227. mapbuf = RFIFOP(fd,4);
  228. RFIFOSKIP(fd,RFIFOW(fd,2));
  229. ShowStatus("Map-Server %d connected: %d maps, from IP %d.%d.%d.%d port %d.\n",
  230. id, j, CONVIP(map_server[id].ip), map_server[id].port);
  231. ShowStatus("Map-server %d loading complete.\n", id);
  232. chmapif_send_misc(fd);
  233. chmapif_send_fame_list(fd); //Send fame list.
  234. chmapif_send_maps(fd, id, j, mapbuf);
  235. return 1;
  236. }
  237. /**
  238. * Map-serv requesting to send the list of sc_data the player has saved
  239. * @author [Skotlex]
  240. * @param fd: wich fd to parse from
  241. * @return : 0 not enough data received, 1 success
  242. */
  243. int chmapif_parse_askscdata(int fd){
  244. if (RFIFOREST(fd) < 10)
  245. return 0;
  246. {
  247. #ifdef ENABLE_SC_SAVING
  248. int aid, cid;
  249. aid = RFIFOL(fd,2);
  250. cid = RFIFOL(fd,6);
  251. if( SQL_ERROR == Sql_Query(sql_handle, "SELECT type, tick, val1, val2, val3, val4 from `%s` WHERE `account_id` = '%d' AND `char_id`='%d'",
  252. schema_config.scdata_db, aid, cid) )
  253. {
  254. Sql_ShowDebug(sql_handle);
  255. return 1;
  256. }
  257. if( Sql_NumRows(sql_handle) > 0 )
  258. {
  259. struct status_change_data scdata;
  260. int count;
  261. char* data;
  262. WFIFOHEAD(fd,14+50*sizeof(struct status_change_data));
  263. WFIFOW(fd,0) = 0x2b1d;
  264. WFIFOL(fd,4) = aid;
  265. WFIFOL(fd,8) = cid;
  266. for( count = 0; count < 50 && SQL_SUCCESS == Sql_NextRow(sql_handle); ++count )
  267. {
  268. Sql_GetData(sql_handle, 0, &data, NULL); scdata.type = atoi(data);
  269. Sql_GetData(sql_handle, 1, &data, NULL); scdata.tick = atoi(data);
  270. Sql_GetData(sql_handle, 2, &data, NULL); scdata.val1 = atoi(data);
  271. Sql_GetData(sql_handle, 3, &data, NULL); scdata.val2 = atoi(data);
  272. Sql_GetData(sql_handle, 4, &data, NULL); scdata.val3 = atoi(data);
  273. Sql_GetData(sql_handle, 5, &data, NULL); scdata.val4 = atoi(data);
  274. memcpy(WFIFOP(fd, 14+count*sizeof(struct status_change_data)), &scdata, sizeof(struct status_change_data));
  275. }
  276. if (count >= 50)
  277. ShowWarning("Too many status changes for %d:%d, some of them were not loaded.\n", aid, cid);
  278. if (count > 0)
  279. {
  280. WFIFOW(fd,2) = 14 + count*sizeof(struct status_change_data);
  281. WFIFOW(fd,12) = count;
  282. WFIFOSET(fd,WFIFOW(fd,2));
  283. }
  284. }
  285. Sql_FreeResult(sql_handle);
  286. #endif
  287. RFIFOSKIP(fd, 10);
  288. }
  289. return 1;
  290. }
  291. /**
  292. * Map-serv sent us his new users count, updating info
  293. * @param fd: wich fd to parse from
  294. * @param id: wich map_serv id
  295. * @return : 0 not enough data received, 1 success
  296. */
  297. int chmapif_parse_getusercount(int fd, int id){
  298. if (RFIFOREST(fd) < 4)
  299. return 0;
  300. if (RFIFOW(fd,2) != map_server[id].users) {
  301. map_server[id].users = RFIFOW(fd,2);
  302. ShowInfo("User Count: %d (Server: %d)\n", map_server[id].users, id);
  303. }
  304. RFIFOSKIP(fd, 4);
  305. return 1;
  306. }
  307. /**
  308. * Map-serv sent us all his users info, (aid and cid) so we can update online_char_db
  309. * @param fd: wich fd to parse from
  310. * @param id: wich map_serv id
  311. * @return : 0 not enough data received, 1 success
  312. */
  313. int chmapif_parse_regmapuser(int fd, int id){
  314. if (RFIFOREST(fd) < 6 || RFIFOREST(fd) < RFIFOW(fd,2))
  315. return 0;
  316. {
  317. //TODO: When data mismatches memory, update guild/party online/offline states.
  318. DBMap* online_char_db = char_get_onlinedb();
  319. int i;
  320. map_server[id].users = RFIFOW(fd,4);
  321. online_char_db->foreach(online_char_db,char_db_setoffline,id); //Set all chars from this server as 'unknown'
  322. for(i = 0; i < map_server[id].users; i++) {
  323. int aid = RFIFOL(fd,6+i*8);
  324. int cid = RFIFOL(fd,6+i*8+4);
  325. struct online_char_data* character = idb_ensure(online_char_db, aid, char_create_online_data);
  326. if( character->server > -1 && character->server != id )
  327. {
  328. ShowNotice("Set map user: Character (%d:%d) marked on map server %d, but map server %d claims to have (%d:%d) online!\n",
  329. character->account_id, character->char_id, character->server, id, aid, cid);
  330. mapif_disconnectplayer(map_server[character->server].fd, character->account_id, character->char_id, 2);
  331. }
  332. character->server = id;
  333. character->char_id = cid;
  334. }
  335. //If any chars remain in -2, they will be cleaned in the cleanup timer.
  336. RFIFOSKIP(fd,RFIFOW(fd,2));
  337. }
  338. return 1;
  339. }
  340. /**
  341. * Map-serv request to save mmo_char_status in sql
  342. * Receive character data from map-server for saving
  343. * @param fd: wich fd to parse from
  344. * @param id: wich map_serv id
  345. * @return : 0 not enough data received, 1 success
  346. */
  347. int chmapif_parse_reqsavechar(int fd, int id){
  348. if (RFIFOREST(fd) < 4 || RFIFOREST(fd) < RFIFOW(fd,2))
  349. return 0;
  350. {
  351. int aid = RFIFOL(fd,4), cid = RFIFOL(fd,8), size = RFIFOW(fd,2);
  352. struct online_char_data* character;
  353. DBMap* online_char_db = char_get_onlinedb();
  354. if (size - 13 != sizeof(struct mmo_charstatus))
  355. {
  356. ShowError("parse_from_map (save-char): Size mismatch! %d != %d\n", size-13, sizeof(struct mmo_charstatus));
  357. RFIFOSKIP(fd,size);
  358. return 1;
  359. }
  360. //Check account only if this ain't final save. Final-save goes through because of the char-map reconnect
  361. if (RFIFOB(fd,12) || RFIFOB(fd,13) || (
  362. (character = (struct online_char_data*)idb_get(online_char_db, aid)) != NULL &&
  363. character->char_id == cid))
  364. {
  365. struct mmo_charstatus char_dat;
  366. memcpy(&char_dat, RFIFOP(fd,13), sizeof(struct mmo_charstatus));
  367. char_mmo_char_tosql(cid, &char_dat);
  368. } else { //This may be valid on char-server reconnection, when re-sending characters that already logged off.
  369. ShowError("parse_from_map (save-char): Received data for non-existant/offline character (%d:%d).\n", aid, cid);
  370. char_set_char_online(id, cid, aid);
  371. }
  372. if (RFIFOB(fd,12))
  373. { //Flag, set character offline after saving. [Skotlex]
  374. char_set_char_offline(cid, aid);
  375. WFIFOHEAD(fd,10);
  376. WFIFOW(fd,0) = 0x2b21; //Save ack only needed on final save.
  377. WFIFOL(fd,2) = aid;
  378. WFIFOL(fd,6) = cid;
  379. WFIFOSET(fd,10);
  380. }
  381. RFIFOSKIP(fd,size);
  382. }
  383. return 1;
  384. }
  385. /**
  386. * Inform mapserv of a new character selection request
  387. * @param fd : FD link tomapserv
  388. * @param aid : Player account id
  389. * @param res : result, 0=not ok, 1=ok
  390. */
  391. void chmapif_charselres(int fd, uint32 aid, uint8 res){
  392. WFIFOHEAD(fd,7);
  393. WFIFOW(fd,0) = 0x2b03;
  394. WFIFOL(fd,2) = aid;
  395. WFIFOB(fd,6) = res;
  396. WFIFOSET(fd,7);
  397. }
  398. /**
  399. * Player Requesting char-select from map_serv
  400. * @param fd: wich fd to parse from
  401. * @return : 0 not enough data received, 1 success
  402. */
  403. int chmapif_parse_authok(int fd){
  404. if( RFIFOREST(fd) < 19 )
  405. return 0;
  406. else{
  407. uint32 account_id = RFIFOL(fd,2);
  408. uint32 login_id1 = RFIFOL(fd,6);
  409. uint32 login_id2 = RFIFOL(fd,10);
  410. uint32 ip = RFIFOL(fd,14);
  411. int version = RFIFOB(fd,18);
  412. RFIFOSKIP(fd,19);
  413. if( runflag != CHARSERVER_ST_RUNNING ){
  414. chmapif_charselres(fd,account_id,0);
  415. }else{
  416. struct auth_node* node;
  417. DBMap* auth_db = char_get_authdb();
  418. DBMap* online_char_db = char_get_onlinedb();
  419. // create temporary auth entry
  420. CREATE(node, struct auth_node, 1);
  421. node->account_id = account_id;
  422. node->char_id = 0;
  423. node->login_id1 = login_id1;
  424. node->login_id2 = login_id2;
  425. //node->sex = 0;
  426. node->ip = ntohl(ip);
  427. node->version = version; //upd version for mapserv
  428. //node->expiration_time = 0; // unlimited/unknown time by default (not display in map-server)
  429. //node->gmlevel = 0;
  430. idb_put(auth_db, account_id, node);
  431. //Set char to "@ char select" in online db [Kevin]
  432. char_set_charselect(account_id);
  433. {
  434. struct online_char_data* character = (struct online_char_data*)idb_get(online_char_db, account_id);
  435. if( character != NULL ){
  436. character->pincode_success = true;
  437. }
  438. }
  439. chmapif_charselres(fd,account_id,1);
  440. }
  441. }
  442. return 1;
  443. }
  444. //Request to save skill cooldown data
  445. int chmapif_parse_req_saveskillcooldown(int fd){
  446. if( RFIFOREST(fd) < 4 || RFIFOREST(fd) < RFIFOW(fd,2) )
  447. return 0;
  448. else {
  449. int count, aid, cid;
  450. aid = RFIFOL(fd,4);
  451. cid = RFIFOL(fd,8);
  452. count = RFIFOW(fd,12);
  453. if( count > 0 )
  454. {
  455. struct skill_cooldown_data data;
  456. StringBuf buf;
  457. int i;
  458. StringBuf_Init(&buf);
  459. StringBuf_Printf(&buf, "INSERT INTO `%s` (`account_id`, `char_id`, `skill`, `tick`) VALUES ", schema_config.skillcooldown_db);
  460. for( i = 0; i < count; ++i )
  461. {
  462. memcpy(&data,RFIFOP(fd,14+i*sizeof(struct skill_cooldown_data)),sizeof(struct skill_cooldown_data));
  463. if( i > 0 )
  464. StringBuf_AppendStr(&buf, ", ");
  465. StringBuf_Printf(&buf, "('%d','%d','%d','%d')", aid, cid, data.skill_id, data.tick);
  466. }
  467. if( SQL_ERROR == Sql_QueryStr(sql_handle, StringBuf_Value(&buf)) )
  468. Sql_ShowDebug(sql_handle);
  469. StringBuf_Destroy(&buf);
  470. }
  471. RFIFOSKIP(fd, RFIFOW(fd, 2));
  472. }
  473. return 1;
  474. }
  475. //Request skillcooldown data 0x2b0a
  476. int chmapif_parse_req_skillcooldown(int fd){
  477. if (RFIFOREST(fd) < 10)
  478. return 0;
  479. else {
  480. int aid, cid;
  481. aid = RFIFOL(fd,2);
  482. cid = RFIFOL(fd,6);
  483. RFIFOSKIP(fd, 10);
  484. if( SQL_ERROR == Sql_Query(sql_handle, "SELECT skill, tick FROM `%s` WHERE `account_id` = '%d' AND `char_id`='%d'",
  485. schema_config.skillcooldown_db, aid, cid) )
  486. {
  487. Sql_ShowDebug(sql_handle);
  488. return 1;
  489. }
  490. if( Sql_NumRows(sql_handle) > 0 )
  491. {
  492. int count;
  493. char* data;
  494. struct skill_cooldown_data scd;
  495. WFIFOHEAD(fd,14 + MAX_SKILLCOOLDOWN * sizeof(struct skill_cooldown_data));
  496. WFIFOW(fd,0) = 0x2b0b;
  497. WFIFOL(fd,4) = aid;
  498. WFIFOL(fd,8) = cid;
  499. for( count = 0; count < MAX_SKILLCOOLDOWN && SQL_SUCCESS == Sql_NextRow(sql_handle); ++count )
  500. {
  501. Sql_GetData(sql_handle, 0, &data, NULL); scd.skill_id = atoi(data);
  502. Sql_GetData(sql_handle, 1, &data, NULL); scd.tick = atoi(data);
  503. memcpy(WFIFOP(fd,14+count*sizeof(struct skill_cooldown_data)), &scd, sizeof(struct skill_cooldown_data));
  504. }
  505. if( count >= MAX_SKILLCOOLDOWN )
  506. ShowWarning("Too many skillcooldowns for %d:%d, some of them were not loaded.\n", aid, cid);
  507. if( count > 0 )
  508. {
  509. WFIFOW(fd,2) = 14 + count * sizeof(struct skill_cooldown_data);
  510. WFIFOW(fd,12) = count;
  511. WFIFOSET(fd,WFIFOW(fd,2));
  512. //Clear the data once loaded.
  513. if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `account_id` = '%d' AND `char_id`='%d'", schema_config.skillcooldown_db, aid, cid) )
  514. Sql_ShowDebug(sql_handle);
  515. }
  516. }
  517. Sql_FreeResult(sql_handle);
  518. }
  519. return 1;
  520. }
  521. /**
  522. * Inform the mapserv, of a change mapserv request
  523. * @param fd :Link to mapserv
  524. * @param nok : 0=accepted or no=1
  525. */
  526. void chmapif_changemapserv_ack(int fd, bool nok){
  527. WFIFOHEAD(fd,30);
  528. WFIFOW(fd,0) = 0x2b06;
  529. memcpy(WFIFOP(fd,2), RFIFOP(fd,2), 28);
  530. if(nok)
  531. WFIFOL(fd,6) = 0; //Set login1 to 0.(not ok)
  532. WFIFOSET(fd,30);
  533. }
  534. /**
  535. * Player requesting to change map-serv
  536. * @param fd: wich fd to parse from
  537. * @return : 0 not enough data received, 1 success
  538. */
  539. int chmapif_parse_reqchangemapserv(int fd){
  540. if (RFIFOREST(fd) < 39)
  541. return 0;
  542. {
  543. int map_id, map_fd = -1;
  544. struct mmo_charstatus* char_data;
  545. struct mmo_charstatus char_dat;
  546. DBMap* char_db_ = char_get_chardb();
  547. map_id = char_search_mapserver(RFIFOW(fd,18), ntohl(RFIFOL(fd,24)), ntohs(RFIFOW(fd,28))); //Locate mapserver by ip and port.
  548. if (map_id >= 0)
  549. map_fd = map_server[map_id].fd;
  550. //Char should just had been saved before this packet, so this should be safe. [Skotlex]
  551. char_data = (struct mmo_charstatus*)uidb_get(char_db_,RFIFOL(fd,14));
  552. if (char_data == NULL) { //Really shouldn't happen.
  553. char_mmo_char_fromsql(RFIFOL(fd,14), &char_dat, true);
  554. char_data = (struct mmo_charstatus*)uidb_get(char_db_,RFIFOL(fd,14));
  555. }
  556. if( runflag == CHARSERVER_ST_RUNNING &&
  557. session_isActive(map_fd) &&
  558. char_data )
  559. { //Send the map server the auth of this player.
  560. struct online_char_data* data;
  561. struct auth_node* node;
  562. DBMap* auth_db = char_get_authdb();
  563. DBMap* online_char_db = char_get_onlinedb();
  564. int aid = RFIFOL(fd,2);
  565. //Update the "last map" as this is where the player must be spawned on the new map server.
  566. char_data->last_point.map = RFIFOW(fd,18);
  567. char_data->last_point.x = RFIFOW(fd,20);
  568. char_data->last_point.y = RFIFOW(fd,22);
  569. char_data->sex = RFIFOB(fd,30);
  570. // create temporary auth entry
  571. CREATE(node, struct auth_node, 1);
  572. node->account_id = aid;
  573. node->char_id = RFIFOL(fd,14);
  574. node->login_id1 = RFIFOL(fd,6);
  575. node->login_id2 = RFIFOL(fd,10);
  576. node->sex = RFIFOB(fd,30);
  577. node->expiration_time = 0; // FIXME (this thing isn't really supported we could as well purge it instead of fixing)
  578. node->ip = ntohl(RFIFOL(fd,31));
  579. node->group_id = RFIFOL(fd,35);
  580. node->changing_mapservers = 1;
  581. idb_put(auth_db, aid, node);
  582. data = idb_ensure(online_char_db, aid, char_create_online_data);
  583. data->char_id = char_data->char_id;
  584. data->server = map_id; //Update server where char is.
  585. //Reply with an ack.
  586. chmapif_changemapserv_ack(fd,0);
  587. } else { //Reply with nak
  588. chmapif_changemapserv_ack(fd,1);
  589. }
  590. RFIFOSKIP(fd,39);
  591. }
  592. return 1;
  593. }
  594. /**
  595. * Player requesting to remove friend from list
  596. * Remove RFIFOL(fd,6) (friend_id) from RFIFOL(fd,2) (char_id) friend list
  597. * @author [Ind]
  598. * @param fd: wich fd to parse from
  599. * @return : 0 not enough data received, 1 success
  600. */
  601. int chmapif_parse_askrmfriend(int fd){
  602. if (RFIFOREST(fd) < 10)
  603. return 0;
  604. {
  605. uint32 char_id, friend_id;
  606. char_id = RFIFOL(fd,2);
  607. friend_id = RFIFOL(fd,6);
  608. if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `char_id`='%d' AND `friend_id`='%d' LIMIT 1",
  609. schema_config.friend_db, char_id, friend_id) ) {
  610. Sql_ShowDebug(sql_handle);
  611. return 1;
  612. }
  613. RFIFOSKIP(fd,10);
  614. }
  615. return 1;
  616. }
  617. /**
  618. * Lookup to search if that char_id correspond to a name.
  619. * Comming from map-serv to search on other map-serv
  620. * @param fd: wich fd to parse from
  621. * @return : 0 not enough data received, 1 success
  622. */
  623. int chmapif_parse_reqcharname(int fd){
  624. if (RFIFOREST(fd) < 6)
  625. return 0;
  626. WFIFOHEAD(fd,30);
  627. WFIFOW(fd,0) = 0x2b09;
  628. WFIFOL(fd,2) = RFIFOL(fd,2);
  629. char_loadName((int)RFIFOL(fd,2), (char*)WFIFOP(fd,6));
  630. WFIFOSET(fd,30);
  631. RFIFOSKIP(fd,6);
  632. return 1;
  633. }
  634. /**
  635. * Forward an email update request to login-serv
  636. * Map server send information to change an email of an account -> login-server
  637. * @param fd: wich fd to parse from
  638. * @return : 0 not enough data received, 1 success
  639. */
  640. int chmapif_parse_reqnewemail(int fd){
  641. if (RFIFOREST(fd) < 86)
  642. return 0;
  643. if (chlogif_isconnected()) { // don't send request if no login-server
  644. WFIFOHEAD(login_fd,86);
  645. memcpy(WFIFOP(login_fd,0), RFIFOP(fd,0),86); // 0x2722 <account_id>.L <actual_e-mail>.40B <new_e-mail>.40B
  646. WFIFOW(login_fd,0) = 0x2722;
  647. WFIFOSET(login_fd,86);
  648. }
  649. RFIFOSKIP(fd, 86);
  650. return 1;
  651. }
  652. /**
  653. * Forward a change of status for account to login-serv
  654. * @param fd: which fd to parse from
  655. * @return : 0 not enough data received, 1 success
  656. */
  657. int chmapif_parse_fwlog_changestatus(int fd){
  658. if (RFIFOREST(fd) < 44)
  659. return 0;
  660. else {
  661. int result = 0; // 0-login-server request done, 1-player not found, 2-gm level too low, 3-login-server offline, 4-current group level > VIP group level
  662. char esc_name[NAME_LENGTH*2+1];
  663. char answer = true;
  664. int aid = RFIFOL(fd,2); // account_id of who ask (-1 if server itself made this request)
  665. const char* name = (char*)RFIFOP(fd,6); // name of the target character
  666. int operation = RFIFOW(fd,30); // type of operation: 1-block, 2-ban, 3-unblock, 4-unban, 5-changesex, 6-vip, 7-changecharsex
  667. int32 timediff = 0;
  668. int val1 = 0, sex = SEX_MALE;
  669. if (operation == 2) {
  670. timediff = RFIFOL(fd, 32);
  671. val1 = RFIFOL(fd, 36);
  672. } else if (operation == 7)
  673. sex = RFIFOB(fd, 32);
  674. RFIFOSKIP(fd,44);
  675. Sql_EscapeStringLen(sql_handle, esc_name, name, strnlen(name, NAME_LENGTH));
  676. if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `account_id`, `char_id` FROM `%s` WHERE `name` = '%s'", schema_config.char_db, esc_name) )
  677. Sql_ShowDebug(sql_handle);
  678. else if( Sql_NumRows(sql_handle) == 0 ) {
  679. result = 1; // 1-player not found
  680. }
  681. else if( SQL_SUCCESS != Sql_NextRow(sql_handle) ) {
  682. Sql_ShowDebug(sql_handle);
  683. result = 1;
  684. } else {
  685. int t_aid; // target account id
  686. int t_cid; // target char id
  687. char* data;
  688. Sql_GetData(sql_handle, 0, &data, NULL); t_aid = atoi(data);
  689. Sql_GetData(sql_handle, 1, &data, NULL); t_cid = atoi(data);
  690. Sql_FreeResult(sql_handle);
  691. if(!chlogif_isconnected())
  692. result = 3; // 3-login-server offline
  693. //FIXME: need to move this check to login server [ultramage]
  694. // if( acc != -1 && isGM(acc) < isGM(account_id) )
  695. // result = 2; // 2-gm level too low
  696. else {
  697. //! NOTE: See src/char/chrif.h::enum chrif_req_op for the number
  698. switch( operation ) {
  699. case 1: // block
  700. WFIFOHEAD(login_fd,10);
  701. WFIFOW(login_fd,0) = 0x2724;
  702. WFIFOL(login_fd,2) = t_aid;
  703. WFIFOL(login_fd,6) = 5; // new account status
  704. WFIFOSET(login_fd,10);
  705. break;
  706. case 2: // ban
  707. WFIFOHEAD(login_fd,10);
  708. WFIFOW(login_fd, 0) = 0x2725;
  709. WFIFOL(login_fd, 2) = t_aid;
  710. WFIFOL(login_fd, 6) = timediff;
  711. WFIFOSET(login_fd,10);
  712. break;
  713. case 3: // unblock
  714. WFIFOHEAD(login_fd,10);
  715. WFIFOW(login_fd,0) = 0x2724;
  716. WFIFOL(login_fd,2) = t_aid;
  717. WFIFOL(login_fd,6) = 0; // new account status
  718. WFIFOSET(login_fd,10);
  719. break;
  720. case 4: // unban
  721. WFIFOHEAD(login_fd,6);
  722. WFIFOW(login_fd,0) = 0x272a;
  723. WFIFOL(login_fd,2) = t_aid;
  724. WFIFOSET(login_fd,6);
  725. break;
  726. case 5: // changesex
  727. answer = false;
  728. WFIFOHEAD(login_fd,6);
  729. WFIFOW(login_fd,0) = 0x2727;
  730. WFIFOL(login_fd,2) = t_aid;
  731. WFIFOSET(login_fd,6);
  732. break;
  733. case 6: // vip
  734. answer = (val1&4); // vip_req val1=type, &1 login send return, &2 update timestamp, &4 map send answer
  735. chlogif_reqvipdata(t_aid, val1, timediff, fd);
  736. break;
  737. case 7: // changecharsex
  738. answer = false;
  739. chlogif_parse_ackchangecharsex(t_cid, sex);
  740. break;
  741. } //end switch operation
  742. } //login is connected
  743. }
  744. // send answer if a player asks, not if the server asks
  745. if( aid != -1 && answer) { // Don't send answer for changesex/changecharsex
  746. WFIFOHEAD(fd,34);
  747. WFIFOW(fd, 0) = 0x2b0f;
  748. WFIFOL(fd, 2) = aid;
  749. safestrncpy((char*)WFIFOP(fd,6), name, NAME_LENGTH);
  750. WFIFOW(fd,30) = operation;
  751. WFIFOW(fd,32) = result;
  752. WFIFOSET(fd,34);
  753. }
  754. }
  755. return 1;
  756. }
  757. /**
  758. * Transmit the acknowledgement of divorce of partner_id1 and partner_id2
  759. * Update the list associated and transmit the new ranking
  760. * @param partner_id1: char id1 divorced
  761. * @param partner_id2: char id2 divorced
  762. */
  763. void chmapif_send_ackdivorce(int partner_id1, int partner_id2){
  764. unsigned char buf[11];
  765. WBUFW(buf,0) = 0x2b12;
  766. WBUFL(buf,2) = partner_id1;
  767. WBUFL(buf,6) = partner_id2;
  768. chmapif_sendall(buf,10);
  769. }
  770. /**
  771. * Received a divorce request
  772. * @param fd: wich fd to parse from
  773. * @return : 0 not enough data received, 1 success
  774. */
  775. int chmapif_parse_reqdivorce(int fd){
  776. if( RFIFOREST(fd) < 10 )
  777. return 0;
  778. char_divorce_char_sql(RFIFOL(fd,2), RFIFOL(fd,6));
  779. RFIFOSKIP(fd,10);
  780. return 1;
  781. }
  782. /**
  783. * Receive rates of this map index
  784. * @author [Wizputer]
  785. * @param fd: wich fd to parse from
  786. * @return : 0 not enough data received, 1 success
  787. */
  788. int chmapif_parse_updmapinfo(int fd){
  789. if( RFIFOREST(fd) < 14 )
  790. return 0;
  791. {
  792. char esc_server_name[sizeof(charserv_config.server_name)*2+1];
  793. Sql_EscapeString(sql_handle, esc_server_name, charserv_config.server_name);
  794. if( SQL_ERROR == Sql_Query(sql_handle, "INSERT INTO `%s` SET `index`='%d',`name`='%s',`exp`='%d',`jexp`='%d',`drop`='%d'",
  795. schema_config.ragsrvinfo_db, fd, esc_server_name, RFIFOL(fd,2), RFIFOL(fd,6), RFIFOL(fd,10)) )
  796. Sql_ShowDebug(sql_handle);
  797. RFIFOSKIP(fd,14);
  798. }
  799. return 1;
  800. }
  801. /**
  802. * Character disconnected set online 0
  803. * @author [Wizputer]
  804. * @param fd: wich fd to parse from
  805. * @return : 0 not enough data received, 1 success
  806. */
  807. int chmapif_parse_setcharoffline(int fd){
  808. if (RFIFOREST(fd) < 6)
  809. return 0;
  810. char_set_char_offline(RFIFOL(fd,2),RFIFOL(fd,6));
  811. RFIFOSKIP(fd,10);
  812. return 1;
  813. }
  814. /**
  815. * Reset all chars to offline
  816. * @author [Wizputer]
  817. * @param fd: wich fd to parse from
  818. * @param id: wich map_serv id
  819. * @return : 0 not enough data received, 1 success
  820. */
  821. int chmapif_parse_setalloffline(int fd, int id){
  822. char_set_all_offline(id);
  823. RFIFOSKIP(fd,2);
  824. return 1;
  825. }
  826. /**
  827. * Character set online
  828. * @author [Wizputer]
  829. * @param fd: wich fd to parse from
  830. * @param id: wich map_serv id
  831. * @return : 0 not enough data received, 1 success
  832. */
  833. int chmapif_parse_setcharonline(int fd, int id){
  834. if (RFIFOREST(fd) < 10)
  835. return 0;
  836. char_set_char_online(id, RFIFOL(fd,2),RFIFOL(fd,6));
  837. RFIFOSKIP(fd,10);
  838. return 1;
  839. }
  840. /**
  841. * Build and send fame ranking lists
  842. * @author [DracoRPG]
  843. * @param fd: wich fd to parse from
  844. * @param id: wich map_serv id
  845. * @return : 0 not enough data received, 1 success
  846. */
  847. int chmapif_parse_reqfamelist(int fd){
  848. if (RFIFOREST(fd) < 2)
  849. return 0;
  850. char_read_fame_list();
  851. chmapif_send_fame_list(-1);
  852. RFIFOSKIP(fd,2);
  853. return 1;
  854. }
  855. /**
  856. * Request to save status change data.s
  857. * @author [Skotlex]
  858. * @param fd: wich fd to parse from
  859. * @return : 0 not enough data received, 1 success
  860. */
  861. int chmapif_parse_save_scdata(int fd){
  862. if (RFIFOREST(fd) < 4 || RFIFOREST(fd) < RFIFOW(fd,2))
  863. return 0;
  864. {
  865. #ifdef ENABLE_SC_SAVING
  866. int count, aid, cid;
  867. aid = RFIFOL(fd, 4);
  868. cid = RFIFOL(fd, 8);
  869. count = RFIFOW(fd, 12);
  870. // Whatever comes from the mapserver, now is the time to drop previous entries
  871. if( Sql_Query( sql_handle, "DELETE FROM `%s` where `account_id` = %d and `char_id` = %d;", schema_config.scdata_db, aid, cid ) != SQL_SUCCESS ){
  872. Sql_ShowDebug( sql_handle );
  873. }
  874. else if( count > 0 )
  875. {
  876. struct status_change_data data;
  877. StringBuf buf;
  878. int i;
  879. StringBuf_Init(&buf);
  880. StringBuf_Printf(&buf, "INSERT INTO `%s` (`account_id`, `char_id`, `type`, `tick`, `val1`, `val2`, `val3`, `val4`) VALUES ", schema_config.scdata_db);
  881. for( i = 0; i < count; ++i )
  882. {
  883. memcpy (&data, RFIFOP(fd, 14+i*sizeof(struct status_change_data)), sizeof(struct status_change_data));
  884. if( i > 0 )
  885. StringBuf_AppendStr(&buf, ", ");
  886. StringBuf_Printf(&buf, "('%d','%d','%hu','%d','%d','%d','%d','%d')", aid, cid,
  887. data.type, data.tick, data.val1, data.val2, data.val3, data.val4);
  888. }
  889. if( SQL_ERROR == Sql_QueryStr(sql_handle, StringBuf_Value(&buf)) )
  890. Sql_ShowDebug(sql_handle);
  891. StringBuf_Destroy(&buf);
  892. }
  893. #endif
  894. RFIFOSKIP(fd, RFIFOW(fd, 2));
  895. }
  896. return 1;
  897. }
  898. /**
  899. * map-server keep alive packet, awnser back map that we alive as well
  900. * @param fd: wich fd to parse from
  901. * @return : 0 not enough data received, 1 success
  902. */
  903. int chmapif_parse_keepalive(int fd){
  904. WFIFOHEAD(fd,2);
  905. WFIFOW(fd,0) = 0x2b24;
  906. WFIFOSET(fd,2);
  907. RFIFOSKIP(fd,2);
  908. return 1;
  909. }
  910. /**
  911. * auth request from map-server
  912. * @param fd: wich fd to parse from
  913. * @return : 0 not enough data received, 1 success
  914. */
  915. int chmapif_parse_reqauth(int fd, int id){
  916. if (RFIFOREST(fd) < 20)
  917. return 0;
  918. {
  919. uint32 account_id;
  920. uint32 char_id;
  921. uint32 login_id1;
  922. unsigned char sex;
  923. uint32 ip;
  924. struct auth_node* node;
  925. struct mmo_charstatus* cd;
  926. struct mmo_charstatus char_dat;
  927. bool autotrade;
  928. DBMap* auth_db = char_get_authdb();
  929. DBMap* char_db_ = char_get_chardb();
  930. account_id = RFIFOL(fd,2);
  931. char_id = RFIFOL(fd,6);
  932. login_id1 = RFIFOL(fd,10);
  933. sex = RFIFOB(fd,14);
  934. ip = ntohl(RFIFOL(fd,15));
  935. autotrade = RFIFOB(fd,19);
  936. RFIFOSKIP(fd,20);
  937. node = (struct auth_node*)idb_get(auth_db, account_id);
  938. cd = (struct mmo_charstatus*)uidb_get(char_db_,char_id);
  939. if( cd == NULL )
  940. { //Really shouldn't happen. (or autotrade)
  941. char_mmo_char_fromsql(char_id, &char_dat, true);
  942. cd = (struct mmo_charstatus*)uidb_get(char_db_,char_id);
  943. }
  944. if( runflag == CHARSERVER_ST_RUNNING && autotrade && cd ){
  945. uint16 mmo_charstatus_len = sizeof(struct mmo_charstatus) + 25;
  946. if (cd->sex == 99)
  947. cd->sex = sex;
  948. WFIFOHEAD(fd,mmo_charstatus_len);
  949. WFIFOW(fd,0) = 0x2afd;
  950. WFIFOW(fd,2) = mmo_charstatus_len;
  951. WFIFOL(fd,4) = account_id;
  952. WFIFOL(fd,8) = 0;
  953. WFIFOL(fd,12) = 0;
  954. WFIFOL(fd,16) = 0;
  955. WFIFOL(fd,20) = 0;
  956. WFIFOB(fd,24) = 0;
  957. memcpy(WFIFOP(fd,25), cd, sizeof(struct mmo_charstatus));
  958. WFIFOSET(fd, WFIFOW(fd,2));
  959. char_set_char_online(id, char_id, account_id);
  960. } else if( runflag == CHARSERVER_ST_RUNNING &&
  961. cd != NULL &&
  962. node != NULL &&
  963. node->account_id == account_id &&
  964. node->char_id == char_id &&
  965. node->login_id1 == login_id1
  966. //&& node->ip == ip
  967. #if PACKETVER < 20141016
  968. && node->sex == sex
  969. #endif
  970. )
  971. {// auth ok
  972. uint16 mmo_charstatus_len = sizeof(struct mmo_charstatus) + 25;
  973. if (cd->sex == 99)
  974. cd->sex = sex;
  975. WFIFOHEAD(fd,mmo_charstatus_len);
  976. WFIFOW(fd,0) = 0x2afd;
  977. WFIFOW(fd,2) = mmo_charstatus_len;
  978. WFIFOL(fd,4) = account_id;
  979. WFIFOL(fd,8) = node->login_id1;
  980. WFIFOL(fd,12) = node->login_id2;
  981. WFIFOL(fd,16) = (uint32)node->expiration_time; // FIXME: will wrap to negative after "19-Jan-2038, 03:14:07 AM GMT"
  982. WFIFOL(fd,20) = node->group_id;
  983. WFIFOB(fd,24) = node->changing_mapservers;
  984. memcpy(WFIFOP(fd,25), cd, sizeof(struct mmo_charstatus));
  985. WFIFOSET(fd, WFIFOW(fd,2));
  986. // only use the auth once and mark user online
  987. idb_remove(auth_db, account_id);
  988. char_set_char_online(id, char_id, account_id);
  989. } else {// auth failed
  990. WFIFOHEAD(fd,19);
  991. WFIFOW(fd,0) = 0x2b27;
  992. WFIFOL(fd,2) = account_id;
  993. WFIFOL(fd,6) = char_id;
  994. WFIFOL(fd,10) = login_id1;
  995. WFIFOB(fd,14) = sex;
  996. WFIFOL(fd,15) = htonl(ip);
  997. WFIFOSET(fd,19);
  998. }
  999. }
  1000. return 1;
  1001. }
  1002. /**
  1003. * ip address update
  1004. * @param fd: wich fd to parse from
  1005. * @return : 0 not enough data received, 1 success
  1006. */
  1007. int chmapif_parse_updmapip(int fd, int id){
  1008. if (RFIFOREST(fd) < 6)
  1009. return 0;
  1010. map_server[id].ip = ntohl(RFIFOL(fd, 2));
  1011. ShowInfo("Updated IP address of map-server #%d to %d.%d.%d.%d.\n", id, CONVIP(map_server[id].ip));
  1012. RFIFOSKIP(fd,6);
  1013. return 1;
  1014. }
  1015. /**
  1016. * transmit emu usage for anom stats
  1017. * @param fd: wich fd to parse from
  1018. * @return : 0 not enough data received, 1 success
  1019. */
  1020. int chmapif_parse_fw_configstats(int fd){
  1021. if( RFIFOREST(fd) < RFIFOW(fd,4) )
  1022. return 0;/* packet wasn't fully received yet (still fragmented) */
  1023. else {
  1024. int sfd;/* stat server fd */
  1025. RFIFOSKIP(fd, 2);/* we skip first 2 bytes which are the 0x3008, so we end up with a buffer equal to the one we send */
  1026. if( (sfd = make_connection(host2ip("stats.rathena.org"),(uint16)25421,true,10) ) == -1 ) {
  1027. RFIFOSKIP(fd, RFIFOW(fd,2) );/* skip this packet */
  1028. return 0;/* connection not possible, we drop the report */
  1029. }
  1030. session[sfd]->flag.server = 1;/* to ensure we won't drop our own packet */
  1031. WFIFOHEAD(sfd, RFIFOW(fd,2) );
  1032. memcpy((char*)WFIFOP(sfd,0), (char*)RFIFOP(fd, 0), RFIFOW(fd,2));
  1033. WFIFOSET(sfd, RFIFOW(fd,2) );
  1034. flush_fifo(sfd);
  1035. do_close(sfd);
  1036. RFIFOSKIP(fd, RFIFOW(fd,2) );/* skip this packet */
  1037. }
  1038. return 1;
  1039. }
  1040. /**
  1041. * Received an update of fame point for char_id cid
  1042. * Update the list associated and transmit the new ranking
  1043. * @param fd: wich fd to parse from
  1044. * @return : 0 not enough data received, 1 success
  1045. */
  1046. int chmapif_parse_updfamelist(int fd){
  1047. if (RFIFOREST(fd) < 11)
  1048. return 0;
  1049. {
  1050. int cid = RFIFOL(fd, 2);
  1051. int fame = RFIFOL(fd, 6);
  1052. char type = RFIFOB(fd, 10);
  1053. int size;
  1054. struct fame_list* list;
  1055. int player_pos;
  1056. int fame_pos;
  1057. switch(type)
  1058. {
  1059. case 1: size = fame_list_size_smith; list = smith_fame_list; break;
  1060. case 2: size = fame_list_size_chemist; list = chemist_fame_list; break;
  1061. case 3: size = fame_list_size_taekwon; list = taekwon_fame_list; break;
  1062. default: size = 0; list = NULL; break;
  1063. }
  1064. ARR_FIND(0, size, player_pos, list[player_pos].id == cid);// position of the player
  1065. ARR_FIND(0, size, fame_pos, list[fame_pos].fame <= fame);// where the player should be
  1066. if( player_pos == size && fame_pos == size )
  1067. ;// not on list and not enough fame to get on it
  1068. else if( fame_pos == player_pos )
  1069. {// same position
  1070. list[player_pos].fame = fame;
  1071. chmapif_update_fame_list(type, player_pos, fame);
  1072. }
  1073. else
  1074. {// move in the list
  1075. if( player_pos == size )
  1076. {// new ranker - not in the list
  1077. ARR_MOVE(size - 1, fame_pos, list, struct fame_list);
  1078. list[fame_pos].id = cid;
  1079. list[fame_pos].fame = fame;
  1080. char_loadName(cid, list[fame_pos].name);
  1081. }
  1082. else
  1083. {// already in the list
  1084. if( fame_pos == size )
  1085. --fame_pos;// move to the end of the list
  1086. ARR_MOVE(player_pos, fame_pos, list, struct fame_list);
  1087. list[fame_pos].fame = fame;
  1088. }
  1089. chmapif_send_fame_list(-1);
  1090. }
  1091. RFIFOSKIP(fd,11);
  1092. }
  1093. return 1;
  1094. }
  1095. /*
  1096. * HZ 0x2b2b
  1097. * Transmist vip data to mapserv
  1098. */
  1099. int chmapif_vipack(int mapfd, uint32 aid, uint32 vip_time, uint8 isvip, uint8 isgm, uint32 groupid) {
  1100. #ifdef VIP_ENABLE
  1101. uint8 buf[16];
  1102. WBUFW(buf,0) = 0x2b2b;
  1103. WBUFL(buf,2) = aid;
  1104. WBUFL(buf,6) = vip_time;
  1105. WBUFB(buf,10) = isvip;
  1106. WBUFB(buf,11) = isgm;
  1107. WBUFL(buf,12) = groupid;
  1108. chmapif_send(mapfd,buf,16); // inform the mapserv back
  1109. #endif
  1110. return 0;
  1111. }
  1112. int chmapif_parse_reqcharban(int fd){
  1113. if (RFIFOREST(fd) < 10+NAME_LENGTH)
  1114. return 0;
  1115. else {
  1116. //int aid = RFIFOL(fd,2); aid of player who as requested the ban
  1117. int timediff = RFIFOL(fd,6);
  1118. const char* name = (char*)RFIFOP(fd,10); // name of the target character
  1119. RFIFOSKIP(fd,10+NAME_LENGTH);
  1120. if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `account_id`,`char_id`,`unban_time` FROM `%s` WHERE `name` = '%s'", schema_config.char_db, name) )
  1121. Sql_ShowDebug(sql_handle);
  1122. else if( Sql_NumRows(sql_handle) == 0 ){
  1123. return 1; // 1-player not found
  1124. }
  1125. else if( SQL_SUCCESS != Sql_NextRow(sql_handle) ){
  1126. Sql_ShowDebug(sql_handle);
  1127. Sql_FreeResult(sql_handle);
  1128. return 1;
  1129. } else {
  1130. int t_cid=0,t_aid=0;
  1131. char* data;
  1132. time_t unban_time;
  1133. time_t now = time(NULL);
  1134. SqlStmt* stmt = SqlStmt_Malloc(sql_handle);
  1135. Sql_GetData(sql_handle, 0, &data, NULL); t_aid = atoi(data);
  1136. Sql_GetData(sql_handle, 1, &data, NULL); t_cid = atoi(data);
  1137. Sql_GetData(sql_handle, 2, &data, NULL); unban_time = atol(data);
  1138. Sql_FreeResult(sql_handle);
  1139. if(timediff<0 && unban_time==0)
  1140. return 1; //attemp to reduce time of a non banned account ?!?
  1141. else if(unban_time<now) unban_time=now; //new entry
  1142. unban_time += timediff; //alterate the time
  1143. if( unban_time < now ) unban_time=0; //we have totally reduce the time
  1144. if( SQL_SUCCESS != SqlStmt_Prepare(stmt,
  1145. "UPDATE `%s` SET `unban_time` = ? WHERE `char_id` = ? LIMIT 1",
  1146. schema_config.char_db)
  1147. || SQL_SUCCESS != SqlStmt_BindParam(stmt, 0, SQLDT_LONG, (void*)&unban_time, sizeof(unban_time))
  1148. || SQL_SUCCESS != SqlStmt_BindParam(stmt, 1, SQLDT_INT, (void*)&t_cid, sizeof(t_cid))
  1149. || SQL_SUCCESS != SqlStmt_Execute(stmt)
  1150. )
  1151. {
  1152. SqlStmt_ShowDebug(stmt);
  1153. SqlStmt_Free(stmt);
  1154. return 1;
  1155. }
  1156. SqlStmt_Free(stmt);
  1157. // condition applies; send to all map-servers to disconnect the player
  1158. if( unban_time > now ) {
  1159. unsigned char buf[11];
  1160. WBUFW(buf,0) = 0x2b14;
  1161. WBUFL(buf,2) = t_cid;
  1162. WBUFB(buf,6) = 2;
  1163. WBUFL(buf,7) = (unsigned int)unban_time;
  1164. chmapif_sendall(buf, 11);
  1165. // disconnect player if online on char-server
  1166. char_disconnect_player(t_aid);
  1167. }
  1168. }
  1169. }
  1170. return 1;
  1171. }
  1172. int chmapif_parse_reqcharunban(int fd){
  1173. if (RFIFOREST(fd) < 6+NAME_LENGTH)
  1174. return 0;
  1175. else {
  1176. const char* name = (char*)RFIFOP(fd,6);
  1177. RFIFOSKIP(fd,6+NAME_LENGTH);
  1178. if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `unban_time` = '0' WHERE `name` = '%s' LIMIT 1", schema_config.char_db, name) ) {
  1179. Sql_ShowDebug(sql_handle);
  1180. return 1;
  1181. }
  1182. }
  1183. return 1;
  1184. }
  1185. /**
  1186. * ZA 0x2b2d
  1187. * <cmd>.W <char_id>.L
  1188. * AZ 0x2b2f
  1189. * <cmd>.W <len>.W <cid>.L <count>.B { <bonus_script_data>.?B }
  1190. * Get bonus_script data(s) from table to load then send to player
  1191. * @param fd
  1192. * @author [Cydh]
  1193. **/
  1194. int chmapif_bonus_script_get(int fd) {
  1195. if (RFIFOREST(fd) < 6)
  1196. return 0;
  1197. else {
  1198. uint8 num_rows = 0;
  1199. uint32 cid = RFIFOL(fd,2);
  1200. struct bonus_script_data tmp_bsdata;
  1201. SqlStmt* stmt = SqlStmt_Malloc(sql_handle);
  1202. RFIFOSKIP(fd,6);
  1203. if (SQL_ERROR == SqlStmt_Prepare(stmt,
  1204. "SELECT `script`, `tick`, `flag`, `type`, `icon` FROM `%s` WHERE `char_id` = '%d' LIMIT %d",
  1205. schema_config.bonus_script_db, cid, MAX_PC_BONUS_SCRIPT) ||
  1206. SQL_ERROR == SqlStmt_Execute(stmt) ||
  1207. SQL_ERROR == SqlStmt_BindColumn(stmt, 0, SQLDT_STRING, &tmp_bsdata.script_str, sizeof(tmp_bsdata.script_str), NULL, NULL) ||
  1208. SQL_ERROR == SqlStmt_BindColumn(stmt, 1, SQLDT_UINT32, &tmp_bsdata.tick, 0, NULL, NULL) ||
  1209. SQL_ERROR == SqlStmt_BindColumn(stmt, 2, SQLDT_UINT16, &tmp_bsdata.flag, 0, NULL, NULL) ||
  1210. SQL_ERROR == SqlStmt_BindColumn(stmt, 3, SQLDT_UINT8, &tmp_bsdata.type, 0, NULL, NULL) ||
  1211. SQL_ERROR == SqlStmt_BindColumn(stmt, 4, SQLDT_INT16, &tmp_bsdata.icon, 0, NULL, NULL)
  1212. )
  1213. {
  1214. SqlStmt_ShowDebug(stmt);
  1215. SqlStmt_Free(stmt);
  1216. return 1;
  1217. }
  1218. if ((num_rows = (uint8)SqlStmt_NumRows(stmt)) > 0) {
  1219. uint8 i;
  1220. uint32 size = 9 + num_rows * sizeof(struct bonus_script_data);
  1221. WFIFOHEAD(fd, size);
  1222. WFIFOW(fd, 0) = 0x2b2f;
  1223. WFIFOW(fd, 2) = size;
  1224. WFIFOL(fd, 4) = cid;
  1225. WFIFOB(fd, 8) = num_rows;
  1226. for (i = 0; i < num_rows && SQL_SUCCESS == SqlStmt_NextRow(stmt); i++) {
  1227. struct bonus_script_data bsdata;
  1228. memset(&bsdata, 0, sizeof(bsdata));
  1229. memset(bsdata.script_str, '\0', sizeof(bsdata.script_str));
  1230. safestrncpy(bsdata.script_str, tmp_bsdata.script_str, strlen(tmp_bsdata.script_str)+1);
  1231. bsdata.tick = tmp_bsdata.tick;
  1232. bsdata.flag = tmp_bsdata.flag;
  1233. bsdata.type = tmp_bsdata.type;
  1234. bsdata.icon = tmp_bsdata.icon;
  1235. memcpy(WFIFOP(fd, 9 + i * sizeof(struct bonus_script_data)), &bsdata, sizeof(struct bonus_script_data));
  1236. }
  1237. WFIFOSET(fd, size);
  1238. ShowInfo("Bonus Script loaded for CID=%d. Total: %d.\n", cid, i);
  1239. if (SQL_ERROR == SqlStmt_Prepare(stmt,"DELETE FROM `%s` WHERE `char_id`='%d'",schema_config.bonus_script_db,cid) ||
  1240. SQL_ERROR == SqlStmt_Execute(stmt))
  1241. SqlStmt_ShowDebug(stmt);
  1242. }
  1243. SqlStmt_Free(stmt);
  1244. }
  1245. return 1;
  1246. }
  1247. /**
  1248. * ZA 0x2b2e
  1249. * <cmd>.W <len>.W <char_id>.L <count>.B { <bonus_script>.?B }
  1250. * Save bonus_script data(s) to the table
  1251. * @param fd
  1252. * @author [Cydh]
  1253. **/
  1254. int chmapif_bonus_script_save(int fd) {
  1255. if (RFIFOREST(fd) < 4 || RFIFOREST(fd) < RFIFOW(fd,2))
  1256. return 0;
  1257. else {
  1258. uint32 cid = RFIFOL(fd,4);
  1259. uint8 count = RFIFOB(fd,8);
  1260. if (SQL_ERROR == Sql_Query(sql_handle,"DELETE FROM `%s` WHERE `char_id` = '%d'", schema_config.bonus_script_db, cid))
  1261. Sql_ShowDebug(sql_handle);
  1262. if (count > 0) {
  1263. char esc_script[MAX_BONUS_SCRIPT_LENGTH*2];
  1264. struct bonus_script_data bsdata;
  1265. StringBuf buf;
  1266. uint8 i;
  1267. StringBuf_Init(&buf);
  1268. StringBuf_Printf(&buf, "INSERT INTO `%s` (`char_id`, `script`, `tick`, `flag`, `type`, `icon`) VALUES ", schema_config.bonus_script_db);
  1269. for (i = 0; i < count; ++i) {
  1270. memcpy(&bsdata, RFIFOP(fd, 9 + i*sizeof(struct bonus_script_data)), sizeof(struct bonus_script_data));
  1271. Sql_EscapeString(sql_handle, esc_script, bsdata.script_str);
  1272. if (i > 0)
  1273. StringBuf_AppendStr(&buf,", ");
  1274. StringBuf_Printf(&buf, "('%d','%s','%d','%d','%d','%d')", cid, esc_script, bsdata.tick, bsdata.flag, bsdata.type, bsdata.icon);
  1275. }
  1276. if (SQL_ERROR == Sql_QueryStr(sql_handle,StringBuf_Value(&buf)))
  1277. Sql_ShowDebug(sql_handle);
  1278. StringBuf_Destroy(&buf);
  1279. }
  1280. ShowInfo("Bonus Script saved for CID=%d. Total: %d.\n", cid, count);
  1281. RFIFOSKIP(fd,RFIFOW(fd,2));
  1282. }
  1283. return 1;
  1284. }
  1285. /**
  1286. * Inform the mapserv wheater his login attemp to us was a success or not
  1287. * @param fd : file descriptor to parse, (link to mapserv)
  1288. * @param errCode 0:success, 3:fail
  1289. */
  1290. void chmapif_connectack(int fd, uint8 errCode){
  1291. WFIFOHEAD(fd,3);
  1292. WFIFOW(fd,0) = 0x2af9;
  1293. WFIFOB(fd,2) = errCode;
  1294. WFIFOSET(fd,3);
  1295. }
  1296. /**
  1297. * Entry point from map-server to char-server.
  1298. * Function that checks incoming command, then splits it to the correct handler.
  1299. * If not found any hander here transmis packet to inter
  1300. * @param fd: file descriptor to parse, (link to map-serv)
  1301. * @return 0=invalid server,marked for disconnection,unknow packet; 1=success
  1302. */
  1303. int chmapif_parse(int fd){
  1304. int id; //mapserv id
  1305. ARR_FIND( 0, ARRAYLENGTH(map_server), id, map_server[id].fd == fd );
  1306. if( id == ARRAYLENGTH(map_server) )
  1307. {// not a map server
  1308. ShowDebug("parse_frommap: Disconnecting invalid session #%d (is not a map-server)\n", fd);
  1309. do_close(fd);
  1310. return 0;
  1311. }
  1312. if( session[fd]->flag.eof )
  1313. {
  1314. do_close(fd);
  1315. map_server[id].fd = -1;
  1316. chmapif_on_disconnect(id);
  1317. return 0;
  1318. }
  1319. while(RFIFOREST(fd) >= 2){
  1320. int next=1;
  1321. switch(RFIFOW(fd,0)){
  1322. case 0x2736: next=chmapif_parse_updmapip(fd,id); break;
  1323. case 0x2afa: next=chmapif_parse_getmapname(fd,id); break;
  1324. case 0x2afc: next=chmapif_parse_askscdata(fd); break;
  1325. case 0x2afe: next=chmapif_parse_getusercount(fd,id); break; //get nb user
  1326. case 0x2aff: next=chmapif_parse_regmapuser(fd,id); break; //register users
  1327. case 0x2b01: next=chmapif_parse_reqsavechar(fd,id); break;
  1328. case 0x2b02: next=chmapif_parse_authok(fd); break;
  1329. case 0x2b05: next=chmapif_parse_reqchangemapserv(fd); break;
  1330. case 0x2b07: next=chmapif_parse_askrmfriend(fd); break;
  1331. case 0x2b08: next=chmapif_parse_reqcharname(fd); break;
  1332. case 0x2b0a: next=chmapif_parse_req_skillcooldown(fd); break;
  1333. case 0x2b0c: next=chmapif_parse_reqnewemail(fd); break;
  1334. case 0x2b0e: next=chmapif_parse_fwlog_changestatus(fd); break;
  1335. case 0x2b10: next=chmapif_parse_updfamelist(fd); break;
  1336. case 0x2b11: next=chmapif_parse_reqdivorce(fd); break;
  1337. case 0x2b15: next=chmapif_parse_req_saveskillcooldown(fd); break;
  1338. case 0x2b16: next=chmapif_parse_updmapinfo(fd); break;
  1339. case 0x2b17: next=chmapif_parse_setcharoffline(fd); break;
  1340. case 0x2b18: next=chmapif_parse_setalloffline(fd,id); break;
  1341. case 0x2b19: next=chmapif_parse_setcharonline(fd,id); break;
  1342. case 0x2b1a: next=chmapif_parse_reqfamelist(fd); break;
  1343. case 0x2b1c: next=chmapif_parse_save_scdata(fd); break;
  1344. case 0x2b23: next=chmapif_parse_keepalive(fd); break;
  1345. case 0x2b26: next=chmapif_parse_reqauth(fd,id); break;
  1346. case 0x2b28: next=chmapif_parse_reqcharban(fd); break; //charban
  1347. case 0x2b2a: next=chmapif_parse_reqcharunban(fd); break; //charunban
  1348. //case 0x2b2c: /*free*/; break;
  1349. case 0x2b2d: next=chmapif_bonus_script_get(fd); break; //Load data
  1350. case 0x2b2e: next=chmapif_bonus_script_save(fd); break;//Save data
  1351. case 0x3008: next=chmapif_parse_fw_configstats(fd); break;
  1352. default:
  1353. {
  1354. // inter server - packet
  1355. int r = inter_parse_frommap(fd);
  1356. if (r == 1) break; // processed
  1357. if (r == 2) return 0; // need more packet
  1358. // no inter server packet. no char server packet -> disconnect
  1359. ShowError("Unknown packet 0x%04x from map server, disconnecting.\n", RFIFOW(fd,0));
  1360. set_eof(fd);
  1361. return 0;
  1362. }
  1363. } // switch
  1364. if(next==0) return 0; //avoid processing rest of packet
  1365. } // while
  1366. return 1;
  1367. }
  1368. // Initialization process (currently only initialization inter_mapif)
  1369. int chmapif_init(int fd){
  1370. return inter_mapif_init(fd);
  1371. }
  1372. /**
  1373. * Initializes a server structure.
  1374. * @param id: id of map-serv (should be >0, FIXME)
  1375. */
  1376. void chmapif_server_init(int id) {
  1377. memset(&map_server[id], 0, sizeof(map_server[id]));
  1378. map_server[id].fd = -1;
  1379. }
  1380. /**
  1381. * Destroys a server structure.
  1382. * @param id: id of map-serv (should be >0, FIXME)
  1383. */
  1384. void chmapif_server_destroy(int id){
  1385. if( map_server[id].fd == -1 ){
  1386. do_close(map_server[id].fd);
  1387. map_server[id].fd = -1;
  1388. }
  1389. }
  1390. /**
  1391. * chmapif constructor
  1392. * Initialisation, function called at start of the char-serv.
  1393. */
  1394. void do_init_chmapif(void){
  1395. int i;
  1396. for( i = 0; i < ARRAYLENGTH(map_server); ++i )
  1397. chmapif_server_init(i);
  1398. }
  1399. /**
  1400. * Resets all the data related to a server.
  1401. * Actually destroys then recreates the struct.
  1402. * @param id: id of map-serv (should be >0, FIXME)
  1403. */
  1404. void chmapif_server_reset(int id){
  1405. int i,j;
  1406. unsigned char buf[16384];
  1407. int fd = map_server[id].fd;
  1408. DBMap* online_char_db = char_get_onlinedb();
  1409. //Notify other map servers that this one is gone. [Skotlex]
  1410. WBUFW(buf,0) = 0x2b20;
  1411. WBUFL(buf,4) = htonl(map_server[id].ip);
  1412. WBUFW(buf,8) = htons(map_server[id].port);
  1413. j = 0;
  1414. for(i = 0; i < MAX_MAP_PER_SERVER; i++)
  1415. if (map_server[id].map[i])
  1416. WBUFW(buf,10+(j++)*4) = map_server[id].map[i];
  1417. if (j > 0) {
  1418. WBUFW(buf,2) = j * 4 + 10;
  1419. chmapif_sendallwos(fd, buf, WBUFW(buf,2));
  1420. }
  1421. if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `index`='%d'", schema_config.ragsrvinfo_db, map_server[id].fd) )
  1422. Sql_ShowDebug(sql_handle);
  1423. online_char_db->foreach(online_char_db,char_db_setoffline,id); //Tag relevant chars as 'in disconnected' server.
  1424. chmapif_server_destroy(id);
  1425. chmapif_server_init(id);
  1426. }
  1427. /**
  1428. * Called when the connection to Map Server is disconnected.
  1429. * @param id: id of map-serv (should be >0, FIXME)
  1430. */
  1431. void chmapif_on_disconnect(int id){
  1432. ShowStatus("Map-server #%d has disconnected.\n", id);
  1433. chmapif_server_reset(id);
  1434. }
  1435. /**
  1436. * chmapif destructor
  1437. * dealloc..., function called at exit of the char-serv
  1438. */
  1439. void do_final_chmapif(void){
  1440. int i;
  1441. for( i = 0; i < ARRAYLENGTH(map_server); ++i )
  1442. chmapif_server_destroy(i);
  1443. }