PageRenderTime 59ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/src/map/chrif.c

https://gitlab.com/evol/hercules
C | 1790 lines | 1207 code | 305 blank | 278 comment | 258 complexity | 32098588d99b9c8a78aeacbfc2453412 MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.0
  1. /**
  2. * This file is part of Hercules.
  3. * http://herc.ws - http://github.com/HerculesWS/Hercules
  4. *
  5. * Copyright (C) 2012-2015 Hercules Dev Team
  6. * Copyright (C) Athena Dev Teams
  7. *
  8. * Hercules is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. #define HERCULES_CORE
  22. #include "config/core.h" // AUTOTRADE_PERSISTENCY, STATS_OPT_OUT
  23. #include "chrif.h"
  24. #include "map/battle.h"
  25. #include "map/clif.h"
  26. #include "map/elemental.h"
  27. #include "map/guild.h"
  28. #include "map/homunculus.h"
  29. #include "map/instance.h"
  30. #include "map/intif.h"
  31. #include "map/map.h"
  32. #include "map/mercenary.h"
  33. #include "map/npc.h"
  34. #include "map/pc.h"
  35. #include "map/pet.h"
  36. #include "map/quest.h"
  37. #include "map/skill.h"
  38. #include "map/status.h"
  39. #include "map/storage.h"
  40. #include "common/HPM.h"
  41. #include "common/cbasetypes.h"
  42. #include "common/ers.h"
  43. #include "common/memmgr.h"
  44. #include "common/nullpo.h"
  45. #include "common/showmsg.h"
  46. #include "common/socket.h"
  47. #include "common/strlib.h"
  48. #include "common/timer.h"
  49. #include <stdio.h>
  50. #include <stdlib.h>
  51. #include <sys/types.h>
  52. struct chrif_interface chrif_s;
  53. struct chrif_interface *chrif;
  54. //Used Packets:
  55. //2af8: Outgoing, chrif_connect -> 'connect to charserver / auth @ charserver'
  56. //2af9: Incoming, chrif_connectack -> 'answer of the 2af8 login(ok / fail)'
  57. //2afa: Outgoing, chrif_sendmap -> 'sending our maps'
  58. //2afb: Incoming, chrif_sendmapack -> 'Maps received successfully / or not ..'
  59. //2afc: Outgoing, chrif_scdata_request -> request sc_data for pc->authok'ed char. <- new command reuses previous one.
  60. //2afd: Incoming, chrif_authok -> 'client authentication ok'
  61. //2afe: Outgoing, send_usercount_tochar -> 'sends player count of this map server to charserver'
  62. //2aff: Outgoing, chrif_send_users_tochar -> 'sends all actual connected character ids to charserver'
  63. //2b00: Incoming, map_setusers -> 'set the actual usercount? PACKET.2B COUNT.L.. ?' (not sure)
  64. //2b01: Outgoing, chrif_save -> 'charsave of char XY account XY (complete struct)'
  65. //2b02: Outgoing, chrif_charselectreq -> 'player returns from ingame to charserver to select another char.., this packets includes sessid etc' ? (not 100% sure)
  66. //2b03: Incoming, clif_charselectok -> '' (i think its the packet after enterworld?) (not sure)
  67. //2b04: Incoming, chrif_recvmap -> 'getting maps from charserver of other mapserver's'
  68. //2b05: Outgoing, chrif_changemapserver -> 'Tell the charserver the mapchange / quest for ok...'
  69. //2b06: Incoming, chrif_changemapserverack -> 'answer of 2b05, ok/fail, data: dunno^^'
  70. //2b07: Outgoing, chrif_removefriend -> 'Tell charserver to remove friend_id from char_id friend list'
  71. //2b08: Outgoing, chrif_searchcharid -> '...'
  72. //2b09: Incoming, map_addchariddb -> 'Adds a name to the nick db'
  73. //2b0a: Incoming/Outgoing, socket_datasync()
  74. //2b0b: Outgoing, update charserv skillid2idx
  75. //2b0c: Outgoing, chrif_changeemail -> 'change mail address ...'
  76. //2b0d: Incoming, chrif_changedsex -> 'Change sex of acc XY' (or char)
  77. //2b0e: Outgoing, chrif_char_ask_name -> 'Do some operations (change sex, ban / unban etc)'
  78. //2b0f: Incoming, chrif_char_ask_name_answer -> 'answer of the 2b0e'
  79. //2b10: Outgoing, chrif_updatefamelist -> 'Update the fame ranking lists and send them'
  80. //2b11: Outgoing, chrif_divorce -> 'tell the charserver to do divorce'
  81. //2b12: Incoming, chrif_divorceack -> 'divorce chars
  82. //2b13: FREE
  83. //2b14: Incoming, chrif_accountban -> 'not sure: kick the player with message XY'
  84. //2b15: FREE
  85. //2b16: Outgoing, chrif_ragsrvinfo -> 'sends base / job / drop rates ....'
  86. //2b17: Outgoing, chrif_char_offline -> 'tell the charserver that the char is now offline'
  87. //2b18: Outgoing, chrif_char_reset_offline -> 'set all players OFF!'
  88. //2b19: Outgoing, chrif_char_online -> 'tell the charserver that the char .. is online'
  89. //2b1a: Outgoing, chrif_buildfamelist -> 'Build the fame ranking lists and send them'
  90. //2b1b: Incoming, chrif_recvfamelist -> 'Receive fame ranking lists'
  91. //2b1c: Outgoing, chrif_save_scdata -> 'Send sc_data of player for saving.'
  92. //2b1d: Incoming, chrif_load_scdata -> 'received sc_data of player for loading.'
  93. //2b1e: Incoming, chrif_update_ip -> 'Request forwarded from char-server for interserver IP sync.' [Lance]
  94. //2b1f: Incoming, chrif_disconnectplayer -> 'disconnects a player (aid X) with the message XY ... 0x81 ..' [Sirius]
  95. //2b20: Incoming, chrif_removemap -> 'remove maps of a server (sample: its going offline)' [Sirius]
  96. //2b21: Incoming, chrif_save_ack. Returned after a character has been "final saved" on the char-server. [Skotlex]
  97. //2b22: Incoming, chrif_updatefamelist_ack. Updated one position in the fame list.
  98. //2b23: Outgoing, chrif_keepalive. charserver ping.
  99. //2b24: Incoming, chrif_keepalive_ack. charserver ping reply.
  100. //2b25: Incoming, chrif_deadopt -> 'Removes baby from Father ID and Mother ID'
  101. //2b26: Outgoing, chrif_authreq -> 'client authentication request'
  102. //2b27: Incoming, chrif_authfail -> 'client authentication failed'
  103. //This define should spare writing the check in every function. [Skotlex]
  104. #define chrif_check(a) do { if(!chrif->isconnected()) return a; } while(0)
  105. /// Resets all the data.
  106. void chrif_reset(void) {
  107. // TODO kick everyone out and reset everything [FlavioJS]
  108. exit(EXIT_FAILURE);
  109. }
  110. /// Checks the conditions for the server to stop.
  111. /// Releases the cookie when all characters are saved.
  112. /// If all the conditions are met, it stops the core loop.
  113. void chrif_check_shutdown(void) {
  114. if( core->runflag != MAPSERVER_ST_SHUTDOWN )
  115. return;
  116. if( db_size(chrif->auth_db) > 0 )
  117. return;
  118. core->runflag = CORE_ST_STOP;
  119. }
  120. struct auth_node* chrif_search(int account_id) {
  121. return (struct auth_node*)idb_get(chrif->auth_db, account_id);
  122. }
  123. struct auth_node* chrif_auth_check(int account_id, int char_id, enum sd_state state) {
  124. struct auth_node *node = chrif->search(account_id);
  125. return ( node && node->char_id == char_id && node->state == state ) ? node : NULL;
  126. }
  127. bool chrif_auth_delete(int account_id, int char_id, enum sd_state state) {
  128. struct auth_node *node;
  129. if ( (node = chrif->auth_check(account_id, char_id, state) ) ) {
  130. int fd = node->sd ? node->sd->fd : node->fd;
  131. if ( sockt->session[fd] && sockt->session[fd]->session_data == node->sd )
  132. sockt->session[fd]->session_data = NULL;
  133. if ( node->sd ) {
  134. if( node->sd->regs.vars )
  135. node->sd->regs.vars->destroy(node->sd->regs.vars, script->reg_destroy);
  136. if( node->sd->regs.arrays )
  137. node->sd->regs.arrays->destroy(node->sd->regs.arrays, script->array_free_db);
  138. aFree(node->sd);
  139. }
  140. ers_free(chrif->auth_db_ers, node);
  141. idb_remove(chrif->auth_db,account_id);
  142. return true;
  143. }
  144. return false;
  145. }
  146. //Moves the sd character to the auth_db structure.
  147. bool chrif_sd_to_auth(struct map_session_data *sd, enum sd_state state)
  148. {
  149. struct auth_node *node;
  150. nullpo_retr(false, sd);
  151. if ( chrif->search(sd->status.account_id) )
  152. return false; //Already exists?
  153. node = ers_alloc(chrif->auth_db_ers, struct auth_node);
  154. memset(node, 0, sizeof(struct auth_node));
  155. node->account_id = sd->status.account_id;
  156. node->char_id = sd->status.char_id;
  157. node->login_id1 = sd->login_id1;
  158. node->login_id2 = sd->login_id2;
  159. node->sex = sd->status.sex;
  160. node->fd = sd->fd;
  161. node->sd = sd; //Data from logged on char.
  162. node->node_created = timer->gettick(); //timestamp for node timeouts
  163. node->state = state;
  164. sd->state.active = 0;
  165. idb_put(chrif->auth_db, node->account_id, node);
  166. return true;
  167. }
  168. bool chrif_auth_logout(struct map_session_data *sd, enum sd_state state)
  169. {
  170. nullpo_retr(false, sd);
  171. if(sd->fd && state == ST_LOGOUT) { //Disassociate player, and free it after saving ack returns. [Skotlex]
  172. //fd info must not be lost for ST_MAPCHANGE as a final packet needs to be sent to the player.
  173. if ( sockt->session[sd->fd] )
  174. sockt->session[sd->fd]->session_data = NULL;
  175. sd->fd = 0;
  176. }
  177. return chrif->sd_to_auth(sd, state);
  178. }
  179. bool chrif_auth_finished(struct map_session_data *sd)
  180. {
  181. struct auth_node *node;
  182. nullpo_retr(false, sd);
  183. node = chrif->search(sd->status.account_id);
  184. if ( node && node->sd == sd && node->state == ST_LOGIN ) {
  185. node->sd = NULL;
  186. return chrif->auth_delete(node->account_id, node->char_id, ST_LOGIN);
  187. }
  188. return false;
  189. }
  190. // sets char-server's user id
  191. void chrif_setuserid(char *id) {
  192. nullpo_retv(id);
  193. memcpy(chrif->userid, id, NAME_LENGTH);
  194. }
  195. // sets char-server's password
  196. void chrif_setpasswd(char *pwd) {
  197. nullpo_retv(pwd);
  198. memcpy(chrif->passwd, pwd, NAME_LENGTH);
  199. }
  200. // security check, prints warning if using default password
  201. void chrif_checkdefaultlogin(void) {
  202. if (strcmp(chrif->userid, "s1")==0 && strcmp(chrif->passwd, "p1")==0) {
  203. ShowWarning("Using the default user/password s1/p1 is NOT RECOMMENDED.\n");
  204. ShowNotice("Please edit your 'login' table to create a proper inter-server user/password (gender 'S')\n");
  205. ShowNotice("and then edit your user/password in conf/map-server.conf (or conf/import/map_conf.txt)\n");
  206. }
  207. }
  208. // sets char-server's ip address
  209. bool chrif_setip(const char* ip) {
  210. char ip_str[16];
  211. nullpo_retr(false, ip);
  212. if (!(chrif->ip = sockt->host2ip(ip))) {
  213. ShowWarning("Failed to Resolve Char Server Address! (%s)\n", ip);
  214. return false;
  215. }
  216. safestrncpy(chrif->ip_str, ip, sizeof(chrif->ip_str));
  217. ShowInfo("Char Server IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, sockt->ip2str(chrif->ip, ip_str));
  218. return true;
  219. }
  220. // sets char-server's port number
  221. void chrif_setport(uint16 port) {
  222. chrif->port = port;
  223. }
  224. // says whether the char-server is connected or not
  225. int chrif_isconnected(void) {
  226. return (chrif->fd > 0 && sockt->session[chrif->fd] != NULL && chrif->state == 2);
  227. }
  228. /*==========================================
  229. * Saves character data.
  230. * Flag = 1: Character is quitting
  231. * Flag = 2: Character is changing map-servers
  232. *------------------------------------------*/
  233. // TODO: Flag enum
  234. bool chrif_save(struct map_session_data *sd, int flag) {
  235. nullpo_ret(sd);
  236. pc->makesavestatus(sd);
  237. if (flag && sd->state.active) { //Store player data which is quitting
  238. //FIXME: SC are lost if there's no connection at save-time because of the way its related data is cleared immediately after this function. [Skotlex]
  239. if ( chrif->isconnected() )
  240. chrif->save_scdata(sd);
  241. if ( !chrif->auth_logout(sd,flag == 1 ? ST_LOGOUT : ST_MAPCHANGE) )
  242. ShowError("chrif_save: Failed to set up player %d:%d for proper quitting!\n", sd->status.account_id, sd->status.char_id);
  243. }
  244. chrif_check(false); //Character is saved on reconnect.
  245. //For data sync
  246. if (sd->state.storage_flag == STORAGE_FLAG_GUILD)
  247. gstorage->save(sd->status.account_id, sd->status.guild_id, flag);
  248. if (flag)
  249. sd->state.storage_flag = STORAGE_FLAG_CLOSED; //Force close it.
  250. //Saving of registry values.
  251. if (sd->vars_dirty)
  252. intif->saveregistry(sd);
  253. WFIFOHEAD(chrif->fd, sizeof(sd->status) + 13);
  254. WFIFOW(chrif->fd,0) = 0x2b01;
  255. WFIFOW(chrif->fd,2) = sizeof(sd->status) + 13;
  256. WFIFOL(chrif->fd,4) = sd->status.account_id;
  257. WFIFOL(chrif->fd,8) = sd->status.char_id;
  258. WFIFOB(chrif->fd,12) = (flag==1)?1:0; //Flag to tell char-server this character is quitting.
  259. memcpy(WFIFOP(chrif->fd,13), &sd->status, sizeof(sd->status));
  260. WFIFOSET(chrif->fd, WFIFOW(chrif->fd,2));
  261. if( sd->status.pet_id > 0 && sd->pd )
  262. intif->save_petdata(sd->status.account_id,&sd->pd->pet);
  263. if( sd->hd && homun_alive(sd->hd) )
  264. homun->save(sd->hd);
  265. if( sd->md && mercenary->get_lifetime(sd->md) > 0 )
  266. mercenary->save(sd->md);
  267. if( sd->ed && elemental->get_lifetime(sd->ed) > 0 )
  268. elemental->save(sd->ed);
  269. if( sd->save_quest )
  270. intif->quest_save(sd);
  271. return true;
  272. }
  273. // connects to char-server (plaintext)
  274. void chrif_connect(int fd) {
  275. ShowStatus("Logging in to char server...\n");
  276. WFIFOHEAD(fd,60);
  277. WFIFOW(fd,0) = 0x2af8;
  278. memcpy(WFIFOP(fd,2), chrif->userid, NAME_LENGTH);
  279. memcpy(WFIFOP(fd,26), chrif->passwd, NAME_LENGTH);
  280. WFIFOL(fd,50) = 0;
  281. WFIFOL(fd,54) = htonl(clif->map_ip);
  282. WFIFOW(fd,58) = htons(clif->map_port);
  283. WFIFOSET(fd,60);
  284. }
  285. // sends maps to char-server
  286. void chrif_sendmap(int fd) {
  287. int i;
  288. ShowStatus("Sending maps to char server...\n");
  289. // Sending normal maps, not instances
  290. WFIFOHEAD(fd, 4 + instance->start_id * 4);
  291. WFIFOW(fd,0) = 0x2afa;
  292. for(i = 0; i < instance->start_id; i++)
  293. WFIFOW(fd,4+i*4) = map_id2index(i);
  294. WFIFOW(fd,2) = 4 + i * 4;
  295. WFIFOSET(fd,WFIFOW(fd,2));
  296. }
  297. // receive maps from some other map-server (relayed via char-server)
  298. void chrif_recvmap(int fd) {
  299. int i, j;
  300. uint32 ip = ntohl(RFIFOL(fd,4));
  301. uint16 port = ntohs(RFIFOW(fd,8));
  302. for(i = 10, j = 0; i < RFIFOW(fd,2); i += 4, j++) {
  303. map->setipport(RFIFOW(fd,i), ip, port);
  304. }
  305. if (battle_config.etc_log)
  306. ShowStatus("Received maps from %d.%d.%d.%d:%d (%d maps)\n", CONVIP(ip), port, j);
  307. chrif->other_mapserver_count++;
  308. }
  309. // remove specified maps (used when some other map-server disconnects)
  310. void chrif_removemap(int fd) {
  311. int i, j;
  312. uint32 ip = RFIFOL(fd,4);
  313. uint16 port = RFIFOW(fd,8);
  314. for(i = 10, j = 0; i < RFIFOW(fd, 2); i += 4, j++)
  315. map->eraseipport(RFIFOW(fd, i), ip, port);
  316. chrif->other_mapserver_count--;
  317. if(battle_config.etc_log)
  318. ShowStatus("remove map of server %d.%d.%d.%d:%d (%d maps)\n", CONVIP(ip), port, j);
  319. }
  320. // received after a character has been "final saved" on the char-server
  321. void chrif_save_ack(int fd) {
  322. chrif->auth_delete(RFIFOL(fd,2), RFIFOL(fd,6), ST_LOGOUT);
  323. chrif->check_shutdown();
  324. }
  325. // request to move a character between mapservers
  326. bool chrif_changemapserver(struct map_session_data* sd, uint32 ip, uint16 port) {
  327. nullpo_ret(sd);
  328. if (chrif->other_mapserver_count < 1) {//No other map servers are online!
  329. clif->authfail_fd(sd->fd, 0);
  330. return false;
  331. }
  332. chrif_check(false);
  333. WFIFOHEAD(chrif->fd,35);
  334. WFIFOW(chrif->fd, 0) = 0x2b05;
  335. WFIFOL(chrif->fd, 2) = sd->bl.id;
  336. WFIFOL(chrif->fd, 6) = sd->login_id1;
  337. WFIFOL(chrif->fd,10) = sd->login_id2;
  338. WFIFOL(chrif->fd,14) = sd->status.char_id;
  339. WFIFOW(chrif->fd,18) = sd->mapindex;
  340. WFIFOW(chrif->fd,20) = sd->bl.x;
  341. WFIFOW(chrif->fd,22) = sd->bl.y;
  342. WFIFOL(chrif->fd,24) = htonl(ip);
  343. WFIFOW(chrif->fd,28) = htons(port);
  344. WFIFOB(chrif->fd,30) = sd->status.sex;
  345. WFIFOL(chrif->fd,31) = htonl(sockt->session[sd->fd]->client_addr);
  346. WFIFOL(chrif->fd,35) = sd->group_id;
  347. WFIFOSET(chrif->fd,39);
  348. return true;
  349. }
  350. /// map-server change request acknowledgment (positive or negative)
  351. /// R 2b06 <account_id>.L <login_id1>.L <login_id2>.L <char_id>.L <map_index>.W <x>.W <y>.W <ip>.L <port>.W
  352. bool chrif_changemapserverack(int account_id, int login_id1, int login_id2, int char_id, short map_index, short x, short y, uint32 ip, uint16 port) {
  353. struct auth_node *node;
  354. if ( !( node = chrif->auth_check(account_id, char_id, ST_MAPCHANGE) ) )
  355. return false;
  356. if ( !login_id1 ) {
  357. ShowError("chrif_changemapserverack: map server change failed.\n");
  358. clif->authfail_fd(node->fd, 0); // Disconnected from server
  359. } else
  360. clif->changemapserver(node->sd, map_index, x, y, ntohl(ip), ntohs(port));
  361. //Player has been saved already, remove him from memory. [Skotlex]
  362. chrif->auth_delete(account_id, char_id, ST_MAPCHANGE);
  363. return (!login_id1)?false:true; // Is this the best approach here?
  364. }
  365. /*==========================================
  366. *
  367. *------------------------------------------*/
  368. void chrif_connectack(int fd) {
  369. static bool char_init_done = false;
  370. if (RFIFOB(fd,2)) {
  371. ShowFatalError("Connection to char-server failed %d.\n", RFIFOB(fd,2));
  372. exit(EXIT_FAILURE);
  373. }
  374. ShowStatus("Successfully logged on to Char Server (Connection: '"CL_WHITE"%d"CL_RESET"').\n",fd);
  375. chrif->state = 1;
  376. chrif->connected = 1;
  377. chrif->sendmap(fd);
  378. ShowStatus("Event '"CL_WHITE"OnInterIfInit"CL_RESET"' executed with '"CL_WHITE"%d"CL_RESET"' NPCs.\n", npc->event_doall("OnInterIfInit"));
  379. if( !char_init_done ) {
  380. char_init_done = true;
  381. ShowStatus("Event '"CL_WHITE"OnInterIfInitOnce"CL_RESET"' executed with '"CL_WHITE"%d"CL_RESET"' NPCs.\n", npc->event_doall("OnInterIfInitOnce"));
  382. guild->castle_map_init();
  383. }
  384. sockt->datasync(fd, true);
  385. chrif->skillid2idx(fd);
  386. }
  387. /**
  388. * @see DBApply
  389. */
  390. int chrif_reconnect(DBKey key, DBData *data, va_list ap) {
  391. struct auth_node *node = DB->data2ptr(data);
  392. nullpo_ret(node);
  393. switch (node->state) {
  394. case ST_LOGIN:
  395. if ( node->sd ) {//Since there is no way to request the char auth, make it fail.
  396. pc->authfail(node->sd);
  397. chrif_char_offline(node->sd);
  398. chrif->auth_delete(node->account_id, node->char_id, ST_LOGIN);
  399. }
  400. break;
  401. case ST_LOGOUT:
  402. //Re-send final save
  403. chrif->save(node->sd, 1);
  404. break;
  405. case ST_MAPCHANGE: { //Re-send map-change request.
  406. struct map_session_data *sd = node->sd;
  407. uint32 ip;
  408. uint16 port;
  409. if( map->mapname2ipport(sd->mapindex,&ip,&port) == 0 )
  410. chrif->changemapserver(sd, ip, port);
  411. else //too much lag/timeout is the closest explanation for this error.
  412. clif->authfail_fd(sd->fd, 3); // timeout
  413. break;
  414. }
  415. }
  416. return 0;
  417. }
  418. /// Called when all the connection steps are completed.
  419. void chrif_on_ready(void) {
  420. static bool once = false;
  421. ShowStatus("Map Server is now online.\n");
  422. chrif->state = 2;
  423. chrif->check_shutdown();
  424. //If there are players online, send them to the char-server. [Skotlex]
  425. chrif->send_users_tochar();
  426. //Auth db reconnect handling
  427. chrif->auth_db->foreach(chrif->auth_db,chrif->reconnect);
  428. //Re-save any storages that were modified in the disconnection time. [Skotlex]
  429. storage->reconnect();
  430. //Re-save any guild castles that were modified in the disconnection time.
  431. guild->castle_reconnect(-1, 0, 0);
  432. if( !once ) {
  433. #ifdef AUTOTRADE_PERSISTENCY
  434. pc->autotrade_load();
  435. #endif
  436. once = true;
  437. }
  438. }
  439. /*==========================================
  440. *
  441. *------------------------------------------*/
  442. void chrif_sendmapack(int fd)
  443. {
  444. if (RFIFOB(fd,2)) {
  445. ShowFatalError("chrif : send map list to char server failed %d\n", RFIFOB(fd,2));
  446. exit(EXIT_FAILURE);
  447. }
  448. memcpy(map->wisp_server_name, RFIFOP(fd,3), NAME_LENGTH);
  449. chrif->on_ready();
  450. }
  451. /*==========================================
  452. * Request sc_data from charserver [Skotlex]
  453. *------------------------------------------*/
  454. bool chrif_scdata_request(int account_id, int char_id)
  455. {
  456. #ifdef ENABLE_SC_SAVING
  457. chrif_check(false);
  458. WFIFOHEAD(chrif->fd,10);
  459. WFIFOW(chrif->fd,0) = 0x2afc;
  460. WFIFOL(chrif->fd,2) = account_id;
  461. WFIFOL(chrif->fd,6) = char_id;
  462. WFIFOSET(chrif->fd,10);
  463. #endif
  464. return true;
  465. }
  466. /*==========================================
  467. * Request auth confirmation
  468. *------------------------------------------*/
  469. void chrif_authreq(struct map_session_data *sd, bool hstandalone) {
  470. struct auth_node *node= chrif->search(sd->bl.id);
  471. nullpo_retv(sd);
  472. if( node != NULL || !chrif->isconnected() ) {
  473. sockt->eof(sd->fd);
  474. return;
  475. }
  476. WFIFOHEAD(chrif->fd,20);
  477. WFIFOW(chrif->fd,0) = 0x2b26;
  478. WFIFOL(chrif->fd,2) = sd->status.account_id;
  479. WFIFOL(chrif->fd,6) = sd->status.char_id;
  480. WFIFOL(chrif->fd,10) = sd->login_id1;
  481. WFIFOB(chrif->fd,14) = sd->status.sex;
  482. WFIFOL(chrif->fd,15) = htonl(sockt->session[sd->fd]->client_addr);
  483. WFIFOB(chrif->fd,19) = hstandalone ? 1 : 0;
  484. WFIFOSET(chrif->fd,20);
  485. chrif->sd_to_auth(sd, ST_LOGIN);
  486. }
  487. /*==========================================
  488. * Auth confirmation ack
  489. *------------------------------------------*/
  490. void chrif_authok(int fd) {
  491. int account_id, group_id, char_id;
  492. uint32 login_id1,login_id2;
  493. time_t expiration_time;
  494. struct mmo_charstatus* charstatus;
  495. struct auth_node *node;
  496. bool changing_mapservers;
  497. struct map_session_data *sd = NULL;
  498. //Check if both servers agree on the struct's size
  499. if( RFIFOW(fd,2) - 25 != sizeof(struct mmo_charstatus) ) {
  500. ShowError("chrif_authok: Data size mismatch! %d != %"PRIuS"\n", RFIFOW(fd,2) - 25, sizeof(struct mmo_charstatus));
  501. return;
  502. }
  503. account_id = RFIFOL(fd,4);
  504. login_id1 = RFIFOL(fd,8);
  505. login_id2 = RFIFOL(fd,12);
  506. expiration_time = (time_t)(int32)RFIFOL(fd,16);
  507. group_id = RFIFOL(fd,20);
  508. changing_mapservers = (RFIFOB(fd,24));
  509. charstatus = (struct mmo_charstatus*)RFIFOP(fd,25);
  510. char_id = charstatus->char_id;
  511. //Check if we don't already have player data in our server
  512. //Causes problems if the currently connected player tries to quit or this data belongs to an already connected player which is trying to re-auth.
  513. if ( ( sd = map->id2sd(account_id) ) != NULL )
  514. return;
  515. if ( ( node = chrif->search(account_id) ) == NULL )
  516. return; // should not happen
  517. if ( node->state != ST_LOGIN )
  518. return; //character in logout phase, do not touch that data.
  519. if ( node->sd == NULL ) {
  520. /*
  521. //When we receive double login info and the client has not connected yet,
  522. //discard the older one and keep the new one.
  523. chrif->auth_delete(node->account_id, node->char_id, ST_LOGIN);
  524. */
  525. return; // should not happen
  526. }
  527. sd = node->sd;
  528. if( core->runflag == MAPSERVER_ST_RUNNING &&
  529. node->account_id == account_id &&
  530. node->char_id == char_id &&
  531. node->login_id1 == login_id1 )
  532. { //Auth Ok
  533. if (pc->authok(sd, login_id2, expiration_time, group_id, charstatus, changing_mapservers))
  534. return;
  535. } else { //Auth Failed
  536. pc->authfail(sd);
  537. }
  538. chrif_char_offline(sd); //Set him offline, the char server likely has it set as online already.
  539. chrif->auth_delete(account_id, char_id, ST_LOGIN);
  540. }
  541. // client authentication failed
  542. void chrif_authfail(int fd) {/* HELLO WORLD. ip in RFIFOL 15 is not being used (but is available) */
  543. int account_id, char_id;
  544. uint32 login_id1;
  545. char sex;
  546. struct auth_node* node;
  547. account_id = RFIFOL(fd,2);
  548. char_id = RFIFOL(fd,6);
  549. login_id1 = RFIFOL(fd,10);
  550. sex = RFIFOB(fd,14);
  551. node = chrif->search(account_id);
  552. if( node != NULL &&
  553. node->account_id == account_id &&
  554. node->char_id == char_id &&
  555. node->login_id1 == login_id1 &&
  556. node->sex == sex &&
  557. node->state == ST_LOGIN )
  558. {// found a match
  559. clif->authfail_fd(node->fd, 0); // Disconnected from server
  560. chrif->auth_delete(account_id, char_id, ST_LOGIN);
  561. }
  562. }
  563. /**
  564. * This can still happen (client times out while waiting for char to confirm auth data)
  565. * @see DBApply
  566. */
  567. int auth_db_cleanup_sub(DBKey key, DBData *data, va_list ap) {
  568. struct auth_node *node = DB->data2ptr(data);
  569. nullpo_retr(1, node);
  570. if(DIFF_TICK(timer->gettick(),node->node_created)>60000) {
  571. const char* states[] = { "Login", "Logout", "Map change" };
  572. switch (node->state) {
  573. case ST_LOGOUT:
  574. //Re-save attempt (->sd should never be null here).
  575. node->node_created = timer->gettick(); //Refresh tick (avoid char-server load if connection is really bad)
  576. chrif->save(node->sd, 1);
  577. break;
  578. default:
  579. //Clear data. any connected players should have timed out by now.
  580. ShowInfo("auth_db: Node (state %s) timed out for %d:%d\n", states[node->state], node->account_id, node->char_id);
  581. chrif->char_offline_nsd(node->account_id, node->char_id);
  582. chrif->auth_delete(node->account_id, node->char_id, node->state);
  583. break;
  584. }
  585. return 1;
  586. }
  587. return 0;
  588. }
  589. int auth_db_cleanup(int tid, int64 tick, int id, intptr_t data) {
  590. chrif_check(0);
  591. chrif->auth_db->foreach(chrif->auth_db, chrif->auth_db_cleanup_sub);
  592. return 0;
  593. }
  594. /*==========================================
  595. * Request char selection
  596. *------------------------------------------*/
  597. bool chrif_charselectreq(struct map_session_data* sd, uint32 s_ip) {
  598. nullpo_ret(sd);
  599. if( !sd->bl.id || !sd->login_id1 )
  600. return false;
  601. chrif_check(false);
  602. WFIFOHEAD(chrif->fd,22);
  603. WFIFOW(chrif->fd, 0) = 0x2b02;
  604. WFIFOL(chrif->fd, 2) = sd->bl.id;
  605. WFIFOL(chrif->fd, 6) = sd->login_id1;
  606. WFIFOL(chrif->fd,10) = sd->login_id2;
  607. WFIFOL(chrif->fd,14) = htonl(s_ip);
  608. WFIFOL(chrif->fd,18) = sd->group_id;
  609. WFIFOSET(chrif->fd,22);
  610. return true;
  611. }
  612. /*==========================================
  613. * Search Char trough id on char serv
  614. *------------------------------------------*/
  615. bool chrif_searchcharid(int char_id) {
  616. if( !char_id )
  617. return false;
  618. chrif_check(false);
  619. WFIFOHEAD(chrif->fd,6);
  620. WFIFOW(chrif->fd,0) = 0x2b08;
  621. WFIFOL(chrif->fd,2) = char_id;
  622. WFIFOSET(chrif->fd,6);
  623. return true;
  624. }
  625. /*==========================================
  626. * Change Email
  627. *------------------------------------------*/
  628. bool chrif_changeemail(int id, const char *actual_email, const char *new_email) {
  629. if (battle_config.etc_log)
  630. ShowInfo("chrif_changeemail: account: %d, actual_email: '%s', new_email: '%s'.\n", id, actual_email, new_email);
  631. nullpo_retr(false, actual_email);
  632. nullpo_retr(false, new_email);
  633. chrif_check(false);
  634. WFIFOHEAD(chrif->fd,86);
  635. WFIFOW(chrif->fd,0) = 0x2b0c;
  636. WFIFOL(chrif->fd,2) = id;
  637. memcpy(WFIFOP(chrif->fd,6), actual_email, 40);
  638. memcpy(WFIFOP(chrif->fd,46), new_email, 40);
  639. WFIFOSET(chrif->fd,86);
  640. return true;
  641. }
  642. /*==========================================
  643. * S 2b0e <accid>.l <name>.24B <type>.w { <additional fields>.12B }
  644. * { <year>.w <month>.w <day>.w <hour>.w <minute>.w <second>.w }
  645. * Send an account modification request to the login server (via char server).
  646. * type of operation: @see enum zh_char_ask_name
  647. * block { n/a }
  648. * ban { <year>.w <month>.w <day>.w <hour>.w <minute>.w <second>.w }
  649. * unblock { n/a }
  650. * unban { n/a }
  651. * changesex { n/a } -- use chrif_changesex
  652. * charban { <year>.w <month>.w <day>.w <hour>.w <minute>.w <second>.w }
  653. * charunban { n/a }
  654. * changecharsex { <sex>.b } -- use chrif_changesex
  655. *------------------------------------------*/
  656. bool chrif_char_ask_name(int acc, const char* character_name, unsigned short operation_type, int year, int month, int day, int hour, int minute, int second)
  657. {
  658. nullpo_retr(false, character_name);
  659. chrif_check(false);
  660. WFIFOHEAD(chrif->fd,44);
  661. WFIFOW(chrif->fd,0) = 0x2b0e;
  662. WFIFOL(chrif->fd,2) = acc;
  663. safestrncpy((char*)WFIFOP(chrif->fd,6), character_name, NAME_LENGTH);
  664. WFIFOW(chrif->fd,30) = operation_type;
  665. if (operation_type == CHAR_ASK_NAME_BAN || operation_type == CHAR_ASK_NAME_CHARBAN) {
  666. WFIFOW(chrif->fd,32) = year;
  667. WFIFOW(chrif->fd,34) = month;
  668. WFIFOW(chrif->fd,36) = day;
  669. WFIFOW(chrif->fd,38) = hour;
  670. WFIFOW(chrif->fd,40) = minute;
  671. WFIFOW(chrif->fd,42) = second;
  672. }
  673. WFIFOSET(chrif->fd,44);
  674. return true;
  675. }
  676. /**
  677. * Requests a sex change (either per character or per account).
  678. *
  679. * @param sd The character's data.
  680. * @param change_account Whether to change the per-account sex.
  681. * @retval true.
  682. */
  683. bool chrif_changesex(struct map_session_data *sd, bool change_account)
  684. {
  685. nullpo_retr(false, sd);
  686. chrif_check(false);
  687. WFIFOHEAD(chrif->fd,44);
  688. WFIFOW(chrif->fd,0) = 0x2b0e;
  689. WFIFOL(chrif->fd,2) = sd->status.account_id;
  690. safestrncpy((char*)WFIFOP(chrif->fd,6), sd->status.name, NAME_LENGTH);
  691. WFIFOW(chrif->fd,30) = change_account ? CHAR_ASK_NAME_CHANGESEX : CHAR_ASK_NAME_CHANGECHARSEX;
  692. if (!change_account)
  693. WFIFOB(chrif->fd,32) = sd->status.sex == SEX_MALE ? SEX_FEMALE : SEX_MALE;
  694. WFIFOSET(chrif->fd,44);
  695. clif->message(sd->fd, msg_sd(sd,408)); //"Disconnecting to perform change-sex request..."
  696. if (sd->fd)
  697. clif->authfail_fd(sd->fd, 15);
  698. else
  699. map->quit(sd);
  700. return true;
  701. }
  702. /*==========================================
  703. * R 2b0f <accid>.l <name>.24B <type>.w <answer>.w
  704. * Processing a reply to chrif->char_ask_name() (request to modify an account).
  705. * type of operation: @see chrif_char_ask_name
  706. * type of answer: @see hz_char_ask_name_answer
  707. *------------------------------------------*/
  708. bool chrif_char_ask_name_answer(int acc, const char* player_name, uint16 type, uint16 answer) {
  709. struct map_session_data* sd;
  710. char action[25];
  711. char output[256];
  712. bool charsrv = ( type == CHAR_ASK_NAME_CHARBAN || type == CHAR_ASK_NAME_CHARUNBAN ) ? true : false;
  713. nullpo_retr(false, player_name);
  714. sd = map->id2sd(acc);
  715. if( acc < 0 || sd == NULL ) {
  716. ShowError("chrif_char_ask_name_answer failed - player not online.\n");
  717. return false;
  718. }
  719. /* re-use previous msg_number */
  720. if( type == CHAR_ASK_NAME_CHARBAN ) type = CHAR_ASK_NAME_BAN;
  721. if( type == CHAR_ASK_NAME_CHARUNBAN ) type = CHAR_ASK_NAME_UNBAN;
  722. if( type >= CHAR_ASK_NAME_BLOCK && type <= CHAR_ASK_NAME_CHANGESEX )
  723. snprintf(action,25,"%s",msg_sd(sd,427+type)); //block|ban|unblock|unban|change the sex of
  724. else
  725. snprintf(action,25,"???");
  726. switch( answer ) {
  727. case CHAR_ASK_NAME_ANS_DONE: sprintf(output, msg_sd(sd,charsrv?434:424), action, NAME_LENGTH, player_name); break;
  728. case CHAR_ASK_NAME_ANS_NOTFOUND: sprintf(output, msg_sd(sd,425), NAME_LENGTH, player_name); break;
  729. case CHAR_ASK_NAME_ANS_GMLOW: sprintf(output, msg_sd(sd,426), action, NAME_LENGTH, player_name); break;
  730. case CHAR_ASK_NAME_ANS_OFFLINE: sprintf(output, msg_sd(sd,427), action, NAME_LENGTH, player_name); break;
  731. default: output[0] = '\0'; break;
  732. }
  733. clif->message(sd->fd, output);
  734. return true;
  735. }
  736. /*==========================================
  737. * Request char server to change sex of char (modified by Yor)
  738. *------------------------------------------*/
  739. void chrif_changedsex(int fd) {
  740. int acc = RFIFOL(fd,2);
  741. //int sex = RFIFOL(fd,6); // Dead store. Uncomment if needed again.
  742. if ( battle_config.etc_log )
  743. ShowNotice("chrif_changedsex %d.\n", acc);
  744. // Path to activate this response:
  745. // Map(start) (0x2b0e type 5) -> Char(0x2727) -> Login
  746. // Login(0x2723) [ALL] -> Char (0x2b0d)[ALL] -> Map (HERE)
  747. // OR
  748. // Map(start) (0x2b03 type 8) -> Char
  749. // Char(0x2b0d)[ALL] -> Map (HERE)
  750. // Char will usually be "logged in" despite being forced to log-out in the beginning
  751. // of this process, but there's no need to perform map-server specific response
  752. // as everything should been changed through char-server [Panikon]
  753. }
  754. /*==========================================
  755. * Request Char Server to Divorce Players
  756. *------------------------------------------*/
  757. bool chrif_divorce(int partner_id1, int partner_id2) {
  758. chrif_check(false);
  759. WFIFOHEAD(chrif->fd,10);
  760. WFIFOW(chrif->fd,0) = 0x2b11;
  761. WFIFOL(chrif->fd,2) = partner_id1;
  762. WFIFOL(chrif->fd,6) = partner_id2;
  763. WFIFOSET(chrif->fd,10);
  764. return true;
  765. }
  766. /*==========================================
  767. * Divorce players
  768. * only used if 'partner_id' is offline
  769. *------------------------------------------*/
  770. bool chrif_divorceack(int char_id, int partner_id) {
  771. struct map_session_data* sd;
  772. int i;
  773. if( !char_id || !partner_id )
  774. return false;
  775. if( ( sd = map->charid2sd(char_id) ) != NULL && sd->status.partner_id == partner_id ) {
  776. sd->status.partner_id = 0;
  777. for(i = 0; i < MAX_INVENTORY; i++)
  778. if (sd->status.inventory[i].nameid == WEDDING_RING_M || sd->status.inventory[i].nameid == WEDDING_RING_F)
  779. pc->delitem(sd, i, 1, 0, DELITEM_NORMAL, LOG_TYPE_OTHER);
  780. }
  781. if( ( sd = map->charid2sd(partner_id) ) != NULL && sd->status.partner_id == char_id ) {
  782. sd->status.partner_id = 0;
  783. for(i = 0; i < MAX_INVENTORY; i++)
  784. if (sd->status.inventory[i].nameid == WEDDING_RING_M || sd->status.inventory[i].nameid == WEDDING_RING_F)
  785. pc->delitem(sd, i, 1, 0, DELITEM_NORMAL, LOG_TYPE_OTHER);
  786. }
  787. return true;
  788. }
  789. /*==========================================
  790. * Removes Baby from parents
  791. *------------------------------------------*/
  792. void chrif_deadopt(int father_id, int mother_id, int child_id) {
  793. struct map_session_data* sd;
  794. int idx = skill->get_index(WE_CALLBABY);
  795. if( father_id && ( sd = map->charid2sd(father_id) ) != NULL && sd->status.child == child_id ) {
  796. sd->status.child = 0;
  797. sd->status.skill[idx].id = 0;
  798. sd->status.skill[idx].lv = 0;
  799. sd->status.skill[idx].flag = 0;
  800. clif->deleteskill(sd,WE_CALLBABY);
  801. }
  802. if( mother_id && ( sd = map->charid2sd(mother_id) ) != NULL && sd->status.child == child_id ) {
  803. sd->status.child = 0;
  804. sd->status.skill[idx].id = 0;
  805. sd->status.skill[idx].lv = 0;
  806. sd->status.skill[idx].flag = 0;
  807. clif->deleteskill(sd,WE_CALLBABY);
  808. }
  809. }
  810. /*==========================================
  811. * Disconnection of a player (account or char has been banned of has a status, from login or char server) by [Yor]
  812. *------------------------------------------*/
  813. void chrif_idbanned(int fd) {
  814. int id;
  815. struct map_session_data *sd;
  816. id = RFIFOL(fd,2);
  817. if ( battle_config.etc_log )
  818. ShowNotice("chrif_idbanned %d.\n", id);
  819. sd = ( RFIFOB(fd,6) == 2 ) ? map->charid2sd(id) : map->id2sd(id);
  820. if ( id < 0 || sd == NULL ) {
  821. /* player not online or unknown id, either way no error is necessary (since if you try to ban a offline char it still works) */
  822. return;
  823. }
  824. sd->login_id1++; // change identify, because if player come back in char within the 5 seconds, he can change its characters
  825. if (RFIFOB(fd,6) == 0) { // 0: change of status
  826. int ret_status = RFIFOL(fd,7); // status or final date of a banishment
  827. if(0<ret_status && ret_status<=9)
  828. clif->message(sd->fd, msg_sd(sd,411+ret_status)); // Message IDs (for search convenience): 412, 413, 414, 415, 416, 417, 418, 419, 420
  829. else if(ret_status==100)
  830. clif->message(sd->fd, msg_sd(sd,421));
  831. else
  832. clif->message(sd->fd, msg_sd(sd,420)); //"Your account has not more authorized."
  833. } else if (RFIFOB(fd,6) == 1) { // 1: ban
  834. time_t timestamp;
  835. char tmpstr[2048];
  836. timestamp = (time_t)RFIFOL(fd,7); // status or final date of a banishment
  837. safestrncpy(tmpstr, msg_sd(sd,423), sizeof(tmpstr)); //"Your account has been banished until "
  838. strftime(tmpstr + strlen(tmpstr), 24, "%d-%m-%Y %H:%M:%S", localtime(&timestamp));
  839. clif->message(sd->fd, tmpstr);
  840. } else if (RFIFOB(fd,6) == 2) { // 2: change of status for character
  841. time_t timestamp;
  842. char tmpstr[2048];
  843. timestamp = (time_t)RFIFOL(fd,7); // status or final date of a banishment
  844. safestrncpy(tmpstr, msg_sd(sd,433), sizeof(tmpstr)); //"This character has been banned until "
  845. strftime(tmpstr + strlen(tmpstr), 24, "%d-%m-%Y %H:%M:%S", localtime(&timestamp));
  846. clif->message(sd->fd, tmpstr);
  847. }
  848. sockt->eof(sd->fd); // forced to disconnect for the change
  849. map->quit(sd); // Remove leftovers (e.g. autotrading) [Paradox924X]
  850. }
  851. //Disconnect the player out of the game, simple packet
  852. //packet.w AID.L WHY.B 2+4+1 = 7byte
  853. int chrif_disconnectplayer(int fd) {
  854. struct map_session_data* sd;
  855. int account_id = RFIFOL(fd, 2);
  856. sd = map->id2sd(account_id);
  857. if( sd == NULL ) {
  858. struct auth_node* auth = chrif->search(account_id);
  859. if( auth != NULL && chrif->auth_delete(account_id, auth->char_id, ST_LOGIN) )
  860. return 0;
  861. return -1;
  862. }
  863. if (!sd->fd) { //No connection
  864. if (sd->state.autotrade)
  865. map->quit(sd); //Remove it.
  866. //Else we don't remove it because the char should have a timer to remove the player because it force-quit before,
  867. //and we don't want them kicking their previous instance before the 10 secs penalty time passes. [Skotlex]
  868. return 0;
  869. }
  870. switch(RFIFOB(fd, 6)) {
  871. case 1: clif->authfail_fd(sd->fd, 1); break; //server closed
  872. case 2: clif->authfail_fd(sd->fd, 2); break; //someone else logged in
  873. case 3: clif->authfail_fd(sd->fd, 4); break; //server overpopulated
  874. case 4: clif->authfail_fd(sd->fd, 10); break; //out of available time paid for
  875. case 5: clif->authfail_fd(sd->fd, 15); break; //forced to dc by gm
  876. }
  877. return 0;
  878. }
  879. /*==========================================
  880. * Request/Receive top 10 Fame character list
  881. *------------------------------------------*/
  882. int chrif_updatefamelist(struct map_session_data* sd) {
  883. char type;
  884. nullpo_retr(0, sd);
  885. chrif_check(-1);
  886. switch(sd->class_ & MAPID_UPPERMASK) {
  887. case MAPID_BLACKSMITH: type = RANKTYPE_BLACKSMITH; break;
  888. case MAPID_ALCHEMIST: type = RANKTYPE_ALCHEMIST; break;
  889. case MAPID_TAEKWON: type = RANKTYPE_TAEKWON; break;
  890. default:
  891. return 0;
  892. }
  893. WFIFOHEAD(chrif->fd, 11);
  894. WFIFOW(chrif->fd,0) = 0x2b10;
  895. WFIFOL(chrif->fd,2) = sd->status.char_id;
  896. WFIFOL(chrif->fd,6) = sd->status.fame;
  897. WFIFOB(chrif->fd,10) = type;
  898. WFIFOSET(chrif->fd,11);
  899. return 0;
  900. }
  901. bool chrif_buildfamelist(void) {
  902. chrif_check(false);
  903. WFIFOHEAD(chrif->fd,2);
  904. WFIFOW(chrif->fd,0) = 0x2b1a;
  905. WFIFOSET(chrif->fd,2);
  906. return true;
  907. }
  908. void chrif_recvfamelist(int fd) {
  909. int num, size;
  910. int total = 0, len = 8;
  911. memset(pc->smith_fame_list, 0, sizeof(pc->smith_fame_list));
  912. memset(pc->chemist_fame_list, 0, sizeof(pc->chemist_fame_list));
  913. memset(pc->taekwon_fame_list, 0, sizeof(pc->taekwon_fame_list));
  914. size = RFIFOW(fd, 6); //Blacksmith block size
  915. for (num = 0; len < size && num < MAX_FAME_LIST; num++) {
  916. memcpy(&pc->smith_fame_list[num], RFIFOP(fd,len), sizeof(struct fame_list));
  917. len += sizeof(struct fame_list);
  918. }
  919. total += num;
  920. size = RFIFOW(fd, 4); //Alchemist block size
  921. for (num = 0; len < size && num < MAX_FAME_LIST; num++) {
  922. memcpy(&pc->chemist_fame_list[num], RFIFOP(fd,len), sizeof(struct fame_list));
  923. len += sizeof(struct fame_list);
  924. }
  925. total += num;
  926. size = RFIFOW(fd, 2); //Total packet length
  927. for (num = 0; len < size && num < MAX_FAME_LIST; num++) {
  928. memcpy(&pc->taekwon_fame_list[num], RFIFOP(fd,len), sizeof(struct fame_list));
  929. len += sizeof(struct fame_list);
  930. }
  931. total += num;
  932. ShowInfo("Received Fame List of '"CL_WHITE"%d"CL_RESET"' characters.\n", total);
  933. }
  934. /// fame ranking update confirmation
  935. /// R 2b22 <table>.B <index>.B <value>.L
  936. int chrif_updatefamelist_ack(int fd) {
  937. struct fame_list* list;
  938. uint8 index;
  939. switch (RFIFOB(fd,2)) {
  940. case RANKTYPE_BLACKSMITH: list = pc->smith_fame_list; break;
  941. case RANKTYPE_ALCHEMIST: list = pc->chemist_fame_list; break;
  942. case RANKTYPE_TAEKWON: list = pc->taekwon_fame_list; break;
  943. default: return 0;
  944. }
  945. index = RFIFOB(fd, 3);
  946. if (index >= MAX_FAME_LIST)
  947. return 0;
  948. list[index].fame = RFIFOL(fd,4);
  949. return 1;
  950. }
  951. bool chrif_save_scdata(struct map_session_data *sd) { //parses the sc_data of the player and sends it to the char-server for saving. [Skotlex]
  952. #ifdef ENABLE_SC_SAVING
  953. int i, count=0;
  954. int64 tick;
  955. struct status_change_data data;
  956. struct status_change *sc;
  957. const struct TimerData *td;
  958. nullpo_retr(false, sd);
  959. sc = &sd->sc;
  960. chrif_check(false);
  961. tick = timer->gettick();
  962. WFIFOHEAD(chrif->fd, 14 + SC_MAX*sizeof(struct status_change_data));
  963. WFIFOW(chrif->fd,0) = 0x2b1c;
  964. WFIFOL(chrif->fd,4) = sd->status.account_id;
  965. WFIFOL(chrif->fd,8) = sd->status.char_id;
  966. for (i = 0; i < SC_MAX; i++) {
  967. if (!sc->data[i])
  968. continue;
  969. if (sc->data[i]->timer != INVALID_TIMER) {
  970. td = timer->get(sc->data[i]->timer);
  971. if (td == NULL || td->func != status->change_timer)
  972. continue;
  973. if (DIFF_TICK32(td->tick,tick) > 0)
  974. data.tick = DIFF_TICK32(td->tick,tick); //Duration that is left before ending.
  975. else
  976. data.tick = 0; //Negative tick does not necessarily mean that sc has expired
  977. } else
  978. data.tick = -1; //Infinite duration
  979. data.type = i;
  980. data.val1 = sc->data[i]->val1;
  981. data.val2 = sc->data[i]->val2;
  982. data.val3 = sc->data[i]->val3;
  983. data.val4 = sc->data[i]->val4;
  984. memcpy(WFIFOP(chrif->fd,14 +count*sizeof(struct status_change_data)),
  985. &data, sizeof(struct status_change_data));
  986. count++;
  987. }
  988. if (count == 0)
  989. return true; //Nothing to save. | Everything was as successful as if there was something to save.
  990. WFIFOW(chrif->fd,12) = count;
  991. WFIFOW(chrif->fd,2) = 14 +count*sizeof(struct status_change_data); //Total packet size
  992. WFIFOSET(chrif->fd,WFIFOW(chrif->fd,2));
  993. #endif
  994. return true;
  995. }
  996. //Retrieve and load sc_data for a player. [Skotlex]
  997. bool chrif_load_scdata(int fd) {
  998. #ifdef ENABLE_SC_SAVING
  999. struct map_session_data *sd;
  1000. int aid, cid, i, count;
  1001. aid = RFIFOL(fd,4); //Player Account ID
  1002. cid = RFIFOL(fd,8); //Player Char ID
  1003. sd = map->id2sd(aid);
  1004. if ( !sd ) {
  1005. ShowError("chrif_load_scdata: Player of AID %d not found!\n", aid);
  1006. return false;
  1007. }
  1008. if ( sd->status.char_id != cid ) {
  1009. ShowError("chrif_load_scdata: Receiving data for account %d, char id does not matches (%d != %d)!\n", aid, sd->status.char_id, cid);
  1010. return false;
  1011. }
  1012. count = RFIFOW(fd,12); //sc_count
  1013. for (i = 0; i < count; i++) {
  1014. struct status_change_data *data = (struct status_change_data*)RFIFOP(fd,14 + i*sizeof(struct status_change_data));
  1015. status->change_start(NULL, &sd->bl, (sc_type)data->type, 10000, data->val1, data->val2, data->val3, data->val4,
  1016. data->tick, SCFLAG_NOAVOID|SCFLAG_FIXEDTICK|SCFLAG_LOADED|SCFLAG_FIXEDRATE);
  1017. }
  1018. pc->scdata_received(sd);
  1019. #endif
  1020. return true;
  1021. }
  1022. /*==========================================
  1023. * Send rates to char server [Wizputer]
  1024. * S 2b16 <base rate>.L <job rate>.L <drop rate>.L
  1025. *------------------------------------------*/
  1026. bool chrif_ragsrvinfo(int base_rate, int job_rate, int drop_rate) {
  1027. chrif_check(false);
  1028. WFIFOHEAD(chrif->fd,14);
  1029. WFIFOW(chrif->fd,0) = 0x2b16;
  1030. WFIFOL(chrif->fd,2) = base_rate;
  1031. WFIFOL(chrif->fd,6) = job_rate;
  1032. WFIFOL(chrif->fd,10) = drop_rate;
  1033. WFIFOSET(chrif->fd,14);
  1034. return true;
  1035. }
  1036. /*=========================================
  1037. * Tell char-server character disconnected [Wizputer]
  1038. *-----------------------------------------*/
  1039. bool chrif_char_offline_nsd(int account_id, int char_id) {
  1040. chrif_check(false);
  1041. WFIFOHEAD(chrif->fd,10);
  1042. WFIFOW(chrif->fd,0) = 0x2b17;
  1043. WFIFOL(chrif->fd,2) = char_id;
  1044. WFIFOL(chrif->fd,6) = account_id;
  1045. WFIFOSET(chrif->fd,10);
  1046. return true;
  1047. }
  1048. /*=========================================
  1049. * Tell char-server to reset all chars offline [Wizputer]
  1050. *-----------------------------------------*/
  1051. bool chrif_flush(void) {
  1052. chrif_check(false);
  1053. sockt->set_nonblocking(chrif->fd, 0);
  1054. sockt->flush_fifos();
  1055. sockt->set_nonblocking(chrif->fd, 1);
  1056. return true;
  1057. }
  1058. /*=========================================
  1059. * Tell char-server to reset all chars offline [Wizputer]
  1060. *-----------------------------------------*/
  1061. bool chrif_char_reset_offline(void) {
  1062. chrif_check(false);
  1063. WFIFOHEAD(chrif->fd,2);
  1064. WFIFOW(chrif->fd,0) = 0x2b18;
  1065. WFIFOSET(chrif->fd,2);
  1066. return true;
  1067. }
  1068. /*=========================================
  1069. * Tell char-server character is online [Wizputer]. Look like unused.
  1070. *-----------------------------------------*/
  1071. bool chrif_char_online(struct map_session_data *sd) {
  1072. chrif_check(false);
  1073. nullpo_retr(false, sd);
  1074. WFIFOHEAD(chrif->fd,10);
  1075. WFIFOW(chrif->fd,0) = 0x2b19;
  1076. WFIFOL(chrif->fd,2) = sd->status.char_id;
  1077. WFIFOL(chrif->fd,6) = sd->status.account_id;
  1078. WFIFOSET(chrif->fd,10);
  1079. return true;
  1080. }
  1081. /// Called when the connection to Char Server is disconnected.
  1082. void chrif_on_disconnect(void) {
  1083. if( chrif->connected != 1 )
  1084. ShowWarning("Connection to Char Server lost.\n\n");
  1085. chrif->connected = 0;
  1086. chrif->other_mapserver_count = 0; //Reset counter. We receive ALL maps from all map-servers on reconnect.
  1087. map->eraseallipport();
  1088. //Attempt to reconnect in a second. [Skotlex]
  1089. timer->add(timer->gettick() + 1000, chrif->check_connect_char_server, 0, 0);
  1090. }
  1091. void chrif_update_ip(int fd) {
  1092. uint32 new_ip;
  1093. WFIFOHEAD(fd,6);
  1094. new_ip = sockt->host2ip(chrif->ip_str);
  1095. if (new_ip && new_ip != chrif->ip)
  1096. chrif->ip = new_ip; //Update chrif->ip
  1097. new_ip = clif->refresh_ip();
  1098. if (!new_ip)
  1099. return; //No change
  1100. WFIFOW(fd,0) = 0x2736;
  1101. WFIFOL(fd,2) = htonl(new_ip);
  1102. WFIFOSET(fd,6);
  1103. }
  1104. // pings the charserver ( since on-demand flag.ping was introduced, shouldn't this be dropped? only wasting traffic and processing [Ind])
  1105. void chrif_keepalive(int fd) {
  1106. WFIFOHEAD(fd,2);
  1107. WFIFOW(fd,0) = 0x2b23;
  1108. WFIFOSET(fd,2);
  1109. }
  1110. void chrif_keepalive_ack(int fd) {
  1111. sockt->session[fd]->flag.ping = 0;/* reset ping state, we received a packet */
  1112. }
  1113. void chrif_skillid2idx(int fd) {
  1114. int i, count = 0;
  1115. if( fd == 0 ) fd = chrif->fd;
  1116. if (!sockt->session_is_valid(fd))
  1117. return;
  1118. WFIFOHEAD(fd,4 + (MAX_SKILL * 4));
  1119. WFIFOW(fd,0) = 0x2b0b;
  1120. for(i = 0; i < MAX_SKILL; i++) {
  1121. if( skill->dbs->db[i].nameid ) {
  1122. WFIFOW(fd, 4 + (count*4)) = skill->dbs->db[i].nameid;
  1123. WFIFOW(fd, 6 + (count*4)) = i;
  1124. count++;
  1125. }
  1126. }
  1127. WFIFOW(fd,2) = 4 + (count * 4);
  1128. WFIFOSET(fd,4 + (count * 4));
  1129. }
  1130. /*==========================================
  1131. *
  1132. *------------------------------------------*/
  1133. int chrif_parse(int fd) {
  1134. int packet_len, cmd;
  1135. // only process data from the char-server
  1136. if ( fd != chrif->fd ) {
  1137. ShowDebug("chrif_parse: Disconnecting invalid session #%d (is not the char-server)\n", fd);
  1138. sockt->close(fd);
  1139. return 0;
  1140. }
  1141. if ( sockt->session[fd]->flag.eof ) {
  1142. sockt->close(fd);
  1143. chrif->fd = -1;
  1144. chrif->on_disconnect();
  1145. return 0;
  1146. } else if ( sockt->session[fd]->flag.ping ) {/* we've reached stall time */
  1147. if( DIFF_TICK(sockt->last_tick, sockt->session[fd]->rdata_tick) > (sockt->stall_time * 2) ) {/* we can't wait any longer */
  1148. sockt->eof(fd);
  1149. return 0;
  1150. } else if( sockt->session[fd]->flag.ping != 2 ) { /* we haven't sent ping out yet */
  1151. chrif->keepalive(fd);
  1152. sockt->session[fd]->flag.ping = 2;
  1153. }
  1154. }
  1155. while (RFIFOREST(fd) >= 2) {
  1156. if (VECTOR_LENGTH(HPM->packets[hpChrif_Parse]) > 0) {
  1157. int result = HPM->parse_packets(fd,hpChrif_Parse);
  1158. if (result == 1)
  1159. continue;
  1160. if (result == 2)
  1161. return 0;
  1162. }
  1163. cmd = RFIFOW(fd,0);
  1164. if (cmd < 0x2af8 || cmd >= 0x2af8 + ARRAYLENGTH(chrif->packet_len_table) || chrif->packet_len_table[cmd-0x2af8] == 0) {
  1165. int result = intif->parse(fd); // Passed on to the intif
  1166. if (result == 1) continue; // Treated in intif
  1167. if (result == 2) return 0; // Didn't have enough data (len==-1)
  1168. ShowWarning("chrif_parse: session #%d, intif->parse failed (unrecognized command 0x%.4x).\n", fd, cmd);
  1169. sockt->eof(fd);
  1170. return 0;
  1171. }
  1172. if ( ( packet_len = chrif->packet_len_table[cmd-0x2af8] ) == -1) { // dynamic-length packet, second WORD holds the length
  1173. if (RFIFOREST(fd) < 4)
  1174. return 0;
  1175. packet_len = RFIFOW(fd,2);
  1176. }
  1177. if ((int)RFIFOREST(fd) < packet_len)
  1178. return 0;
  1179. //ShowDebug("Received packet 0x%4x (%d bytes) from char-server (connection %d)\n", RFIFOW(fd,0), packet_len, fd);
  1180. switch(cmd) {
  1181. case 0x2af9: chrif->connectack(fd); break;
  1182. case 0x2afb: chrif->sendmapack(fd); break;
  1183. case 0x2afd: chrif->authok(fd); break;
  1184. case 0x2b00: map->setusers(RFIFOL(fd,2)); chrif->keepalive(fd); break;
  1185. case 0x2b03: clif->charselectok(RFIFOL(fd,2), RFIFOB(fd,6)); break;
  1186. case 0x2b04: chrif->recvmap(fd); break;
  1187. case 0x2b06: chrif->changemapserverack(RFIFOL(fd,2), RFIFOL(fd,6), RFIFOL(fd,10), RFIFOL(fd,14), RFIFOW(fd,18), RFIFOW(fd,20), RFIFOW(fd,22), RFIFOL(fd,24), RFIFOW(fd,28)); break;
  1188. case 0x2b09: map->addnickdb(RFIFOL(fd,2), (char*)RFIFOP(fd,6)); break;
  1189. case 0x2b0a: sockt->datasync(fd, false); break;
  1190. case 0x2b0d: chrif->changedsex(fd); break;
  1191. case 0x2b0f: chrif->char_ask_name_answer(RFIFOL(fd,2), (char*)RFIFOP(fd,6), RFIFOW(fd,30), RFIFOW(fd,32)); break;
  1192. case 0x2b12: chrif->divorceack(RFIFOL(fd,2), RFIFOL(fd,6)); break;
  1193. case 0x2b14: chrif->idbanned(fd); break;
  1194. case 0x2b1b: chrif->recvfamelist(fd); break;
  1195. case 0x2b1d: chrif->load_scdata(fd); break;
  1196. case 0x2b1e: chrif->update_ip(fd); break;
  1197. case 0x2b1f: chrif->disconnectplayer(fd); break;
  1198. case 0x2b20: chrif->removemap(fd); break;
  1199. case 0x2b21: chrif->save_ack(fd); break;
  1200. case 0x2b22: chrif->updatefamelist_ack(fd); break;
  1201. case 0x2b24: chrif->keepalive_ack(fd); break;
  1202. case 0x2b25: chrif->deadopt(RFIFOL(fd,2), RFIFOL(fd,6), RFIFOL(fd,10)); break;
  1203. case 0x2b27: chrif->authfail(fd); break;
  1204. default:
  1205. ShowError("chrif_parse : unknown packet (session #%d): 0x%x. Disconnecting.\n", fd, cmd);
  1206. sockt->eof(fd);
  1207. return 0;
  1208. }
  1209. if ( fd == chrif->fd ) //There's the slight chance we lost the connection during parse, in which case this would segfault if not checked [Skotlex]
  1210. RFIFOSKIP(fd, packet_len);
  1211. }
  1212. return 0;
  1213. }
  1214. int send_usercount_tochar(int tid, int64 tick, int id, intptr_t data) {
  1215. chrif_check(-1);
  1216. WFIFOHEAD(chrif->fd,4);
  1217. WFIFOW(chrif->fd,0) = 0x2afe;
  1218. WFIFOW(chrif->fd,2) = map->usercount();
  1219. WFIFOSET(chrif->fd,4);
  1220. return 0;
  1221. }
  1222. /*==========================================
  1223. * timerFunction
  1224. * Send to char the number of client connected to map
  1225. *------------------------------------------*/
  1226. bool send_users_tochar(void) {
  1227. int users = 0, i = 0;
  1228. const struct map_session_data *sd;
  1229. struct s_mapiterator *iter;
  1230. chrif_check(false);
  1231. users = map->usercount();
  1232. WFIFOHEAD(chrif->fd, 6+8*users);
  1233. WFIFOW(chrif->fd,0) = 0x2aff;
  1234. iter = mapit_getallusers();
  1235. for (sd = BL_UCCAST(BL_PC, mapit->first(iter)); mapit->exists(iter); sd = BL_UCCAST(BL_PC, mapit->next(iter))) {
  1236. WFIFOL(chrif->fd,6+8*i) = sd->status.account_id;
  1237. WFIFOL(chrif->fd,6+8*i+4) = sd->status.char_id;
  1238. i++;
  1239. }
  1240. mapit->free(iter);
  1241. WFIFOW(chrif->fd,2) = 6 + 8*users;
  1242. WFIFOW(chrif->fd,4) = users;
  1243. WFIFOSET(chrif->fd, 6+8*users);
  1244. return true;
  1245. }
  1246. /*==========================================
  1247. * timerFunction
  1248. * Check the connection to char server, (if it down)
  1249. *------------------------------------------*/
  1250. int check_connect_char_server(int tid, int64 tick, int id, intptr_t data) {
  1251. static int displayed = 0;
  1252. if ( chrif->fd <= 0 || sockt->session[chrif->fd] == NULL ) {
  1253. if ( !displayed ) {
  1254. ShowStatus("Attempting to connect to Char Server. Please wait.\n");
  1255. displayed = 1;
  1256. }
  1257. chrif->state = 0;
  1258. if ((chrif->fd = sockt->make_connection(chrif->ip, chrif->port,NULL)) == -1) //Attempt to connect later. [Skotlex]
  1259. return 0;
  1260. sockt->session[chrif->fd]->func_parse = chrif->parse;
  1261. sockt->session[chrif->fd]->flag.server = 1;
  1262. sockt->realloc_fifo(chrif->fd, FIFOSIZE_SERVERLINK, FIFOSIZE_SERVERLINK);
  1263. chrif->connect(chrif->fd);
  1264. chrif->connected = (chrif->state == 2);
  1265. chrif->srvinfo = 0;
  1266. } else {
  1267. if (chrif->srvinfo == 0) {
  1268. chrif->ragsrvinfo(battle_config.base_exp_rate, battle_config.job_exp_rate, battle_config.item_rate_common);
  1269. chrif->srvinfo = 1;
  1270. }
  1271. }
  1272. if ( chrif->isconnected() )
  1273. displayed = 0;
  1274. return 0;
  1275. }
  1276. /*==========================================
  1277. * Asks char server to remove friend_id from the friend list of char_id
  1278. *------------------------------------------*/
  1279. bool chrif_removefriend(int char_id, int friend_id)
  1280. {
  1281. chrif_check(false);
  1282. WFIFOHEAD(chrif->fd,10);
  1283. WFIFOW(chrif->fd,0) = 0x2b07;
  1284. WFIFOL(chrif->fd,2) = char_id;
  1285. WFIFOL(chrif->fd,6) = friend_id;
  1286. WFIFOSET(chrif->fd,10);
  1287. return true;
  1288. }
  1289. void chrif_send_report(char* buf, int len) {
  1290. #ifndef STATS_OPT_OUT
  1291. if( chrif->fd > 0 ) {
  1292. nullpo_retv(buf);
  1293. WFIFOHEAD(chrif->fd,len + 2);
  1294. WFIFOW(chrif->fd,0) = 0x3008;
  1295. memcpy(WFIFOP(chrif->fd,2), buf, len);
  1296. WFIFOSET(chrif->fd,len + 2);
  1297. sockt->flush(chrif->fd); /* ensure it's sent now. */
  1298. }
  1299. #endif
  1300. }
  1301. /**
  1302. * Sends a single scdata for saving into char server, meant to ensure integrity of duration-less conditions
  1303. **/
  1304. void chrif_save_scdata_single(int account_id, int char_id, short type, struct status_change_entry *sce)
  1305. {
  1306. if( !chrif->isconnected() )
  1307. return;
  1308. nullpo_retv(sce);
  1309. WFIFOHEAD(chrif->fd, 28);
  1310. WFIFOW(chrif->fd, 0) = 0x2740;
  1311. WFIFOL(chrif->fd, 2) = account_id;
  1312. WFIFOL(chrif->fd, 6) = char_id;
  1313. WFIFOW(chrif->fd, 10) = type;
  1314. WFIFOL(chrif->fd, 12) = sce->val1;
  1315. WFIFOL(chrif->fd, 16) = sce->val2;
  1316. WFIFOL(chrif->fd, 20) = sce->val3;
  1317. WFIFOL(chrif->fd, 24) = sce->val4;
  1318. WFIFOSET(chrif->fd, 28);
  1319. }
  1320. /**
  1321. * Sends a single scdata deletion request into char server, meant to ensure integrity of duration-less conditions
  1322. **/
  1323. void chrif_del_scdata_single(int account_id, int char_id, short type)
  1324. {
  1325. if( !chrif->isconnected() ) {
  1326. ShowError("MAYDAY! failed to delete status %d from CID:%d/AID:%d\n",type,char_id,account_id);
  1327. return;
  1328. }
  1329. WFIFOHEAD(chrif->fd, 12);
  1330. WFIFOW(chrif->fd, 0) = 0x2741;
  1331. WFIFOL(chrif->fd, 2) = account_id;
  1332. WFIFOL(chrif->fd, 6) = char_id;
  1333. WFIFOW(chrif->fd, 10) = type;
  1334. WFIFOSET(chrif->fd, 12);
  1335. }
  1336. /**
  1337. * @see DBApply
  1338. */
  1339. int auth_db_final(DBKey key, DBData *data, va_list ap) {
  1340. struct auth_node *node = DB->data2ptr(data);
  1341. nullpo_ret(node);
  1342. if (node->sd) {
  1343. if( node->sd->regs.vars )
  1344. node->sd->regs.vars->destroy(node->sd->regs.vars, script->reg_destroy);
  1345. if( node->sd->regs.arrays )
  1346. node->sd->regs.arrays->destroy(node->sd->regs.arrays, script->array_free_db);
  1347. aFree(node->sd);
  1348. }
  1349. ers_free(chrif->auth_db_ers, node);
  1350. return 0;
  1351. }
  1352. /*==========================================
  1353. * Destructor
  1354. *------------------------------------------*/
  1355. void do_final_chrif(void)
  1356. {
  1357. if( chrif->fd != -1 ) {
  1358. sockt->close(chrif->fd);
  1359. chrif->fd = -1;
  1360. }
  1361. chrif->auth_db->destroy(chrif->auth_db, chrif->auth_db_final);
  1362. ers_destroy(chrif->auth_db_ers);
  1363. }
  1364. /*==========================================
  1365. *
  1366. *------------------------------------------*/
  1367. void do_init_chrif(bool minimal) {
  1368. if (minimal)
  1369. return;
  1370. chrif->auth_db = idb_alloc(DB_OPT_BASE);
  1371. chrif->auth_db_ers = ers_new(sizeof(struct auth_node),"chrif.c::auth_db_ers",ERS_OPT_NONE);
  1372. timer->add_func_list(chrif->check_connect_char_server, "check_connect_char_server");
  1373. timer->add_func_list(chrif->auth_db_cleanup, "auth_db_cleanup");
  1374. timer->add_func_list(chrif->send_usercount_tochar, "send_usercount_tochar");
  1375. // establish map-char connection if not present
  1376. timer->add_interval(timer->gettick() + 1000, chrif->check_connect_char_server, 0, 0, 10 * 1000);
  1377. // wipe stale data for timed-out client connection requests
  1378. timer->add_interval(timer->gettick() + 1000, chrif->auth_db_cleanup, 0, 0, 30 * 1000);
  1379. // send the user count every 10 seconds, to hide the charserver's online counting problem
  1380. timer->add_interval(timer->gettick() + 1000, chrif->send_usercount_tochar, 0, 0, UPDATE_INTERVAL);
  1381. }
  1382. /*=====================================
  1383. * Default Functions : chrif.h
  1384. * Generated by HerculesInterfaceMaker
  1385. * created by Susu
  1386. *-------------------------------------*/
  1387. void chrif_defaults(void) {
  1388. const int packet_len_table[CHRIF_PACKET_LEN_TABLE_SIZE] = { // U - used, F - free
  1389. 60, 3, -1, 27, 10, -1, 6, -1, // 2af8-2aff: U->2af8, U->2af9, U->2afa, U->2afb, U->2afc, U->2afd, U->2afe, U->2aff
  1390. 6, -1, 18, 7, -1, 39, 30, 10, // 2b00-2b07: U->2b00, U->2b01, U->2b02, U->2b03, U->2b04, U->2b05, U->2b06, U->2b07
  1391. 6, 30, -1, 0, 86, 7, 44, 34, // 2b08-2b0f: U->2b08, U->2b09, U->2b0a, F->2b0b, U->2b0c, U->2b0d, U->2b0e, U->2b0f
  1392. 11, 10, 10, 0, 11, 0,266, 10, // 2b10-2b17: U->2b10, U->2b11, U->2b12, F->2b13, U->2b14, F->2b15, U->2b16, U->2b17
  1393. 2, 10, 2, -1, -1, -1, 2, 7, // 2b18-2b1f: U->2b18, U->2b19, U->2b1a, U->2b1b, U->2b1c, U->2b1d, U->2b1e, U->2b1f
  1394. -1, 10, 8, 2, 2, 14, 19, 19, // 2b20-2b27: U->2b20, U->2b21, U->2b22, U->2b23, U->2b24, U->2b25, U->2b26, U->2b27
  1395. };
  1396. chrif = &chrif_s;
  1397. /* vars */
  1398. chrif->connected = 0;
  1399. chrif->other_mapserver_count = 0;
  1400. memcpy(chrif->packet_len_table,&packet_len_table,sizeof(chrif->packet_len_table));
  1401. chrif->fd = -1;
  1402. chrif->srvinfo = 0;
  1403. memset(chrif->ip_str,0,sizeof(chrif->ip_str));
  1404. chrif->ip = 0;
  1405. chrif->port = 6121;
  1406. memset(chrif->userid,0,sizeof(chrif->userid));
  1407. memset(chrif->passwd,0,sizeof(chrif->passwd));
  1408. chrif->state = 0;
  1409. /* */
  1410. chrif->auth_db = NULL;
  1411. chrif->auth_db_ers = NULL;
  1412. /* */
  1413. chrif->init = do_init_chrif;
  1414. chrif->final = do_final_chrif;
  1415. /* funcs */
  1416. chrif->setuserid = chrif_setuserid;
  1417. chrif->setpasswd = chrif_setpasswd;
  1418. chrif->checkdefaultlogin = chrif_checkdefaultlogin;
  1419. chrif->setip = chrif_setip;
  1420. chrif->setport = chrif_setport;
  1421. chrif->isconnected = chrif_isconnected;
  1422. chrif->check_shutdown = chrif_check_shutdown;
  1423. chrif->search = chrif_search;
  1424. chrif->auth_check = chrif_auth_check;
  1425. chrif->auth_delete = chrif_auth_delete;
  1426. chrif->auth_finished = chrif_auth_finished;
  1427. chrif->authreq = chrif_authreq;
  1428. chrif->authok = chrif_authok;
  1429. chrif->scdata_request = chrif_scdata_request;
  1430. chrif->save = chrif_save;
  1431. chrif->charselectreq = chrif_charselectreq;
  1432. chrif->changemapserver = chrif_changemapserver;
  1433. chrif->searchcharid = chrif_searchcharid;
  1434. chrif->changeemail = chrif_changeemail;
  1435. chrif->char_ask_name = chrif_char_ask_name;
  1436. chrif->updatefamelist = chrif_updatefamelist;
  1437. chrif->buildfamelist = chrif_buildfamelist;
  1438. chrif->save_scdata = chrif_save_scdata;
  1439. chrif->ragsrvinfo = chrif_ragsrvinfo;
  1440. chrif->char_offline_nsd = chrif_char_offline_nsd;
  1441. chrif->char_reset_offline = chrif_char_reset_offline;
  1442. chrif->send_users_tochar = send_users_tochar;
  1443. chrif->char_online = chrif_char_online; // look like unused
  1444. chrif->changesex = chrif_changesex;
  1445. //chrif->chardisconnect = chrif_chardisconnect;
  1446. chrif->divorce = chrif_divorce;
  1447. chrif->removefriend = chrif_removefriend;
  1448. chrif->send_report = chrif_send_report;
  1449. chrif->flush = chrif_flush;
  1450. chrif->skillid2idx = chrif_skillid2idx;
  1451. chrif->sd_to_auth = chrif_sd_to_auth;
  1452. chrif->check_connect_char_server = check_connect_char_server;
  1453. chrif->auth_logout = chrif_auth_logout;
  1454. chrif->save_ack = chrif_save_ack;
  1455. chrif->reconnect = chrif_reconnect;
  1456. chrif->auth_db_cleanup_sub = auth_db_cleanup_sub;
  1457. chrif->char_ask_name_answer = chrif_char_ask_name_answer;
  1458. chrif->auth_db_final = auth_db_final;
  1459. chrif->send_usercount_tochar = send_usercount_tochar;
  1460. chrif->auth_db_cleanup = auth_db_cleanup;
  1461. chrif->connect = chrif_connect;
  1462. chrif->connectack = chrif_connectack;
  1463. chrif->sendmap = chrif_sendmap;
  1464. chrif->sendmapack = chrif_sendmapack;
  1465. chrif->recvmap = chrif_recvmap;
  1466. chrif->changemapserverack = chrif_changemapserverack;
  1467. chrif->changedsex = chrif_changedsex;
  1468. chrif->divorceack = chrif_divorceack;
  1469. chrif->idbanned = chrif_idbanned;
  1470. chrif->recvfamelist = chrif_recvfamelist;
  1471. chrif->load_scdata = chrif_load_scdata;
  1472. chrif->update_ip = chrif_update_ip;
  1473. chrif->disconnectplayer = chrif_disconnectplayer;
  1474. chrif->removemap = chrif_removemap;
  1475. chrif->updatefamelist_ack = chrif_updatefamelist_ack;
  1476. chrif->keepalive = chrif_keepalive;
  1477. chrif->keepalive_ack = chrif_keepalive_ack;
  1478. chrif->deadopt = chrif_deadopt;
  1479. chrif->authfail = chrif_authfail;
  1480. chrif->on_ready = chrif_on_ready;
  1481. chrif->on_disconnect = chrif_on_disconnect;
  1482. chrif->parse = chrif_parse;
  1483. chrif->save_scdata_single = chrif_save_scdata_single;
  1484. chrif->del_scdata_single = chrif_del_scdata_single;
  1485. }