char_mapif.c 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582
  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, 0, &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. cd->sex = sex;
  947. WFIFOHEAD(fd,mmo_charstatus_len);
  948. WFIFOW(fd,0) = 0x2afd;
  949. WFIFOW(fd,2) = mmo_charstatus_len;
  950. WFIFOL(fd,4) = account_id;
  951. WFIFOL(fd,8) = 0;
  952. WFIFOL(fd,12) = 0;
  953. WFIFOL(fd,16) = 0;
  954. WFIFOL(fd,20) = 0;
  955. WFIFOB(fd,24) = 0;
  956. memcpy(WFIFOP(fd,25), cd, sizeof(struct mmo_charstatus));
  957. WFIFOSET(fd, WFIFOW(fd,2));
  958. char_set_char_online(id, char_id, account_id);
  959. } else if( runflag == CHARSERVER_ST_RUNNING &&
  960. cd != NULL &&
  961. node != NULL &&
  962. node->account_id == account_id &&
  963. node->char_id == char_id &&
  964. node->login_id1 == login_id1 &&
  965. node->sex == sex /*&&
  966. node->ip == ip*/ )
  967. {// auth ok
  968. uint16 mmo_charstatus_len = sizeof(struct mmo_charstatus) + 25;
  969. if (cd->sex == 99)
  970. cd->sex = sex;
  971. WFIFOHEAD(fd,mmo_charstatus_len);
  972. WFIFOW(fd,0) = 0x2afd;
  973. WFIFOW(fd,2) = mmo_charstatus_len;
  974. WFIFOL(fd,4) = account_id;
  975. WFIFOL(fd,8) = node->login_id1;
  976. WFIFOL(fd,12) = node->login_id2;
  977. WFIFOL(fd,16) = (uint32)node->expiration_time; // FIXME: will wrap to negative after "19-Jan-2038, 03:14:07 AM GMT"
  978. WFIFOL(fd,20) = node->group_id;
  979. WFIFOB(fd,24) = node->changing_mapservers;
  980. memcpy(WFIFOP(fd,25), cd, sizeof(struct mmo_charstatus));
  981. WFIFOSET(fd, WFIFOW(fd,2));
  982. // only use the auth once and mark user online
  983. idb_remove(auth_db, account_id);
  984. char_set_char_online(id, char_id, account_id);
  985. } else {// auth failed
  986. WFIFOHEAD(fd,19);
  987. WFIFOW(fd,0) = 0x2b27;
  988. WFIFOL(fd,2) = account_id;
  989. WFIFOL(fd,6) = char_id;
  990. WFIFOL(fd,10) = login_id1;
  991. WFIFOB(fd,14) = sex;
  992. WFIFOL(fd,15) = htonl(ip);
  993. WFIFOSET(fd,19);
  994. }
  995. }
  996. return 1;
  997. }
  998. /**
  999. * ip address update
  1000. * @param fd: wich fd to parse from
  1001. * @return : 0 not enough data received, 1 success
  1002. */
  1003. int chmapif_parse_updmapip(int fd, int id){
  1004. if (RFIFOREST(fd) < 6)
  1005. return 0;
  1006. map_server[id].ip = ntohl(RFIFOL(fd, 2));
  1007. ShowInfo("Updated IP address of map-server #%d to %d.%d.%d.%d.\n", id, CONVIP(map_server[id].ip));
  1008. RFIFOSKIP(fd,6);
  1009. return 1;
  1010. }
  1011. /**
  1012. * transmit emu usage for anom stats
  1013. * @param fd: wich fd to parse from
  1014. * @return : 0 not enough data received, 1 success
  1015. */
  1016. int chmapif_parse_fw_configstats(int fd){
  1017. if( RFIFOREST(fd) < RFIFOW(fd,4) )
  1018. return 0;/* packet wasn't fully received yet (still fragmented) */
  1019. else {
  1020. int sfd;/* stat server fd */
  1021. 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 */
  1022. if( (sfd = make_connection(host2ip("stats.rathena.org"),(uint16)25421,true,10) ) == -1 ) {
  1023. RFIFOSKIP(fd, RFIFOW(fd,2) );/* skip this packet */
  1024. return 0;/* connection not possible, we drop the report */
  1025. }
  1026. session[sfd]->flag.server = 1;/* to ensure we won't drop our own packet */
  1027. WFIFOHEAD(sfd, RFIFOW(fd,2) );
  1028. memcpy((char*)WFIFOP(sfd,0), (char*)RFIFOP(fd, 0), RFIFOW(fd,2));
  1029. WFIFOSET(sfd, RFIFOW(fd,2) );
  1030. flush_fifo(sfd);
  1031. do_close(sfd);
  1032. RFIFOSKIP(fd, RFIFOW(fd,2) );/* skip this packet */
  1033. }
  1034. return 1;
  1035. }
  1036. /**
  1037. * Received an update of fame point for char_id cid
  1038. * Update the list associated and transmit the new ranking
  1039. * @param fd: wich fd to parse from
  1040. * @return : 0 not enough data received, 1 success
  1041. */
  1042. int chmapif_parse_updfamelist(int fd){
  1043. if (RFIFOREST(fd) < 11)
  1044. return 0;
  1045. {
  1046. int cid = RFIFOL(fd, 2);
  1047. int fame = RFIFOL(fd, 6);
  1048. char type = RFIFOB(fd, 10);
  1049. int size;
  1050. struct fame_list* list;
  1051. int player_pos;
  1052. int fame_pos;
  1053. switch(type)
  1054. {
  1055. case 1: size = fame_list_size_smith; list = smith_fame_list; break;
  1056. case 2: size = fame_list_size_chemist; list = chemist_fame_list; break;
  1057. case 3: size = fame_list_size_taekwon; list = taekwon_fame_list; break;
  1058. default: size = 0; list = NULL; break;
  1059. }
  1060. ARR_FIND(0, size, player_pos, list[player_pos].id == cid);// position of the player
  1061. ARR_FIND(0, size, fame_pos, list[fame_pos].fame <= fame);// where the player should be
  1062. if( player_pos == size && fame_pos == size )
  1063. ;// not on list and not enough fame to get on it
  1064. else if( fame_pos == player_pos )
  1065. {// same position
  1066. list[player_pos].fame = fame;
  1067. chmapif_update_fame_list(type, player_pos, fame);
  1068. }
  1069. else
  1070. {// move in the list
  1071. if( player_pos == size )
  1072. {// new ranker - not in the list
  1073. ARR_MOVE(size - 1, fame_pos, list, struct fame_list);
  1074. list[fame_pos].id = cid;
  1075. list[fame_pos].fame = fame;
  1076. char_loadName(cid, list[fame_pos].name);
  1077. }
  1078. else
  1079. {// already in the list
  1080. if( fame_pos == size )
  1081. --fame_pos;// move to the end of the list
  1082. ARR_MOVE(player_pos, fame_pos, list, struct fame_list);
  1083. list[fame_pos].fame = fame;
  1084. }
  1085. chmapif_send_fame_list(-1);
  1086. }
  1087. RFIFOSKIP(fd,11);
  1088. }
  1089. return 1;
  1090. }
  1091. /*
  1092. * HZ 0x2b2b
  1093. * Transmist vip data to mapserv
  1094. */
  1095. int chmapif_vipack(int mapfd, uint32 aid, uint32 vip_time, uint8 isvip, uint8 isgm, uint32 groupid) {
  1096. #ifdef VIP_ENABLE
  1097. uint8 buf[16];
  1098. WBUFW(buf,0) = 0x2b2b;
  1099. WBUFL(buf,2) = aid;
  1100. WBUFL(buf,6) = vip_time;
  1101. WBUFB(buf,10) = isvip;
  1102. WBUFB(buf,11) = isgm;
  1103. WBUFL(buf,12) = groupid;
  1104. chmapif_send(mapfd,buf,16); // inform the mapserv back
  1105. #endif
  1106. return 0;
  1107. }
  1108. int chmapif_parse_reqcharban(int fd){
  1109. if (RFIFOREST(fd) < 10+NAME_LENGTH)
  1110. return 0;
  1111. else {
  1112. //int aid = RFIFOL(fd,2); aid of player who as requested the ban
  1113. int timediff = RFIFOL(fd,6);
  1114. const char* name = (char*)RFIFOP(fd,10); // name of the target character
  1115. RFIFOSKIP(fd,10+NAME_LENGTH);
  1116. if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `account_id`,`char_id`,`unban_time` FROM `%s` WHERE `name` = '%s'", schema_config.char_db, name) )
  1117. Sql_ShowDebug(sql_handle);
  1118. else if( Sql_NumRows(sql_handle) == 0 ){
  1119. return 1; // 1-player not found
  1120. }
  1121. else if( SQL_SUCCESS != Sql_NextRow(sql_handle) ){
  1122. Sql_ShowDebug(sql_handle);
  1123. Sql_FreeResult(sql_handle);
  1124. return 1;
  1125. } else {
  1126. int t_cid=0,t_aid=0;
  1127. char* data;
  1128. time_t unban_time;
  1129. time_t now = time(NULL);
  1130. SqlStmt* stmt = SqlStmt_Malloc(sql_handle);
  1131. Sql_GetData(sql_handle, 0, &data, NULL); t_aid = atoi(data);
  1132. Sql_GetData(sql_handle, 1, &data, NULL); t_cid = atoi(data);
  1133. Sql_GetData(sql_handle, 2, &data, NULL); unban_time = atol(data);
  1134. Sql_FreeResult(sql_handle);
  1135. if(timediff<0 && unban_time==0)
  1136. return 1; //attemp to reduce time of a non banned account ?!?
  1137. else if(unban_time<now) unban_time=now; //new entry
  1138. unban_time += timediff; //alterate the time
  1139. if( unban_time < now ) unban_time=0; //we have totally reduce the time
  1140. if( SQL_SUCCESS != SqlStmt_Prepare(stmt,
  1141. "UPDATE `%s` SET `unban_time` = ? WHERE `char_id` = ? LIMIT 1",
  1142. schema_config.char_db)
  1143. || SQL_SUCCESS != SqlStmt_BindParam(stmt, 0, SQLDT_LONG, (void*)&unban_time, sizeof(unban_time))
  1144. || SQL_SUCCESS != SqlStmt_BindParam(stmt, 1, SQLDT_INT, (void*)&t_cid, sizeof(t_cid))
  1145. || SQL_SUCCESS != SqlStmt_Execute(stmt)
  1146. )
  1147. {
  1148. SqlStmt_ShowDebug(stmt);
  1149. SqlStmt_Free(stmt);
  1150. return 1;
  1151. }
  1152. SqlStmt_Free(stmt);
  1153. // condition applies; send to all map-servers to disconnect the player
  1154. if( unban_time > now ) {
  1155. unsigned char buf[11];
  1156. WBUFW(buf,0) = 0x2b14;
  1157. WBUFL(buf,2) = t_cid;
  1158. WBUFB(buf,6) = 2;
  1159. WBUFL(buf,7) = (unsigned int)unban_time;
  1160. chmapif_sendall(buf, 11);
  1161. // disconnect player if online on char-server
  1162. char_disconnect_player(t_aid);
  1163. }
  1164. }
  1165. }
  1166. return 1;
  1167. }
  1168. int chmapif_parse_reqcharunban(int fd){
  1169. if (RFIFOREST(fd) < 6+NAME_LENGTH)
  1170. return 0;
  1171. else {
  1172. const char* name = (char*)RFIFOP(fd,6);
  1173. RFIFOSKIP(fd,6+NAME_LENGTH);
  1174. if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `unban_time` = '0' WHERE `name` = '%s' LIMIT 1", schema_config.char_db, name) ) {
  1175. Sql_ShowDebug(sql_handle);
  1176. return 1;
  1177. }
  1178. }
  1179. return 1;
  1180. }
  1181. /**
  1182. * ZA 0x2b2d
  1183. * <cmd>.W <char_id>.L
  1184. * AZ 0x2b2f
  1185. * <cmd>.W <len>.W <cid>.L <count>.B { <bonus_script_data>.?B }
  1186. * Get bonus_script data(s) from table to load then send to player
  1187. * @param fd
  1188. * @author [Cydh]
  1189. **/
  1190. int chmapif_bonus_script_get(int fd) {
  1191. if (RFIFOREST(fd) < 6)
  1192. return 0;
  1193. else {
  1194. uint8 num_rows = 0;
  1195. uint32 cid = RFIFOL(fd,2);
  1196. struct bonus_script_data tmp_bsdata;
  1197. SqlStmt* stmt = SqlStmt_Malloc(sql_handle);
  1198. RFIFOSKIP(fd,6);
  1199. if (SQL_ERROR == SqlStmt_Prepare(stmt,
  1200. "SELECT `script`, `tick`, `flag`, `type`, `icon` FROM `%s` WHERE `char_id` = '%d' LIMIT %d",
  1201. schema_config.bonus_script_db, cid, MAX_PC_BONUS_SCRIPT) ||
  1202. SQL_ERROR == SqlStmt_Execute(stmt) ||
  1203. SQL_ERROR == SqlStmt_BindColumn(stmt, 0, SQLDT_STRING, &tmp_bsdata.script_str, sizeof(tmp_bsdata.script_str), NULL, NULL) ||
  1204. SQL_ERROR == SqlStmt_BindColumn(stmt, 1, SQLDT_UINT32, &tmp_bsdata.tick, 0, NULL, NULL) ||
  1205. SQL_ERROR == SqlStmt_BindColumn(stmt, 2, SQLDT_UINT16, &tmp_bsdata.flag, 0, NULL, NULL) ||
  1206. SQL_ERROR == SqlStmt_BindColumn(stmt, 3, SQLDT_UINT8, &tmp_bsdata.type, 0, NULL, NULL) ||
  1207. SQL_ERROR == SqlStmt_BindColumn(stmt, 4, SQLDT_INT16, &tmp_bsdata.icon, 0, NULL, NULL)
  1208. )
  1209. {
  1210. SqlStmt_ShowDebug(stmt);
  1211. SqlStmt_Free(stmt);
  1212. return 1;
  1213. }
  1214. if ((num_rows = (uint8)SqlStmt_NumRows(stmt)) > 0) {
  1215. uint8 i;
  1216. uint32 size = 9 + num_rows * sizeof(struct bonus_script_data);
  1217. WFIFOHEAD(fd, size);
  1218. WFIFOW(fd, 0) = 0x2b2f;
  1219. WFIFOW(fd, 2) = size;
  1220. WFIFOL(fd, 4) = cid;
  1221. WFIFOB(fd, 8) = num_rows;
  1222. for (i = 0; i < num_rows && SQL_SUCCESS == SqlStmt_NextRow(stmt); i++) {
  1223. struct bonus_script_data bsdata;
  1224. memset(&bsdata, 0, sizeof(bsdata));
  1225. memset(bsdata.script_str, '\0', sizeof(bsdata.script_str));
  1226. safestrncpy(bsdata.script_str, tmp_bsdata.script_str, strlen(tmp_bsdata.script_str)+1);
  1227. bsdata.tick = tmp_bsdata.tick;
  1228. bsdata.flag = tmp_bsdata.flag;
  1229. bsdata.type = tmp_bsdata.type;
  1230. bsdata.icon = tmp_bsdata.icon;
  1231. memcpy(WFIFOP(fd, 9 + i * sizeof(struct bonus_script_data)), &bsdata, sizeof(struct bonus_script_data));
  1232. }
  1233. WFIFOSET(fd, size);
  1234. ShowInfo("Bonus Script loaded for CID=%d. Total: %d.\n", cid, i);
  1235. if (SQL_ERROR == SqlStmt_Prepare(stmt,"DELETE FROM `%s` WHERE `char_id`='%d'",schema_config.bonus_script_db,cid) ||
  1236. SQL_ERROR == SqlStmt_Execute(stmt))
  1237. SqlStmt_ShowDebug(stmt);
  1238. }
  1239. SqlStmt_Free(stmt);
  1240. }
  1241. return 1;
  1242. }
  1243. /**
  1244. * ZA 0x2b2e
  1245. * <cmd>.W <len>.W <char_id>.L <count>.B { <bonus_script>.?B }
  1246. * Save bonus_script data(s) to the table
  1247. * @param fd
  1248. * @author [Cydh]
  1249. **/
  1250. int chmapif_bonus_script_save(int fd) {
  1251. if (RFIFOREST(fd) < 4 || RFIFOREST(fd) < RFIFOW(fd,2))
  1252. return 0;
  1253. else {
  1254. uint32 cid = RFIFOL(fd,4);
  1255. uint8 count = RFIFOB(fd,8);
  1256. if (SQL_ERROR == Sql_Query(sql_handle,"DELETE FROM `%s` WHERE `char_id` = '%d'", schema_config.bonus_script_db, cid))
  1257. Sql_ShowDebug(sql_handle);
  1258. if (count > 0) {
  1259. char esc_script[MAX_BONUS_SCRIPT_LENGTH*2];
  1260. struct bonus_script_data bsdata;
  1261. StringBuf buf;
  1262. uint8 i;
  1263. StringBuf_Init(&buf);
  1264. StringBuf_Printf(&buf, "INSERT INTO `%s` (`char_id`, `script`, `tick`, `flag`, `type`, `icon`) VALUES ", schema_config.bonus_script_db);
  1265. for (i = 0; i < count; ++i) {
  1266. memcpy(&bsdata, RFIFOP(fd, 9 + i*sizeof(struct bonus_script_data)), sizeof(struct bonus_script_data));
  1267. Sql_EscapeString(sql_handle, esc_script, bsdata.script_str);
  1268. if (i > 0)
  1269. StringBuf_AppendStr(&buf,", ");
  1270. StringBuf_Printf(&buf, "('%d','%s','%d','%d','%d','%d')", cid, esc_script, bsdata.tick, bsdata.flag, bsdata.type, bsdata.icon);
  1271. }
  1272. if (SQL_ERROR == Sql_QueryStr(sql_handle,StringBuf_Value(&buf)))
  1273. Sql_ShowDebug(sql_handle);
  1274. StringBuf_Destroy(&buf);
  1275. }
  1276. ShowInfo("Bonus Script saved for CID=%d. Total: %d.\n", cid, count);
  1277. RFIFOSKIP(fd,RFIFOW(fd,2));
  1278. }
  1279. return 1;
  1280. }
  1281. /**
  1282. * Inform the mapserv wheater his login attemp to us was a success or not
  1283. * @param fd : file descriptor to parse, (link to mapserv)
  1284. * @param errCode 0:success, 3:fail
  1285. */
  1286. void chmapif_connectack(int fd, uint8 errCode){
  1287. WFIFOHEAD(fd,3);
  1288. WFIFOW(fd,0) = 0x2af9;
  1289. WFIFOB(fd,2) = errCode;
  1290. WFIFOSET(fd,3);
  1291. }
  1292. /**
  1293. * Entry point from map-server to char-server.
  1294. * Function that checks incoming command, then splits it to the correct handler.
  1295. * If not found any hander here transmis packet to inter
  1296. * @param fd: file descriptor to parse, (link to map-serv)
  1297. * @return 0=invalid server,marked for disconnection,unknow packet; 1=success
  1298. */
  1299. int chmapif_parse(int fd){
  1300. int id; //mapserv id
  1301. ARR_FIND( 0, ARRAYLENGTH(map_server), id, map_server[id].fd == fd );
  1302. if( id == ARRAYLENGTH(map_server) )
  1303. {// not a map server
  1304. ShowDebug("parse_frommap: Disconnecting invalid session #%d (is not a map-server)\n", fd);
  1305. do_close(fd);
  1306. return 0;
  1307. }
  1308. if( session[fd]->flag.eof )
  1309. {
  1310. do_close(fd);
  1311. map_server[id].fd = -1;
  1312. chmapif_on_disconnect(id);
  1313. return 0;
  1314. }
  1315. while(RFIFOREST(fd) >= 2){
  1316. int next=1;
  1317. switch(RFIFOW(fd,0)){
  1318. case 0x2736: next=chmapif_parse_updmapip(fd,id); break;
  1319. case 0x2afa: next=chmapif_parse_getmapname(fd,id); break;
  1320. case 0x2afc: next=chmapif_parse_askscdata(fd); break;
  1321. case 0x2afe: next=chmapif_parse_getusercount(fd,id); break; //get nb user
  1322. case 0x2aff: next=chmapif_parse_regmapuser(fd,id); break; //register users
  1323. case 0x2b01: next=chmapif_parse_reqsavechar(fd,id); break;
  1324. case 0x2b02: next=chmapif_parse_authok(fd); break;
  1325. case 0x2b05: next=chmapif_parse_reqchangemapserv(fd); break;
  1326. case 0x2b07: next=chmapif_parse_askrmfriend(fd); break;
  1327. case 0x2b08: next=chmapif_parse_reqcharname(fd); break;
  1328. case 0x2b0a: next=chmapif_parse_req_skillcooldown(fd); break;
  1329. case 0x2b0c: next=chmapif_parse_reqnewemail(fd); break;
  1330. case 0x2b0e: next=chmapif_parse_fwlog_changestatus(fd); break;
  1331. case 0x2b10: next=chmapif_parse_updfamelist(fd); break;
  1332. case 0x2b11: next=chmapif_parse_reqdivorce(fd); break;
  1333. case 0x2b15: next=chmapif_parse_req_saveskillcooldown(fd); break;
  1334. case 0x2b16: next=chmapif_parse_updmapinfo(fd); break;
  1335. case 0x2b17: next=chmapif_parse_setcharoffline(fd); break;
  1336. case 0x2b18: next=chmapif_parse_setalloffline(fd,id); break;
  1337. case 0x2b19: next=chmapif_parse_setcharonline(fd,id); break;
  1338. case 0x2b1a: next=chmapif_parse_reqfamelist(fd); break;
  1339. case 0x2b1c: next=chmapif_parse_save_scdata(fd); break;
  1340. case 0x2b23: next=chmapif_parse_keepalive(fd); break;
  1341. case 0x2b26: next=chmapif_parse_reqauth(fd,id); break;
  1342. case 0x2b28: next=chmapif_parse_reqcharban(fd); break; //charban
  1343. case 0x2b2a: next=chmapif_parse_reqcharunban(fd); break; //charunban
  1344. //case 0x2b2c: /*free*/; break;
  1345. case 0x2b2d: next=chmapif_bonus_script_get(fd); break; //Load data
  1346. case 0x2b2e: next=chmapif_bonus_script_save(fd); break;//Save data
  1347. case 0x3008: next=chmapif_parse_fw_configstats(fd); break;
  1348. default:
  1349. {
  1350. // inter server - packet
  1351. int r = inter_parse_frommap(fd);
  1352. if (r == 1) break; // processed
  1353. if (r == 2) return 0; // need more packet
  1354. // no inter server packet. no char server packet -> disconnect
  1355. ShowError("Unknown packet 0x%04x from map server, disconnecting.\n", RFIFOW(fd,0));
  1356. set_eof(fd);
  1357. return 0;
  1358. }
  1359. } // switch
  1360. if(next==0) return 0; //avoid processing rest of packet
  1361. } // while
  1362. return 1;
  1363. }
  1364. // Initialization process (currently only initialization inter_mapif)
  1365. int chmapif_init(int fd){
  1366. return inter_mapif_init(fd);
  1367. }
  1368. /**
  1369. * Initializes a server structure.
  1370. * @param id: id of map-serv (should be >0, FIXME)
  1371. */
  1372. void chmapif_server_init(int id) {
  1373. memset(&map_server[id], 0, sizeof(map_server[id]));
  1374. map_server[id].fd = -1;
  1375. }
  1376. /**
  1377. * Destroys a server structure.
  1378. * @param id: id of map-serv (should be >0, FIXME)
  1379. */
  1380. void chmapif_server_destroy(int id){
  1381. if( map_server[id].fd == -1 ){
  1382. do_close(map_server[id].fd);
  1383. map_server[id].fd = -1;
  1384. }
  1385. }
  1386. /**
  1387. * chmapif constructor
  1388. * Initialisation, function called at start of the char-serv.
  1389. */
  1390. void do_init_chmapif(void){
  1391. int i;
  1392. for( i = 0; i < ARRAYLENGTH(map_server); ++i )
  1393. chmapif_server_init(i);
  1394. }
  1395. /**
  1396. * Resets all the data related to a server.
  1397. * Actually destroys then recreates the struct.
  1398. * @param id: id of map-serv (should be >0, FIXME)
  1399. */
  1400. void chmapif_server_reset(int id){
  1401. int i,j;
  1402. unsigned char buf[16384];
  1403. int fd = map_server[id].fd;
  1404. DBMap* online_char_db = char_get_onlinedb();
  1405. //Notify other map servers that this one is gone. [Skotlex]
  1406. WBUFW(buf,0) = 0x2b20;
  1407. WBUFL(buf,4) = htonl(map_server[id].ip);
  1408. WBUFW(buf,8) = htons(map_server[id].port);
  1409. j = 0;
  1410. for(i = 0; i < MAX_MAP_PER_SERVER; i++)
  1411. if (map_server[id].map[i])
  1412. WBUFW(buf,10+(j++)*4) = map_server[id].map[i];
  1413. if (j > 0) {
  1414. WBUFW(buf,2) = j * 4 + 10;
  1415. chmapif_sendallwos(fd, buf, WBUFW(buf,2));
  1416. }
  1417. if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `index`='%d'", schema_config.ragsrvinfo_db, map_server[id].fd) )
  1418. Sql_ShowDebug(sql_handle);
  1419. online_char_db->foreach(online_char_db,char_db_setoffline,id); //Tag relevant chars as 'in disconnected' server.
  1420. chmapif_server_destroy(id);
  1421. chmapif_server_init(id);
  1422. }
  1423. /**
  1424. * Called when the connection to Map Server is disconnected.
  1425. * @param id: id of map-serv (should be >0, FIXME)
  1426. */
  1427. void chmapif_on_disconnect(int id){
  1428. ShowStatus("Map-server #%d has disconnected.\n", id);
  1429. chmapif_server_reset(id);
  1430. }
  1431. /**
  1432. * chmapif destructor
  1433. * dealloc..., function called at exit of the char-serv
  1434. */
  1435. void do_final_chmapif(void){
  1436. int i;
  1437. for( i = 0; i < ARRAYLENGTH(map_server); ++i )
  1438. chmapif_server_destroy(i);
  1439. }