From 58b8c8d8cb9f78537495f908887fea9d0a451637 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 4 Jul 2015 22:37:51 +0300 Subject: Rename login/char/map dirs to elogin/echar/emap for avoid conflicts with hercules. --- src/echar/char.c | 191 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/echar/char.h | 19 ++++++ src/echar/config.c | 59 +++++++++++++++++ src/echar/config.h | 20 ++++++ src/echar/init.c | 96 +++++++++++++++++++++++++++ 5 files changed, 385 insertions(+) create mode 100644 src/echar/char.c create mode 100644 src/echar/char.h create mode 100644 src/echar/config.c create mode 100644 src/echar/config.h create mode 100644 src/echar/init.c (limited to 'src/echar') diff --git a/src/echar/char.c b/src/echar/char.c new file mode 100644 index 0000000..fc0fb6d --- /dev/null +++ b/src/echar/char.c @@ -0,0 +1,191 @@ +// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// Copyright (c) 2014 Evol developers + +#include +#include +#include + +#include "common/HPMi.h" +#include "common/malloc.h" +#include "common/mmo.h" +#include "common/socket.h" +#include "common/strlib.h" +#include "common/timer.h" +#include "char/char.h" + +#include "ecommon/ip.h" +#include "echar/char.h" +#include "echar/config.h" + +void echar_parse_char_login_map_server(int *fd) +{ + if (!inter_server_ip) + return; + + const uint32 ipl = session[*fd]->client_addr; + + const char *const ip = ip2str(ipl, NULL); + if (!checkAllowedIp(inter_server_ip, ip)) + { + ShowNotice("Connection of the map-server from ip %s REFUSED.\n", ip); + chr->login_map_server_ack(*fd, 3); + hookStop(); + } +} + +void echar_parse_char_create_new_char(int *fdPtr, struct char_session_data* sd) +{ + // ignore char creation disable option + const int fd = *fdPtr; + uint16 race = 0; + uint16 look = 0; + uint8 sex = 0; + + if (!sd) + return; + + if (sd->version >= 4) + { + race = RFIFOW(fd, 31); + if (race < min_char_class || race > max_char_class) + { + chr->creation_failed(fd, -10); + RFIFOSKIP(fd, 31 + 5); + hookStop(); + return; + } + sex = RFIFOB(fd, 33); + if (sex > 1 && sex != 99) + { + chr->creation_failed(fd, -11); + RFIFOSKIP(fd, 31 + 5); + hookStop(); + return; + } + look = RFIFOW(fd, 34); + if (look < min_look || look > max_look) + { + chr->creation_failed(fd, -12); + RFIFOSKIP(fd, 31 + 5); + hookStop(); + return; + } + } + + const int result = chr->make_new_char_sql(sd, (char*)RFIFOP(fd, 2), 1, 1, 1, 1, 1, 1, RFIFOB(fd, 26), RFIFOW(fd, 27), RFIFOW(fd, 29)); + if (result < 0) + { + chr->creation_failed(fd, result); + } + else + { + // retrieve data + struct mmo_charstatus char_dat; + chr->mmo_char_fromsql(result, &char_dat, false); //Only the short data is needed. + + if (sd->version >= 4) + { + char_dat.class_ = race; + char_dat.sex = sex; + char_dat.clothes_color = look; + + chr->mmo_char_tosql(result, &char_dat); + } + chr->creation_ok(fd, &char_dat); + + // add new entry to the chars list + sd->found_char[char_dat.slot] = result; // the char_id of the new char + } + if (sd->version >= 4) + RFIFOSKIP(fd, 31 + 5); + else + RFIFOSKIP(fd, 31); + hookStop(); +} + +void echar_creation_failed(int *fdPtr, int *result) +{ + const int fd = *fdPtr; + WFIFOHEAD(fd, 3); + WFIFOW(fd, 0) = 0x6e; + /* Others I found [Ind] */ + /* 0x02 = Symbols in Character Names are forbidden */ + /* 0x03 = You are not eligible to open the Character Slot. */ + /* 0x0B = This service is only available for premium users. */ + switch (*result) + { + case -1: WFIFOB(fd, 2) = 0x00; break; // 'Charname already exists' + case -2: WFIFOB(fd, 2) = 0xFF; break; // 'Char creation denied' + case -3: WFIFOB(fd, 2) = 0x01; break; // 'You are underaged' + case -4: WFIFOB(fd, 2) = 0x03; break; // 'You are not eligible to open the Character Slot.' + case -5: WFIFOB(fd, 2) = 0x02; break; // 'Symbols in Character Names are forbidden' + case -10: WFIFOB(fd, 2) = 0x50; break; // Wrong class + case -11: WFIFOB(fd, 2) = 0x51; break; // Wrong sex + case -12: WFIFOB(fd, 2) = 0x52; break; // Wrong look + + default: + ShowWarning("chr->parse_char: Unknown result received from chr->make_new_char_sql: %d!\n", *result); + WFIFOB(fd,2) = 0xFF; + break; + } + WFIFOSET(fd,3); + hookStop(); +} + +void echar_parse_char_ping(int *fdPtr) +{ + const int fd = *fdPtr; + RFIFOSKIP(fd, 6); + + struct char_session_data* sd = (struct char_session_data*)session[fd]->session_data; + if (!sd) + { + hookStop(); + return; + } + struct online_char_data* character = (struct online_char_data*)idb_get(chr->online_char_db, sd->account_id); + if (!character) + { + hookStop(); + return; + } + + if (character->waiting_disconnect != INVALID_TIMER) + { + timer->delete(character->waiting_disconnect, chr->waiting_disconnect); + character->waiting_disconnect = timer->add(timer->gettick() + 30000, chr->waiting_disconnect, character->account_id, 0); + } + hookStop(); +} + +void echar_parse_change_paassword(int fd) +{ + if (chr->login_fd < 0) + return; + struct char_session_data* sd = (struct char_session_data*)session[fd]->session_data; + if (!sd) + return; + WFIFOHEAD(chr->login_fd, 54); + WFIFOW(chr->login_fd, 0) = 0x5000; + WFIFOL(chr->login_fd, 2) = sd->account_id; + memcpy (WFIFOP (chr->login_fd, 6), RFIFOP (fd, 2), 24); + memcpy (WFIFOP (chr->login_fd, 30), RFIFOP (fd, 26), 24); + WFIFOSET(chr->login_fd, 54); +} + +void echar_parse_login_password_change_ack(int charFd) +{ + struct char_session_data* sd = NULL; + const int accountId = RFIFOL(charFd, 2); + const int status = RFIFOB(charFd, 6); + + int fd = -1; + ARR_FIND( 0, sockt->fd_max, fd, session[fd] && (sd = (struct char_session_data*)session[fd]->session_data) && sd->auth && sd->account_id == accountId ); + if (fd < sockt->fd_max && fd >= 0) + { + WFIFOHEAD(fd, 3); + WFIFOW(fd, 0) = 0x62; + WFIFOB(fd, 2) = status; + WFIFOSET(fd, 3); + } +} diff --git a/src/echar/char.h b/src/echar/char.h new file mode 100644 index 0000000..b013f44 --- /dev/null +++ b/src/echar/char.h @@ -0,0 +1,19 @@ +// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// Copyright (c) 2014 Evol developers + +#ifndef EVOL_CHAR_CHAR +#define EVOL_CHAR_CHAR + +void echar_parse_char_login_map_server(int *fd); + +void echar_parse_char_create_new_char(int *fdPtr, struct char_session_data* sd); + +void echar_creation_failed(int *fdPtr, int *result); + +void echar_parse_char_ping(int *fdPtr); + +void echar_parse_change_paassword(int fd); + +void echar_parse_login_password_change_ack(int charFd); + +#endif // EVOL_CHAR_CHAR diff --git a/src/echar/config.c b/src/echar/config.c new file mode 100644 index 0000000..f8cff5f --- /dev/null +++ b/src/echar/config.c @@ -0,0 +1,59 @@ +// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// Copyright (c) 2014 Evol developers + +#include +#include +#include + +#include "common/HPMi.h" +#include "common/malloc.h" +#include "common/mmo.h" +#include "common/socket.h" +#include "common/strlib.h" + +#include "echar/config.h" + +char *inter_server_ip = NULL; +int min_char_class = 0; +int max_char_class = 0; +int min_look = 0; +int max_look = 0; + +void config_inter_server_ip(const char *val) +{ + char buf[1000]; + + if (strlen(val) > 900) + return; + + strcpy(buf, ","); + strcat(buf, val); + strcat(buf, ","); + inter_server_ip = aStrdup(buf); +} + +void config_min_char_class(const char *val) +{ + min_char_class = atoi(val); +} + +void config_max_char_class(const char *val) +{ + max_char_class = atoi(val); +} + +void config_min_look(const char *val) +{ + min_look = atoi(val); +} + +void config_max_look(const char *val) +{ + max_look = atoi(val); +} + +void config_final(void) +{ + if (inter_server_ip) + aFree(inter_server_ip); +} diff --git a/src/echar/config.h b/src/echar/config.h new file mode 100644 index 0000000..d60abc0 --- /dev/null +++ b/src/echar/config.h @@ -0,0 +1,20 @@ +// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// Copyright (c) 2014 Evol developers + +#ifndef EVOL_CHAR_CONFIG +#define EVOL_CHAR_CONFIG + +void config_final(void); +void config_inter_server_ip(const char *val); +void config_min_char_class(const char *val); +void config_max_char_class(const char *val); +void config_min_look(const char *val); +void config_max_look(const char *val); + +extern char *inter_server_ip; +extern int min_char_class; +extern int max_char_class; +extern int min_look; +extern int max_look; + +#endif // EVOL_CHAR_CONFIG diff --git a/src/echar/init.c b/src/echar/init.c new file mode 100644 index 0000000..a167636 --- /dev/null +++ b/src/echar/init.c @@ -0,0 +1,96 @@ +// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// Copyright (c) 2014 Evol developers + +#include +#include +#include + +#include "common/HPMi.h" +#include "common/malloc.h" +#include "common/mapindex.h" +#include "common/mmo.h" +#include "common/socket.h" +#include "common/strlib.h" +#include "char/char.h" +#include "char/geoip.h" +#include "char/int_auction.h" +#include "char/int_elemental.h" +#include "char/int_guild.h" +#include "char/int_homun.h" +#include "char/int_mail.h" +#include "char/int_mercenary.h" +#include "char/int_party.h" +#include "char/int_pet.h" +#include "char/int_quest.h" +#include "char/int_storage.h" +#include "char/inter.h" +#include "char/loginif.h" +#include "char/mapif.h" + +#include "ecommon/config.h" +#include "ecommon/init.h" +#include "echar/char.h" +#include "echar/config.h" + +#include "common/HPMDataCheck.h" /* should always be the last file included! (if you don't make it last, it'll intentionally break compile time) */ + +HPExport struct hplugin_info pinfo = +{ + "evol_char", + SERVER_TYPE_CHAR, + "0.1", + HPM_VERSION +}; + +HPExport void plugin_init (void) +{ + chr = GET_SYMBOL("chr"); + geoip = GET_SYMBOL("geoip"); + inter_auction = GET_SYMBOL("inter_auction"); + inter_elemental = GET_SYMBOL("inter_elemental"); + inter_guild = GET_SYMBOL("inter_guild"); + inter_homunculus = GET_SYMBOL("inter_homunculus"); + inter_mail = GET_SYMBOL("inter_mail"); + inter_mercenary = GET_SYMBOL("inter_mercenary"); + inter_party = GET_SYMBOL("inter_party"); + inter_pet = GET_SYMBOL("inter_pet"); + inter_quest = GET_SYMBOL("inter_quest"); + inter_storage = GET_SYMBOL("inter_storage"); + inter = GET_SYMBOL("inter"); + loginif = GET_SYMBOL("loginif"); + mapif = GET_SYMBOL("mapif"); + + addPacket(0x0061, 50, echar_parse_change_paassword, hpParse_Char); + addPacket(0x5001, 7, echar_parse_login_password_change_ack, hpParse_FromLogin); + + addHookPre("chr->parse_char_login_map_server", echar_parse_char_login_map_server); + addHookPre("chr->parse_char_create_new_char", echar_parse_char_create_new_char); + //addHookPre("chr->parse_char_ping", echar_parse_char_ping); + addHookPre("chr->creation_failed", echar_creation_failed); +} + +HPExport void server_preinit (void) +{ + interfaces_init_common(); + mapindex = GET_SYMBOL("mapindex"); + + setDefaultMap(); + addMapInterConf("default_map", config_default_map); + addMapInterConf("default_x", config_default_x); + addMapInterConf("default_y", config_default_y); + + addCharInterConf("inter_server_ip", config_inter_server_ip); + addCharConf("min_char_class", config_min_char_class); + addCharConf("max_char_class", config_max_char_class); + addCharConf("min_cloth_color", config_min_look); + addCharConf("max_cloth_color", config_max_look); +} + +HPExport void server_online (void) +{ +} + +HPExport void plugin_final (void) +{ + commonClean(); +} -- cgit v1.2.3-70-g09d2