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/Makefile.am | 170 +++---- src/char/char.c | 191 ------- src/char/char.h | 19 - src/char/config.c | 59 --- src/char/config.h | 20 - src/char/init.c | 96 ---- src/common/config.c | 38 -- src/common/config.h | 16 - src/common/init.c | 44 -- src/common/init.h | 11 - src/common/ip.c | 25 - src/common/ip.h | 9 - 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 ++++ src/ecommon/config.c | 38 ++ src/ecommon/config.h | 16 + src/ecommon/init.c | 44 ++ src/ecommon/init.h | 11 + src/ecommon/ip.c | 25 + src/ecommon/ip.h | 9 + src/elogin/config.c | 43 ++ src/elogin/config.h | 14 + src/elogin/init.c | 59 +++ src/elogin/login.c | 30 ++ src/elogin/login.h | 9 + src/elogin/md5calc.c | 406 +++++++++++++++ src/elogin/md5calc.h | 13 + src/elogin/mt_rand.c | 118 +++++ src/elogin/mt_rand.h | 9 + src/elogin/parse.c | 210 ++++++++ src/elogin/parse.h | 14 + src/elogin/send.c | 47 ++ src/elogin/send.h | 11 + src/emap/atcommand.c | 84 ++++ src/emap/atcommand.h | 14 + src/emap/clif.c | 377 ++++++++++++++ src/emap/clif.h | 26 + src/emap/data/itemd.c | 68 +++ src/emap/data/itemd.h | 13 + src/emap/data/mapd.c | 40 ++ src/emap/data/mapd.h | 12 + src/emap/data/npcd.c | 38 ++ src/emap/data/npcd.h | 12 + src/emap/data/session.c | 48 ++ src/emap/data/session.h | 13 + src/emap/init.c | 244 +++++++++ src/emap/itemdb.c | 91 ++++ src/emap/itemdb.h | 11 + src/emap/lang.c | 234 +++++++++ src/emap/lang.h | 15 + src/emap/mail.c | 36 ++ src/emap/mail.h | 9 + src/emap/map.c | 133 +++++ src/emap/map.h | 10 + src/emap/mob.c | 48 ++ src/emap/mob.h | 9 + src/emap/npc.c | 127 +++++ src/emap/npc.h | 14 + src/emap/parse.c | 220 ++++++++ src/emap/parse.h | 20 + src/emap/pc.c | 309 ++++++++++++ src/emap/pc.h | 42 ++ src/emap/permission.c | 18 + src/emap/permission.h | 10 + src/emap/quest.c | 132 +++++ src/emap/quest.h | 9 + src/emap/script.c | 1148 ++++++++++++++++++++++++++++++++++++++++++ src/emap/script.h | 46 ++ src/emap/scriptdefines.h | 55 ++ src/emap/send.c | 305 +++++++++++ src/emap/send.h | 31 ++ src/emap/skill.c | 44 ++ src/emap/skill.h | 12 + src/emap/status.c | 70 +++ src/emap/status.h | 12 + src/emap/struct/itemdext.h | 33 ++ src/emap/struct/mapdext.h | 17 + src/emap/struct/npcdext.h | 12 + src/emap/struct/sessionext.h | 15 + src/emap/unit.c | 163 ++++++ src/emap/unit.h | 10 + src/emap/utils/formatutils.c | 116 +++++ src/emap/utils/formatutils.h | 9 + src/login/config.c | 43 -- src/login/config.h | 14 - src/login/init.c | 59 --- src/login/login.c | 30 -- src/login/login.h | 9 - src/login/md5calc.c | 406 --------------- src/login/md5calc.h | 13 - src/login/mt_rand.c | 118 ----- src/login/mt_rand.h | 9 - src/login/parse.c | 210 -------- src/login/parse.h | 14 - src/login/send.c | 47 -- src/login/send.h | 11 - src/map/atcommand.c | 84 ---- src/map/atcommand.h | 14 - src/map/clif.c | 376 -------------- src/map/clif.h | 26 - src/map/data/itemd.c | 68 --- src/map/data/itemd.h | 13 - src/map/data/mapd.c | 40 -- src/map/data/mapd.h | 12 - src/map/data/npcd.c | 38 -- src/map/data/npcd.h | 12 - src/map/data/session.c | 48 -- src/map/data/session.h | 13 - src/map/init.c | 243 --------- src/map/itemdb.c | 91 ---- src/map/itemdb.h | 11 - src/map/lang.c | 234 --------- src/map/lang.h | 15 - src/map/mail.c | 36 -- src/map/mail.h | 9 - src/map/map.c | 133 ----- src/map/map.h | 10 - src/map/mob.c | 48 -- src/map/mob.h | 9 - src/map/npc.c | 127 ----- src/map/npc.h | 14 - src/map/parse.c | 220 -------- src/map/parse.h | 20 - src/map/pc.c | 309 ------------ src/map/pc.h | 42 -- src/map/permission.c | 18 - src/map/permission.h | 10 - src/map/quest.c | 132 ----- src/map/quest.h | 9 - src/map/script.c | 1148 ------------------------------------------ src/map/script.h | 46 -- src/map/scriptdefines.h | 55 -- src/map/send.c | 305 ----------- src/map/send.h | 31 -- src/map/skill.c | 44 -- src/map/skill.h | 12 - src/map/status.c | 70 --- src/map/status.h | 12 - src/map/struct/itemdext.h | 33 -- src/map/struct/mapdext.h | 17 - src/map/struct/npcdext.h | 12 - src/map/struct/sessionext.h | 15 - src/map/unit.c | 163 ------ src/map/unit.h | 10 - src/map/utils/formatutils.c | 116 ----- src/map/utils/formatutils.h | 9 - 149 files changed, 6180 insertions(+), 6178 deletions(-) delete mode 100644 src/char/char.c delete mode 100644 src/char/char.h delete mode 100644 src/char/config.c delete mode 100644 src/char/config.h delete mode 100644 src/char/init.c delete mode 100644 src/common/config.c delete mode 100644 src/common/config.h delete mode 100644 src/common/init.c delete mode 100644 src/common/init.h delete mode 100644 src/common/ip.c delete mode 100644 src/common/ip.h 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 create mode 100644 src/ecommon/config.c create mode 100644 src/ecommon/config.h create mode 100644 src/ecommon/init.c create mode 100644 src/ecommon/init.h create mode 100644 src/ecommon/ip.c create mode 100644 src/ecommon/ip.h create mode 100644 src/elogin/config.c create mode 100644 src/elogin/config.h create mode 100644 src/elogin/init.c create mode 100644 src/elogin/login.c create mode 100644 src/elogin/login.h create mode 100644 src/elogin/md5calc.c create mode 100644 src/elogin/md5calc.h create mode 100644 src/elogin/mt_rand.c create mode 100644 src/elogin/mt_rand.h create mode 100644 src/elogin/parse.c create mode 100644 src/elogin/parse.h create mode 100644 src/elogin/send.c create mode 100644 src/elogin/send.h create mode 100644 src/emap/atcommand.c create mode 100644 src/emap/atcommand.h create mode 100644 src/emap/clif.c create mode 100644 src/emap/clif.h create mode 100644 src/emap/data/itemd.c create mode 100644 src/emap/data/itemd.h create mode 100644 src/emap/data/mapd.c create mode 100644 src/emap/data/mapd.h create mode 100644 src/emap/data/npcd.c create mode 100644 src/emap/data/npcd.h create mode 100644 src/emap/data/session.c create mode 100644 src/emap/data/session.h create mode 100644 src/emap/init.c create mode 100644 src/emap/itemdb.c create mode 100644 src/emap/itemdb.h create mode 100644 src/emap/lang.c create mode 100644 src/emap/lang.h create mode 100644 src/emap/mail.c create mode 100644 src/emap/mail.h create mode 100644 src/emap/map.c create mode 100644 src/emap/map.h create mode 100644 src/emap/mob.c create mode 100644 src/emap/mob.h create mode 100644 src/emap/npc.c create mode 100644 src/emap/npc.h create mode 100644 src/emap/parse.c create mode 100644 src/emap/parse.h create mode 100644 src/emap/pc.c create mode 100644 src/emap/pc.h create mode 100644 src/emap/permission.c create mode 100644 src/emap/permission.h create mode 100644 src/emap/quest.c create mode 100644 src/emap/quest.h create mode 100644 src/emap/script.c create mode 100644 src/emap/script.h create mode 100644 src/emap/scriptdefines.h create mode 100644 src/emap/send.c create mode 100644 src/emap/send.h create mode 100644 src/emap/skill.c create mode 100644 src/emap/skill.h create mode 100644 src/emap/status.c create mode 100644 src/emap/status.h create mode 100644 src/emap/struct/itemdext.h create mode 100644 src/emap/struct/mapdext.h create mode 100644 src/emap/struct/npcdext.h create mode 100644 src/emap/struct/sessionext.h create mode 100644 src/emap/unit.c create mode 100644 src/emap/unit.h create mode 100644 src/emap/utils/formatutils.c create mode 100644 src/emap/utils/formatutils.h delete mode 100644 src/login/config.c delete mode 100644 src/login/config.h delete mode 100644 src/login/init.c delete mode 100644 src/login/login.c delete mode 100644 src/login/login.h delete mode 100644 src/login/md5calc.c delete mode 100644 src/login/md5calc.h delete mode 100644 src/login/mt_rand.c delete mode 100644 src/login/mt_rand.h delete mode 100644 src/login/parse.c delete mode 100644 src/login/parse.h delete mode 100644 src/login/send.c delete mode 100644 src/login/send.h delete mode 100644 src/map/atcommand.c delete mode 100644 src/map/atcommand.h delete mode 100644 src/map/clif.c delete mode 100644 src/map/clif.h delete mode 100644 src/map/data/itemd.c delete mode 100644 src/map/data/itemd.h delete mode 100644 src/map/data/mapd.c delete mode 100644 src/map/data/mapd.h delete mode 100644 src/map/data/npcd.c delete mode 100644 src/map/data/npcd.h delete mode 100644 src/map/data/session.c delete mode 100644 src/map/data/session.h delete mode 100644 src/map/init.c delete mode 100644 src/map/itemdb.c delete mode 100644 src/map/itemdb.h delete mode 100644 src/map/lang.c delete mode 100644 src/map/lang.h delete mode 100644 src/map/mail.c delete mode 100644 src/map/mail.h delete mode 100644 src/map/map.c delete mode 100644 src/map/map.h delete mode 100644 src/map/mob.c delete mode 100644 src/map/mob.h delete mode 100644 src/map/npc.c delete mode 100644 src/map/npc.h delete mode 100644 src/map/parse.c delete mode 100644 src/map/parse.h delete mode 100644 src/map/pc.c delete mode 100644 src/map/pc.h delete mode 100644 src/map/permission.c delete mode 100644 src/map/permission.h delete mode 100644 src/map/quest.c delete mode 100644 src/map/quest.h delete mode 100644 src/map/script.c delete mode 100644 src/map/script.h delete mode 100644 src/map/scriptdefines.h delete mode 100644 src/map/send.c delete mode 100644 src/map/send.h delete mode 100644 src/map/skill.c delete mode 100644 src/map/skill.h delete mode 100644 src/map/status.c delete mode 100644 src/map/status.h delete mode 100644 src/map/struct/itemdext.h delete mode 100644 src/map/struct/mapdext.h delete mode 100644 src/map/struct/npcdext.h delete mode 100644 src/map/struct/sessionext.h delete mode 100644 src/map/unit.c delete mode 100644 src/map/unit.h delete mode 100644 src/map/utils/formatutils.c delete mode 100644 src/map/utils/formatutils.h diff --git a/src/Makefile.am b/src/Makefile.am index 19f8bcb..c26d169 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,93 +1,93 @@ AUTOMAKE_OPTIONS = subdir-objects -CHAR_SRC = char/char.c \ - char/char.h \ - char/config.c \ - char/config.h \ - char/init.c \ - common/config.c \ - common/config.h \ - common/init.c \ - common/init.h \ - common/ip.c \ - common/ip.h +CHAR_SRC = echar/char.c \ + echar/char.h \ + echar/config.c \ + echar/config.h \ + echar/init.c \ + ecommon/config.c \ + ecommon/config.h \ + ecommon/init.c \ + ecommon/init.h \ + ecommon/ip.c \ + ecommon/ip.h -LOGIN_SRC = login/config.c \ - login/config.h \ - login/init.c \ - login/login.c \ - login/login.h \ - login/md5calc.c \ - login/md5calc.h \ - login/mt_rand.c \ - login/mt_rand.h \ - login/parse.c \ - login/parse.h \ - login/send.c \ - login/send.h \ - common/config.c \ - common/config.h \ - common/init.c \ - common/init.h \ - common/ip.c \ - common/ip.h +LOGIN_SRC = elogin/config.c \ + elogin/config.h \ + elogin/init.c \ + elogin/login.c \ + elogin/login.h \ + elogin/md5calc.c \ + elogin/md5calc.h \ + elogin/mt_rand.c \ + elogin/mt_rand.h \ + elogin/parse.c \ + elogin/parse.h \ + elogin/send.c \ + elogin/send.h \ + ecommon/config.c \ + ecommon/config.h \ + ecommon/init.c \ + ecommon/init.h \ + ecommon/ip.c \ + ecommon/ip.h -MAP_SRC = map/atcommand.c \ - map/atcommand.h \ - map/clif.c \ - map/clif.h \ - map/init.c \ - map/itemdb.c \ - map/itemdb.h \ - map/lang.c \ - map/lang.h \ - map/mail.c \ - map/mail.h \ - map/map.c \ - map/map.h \ - map/mob.c \ - map/mob.h \ - map/npc.c \ - map/npc.h \ - map/parse.c \ - map/parse.h \ - map/pc.c \ - map/pc.h \ - map/permission.c \ - map/permission.h \ - map/quest.c \ - map/quest.h \ - map/script.c \ - map/script.h \ - map/scriptdefines.h \ - map/send.c \ - map/send.h \ - map/skill.c \ - map/skill.h \ - map/status.c \ - map/status.h \ - map/unit.c \ - map/unit.h \ - map/data/itemd.c \ - map/data/itemd.h \ - map/data/mapd.c \ - map/data/mapd.h \ - map/data/npcd.c \ - map/data/npcd.h \ - map/data/session.c \ - map/data/session.h \ - map/struct/itemdext.h \ - map/struct/mapdext.h \ - map/struct/npcdext.h \ - map/struct/sessionext.h \ - map/utils/formatutils.c \ - map/utils/formatutils.h \ - common/config.c \ - common/config.h \ - common/init.c \ - common/init.h +MAP_SRC = emap/atcommand.c \ + emap/atcommand.h \ + emap/clif.c \ + emap/clif.h \ + emap/init.c \ + emap/itemdb.c \ + emap/itemdb.h \ + emap/lang.c \ + emap/lang.h \ + emap/mail.c \ + emap/mail.h \ + emap/map.c \ + emap/map.h \ + emap/mob.c \ + emap/mob.h \ + emap/npc.c \ + emap/npc.h \ + emap/parse.c \ + emap/parse.h \ + emap/pc.c \ + emap/pc.h \ + emap/permission.c \ + emap/permission.h \ + emap/quest.c \ + emap/quest.h \ + emap/script.c \ + emap/script.h \ + emap/scriptdefines.h \ + emap/send.c \ + emap/send.h \ + emap/skill.c \ + emap/skill.h \ + emap/status.c \ + emap/status.h \ + emap/unit.c \ + emap/unit.h \ + emap/data/itemd.c \ + emap/data/itemd.h \ + emap/data/mapd.c \ + emap/data/mapd.h \ + emap/data/npcd.c \ + emap/data/npcd.h \ + emap/data/session.c \ + emap/data/session.h \ + emap/struct/itemdext.h \ + emap/struct/mapdext.h \ + emap/struct/npcdext.h \ + emap/struct/sessionext.h \ + emap/utils/formatutils.c \ + emap/utils/formatutils.h \ + ecommon/config.c \ + ecommon/config.h \ + ecommon/init.c \ + ecommon/init.h -SHARED_CFLAGS = -pipe -ffast-math -Wall -Wextra -Wno-sign-compare -DPCRE_SUPPORT +SHARED_CFLAGS = -pipe -ffast-math -Wall -Wextra -Wno-sign-compare -DPCRE_SUPPORT -I../../.. -I../../../../3rdparty SHARED_LDFLAGS = -avoid-version -Wl,--no-undefined if ENABLE_SANITIZE diff --git a/src/char/char.c b/src/char/char.c deleted file mode 100644 index dccc7ac..0000000 --- a/src/char/char.c +++ /dev/null @@ -1,191 +0,0 @@ -// 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 "common/ip.h" -#include "char/char.h" -#include "char/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/char/char.h b/src/char/char.h deleted file mode 100644 index b013f44..0000000 --- a/src/char/char.h +++ /dev/null @@ -1,19 +0,0 @@ -// 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/char/config.c b/src/char/config.c deleted file mode 100644 index 3454a74..0000000 --- a/src/char/config.c +++ /dev/null @@ -1,59 +0,0 @@ -// 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 "char/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/char/config.h b/src/char/config.h deleted file mode 100644 index d60abc0..0000000 --- a/src/char/config.h +++ /dev/null @@ -1,20 +0,0 @@ -// 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/char/init.c b/src/char/init.c deleted file mode 100644 index 6c8e34d..0000000 --- a/src/char/init.c +++ /dev/null @@ -1,96 +0,0 @@ -// 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 "common/config.h" -#include "common/init.h" -#include "char/char.h" -#include "char/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(); -} diff --git a/src/common/config.c b/src/common/config.c deleted file mode 100644 index 232b199..0000000 --- a/src/common/config.c +++ /dev/null @@ -1,38 +0,0 @@ -// 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 "common/config.h" - -const char *default_map = NULL; -int default_x = 0; -int default_y = 0; - -void config_default_map(const char *val) -{ - mapindex->default_map = aStrdup(val); -} - -void config_default_x(const char *val) -{ - mapindex->default_x = atoi(val); -} - -void config_default_y(const char *val) -{ - mapindex->default_y = atoi(val); -} - -void common_config_final(void) -{ -} diff --git a/src/common/config.h b/src/common/config.h deleted file mode 100644 index 9c24932..0000000 --- a/src/common/config.h +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. -// Copyright (c) 2014 Evol developers - -#ifndef EVOL_COMMON_CONFIG -#define EVOL_COMMON_CONFIG - -void config_default_map(const char *val); -void config_default_x(const char *val); -void config_default_y(const char *val); -void common_config_final(void); - -extern const char *default_map; -extern int default_x; -extern int default_y; - -#endif // EVOL_COMMON_CONFIG diff --git a/src/common/init.c b/src/common/init.c deleted file mode 100644 index 07bb936..0000000 --- a/src/common/init.c +++ /dev/null @@ -1,44 +0,0 @@ -// 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/conf.h" -#include "../../../common/malloc.h" -#include "../../../common/mapindex.h" -#include "../../../common/mmo.h" -#include "../../../common/socket.h" -#include "../../../common/strlib.h" -#include "../../../common/sysinfo.h" -#include "../../../common/timer.h" - -void interfaces_init_common(void) -{ - iMalloc = GET_SYMBOL("iMalloc"); - strlib = GET_SYMBOL("strlib"); - session = GET_SYMBOL("session"); - sockt = GET_SYMBOL("sockt"); - sv = GET_SYMBOL("sv"); - StrBuf = GET_SYMBOL("StrBuf"); - SQL = GET_SYMBOL("SQL"); - timer = GET_SYMBOL("timer"); - libconfig = GET_SYMBOL("libconfig"); - sysinfo = GET_SYMBOL("sysinfo"); - DB = GET_SYMBOL("DB"); -} - -void setDefaultMap(void) -{ - mapindex->default_map = aStrdup("000-1"); - mapindex->default_x = 80; - mapindex->default_y = 109; -} - -void commonClean(void) -{ - aFree(mapindex->default_map); - mapindex->default_map = NULL; -} diff --git a/src/common/init.h b/src/common/init.h deleted file mode 100644 index 41f844c..0000000 --- a/src/common/init.h +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. -// Copyright (c) 2014 Evol developers - -#ifndef EVOL_COMMON_INTERFACES -#define EVOL_COMMON_INTERFACES - -void interfaces_init_common(void); -void setDefaultMap(void); -void commonClean(void); - -#endif // EVOL_COMMON_INTERFACES diff --git a/src/common/ip.c b/src/common/ip.c deleted file mode 100644 index bad4b61..0000000 --- a/src/common/ip.c +++ /dev/null @@ -1,25 +0,0 @@ -// 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/ip.h" - -bool checkAllowedIp(const char* const mask, const char* const ip) -{ - char buf[1000]; - - strcpy(buf, ","); - strcat(buf, ip); - strcat(buf, ","); - - return strstr(mask, buf) != NULL; -} diff --git a/src/common/ip.h b/src/common/ip.h deleted file mode 100644 index 1b0ba18..0000000 --- a/src/common/ip.h +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. -// Copyright (c) 2014 Evol developers - -#ifndef EVOL_COMMON_IP -#define EVOL_COMMON_IP - -bool checkAllowedIp(const char* const mask, const char* const ip); - -#endif // EVOL_COMMON_IP 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(); +} diff --git a/src/ecommon/config.c b/src/ecommon/config.c new file mode 100644 index 0000000..0395dd7 --- /dev/null +++ b/src/ecommon/config.c @@ -0,0 +1,38 @@ +// 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 "ecommon/config.h" + +const char *default_map = NULL; +int default_x = 0; +int default_y = 0; + +void config_default_map(const char *val) +{ + mapindex->default_map = aStrdup(val); +} + +void config_default_x(const char *val) +{ + mapindex->default_x = atoi(val); +} + +void config_default_y(const char *val) +{ + mapindex->default_y = atoi(val); +} + +void common_config_final(void) +{ +} diff --git a/src/ecommon/config.h b/src/ecommon/config.h new file mode 100644 index 0000000..9c24932 --- /dev/null +++ b/src/ecommon/config.h @@ -0,0 +1,16 @@ +// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// Copyright (c) 2014 Evol developers + +#ifndef EVOL_COMMON_CONFIG +#define EVOL_COMMON_CONFIG + +void config_default_map(const char *val); +void config_default_x(const char *val); +void config_default_y(const char *val); +void common_config_final(void); + +extern const char *default_map; +extern int default_x; +extern int default_y; + +#endif // EVOL_COMMON_CONFIG diff --git a/src/ecommon/init.c b/src/ecommon/init.c new file mode 100644 index 0000000..d0304b2 --- /dev/null +++ b/src/ecommon/init.c @@ -0,0 +1,44 @@ +// 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/conf.h" +#include "common/malloc.h" +#include "common/mapindex.h" +#include "common/mmo.h" +#include "common/socket.h" +#include "common/strlib.h" +#include "common/sysinfo.h" +#include "common/timer.h" + +void interfaces_init_common(void) +{ + iMalloc = GET_SYMBOL("iMalloc"); + strlib = GET_SYMBOL("strlib"); + session = GET_SYMBOL("session"); + sockt = GET_SYMBOL("sockt"); + sv = GET_SYMBOL("sv"); + StrBuf = GET_SYMBOL("StrBuf"); + SQL = GET_SYMBOL("SQL"); + timer = GET_SYMBOL("timer"); + libconfig = GET_SYMBOL("libconfig"); + sysinfo = GET_SYMBOL("sysinfo"); + DB = GET_SYMBOL("DB"); +} + +void setDefaultMap(void) +{ + mapindex->default_map = aStrdup("000-1"); + mapindex->default_x = 80; + mapindex->default_y = 109; +} + +void commonClean(void) +{ + aFree(mapindex->default_map); + mapindex->default_map = NULL; +} diff --git a/src/ecommon/init.h b/src/ecommon/init.h new file mode 100644 index 0000000..41f844c --- /dev/null +++ b/src/ecommon/init.h @@ -0,0 +1,11 @@ +// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// Copyright (c) 2014 Evol developers + +#ifndef EVOL_COMMON_INTERFACES +#define EVOL_COMMON_INTERFACES + +void interfaces_init_common(void); +void setDefaultMap(void); +void commonClean(void); + +#endif // EVOL_COMMON_INTERFACES diff --git a/src/ecommon/ip.c b/src/ecommon/ip.c new file mode 100644 index 0000000..eb6d792 --- /dev/null +++ b/src/ecommon/ip.c @@ -0,0 +1,25 @@ +// 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 "ecommon/ip.h" + +bool checkAllowedIp(const char* const mask, const char* const ip) +{ + char buf[1000]; + + strcpy(buf, ","); + strcat(buf, ip); + strcat(buf, ","); + + return strstr(mask, buf) != NULL; +} diff --git a/src/ecommon/ip.h b/src/ecommon/ip.h new file mode 100644 index 0000000..1b0ba18 --- /dev/null +++ b/src/ecommon/ip.h @@ -0,0 +1,9 @@ +// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// Copyright (c) 2014 Evol developers + +#ifndef EVOL_COMMON_IP +#define EVOL_COMMON_IP + +bool checkAllowedIp(const char* const mask, const char* const ip); + +#endif // EVOL_COMMON_IP diff --git a/src/elogin/config.c b/src/elogin/config.c new file mode 100644 index 0000000..83c3c4f --- /dev/null +++ b/src/elogin/config.c @@ -0,0 +1,43 @@ +// 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 "elogin/config.h" + +char *update_server = NULL; +char *inter_server_ip = NULL; + +void config_update_server(const char *val) +{ + update_server = aStrdup(val); +} + +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_final(void) +{ + if (update_server) + aFree(update_server); + if (inter_server_ip) + aFree(inter_server_ip); +} diff --git a/src/elogin/config.h b/src/elogin/config.h new file mode 100644 index 0000000..ad63371 --- /dev/null +++ b/src/elogin/config.h @@ -0,0 +1,14 @@ +// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// Copyright (c) 2014 Evol developers + +#ifndef EVOL_LOGIN_CONFIG +#define EVOL_LOGIN_CONFIG + +void config_update_server(const char *val); +void config_final(void); +void config_inter_server_ip(const char *val); + +extern char *update_server; +extern char *inter_server_ip; + +#endif // EVOL_LOGIN_CONFIG diff --git a/src/elogin/init.c b/src/elogin/init.c new file mode 100644 index 0000000..6105b3b --- /dev/null +++ b/src/elogin/init.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 "login/login.h" + +#include "ecommon/init.h" +#include "elogin/config.h" +#include "elogin/login.h" +#include "elogin/parse.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_login", + SERVER_TYPE_LOGIN, + "0.1", + HPM_VERSION +}; + +HPExport void plugin_init (void) +{ + interfaces_init_common(); + + login = GET_SYMBOL("login"); + + addPacket(0x7530, 22, login_parse_version, hpParse_Login); + addPacket(0x027c, 95, elogin_parse_client_login2, hpParse_Login); + addPacket(0x5000, 54, elogin_parse_change_paassword, hpParse_FromChar); + addHookPre("login->parse_client_login", elogin_parse_client_login_pre); + addHookPre("login->parse_request_connection", elogin_parse_request_connection); + addHookPre("login->check_password", elogin_check_password); + addHookPre("login->parse_ping", elogin_parse_ping); +} + +HPExport void server_preinit (void) +{ + iMalloc = GET_SYMBOL("iMalloc"); + addLoginConf("update_server", config_update_server); + addLoginConf("inter_server_ip", config_inter_server_ip); +} + +HPExport void server_online (void) +{ +} + +HPExport void plugin_final (void) +{ + config_final(); +} diff --git a/src/elogin/login.c b/src/elogin/login.c new file mode 100644 index 0000000..3766a1e --- /dev/null +++ b/src/elogin/login.c @@ -0,0 +1,30 @@ +// 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 "login/login.h" + +#include "elogin/md5calc.h" + +bool elogin_check_password(const char* md5key __attribute__ ((unused)), + int *passwdenc __attribute__ ((unused)), + const char* passwd, + const char* refpass) +{ + if (!strcmp(passwd, refpass) || pass_ok(passwd, refpass)) + { + hookStop(); + return 1; + } + + hookStop(); + return 0; +} diff --git a/src/elogin/login.h b/src/elogin/login.h new file mode 100644 index 0000000..0783a5c --- /dev/null +++ b/src/elogin/login.h @@ -0,0 +1,9 @@ +// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// Copyright (c) 2014 Evol developers + +#ifndef EVOL_LOGIN_LOGIN +#define EVOL_LOGIN_LOGIN + +bool elogin_check_password(const char* md5key, int *passwdenc, const char* passwd, const char* refpass); + +#endif // EVOL_LOGIN_SEND diff --git a/src/elogin/md5calc.c b/src/elogin/md5calc.c new file mode 100644 index 0000000..bfa7b92 --- /dev/null +++ b/src/elogin/md5calc.c @@ -0,0 +1,406 @@ +// $Id: md5calc.c,v 1.1.1.1 2004/09/10 17:26:54 MagicalTux Exp $ +/*********************************************************** + * md5 calculation algorithm + * + * The source code referred to the following URL. + * http://www.geocities.co.jp/SiliconValley-Oakland/8878/lab17/lab17.html + * + ***********************************************************/ + +#include "md5calc.h" +#include +#include +#include "mt_rand.h" + +#ifndef UINT_MAX +#define UINT_MAX 4294967295U +#endif + +// Global variable +static unsigned int *pX; + +// Stirng Table +static const unsigned int T[] = { + 0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee, //0 + 0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501, //4 + 0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be, //8 + 0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821, //12 + 0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa, //16 + 0xd62f105d, 0x2441453, 0xd8a1e681, 0xe7d3fbc8, //20 + 0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed, //24 + 0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a, //28 + 0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c, //32 + 0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70, //36 + 0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x4881d05, //40 + 0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665, //44 + 0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039, //48 + 0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1, //52 + 0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1, //56 + 0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391 //60 +}; + +// ROTATE_LEFT The left is made to rotate x [ n-bit ]. This is diverted as it is from RFC. +#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) + +// The function used for other calculation +static unsigned int F (unsigned int X, unsigned int Y, unsigned int Z) +{ + return (X & Y) | (~X & Z); +} + +static unsigned int G (unsigned int X, unsigned int Y, unsigned int Z) +{ + return (X & Z) | (Y & ~Z); +} + +static unsigned int H (unsigned int X, unsigned int Y, unsigned int Z) +{ + return X ^ Y ^ Z; +} + +static unsigned int I (unsigned int X, unsigned int Y, unsigned int Z) +{ + return Y ^ (X | ~Z); +} + +static unsigned int Round (unsigned int a, unsigned int b, unsigned int FGHI, + unsigned int k, unsigned int s, unsigned int i) +{ + return b + ROTATE_LEFT (a + FGHI + pX[k] + T[i], s); +} + +static void Round1 (unsigned int *a, unsigned int b, unsigned int c, + unsigned int d, unsigned int k, unsigned int s, + unsigned int i) +{ + *a = Round (*a, b, F (b, c, d), k, s, i); +} + +static void Round2 (unsigned int *a, unsigned int b, unsigned int c, + unsigned int d, unsigned int k, unsigned int s, + unsigned int i) +{ + *a = Round (*a, b, G (b, c, d), k, s, i); +} + +static void Round3 (unsigned int *a, unsigned int b, unsigned int c, + unsigned int d, unsigned int k, unsigned int s, + unsigned int i) +{ + *a = Round (*a, b, H (b, c, d), k, s, i); +} + +static void Round4 (unsigned int *a, unsigned int b, unsigned int c, + unsigned int d, unsigned int k, unsigned int s, + unsigned int i) +{ + *a = Round (*a, b, I (b, c, d), k, s, i); +} + +static void MD5_Round_Calculate (const unsigned char *block, + unsigned int *A2, unsigned int *B2, + unsigned int *C2, unsigned int *D2) +{ + //create X It is since it is required. + unsigned int X[16]; //512bit 64byte + int j, k; + + //Save A as AA, B as BB, C as CC, and and D as DD (saving of A, B, C, and D) + unsigned int A = *A2, B = *B2, C = *C2, D = *D2; + unsigned int AA = A, BB = B, CC = C, DD = D; + + //It is a large region variable reluctantly because of calculation of a round. . . for Round1...4 + pX = X; + + //Copy block(padding_message) i into X + for (j = 0, k = 0; j < 64; j += 4, k++) + X[k] = ((unsigned int) block[j]) // 8byte*4 -> 32byte conversion + | (((unsigned int) block[j + 1]) << 8) // A function called Decode as used in the field of RFC + | (((unsigned int) block[j + 2]) << 16) + | (((unsigned int) block[j + 3]) << 24); + + //Round 1 + Round1 (&A, B, C, D, 0, 7, 0); + Round1 (&D, A, B, C, 1, 12, 1); + Round1 (&C, D, A, B, 2, 17, 2); + Round1 (&B, C, D, A, 3, 22, 3); + Round1 (&A, B, C, D, 4, 7, 4); + Round1 (&D, A, B, C, 5, 12, 5); + Round1 (&C, D, A, B, 6, 17, 6); + Round1 (&B, C, D, A, 7, 22, 7); + Round1 (&A, B, C, D, 8, 7, 8); + Round1 (&D, A, B, C, 9, 12, 9); + Round1 (&C, D, A, B, 10, 17, 10); + Round1 (&B, C, D, A, 11, 22, 11); + Round1 (&A, B, C, D, 12, 7, 12); + Round1 (&D, A, B, C, 13, 12, 13); + Round1 (&C, D, A, B, 14, 17, 14); + Round1 (&B, C, D, A, 15, 22, 15); + + //Round 2 + Round2 (&A, B, C, D, 1, 5, 16); + Round2 (&D, A, B, C, 6, 9, 17); + Round2 (&C, D, A, B, 11, 14, 18); + Round2 (&B, C, D, A, 0, 20, 19); + Round2 (&A, B, C, D, 5, 5, 20); + Round2 (&D, A, B, C, 10, 9, 21); + Round2 (&C, D, A, B, 15, 14, 22); + Round2 (&B, C, D, A, 4, 20, 23); + Round2 (&A, B, C, D, 9, 5, 24); + Round2 (&D, A, B, C, 14, 9, 25); + Round2 (&C, D, A, B, 3, 14, 26); + Round2 (&B, C, D, A, 8, 20, 27); + Round2 (&A, B, C, D, 13, 5, 28); + Round2 (&D, A, B, C, 2, 9, 29); + Round2 (&C, D, A, B, 7, 14, 30); + Round2 (&B, C, D, A, 12, 20, 31); + + //Round 3 + Round3 (&A, B, C, D, 5, 4, 32); + Round3 (&D, A, B, C, 8, 11, 33); + Round3 (&C, D, A, B, 11, 16, 34); + Round3 (&B, C, D, A, 14, 23, 35); + Round3 (&A, B, C, D, 1, 4, 36); + Round3 (&D, A, B, C, 4, 11, 37); + Round3 (&C, D, A, B, 7, 16, 38); + Round3 (&B, C, D, A, 10, 23, 39); + Round3 (&A, B, C, D, 13, 4, 40); + Round3 (&D, A, B, C, 0, 11, 41); + Round3 (&C, D, A, B, 3, 16, 42); + Round3 (&B, C, D, A, 6, 23, 43); + Round3 (&A, B, C, D, 9, 4, 44); + Round3 (&D, A, B, C, 12, 11, 45); + Round3 (&C, D, A, B, 15, 16, 46); + Round3 (&B, C, D, A, 2, 23, 47); + + //Round 4 + Round4 (&A, B, C, D, 0, 6, 48); + Round4 (&D, A, B, C, 7, 10, 49); + Round4 (&C, D, A, B, 14, 15, 50); + Round4 (&B, C, D, A, 5, 21, 51); + Round4 (&A, B, C, D, 12, 6, 52); + Round4 (&D, A, B, C, 3, 10, 53); + Round4 (&C, D, A, B, 10, 15, 54); + Round4 (&B, C, D, A, 1, 21, 55); + Round4 (&A, B, C, D, 8, 6, 56); + Round4 (&D, A, B, C, 15, 10, 57); + Round4 (&C, D, A, B, 6, 15, 58); + Round4 (&B, C, D, A, 13, 21, 59); + Round4 (&A, B, C, D, 4, 6, 60); + Round4 (&D, A, B, C, 11, 10, 61); + Round4 (&C, D, A, B, 2, 15, 62); + Round4 (&B, C, D, A, 9, 21, 63); + + // Then perform the following additions. (let's add) + *A2 = A + AA; + *B2 = B + BB; + *C2 = C + CC; + *D2 = D + DD; + + //The clearance of confidential information + memset (pX, 0, sizeof (X)); +} + +//------------------------------------------------------------------- +// The function for the exteriors + +/** output is the coded binary in the character sequence which wants to code string. */ +void MD5_String2binary (const char *string, char *output) +{ + if (!output) + return; + if (!string) + { + *output=0; + return; + } +//var + /*8bit */ + unsigned char padding_message[64]; //Extended message 512bit 64byte + unsigned char *pstring; //The position of string in the present scanning notes is held. + +// unsigned char digest[16]; + /*32bit */ + unsigned int string_byte_len, //The byte chief of string is held. + string_bit_len, //The bit length of string is held. + copy_len, //The number of bytes which is used by 1-3 and which remained + msg_digest[4]; //Message digest 128bit 4byte + unsigned int *A = &msg_digest[0], //The message digest in accordance with RFC (reference) + *B = &msg_digest[1], *C = &msg_digest[2], *D = &msg_digest[3]; + int i; + +//prog + //Step 3.Initialize MD Buffer (although it is the initialization; step 3 of A, B, C, and D -- unavoidable -- a head) + *A = 0x67452301; + *B = 0xefcdab89; + *C = 0x98badcfe; + *D = 0x10325476; + + //Step 1.Append Padding Bits (extension of a mark bit) + //1-1 + string_byte_len = strlen (string); //The byte chief of a character sequence is acquired. + pstring = (unsigned char *) string; //The position of the present character sequence is set. + + //1-2 Repeat calculation until length becomes less than 64 bytes. + for (i = string_byte_len; 64 <= i; i -= 64, pstring += 64) + MD5_Round_Calculate (pstring, A, B, C, D); + + //1-3 + copy_len = string_byte_len % 64; //The number of bytes which remained is computed. + strncpy ((char *) padding_message, (char *) pstring, copy_len); //A message is copied to an extended bit sequence. + memset (padding_message + copy_len, 0, 64 - copy_len); //It buries by 0 until it becomes extended bit length. + padding_message[copy_len] |= 0x80; //The next of a message is 1. + + //1-4 + //If 56 bytes or more (less than 64 bytes) of remainder becomes, it will calculate by extending to 64 bytes. + if (56 <= copy_len) + { + MD5_Round_Calculate (padding_message, A, B, C, D); + memset (padding_message, 0, 56); //56 bytes is newly fill uped with 0. + } + + //Step 2.Append Length (the information on length is added) + string_bit_len = string_byte_len * 8; //From the byte chief to bit length (32 bytes of low rank) + memcpy (&padding_message[56], &string_bit_len, 4); //32 bytes of low rank is set. + + //When bit length cannot be expressed in 32 bytes of low rank, it is a beam raising to a higher rank. + if (UINT_MAX / 8 < string_byte_len) + { + unsigned int high = (string_byte_len - UINT_MAX / 8) * 8; + memcpy (&padding_message[60], &high, 4); + } + else + memset (&padding_message[60], 0, 4); //In this case, it is good for a higher rank at 0. + + //Step 4.Process Message in 16-Word Blocks (calculation of MD5) + MD5_Round_Calculate (padding_message, A, B, C, D); + + //Step 5.Output (output) + memcpy (output, msg_digest, 16); +// memcpy (digest, msg_digest, and 16); //8 byte*4 < - 32byte conversion A function called Encode as used in the field of RFC +/* sprintf(output, + "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", + digest[ 0], digest[ 1], digest[ 2], digest[ 3], + digest[ 4], digest[ 5], digest[ 6], digest[ 7], + digest[ 8], digest[ 9], digest[10], digest[11], + digest[12], digest[13], digest[14], digest[15]);*/ +} + +/** output is the coded character sequence in the character sequence which wants to code string. */ +void MD5_String (const char *string, char *output) +{ + if (!output) + return; + if (!string) + { + *output=0; + return; + } + unsigned char digest[16]; + + MD5_String2binary (string, (char *)digest); + sprintf (output, + "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", + digest[0], digest[1], digest[2], digest[3], + digest[4], digest[5], digest[6], digest[7], + digest[8], digest[9], digest[10], digest[11], + digest[12], digest[13], digest[14], digest[15]); +} + +// Hash a password with a salt. +char *MD5_saltcrypt(const char *key, const char *salt) +{ + if (!salt) + return 0; + + char buf[66], *sbuf = buf+32; + static char obuf[33]; + + // hash the key then the salt + // buf ends up as a 64char null terminated string + MD5_String(key, buf); + MD5_String(salt, sbuf); + + // Hash the buffer back into sbuf + MD5_String(buf, sbuf); + + snprintf(obuf, 32, "!%s$%s", salt, sbuf); + return(obuf); +} + +char *make_salt(void) +{ + static char salt[6]; + int i; + for (i=0; i<5; i++) + salt[i] = (char)((mt_rand() % 78) + 48); + salt[5] = '\0'; + return(salt); +} + +int pass_ok(const char *password, const char *crypted) +{ + if (!password || !crypted) + return 0; + + char buf[40], *salt=buf+1; + + strncpy(buf, crypted, 40); + buf[39] = 0; + char *ptr = strchr(buf, '$'); + if (ptr) + { + *ptr = '\0'; + + if (!strcmp(crypted, MD5_saltcrypt(password, salt))) + return(1); + } + else + { + //++ may be here need compare non encripted passwords? +// if (!strcmp(crypted, password)) +// return(1); + } + + return(0); +} + +// [M|h]ashes up an IP address and a secret key +// to return a hopefully unique masked IP. +in_addr_t MD5_ip(char *secret, in_addr_t ip) +{ + char ipbuf[32]; + char obuf[16]; + union { + struct bytes { + unsigned char b1; + unsigned char b2; + unsigned char b3; + unsigned char b4; + } bytes; + in_addr_t ip; + } conv; + + if (!secret) + { + conv.bytes.b1 = 0; + conv.bytes.b2 = 0; + conv.bytes.b3 = 0; + conv.bytes.b4 = 0; + return conv.ip; + } + + // MD5sum a secret + the IP address + memset(&ipbuf, 0, sizeof(ipbuf)); + snprintf(ipbuf, sizeof(ipbuf), "%lu%s", (unsigned long)ip, secret); + MD5_String2binary(ipbuf, obuf); + + // Fold the md5sum to 32 bits, pack the bytes to an in_addr_t + conv.bytes.b1 = obuf[0] ^ obuf[1] ^ obuf[8] ^ obuf[9]; + conv.bytes.b2 = obuf[2] ^ obuf[3] ^ obuf[10] ^ obuf[11]; + conv.bytes.b3 = obuf[4] ^ obuf[5] ^ obuf[12] ^ obuf[13]; + conv.bytes.b4 = obuf[6] ^ obuf[7] ^ obuf[14] ^ obuf[15]; + + return conv.ip; +} + diff --git a/src/elogin/md5calc.h b/src/elogin/md5calc.h new file mode 100644 index 0000000..cf82738 --- /dev/null +++ b/src/elogin/md5calc.h @@ -0,0 +1,13 @@ +// $Id: md5calc.h,v 1.1.1.1 2004/09/10 17:26:54 MagicalTux Exp $ +#ifndef _MD5CALC_H_ +#define _MD5CALC_H_ +#include + +void MD5_String (const char *string, char *output); +void MD5_String2binary (const char *string, char *output); +char *MD5_saltcrypt(const char *key, const char *salt); +char *make_salt(void); +int pass_ok(const char *password, const char *crypted); +in_addr_t MD5_ip(char *secret, in_addr_t ip); + +#endif diff --git a/src/elogin/mt_rand.c b/src/elogin/mt_rand.c new file mode 100644 index 0000000..627d9dd --- /dev/null +++ b/src/elogin/mt_rand.c @@ -0,0 +1,118 @@ +/* +// This is the ``Mersenne Twister'' random number generator MT19937, which +// generates pseudorandom integers uniformly distributed in 0..(2^32 - 1) +// starting from any odd seed in 0..(2^32 - 1). This version is a recode +// by Shawn Cokus (Cokus@math.washington.edu) on March 8, 1998 of a version by +// Takuji Nishimura (who had suggestions from Topher Cooper and Marc Rieffel in +// July-August 1997). +// +// Effectiveness of the recoding (on Goedel2.math.washington.edu, a DEC Alpha +// running OSF/1) using GCC -O3 as a compiler: before recoding: 51.6 sec. to +// generate 300 million random numbers; after recoding: 24.0 sec. for the same +// (i.e., 46.5% of original time), so speed is now about 12.5 million random +// number generations per second on this machine. +// +// According to the URL +// (and paraphrasing a bit in places), the Mersenne Twister is ``designed +// with consideration of the flaws of various existing generators,'' has +// a period of 2^19937 - 1, gives a sequence that is 623-dimensionally +// equidistributed, and ``has passed many stringent tests, including the +// die-hard test of G. Marsaglia and the load test of P. Hellekalek and +// S. Wegenkittl.'' It is efficient in memory usage (typically using 2506 +// to 5012 bytes of static data, depending on data type sizes, and the code +// is quite short as well). It generates random numbers in batches of 624 +// at a time, so the caching and pipelining of modern systems is exploited. +// It is also divide- and mod-free. +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Library General Public License as published by +// the Free Software Foundation (either version 2 of the License or, at your +// option, any later version). This library is distributed in the hope that +// it will be useful, but WITHOUT ANY WARRANTY, without even the implied +// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +// the GNU Library General Public License for more details. You should have +// received a copy of the GNU Library General Public License along with this +// library; if not, write to the Free Software Foundation, Inc., 59 Temple +// Place, Suite 330, Boston, MA 02111-1307, USA. +// +// The code as Shawn received it included the following notice: +// +// Copyright (C) 1997 Makoto Matsumoto and Takuji Nishimura. When +// you use this, send an e-mail to with +// an appropriate reference to your work. +// +// It would be nice to CC: when you write. +// +*/ + +#include +#include "mt_rand.h" + +#define N (624) /* length of state vector */ +#define M (397) /* a period parameter */ +#define K (0x9908B0DFU) /* a magic constant */ +#define hiBit(u) ((u) & 0x80000000U) /* mask all but highest bit of u */ +#define loBit(u) ((u) & 0x00000001U) /* mask all but lowest bit of u */ +#define loBits(u) ((u) & 0x7FFFFFFFU) /* mask the highest bit of u */ +#define mixBits(u, v) (hiBit(u)|loBits(v)) /* move hi bit of u to hi bit of v */ + +static unsigned long state[N + 1]; /* state vector + 1 extra to not violate ANSI C */ +static unsigned long *next; /* next random value is computed from here */ +static int left = -1; /* can *next++ this many times before reloading */ + +void mt_seed (unsigned long seed) +{ + register unsigned long x = (seed | 1U) & 0xFFFFFFFFU, *s = state; + register int j; + + for (left = 0, *s++ = x, j = N; --j; *s++ = (x *= 69069U) & 0xFFFFFFFFU); +} + +unsigned long mt_reload (void) +{ + register unsigned long *p0 = state, *p2 = state + 2, *pM = + state + M, s0, s1; + register int j; + + if (left < -1) + mt_seed (time (NULL)); + + left = N - 1, next = state + 1; + + for (s0 = state[0], s1 = state[1], j = N - M + 1; --j; + s0 = s1, s1 = *p2++) + *p0++ = *pM++ ^ (mixBits (s0, s1) >> 1) ^ (loBit (s1) ? K : 0U); + + for (pM = state, j = M; --j; s0 = s1, s1 = *p2++) + *p0++ = *pM++ ^ (mixBits (s0, s1) >> 1) ^ (loBit (s1) ? K : 0U); + + s1 = state[0], *p0 = + *pM ^ (mixBits (s0, s1) >> 1) ^ (loBit (s1) ? K : 0U); + s1 ^= (s1 >> 11); + s1 ^= (s1 << 7) & 0x9D2C5680U; + s1 ^= (s1 << 15) & 0xEFC60000U; + return (s1 ^ (s1 >> 18)); +} + +unsigned long mt_random (void) +{ + unsigned long y; + + if (--left < 0) + return (mt_reload ()); + + y = *next++; + y ^= (y >> 11); + y ^= (y << 7) & 0x9D2C5680U; + y ^= (y << 15) & 0xEFC60000U; + return (y ^ (y >> 18)); +} + +int mt_rand (void) +{ + unsigned long r = mt_random (); + while (r >> 16) + r = (r & 0xFFFF) + (r >> 16); + + return (r); +} diff --git a/src/elogin/mt_rand.h b/src/elogin/mt_rand.h new file mode 100644 index 0000000..d798fee --- /dev/null +++ b/src/elogin/mt_rand.h @@ -0,0 +1,9 @@ +#ifndef __mt_rand_h +#define __mt_rand_h + +void mt_seed (unsigned long seed); +unsigned long mt_reload (void); +unsigned long mt_random (void); +int mt_rand (void); + +#endif /* __mt_rand_h */ diff --git a/src/elogin/parse.c b/src/elogin/parse.c new file mode 100644 index 0000000..8f62e9f --- /dev/null +++ b/src/elogin/parse.c @@ -0,0 +1,210 @@ +// 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 "login/account.h" +#include "login/login.h" + +#include "ecommon/ip.h" +#include "elogin/config.h" +#include "elogin/md5calc.h" +#include "elogin/parse.h" +#include "elogin/send.h" + +int clientVersion = 0; + +void login_parse_version(int fd) +{ + struct login_session_data* sd = (struct login_session_data*)session[fd]->session_data; + if (!sd) + return; + + clientVersion = RFIFOL(fd, 2); + + if (clientVersion < 2) + { + login->login_error(fd, 5); + return; + } + + send_update_host(fd); + send_server_version(fd); +} + +int elogin_parse_client_login_pre(int *fdPtr, + struct login_session_data* sd __attribute__ ((unused)), + const char *const ip __attribute__ ((unused))) +{ + int fd = *fdPtr; + uint16 command = RFIFOW(fd,0); + if (command != 0x64) + { + login->login_error(fd, 3); + hookStop(); + return 1; + } + char username[NAME_LENGTH]; + safestrncpy(username, (const char*)RFIFOP(fd, 6), NAME_LENGTH); + int len = strnlen(username, NAME_LENGTH); + if (clientVersion < 2) + { + login->login_error(fd, 5); + hookStop(); + return 1; + } + else if (len >= 2 && username[len - 2] == '_' && memchr("FfMm", username[len - 1], 4)) + { + login->login_error(fd, 3); + hookStop(); + return 1; + } + + return 0; +} + +void elogin_parse_client_login2(int fd) +{ + char username[NAME_LENGTH]; + char password[PASSWD_LEN]; + char email[40]; + uint8 clienttype; + int result; + + safestrncpy(username, (const char*)RFIFOP(fd, 2), NAME_LENGTH); + + int len = strnlen(username, NAME_LENGTH); + if (len < 2 || !(username[len - 2] == '_') || !memchr("FfMm", username[len - 1], 4)) + { + login->login_error(fd, 3); + return; + } + + safestrncpy(password, (const char*)RFIFOP(fd, 26), NAME_LENGTH); + safestrncpy(email, (const char*)RFIFOP(fd, 51), 40); + clienttype = RFIFOB(fd, 50); + + struct login_session_data* sd = (struct login_session_data*)session[fd]->session_data; + if (!sd) + return; + + char ip[16]; + uint32 ipl = session[fd]->client_addr; + ip2str(ipl, ip); + sd->clienttype = clienttype; + sd->version = clientVersion; + sd->passwdenc = 0; + safestrncpy(sd->userid, username, NAME_LENGTH); + ShowStatus("Request for connection of %s (ip: %s).\n", sd->userid, ip); + safestrncpy(sd->passwd, password, PASSWD_LEN); + + if (e_mail_check(email) == 0) + { + ShowNotice("Attempt to create an e-mail REFUSED - e-mail is invalid (ip: %s)\n", ip); + login->login_error(fd, 11); + return; + } + + result = login->mmo_auth(sd, false); + + if (result == -1) + { + int account_id = sd->account_id; + struct mmo_account acc; + if (!login->accounts->load_num(login->accounts, &acc, account_id)) + { + ShowNotice("Attempt to create an e-mail on an account REFUSED - account: %d, ip: %s).\n", account_id, ip); + } + else + { + memcpy(acc.email, email, 40); + ShowNotice("Create an e-mail on an account with a default e-mail (account: %d, new e-mail: %s, ip: %s).\n", account_id, email, ip); + // Save + login->accounts->save(login->accounts, &acc); + } + + login->auth_ok(sd); + } + else + { + login->auth_failed(sd, result); + } + + return; +} + +void elogin_parse_request_connection(int *fd, struct login_session_data* sd, const char *const ip) +{ + if (!inter_server_ip || !ip) + return; + if (!checkAllowedIp(inter_server_ip, ip)) + { + hookStop(); + login->char_server_connection_status(*fd, sd, 3); + ShowNotice("Connection of the char-server from ip %s REFUSED.\n", ip); + } +} + +void elogin_parse_ping(int *fd, struct login_session_data* sd) +{ + RFIFOSKIP(*fd, 26); + if (!sd) + { + hookStop(); + return; + } + struct online_login_data* data = (struct online_login_data*)idb_get(login->online_db, sd->account_id); + if (data == NULL) + { + hookStop(); + return; + } + if (data->waiting_disconnect != INVALID_TIMER) + { + timer->delete(data->waiting_disconnect, login->waiting_disconnect_timer); + data->waiting_disconnect = timer->add(timer->gettick() + 30000, login->waiting_disconnect_timer, sd->account_id, 0); + } + hookStop(); +} + +void elogin_parse_change_paassword(int fd) +{ + char actual_pass[24], new_pass[24]; + int status = 0; + struct mmo_account acc; + const int accountId = RFIFOL (fd, 2); + + memcpy (actual_pass, RFIFOP (fd, 6), 24); + actual_pass[23] = '\0'; + memcpy (new_pass, RFIFOP (fd, 30), 24); + new_pass[23] = '\0'; + + if (!login->accounts->load_num(login->accounts, &acc, accountId)) + { + // account not found + send_char_password_change_ack(fd, accountId, 0); + return; + } + + if (!strcmp(actual_pass, acc.pass) || pass_ok(actual_pass, acc.pass)) + { + // changed ok + status = 1; + safestrncpy(acc.pass, new_pass, sizeof(acc.pass)); + login->accounts->save(login->accounts, &acc); + } + else + { + // wrong password + status = 2; + } + send_char_password_change_ack(fd, accountId, status); +} diff --git a/src/elogin/parse.h b/src/elogin/parse.h new file mode 100644 index 0000000..b5c2418 --- /dev/null +++ b/src/elogin/parse.h @@ -0,0 +1,14 @@ +// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// Copyright (c) 2014 Evol developers + +#ifndef EVOL_LOGIN_PARSE +#define EVOL_LOGIN_PARSE + +void login_parse_version(int fd); +int elogin_parse_client_login_pre(int *fd, struct login_session_data* sd, const char *const ip); +void elogin_parse_client_login2(int fd); +void elogin_parse_request_connection(int *fd, struct login_session_data* sd, const char *const ip); +void elogin_parse_ping(int *fd, struct login_session_data* sd); +void elogin_parse_change_paassword(int fd); + +#endif // EVOL_LOGIN_PARSE diff --git a/src/elogin/send.c b/src/elogin/send.c new file mode 100644 index 0000000..396c314 --- /dev/null +++ b/src/elogin/send.c @@ -0,0 +1,47 @@ +// 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 "login/login.h" + +#include "elogin/config.h" +#include "elogin/send.h" + +void send_server_version(int fd) +{ + WFIFOHEAD(fd, 4 + 8); + WFIFOW(fd, 0) = 0x7531; + WFIFOW(fd, 2) = 4 + 8; + WFIFOL(fd, 4) = 0; // unused + WFIFOL(fd, 8) = 6; // server version + WFIFOSET(fd, WFIFOW(fd,2)); +} + +void send_update_host(int fd) +{ + if (!update_server) + return; + const int sz = strlen(update_server); + WFIFOHEAD(fd, sz + 4); + WFIFOW(fd, 0) = 0x63; + WFIFOW(fd, 2) = sz + 4; + memcpy(WFIFOP (fd, 4), update_server, sz); + WFIFOSET(fd, sz + 4); +} + +void send_char_password_change_ack(int fd, int accoundId, char status) +{ + WFIFOHEAD(fd, 7); + WFIFOW(fd, 0) = 0x5001; + WFIFOL(fd, 2) = accoundId; + WFIFOB(fd, 6) = status; + WFIFOSET(fd, 7); +} diff --git a/src/elogin/send.h b/src/elogin/send.h new file mode 100644 index 0000000..5fdb6c4 --- /dev/null +++ b/src/elogin/send.h @@ -0,0 +1,11 @@ +// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// Copyright (c) 2014 Evol developers + +#ifndef EVOL_LOGIN_SEND +#define EVOL_LOGIN_SEND + +void send_server_version(); +void send_update_host(int fd); +void send_char_password_change_ack(int fd, int accoundId, char status); + +#endif // EVOL_LOGIN_SEND diff --git a/src/emap/atcommand.c b/src/emap/atcommand.c new file mode 100644 index 0000000..c697b22 --- /dev/null +++ b/src/emap/atcommand.c @@ -0,0 +1,84 @@ +// 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 "map/atcommand.h" +#include "map/clif.h" +#include "map/map.h" +#include "map/pc.h" +#include "map/skill.h" +#include "emap/atcommand.h" +#include "emap/lang.h" + +const char* eatcommand_msgsd(struct map_session_data *sd, int *msgPtr) +{ + const int msg_number = *msgPtr; + if (!(msg_number >= 0 && msg_number < MAX_MSG)) + { + hookStop(); + return "??"; + } + if (*msgPtr == 1435) + { + hookStop(); + // service message, must be not translated + return "You're now in the '#%s' channel for '%s'"; + } + else if (*msgPtr == 1403) + { + hookStop(); + // service message, must be not translated + return "You're now in the '#%s' channel for '-'"; + } + hookStop(); + return lang_pctrans(atcommand->msg_table[0][msg_number], sd); +} + +const char* eatcommand_msgfd(int *fdPtr, int *msgPtr) +{ + const int msg_number = *msgPtr; + const int fd = *fdPtr; + struct map_session_data *sd = session_isValid(fd) ? session[fd]->session_data : NULL; + if (!(msg_number >= 0 && msg_number < MAX_MSG)) + { + hookStop(); + return "??"; + } + hookStop(); + return lang_pctrans(atcommand->msg_table[0][msg_number], sd); +} + +ACMD2(setSkill) +{ + int skill_id = 0; + int skill_level = 0; + + if (!message || !*message || sscanf(message, "%5d %2d", &skill_id, &skill_level) < 2) + { + const char* text = info->help; + + if (text) + clif->messageln (fd, text); + + return false; + } + if (!skill->get_index(skill_id)) + { + clif->message(fd, msg_fd(fd,198)); // This skill number doesn't exist. + return false; + } + + pc->skill(sd, skill_id, skill_level, 0); + clif->message(fd, msg_fd(fd,70)); // You have learned the skill. + + return true; +} diff --git a/src/emap/atcommand.h b/src/emap/atcommand.h new file mode 100644 index 0000000..ab970c6 --- /dev/null +++ b/src/emap/atcommand.h @@ -0,0 +1,14 @@ +// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// Copyright (c) 2014 Evol developers + +#ifndef EVOL_MAP_ATCOMMAND +#define EVOL_MAP_ATCOMMAND + +const char* eatcommand_msgsd(struct map_session_data *sd, int *msgPtr); +const char* eatcommand_msgfd(int *fdPtr, int *msgPtr); + +#define ACMD2(x) bool atcommand_ ## x (const int fd, struct map_session_data* sd, const char* command __attribute__ ((unused)), const char* message, struct AtCommandInfo *info) + +ACMD2(setSkill); + +#endif // EVOL_MAP_ATCOMMAND diff --git a/src/emap/clif.c b/src/emap/clif.c new file mode 100644 index 0000000..7651f09 --- /dev/null +++ b/src/emap/clif.c @@ -0,0 +1,377 @@ +// 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/cbasetypes.h" +#include "map/guild.h" +#include "map/mob.h" +#include "map/npc.h" +#include "map/pc.h" +#include "map/quest.h" + +#include "emap/clif.h" +#include "emap/lang.h" +#include "emap/send.h" +#include "emap/data/mapd.h" +#include "emap/data/session.h" +#include "emap/struct/mapdext.h" +#include "emap/struct/sessionext.h" + +void eclif_quest_send_list(TBL_PC *sd) +{ + if (!sd) + { + hookStop(); + return; + } + + int fd = sd->fd; + int i; + int info_len = 15; + int len = sd->avail_quests * info_len + 8; + WFIFOHEAD(fd,len); + WFIFOW(fd, 0) = 0x97a; + WFIFOW(fd, 2) = len; + WFIFOL(fd, 4) = sd->avail_quests; + + for (i = 0; i < sd->avail_quests; i++ ) + { + struct quest_db *qi = quest->db(sd->quest_log[i].quest_id); + if (!qi) + continue; + WFIFOL(fd, i * info_len + 8) = sd->quest_log[i].quest_id; + WFIFOB(fd, i * info_len + 12) = sd->quest_log[i].count[0]; // was state + WFIFOL(fd, i * info_len + 13) = sd->quest_log[i].time - qi->time; + WFIFOL(fd, i * info_len + 17) = sd->quest_log[i].time; + WFIFOW(fd, i * info_len + 21) = 0; + } + + WFIFOSET(fd, len); + hookStop(); +} + +void eclif_quest_add(TBL_PC *sd, struct quest *qd) +{ + if (!sd) + { + hookStop(); + return; + } + int fd = sd->fd; + struct quest_db *qi = quest->db(qd->quest_id); + + if (!qi) + { + hookStop(); + return; + } + + WFIFOHEAD(fd, 107); + WFIFOW(fd, 0) = 0x2b3; + WFIFOL(fd, 2) = qd->quest_id; + WFIFOB(fd, 6) = qd->count[0]; // was state; + WFIFOB(fd, 7) = qd->time - qi->time; + WFIFOL(fd, 11) = qd->time; + WFIFOW(fd, 15) = 0; + WFIFOSET(fd, 107); + hookStop(); +} + +void eclif_charnameack(int *fdPtr, struct block_list *bl) +{ + if (!bl) + { + hookStop(); + return; + } + if (bl->type == BL_NPC) + { + int fd = *fdPtr; + TBL_PC* sd = (TBL_PC*)session[fd]->session_data; + if (!sd) + { + hookStop(); + return; + } + const char *tr = lang_pctrans(((TBL_NPC*)bl)->name, sd); + const int trLen = strlen(tr); + const int len = 8 + trLen; + // if no recipient specified just update nearby clients + if (fd == 0) + { + char *buf; + CREATE(buf, char, len); + WBUFW(buf, 0) = 0xB01; + WBUFW(buf, 2) = len; + WBUFL(buf, 4) = bl->id; + memcpy(WBUFP(buf, 8), tr, trLen); + clif->send(buf, len, bl, AREA); + aFree(buf); + } + else + { + WFIFOHEAD(fd, len); + WFIFOW(fd, 0) = 0xB01; + WFIFOW(fd, 2) = len; + WFIFOL(fd, 4) = bl->id; + memcpy(WFIFOP(fd, 8), tr, trLen); + WFIFOSET(fd, len); + } + hookStop(); + } + else if (bl->type == BL_MOB) + { + struct mob_data *md = (struct mob_data *)bl; + if (!md) + { + hookStop(); + return; + } + if (md->guardian_data && md->guardian_data->g) + return; // allow default code to work + int fd = *fdPtr; + TBL_PC* sd = (TBL_PC*)session[fd]->session_data; + if (!sd) + { + hookStop(); + return; + } + + char tmpBuf[25]; + char *ptr = tmpBuf; + int f; + memcpy(tmpBuf, md->name, 24); + tmpBuf[24] = 0; + for (f = 23; f > 1; f --) + { + if (tmpBuf[f] == ' ') + tmpBuf[f] = 0; + else + break; + } + for (f = 0; f < 24; f ++) + { + if (*ptr == ' ') + ptr ++; + else + break; + } + const char *tr = lang_pctrans(ptr, sd); + const int trLen = strlen(tr); + const int len = 8 + trLen; + + // if no recipient specified just update nearby clients + if (fd == 0) + { + char *buf; + CREATE(buf, char, len); + WBUFW(buf, 0) = 0xB01; + WBUFW(buf, 2) = len; + WBUFL(buf, 4) = bl->id; + memcpy(WBUFP(buf, 8), tr, trLen); + clif->send(buf, len, bl, AREA); + aFree(buf); + } + else + { + WFIFOHEAD(fd, len); + WFIFOW(fd, 0) = 0xB01; + WFIFOW(fd, 2) = len; + WFIFOL(fd, 4) = bl->id; + memcpy(WFIFOP(fd, 8), tr, trLen); + WFIFOSET(fd, len); + } + hookStop(); + } +} + +#define equipPos(index, field) \ + equip = sd->equip_index[index]; \ + if (equip >= 0) \ + { \ + item = sd->inventory_data[equip]; \ + if (item && item->look) \ + send_changelook(fd, id, field, item->look); \ + } + +static void eclif_send_additional_slots(TBL_PC* sd, TBL_PC* sd2) +{ + if (!sd || !sd2) + return; + + const int id = sd->bl.id; + const int fd = sd2->fd; + + struct item_data *item; + short equip; + struct MapdExt *data = mapd_get(sd->bl.m); + if (!data || data->invisible) + return; + + equipPos(EQI_HEAD_LOW, LOOK_HEAD_BOTTOM); + equipPos(EQI_HEAD_TOP, LOOK_HEAD_TOP); + equipPos(EQI_HEAD_MID, LOOK_HEAD_MID); + equipPos(EQI_GARMENT, LOOK_ROBE); + equipPos(EQI_SHOES, LOOK_SHOES); + equipPos(EQI_COSTUME_TOP, 13); + equipPos(EQI_COSTUME_MID, 14); + equipPos(EQI_COSTUME_LOW, 15); + equipPos(EQI_COSTUME_GARMENT, 16); + equipPos(EQI_ARMOR, 17); + //skipping SHADOW slots +} + +void eclif_getareachar_unit_post(TBL_PC* sd, struct block_list *bl) +{ + if (!bl) + return; + if (bl->type == BL_PC) + { + eclif_send_additional_slots(sd, (TBL_PC *)bl); + eclif_send_additional_slots((TBL_PC *)bl, sd); + } +} + +void eclif_authok_post(TBL_PC *sd) +{ + if (!sd) + return; + + eclif_send_additional_slots(sd, sd); + send_pc_info(&sd->bl, &sd->bl, SELF); + struct MapdExt *data = mapd_get(sd->bl.m); + int mask = data ? data->mask : 1; + send_mapmask(sd->fd, mask); +} + +void eclif_changemap_post(TBL_PC *sd, short *m, + int *x __attribute__ ((unused)), int *y __attribute__ ((unused))) +{ + if (!sd) + return; + struct MapdExt *data = mapd_get(*m); + int mask = data ? data->mask : 1; + send_mapmask(sd->fd, mask); +} + +void eclif_handle_invisible_map(struct block_list *bl, enum send_target target __attribute__ ((unused))) +{ + if (!bl || bl->type != BL_PC) + return; + struct MapdExt *data = mapd_get(bl->m); + if (data && data->invisible) + hookStop(); +} + +void eclif_sendlook(struct block_list *bl, + int *id __attribute__ ((unused)), + int *type __attribute__ ((unused)), + int *val __attribute__ ((unused)), + int *val2 __attribute__ ((unused)), + enum send_target *target) +{ + if (*target == SELF) + return; + eclif_handle_invisible_map(bl, *target); +} + +bool eclif_send(const void* buf __attribute__ ((unused)), + int *len __attribute__ ((unused)), + struct block_list* bl, + enum send_target *type) +{ + if (*type == SELF) + return true; + eclif_handle_invisible_map(bl, *type); + return true; +} + +void eclif_set_unit_idle(struct block_list* bl, TBL_PC *tsd, enum send_target *target) +{ + if (tsd && bl && bl->id == tsd->bl.id && *target == SELF) + return; + + eclif_handle_invisible_map(bl, *target); +} + +int eclif_send_actual(int *fd, void *buf, int *len) +{ + if (*len >= 2) + { + const int packet = RBUFW (buf, 0); + if (packet >= 0xb02 && packet <= 0xb10) + { + struct SessionExt *data = session_get(*fd); + if (!data) + return 0; + if (data->clientVersion < 3) + { // not sending new packets to old clients +// ShowWarning("skip packet %d\n", packet); + hookStop(); + return 0; + } + } + if (packet >= 0xb03 && packet <= 0xb0a) + { + struct SessionExt *data = session_get(*fd); + if (!data) + return 0; + if (data->clientVersion < 4) + { // not sending new packets to old clients +// ShowWarning("skip packet %d\n", packet); + hookStop(); + return 0; + } + } + if (packet == 0xb0b) + { + struct SessionExt *data = session_get(*fd); + if (!data) + return 0; + if (data->clientVersion < 5) + { // not sending new packets to old clients +// ShowWarning("skip packet %d\n", packet); + hookStop(); + return 0; + } + } + } + return 0; +} + +void eclif_set_unit_idle_post(struct block_list* bl, TBL_PC *tsd, + enum send_target *target) +{ + if (!bl || !tsd) + return; + + if (bl->type == BL_MOB) + send_mob_info(bl, &tsd->bl, *target); + else if (bl->type == BL_PC) + send_pc_info(bl, &tsd->bl, *target); + else if (bl->type == BL_NPC) + send_npc_info(bl, &tsd->bl, *target); +} + +void eclif_set_unit_walking(struct block_list* bl, TBL_PC *tsd, + struct unit_data* ud, enum send_target *target) +{ + TBL_PC *sd = BL_CAST(BL_PC, ud->bl); + if (!sd || !pc_isinvisible(sd)) + send_advmoving(ud, tsd ? &tsd->bl : bl, *target); +} + +void eclif_move(struct unit_data *ud) +{ + TBL_PC *sd = BL_CAST(BL_PC, ud->bl); + if (!sd || !pc_isinvisible(sd)) + send_advmoving(ud, ud->bl, AREA_WOS); +} diff --git a/src/emap/clif.h b/src/emap/clif.h new file mode 100644 index 0000000..5fd155b --- /dev/null +++ b/src/emap/clif.h @@ -0,0 +1,26 @@ +// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// Copyright (c) 2014 Evol developers + +#ifndef EVOL_MAP_CLIF +#define EVOL_MAP_CLIF + +void eclif_quest_send_list(TBL_PC *sd); +void eclif_quest_add(TBL_PC *sd, struct quest *qd); +void eclif_charnameack(int *fdPtr, struct block_list *bl); +void eclif_getareachar_unit_post(TBL_PC* sd, struct block_list *bl); +void eclif_sendlook(struct block_list *bl, int *id, int *type, + int *val, int *val2, enum send_target *target); +bool eclif_send(const void* buf, int *len, struct block_list* bl, enum send_target *type); +void eclif_set_unit_idle(struct block_list* bl, TBL_PC *tsd, + enum send_target *target); +int eclif_send_actual(int *fd, void *buf, int *len); + +void eclif_authok_post(TBL_PC *sd); +void eclif_changemap_post(TBL_PC *sd, short *m, int *x, int *y); +void eclif_set_unit_idle_post(struct block_list* bl, TBL_PC *tsd, + enum send_target *target); +void eclif_set_unit_walking(struct block_list* bl, TBL_PC *tsd, + struct unit_data* ud, enum send_target *target); +void eclif_move(struct unit_data *ud); + +#endif // EVOL_MAP_CLIF diff --git a/src/emap/data/itemd.c b/src/emap/data/itemd.c new file mode 100644 index 0000000..4b171b2 --- /dev/null +++ b/src/emap/data/itemd.c @@ -0,0 +1,68 @@ +// 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 "map/battle.h" +#include "map/itemdb.h" + +#include "emap/data/itemd.h" +#include "emap/struct/itemdext.h" + +struct ItemdExt *itemd_get_by_item(struct item *item) +{ + if (!item) + return NULL; + const int nameid = item->nameid; + struct item_data *item_data = itemdb->exists(nameid); + return itemd_get(item_data); +} + +struct ItemdExt *itemd_get(struct item_data *item) +{ + if (!item) + return NULL; + + struct ItemdExt *data = getFromITEMDATA(item, 0); + if (!data) + { + data = itemd_create(); + addToITEMDATA(item, data, 0, true); + } + return data; +} + +struct ItemdExt *itemd_create(void) +{ + struct ItemdExt *data = NULL; + CREATE(data, struct ItemdExt, 1); + if (!data) + return NULL; + data->floorLifeTime = battle->bc->flooritem_lifetime; + data->allowPickup = true; + data->requiredStr = 0; + data->requiredAgi = 0; + data->requiredVit = 0; + data->requiredInt = 0; + data->requiredDex = 0; + data->requiredLuk = 0; + data->requiredMaxHp = 0; + data->requiredMaxSp = 0; + data->requiredAtk = 0; + data->requiredMAtkMin = 0; + data->requiredMAtkMax = 0; + data->requiredDef = 0; + data->requiredMDef = 0; + data->useEffect = -1; + data->useFailEffect = -1; + data->unequipEffect = -1; + data->unequipFailEffect = -1; + return data; +} diff --git a/src/emap/data/itemd.h b/src/emap/data/itemd.h new file mode 100644 index 0000000..d3c529b --- /dev/null +++ b/src/emap/data/itemd.h @@ -0,0 +1,13 @@ +// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// Copyright (c) 2014 Evol developers + +#ifndef EVOL_MAP_ITEMD +#define EVOL_MAP_ITEMD + +struct ItemdExt; + +struct ItemdExt *itemd_get_by_item(struct item *item); +struct ItemdExt *itemd_get(struct item_data *item); +struct ItemdExt *itemd_create(void); + +#endif // EVOL_MAP_MAPD diff --git a/src/emap/data/mapd.c b/src/emap/data/mapd.c new file mode 100644 index 0000000..cb1a506 --- /dev/null +++ b/src/emap/data/mapd.c @@ -0,0 +1,40 @@ +// 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 "map/map.h" + +#include "emap/data/mapd.h" +#include "emap/struct/mapdext.h" + +struct MapdExt *mapd_get(int m) +{ + struct map_data *md = &map->list[m]; + struct MapdExt *data = getFromMAPD(md, 0); + if (!data) + { + data = mapd_create(); + addToMAPD(md, data, 0, true); + } + return data; +} + +struct MapdExt *mapd_create(void) +{ + struct MapdExt *data = NULL; + CREATE(data, struct MapdExt, 1); + if (!data) + return NULL; + data->mask = 1; + data->invisible = false; + data->flag.nopve = 0; + return data; +} diff --git a/src/emap/data/mapd.h b/src/emap/data/mapd.h new file mode 100644 index 0000000..a0878ae --- /dev/null +++ b/src/emap/data/mapd.h @@ -0,0 +1,12 @@ +// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// Copyright (c) 2014 Evol developers + +#ifndef EVOL_MAP_MAPD +#define EVOL_MAP_MAPD + +struct MapdExt; + +struct MapdExt *mapd_get(int fd); +struct MapdExt *mapd_create(void); + +#endif // EVOL_MAP_MAPD diff --git a/src/emap/data/npcd.c b/src/emap/data/npcd.c new file mode 100644 index 0000000..183db46 --- /dev/null +++ b/src/emap/data/npcd.c @@ -0,0 +1,38 @@ +// 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 "map/battle.h" +#include "map/npc.h" + +#include "emap/data/npcd.h" +#include "emap/struct/npcdext.h" + +struct NpcdExt *npcd_get(TBL_NPC *nd) +{ + struct NpcdExt *data = getFromNPCD(nd, 0); + if (!data) + { + data = npcd_create(); + addToNPCD(nd, data, 0, true); + } + return data; +} + +struct NpcdExt *npcd_create(void) +{ + struct NpcdExt *data = NULL; + CREATE(data, struct NpcdExt, 1); + if (!data) + return NULL; + data->init = false; + return data; +} diff --git a/src/emap/data/npcd.h b/src/emap/data/npcd.h new file mode 100644 index 0000000..52f3b76 --- /dev/null +++ b/src/emap/data/npcd.h @@ -0,0 +1,12 @@ +// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// Copyright (c) 2014 Evol developers + +#ifndef EVOL_MAP_NPCD +#define EVOL_MAP_NPCD + +struct NpcdExt; + +struct NpcdExt *npcd_get(TBL_NPC *nd); +struct NpcdExt *npcd_create(void); + +#endif // EVOL_MAP_NPCD diff --git a/src/emap/data/session.c b/src/emap/data/session.c new file mode 100644 index 0000000..c3c3ffa --- /dev/null +++ b/src/emap/data/session.c @@ -0,0 +1,48 @@ +// 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 "map/pc.h" + +#include "emap/data/session.h" +#include "emap/struct/sessionext.h" + +struct SessionExt *session_get(int fd) +{ + struct SessionExt *data = getFromSession(session[fd], 0); + if (!data) + { + data = session_create(); + addToSession(session[fd], data, 0, true); + } + return data; +} + +struct SessionExt *session_get_bysd(TBL_PC *sd) +{ + if (!sd) + return NULL; + + return session_get(sd->fd); +} + +struct SessionExt *session_create(void) +{ + struct SessionExt *data = NULL; + CREATE(data, struct SessionExt, 1); + if (!data) + return NULL; + data->clientVersion = 0; + data->language = 0; + data->state = 0; + data->onlinelistlasttime = 0; + return data; +} diff --git a/src/emap/data/session.h b/src/emap/data/session.h new file mode 100644 index 0000000..040b408 --- /dev/null +++ b/src/emap/data/session.h @@ -0,0 +1,13 @@ +// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// Copyright (c) 2014 Evol developers + +#ifndef EVOL_MAP_SESSION +#define EVOL_MAP_SESSION + +struct SessionExt; + +struct SessionExt *session_get(int fd); +struct SessionExt *session_get_bysd(TBL_PC *sd); +struct SessionExt *session_create(void); + +#endif // EVOL_MAP_SESSION diff --git a/src/emap/init.c b/src/emap/init.c new file mode 100644 index 0000000..c74c441 --- /dev/null +++ b/src/emap/init.c @@ -0,0 +1,244 @@ +// 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 "map/channel.h" +#include "map/chat.h" +#include "map/chrif.h" +#include "map/clif.h" +#include "map/duel.h" +#include "map/elemental.h" +#include "map/homunculus.h" +#include "map/guild.h" +#include "map/instance.h" +#include "map/intif.h" +#include "map/irc-bot.h" +#include "map/itemdb.h" +#include "map/mail.h" +#include "map/mapreg.h" +#include "map/mercenary.h" +#include "map/mob.h" +#include "map/npc.h" +#include "map/party.h" +#include "map/pet.h" +#include "map/pc.h" +#include "map/script.h" +#include "map/storage.h" +#include "map/trade.h" +#include "map/quest.h" + +#include "ecommon/config.h" +#include "ecommon/init.h" +#include "emap/atcommand.h" +#include "emap/clif.h" +#include "emap/itemdb.h" +#include "emap/lang.h" +#include "emap/mail.h" +#include "emap/map.h" +#include "emap/mob.h" +#include "emap/npc.h" +#include "emap/unit.h" +#include "emap/parse.h" +#include "emap/permission.h" +#include "emap/pc.h" +#include "emap/quest.h" +#include "emap/script.h" +#include "emap/skill.h" +#include "emap/status.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) */ + +extern int langScriptId; + +HPExport struct hplugin_info pinfo = +{ + "evol_map", + SERVER_TYPE_MAP, + "0.1", + HPM_VERSION +}; + +HPExport void plugin_init (void) +{ +// HPM_map_add_group_permission = GET_SYMBOL("addGroupPermission"); + + status_init(); + + addAtcommand("setskill", setSkill); + + addScriptCommand("setcamnpc", "*", setCamNpc); + addScriptCommand("setcam", "ii", setCam); + addScriptCommand("movecam", "ii", moveCam); + addScriptCommand("restorecam", "", restoreCam); + addScriptCommand("npctalk3", "s", npcTalk3); + addScriptCommand("closedialog", "", closeDialog); + addScriptCommand("shop", "s", shop); + addScriptCommand("getitemlink", "s", getItemLink); + addScriptCommand("l", "s*", l); + addScriptCommand("lg", "s*", lg); + addScriptCommand("requestlang", "v", requestLang); + addScriptCommand("requestitem", "v", requestItem); + addScriptCommand("requestitems", "v*", requestItems); + addScriptCommand("getq", "i", getq); + addScriptCommand("setq", "ii", setq); + addScriptCommand("setnpcdir", "*", setNpcDir); + addScriptCommand("rif", "is*", rif); + addScriptCommand("countitemcolor", "v*", countItemColor); + addScriptCommand("misceffect", "i*", miscEffect); + addScriptCommand("setmapmask", "si", setMapMask); + addScriptCommand("addmapmask", "si", addMapMask); + addScriptCommand("removemapmask", "si", removeMapMask); + addScriptCommand("getmapmask", "s", getMapMask); + addScriptCommand("setnpcsex", "*", setNpcSex); + addScriptCommand("showavatar", "*", showAvatar); + addScriptCommand("setavatardir", "i", setAvatarDir); + addScriptCommand("setavataraction", "i", setAvatarAction); + addScriptCommand("clear", "", clear); + addScriptCommand("changemusic", "ss", changeMusic); + addScriptCommand("setnpcdialogtitle", "s", setNpcDialogTitle); + addScriptCommand("getmapname", "", getMapName); + addScriptCommand("unequipbyid", "i", unequipById); + addScriptCommand("ispcdead", "", isPcDead); + addScriptCommand("areatimer", "siiiii*", areaTimer); + addScriptCommand("getareadropitem", "siiiiv*", getAreaDropItem); + addScriptCommand("setmount", "?", setMount); + addScriptCommand("clientcommand", "s", clientCommand); + addScriptCommand("isunitwalking", "?", isUnitWalking); + + do_init_langs(); + + addPacket(0x7530, 22, map_parse_version, hpClif_Parse); + addPacket(0xb07, 26, map_parse_join_channel, hpClif_Parse); + addPacket(0xb09, 26, map_parse_part_channel, hpClif_Parse); + addPacket(0xb0c, -1, map_parse_pet_say, hpClif_Parse); + addPacket(0xb0d, 3, map_parse_pet_emote, hpClif_Parse); + addPacket(0xb0e, 4, map_parse_set_status, hpClif_Parse); + addPacket(0xb0f, 2, map_parse_get_online_list, hpClif_Parse); + addPacket(0xb11, 10, map_parse_pet_move, hpClif_Parse); + addPacket(0xb12, 9, map_parse_pet_dir, hpClif_Parse); + addPacket(0xb13, -1, map_parse_homun_say, hpClif_Parse); + addPacket(0xb14, 3, map_parse_homun_emote, hpClif_Parse); + addPacket(0xb15, 9, map_parse_homun_dir, hpClif_Parse); + + addHookPre("atcommand->msgfd", eatcommand_msgfd); + addHookPre("atcommand->msgsd", eatcommand_msgsd); + addHookPre("pc->readparam", epc_readparam_pre); + addHookPre("pc->setregistry", epc_setregistry); + addHookPre("pc->equipitem_pos", epc_equipitem_pos); + addHookPre("pc->unequipitem_pos", epc_unequipitem_pos); + addHookPre("pc->can_attack", epc_can_attack); + addHookPre("pc->takeitem", epc_takeitem); + addHookPre("pc->validate_levels", epc_validate_levels); + addHookPre("pc->check_job_name", epc_check_job_name); + addHookPre("mob->deleteslave_sub", emob_deleteslave_sub); + addHookPre("npc->parse_unknown_mapflag", enpc_parse_unknown_mapflag); + addHookPre("npc->buysellsel", enpc_buysellsel); + addHookPre("npc->db_checkid", enpc_db_checkid); + addHookPre("clif->quest_send_list", eclif_quest_send_list); + addHookPre("clif->quest_add", eclif_quest_add); + addHookPre("clif->charnameack", eclif_charnameack); + addHookPre("clif->sendlook", eclif_sendlook); + addHookPre("clif->send", eclif_send); + addHookPre("clif->set_unit_idle", eclif_set_unit_idle); + addHookPre("clif->send_actual", eclif_send_actual); + addHookPre("itemdb->is_item_usable", eitemdb_is_item_usable); + addHookPre("itemdb->readdb_additional_fields", eitemdb_readdb_additional_fields); + addHookPre("unit->can_move", eunit_can_move); + addHookPre("unit->walktoxy", eunit_walktoxy); + addHookPre("mail->invalid_operation", email_invalid_operation); + + addHookPost("clif->getareachar_unit", eclif_getareachar_unit_post); + addHookPost("clif->authok", eclif_authok_post); + addHookPost("clif->changemap", eclif_changemap_post); + addHookPost("clif->set_unit_idle", eclif_set_unit_idle_post); + addHookPost("status->set_viewdata", estatus_set_viewdata_post); + addHookPost("status->read_job_db_sub", estatus_read_job_db_sub); + addHookPost("status->calc_pc_", estatus_calc_pc_); + addHookPost("clif->set_unit_walking", eclif_set_unit_walking); + addHookPost("clif->move", eclif_move); + addHookPost("map->addflooritem", emap_addflooritem_post); + addHookPost("skill->check_condition_castend", eskill_check_condition_castend_post); + addHookPost("pc->isequip", epc_isuseequip_post); + addHookPost("pc->isUseitem", epc_isuseequip_post); + addHookPost("pc->useitem", epc_useitem_post); + addHookPost("pc->equipitem", epc_equipitem_post); + addHookPost("pc->unequipitem", epc_unequipitem_post); + addHookPost("pc->setnewpc", epc_setnewpc); + + langScriptId = script->add_str("Lang"); +} + +HPExport void server_preinit (void) +{ + interfaces_init_common(); + + atcommand = GET_SYMBOL("atcommand"); + battle = GET_SYMBOL("battle"); + bg = GET_SYMBOL("battlegrounds"); + buyingstore = GET_SYMBOL("buyingstore"); + clif = GET_SYMBOL("clif"); + chrif = GET_SYMBOL("chrif"); + guild = GET_SYMBOL("guild"); + gstorage = GET_SYMBOL("gstorage"); + homun = GET_SYMBOL("homun"); + map = GET_SYMBOL("map"); + ircbot = GET_SYMBOL("ircbot"); + itemdb = GET_SYMBOL("itemdb"); + logs = GET_SYMBOL("logs"); + mail = GET_SYMBOL("mail"); + instance = GET_SYMBOL("instance"); + script = GET_SYMBOL("script"); + searchstore = GET_SYMBOL("searchstore"); + skill = GET_SYMBOL("skill"); + vending = GET_SYMBOL("vending"); + pc = GET_SYMBOL("pc"); + pcg = GET_SYMBOL("pc_groups"); + party = GET_SYMBOL("party"); + storage = GET_SYMBOL("storage"); + trade = GET_SYMBOL("trade"); + status = GET_SYMBOL("status"); + chat = GET_SYMBOL("chat"); + duel = GET_SYMBOL("duel"); + elemental = GET_SYMBOL("elemental"); + intif = GET_SYMBOL("intif"); + mercenary = GET_SYMBOL("mercenary"); + mob = GET_SYMBOL("mob"); + unit = GET_SYMBOL("unit"); + npc = GET_SYMBOL("npc"); + mapreg = GET_SYMBOL("mapreg"); + pet = GET_SYMBOL("pet"); + path = GET_SYMBOL("path"); + quest = GET_SYMBOL("quest"); + npc_chat = GET_SYMBOL("npc_chat"); + libpcre = GET_SYMBOL("libpcre"); + mapit = GET_SYMBOL("mapit"); + mapindex = GET_SYMBOL("mapindex"); + channel = GET_SYMBOL("channel"); + + setDefaultMap(); + addMapInterConf("default_map", config_default_map); + addMapInterConf("default_x", config_default_x); + addMapInterConf("default_y", config_default_y); + + addHookPre("quest->read_db_sub", equest_read_db_sub); + addGroupPermission("send_gm", permission_send_gm_flag); + addGroupPermission("show_client_version", permission_show_client_version_flag); +} + +HPExport void server_online (void) +{ +} + +HPExport void plugin_final (void) +{ + do_final_langs(); + commonClean(); +} diff --git a/src/emap/itemdb.c b/src/emap/itemdb.c new file mode 100644 index 0000000..34905a9 --- /dev/null +++ b/src/emap/itemdb.c @@ -0,0 +1,91 @@ +// 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 "map/itemdb.h" +#include "map/map.h" +#include "map/npc.h" +#include "map/pc.h" + +#include "emap/data/itemd.h" +#include "emap/struct/itemdext.h" +#include "emap/npc.h" + +bool eitemdb_is_item_usable(struct item_data *item) +{ + hookStop(); + if (!item) + return false; + return item->type == IT_HEALING || item->type == IT_USABLE || item->type == IT_CASH || item->type == IT_PETEGG; +} + +void eitemdb_readdb_additional_fields(int *itemid, + config_setting_t *it, + int *n __attribute__ ((unused)), + const char *source __attribute__ ((unused))) +{ + struct item_data *item = itemdb->exists(*itemid); + int i32 = 0; + if (!item) + { + hookStop(); + return; + } + struct ItemdExt *data = itemd_get(item); + if (!data) + { + hookStop(); + return; + } + + config_setting_t *t = NULL; + + if (libconfig->setting_lookup_int(it, "FloorLifeTime", &i32) && i32 >= 0) + data->floorLifeTime = i32; + if ((t = libconfig->setting_get_member(it, "AllowPickup"))) + data->allowPickup = libconfig->setting_get_bool(t) ? 1 : 0; + if (libconfig->setting_lookup_int(it, "RequiredStr", &i32) && i32 >= 0) + data->requiredStr = i32; + if (libconfig->setting_lookup_int(it, "RequiredAgi", &i32) && i32 >= 0) + data->requiredAgi = i32; + if (libconfig->setting_lookup_int(it, "RequiredVit", &i32) && i32 >= 0) + data->requiredVit = i32; + if (libconfig->setting_lookup_int(it, "RequiredInt", &i32) && i32 >= 0) + data->requiredInt = i32; + if (libconfig->setting_lookup_int(it, "RequiredDex", &i32) && i32 >= 0) + data->requiredDex = i32; + if (libconfig->setting_lookup_int(it, "RequiredLuk", &i32) && i32 >= 0) + data->requiredLuk = i32; + if (libconfig->setting_lookup_int(it, "RequiredMaxHp", &i32) && i32 >= 0) + data->requiredMaxHp = i32; + if (libconfig->setting_lookup_int(it, "RequiredMaxSp", &i32) && i32 >= 0) + data->requiredMaxSp = i32; + if (libconfig->setting_lookup_int(it, "RequiredAtk", &i32) && i32 >= 0) + data->requiredAtk = i32; + if (libconfig->setting_lookup_int(it, "RequiredMAtkMin", &i32) && i32 >= 0) + data->requiredMAtkMin = i32; + if (libconfig->setting_lookup_int(it, "RequiredMAtkMax", &i32) && i32 >= 0) + data->requiredMAtkMax = i32; + if (libconfig->setting_lookup_int(it, "RequiredDef", &i32) && i32 >= 0) + data->requiredDef = i32; + if (libconfig->setting_lookup_int(it, "RequiredMDef", &i32) && i32 >= 0) + data->requiredMDef = i32; + + if (itemdb->lookup_const(it, "UseEffect", &i32)) + data->useEffect = i32; + if (itemdb->lookup_const(it, "UseFailEffect", &i32)) + data->useFailEffect = i32; + if (itemdb->lookup_const(it, "UnequipEffect", &i32)) + data->unequipEffect = i32; + if (itemdb->lookup_const(it, "UnequipFailEffect", &i32)) + data->unequipFailEffect = i32; + hookStop(); +} diff --git a/src/emap/itemdb.h b/src/emap/itemdb.h new file mode 100644 index 0000000..5e35d57 --- /dev/null +++ b/src/emap/itemdb.h @@ -0,0 +1,11 @@ +// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// Copyright (c) 2014 Evol developers + +#ifndef EVOL_MAP_ITEMDB +#define EVOL_MAP_ITEMDB + +bool eitemdb_is_item_usable(struct item_data *item); + +void eitemdb_readdb_additional_fields(int *itemid, config_setting_t *it, int *n, const char *source); + +#endif // EVOL_MAP_ITEMDB diff --git a/src/emap/lang.c b/src/emap/lang.c new file mode 100644 index 0000000..d6a1910 --- /dev/null +++ b/src/emap/lang.c @@ -0,0 +1,234 @@ +// 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 "map/npc.h" +#include "map/pc.h" + +#include "emap/lang.h" +#include "emap/data/session.h" +#include "emap/struct/sessionext.h" + +#define MAX_LANGS 100 + +struct DBMap *translate_db = NULL; +char *lang_langs[MAX_LANGS]; +int lang_num = 0; + +static int langsdb_readdb (void); +static int langsdb_readlangs (void); + +void do_init_langs (void) +{ + translate_db = strdb_alloc(DB_OPT_RELEASE_BOTH, 1000); + + langsdb_readlangs (); + langsdb_readdb (); +} + +static int delete_lang_sub(DBKey key __attribute__ ((unused)), + DBData *data, + va_list args __attribute__ ((unused))) +{ + int f; + char **strings = DB->data2ptr(data); + for (f = 0; f < lang_num; f ++) + { + aFree(strings[f]); + strings[f] = NULL; + } + return 0; +} + +void do_final_langs(void) +{ + translate_db->destroy(translate_db, delete_lang_sub); + int f; + for (f = 0; f < lang_num; f ++) + aFree(lang_langs[f]); +} + +static int langsdb_readlangs (void) +{ + FILE *fp; + lang_num = 0; + fp = fopen("langs/langs.txt", "r"); + if (fp == NULL) + { + printf ("can't read langs/langs.txt\n"); + return 1; + } + char line[100]; + char text[101]; + while (fgets (line, 99, fp)) + { + if (sscanf(line, "%99s\n", text) < 1) + continue; + + lang_langs[lang_num] = aStrdup (text); + lang_num ++; + } + fclose(fp); + return 0; +} + +static int langsdb_readdb (void) +{ + char line[1020], line1[1020], line2[1020]; + char filename[1000]; + char **strings = NULL; + char *idx; + int i; + int sz; + for (i = 0; i < lang_num; i ++) + { + strcpy (filename, "langs/lang_"); + strcat (filename, lang_langs[i]); + strcat (filename, ".txt"); + + FILE *fp = fopen(filename, "r"); + if (fp == NULL) + { + printf ("can't read %s\n", filename); + return 1; + } + + if (!fgets (line, 1010, fp)) + { + printf ("can't read %s\n", filename); + continue; + } + + line1[0] = 0; + line2[0] = 0; + while (fgets (line, 1010, fp)) + { + if (*line) + { + idx = strrchr (line, '\n'); + if (idx) + *idx = 0; + } + + if (!*line) + { + line1[0] = 0; + line2[0] = 0; + continue; + } + else if (!*line1) + { + strcpy (line1, line); + continue; + } + strcpy (line2, line); + + strings = (char **)strdb_get(translate_db, line1); + if (!strings) + { + strings = aCalloc (lang_num, sizeof(int*)); + sz = strlen(line1) + 1; + strings[0] = aCalloc (sz < 24 ? 24 : sz, sizeof(char)); + strcpy (strings[0], line2); + strdb_put(translate_db, aStrdup (line1), strings); + } + else + { + sz = strlen(line2) + 1; + strings[i] = aCalloc (sz < 24 ? 24 : sz, sizeof(char)); + strcpy (strings[i], line2); + } + + *line1 = 0; + *line2 = 0; + } + fclose (fp); + } + return 0; +} + +const char* lang_trans(const char *str, int lng, int flg) +{ + if (!str) + return 0; + + if (lng < 0 || lng >= lang_num) + return str; + + char **strings = (char **)strdb_get(translate_db, str); + if (!strings) + { + if (flg) + printf ("no translations for: %s\n", str); + return str; + } + + if (!strings[lng]) + { + if (flg) + printf ("no lang string (%s) for: %s\n", lang_langs[lng], str); + return str; + } + + return strings[lng]; +} + +const char* lang_pctrans(const char *str, TBL_PC *sd) +{ + int lng = 0; + int flg = 1; + if (!str) + return 0; + + if (*str == '#') + flg = 0; + if (sd) + { + struct SessionExt *data = session_get_bysd(sd); + if (data) + lng = data->language; + } + + return lang_trans(str, lng, flg); +} + +int lang_getId(const char *str) +{ + char *str1 = aStrdup(str); + char *str2 = NULL; + int f; + + if ((str2 = strchr(str, '.'))) + *str2 = 0; + + for (f = 0; f < MAX_LANGS && lang_langs[f]; f ++) + { + if (!strcmp(str, lang_langs[f])) + { + aFree (str1); + return f; + } + } + + if ((str2 = strchr(str1, '_'))) + *str2 = 0; + + for (f = 0; f < MAX_LANGS && lang_langs[f]; f ++) + { + if (strstr(lang_langs[f], str1) == lang_langs[f]) + { + aFree (str1); + return f; + } + } + aFree (str1); + return -1; +} diff --git a/src/emap/lang.h b/src/emap/lang.h new file mode 100644 index 0000000..4afc6b9 --- /dev/null +++ b/src/emap/lang.h @@ -0,0 +1,15 @@ +// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// Copyright (c) 2014 Evol developers + +#ifndef EVOL_MAP_LANG +#define EVOL_MAP_LANG + +extern struct DBMap *translate_db; + +void do_init_langs (void); +void do_final_langs(void); +const char* lang_trans(const char *str, int lng, int flg); +const char* lang_pctrans(const char *str, TBL_PC *sd); +int lang_getId(const char *str); + +#endif // EVOL_MAP_LANG diff --git a/src/emap/mail.c b/src/emap/mail.c new file mode 100644 index 0000000..a3d92c8 --- /dev/null +++ b/src/emap/mail.c @@ -0,0 +1,36 @@ +// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// Copyright (c) 2014 Evol developers + +#include +#include +#include + +#include "common/db.h" +#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 "map/battle.h" +#include "map/itemdb.h" +#include "map/map.h" +#include "map/pc.h" + +bool email_invalid_operation(struct map_session_data *sd) +{ + if (!sd) + { + hookStop(); + return true; + } + + if (!map->list[sd->bl.m].flag.town) + { + ShowWarning("clif->parse_Mail: char '%s' trying to do invalid mail operations.\n", sd->status.name); + hookStop(); + return true; + } + hookStop(); + return false; +} diff --git a/src/emap/mail.h b/src/emap/mail.h new file mode 100644 index 0000000..2c3aca2 --- /dev/null +++ b/src/emap/mail.h @@ -0,0 +1,9 @@ +// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// Copyright (c) 2014 Evol developers + +#ifndef EVOL_MAP_MAIL +#define EVOL_MAP_MAIL + +bool email_invalid_operation(struct map_session_data *sd); + +#endif // EVOL_MAP_MAIL diff --git a/src/emap/map.c b/src/emap/map.c new file mode 100644 index 0000000..55f4245 --- /dev/null +++ b/src/emap/map.c @@ -0,0 +1,133 @@ +// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// Copyright (c) 2014 Evol developers + +#include +#include +#include + +#include "common/db.h" +#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 "map/battle.h" +#include "map/itemdb.h" +#include "map/map.h" +#include "map/pc.h" + +#include "emap/permission.h" +#include "emap/send.h" +#include "emap/data/itemd.h" +#include "emap/data/session.h" +#include "emap/struct/itemdext.h" +#include "emap/struct/sessionext.h" + +int emap_addflooritem_post(int retVal, + struct item *item, + int *amount __attribute__ ((unused)), + int16 *m __attribute__ ((unused)), + int16 *x __attribute__ ((unused)), + int16 *y __attribute__ ((unused)), + int *first_charid __attribute__ ((unused)), + int *second_charid __attribute__ ((unused)), + int *third_charid __attribute__ ((unused)), + int *flags __attribute__ ((unused))) +{ + TBL_ITEM* fitem = (TBL_ITEM*)idb_get(map->id_db, retVal); + if (fitem && fitem->cleartimer != INVALID_TIMER) + { + int timeout = battle->bc->flooritem_lifetime; + struct ItemdExt *data = itemd_get_by_item(item); + if (data) + timeout = data->floorLifeTime; + timer->delete(fitem->cleartimer, map->clearflooritem_timer); + if (timeout >= 0) + fitem->cleartimer = timer->add(timer->gettick() + timeout, map->clearflooritem_timer, fitem->bl.id, 0); + } + return retVal; +} + +void emap_online_list(int fd) +{ + char *buf = aCalloc (1, 20000); + char *ptr = buf; + TBL_PC* sd; + + struct SessionExt *data1 = session_get(fd); + if (!data1) + { + aFree(buf); + return; + } + + const time_t t = time(NULL); + if (data1->onlinelistlasttime + 15 >= t) + { // not more than 1 per 15 seconds + data1->onlinelistlasttime = t; + aFree(buf); + return; + } + + TBL_PC* ssd = (TBL_PC*)session[fd]->session_data; + if (!ssd) + { + aFree(buf); + return; + } + + const bool showVersion = pc_has_permission(ssd, permission_show_client_version_flag); + const int gpoupLevel = pc_get_group_level(ssd); + data1->onlinelistlasttime = t; + + DBIterator* iter = db_iterator(map->pc_db); + + for (sd = dbi_first(iter); dbi_exists(iter); sd = dbi_next(iter)) + { + if (!sd) + continue; + + if (ptr - buf > 19500) + break; + + if (pc_isinvisible(sd) && gpoupLevel < pc_get_group_level(sd)) + continue; + + struct SessionExt *data = session_get_bysd(sd); + if (!data) + continue; + + uint8 state = data->state; + if (sd->status.sex == 1) + state |= 128; + else + state = (state | 128) ^ 128; + + if (pc_has_permission(sd, permission_send_gm_flag)) + state |= 64; + else + state = (state | 64) ^ 64; + + *ptr = state; + ptr ++; + + *ptr = sd->status.base_level; + ptr ++; + + if (showVersion) + *ptr = data->clientVersion; + else + *ptr = 0; + ptr ++; + + strcpy(ptr, sd->status.name); + ptr += strlen(sd->status.name); + *ptr = 0; + ptr ++; + + } + dbi_destroy(iter); + send_online_list(fd, buf, ptr - buf); + aFree(buf); +} diff --git a/src/emap/map.h b/src/emap/map.h new file mode 100644 index 0000000..3b9afce --- /dev/null +++ b/src/emap/map.h @@ -0,0 +1,10 @@ +// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// Copyright (c) 2014 Evol developers + +#ifndef EVOL_MAP_MAP +#define EVOL_MAP_MAP + +int emap_addflooritem_post(int retVal, struct item *item, int *amount, int16 *m, int16 *x, int16 *y, int *first_charid, int *second_charid, int *third_charid, int *flags); +void emap_online_list(int fd); + +#endif // EVOL_MAP_MAP diff --git a/src/emap/mob.c b/src/emap/mob.c new file mode 100644 index 0000000..c4c8bcf --- /dev/null +++ b/src/emap/mob.c @@ -0,0 +1,48 @@ +// 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 "map/battle.h" +#include "map/itemdb.h" +#include "map/mob.h" + +int emob_deleteslave_sub(struct block_list *bl, va_list ap) +{ + if (!bl) + { + hookStop(); + return 0; + } + TBL_MOB *md = (TBL_MOB *)bl; + if (!md) + { + hookStop(); + return 0; + } + + const int id = va_arg(ap, int); + if (md->master_id > 0 && md->master_id == id) + { + if (md->db->status.mode & 0x8000) + { + md->master_id = 0; + md->master_dist = 0; + } + else + { + status_kill(bl); + } + } + + hookStop(); + return 0; +} diff --git a/src/emap/mob.h b/src/emap/mob.h new file mode 100644 index 0000000..d0d9e87 --- /dev/null +++ b/src/emap/mob.h @@ -0,0 +1,9 @@ +// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// Copyright (c) 2014 Evol developers + +#ifndef EVOL_MAP_MOB +#define EVOL_MAP_MOB + +int emob_deleteslave_sub(struct block_list *bl, va_list ap); + +#endif // EVOL_MAP_MOB diff --git a/src/emap/npc.c b/src/emap/npc.c new file mode 100644 index 0000000..16fe2bb --- /dev/null +++ b/src/emap/npc.c @@ -0,0 +1,127 @@ +// 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 "map/map.h" +#include "map/npc.h" +#include "map/pc.h" + +#include "emap/data/mapd.h" +#include "emap/data/npcd.h" +#include "emap/struct/mapdext.h" +#include "emap/struct/npcdext.h" +#include "emap/npc.h" + +void enpc_parse_unknown_mapflag(const char *name, char *w3, char *w4, const char* start, + const char* buffer, const char* filepath, int *retval) +{ + if (!strcmpi(w3, "invisible")) + { + int16 m = map->mapname2mapid(name); + struct MapdExt *data = mapd_get(m); + if (data) + data->invisible = true; + } + else if (!strcmpi(w3, "mask")) + { + int16 m = map->mapname2mapid(name); + struct MapdExt *data = mapd_get(m); + if (data) + data->mask = atoi(w4); + } + else if (!strcmpi(w3, "nopve")) + { + int16 m = map->mapname2mapid(name); + struct MapdExt *data = mapd_get(m); + if (data) + data->flag.nopve = 1; + } + else + { + ShowError("npc_parse_mapflag: unrecognized mapflag '%s' in file '%s', line '%d'.\n", w3, filepath, strline(buffer,start-buffer)); + if (retval) + *retval = EXIT_FAILURE; + } + hookStop(); +} + +int enpc_buysellsel(TBL_PC* sd, int *id, int *type) +{ + TBL_NPC *nd; + + if (!sd) + return 1; + + if ((nd = npc->checknear(sd, map->id2bl(*id))) == NULL) + { + hookStop(); + return 1; + } + + if (nd->option & OPTION_INVISIBLE) // can't buy if npc is not visible (hack?) + { + hookStop(); + return 1; + } + + if (*type == 0 && nd->subtype == SCRIPT && nd->u.scr.shop && nd->u.scr.shop->type == NST_MARKET) + { + clif->npc_market_open(sd, nd); + hookStop(); + return 0; + } + + if (nd->subtype != SHOP && !(nd->subtype == SCRIPT && nd->u.scr.shop && nd->u.scr.shop->items)) + { + if (nd->subtype == SCRIPT) + ShowError("npc_buysellsel: trader '%s' has no shop list!\n", nd->exname); + else + ShowError("npc_buysellsel: no such shop npc %d (%s)\n", *id, nd->exname); + + if (sd->npc_id == *id) + sd->npc_id = 0; + hookStop(); + return 1; + } + + if (nd->class_ < 0 && !sd->state.callshop) + { // not called through a script and is not a visible NPC so an invalid call + hookStop(); + return 1; + } + + // reset the callshop state for future calls + sd->state.callshop = 0; + sd->npc_shopid = *id; + + if (*type == 0) + clif->buylist(sd, nd); + else + clif->selllist(sd); + + hookStop(); + return 0; +} + +bool enpc_db_checkid(int *idPtr) +{ + const int id = *idPtr; + hookStop(); + + if (id == HIDDEN_WARP_CLASS || id == INVISIBLE_CLASS) // Special IDs not included in the valid ranges + return true; + if (id >= 45 && id < MAX_NPC_CLASS) // Second subrange + return true; + if (id >= MAX_NPC_CLASS2_START && id < MAX_NPC_CLASS2_END) // Second range + return true; + // Anything else is invalid + return false; +} diff --git a/src/emap/npc.h b/src/emap/npc.h new file mode 100644 index 0000000..4f584fe --- /dev/null +++ b/src/emap/npc.h @@ -0,0 +1,14 @@ +// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// Copyright (c) 2014 Evol developers + +#ifndef EVOL_MAP_NPC +#define EVOL_MAP_NPC + +void enpc_parse_unknown_mapflag(const char *name, char *w3, char *w4, const char* start, + const char* buffer, const char* filepath, int *retval); + +int enpc_buysellsel(TBL_PC* sd, int *id, int *type); + +bool enpc_db_checkid(int *idPtr); + +#endif // EVOL_MAP_NPC diff --git a/src/emap/parse.c b/src/emap/parse.c new file mode 100644 index 0000000..c5179cd --- /dev/null +++ b/src/emap/parse.c @@ -0,0 +1,220 @@ +// 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 "map/channel.h" +#include "map/clif.h" +#include "map/homunculus.h" +#include "map/mercenary.h" +#include "map/pc.h" +#include "map/pet.h" +#include "map/unit.h" + +#include "emap/parse.h" +#include "emap/send.h" +#include "emap/map.h" +#include "emap/data/session.h" +#include "emap/struct/sessionext.h" + +void map_parse_version(int fd) +{ + struct SessionExt *data = session_get(fd); + if (!data) + return; + data->clientVersion = RFIFOL(fd, 2); +} + +void map_parse_join_channel(int fd) +{ + char name[24]; + char *p; + TBL_PC* sd = (TBL_PC*)session[fd]->session_data; + int res = 0; + if (!sd) + return; + + safestrncpy(name, (char*)RFIFOP(fd, 2), 24); + if (name[0] == '#') + p = name + 1; + else + p = name; + + struct channel_data *chan = channel->search(p, sd); + + if (chan) + { + int k; + ARR_FIND(0, sd->channel_count, k, sd->channels[k] == chan); + if (k < sd->channel_count || channel->join(chan, sd, NULL, true) == HCS_STATUS_OK) + res = 1; + else + res = 0; + } + + send_join_ack(fd, name, res); +} + +void map_parse_part_channel(int fd) +{ + char name[24]; + char *p; + TBL_PC* sd = (TBL_PC*)session[fd]->session_data; + int k; + if (!sd) + return; + + safestrncpy(name, (char*)RFIFOP(fd, 2), 24); + if (name[0] == '#') + p = name + 1; + else + p = name; + + for (k = 0; k < sd->channel_count; k ++) + { + if (strcmpi(p, sd->channels[k]->name) == 0) + break; + } + + if (k == sd->channel_count) + return; + + if (sd->channels[k]->type == HCS_TYPE_ALLY) + { + do + { + for (k = 0; k < sd->channel_count; k++) + { + if (sd->channels[k]->type == HCS_TYPE_ALLY) + { + channel->leave(sd->channels[k], sd); + break; + } + } + } + while (k != sd->channel_count); + } + else + { + channel->leave(sd->channels[k], sd); + } +} + +void map_parse_pet_say(int fd) +{ + char message[500]; + + TBL_PC* sd = (TBL_PC*)session[fd]->session_data; + if (!sd || !sd->pd) + return; + + const int len = RFIFOW(fd, 2); + if (len > 500 || len < 6) + return; + safestrncpy(message, (char*)RFIFOP(fd, 4), len - 4); + send_slave_say(sd, &sd->pd->bl, sd->pd->pet.name, message); +} + +void map_parse_pet_emote(int fd) +{ + TBL_PC* sd = (TBL_PC*)session[fd]->session_data; + if (!sd || !sd->pd) + return; + const time_t t = time(NULL); + if (sd->emotionlasttime + 1 >= t) + { // not more than 1 per second + sd->emotionlasttime = t; + return; + } + + sd->emotionlasttime = t; + clif->emotion(&sd->pd->bl, RFIFOB(fd, 2)); +} + +void map_parse_set_status(int fd) +{ + struct SessionExt *data = session_get(fd); + if (!data) + return; + data->state = RFIFOB(fd, 2); +} + +void map_parse_get_online_list(int fd) +{ + emap_online_list(fd); +} + +void map_parse_pet_move(int fd) +{ + TBL_PC* sd = (TBL_PC*)session[fd]->session_data; + if (!sd || !sd->pd) + return; + short x = RFIFOW(fd, 6); + short y = RFIFOW(fd, 8); + + struct block_list *pdBl = &sd->pd->bl; + if (map->getcell(pdBl->m, x, y, CELL_CHKPASS)) + unit->walktoxy(pdBl, x, y, 0); +} + +void map_parse_pet_dir(int fd) +{ + TBL_PC* sd = (TBL_PC*)session[fd]->session_data; + if (!sd || !sd->pd) + return; + unit->setdir(&sd->pd->bl, RFIFOB(fd, 8)); +} + +void map_parse_homun_say(int fd) +{ + char message[500]; + + TBL_PC* sd = (TBL_PC*)session[fd]->session_data; + if (!sd) + return; + const int len = RFIFOW(fd, 2); + if (len > 500 || len < 6) + return; + safestrncpy(message, (char*)RFIFOP(fd, 4), len - 4); + if (sd->md && sd->md->db) + send_slave_say(sd, &sd->md->bl, sd->md->db->name, message); + else if (sd->hd && homun_alive(sd->hd)) + send_slave_say(sd, &sd->hd->bl, sd->hd->homunculus.name, message); +} + +void map_parse_homun_emote(int fd) +{ + TBL_PC* sd = (TBL_PC*)session[fd]->session_data; + if (!sd) + return; + const time_t t = time(NULL); + if (sd->emotionlasttime + 1 >= t) + { // not more than 1 per second + sd->emotionlasttime = t; + return; + } + + sd->emotionlasttime = t; + if (sd->md && sd->md->db) + clif->emotion(&sd->md->bl, RFIFOB(fd, 2)); + else if (sd->hd && homun_alive(sd->hd)) + clif->emotion(&sd->hd->bl, RFIFOB(fd, 2)); +} + +void map_parse_homun_dir(int fd) +{ + TBL_PC* sd = (TBL_PC*)session[fd]->session_data; + if (!sd || !sd->pd) + return; + if (sd->md && sd->md->db) + unit->setdir(&sd->md->bl, RFIFOB(fd, 8)); + else if (sd->hd && homun_alive(sd->hd)) + unit->setdir(&sd->hd->bl, RFIFOB(fd, 8)); +} diff --git a/src/emap/parse.h b/src/emap/parse.h new file mode 100644 index 0000000..8d137ad --- /dev/null +++ b/src/emap/parse.h @@ -0,0 +1,20 @@ +// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// Copyright (c) 2014 Evol developers + +#ifndef EVOL_MAP_PARSE +#define EVOL_MAP_PARSE + +void map_parse_version(int fd); +void map_parse_join_channel(int fd); +void map_parse_part_channel(int fd); +void map_parse_pet_say(int fd); +void map_parse_pet_emote(int fd); +void map_parse_set_status(int fd); +void map_parse_get_online_list(int fd); +void map_parse_pet_move(int fd); +void map_parse_pet_dir(int fd); +void map_parse_homun_say(int fd); +void map_parse_homun_emote(int fd); +void map_parse_homun_dir(int fd); + +#endif // EVOL_MAP_PARSE diff --git a/src/emap/pc.c b/src/emap/pc.c new file mode 100644 index 0000000..59ac6e2 --- /dev/null +++ b/src/emap/pc.c @@ -0,0 +1,309 @@ +// 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 "map/itemdb.h" +#include "map/pc.h" + +#include "emap/pc.h" +#include "emap/data/itemd.h" +#include "emap/data/mapd.h" +#include "emap/data/session.h" +#include "emap/struct/itemdext.h" +#include "emap/struct/mapdext.h" +#include "emap/struct/sessionext.h" + +int langScriptId; + +int epc_readparam_pre(TBL_PC* sd, int *type) +{ + if (*type == Const_ClientVersion) + { + struct SessionExt *data = session_get_bysd(sd); + hookStop(); + if (!data) + return 0; + return data->clientVersion; + } + return 0; +} + +int epc_setregistry(TBL_PC *sd, int64 *reg, int *val) +{ + if (*reg == langScriptId) + { + struct SessionExt *data = session_get_bysd(sd); + if (!data) + return 0; + + data->language = *val; + } + + return 0; +} + +#define equipPos(mask, field, lookf) \ + if (pos & mask) \ + { \ + if (id) \ + sd->status.field = id->look; \ + else \ + sd->status.field = 0; \ + clif->changelook(&sd->bl, lookf, sd->status.field); \ + hookStop(); \ + } + +#define equipPos2(mask, lookf) \ + if (pos & mask) \ + { \ + if (id) \ + clif->changelook(&sd->bl, lookf, id->look); \ + else \ + clif->changelook(&sd->bl, lookf, 0); \ + hookStop(); \ + } + +void epc_equipitem_pos(TBL_PC *sd, struct item_data *id, int *posPtr) +{ + int pos = *posPtr; + + if (!id) + return; + + equipPos(EQP_HEAD_LOW, head_bottom, LOOK_HEAD_BOTTOM); + equipPos(EQP_HEAD_TOP, head_top, LOOK_HEAD_TOP); + equipPos(EQP_HEAD_MID, head_mid, LOOK_HEAD_MID); + equipPos(EQP_GARMENT, robe, LOOK_ROBE); + //skip EQP_ARMOR + equipPos2(EQP_SHOES, LOOK_SHOES); + equipPos2(EQP_COSTUME_HEAD_TOP, 13); + equipPos2(EQP_COSTUME_HEAD_MID, 14); + equipPos2(EQP_COSTUME_HEAD_LOW, 15); + equipPos2(EQP_COSTUME_GARMENT, 16); + equipPos2(EQP_ARMOR, 17); + //skipping SHADOW slots +} + +#undef equipPos +#undef equipPos2 + +#define unequipPos(mask, field, lookf) \ + if (pos & mask) \ + { \ + sd->status.field = 0; \ + clif->changelook(&sd->bl, lookf, sd->status.field); \ + hookStop(); \ + } + +#define unequipPos2(mask, lookf) \ + if (pos & mask) \ + { \ + clif->changelook(&sd->bl, lookf, 0); \ + hookStop(); \ + } + +void epc_unequipitem_pos(TBL_PC *sd, + int *nPtr __attribute__ ((unused)), + int *posPtr) +{ + if (!sd) + return; + + int pos = *posPtr; + + unequipPos(EQP_HEAD_LOW, head_bottom, LOOK_HEAD_BOTTOM); + unequipPos(EQP_HEAD_TOP, head_top, LOOK_HEAD_TOP); + unequipPos(EQP_HEAD_MID, head_mid, LOOK_HEAD_MID); + unequipPos(EQP_GARMENT, robe, LOOK_ROBE); + unequipPos2(EQP_SHOES, LOOK_SHOES); + unequipPos2(EQP_COSTUME_HEAD_TOP, 13); + unequipPos2(EQP_COSTUME_HEAD_MID, 14); + unequipPos2(EQP_COSTUME_HEAD_LOW, 15); + unequipPos2(EQP_COSTUME_GARMENT, 16); + unequipPos2(EQP_ARMOR, 17); + //skipping SHADOW slots +} + +#undef unequipPos +#undef unequipPos2 + +bool epc_can_attack (TBL_PC *sd, int *target_id) +{ + if (!sd) + return false; + + struct MapdExt *data = mapd_get(sd->bl.m); + if (!data) + return true; + if (data->flag.nopve) + { + if (map->id2md(*target_id)) + { + hookStop(); + return false; + } + } + return true; +} + +int epc_takeitem(TBL_PC *sd __attribute__ ((unused)), + TBL_ITEM *fitem) +{ + if (!fitem) + return 0; + + struct ItemdExt *data = itemd_get_by_item(&fitem->item_data); + if (!data) + return 1; + + if (!data->allowPickup) + { + hookStop(); + return 0; + } + return 1; +} + +void epc_validate_levels(void) +{ + int i; + for (i = 0; i < 7; i++) { + if (!pc->db_checkid(i)) continue; + if (i == JOB_WEDDING || i == JOB_XMAS || i == JOB_SUMMER) + continue; //Classes that do not need exp tables. + int j = pc->class2idx(i); + if (!pc->max_level[j][0]) + ShowWarning("Class %d does not has a base exp table.\n", i); + if (!pc->max_level[j][1]) + ShowWarning("Class %d does not has a job exp table.\n", i); + } + hookStop(); +} + +int epc_isuseequip_post(int retVal, struct map_session_data *sd, int *nPtr) +{ + const int n = *nPtr; + if (retVal) + { + if (!sd) + return 0; + + if (n < 0 || n >= MAX_INVENTORY) + return 0; + + struct ItemdExt *data = itemd_get(sd->inventory_data[n]); + if (!data) + return retVal; + + if (sd->battle_status.str < data->requiredStr || + sd->battle_status.agi < data->requiredAgi || + sd->battle_status.vit < data->requiredVit || + sd->battle_status.int_ < data->requiredInt || + sd->battle_status.dex < data->requiredDex || + sd->battle_status.luk < data->requiredLuk || + sd->battle_status.max_hp < data->requiredMaxHp || + sd->battle_status.max_sp < data->requiredMaxSp || + sd->battle_status.batk < data->requiredAtk || + sd->battle_status.matk_min < data->requiredMAtkMin || + sd->battle_status.matk_max < data->requiredMAtkMax || + sd->battle_status.def < data->requiredDef || + sd->battle_status.mdef < data->requiredMDef + ) + { + return 0; + } + } + return retVal; +} + +int epc_useitem_post(int retVal, struct map_session_data *sd, int *nPtr) +{ + const int n = *nPtr; + if (!sd) + return retVal; + + if (n < 0 || n >= MAX_INVENTORY) + return retVal; + + struct ItemdExt *data = itemd_get(sd->inventory_data[n]); + if (!data) + return retVal; + + const int effect = retVal ? data->useEffect : data->useFailEffect; + if (effect != -1) + clif->specialeffect(&sd->bl, effect, AREA); + return retVal; +} + +static void equippost_effect(struct map_session_data *const sd, const int n, const bool retVal, const bool equip) +{ + if (!sd) + return; + + if (n < 0 || n >= MAX_INVENTORY) + return; + + struct ItemdExt *data = itemd_get(sd->inventory_data[n]); + if (!data) + return; + + int effect; + if (equip) + effect = retVal ? data->useEffect : data->useFailEffect; + else + effect = retVal ? data->unequipEffect : data->unequipFailEffect; + + if (effect != -1) + clif->specialeffect(&sd->bl, effect, AREA); + return; +} + +int epc_equipitem_post(int retVal, struct map_session_data *sd, + int *nPtr, int *data __attribute__ ((unused))) +{ + equippost_effect(sd, *nPtr, retVal, true); + return retVal; +} + +int epc_unequipitem_post(int retVal, struct map_session_data *sd, + int *nPtr, int *data __attribute__ ((unused))) +{ + equippost_effect(sd, *nPtr, retVal, false); + return retVal; +} + +int epc_check_job_name(const char *name) +{ + int val = -1; + if (script->get_constant(name, &val)) + { + hookStop(); + return val; + } + hookStop(); + return -1; +} + +int epc_setnewpc(int retVal, struct map_session_data *sd, + int *account_id __attribute__ ((unused)), + int *char_id __attribute__ ((unused)), + int *login_id1 __attribute__ ((unused)), + unsigned int *client_tick __attribute__ ((unused)), + int *sex __attribute__ ((unused)), + int *fd __attribute__ ((unused))) +{ + if (sd) + { + sd->battle_status.speed = 150; + sd->base_status.speed = 150; + } + return retVal; +} diff --git a/src/emap/pc.h b/src/emap/pc.h new file mode 100644 index 0000000..e850b81 --- /dev/null +++ b/src/emap/pc.h @@ -0,0 +1,42 @@ +// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// Copyright (c) 2014 Evol developers + +#ifndef EVOL_MAP_PC +#define EVOL_MAP_PC + +enum VarConst +{ + Const_ClientVersion = 10000 +}; + +int epc_readparam_pre(TBL_PC* sd, int *type); + +int epc_setregistry(TBL_PC *sd, int64 *reg, int *val); + +void epc_equipitem_pos(TBL_PC *sd, struct item_data *id, int *posPtr); + +void epc_unequipitem_pos(TBL_PC *sd, int *nPtr, int *posPtr); + +bool epc_can_attack (TBL_PC *sd, int *target_id); + +int epc_takeitem(TBL_PC *sd, TBL_ITEM *fitem); + +void epc_validate_levels(void); + +int epc_isuseequip_post(int retVal, struct map_session_data *sd, int *nPtr); + +int epc_useitem_post(int retVal, struct map_session_data *sd, int *nPtr); + +int epc_equipitem_post(int retVal, struct map_session_data *sd, + int *nPtr, int *data); + +int epc_unequipitem_post(int retVal, struct map_session_data *sd, + int *nPtr, int *data); + +int epc_check_job_name(const char *name); + +int epc_setnewpc(int retVal, struct map_session_data *sd, + int *account_id, int *char_id, int *login_id1, + unsigned int *client_tick, int *sex, int *fd); + +#endif // EVOL_MAP_PC diff --git a/src/emap/permission.c b/src/emap/permission.c new file mode 100644 index 0000000..b05b04b --- /dev/null +++ b/src/emap/permission.c @@ -0,0 +1,18 @@ +// 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 "map/map.h" +#include "map/npc.h" +#include "map/status.h" + +unsigned int permission_send_gm_flag = UINT_MAX - 1; +unsigned int permission_show_client_version_flag = UINT_MAX - 2; diff --git a/src/emap/permission.h b/src/emap/permission.h new file mode 100644 index 0000000..a585c98 --- /dev/null +++ b/src/emap/permission.h @@ -0,0 +1,10 @@ +// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// Copyright (c) 2014 Evol developers + +#ifndef EVOL_MAP_PERMISSION +#define EVOL_MAP_PERMISSION + +extern unsigned int permission_send_gm_flag; +extern unsigned int permission_show_client_version_flag; + +#endif // EVOL_MAP_PERMISSION diff --git a/src/emap/quest.c b/src/emap/quest.c new file mode 100644 index 0000000..5ad82f6 --- /dev/null +++ b/src/emap/quest.c @@ -0,0 +1,132 @@ +// 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 "map/itemdb.h" +#include "map/quest.h" + +#include "emap/quest.h" + +/** + * Reads and parses an entry from the quest_db. + * + * @param cs The config setting containing the entry. + * @param n The sequential index of the current config setting. + * @param source The source configuration file. + * @return The parsed quest entry. + * @retval NULL in case of errors. + */ +struct quest_db *equest_read_db_sub(config_setting_t *cs, int *nPtr, const char *source) +{ + struct quest_db *entry = NULL; + config_setting_t *t = NULL; + int i32 = 0, quest_id; + const char *str = NULL; + const int n = *nPtr; + + /* + * Id: Quest ID [int] + * Name: Quest Name [string] + * TimeLimit: Time Limit (seconds) [int, optional] + * Targets: ( [array, optional] + * { + * MobId: Mob ID [int] + * Count: [int] + * }, + * ... (can repeated up to MAX_QUEST_OBJECTIVES times) + * ) + * Drops: ( + * { + * ItemId: Item ID to drop [int] + * Rate: Drop rate [int] + * MobId: Mob ID to match [int, optional] + * }, + * ... (can be repeated) + * ) + */ + + if (!libconfig->setting_lookup_int(cs, "Id", &quest_id)) { + ShowWarning("quest_read_db: Missing id in \"%s\", entry #%d, skipping.\n", source, n); + hookStop(); + return NULL; + } + if (quest_id < 0 || quest_id >= MAX_QUEST_DB) { + ShowWarning("quest_read_db: Invalid quest ID '%d' in \"%s\", entry #%d (min: 0, max: %d), skipping.\n", quest_id, source, n, MAX_QUEST_DB); + hookStop(); + return NULL; + } + + if (!libconfig->setting_lookup_string(cs, "Name", &str) || !*str) { + ShowWarning("quest_read_db_sub: Missing Name in quest %d of \"%s\", skipping.\n", quest_id, source); + hookStop(); + return NULL; + } + + CREATE(entry, struct quest_db, 1); + entry->id = quest_id; + //safestrncpy(entry->name, str, sizeof(entry->name)); + + if (libconfig->setting_lookup_int(cs, "TimeLimit", &i32)) // This is an unsigned value, do not check for >= 0 + entry->time = (unsigned int)i32; + + if ((t=libconfig->setting_get_member(cs, "Targets")) && config_setting_is_list(t)) { +/* + int i, len = libconfig->setting_length(t); + for (i = 0; i < len && entry->objectives_count < MAX_QUEST_OBJECTIVES; i++) { + // Note: We ensure that objectives_count < MAX_QUEST_OBJECTIVES because + // quest_log (as well as the client) expect this maximum size. + config_setting_t *tt = libconfig->setting_get_elem(t, i); + int mob_id = 0, count = 0; + if (!tt) + break; + if (!config_setting_is_group(tt)) + continue; + if (!libconfig->setting_lookup_int(tt, "MobId", &mob_id) || mob_id <= 0) + continue; + if (!libconfig->setting_lookup_int(tt, "Count", &count) || count <= 0) + continue; + RECREATE(entry->objectives, struct quest_objective, ++entry->objectives_count); + entry->objectives[entry->objectives_count-1].mob = mob_id; + entry->objectives[entry->objectives_count-1].count = count; + } +*/ + entry->objectives_count = 1; + RECREATE(entry->objectives, struct quest_objective, 1); + entry->objectives[0].mob = 1; + entry->objectives[0].count = 0; + } + + if ((t=libconfig->setting_get_member(cs, "Drops")) && config_setting_is_list(t)) { + int i, len = libconfig->setting_length(t); + for (i = 0; i < len; i++) { + config_setting_t *tt = libconfig->setting_get_elem(t, i); + int mob_id = 0, nameid = 0, rate = 0; + if (!tt) + break; + if (!config_setting_is_group(tt)) + continue; + if (!libconfig->setting_lookup_int(tt, "MobId", &mob_id)) + mob_id = 0; // Zero = any monster + if (mob_id < 0) + continue; + if (!libconfig->setting_lookup_int(tt, "ItemId", &nameid) || !itemdb->exists(nameid)) + continue; + if (!libconfig->setting_lookup_int(tt, "Rate", &rate) || rate <= 0) + continue; + RECREATE(entry->dropitem, struct quest_dropitem, ++entry->dropitem_count); + entry->dropitem[entry->dropitem_count-1].mob_id = mob_id; + entry->dropitem[entry->dropitem_count-1].nameid = nameid; + entry->dropitem[entry->dropitem_count-1].rate = rate; + } + } + hookStop(); + return entry; +} diff --git a/src/emap/quest.h b/src/emap/quest.h new file mode 100644 index 0000000..c947bcc --- /dev/null +++ b/src/emap/quest.h @@ -0,0 +1,9 @@ +// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// Copyright (c) 2014 Evol developers + +#ifndef EVOL_MAP_QUEST +#define EVOL_MAP_QUEST + +struct quest_db *equest_read_db_sub(config_setting_t *cs, int *nPtr, const char *source); + +#endif // EVOL_MAP_QUEST diff --git a/src/emap/script.c b/src/emap/script.c new file mode 100644 index 0000000..d492430 --- /dev/null +++ b/src/emap/script.c @@ -0,0 +1,1148 @@ +// 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 "map/chrif.h" +#include "map/clif.h" +#include "map/npc.h" +#include "map/pc.h" +#include "map/script.h" +#include "map/quest.h" +#include "map/unit.h" + +#include "emap/script.h" +#include "emap/clif.h" +#include "emap/lang.h" +#include "emap/scriptdefines.h" +#include "emap/send.h" +#include "emap/data/mapd.h" +#include "emap/data/npcd.h" +#include "emap/data/session.h" +#include "emap/struct/mapdext.h" +#include "emap/struct/npcdext.h" +#include "emap/struct/sessionext.h" +#include "emap/utils/formatutils.h" + +BUILDIN(l) +{ + format_sub(st, 1); + return true; +} + +BUILDIN(lg) +{ + format_sub(st, 2); + return true; +} + +BUILDIN(setCamNpc) +{ + getSD(); + TBL_NPC *nd = NULL; + + int x = 0; + int y = 0; + + if (script_hasdata(st, 2)) + { + nd = npc->name2id (script_getstr(st, 2)); + } + else + { + if (!st->oid) + { + ShowWarning("npc not attached\n"); + script->reportsrc(st); + return false; + } + + nd = (TBL_NPC *) map->id2bl (st->oid); + } + if (!nd) + { + ShowWarning("npc not found\n"); + script->reportsrc(st); + return false; + } + if (sd->bl.m != nd->bl.m) + { + ShowWarning("npc and player located in other maps\n"); + script->reportsrc(st); + return false; + } + + if (script_hasdata(st, 3) && script_hasdata(st, 4)) + { + x = script_getnum(st, 3); + y = script_getnum(st, 4); + } + + send_npccommand2(script->rid2sd (st), st->oid, 2, nd->bl.id, x, y); + + return true; +} + +BUILDIN(setCam) +{ + send_npccommand2(script->rid2sd (st), st->oid, 2, 0, + script_getnum(st, 2), script_getnum(st, 3)); + + return true; +} + +BUILDIN(moveCam) +{ + send_npccommand2(script->rid2sd (st), st->oid, 4, 0, + script_getnum(st, 2), script_getnum(st, 3)); + + return true; +} + +BUILDIN(restoreCam) +{ + getSD(); + send_npccommand(sd, st->oid, 3); + return true; +} + +BUILDIN(npcTalk3) +{ + const char *str; + char *msg; + TBL_NPC *nd = NULL; + + getSD(); + + if (script_hasdata(st, 3)) + { + nd = npc->name2id (script_getstr(st, 2)); + str = script_getstr(st, 3); + } + else + { + nd = (TBL_NPC *) map->id2bl (st->oid); + str = script_getstr(st, 2); + } + + if (!nd) + { + ShowWarning("npc not found\n"); + script->reportsrc(st); + return false; + } + + if (!str) + { + ShowWarning("error in string\n"); + script->reportsrc(st); + return false; + } + + if (sd) + msg = (char*)lang_pctrans (nd->name, sd); + else + msg = nd->name; + + if (!msg) + { + ShowWarning("error in string\n"); + script->reportsrc(st); + return false; + } + if (strlen(str) + strlen(msg) > 450) + { + ShowWarning("text message too big\n"); + script->reportsrc(st); + return false; + } + + if (nd) + { + char message[500]; + char name[500]; + strcpy (name, msg); + strtok(name, "#"); + strcpy (message, name); + strcat (message, " : "); + strcat (message, str); + send_local_message (sd->fd, &(nd->bl), message); + } + + return true; +} + +BUILDIN(closeDialog) +{ + getSD(); + send_npccommand(script->rid2sd (st), st->oid, 5); + return true; +} + +BUILDIN(shop) +{ + getSD(); + TBL_NPC *nd = npc->name2id (script_getstr(st, 2)); + if (!nd) + { + ShowWarning("shop npc not found\n"); + script->reportsrc(st); + return false; + } + + st->state = sd->state.dialog == 1 ? CLOSE : END; + clif->scriptclose(sd, st->oid); + + clif->npcbuysell (sd, nd->bl.id); + return true; +} + +BUILDIN(getItemLink) +{ + struct item_data *i_data; + char *item_name; + int item_id = 0; + + if (script_isstringtype(st, 2)) + { + i_data = itemdb->search_name (script_getstr(st, 2)); + } + else + { + item_id = script_getnum (st, 2); + i_data = itemdb->search (item_id); + } + + item_name = (char *) aCalloc (100, sizeof (char)); + TBL_PC *sd = script->rid2sd(st); + + if (sd) + { + int version = 0; + struct SessionExt *data = session_get_bysd(sd); + if (data) + version = data->clientVersion; + + if (i_data && version >= 7) + sprintf(item_name, "[@@%u|@@]", (unsigned)i_data->nameid); + else if (i_data) + sprintf(item_name, "[@@%u|%s@@]", (unsigned)i_data->nameid, lang_pctrans (i_data->jname, sd)); + else if (item_id > 0) + sprintf(item_name, "[@@%u|Unknown Item@@]", (unsigned)item_id); + else + sprintf(item_name, "[Unknown Item]"); + } + else + { + if (i_data) + sprintf(item_name, "[%s]", lang_pctrans (i_data->jname, sd)); + else + sprintf(item_name, "[Unknown Item]"); + } + + script_pushstr(st, item_name); + + return true; +} + +BUILDIN(requestLang) +{ + getSD(); + struct script_data* data; + int64 uid; + const char* name; + + data = script_getdata(st, 2); + if (!data_isreference(data)) + { + ShowError("script:requestlang: not a variable\n"); + script->reportsrc(st); + st->state = END; + return false; + } + uid = reference_getuid(data); + name = reference_getname(data); + + if (is_string_variable(name)) + { + ShowError("script:requestlang: not a variable\n"); + script->reportsrc(st); + return false; + } + + if (!sd->state.menu_or_input) + { + // first invocation, display npc input box + sd->state.menu_or_input = 1; + st->state = RERUNLINE; + + // send lang request + send_npccommand(script->rid2sd(st), st->oid, 0); + clif->scriptinputstr(sd, st->oid); + } + else + { + // take received text/value and store it in the designated variable + sd->state.menu_or_input = 0; + + int lng = -1; + if (*sd->npc_str) + lng = lang_getId(sd->npc_str); + script->set_reg(st, sd, uid, name, (void*)h64BPTRSIZE(lng), script_getref(st,2)); + st->state = RUN; + } + return true; +} + +BUILDIN(requestItem) +{ + getSD(); + struct script_data* data; + int64 uid; + const char* name; + + data = script_getdata(st, 2); + if (!data_isreference(data)) + { + ShowError("script:requestitem: not a variable\n"); + script->reportsrc(st); + st->state = END; + return false; + } + uid = reference_getuid(data); + name = reference_getname(data); + + if (is_string_variable(name)) + { + ShowError("script:requestlang: not a variable\n"); + script->reportsrc(st); + return false; + } + + if (!sd->state.menu_or_input) + { + // first invocation, display npc input box + sd->state.menu_or_input = 1; + st->state = RERUNLINE; + + // send item request + send_npccommand(script->rid2sd(st), st->oid, 10); + } + else + { + // take received text/value and store it in the designated variable + sd->state.menu_or_input = 0; + + int item = 0; + + if (!sd->npc_str) + { + ShowWarning("npc string not found\n"); + script->reportsrc(st); + return false; + } + + if (sscanf (sd->npc_str, "%5d", &item) < 1) + { + ShowWarning("input data is not item id\n"); + script->reportsrc(st); + return false; + } + + script->set_reg(st, sd, uid, name, (void*)h64BPTRSIZE(item), script_getref(st,2)); + st->state = RUN; + } + return true; +} + +BUILDIN(requestItems) +{ + getSD(); + struct script_data* data; + int64 uid; + const char* name; + + data = script_getdata(st, 2); + if (!data_isreference(data)) + { + ShowError("script:requestitem: not a variable\n"); + script->reportsrc(st); + st->state = END; + return false; + } + uid = reference_getuid(data); + name = reference_getname(data); + + if (!is_string_variable(name)) + { + ShowWarning("parameter is not variable\n"); + script->reportsrc(st); + return false; + } + + int count = 1; + + if (script_hasdata(st, 3)) + { + count = script_getnum(st, 3); + if (count < 0) + count = 1; + } + + if (!sd->state.menu_or_input) + { + // first invocation, display npc input box + sd->state.menu_or_input = 1; + st->state = RERUNLINE; + + // send item request with limit count + send_npccommand2(script->rid2sd (st), st->oid, 10, count, 0, 0); + } + else + { + // take received text/value and store it in the designated variable + sd->state.menu_or_input = 0; + + if (!sd->npc_str) + { + ShowWarning("npc string not found\n"); + script->reportsrc(st); + return false; + } + + script->set_reg(st, sd, uid, name, (void*)sd->npc_str, script_getref(st, 2)); + st->state = RUN; + } + return true; +} + +BUILDIN(setq) +{ + int i; + getSD(); + + int quest_id = script_getnum(st, 2); + int quest_value = script_getnum(st, 3); + + if (quest->check(sd, quest_id, HAVEQUEST) < 0) + quest->add(sd, quest_id); + ARR_FIND(0, sd->num_quests, i, sd->quest_log[i].quest_id == quest_id); + if (i == sd->num_quests) + { + ShowError("Quest with id=%d not found\n", quest_id); + script->reportsrc(st); + return false; + } + + sd->quest_log[i].count[0] = quest_value; + sd->save_quest = true; + if (map->save_settings & 64) + chrif->save(sd,0); + + eclif_quest_add(sd, &sd->quest_log[i]); + return true; +} + +BUILDIN(getq) +{ + int i; + getSDReturn(0); + + int quest_id = script_getnum(st, 2); + if (quest->check(sd, quest_id, HAVEQUEST) < 0) + { + script_pushint(st, 0); + return true; + } + ARR_FIND(0, sd->num_quests, i, sd->quest_log[i].quest_id == quest_id); + if (i == sd->num_quests) + { + script_pushint(st, 0); + return true; + } + script_pushint(st, sd->quest_log[i].count[0]); + return true; +} + +BUILDIN(setNpcDir) +{ + int newdir; + TBL_NPC *nd = 0; + + if (script_hasdata(st, 3)) + { + nd = npc->name2id (script_getstr(st, 2)); + newdir = script_getnum(st, 3); + } + else if (script_hasdata(st, 2)) + { + if (!st->oid) + { + ShowWarning("npc not found\n"); + script->reportsrc(st); + return false; + } + + nd = (TBL_NPC *) map->id2bl (st->oid); + newdir = script_getnum(st, 2); + } + if (!nd) + { + ShowWarning("npc not found\n"); + script->reportsrc(st); + return false; + } + + if (newdir < 0) + newdir = 0; + else if (newdir > 7) + newdir = 7; + + nd->dir = newdir; + npc->enable (nd->name, 1); + + return true; +} + +BUILDIN(rif) +{ + const char *str = 0; + if (script_getnum(st, 2)) + { + str = script_getstr(st, 3); + if (str) + script_pushstr(st, aStrdup(str)); + else + script_pushconststr(st, (char *)""); + } + else if (script_hasdata(st, 4)) + { + str = script_getstr(st, 4); + if (str) + script_pushstr(st, aStrdup(str)); + else + script_pushconststr(st, (char *)""); + } + else + { + script_pushconststr(st, (char *)""); + } + + return true; +} + +BUILDIN(countItemColor) +{ + int nameid, i; + int count = 0; + struct item_data* id = NULL; + + TBL_PC* sd = script->rid2sd(st); + if (!sd) + { + ShowWarning("player not attached\n"); + script->reportsrc(st); + return false; + } + + if (script_isstringtype(st, 2)) + { + // item name + id = itemdb->search_name(script_getstr(st, 2)); + } + else + { + // item id + id = itemdb->exists(script_getnum(st, 2)); + } + + if (id == NULL) + { + ShowError("buildin_countitem: Invalid item '%s'.\n", script_getstr(st,2)); // returns string, regardless of what it was + script->reportsrc(st); + script_pushint(st,0); + return false; + } + + nameid = id->nameid; + + for(i = 0; i < MAX_INVENTORY; i++) + { + if(sd->status.inventory[i].nameid == nameid) + count += sd->status.inventory[i].amount; + } + + script_pushint(st, count); + return true; +} + +BUILDIN(miscEffect) +{ + int type = script_getnum(st, 2); + struct block_list *bl = NULL; + + if (script_hasdata(st, 3)) + { + if (script_isstring(st, 3)) + { + TBL_PC *sd = map->nick2sd(script_getstr(st, 3)); + if (sd) + bl = &sd->bl; + } + else if (script_isint(st, 3)) + { + bl = map->id2bl(script_getnum(st, 3)); + } + } + + if (!bl) + { + TBL_PC *sd = script->rid2sd (st); + if (sd) + bl = &sd->bl; + } + if (bl) + clif->specialeffect(bl, type, AREA); + return true; +} + +BUILDIN(setMapMask) +{ + const char *const mapName = script_getstr(st, 2); + if (!mapName) + { + ShowWarning("invalid map name\n"); + script->reportsrc(st); + return false; + } + const int m = map->mapname2mapid(mapName); + if (m < 0) + { + ShowWarning("map not found\n"); + script->reportsrc(st); + return false; + } + getMapData(m); + + const int val = script_getnum(st, 3); + const unsigned int old = mapData->mask; + mapData->mask = val; + if (old != mapData->mask) + send_mapmask_brodcast(m, mapData->mask); + return true; +} + +BUILDIN(getMapMask) +{ + const char *const mapName = script_getstr(st, 2); + if (!mapName) + { + script_pushint(st, 0); + ShowWarning("invalid map name\n"); + script->reportsrc(st); + return false; + } + const int m = map->mapname2mapid(mapName); + if (m < 0) + { + script_pushint(st, 0); + ShowWarning("map not found\n"); + script->reportsrc(st); + return false; + } + getMapDataReturn(m, 0); + script_pushint(st, mapData->mask); + return true; +} + +BUILDIN(addMapMask) +{ + const char *const mapName = script_getstr(st, 2); + if (!mapName) + { + ShowWarning("invalid map name\n"); + script->reportsrc(st); + return false; + } + const int m = map->mapname2mapid(mapName); + if (m < 0) + { + ShowWarning("map not found\n"); + script->reportsrc(st); + return false; + } + getMapData(m); + const int val = script_getnum(st, 3); + const unsigned int old = mapData->mask; + mapData->mask |= val; + if (old != mapData->mask) + send_mapmask_brodcast(m, mapData->mask); + + return true; +} + +BUILDIN(removeMapMask) +{ + const char *const mapName = script_getstr(st, 2); + if (!mapName) + { + ShowWarning("invalid map name\n"); + script->reportsrc(st); + return true; + } + const int m = map->mapname2mapid(mapName); + if (m < 0) + { + ShowWarning("map not found\n"); + script->reportsrc(st); + return false; + } + getMapData(m); + const int val = script_getnum(st, 3); + const unsigned int old = mapData->mask; + mapData->mask |= val; + mapData->mask ^= val; + if (old != mapData->mask) + send_mapmask_brodcast(m, mapData->mask); + return true; +} + +BUILDIN(setNpcSex) +{ + TBL_NPC *nd = NULL; + int sex = 0; + if (script_hasdata(st, 3)) + { + nd = npc->name2id (script_getstr(st, 2)); + sex = script_getnum(st, 3); + } + else if (script_hasdata(st, 2)) + { + sex = script_getnum(st, 2); + } + else + { + ShowWarning("no parameters provided\n"); + script->reportsrc(st); + return false; + } + + if (!nd && !st->oid) + { + ShowWarning("npc not found\n"); + script->reportsrc(st); + return false; + } + + if (!nd) + nd = (TBL_NPC *) map->id2bl(st->oid); + + if (!nd || !nd->vd) + { + ShowWarning("npc not found\n"); + script->reportsrc(st); + return false; + } + + clif->clearunit_area(&nd->bl, CLR_OUTSIGHT); + nd->vd->sex = sex; + clif->spawn(&nd->bl); + return true; +} + +BUILDIN(showAvatar) +{ + int id = 0; + if (script_hasdata(st, 2)) + id = script_getnum(st, 2); + + send_npccommand2(script->rid2sd (st), st->oid, 6, id, 0, 0); + return true; +} + +BUILDIN(setAvatarDir) +{ + int newdir = script_getnum(st, 2); + + if (newdir < 0) + newdir = 0; + else if (newdir > 7) + newdir = 7; + + send_npccommand2(script->rid2sd (st), st->oid, 7, newdir, 0, 0); + return true; +} + +BUILDIN(setAvatarAction) +{ + send_npccommand2(script->rid2sd (st), st->oid, 8, script_getnum(st, 2), 0, 0); + return true; +} + +BUILDIN(clear) +{ + send_npccommand(script->rid2sd (st), st->oid, 9); + return true; +} + +BUILDIN(changeMusic) +{ + const char *const mapName = script_getstr(st, 2); + const char *const music = script_getstr(st, 3); + if (!music) + { + ShowWarning("invalid music file\n"); + script->reportsrc(st); + return false; + } + if (!mapName) + { + ShowWarning("invalid map file\n"); + script->reportsrc(st); + return false; + } + const int m = map->mapname2mapid(mapName); + if (m < 0) + { + ShowWarning("map not found\n"); + script->reportsrc(st); + return false; + } + + send_changemusic_brodcast(m, music); + return true; +} + +BUILDIN(setNpcDialogTitle) +{ + const char *const name = script_getstr(st, 2); + if (!name) + { + ShowWarning("invalid window title\n"); + script->reportsrc(st); + return false; + } + TBL_PC *sd = script->rid2sd (st); + if (!sd) + { + ShowWarning("player not attached\n"); + script->reportsrc(st); + return false; + } + + send_changenpc_title(sd, st->oid, name); + return true; +} + +BUILDIN(getMapName) +{ + TBL_PC *sd = script->rid2sd(st); + if (!sd) + { + script_pushstr(st, aStrdup("")); + ShowWarning("player not attached\n"); + script->reportsrc(st); + return false; + } + if (sd->bl.m == -1) + { + script_pushstr(st, aStrdup("")); + ShowWarning("invalid map\n"); + script->reportsrc(st); + return false; + } + script_pushstr(st, aStrdup(map->list[sd->bl.m].name)); + return true; +} + +BUILDIN(unequipById) +{ + int nameid = 0; + int i; + struct item_data *item_data; + TBL_PC *sd = script->rid2sd(st); + + if (sd == NULL) + { + ShowWarning("player not attached\n"); + script->reportsrc(st); + return false; + } + + nameid = script_getnum(st, 2); + if((item_data = itemdb->exists(nameid)) == NULL) + { + ShowWarning("item %d not found\n", nameid); + script->reportsrc(st); + return false; + } + for (i = 0; i < EQI_MAX; i++) + { + const int idx = sd->equip_index[i]; + if (idx >= 0) + { + if (sd->status.inventory[idx].nameid == nameid) + pc->unequipitem(sd, idx, 1 | 2); + } + } + return true; +} + +BUILDIN(isPcDead) +{ + TBL_PC *sd = script->rid2sd(st); + + if (sd == NULL) + { + ShowWarning("player not attached\n"); + script->reportsrc(st); + return false; + } + + script_pushint(st, pc_isdead(sd) ? 1 : 0); + return true; +} + +static int areatimer_sub(struct block_list *bl, va_list ap) +{ + int tick; + char *event; + TBL_PC *sd; + + tick = va_arg(ap, int); + event = va_arg(ap, char*); + + sd = (TBL_PC *)bl; + if (!pc->addeventtimer(sd, tick, event)) + { + if (sd) + ShowWarning("buildin_addtimer: Event timer is full, can't add new event timer. (cid:%d timer:%s)\n", sd->status.char_id, event); + } + return 0; +} + +BUILDIN(areaTimer) +{ + const char *const mapname = script_getstr(st, 2); + const int x1 = script_getnum(st, 3); + const int y1 = script_getnum(st, 4); + const int x2 = script_getnum(st, 5); + const int y2 = script_getnum(st, 6); + const int time = script_getnum(st, 7); + const char *const eventName = script_getstr(st, 8); + int m; + + if ((m = map->mapname2mapid(mapname)) < 0) + { + ShowWarning("map not found\n"); + script->reportsrc(st); + return false; + } + + map->foreachinarea(areatimer_sub, m, x1, y1, x2, y2, BL_PC, time, eventName); + + return true; +} + +static int buildin_getareadropitem_sub_del(struct block_list *bl, va_list ap) +{ + if (!bl) + return 0; + + const int item = va_arg(ap, int); + int *const amount = va_arg(ap, int *); + TBL_ITEM *drop = (TBL_ITEM *)bl; + + if (drop->item_data.nameid == item) + { + (*amount) += drop->item_data.amount; + map->clearflooritem(&drop->bl); + } + + return 0; +} + +BUILDIN(getAreaDropItem) +{ + const char *const str = script_getstr(st, 2); + int16 m; + int x0 = script_getnum(st, 3); + int y0 = script_getnum(st, 4); + int x1 = script_getnum(st, 5); + int y1 = script_getnum(st, 6); + int item; + int amount = 0; + + if (script_isstringtype(st, 7)) + { + const char *name = script_getstr(st, 7); + struct item_data *item_data = itemdb->search_name(name); + item = UNKNOWN_ITEM_ID; + if (item_data) + item = item_data->nameid; + } + else + { + item = script_getnum(st, 7); + } + + if ((m = map->mapname2mapid(str)) < 0) + { + script_pushint(st, -1); + ShowWarning("map not found\n"); + script->reportsrc(st); + return false; + } + + if (script_hasdata(st, 8) && script_getnum(st, 8)) + { + map->foreachinarea(buildin_getareadropitem_sub_del, + m, x0, y0, x1, y1, BL_ITEM, item, &amount); + } + else + { + map->foreachinarea(script->buildin_getareadropitem_sub, + m, x0, y0, x1, y1, BL_ITEM, item, &amount); + } + script_pushint(st, amount); + return true; +} + +enum setmount_type +{ + SETMOUNT_TYPE_NONE = 0, + SETMOUNT_TYPE_PECO = 1, + SETMOUNT_TYPE_WUG = 2, + SETMOUNT_TYPE_MADO = 3, + SETMOUNT_TYPE_DRAGON_GREEN = 4, + SETMOUNT_TYPE_DRAGON_BROWN = 5, + SETMOUNT_TYPE_DRAGON_GRAY = 6, + SETMOUNT_TYPE_DRAGON_BLUE = 7, + SETMOUNT_TYPE_DRAGON_RED = 8, + SETMOUNT_TYPE_MAX, + SETMOUNT_TYPE_DRAGON = SETMOUNT_TYPE_DRAGON_GREEN, +}; + +BUILDIN(setMount) +{ + int flag = SETMOUNT_TYPE_NONE; + TBL_PC* sd = script->rid2sd(st); + + if (sd == NULL) + return true; // no player attached, report source + + if (script_hasdata(st, 2)) + flag = script_getnum(st, 2); + + // Sanity checks and auto-detection + if (flag >= SETMOUNT_TYPE_DRAGON_GREEN && flag <= SETMOUNT_TYPE_DRAGON_RED) + { + if (pc->checkskill(sd, RK_DRAGONTRAINING)) + { + // Rune Knight (Dragon) + unsigned int option; + option = ( flag == SETMOUNT_TYPE_DRAGON_GREEN ? OPTION_DRAGON1 : + flag == SETMOUNT_TYPE_DRAGON_BROWN ? OPTION_DRAGON2 : + flag == SETMOUNT_TYPE_DRAGON_GRAY ? OPTION_DRAGON3 : + flag == SETMOUNT_TYPE_DRAGON_BLUE ? OPTION_DRAGON4 : + flag == SETMOUNT_TYPE_DRAGON_RED ? OPTION_DRAGON5 : + OPTION_DRAGON1); // default value + pc->setridingdragon(sd, option); + } + } + else if (flag == SETMOUNT_TYPE_WUG) + { + // Ranger (Warg) + if (pc->checkskill(sd, RA_WUGRIDER)) + pc->setridingwug(sd, true); + } + else if (flag == SETMOUNT_TYPE_MADO) + { + // Mechanic (Mado Gear) + if (pc->checkskill(sd, NC_MADOLICENCE)) + pc->setmadogear(sd, true); + } + else if (flag == SETMOUNT_TYPE_PECO) + { + // Knight / Crusader (Peco Peco) + if (pc->checkskill(sd, KN_RIDING)) + pc->setridingpeco(sd, true); + } + else if (flag == SETMOUNT_TYPE_NONE && pc_hasmount(sd)) + { + if (pc_isridingdragon(sd)) + { + pc->setridingdragon(sd, 0); + } + if (pc_isridingwug(sd)) + { + pc->setridingwug(sd, false); + } + if (pc_ismadogear(sd)) + { + pc->setmadogear(sd, false); + } + if (pc_isridingpeco(sd)) + { + pc->setridingpeco(sd, false); + } + } + + return true; +} + +BUILDIN(clientCommand) +{ + TBL_PC* sd = script->rid2sd(st); + + if (sd == NULL) + { + ShowWarning("player not attached\n"); + script->reportsrc(st); + return false; + } + const char *const command = script_getstr(st, 2); + if (!command) + { + ShowWarning("invalid client command\n"); + script->reportsrc(st); + return false; + } + send_client_command(sd, command); + return true; +} + +BUILDIN(isUnitWalking) +{ + int id = 0; + if (script_hasdata(st, 2)) + id = script_getnum(st, 2); + else + id = st->oid; + struct block_list *bl = map->id2bl(id); + if (!bl) + { + ShowWarning("invalid unit id\n"); + script->reportsrc(st); + script_pushint(st, 0); + return false; + } + struct unit_data *ud = unit->bl2ud(bl); + if (!ud) + { + ShowWarning("invalid unit data\n"); + script->reportsrc(st); + script_pushint(st, 0); + return false; + } + script_pushint(st, ud->walktimer != INVALID_TIMER); + return true; +} diff --git a/src/emap/script.h b/src/emap/script.h new file mode 100644 index 0000000..41c96ee --- /dev/null +++ b/src/emap/script.h @@ -0,0 +1,46 @@ +// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// Copyright (c) 2014 Evol developers + +#ifndef EVOL_MAP_SCRIPT +#define EVOL_MAP_SCRIPT + +BUILDIN(l); +BUILDIN(lg); +BUILDIN(setCamNpc); +BUILDIN(setCam); +BUILDIN(moveCam); +BUILDIN(restoreCam); +BUILDIN(npcTalk3); +BUILDIN(closeDialog); +BUILDIN(shop); +BUILDIN(getItemLink); +BUILDIN(requestLang); +BUILDIN(requestItem); +BUILDIN(requestItems); +BUILDIN(getq); +BUILDIN(setq); +BUILDIN(setNpcDir); +BUILDIN(rif); +BUILDIN(countItemColor); +BUILDIN(miscEffect); +BUILDIN(setMapMask); +BUILDIN(getMapMask); +BUILDIN(addMapMask); +BUILDIN(removeMapMask); +BUILDIN(setNpcSex); +BUILDIN(showAvatar); +BUILDIN(setAvatarDir); +BUILDIN(setAvatarAction); +BUILDIN(clear); +BUILDIN(changeMusic); +BUILDIN(setNpcDialogTitle); +BUILDIN(getMapName); +BUILDIN(unequipById); +BUILDIN(isPcDead); +BUILDIN(areaTimer); +BUILDIN(getAreaDropItem); +BUILDIN(setMount); +BUILDIN(clientCommand); +BUILDIN(isUnitWalking); + +#endif // EVOL_MAP_SCRIPT diff --git a/src/emap/scriptdefines.h b/src/emap/scriptdefines.h new file mode 100644 index 0000000..1a6cf14 --- /dev/null +++ b/src/emap/scriptdefines.h @@ -0,0 +1,55 @@ +// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// Copyright (c) 2014 Evol developers + +#ifndef EVOL_MAP_SCRIPTDEFINES +#define EVOL_MAP_SCRIPTDEFINES + +#define getSessionDataReturn(def) \ + if (!st->rid) \ + { \ + script_pushint(st, def); \ + return true; \ + } \ + TBL_PC *sd = script->rid2sd(st); \ + if (!sd) \ + { \ + script_pushint(st, def); \ + return true; \ + } \ + struct SessionExt *data = session_get(sd->fd) + +#define getSessionData() \ + if (!st->rid) \ + return true; \ + TBL_PC *sd = script->rid2sd(st); \ + if (!sd) \ + return true; \ + struct SessionExt *data = session_get(sd->fd) + +#define getMapData(m) \ + struct MapdExt *mapData = mapd_get(m); \ + if (!mapData) \ + return true; + +#define getMapDataReturn(m, def) \ + struct MapdExt *mapData = mapd_get(m); \ + if (!mapData) \ + { \ + script_pushint(st, def); \ + return true; \ + } + +#define getSD() \ + TBL_PC *sd = script->rid2sd(st); \ + if (!sd) \ + return true + +#define getSDReturn(def) \ + TBL_PC *sd = script->rid2sd(st); \ + if (!sd) \ + { \ + script_pushint(st, def); \ + return true; \ + } + +#endif // EVOL_MAP_SCRIPTDEFINES diff --git a/src/emap/send.c b/src/emap/send.c new file mode 100644 index 0000000..6f3f257 --- /dev/null +++ b/src/emap/send.c @@ -0,0 +1,305 @@ +// 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 "map/clif.h" +#include "map/mob.h" +#include "map/npc.h" +#include "map/pc.h" +#include "map/pet.h" +#include "map/unit.h" + +#include "emap/send.h" +#include "emap/permission.h" +#include "emap/data/session.h" +#include "emap/struct/sessionext.h" + +void send_npccommand (TBL_PC *sd, int npcId, int cmd) +{ + if (!sd) + return; + + int fd = sd->fd; + WFIFOHEAD (fd, 16); + WFIFOW (fd, 0) = 0xB00; + WFIFOL (fd, 2) = npcId; + WFIFOW (fd, 6) = cmd; + WFIFOL (fd, 8) = 0; + WFIFOW (fd, 12) = 0; + WFIFOW (fd, 14) = 0; + WFIFOSET (fd, 16); +} + +// 0 - get client lang +void send_npccommand2 (TBL_PC *sd, int npcId, int cmd, int id, int x, int y) +{ + if (!sd) + return; + + int fd = sd->fd; + WFIFOHEAD (fd, 16); + WFIFOW (fd, 0) = 0xB00; + WFIFOL (fd, 2) = npcId; + WFIFOW (fd, 6) = cmd; + WFIFOL (fd, 8) = id; + WFIFOW (fd, 12) = x; + WFIFOW (fd, 14) = y; + WFIFOSET (fd, 16); +} + +void send_local_message(int fd, struct block_list* bl, const char* msg) +{ + if (!msg || !bl) + return; + unsigned short msg_len = strlen(msg) + 1; + uint8 buf[256]; + + int len = sizeof(buf) - 8; + if (msg_len > len) + { + ShowWarning("clif_message: Truncating too long message '%s' (len=%u).\n", msg, msg_len); + msg_len = len; + } + + WFIFOHEAD (fd, msg_len + 8); + WFIFOW (fd, 0) = 0x8d; + WFIFOW (fd, 2) = msg_len + 8; + WFIFOL (fd, 4) = bl->id; + safestrncpy((char*)WFIFOP(fd, 8), msg, msg_len); + WFIFOSET (fd, msg_len + 8); +} + +void send_changelook(int fd, int id, int type, int val) +{ + WFIFOHEAD (fd, 11); + WFIFOW (fd, 0) = 0x1d7; + WFIFOL (fd, 2) = id; + WFIFOB (fd, 6) = type; + WFIFOW (fd, 7) = val; + WFIFOW (fd, 9) = 0; + WFIFOSET (fd, 11); +} + +void send_mapmask(int fd, int mask) +{ + WFIFOHEAD (fd, 10); + WFIFOW (fd, 0) = 0xb02; + WFIFOL (fd, 2) = mask; + WFIFOL (fd, 6) = 0; + WFIFOSET (fd, 10); +} + +void send_mapmask_brodcast(const int map, const int mask) +{ + struct block_list bl; + char buf[10]; + + bl.m = map; + WBUFW (buf, 0) = 0xb02; + WBUFL (buf, 2) = mask; + WBUFL (buf, 6) = 0; + clif->send(buf, 10, &bl, ALL_SAMEMAP); +} + +void send_mob_info(struct block_list* bl1, struct block_list* bl2, + enum send_target target) +{ + if (!bl1 || bl1->type != BL_MOB) + return; + + char buf[12]; + TBL_MOB *md = (TBL_MOB *)bl1; + + WBUFW (buf, 0) = 0xb03; + WBUFW (buf, 2) = 12; // len + WBUFL (buf, 4) = md->bl.id; + WBUFL (buf, 8) = md->status.rhw.range; + + clif->send(&buf, sizeof(buf), bl2, target); +} + +void send_pc_info(struct block_list* bl1, + struct block_list* bl2, + enum send_target target) +{ + if (!bl1 || bl1->type != BL_PC) + return; + + char buf[12]; + TBL_PC *sd = (TBL_PC *)bl1; + struct SessionExt *data = session_get_bysd(sd); + if (!data) + return; + + TBL_PC *tsd = (TBL_PC *)bl2; + if (tsd) + { + struct SessionExt *tdata = session_get_bysd(tsd); + if (!tdata || tdata->clientVersion < 4) + return; + } + + WBUFW (buf, 0) = 0xb0a; + WBUFW (buf, 2) = 12; // len + WBUFL (buf, 4) = sd->bl.id; + if (pc_has_permission(sd, permission_send_gm_flag)) + WBUFL (buf, 8) = sd->group_id; + else + WBUFL (buf, 8) = 0; + + clif->send(&buf, sizeof(buf), bl2, target); +} + +void send_npc_info(struct block_list* bl1, + struct block_list* bl2, + enum send_target target) +{ + if (!bl1 || bl1->type != BL_NPC) + return; + + TBL_PC *tsd = (TBL_PC *)bl2; + if (tsd) + { + struct SessionExt *tdata = session_get_bysd(tsd); + if (!tdata || tdata->clientVersion < 5) + return; + } + + TBL_NPC *const nd = (TBL_NPC*)bl1; + + char buf[12]; + WBUFW (buf, 0) = 0xb0b; + WBUFW (buf, 2) = 12; // len + WBUFL (buf, 4) = nd->bl.id; + WBUFL (buf, 8) = nd->area_size; + + clif->send(&buf, sizeof(buf), bl2, target); +} + +void send_advmoving(struct unit_data* ud, struct block_list *tbl, enum send_target target) +{ + if (!ud) + return; + + struct block_list *bl = ud->bl; + + if (ud->walkpath.path_len <= ud->walkpath.path_pos) + return; + const bool haveMoves = (ud->walkpath.path_len > ud->walkpath.path_pos); + + int i = 14; + const int len = ud->walkpath.path_len - ud->walkpath.path_pos; + if (haveMoves) + i += len; + + char *buf; + CREATE(buf, char, i); + WBUFW (buf, 0) = 0xb04; + WBUFW (buf, 2) = i; + WBUFL (buf, 4) = bl->id; + WBUFW (buf, 8) = status->get_speed(bl); + WBUFW (buf, 10) = bl->x; + WBUFW (buf, 12) = bl->y; + if (haveMoves) + memcpy(buf + 14, ud->walkpath.path + ud->walkpath.path_pos, len); + clif->send(buf, i, tbl, target); + aFree(buf); +} + +void send_changemusic_brodcast(const int map, const char *music) +{ + if (!music) + return; + + struct block_list bl; + const int sz = strlen (music) + 5; + char *buf; + + CREATE(buf, char, sz); + bl.m = map; + WBUFW (buf, 0) = 0xb05; + WBUFW (buf, 2) = sz; + strcpy ((char *)WBUFP (buf, 4), music); + clif->send (buf, sz, &bl, ALL_SAMEMAP); + aFree(buf); +} + +void send_changenpc_title (TBL_PC *sd, const int npcId, const char *name) +{ + if (!sd || !name) + return; + + const int fd = sd->fd; + const int len = strlen (name); + const int sz = len + 5 + 4 + 2; + WFIFOHEAD (fd, sz); + WFIFOW (fd, 0) = 0xb06; + WFIFOW (fd, 2) = sz; + WFIFOL (fd, 4) = npcId; + WFIFOW (fd, 8) = len; + strcpy ((char*)WFIFOP (fd, 10), name); + WFIFOSET (fd, sz); +} + +void send_join_ack(int fd, const char *const name, int flag) +{ + if (!name) + return; + + WFIFOHEAD (fd, 27); + WFIFOW (fd, 0) = 0xb08; + safestrncpy ((char*)WFIFOP (fd, 2), name, 24); + WFIFOB (fd, 26) = flag; + WFIFOSET (fd, 27); +} + +void send_slave_say(TBL_PC *sd, + struct block_list *bl, + const char *const name, + const char *const message) +{ + const int len = 24 + 7 + strlen(message); + char *buf = NULL; + CREATE(buf, char, len); + + snprintf(buf, len, "%s's %s : %s", sd->status.name, name, message); + buf[len - 1] = 0; + clif->GlobalMessage(bl, buf); + aFree(buf); +} + +void send_online_list(int fd, const char *buf, unsigned size) +{ + if (!buf) + return; + const unsigned int len = size + 4 + 1; + WFIFOHEAD (fd, len); + WFIFOW (fd, 0) = 0xb10; + WFIFOW (fd, 2) = len; + memcpy (WFIFOP (fd, 4), buf, size); + WFIFOB (fd, size + 4) = 0; + WFIFOSET (fd, len); +} + +void send_client_command(TBL_PC *sd, const char *const command) +{ + struct SessionExt *data = session_get_bysd(sd); + if (!data || data->clientVersion < 8) + return; + + const unsigned int len = strlen(command); + const int fd = sd->fd; + WFIFOHEAD (fd, len); + WFIFOW (fd, 0) = 0xb16; + WFIFOW (fd, 2) = len + 4; + memcpy (WFIFOP (fd, 4), command, len); + WFIFOSET (fd, len + 4); +} diff --git a/src/emap/send.h b/src/emap/send.h new file mode 100644 index 0000000..efa89ad --- /dev/null +++ b/src/emap/send.h @@ -0,0 +1,31 @@ +// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// Copyright (c) 2014 Evol developers + +#ifndef EVOL_MAP_PC +#define EVOL_MAP_PC + +void send_npccommand (TBL_PC *sd, int npcId, int cmd); +void send_npccommand2 (TBL_PC *sd, int npcId, int cmd, int id, int x, int y); +void send_local_message(int fd, struct block_list* bl, const char* msg); +void send_changelook(int fd, int id, int type, int val); +void send_mapmask(int fd, int mask); +void send_mapmask_brodcast(const int map, const int mask); +void send_mob_info(struct block_list* bl1, struct block_list* bl2, enum send_target target); +void send_advmoving(struct unit_data* ud, struct block_list *tbl, enum send_target target); +void send_changemusic_brodcast(const int map, const char *music); +void send_changenpc_title (TBL_PC *sd, const int npcId, const char *name); +void send_join_ack(int fd, const char *const name, int flag); +void send_pc_info(struct block_list* bl1, + struct block_list* bl2, + enum send_target target); +void send_npc_info(struct block_list* bl1, + struct block_list* bl2, + enum send_target target); +void send_slave_say(TBL_PC *sd, + struct block_list *bl, + const char *const name, + const char *const message); +void send_online_list(int fd, const char *buf, unsigned size); +void send_client_command(TBL_PC *sd, const char *const command); + +#endif // EVOL_MAP_PC diff --git a/src/emap/skill.c b/src/emap/skill.c new file mode 100644 index 0000000..b909feb --- /dev/null +++ b/src/emap/skill.c @@ -0,0 +1,44 @@ +// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// Copyright (c) 2014 Evol developers + +#include +#include +#include + +#include "common/db.h" +#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 "map/pc.h" +#include "map/npc.h" +#include "map/script.h" + +int eskill_check_condition_castend_post(int retVal, + TBL_PC* sd, + uint16 *skill_id, + uint16 *skill_lv) +{ + if (retVal && sd) + { + struct linkdb_node **label_linkdb = strdb_get(npc->ev_label_db, "OnSkillInvoke"); + if (label_linkdb == NULL) + return retVal; + + struct linkdb_node *node = *label_linkdb; + while (node) + { + struct event_data* ev = node->data; + if (ev) + { + pc->setreg(sd, script->add_str("@skillId"), *skill_id); + pc->setreg(sd, script->add_str("@skillLv"), *skill_lv); + script->run(ev->nd->u.scr.script, ev->pos, sd->bl.id, ev->nd->bl.id); + } + node = node->next; + } + } + return retVal; +} diff --git a/src/emap/skill.h b/src/emap/skill.h new file mode 100644 index 0000000..132e909 --- /dev/null +++ b/src/emap/skill.h @@ -0,0 +1,12 @@ +// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// Copyright (c) 2014 Evol developers + +#ifndef EVOL_MAP_SKILL +#define EVOL_MAP_SKILL + +int eskill_check_condition_castend_post(int retVal, + TBL_PC* sd, + uint16 *skill_id, + uint16 *skill_lv); + +#endif // EVOL_MAP_SKILL diff --git a/src/emap/status.c b/src/emap/status.c new file mode 100644 index 0000000..6f853d5 --- /dev/null +++ b/src/emap/status.c @@ -0,0 +1,70 @@ +// 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 "map/itemdb.h" +#include "map/map.h" +#include "map/npc.h" +#include "map/pc.h" +#include "map/status.h" + +#include "emap/data/npcd.h" +#include "emap/struct/npcdext.h" + +int class_move_speed[CLASS_COUNT]; + +void status_init(void) +{ + int f; + for (f = 0; f < CLASS_COUNT; f ++) + class_move_speed[f] = 150; +} + +void estatus_set_viewdata_post(struct block_list *bl, + int *class_ __attribute__ ((unused))) +{ + if (!bl) + return; + if (bl->type != BL_NPC) + return; + TBL_NPC *const npc = (TBL_NPC*)bl; + struct NpcdExt *data = npcd_get(npc); + if (data && data->init == false && npc->vd) + { + data->init = true; + npc->vd->sex = 3; + } +} + +void estatus_read_job_db_sub(int *idxPtr, + const char *name __attribute__ ((unused)), + config_setting_t *jdb) +{ + int i32 = 0; + const int idx = *idxPtr; + if (itemdb->lookup_const(jdb, "MoveSpeed", &i32)) + class_move_speed[idx] = i32; +} + +int estatus_calc_pc_(int retVal, + struct map_session_data *sd, + enum e_status_calc_opt *opt __attribute__ ((unused))) +{ + if (!sd) + return retVal; + + if (!sd->state.permanent_speed) + { + const int idx = pc->class2idx(sd->status.class_); + sd->base_status.speed = class_move_speed[idx]; + } + return retVal; +} diff --git a/src/emap/status.h b/src/emap/status.h new file mode 100644 index 0000000..fb0198b --- /dev/null +++ b/src/emap/status.h @@ -0,0 +1,12 @@ +// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// Copyright (c) 2014 Evol developers + +#ifndef EVOL_MAP_STATUS +#define EVOL_MAP_STATUS + +void status_init(void); +void estatus_set_viewdata_post(struct block_list *bl, int *class_); +void estatus_read_job_db_sub(int *idxPtr, const char *name, config_setting_t *jdb); +int estatus_calc_pc_(int retVal, struct map_session_data* sd, enum e_status_calc_opt *opt); + +#endif // EVOL_MAP_STATUS diff --git a/src/emap/struct/itemdext.h b/src/emap/struct/itemdext.h new file mode 100644 index 0000000..8d4a555 --- /dev/null +++ b/src/emap/struct/itemdext.h @@ -0,0 +1,33 @@ +// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// Copyright (c) 2014 Evol developers + +#ifndef EVOL_MAP_ITEMDEXT +#define EVOL_MAP_ITEMDEXT + +struct ItemdExt +{ + int floorLifeTime; + + int requiredStr; + int requiredAgi; + int requiredVit; + int requiredInt; + int requiredDex; + int requiredLuk; + int requiredMaxHp; + int requiredMaxSp; + int requiredAtk; + int requiredMAtkMin; + int requiredMAtkMax; + int requiredDef; + int requiredMDef; + + int useEffect; + int useFailEffect; + int unequipEffect; + int unequipFailEffect; + + bool allowPickup; +}; + +#endif // EVOL_MAP_ITEMDEXT diff --git a/src/emap/struct/mapdext.h b/src/emap/struct/mapdext.h new file mode 100644 index 0000000..15fee7f --- /dev/null +++ b/src/emap/struct/mapdext.h @@ -0,0 +1,17 @@ +// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// Copyright (c) 2014 Evol developers + +#ifndef EVOL_MAP_MAPDEXT +#define EVOL_MAP_MAPDEXT + +struct MapdExt +{ + unsigned int mask; + bool invisible; + struct MapdExtFlag + { + unsigned nopve : 1; + } flag; +}; + +#endif // EVOL_MAP_MAPDEXT diff --git a/src/emap/struct/npcdext.h b/src/emap/struct/npcdext.h new file mode 100644 index 0000000..2158f2c --- /dev/null +++ b/src/emap/struct/npcdext.h @@ -0,0 +1,12 @@ +// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// Copyright (c) 2014 Evol developers + +#ifndef EVOL_MAP_NPCDEXT +#define EVOL_MAP_NPCDEXT + +struct NpcdExt +{ + bool init; +}; + +#endif // EVOL_MAP_NPCDEXT diff --git a/src/emap/struct/sessionext.h b/src/emap/struct/sessionext.h new file mode 100644 index 0000000..a592e50 --- /dev/null +++ b/src/emap/struct/sessionext.h @@ -0,0 +1,15 @@ +// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// Copyright (c) 2014 Evol developers + +#ifndef EVOL_MAP_SESSIONEXT +#define EVOL_MAP_SESSIONEXT + +struct SessionExt +{ + time_t onlinelistlasttime; + int clientVersion; + int language; + uint8 state; +}; + +#endif // EVOL_MAP_SESSIONEXT diff --git a/src/emap/unit.c b/src/emap/unit.c new file mode 100644 index 0000000..54dca56 --- /dev/null +++ b/src/emap/unit.c @@ -0,0 +1,163 @@ +// 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 "map/unit.h" +#include "map/map.h" +#include "map/mob.h" +#include "map/pc.h" +#include "map/skill.h" +#include "map/status.h" + +#include "emap/unit.h" + +int eunit_can_move(struct block_list *bl) +{ + TBL_PC *sd; + struct unit_data *ud; + struct status_change *sc; + + if (!bl) + { + hookStop(); + return 0; + } + ud = unit->bl2ud(bl); + sc = status->get_sc(bl); + sd = BL_CAST(BL_PC, bl); + + if (!ud) + { + hookStop(); + return 0; + } + + if (ud->skilltimer != INVALID_TIMER + && ud->skill_id != LG_EXEEDBREAK + && (!sd + || !pc->checkskill(sd, SA_FREECAST) + || skill->get_inf2(ud->skill_id)&INF2_GUILD_SKILL)) + { + hookStop(); + return 0; // prevent moving while casting + } + + if (DIFF_TICK(ud->canmove_tick, timer->gettick()) > 0) + { + hookStop(); + return 0; + } + + if (sd && ( + sd->state.vending || + sd->state.buyingstore || + sd->state.blockedmove)) + { + hookStop(); + return 0; //Can't move + } + + // Status changes that block movement + if (sc) + { + if (sc->count && ( + sc->data[SC_ANKLESNARE] + || sc->data[SC_AUTOCOUNTER] + || sc->data[SC_TRICKDEAD] + || sc->data[SC_BLADESTOP] + || sc->data[SC_BLADESTOP_WAIT] + || (sc->data[SC_GOSPEL] && sc->data[SC_GOSPEL]->val4 == BCT_SELF) // cannot move while gospel is in effect + || (sc->data[SC_BASILICA] && sc->data[SC_BASILICA]->val4 == bl->id) // Basilica caster cannot move + || sc->data[SC_STOP] + || sc->data[SC_FALLENEMPIRE] + || sc->data[SC_RG_CCONFINE_M] + || sc->data[SC_RG_CCONFINE_S] + || sc->data[SC_GS_MADNESSCANCEL] + || (sc->data[SC_GRAVITATION] && sc->data[SC_GRAVITATION]->val3 == BCT_SELF) + || sc->data[SC_WHITEIMPRISON] + || sc->data[SC_ELECTRICSHOCKER] + || sc->data[SC_WUGBITE] + || sc->data[SC_THORNS_TRAP] + || ( sc->data[SC_MAGNETICFIELD] && !sc->data[SC_HOVERING] ) + || sc->data[SC__MANHOLE] + || sc->data[SC_CURSEDCIRCLE_ATKER] + || sc->data[SC_CURSEDCIRCLE_TARGET] + || (sc->data[SC_COLD] && bl->type != BL_MOB) + || sc->data[SC_DEEP_SLEEP] + || (sc->data[SC_CAMOUFLAGE] && sc->data[SC_CAMOUFLAGE]->val1 < 3 && !(sc->data[SC_CAMOUFLAGE]->val3&1)) + || sc->data[SC_MEIKYOUSISUI] + || sc->data[SC_KG_KAGEHUMI] + || sc->data[SC_NEEDLE_OF_PARALYZE] + || sc->data[SC_VACUUM_EXTREME] + || (sc->data[SC_FEAR] && sc->data[SC_FEAR]->val2 > 0) + || (sc->data[SC_SPIDERWEB] && sc->data[SC_SPIDERWEB]->val1) + || (sc->data[SC_CLOAKING] && sc->data[SC_CLOAKING]->val1 < 3 && !(sc->data[SC_CLOAKING]->val4&1)) //Need wall at level 1-2 + || ( + sc->data[SC_DANCING] && sc->data[SC_DANCING]->val4 + && ( + !sc->data[SC_LONGING] + || (sc->data[SC_DANCING]->val1&0xFFFF) == CG_MOONLIT + || (sc->data[SC_DANCING]->val1&0xFFFF) == CG_HERMODE)))) + { + hookStop(); + return 0; + } + if (sc->opt1 > 0 + && sc->opt1 != OPT1_STONEWAIT + && sc->opt1 != OPT1_BURNING + && !(sc->opt1 == OPT1_CRYSTALIZE + && bl->type == BL_MOB)) + { + hookStop(); + return 0; + } + + if ((sc->option & OPTION_HIDE) && (!sd || pc->checkskill(sd, RG_TUNNELDRIVE) <= 0)) + { + hookStop(); + return 0; + } + } + + // Icewall walk block special trapped monster mode + if(bl->type == BL_MOB) + { + TBL_MOB *md = BL_CAST(BL_MOB, bl); + if(md && ((md->status.mode&MD_BOSS && battle->bc->boss_icewall_walk_block == 1 && map->getcell(bl->m,bl->x,bl->y,CELL_CHKICEWALL)) + || (!(md->status.mode&MD_BOSS) && battle->bc->mob_icewall_walk_block == 1 && map->getcell(bl->m,bl->x,bl->y,CELL_CHKICEWALL)))) + { + md->walktoxy_fail_count = 1; //Make sure rudeattacked skills are invoked + hookStop(); + return 0; + } + } + + hookStop(); + return 1; +} + +int eunit_walktoxy(struct block_list *bl __attribute__ ((unused)), + short *x __attribute__ ((unused)), + short *y __attribute__ ((unused)), + int *flagPtr) +{ + // reset flag "Search for an unoccupied cell and cancel if none available" + // this reduce CPU usage and allow mobs to walk on each other. + if ((*flagPtr)&8) + *flagPtr = ((*flagPtr) | 8) ^ 8; + + TBL_PC *sd = BL_CAST(BL_PC, bl); + if (sd && pc_issit(sd)) + pc->setstand(sd); + + return 1; +} diff --git a/src/emap/unit.h b/src/emap/unit.h new file mode 100644 index 0000000..675bf0e --- /dev/null +++ b/src/emap/unit.h @@ -0,0 +1,10 @@ +// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// Copyright (c) 2014 Evol developers + +#ifndef EVOL_MAP_UNIT +#define EVOL_MAP_UNIT + +int eunit_can_move(struct block_list *bl); +int eunit_walktoxy(struct block_list *bl, short *x, short *y, int *flagPtr); + +#endif // EVOL_MAP_UNIT diff --git a/src/emap/utils/formatutils.c b/src/emap/utils/formatutils.c new file mode 100644 index 0000000..70a7541 --- /dev/null +++ b/src/emap/utils/formatutils.c @@ -0,0 +1,116 @@ +// 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 "map/script.h" + +#include "map/chrif.h" +#include "map/clif.h" +#include "map/npc.h" +#include "map/pc.h" +#include "map/script.h" +#include "map/quest.h" + +#include "emap/utils/formatutils.h" +#include "emap/lang.h" + +int format_sub(struct script_state* st, int translate) +{ + TBL_PC *sd = NULL; + if (translate) + sd = script->rid2sd(st); + + if (!script_hasdata(st, 3)) + { + if (sd) + { + if (translate == 2) + { + char *buf = aCalloc (strlen(script_getstr(st, 2)) + 3, sizeof(char)); + strcpy (buf, script_getstr(st, 2)); + if (sd->status.sex) + strcat (buf, "#1"); + else + strcat (buf, "#0"); + script_pushstr(st, aStrdup(lang_pctrans(buf, sd))); + aFree (buf); + } + else + { + script_pushstr(st, aStrdup(lang_pctrans(script_getstr(st, 2), sd))); + } + } + else + { + script_pushstr(st, aStrdup(script_getstr(st, 2))); + } + return 1; + } + + char *line = (char *) aCalloc (550, sizeof (char)); + int idx = 3; + if (sd) + { + if (translate == 2) + { + const char *str = NULL; + char *buf = NULL; + if (sd->status.sex) + { + str = script_getstr(st, 3); + buf = aCalloc (strlen(str) + 3, sizeof(char)); + strcpy (buf, str); + strcat (buf, "#1"); + } + else + { + str = script_getstr(st, 2); + buf = aCalloc (strlen(str) + 3, sizeof(char)); + strcpy (buf, str); + strcat (buf, "#0"); + } + strcpy(line, lang_pctrans(buf, sd)); + aFree (buf); + idx = 4; + } + else + { + strcpy(line, lang_pctrans(script_getstr(st, 2), sd)); + } + } + else + { + strcpy(line, script_getstr(st, 2)); + } + + char *ptr = line; + int sz = strlen(line); + while (script_hasdata(st, idx)) + { + char *tmp = strstr(ptr, "@@"); + if (!tmp) + break; + const char *item = script_getstr(st, idx); + int len = strlen(item); + if (len > 50) + break; + sz += len - 2; + if (sz > 490) + break; + memmove(tmp + len, tmp + 2, strlen(tmp + 2)); + memcpy(tmp, item, len); + ptr = tmp + len; + idx ++; + } + + script_pushstr(st, line); + return 0; +} diff --git a/src/emap/utils/formatutils.h b/src/emap/utils/formatutils.h new file mode 100644 index 0000000..361ad84 --- /dev/null +++ b/src/emap/utils/formatutils.h @@ -0,0 +1,9 @@ +// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// Copyright (c) 2014 Evol developers + +#ifndef EVOL_MAP_UTILS_FORMATUTILS +#define EVOL_MAP_UTILS_FORMATUTILS + +int format_sub(struct script_state* st, int translate); + +#endif // EVOL_MAP_UTILS_FORMATUTILS diff --git a/src/login/config.c b/src/login/config.c deleted file mode 100644 index d6ea4bd..0000000 --- a/src/login/config.c +++ /dev/null @@ -1,43 +0,0 @@ -// 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 "login/config.h" - -char *update_server = NULL; -char *inter_server_ip = NULL; - -void config_update_server(const char *val) -{ - update_server = aStrdup(val); -} - -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_final(void) -{ - if (update_server) - aFree(update_server); - if (inter_server_ip) - aFree(inter_server_ip); -} diff --git a/src/login/config.h b/src/login/config.h deleted file mode 100644 index ad63371..0000000 --- a/src/login/config.h +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. -// Copyright (c) 2014 Evol developers - -#ifndef EVOL_LOGIN_CONFIG -#define EVOL_LOGIN_CONFIG - -void config_update_server(const char *val); -void config_final(void); -void config_inter_server_ip(const char *val); - -extern char *update_server; -extern char *inter_server_ip; - -#endif // EVOL_LOGIN_CONFIG diff --git a/src/login/init.c b/src/login/init.c deleted file mode 100644 index 06e747b..0000000 --- a/src/login/init.c +++ /dev/null @@ -1,59 +0,0 @@ -// 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 "../../../login/login.h" - -#include "common/init.h" -#include "login/config.h" -#include "login/login.h" -#include "login/parse.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_login", - SERVER_TYPE_LOGIN, - "0.1", - HPM_VERSION -}; - -HPExport void plugin_init (void) -{ - interfaces_init_common(); - - login = GET_SYMBOL("login"); - - addPacket(0x7530, 22, login_parse_version, hpParse_Login); - addPacket(0x027c, 95, elogin_parse_client_login2, hpParse_Login); - addPacket(0x5000, 54, elogin_parse_change_paassword, hpParse_FromChar); - addHookPre("login->parse_client_login", elogin_parse_client_login_pre); - addHookPre("login->parse_request_connection", elogin_parse_request_connection); - addHookPre("login->check_password", elogin_check_password); - addHookPre("login->parse_ping", elogin_parse_ping); -} - -HPExport void server_preinit (void) -{ - iMalloc = GET_SYMBOL("iMalloc"); - addLoginConf("update_server", config_update_server); - addLoginConf("inter_server_ip", config_inter_server_ip); -} - -HPExport void server_online (void) -{ -} - -HPExport void plugin_final (void) -{ - config_final(); -} diff --git a/src/login/login.c b/src/login/login.c deleted file mode 100644 index bee7aa2..0000000 --- a/src/login/login.c +++ /dev/null @@ -1,30 +0,0 @@ -// 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 "../../../login/login.h" - -#include "login/md5calc.h" - -bool elogin_check_password(const char* md5key __attribute__ ((unused)), - int *passwdenc __attribute__ ((unused)), - const char* passwd, - const char* refpass) -{ - if (!strcmp(passwd, refpass) || pass_ok(passwd, refpass)) - { - hookStop(); - return 1; - } - - hookStop(); - return 0; -} diff --git a/src/login/login.h b/src/login/login.h deleted file mode 100644 index 0783a5c..0000000 --- a/src/login/login.h +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. -// Copyright (c) 2014 Evol developers - -#ifndef EVOL_LOGIN_LOGIN -#define EVOL_LOGIN_LOGIN - -bool elogin_check_password(const char* md5key, int *passwdenc, const char* passwd, const char* refpass); - -#endif // EVOL_LOGIN_SEND diff --git a/src/login/md5calc.c b/src/login/md5calc.c deleted file mode 100644 index bfa7b92..0000000 --- a/src/login/md5calc.c +++ /dev/null @@ -1,406 +0,0 @@ -// $Id: md5calc.c,v 1.1.1.1 2004/09/10 17:26:54 MagicalTux Exp $ -/*********************************************************** - * md5 calculation algorithm - * - * The source code referred to the following URL. - * http://www.geocities.co.jp/SiliconValley-Oakland/8878/lab17/lab17.html - * - ***********************************************************/ - -#include "md5calc.h" -#include -#include -#include "mt_rand.h" - -#ifndef UINT_MAX -#define UINT_MAX 4294967295U -#endif - -// Global variable -static unsigned int *pX; - -// Stirng Table -static const unsigned int T[] = { - 0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee, //0 - 0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501, //4 - 0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be, //8 - 0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821, //12 - 0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa, //16 - 0xd62f105d, 0x2441453, 0xd8a1e681, 0xe7d3fbc8, //20 - 0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed, //24 - 0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a, //28 - 0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c, //32 - 0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70, //36 - 0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x4881d05, //40 - 0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665, //44 - 0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039, //48 - 0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1, //52 - 0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1, //56 - 0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391 //60 -}; - -// ROTATE_LEFT The left is made to rotate x [ n-bit ]. This is diverted as it is from RFC. -#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) - -// The function used for other calculation -static unsigned int F (unsigned int X, unsigned int Y, unsigned int Z) -{ - return (X & Y) | (~X & Z); -} - -static unsigned int G (unsigned int X, unsigned int Y, unsigned int Z) -{ - return (X & Z) | (Y & ~Z); -} - -static unsigned int H (unsigned int X, unsigned int Y, unsigned int Z) -{ - return X ^ Y ^ Z; -} - -static unsigned int I (unsigned int X, unsigned int Y, unsigned int Z) -{ - return Y ^ (X | ~Z); -} - -static unsigned int Round (unsigned int a, unsigned int b, unsigned int FGHI, - unsigned int k, unsigned int s, unsigned int i) -{ - return b + ROTATE_LEFT (a + FGHI + pX[k] + T[i], s); -} - -static void Round1 (unsigned int *a, unsigned int b, unsigned int c, - unsigned int d, unsigned int k, unsigned int s, - unsigned int i) -{ - *a = Round (*a, b, F (b, c, d), k, s, i); -} - -static void Round2 (unsigned int *a, unsigned int b, unsigned int c, - unsigned int d, unsigned int k, unsigned int s, - unsigned int i) -{ - *a = Round (*a, b, G (b, c, d), k, s, i); -} - -static void Round3 (unsigned int *a, unsigned int b, unsigned int c, - unsigned int d, unsigned int k, unsigned int s, - unsigned int i) -{ - *a = Round (*a, b, H (b, c, d), k, s, i); -} - -static void Round4 (unsigned int *a, unsigned int b, unsigned int c, - unsigned int d, unsigned int k, unsigned int s, - unsigned int i) -{ - *a = Round (*a, b, I (b, c, d), k, s, i); -} - -static void MD5_Round_Calculate (const unsigned char *block, - unsigned int *A2, unsigned int *B2, - unsigned int *C2, unsigned int *D2) -{ - //create X It is since it is required. - unsigned int X[16]; //512bit 64byte - int j, k; - - //Save A as AA, B as BB, C as CC, and and D as DD (saving of A, B, C, and D) - unsigned int A = *A2, B = *B2, C = *C2, D = *D2; - unsigned int AA = A, BB = B, CC = C, DD = D; - - //It is a large region variable reluctantly because of calculation of a round. . . for Round1...4 - pX = X; - - //Copy block(padding_message) i into X - for (j = 0, k = 0; j < 64; j += 4, k++) - X[k] = ((unsigned int) block[j]) // 8byte*4 -> 32byte conversion - | (((unsigned int) block[j + 1]) << 8) // A function called Decode as used in the field of RFC - | (((unsigned int) block[j + 2]) << 16) - | (((unsigned int) block[j + 3]) << 24); - - //Round 1 - Round1 (&A, B, C, D, 0, 7, 0); - Round1 (&D, A, B, C, 1, 12, 1); - Round1 (&C, D, A, B, 2, 17, 2); - Round1 (&B, C, D, A, 3, 22, 3); - Round1 (&A, B, C, D, 4, 7, 4); - Round1 (&D, A, B, C, 5, 12, 5); - Round1 (&C, D, A, B, 6, 17, 6); - Round1 (&B, C, D, A, 7, 22, 7); - Round1 (&A, B, C, D, 8, 7, 8); - Round1 (&D, A, B, C, 9, 12, 9); - Round1 (&C, D, A, B, 10, 17, 10); - Round1 (&B, C, D, A, 11, 22, 11); - Round1 (&A, B, C, D, 12, 7, 12); - Round1 (&D, A, B, C, 13, 12, 13); - Round1 (&C, D, A, B, 14, 17, 14); - Round1 (&B, C, D, A, 15, 22, 15); - - //Round 2 - Round2 (&A, B, C, D, 1, 5, 16); - Round2 (&D, A, B, C, 6, 9, 17); - Round2 (&C, D, A, B, 11, 14, 18); - Round2 (&B, C, D, A, 0, 20, 19); - Round2 (&A, B, C, D, 5, 5, 20); - Round2 (&D, A, B, C, 10, 9, 21); - Round2 (&C, D, A, B, 15, 14, 22); - Round2 (&B, C, D, A, 4, 20, 23); - Round2 (&A, B, C, D, 9, 5, 24); - Round2 (&D, A, B, C, 14, 9, 25); - Round2 (&C, D, A, B, 3, 14, 26); - Round2 (&B, C, D, A, 8, 20, 27); - Round2 (&A, B, C, D, 13, 5, 28); - Round2 (&D, A, B, C, 2, 9, 29); - Round2 (&C, D, A, B, 7, 14, 30); - Round2 (&B, C, D, A, 12, 20, 31); - - //Round 3 - Round3 (&A, B, C, D, 5, 4, 32); - Round3 (&D, A, B, C, 8, 11, 33); - Round3 (&C, D, A, B, 11, 16, 34); - Round3 (&B, C, D, A, 14, 23, 35); - Round3 (&A, B, C, D, 1, 4, 36); - Round3 (&D, A, B, C, 4, 11, 37); - Round3 (&C, D, A, B, 7, 16, 38); - Round3 (&B, C, D, A, 10, 23, 39); - Round3 (&A, B, C, D, 13, 4, 40); - Round3 (&D, A, B, C, 0, 11, 41); - Round3 (&C, D, A, B, 3, 16, 42); - Round3 (&B, C, D, A, 6, 23, 43); - Round3 (&A, B, C, D, 9, 4, 44); - Round3 (&D, A, B, C, 12, 11, 45); - Round3 (&C, D, A, B, 15, 16, 46); - Round3 (&B, C, D, A, 2, 23, 47); - - //Round 4 - Round4 (&A, B, C, D, 0, 6, 48); - Round4 (&D, A, B, C, 7, 10, 49); - Round4 (&C, D, A, B, 14, 15, 50); - Round4 (&B, C, D, A, 5, 21, 51); - Round4 (&A, B, C, D, 12, 6, 52); - Round4 (&D, A, B, C, 3, 10, 53); - Round4 (&C, D, A, B, 10, 15, 54); - Round4 (&B, C, D, A, 1, 21, 55); - Round4 (&A, B, C, D, 8, 6, 56); - Round4 (&D, A, B, C, 15, 10, 57); - Round4 (&C, D, A, B, 6, 15, 58); - Round4 (&B, C, D, A, 13, 21, 59); - Round4 (&A, B, C, D, 4, 6, 60); - Round4 (&D, A, B, C, 11, 10, 61); - Round4 (&C, D, A, B, 2, 15, 62); - Round4 (&B, C, D, A, 9, 21, 63); - - // Then perform the following additions. (let's add) - *A2 = A + AA; - *B2 = B + BB; - *C2 = C + CC; - *D2 = D + DD; - - //The clearance of confidential information - memset (pX, 0, sizeof (X)); -} - -//------------------------------------------------------------------- -// The function for the exteriors - -/** output is the coded binary in the character sequence which wants to code string. */ -void MD5_String2binary (const char *string, char *output) -{ - if (!output) - return; - if (!string) - { - *output=0; - return; - } -//var - /*8bit */ - unsigned char padding_message[64]; //Extended message 512bit 64byte - unsigned char *pstring; //The position of string in the present scanning notes is held. - -// unsigned char digest[16]; - /*32bit */ - unsigned int string_byte_len, //The byte chief of string is held. - string_bit_len, //The bit length of string is held. - copy_len, //The number of bytes which is used by 1-3 and which remained - msg_digest[4]; //Message digest 128bit 4byte - unsigned int *A = &msg_digest[0], //The message digest in accordance with RFC (reference) - *B = &msg_digest[1], *C = &msg_digest[2], *D = &msg_digest[3]; - int i; - -//prog - //Step 3.Initialize MD Buffer (although it is the initialization; step 3 of A, B, C, and D -- unavoidable -- a head) - *A = 0x67452301; - *B = 0xefcdab89; - *C = 0x98badcfe; - *D = 0x10325476; - - //Step 1.Append Padding Bits (extension of a mark bit) - //1-1 - string_byte_len = strlen (string); //The byte chief of a character sequence is acquired. - pstring = (unsigned char *) string; //The position of the present character sequence is set. - - //1-2 Repeat calculation until length becomes less than 64 bytes. - for (i = string_byte_len; 64 <= i; i -= 64, pstring += 64) - MD5_Round_Calculate (pstring, A, B, C, D); - - //1-3 - copy_len = string_byte_len % 64; //The number of bytes which remained is computed. - strncpy ((char *) padding_message, (char *) pstring, copy_len); //A message is copied to an extended bit sequence. - memset (padding_message + copy_len, 0, 64 - copy_len); //It buries by 0 until it becomes extended bit length. - padding_message[copy_len] |= 0x80; //The next of a message is 1. - - //1-4 - //If 56 bytes or more (less than 64 bytes) of remainder becomes, it will calculate by extending to 64 bytes. - if (56 <= copy_len) - { - MD5_Round_Calculate (padding_message, A, B, C, D); - memset (padding_message, 0, 56); //56 bytes is newly fill uped with 0. - } - - //Step 2.Append Length (the information on length is added) - string_bit_len = string_byte_len * 8; //From the byte chief to bit length (32 bytes of low rank) - memcpy (&padding_message[56], &string_bit_len, 4); //32 bytes of low rank is set. - - //When bit length cannot be expressed in 32 bytes of low rank, it is a beam raising to a higher rank. - if (UINT_MAX / 8 < string_byte_len) - { - unsigned int high = (string_byte_len - UINT_MAX / 8) * 8; - memcpy (&padding_message[60], &high, 4); - } - else - memset (&padding_message[60], 0, 4); //In this case, it is good for a higher rank at 0. - - //Step 4.Process Message in 16-Word Blocks (calculation of MD5) - MD5_Round_Calculate (padding_message, A, B, C, D); - - //Step 5.Output (output) - memcpy (output, msg_digest, 16); -// memcpy (digest, msg_digest, and 16); //8 byte*4 < - 32byte conversion A function called Encode as used in the field of RFC -/* sprintf(output, - "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", - digest[ 0], digest[ 1], digest[ 2], digest[ 3], - digest[ 4], digest[ 5], digest[ 6], digest[ 7], - digest[ 8], digest[ 9], digest[10], digest[11], - digest[12], digest[13], digest[14], digest[15]);*/ -} - -/** output is the coded character sequence in the character sequence which wants to code string. */ -void MD5_String (const char *string, char *output) -{ - if (!output) - return; - if (!string) - { - *output=0; - return; - } - unsigned char digest[16]; - - MD5_String2binary (string, (char *)digest); - sprintf (output, - "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", - digest[0], digest[1], digest[2], digest[3], - digest[4], digest[5], digest[6], digest[7], - digest[8], digest[9], digest[10], digest[11], - digest[12], digest[13], digest[14], digest[15]); -} - -// Hash a password with a salt. -char *MD5_saltcrypt(const char *key, const char *salt) -{ - if (!salt) - return 0; - - char buf[66], *sbuf = buf+32; - static char obuf[33]; - - // hash the key then the salt - // buf ends up as a 64char null terminated string - MD5_String(key, buf); - MD5_String(salt, sbuf); - - // Hash the buffer back into sbuf - MD5_String(buf, sbuf); - - snprintf(obuf, 32, "!%s$%s", salt, sbuf); - return(obuf); -} - -char *make_salt(void) -{ - static char salt[6]; - int i; - for (i=0; i<5; i++) - salt[i] = (char)((mt_rand() % 78) + 48); - salt[5] = '\0'; - return(salt); -} - -int pass_ok(const char *password, const char *crypted) -{ - if (!password || !crypted) - return 0; - - char buf[40], *salt=buf+1; - - strncpy(buf, crypted, 40); - buf[39] = 0; - char *ptr = strchr(buf, '$'); - if (ptr) - { - *ptr = '\0'; - - if (!strcmp(crypted, MD5_saltcrypt(password, salt))) - return(1); - } - else - { - //++ may be here need compare non encripted passwords? -// if (!strcmp(crypted, password)) -// return(1); - } - - return(0); -} - -// [M|h]ashes up an IP address and a secret key -// to return a hopefully unique masked IP. -in_addr_t MD5_ip(char *secret, in_addr_t ip) -{ - char ipbuf[32]; - char obuf[16]; - union { - struct bytes { - unsigned char b1; - unsigned char b2; - unsigned char b3; - unsigned char b4; - } bytes; - in_addr_t ip; - } conv; - - if (!secret) - { - conv.bytes.b1 = 0; - conv.bytes.b2 = 0; - conv.bytes.b3 = 0; - conv.bytes.b4 = 0; - return conv.ip; - } - - // MD5sum a secret + the IP address - memset(&ipbuf, 0, sizeof(ipbuf)); - snprintf(ipbuf, sizeof(ipbuf), "%lu%s", (unsigned long)ip, secret); - MD5_String2binary(ipbuf, obuf); - - // Fold the md5sum to 32 bits, pack the bytes to an in_addr_t - conv.bytes.b1 = obuf[0] ^ obuf[1] ^ obuf[8] ^ obuf[9]; - conv.bytes.b2 = obuf[2] ^ obuf[3] ^ obuf[10] ^ obuf[11]; - conv.bytes.b3 = obuf[4] ^ obuf[5] ^ obuf[12] ^ obuf[13]; - conv.bytes.b4 = obuf[6] ^ obuf[7] ^ obuf[14] ^ obuf[15]; - - return conv.ip; -} - diff --git a/src/login/md5calc.h b/src/login/md5calc.h deleted file mode 100644 index cf82738..0000000 --- a/src/login/md5calc.h +++ /dev/null @@ -1,13 +0,0 @@ -// $Id: md5calc.h,v 1.1.1.1 2004/09/10 17:26:54 MagicalTux Exp $ -#ifndef _MD5CALC_H_ -#define _MD5CALC_H_ -#include - -void MD5_String (const char *string, char *output); -void MD5_String2binary (const char *string, char *output); -char *MD5_saltcrypt(const char *key, const char *salt); -char *make_salt(void); -int pass_ok(const char *password, const char *crypted); -in_addr_t MD5_ip(char *secret, in_addr_t ip); - -#endif diff --git a/src/login/mt_rand.c b/src/login/mt_rand.c deleted file mode 100644 index 627d9dd..0000000 --- a/src/login/mt_rand.c +++ /dev/null @@ -1,118 +0,0 @@ -/* -// This is the ``Mersenne Twister'' random number generator MT19937, which -// generates pseudorandom integers uniformly distributed in 0..(2^32 - 1) -// starting from any odd seed in 0..(2^32 - 1). This version is a recode -// by Shawn Cokus (Cokus@math.washington.edu) on March 8, 1998 of a version by -// Takuji Nishimura (who had suggestions from Topher Cooper and Marc Rieffel in -// July-August 1997). -// -// Effectiveness of the recoding (on Goedel2.math.washington.edu, a DEC Alpha -// running OSF/1) using GCC -O3 as a compiler: before recoding: 51.6 sec. to -// generate 300 million random numbers; after recoding: 24.0 sec. for the same -// (i.e., 46.5% of original time), so speed is now about 12.5 million random -// number generations per second on this machine. -// -// According to the URL -// (and paraphrasing a bit in places), the Mersenne Twister is ``designed -// with consideration of the flaws of various existing generators,'' has -// a period of 2^19937 - 1, gives a sequence that is 623-dimensionally -// equidistributed, and ``has passed many stringent tests, including the -// die-hard test of G. Marsaglia and the load test of P. Hellekalek and -// S. Wegenkittl.'' It is efficient in memory usage (typically using 2506 -// to 5012 bytes of static data, depending on data type sizes, and the code -// is quite short as well). It generates random numbers in batches of 624 -// at a time, so the caching and pipelining of modern systems is exploited. -// It is also divide- and mod-free. -// -// This library is free software; you can redistribute it and/or modify it -// under the terms of the GNU Library General Public License as published by -// the Free Software Foundation (either version 2 of the License or, at your -// option, any later version). This library is distributed in the hope that -// it will be useful, but WITHOUT ANY WARRANTY, without even the implied -// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See -// the GNU Library General Public License for more details. You should have -// received a copy of the GNU Library General Public License along with this -// library; if not, write to the Free Software Foundation, Inc., 59 Temple -// Place, Suite 330, Boston, MA 02111-1307, USA. -// -// The code as Shawn received it included the following notice: -// -// Copyright (C) 1997 Makoto Matsumoto and Takuji Nishimura. When -// you use this, send an e-mail to with -// an appropriate reference to your work. -// -// It would be nice to CC: when you write. -// -*/ - -#include -#include "mt_rand.h" - -#define N (624) /* length of state vector */ -#define M (397) /* a period parameter */ -#define K (0x9908B0DFU) /* a magic constant */ -#define hiBit(u) ((u) & 0x80000000U) /* mask all but highest bit of u */ -#define loBit(u) ((u) & 0x00000001U) /* mask all but lowest bit of u */ -#define loBits(u) ((u) & 0x7FFFFFFFU) /* mask the highest bit of u */ -#define mixBits(u, v) (hiBit(u)|loBits(v)) /* move hi bit of u to hi bit of v */ - -static unsigned long state[N + 1]; /* state vector + 1 extra to not violate ANSI C */ -static unsigned long *next; /* next random value is computed from here */ -static int left = -1; /* can *next++ this many times before reloading */ - -void mt_seed (unsigned long seed) -{ - register unsigned long x = (seed | 1U) & 0xFFFFFFFFU, *s = state; - register int j; - - for (left = 0, *s++ = x, j = N; --j; *s++ = (x *= 69069U) & 0xFFFFFFFFU); -} - -unsigned long mt_reload (void) -{ - register unsigned long *p0 = state, *p2 = state + 2, *pM = - state + M, s0, s1; - register int j; - - if (left < -1) - mt_seed (time (NULL)); - - left = N - 1, next = state + 1; - - for (s0 = state[0], s1 = state[1], j = N - M + 1; --j; - s0 = s1, s1 = *p2++) - *p0++ = *pM++ ^ (mixBits (s0, s1) >> 1) ^ (loBit (s1) ? K : 0U); - - for (pM = state, j = M; --j; s0 = s1, s1 = *p2++) - *p0++ = *pM++ ^ (mixBits (s0, s1) >> 1) ^ (loBit (s1) ? K : 0U); - - s1 = state[0], *p0 = - *pM ^ (mixBits (s0, s1) >> 1) ^ (loBit (s1) ? K : 0U); - s1 ^= (s1 >> 11); - s1 ^= (s1 << 7) & 0x9D2C5680U; - s1 ^= (s1 << 15) & 0xEFC60000U; - return (s1 ^ (s1 >> 18)); -} - -unsigned long mt_random (void) -{ - unsigned long y; - - if (--left < 0) - return (mt_reload ()); - - y = *next++; - y ^= (y >> 11); - y ^= (y << 7) & 0x9D2C5680U; - y ^= (y << 15) & 0xEFC60000U; - return (y ^ (y >> 18)); -} - -int mt_rand (void) -{ - unsigned long r = mt_random (); - while (r >> 16) - r = (r & 0xFFFF) + (r >> 16); - - return (r); -} diff --git a/src/login/mt_rand.h b/src/login/mt_rand.h deleted file mode 100644 index d798fee..0000000 --- a/src/login/mt_rand.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef __mt_rand_h -#define __mt_rand_h - -void mt_seed (unsigned long seed); -unsigned long mt_reload (void); -unsigned long mt_random (void); -int mt_rand (void); - -#endif /* __mt_rand_h */ diff --git a/src/login/parse.c b/src/login/parse.c deleted file mode 100644 index d803843..0000000 --- a/src/login/parse.c +++ /dev/null @@ -1,210 +0,0 @@ -// 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 "../../../login/account.h" -#include "../../../login/login.h" - -#include "common/ip.h" -#include "login/config.h" -#include "login/md5calc.h" -#include "login/parse.h" -#include "login/send.h" - -int clientVersion = 0; - -void login_parse_version(int fd) -{ - struct login_session_data* sd = (struct login_session_data*)session[fd]->session_data; - if (!sd) - return; - - clientVersion = RFIFOL(fd, 2); - - if (clientVersion < 2) - { - login->login_error(fd, 5); - return; - } - - send_update_host(fd); - send_server_version(fd); -} - -int elogin_parse_client_login_pre(int *fdPtr, - struct login_session_data* sd __attribute__ ((unused)), - const char *const ip __attribute__ ((unused))) -{ - int fd = *fdPtr; - uint16 command = RFIFOW(fd,0); - if (command != 0x64) - { - login->login_error(fd, 3); - hookStop(); - return 1; - } - char username[NAME_LENGTH]; - safestrncpy(username, (const char*)RFIFOP(fd, 6), NAME_LENGTH); - int len = strnlen(username, NAME_LENGTH); - if (clientVersion < 2) - { - login->login_error(fd, 5); - hookStop(); - return 1; - } - else if (len >= 2 && username[len - 2] == '_' && memchr("FfMm", username[len - 1], 4)) - { - login->login_error(fd, 3); - hookStop(); - return 1; - } - - return 0; -} - -void elogin_parse_client_login2(int fd) -{ - char username[NAME_LENGTH]; - char password[PASSWD_LEN]; - char email[40]; - uint8 clienttype; - int result; - - safestrncpy(username, (const char*)RFIFOP(fd, 2), NAME_LENGTH); - - int len = strnlen(username, NAME_LENGTH); - if (len < 2 || !(username[len - 2] == '_') || !memchr("FfMm", username[len - 1], 4)) - { - login->login_error(fd, 3); - return; - } - - safestrncpy(password, (const char*)RFIFOP(fd, 26), NAME_LENGTH); - safestrncpy(email, (const char*)RFIFOP(fd, 51), 40); - clienttype = RFIFOB(fd, 50); - - struct login_session_data* sd = (struct login_session_data*)session[fd]->session_data; - if (!sd) - return; - - char ip[16]; - uint32 ipl = session[fd]->client_addr; - ip2str(ipl, ip); - sd->clienttype = clienttype; - sd->version = clientVersion; - sd->passwdenc = 0; - safestrncpy(sd->userid, username, NAME_LENGTH); - ShowStatus("Request for connection of %s (ip: %s).\n", sd->userid, ip); - safestrncpy(sd->passwd, password, PASSWD_LEN); - - if (e_mail_check(email) == 0) - { - ShowNotice("Attempt to create an e-mail REFUSED - e-mail is invalid (ip: %s)\n", ip); - login->login_error(fd, 11); - return; - } - - result = login->mmo_auth(sd, false); - - if (result == -1) - { - int account_id = sd->account_id; - struct mmo_account acc; - if (!login->accounts->load_num(login->accounts, &acc, account_id)) - { - ShowNotice("Attempt to create an e-mail on an account REFUSED - account: %d, ip: %s).\n", account_id, ip); - } - else - { - memcpy(acc.email, email, 40); - ShowNotice("Create an e-mail on an account with a default e-mail (account: %d, new e-mail: %s, ip: %s).\n", account_id, email, ip); - // Save - login->accounts->save(login->accounts, &acc); - } - - login->auth_ok(sd); - } - else - { - login->auth_failed(sd, result); - } - - return; -} - -void elogin_parse_request_connection(int *fd, struct login_session_data* sd, const char *const ip) -{ - if (!inter_server_ip || !ip) - return; - if (!checkAllowedIp(inter_server_ip, ip)) - { - hookStop(); - login->char_server_connection_status(*fd, sd, 3); - ShowNotice("Connection of the char-server from ip %s REFUSED.\n", ip); - } -} - -void elogin_parse_ping(int *fd, struct login_session_data* sd) -{ - RFIFOSKIP(*fd, 26); - if (!sd) - { - hookStop(); - return; - } - struct online_login_data* data = (struct online_login_data*)idb_get(login->online_db, sd->account_id); - if (data == NULL) - { - hookStop(); - return; - } - if (data->waiting_disconnect != INVALID_TIMER) - { - timer->delete(data->waiting_disconnect, login->waiting_disconnect_timer); - data->waiting_disconnect = timer->add(timer->gettick() + 30000, login->waiting_disconnect_timer, sd->account_id, 0); - } - hookStop(); -} - -void elogin_parse_change_paassword(int fd) -{ - char actual_pass[24], new_pass[24]; - int status = 0; - struct mmo_account acc; - const int accountId = RFIFOL (fd, 2); - - memcpy (actual_pass, RFIFOP (fd, 6), 24); - actual_pass[23] = '\0'; - memcpy (new_pass, RFIFOP (fd, 30), 24); - new_pass[23] = '\0'; - - if (!login->accounts->load_num(login->accounts, &acc, accountId)) - { - // account not found - send_char_password_change_ack(fd, accountId, 0); - return; - } - - if (!strcmp(actual_pass, acc.pass) || pass_ok(actual_pass, acc.pass)) - { - // changed ok - status = 1; - safestrncpy(acc.pass, new_pass, sizeof(acc.pass)); - login->accounts->save(login->accounts, &acc); - } - else - { - // wrong password - status = 2; - } - send_char_password_change_ack(fd, accountId, status); -} diff --git a/src/login/parse.h b/src/login/parse.h deleted file mode 100644 index b5c2418..0000000 --- a/src/login/parse.h +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. -// Copyright (c) 2014 Evol developers - -#ifndef EVOL_LOGIN_PARSE -#define EVOL_LOGIN_PARSE - -void login_parse_version(int fd); -int elogin_parse_client_login_pre(int *fd, struct login_session_data* sd, const char *const ip); -void elogin_parse_client_login2(int fd); -void elogin_parse_request_connection(int *fd, struct login_session_data* sd, const char *const ip); -void elogin_parse_ping(int *fd, struct login_session_data* sd); -void elogin_parse_change_paassword(int fd); - -#endif // EVOL_LOGIN_PARSE diff --git a/src/login/send.c b/src/login/send.c deleted file mode 100644 index 420028c..0000000 --- a/src/login/send.c +++ /dev/null @@ -1,47 +0,0 @@ -// 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 "../../../login/login.h" - -#include "login/config.h" -#include "login/send.h" - -void send_server_version(int fd) -{ - WFIFOHEAD(fd, 4 + 8); - WFIFOW(fd, 0) = 0x7531; - WFIFOW(fd, 2) = 4 + 8; - WFIFOL(fd, 4) = 0; // unused - WFIFOL(fd, 8) = 6; // server version - WFIFOSET(fd, WFIFOW(fd,2)); -} - -void send_update_host(int fd) -{ - if (!update_server) - return; - const int sz = strlen(update_server); - WFIFOHEAD(fd, sz + 4); - WFIFOW(fd, 0) = 0x63; - WFIFOW(fd, 2) = sz + 4; - memcpy(WFIFOP (fd, 4), update_server, sz); - WFIFOSET(fd, sz + 4); -} - -void send_char_password_change_ack(int fd, int accoundId, char status) -{ - WFIFOHEAD(fd, 7); - WFIFOW(fd, 0) = 0x5001; - WFIFOL(fd, 2) = accoundId; - WFIFOB(fd, 6) = status; - WFIFOSET(fd, 7); -} diff --git a/src/login/send.h b/src/login/send.h deleted file mode 100644 index 5fdb6c4..0000000 --- a/src/login/send.h +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. -// Copyright (c) 2014 Evol developers - -#ifndef EVOL_LOGIN_SEND -#define EVOL_LOGIN_SEND - -void send_server_version(); -void send_update_host(int fd); -void send_char_password_change_ack(int fd, int accoundId, char status); - -#endif // EVOL_LOGIN_SEND diff --git a/src/map/atcommand.c b/src/map/atcommand.c deleted file mode 100644 index cd972ad..0000000 --- a/src/map/atcommand.c +++ /dev/null @@ -1,84 +0,0 @@ -// 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 "../../../map/atcommand.h" -#include "../../../map/clif.h" -#include "../../../map/map.h" -#include "../../../map/pc.h" -#include "../../../map/skill.h" -#include "map/atcommand.h" -#include "map/lang.h" - -const char* eatcommand_msgsd(struct map_session_data *sd, int *msgPtr) -{ - const int msg_number = *msgPtr; - if (!(msg_number >= 0 && msg_number < MAX_MSG)) - { - hookStop(); - return "??"; - } - if (*msgPtr == 1435) - { - hookStop(); - // service message, must be not translated - return "You're now in the '#%s' channel for '%s'"; - } - else if (*msgPtr == 1403) - { - hookStop(); - // service message, must be not translated - return "You're now in the '#%s' channel for '-'"; - } - hookStop(); - return lang_pctrans(atcommand->msg_table[0][msg_number], sd); -} - -const char* eatcommand_msgfd(int *fdPtr, int *msgPtr) -{ - const int msg_number = *msgPtr; - const int fd = *fdPtr; - struct map_session_data *sd = session_isValid(fd) ? session[fd]->session_data : NULL; - if (!(msg_number >= 0 && msg_number < MAX_MSG)) - { - hookStop(); - return "??"; - } - hookStop(); - return lang_pctrans(atcommand->msg_table[0][msg_number], sd); -} - -ACMD2(setSkill) -{ - int skill_id = 0; - int skill_level = 0; - - if (!message || !*message || sscanf(message, "%5d %2d", &skill_id, &skill_level) < 2) - { - const char* text = info->help; - - if (text) - clif->messageln (fd, text); - - return false; - } - if (!skill->get_index(skill_id)) - { - clif->message(fd, msg_fd(fd,198)); // This skill number doesn't exist. - return false; - } - - pc->skill(sd, skill_id, skill_level, 0); - clif->message(fd, msg_fd(fd,70)); // You have learned the skill. - - return true; -} diff --git a/src/map/atcommand.h b/src/map/atcommand.h deleted file mode 100644 index ab970c6..0000000 --- a/src/map/atcommand.h +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. -// Copyright (c) 2014 Evol developers - -#ifndef EVOL_MAP_ATCOMMAND -#define EVOL_MAP_ATCOMMAND - -const char* eatcommand_msgsd(struct map_session_data *sd, int *msgPtr); -const char* eatcommand_msgfd(int *fdPtr, int *msgPtr); - -#define ACMD2(x) bool atcommand_ ## x (const int fd, struct map_session_data* sd, const char* command __attribute__ ((unused)), const char* message, struct AtCommandInfo *info) - -ACMD2(setSkill); - -#endif // EVOL_MAP_ATCOMMAND diff --git a/src/map/clif.c b/src/map/clif.c deleted file mode 100644 index 127cd16..0000000 --- a/src/map/clif.c +++ /dev/null @@ -1,376 +0,0 @@ -// 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/cbasetypes.h" -#include "../../../map/mob.h" -#include "../../../map/npc.h" -#include "../../../map/pc.h" -#include "../../../map/quest.h" - -#include "map/clif.h" -#include "map/lang.h" -#include "map/send.h" -#include "map/data/mapd.h" -#include "map/data/session.h" -#include "map/struct/mapdext.h" -#include "map/struct/sessionext.h" - -void eclif_quest_send_list(TBL_PC *sd) -{ - if (!sd) - { - hookStop(); - return; - } - - int fd = sd->fd; - int i; - int info_len = 15; - int len = sd->avail_quests * info_len + 8; - WFIFOHEAD(fd,len); - WFIFOW(fd, 0) = 0x97a; - WFIFOW(fd, 2) = len; - WFIFOL(fd, 4) = sd->avail_quests; - - for (i = 0; i < sd->avail_quests; i++ ) - { - struct quest_db *qi = quest->db(sd->quest_log[i].quest_id); - if (!qi) - continue; - WFIFOL(fd, i * info_len + 8) = sd->quest_log[i].quest_id; - WFIFOB(fd, i * info_len + 12) = sd->quest_log[i].count[0]; // was state - WFIFOL(fd, i * info_len + 13) = sd->quest_log[i].time - qi->time; - WFIFOL(fd, i * info_len + 17) = sd->quest_log[i].time; - WFIFOW(fd, i * info_len + 21) = 0; - } - - WFIFOSET(fd, len); - hookStop(); -} - -void eclif_quest_add(TBL_PC *sd, struct quest *qd) -{ - if (!sd) - { - hookStop(); - return; - } - int fd = sd->fd; - struct quest_db *qi = quest->db(qd->quest_id); - - if (!qi) - { - hookStop(); - return; - } - - WFIFOHEAD(fd, 107); - WFIFOW(fd, 0) = 0x2b3; - WFIFOL(fd, 2) = qd->quest_id; - WFIFOB(fd, 6) = qd->count[0]; // was state; - WFIFOB(fd, 7) = qd->time - qi->time; - WFIFOL(fd, 11) = qd->time; - WFIFOW(fd, 15) = 0; - WFIFOSET(fd, 107); - hookStop(); -} - -void eclif_charnameack(int *fdPtr, struct block_list *bl) -{ - if (!bl) - { - hookStop(); - return; - } - if (bl->type == BL_NPC) - { - int fd = *fdPtr; - TBL_PC* sd = (TBL_PC*)session[fd]->session_data; - if (!sd) - { - hookStop(); - return; - } - const char *tr = lang_pctrans(((TBL_NPC*)bl)->name, sd); - const int trLen = strlen(tr); - const int len = 8 + trLen; - // if no recipient specified just update nearby clients - if (fd == 0) - { - char *buf; - CREATE(buf, char, len); - WBUFW(buf, 0) = 0xB01; - WBUFW(buf, 2) = len; - WBUFL(buf, 4) = bl->id; - memcpy(WBUFP(buf, 8), tr, trLen); - clif->send(buf, len, bl, AREA); - aFree(buf); - } - else - { - WFIFOHEAD(fd, len); - WFIFOW(fd, 0) = 0xB01; - WFIFOW(fd, 2) = len; - WFIFOL(fd, 4) = bl->id; - memcpy(WFIFOP(fd, 8), tr, trLen); - WFIFOSET(fd, len); - } - hookStop(); - } - else if (bl->type == BL_MOB) - { - struct mob_data *md = (struct mob_data *)bl; - if (!md) - { - hookStop(); - return; - } - if (md->guardian_data && md->guardian_data->g) - return; // allow default code to work - int fd = *fdPtr; - TBL_PC* sd = (TBL_PC*)session[fd]->session_data; - if (!sd) - { - hookStop(); - return; - } - - char tmpBuf[25]; - char *ptr = tmpBuf; - int f; - memcpy(tmpBuf, md->name, 24); - tmpBuf[24] = 0; - for (f = 23; f > 1; f --) - { - if (tmpBuf[f] == ' ') - tmpBuf[f] = 0; - else - break; - } - for (f = 0; f < 24; f ++) - { - if (*ptr == ' ') - ptr ++; - else - break; - } - const char *tr = lang_pctrans(ptr, sd); - const int trLen = strlen(tr); - const int len = 8 + trLen; - - // if no recipient specified just update nearby clients - if (fd == 0) - { - char *buf; - CREATE(buf, char, len); - WBUFW(buf, 0) = 0xB01; - WBUFW(buf, 2) = len; - WBUFL(buf, 4) = bl->id; - memcpy(WBUFP(buf, 8), tr, trLen); - clif->send(buf, len, bl, AREA); - aFree(buf); - } - else - { - WFIFOHEAD(fd, len); - WFIFOW(fd, 0) = 0xB01; - WFIFOW(fd, 2) = len; - WFIFOL(fd, 4) = bl->id; - memcpy(WFIFOP(fd, 8), tr, trLen); - WFIFOSET(fd, len); - } - hookStop(); - } -} - -#define equipPos(index, field) \ - equip = sd->equip_index[index]; \ - if (equip >= 0) \ - { \ - item = sd->inventory_data[equip]; \ - if (item && item->look) \ - send_changelook(fd, id, field, item->look); \ - } - -static void eclif_send_additional_slots(TBL_PC* sd, TBL_PC* sd2) -{ - if (!sd || !sd2) - return; - - const int id = sd->bl.id; - const int fd = sd2->fd; - - struct item_data *item; - short equip; - struct MapdExt *data = mapd_get(sd->bl.m); - if (!data || data->invisible) - return; - - equipPos(EQI_HEAD_LOW, LOOK_HEAD_BOTTOM); - equipPos(EQI_HEAD_TOP, LOOK_HEAD_TOP); - equipPos(EQI_HEAD_MID, LOOK_HEAD_MID); - equipPos(EQI_GARMENT, LOOK_ROBE); - equipPos(EQI_SHOES, LOOK_SHOES); - equipPos(EQI_COSTUME_TOP, 13); - equipPos(EQI_COSTUME_MID, 14); - equipPos(EQI_COSTUME_LOW, 15); - equipPos(EQI_COSTUME_GARMENT, 16); - equipPos(EQI_ARMOR, 17); - //skipping SHADOW slots -} - -void eclif_getareachar_unit_post(TBL_PC* sd, struct block_list *bl) -{ - if (!bl) - return; - if (bl->type == BL_PC) - { - eclif_send_additional_slots(sd, (TBL_PC *)bl); - eclif_send_additional_slots((TBL_PC *)bl, sd); - } -} - -void eclif_authok_post(TBL_PC *sd) -{ - if (!sd) - return; - - eclif_send_additional_slots(sd, sd); - send_pc_info(&sd->bl, &sd->bl, SELF); - struct MapdExt *data = mapd_get(sd->bl.m); - int mask = data ? data->mask : 1; - send_mapmask(sd->fd, mask); -} - -void eclif_changemap_post(TBL_PC *sd, short *m, - int *x __attribute__ ((unused)), int *y __attribute__ ((unused))) -{ - if (!sd) - return; - struct MapdExt *data = mapd_get(*m); - int mask = data ? data->mask : 1; - send_mapmask(sd->fd, mask); -} - -void eclif_handle_invisible_map(struct block_list *bl, enum send_target target __attribute__ ((unused))) -{ - if (!bl || bl->type != BL_PC) - return; - struct MapdExt *data = mapd_get(bl->m); - if (data && data->invisible) - hookStop(); -} - -void eclif_sendlook(struct block_list *bl, - int *id __attribute__ ((unused)), - int *type __attribute__ ((unused)), - int *val __attribute__ ((unused)), - int *val2 __attribute__ ((unused)), - enum send_target *target) -{ - if (*target == SELF) - return; - eclif_handle_invisible_map(bl, *target); -} - -bool eclif_send(const void* buf __attribute__ ((unused)), - int *len __attribute__ ((unused)), - struct block_list* bl, - enum send_target *type) -{ - if (*type == SELF) - return true; - eclif_handle_invisible_map(bl, *type); - return true; -} - -void eclif_set_unit_idle(struct block_list* bl, TBL_PC *tsd, enum send_target *target) -{ - if (tsd && bl && bl->id == tsd->bl.id && *target == SELF) - return; - - eclif_handle_invisible_map(bl, *target); -} - -int eclif_send_actual(int *fd, void *buf, int *len) -{ - if (*len >= 2) - { - const int packet = RBUFW (buf, 0); - if (packet >= 0xb02 && packet <= 0xb10) - { - struct SessionExt *data = session_get(*fd); - if (!data) - return 0; - if (data->clientVersion < 3) - { // not sending new packets to old clients -// ShowWarning("skip packet %d\n", packet); - hookStop(); - return 0; - } - } - if (packet >= 0xb03 && packet <= 0xb0a) - { - struct SessionExt *data = session_get(*fd); - if (!data) - return 0; - if (data->clientVersion < 4) - { // not sending new packets to old clients -// ShowWarning("skip packet %d\n", packet); - hookStop(); - return 0; - } - } - if (packet == 0xb0b) - { - struct SessionExt *data = session_get(*fd); - if (!data) - return 0; - if (data->clientVersion < 5) - { // not sending new packets to old clients -// ShowWarning("skip packet %d\n", packet); - hookStop(); - return 0; - } - } - } - return 0; -} - -void eclif_set_unit_idle_post(struct block_list* bl, TBL_PC *tsd, - enum send_target *target) -{ - if (!bl || !tsd) - return; - - if (bl->type == BL_MOB) - send_mob_info(bl, &tsd->bl, *target); - else if (bl->type == BL_PC) - send_pc_info(bl, &tsd->bl, *target); - else if (bl->type == BL_NPC) - send_npc_info(bl, &tsd->bl, *target); -} - -void eclif_set_unit_walking(struct block_list* bl, TBL_PC *tsd, - struct unit_data* ud, enum send_target *target) -{ - TBL_PC *sd = BL_CAST(BL_PC, ud->bl); - if (!sd || !pc_isinvisible(sd)) - send_advmoving(ud, tsd ? &tsd->bl : bl, *target); -} - -void eclif_move(struct unit_data *ud) -{ - TBL_PC *sd = BL_CAST(BL_PC, ud->bl); - if (!sd || !pc_isinvisible(sd)) - send_advmoving(ud, ud->bl, AREA_WOS); -} diff --git a/src/map/clif.h b/src/map/clif.h deleted file mode 100644 index 5fd155b..0000000 --- a/src/map/clif.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. -// Copyright (c) 2014 Evol developers - -#ifndef EVOL_MAP_CLIF -#define EVOL_MAP_CLIF - -void eclif_quest_send_list(TBL_PC *sd); -void eclif_quest_add(TBL_PC *sd, struct quest *qd); -void eclif_charnameack(int *fdPtr, struct block_list *bl); -void eclif_getareachar_unit_post(TBL_PC* sd, struct block_list *bl); -void eclif_sendlook(struct block_list *bl, int *id, int *type, - int *val, int *val2, enum send_target *target); -bool eclif_send(const void* buf, int *len, struct block_list* bl, enum send_target *type); -void eclif_set_unit_idle(struct block_list* bl, TBL_PC *tsd, - enum send_target *target); -int eclif_send_actual(int *fd, void *buf, int *len); - -void eclif_authok_post(TBL_PC *sd); -void eclif_changemap_post(TBL_PC *sd, short *m, int *x, int *y); -void eclif_set_unit_idle_post(struct block_list* bl, TBL_PC *tsd, - enum send_target *target); -void eclif_set_unit_walking(struct block_list* bl, TBL_PC *tsd, - struct unit_data* ud, enum send_target *target); -void eclif_move(struct unit_data *ud); - -#endif // EVOL_MAP_CLIF diff --git a/src/map/data/itemd.c b/src/map/data/itemd.c deleted file mode 100644 index 55351a1..0000000 --- a/src/map/data/itemd.c +++ /dev/null @@ -1,68 +0,0 @@ -// 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 "../../../map/battle.h" -#include "../../../map/itemdb.h" - -#include "map/data/itemd.h" -#include "map/struct/itemdext.h" - -struct ItemdExt *itemd_get_by_item(struct item *item) -{ - if (!item) - return NULL; - const int nameid = item->nameid; - struct item_data *item_data = itemdb->exists(nameid); - return itemd_get(item_data); -} - -struct ItemdExt *itemd_get(struct item_data *item) -{ - if (!item) - return NULL; - - struct ItemdExt *data = getFromITEMDATA(item, 0); - if (!data) - { - data = itemd_create(); - addToITEMDATA(item, data, 0, true); - } - return data; -} - -struct ItemdExt *itemd_create(void) -{ - struct ItemdExt *data = NULL; - CREATE(data, struct ItemdExt, 1); - if (!data) - return NULL; - data->floorLifeTime = battle->bc->flooritem_lifetime; - data->allowPickup = true; - data->requiredStr = 0; - data->requiredAgi = 0; - data->requiredVit = 0; - data->requiredInt = 0; - data->requiredDex = 0; - data->requiredLuk = 0; - data->requiredMaxHp = 0; - data->requiredMaxSp = 0; - data->requiredAtk = 0; - data->requiredMAtkMin = 0; - data->requiredMAtkMax = 0; - data->requiredDef = 0; - data->requiredMDef = 0; - data->useEffect = -1; - data->useFailEffect = -1; - data->unequipEffect = -1; - data->unequipFailEffect = -1; - return data; -} diff --git a/src/map/data/itemd.h b/src/map/data/itemd.h deleted file mode 100644 index d3c529b..0000000 --- a/src/map/data/itemd.h +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. -// Copyright (c) 2014 Evol developers - -#ifndef EVOL_MAP_ITEMD -#define EVOL_MAP_ITEMD - -struct ItemdExt; - -struct ItemdExt *itemd_get_by_item(struct item *item); -struct ItemdExt *itemd_get(struct item_data *item); -struct ItemdExt *itemd_create(void); - -#endif // EVOL_MAP_MAPD diff --git a/src/map/data/mapd.c b/src/map/data/mapd.c deleted file mode 100644 index a557dc9..0000000 --- a/src/map/data/mapd.c +++ /dev/null @@ -1,40 +0,0 @@ -// 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 "../../../map/map.h" - -#include "map/data/mapd.h" -#include "map/struct/mapdext.h" - -struct MapdExt *mapd_get(int m) -{ - struct map_data *md = &map->list[m]; - struct MapdExt *data = getFromMAPD(md, 0); - if (!data) - { - data = mapd_create(); - addToMAPD(md, data, 0, true); - } - return data; -} - -struct MapdExt *mapd_create(void) -{ - struct MapdExt *data = NULL; - CREATE(data, struct MapdExt, 1); - if (!data) - return NULL; - data->mask = 1; - data->invisible = false; - data->flag.nopve = 0; - return data; -} diff --git a/src/map/data/mapd.h b/src/map/data/mapd.h deleted file mode 100644 index a0878ae..0000000 --- a/src/map/data/mapd.h +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. -// Copyright (c) 2014 Evol developers - -#ifndef EVOL_MAP_MAPD -#define EVOL_MAP_MAPD - -struct MapdExt; - -struct MapdExt *mapd_get(int fd); -struct MapdExt *mapd_create(void); - -#endif // EVOL_MAP_MAPD diff --git a/src/map/data/npcd.c b/src/map/data/npcd.c deleted file mode 100644 index 0112916..0000000 --- a/src/map/data/npcd.c +++ /dev/null @@ -1,38 +0,0 @@ -// 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 "../../../map/battle.h" -#include "../../../map/npc.h" - -#include "map/data/npcd.h" -#include "map/struct/npcdext.h" - -struct NpcdExt *npcd_get(TBL_NPC *nd) -{ - struct NpcdExt *data = getFromNPCD(nd, 0); - if (!data) - { - data = npcd_create(); - addToNPCD(nd, data, 0, true); - } - return data; -} - -struct NpcdExt *npcd_create(void) -{ - struct NpcdExt *data = NULL; - CREATE(data, struct NpcdExt, 1); - if (!data) - return NULL; - data->init = false; - return data; -} diff --git a/src/map/data/npcd.h b/src/map/data/npcd.h deleted file mode 100644 index 52f3b76..0000000 --- a/src/map/data/npcd.h +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. -// Copyright (c) 2014 Evol developers - -#ifndef EVOL_MAP_NPCD -#define EVOL_MAP_NPCD - -struct NpcdExt; - -struct NpcdExt *npcd_get(TBL_NPC *nd); -struct NpcdExt *npcd_create(void); - -#endif // EVOL_MAP_NPCD diff --git a/src/map/data/session.c b/src/map/data/session.c deleted file mode 100644 index 7a6e16a..0000000 --- a/src/map/data/session.c +++ /dev/null @@ -1,48 +0,0 @@ -// 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 "../../../map/pc.h" - -#include "map/data/session.h" -#include "map/struct/sessionext.h" - -struct SessionExt *session_get(int fd) -{ - struct SessionExt *data = getFromSession(session[fd], 0); - if (!data) - { - data = session_create(); - addToSession(session[fd], data, 0, true); - } - return data; -} - -struct SessionExt *session_get_bysd(TBL_PC *sd) -{ - if (!sd) - return NULL; - - return session_get(sd->fd); -} - -struct SessionExt *session_create(void) -{ - struct SessionExt *data = NULL; - CREATE(data, struct SessionExt, 1); - if (!data) - return NULL; - data->clientVersion = 0; - data->language = 0; - data->state = 0; - data->onlinelistlasttime = 0; - return data; -} diff --git a/src/map/data/session.h b/src/map/data/session.h deleted file mode 100644 index 040b408..0000000 --- a/src/map/data/session.h +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. -// Copyright (c) 2014 Evol developers - -#ifndef EVOL_MAP_SESSION -#define EVOL_MAP_SESSION - -struct SessionExt; - -struct SessionExt *session_get(int fd); -struct SessionExt *session_get_bysd(TBL_PC *sd); -struct SessionExt *session_create(void); - -#endif // EVOL_MAP_SESSION diff --git a/src/map/init.c b/src/map/init.c deleted file mode 100644 index d14f5b0..0000000 --- a/src/map/init.c +++ /dev/null @@ -1,243 +0,0 @@ -// 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 "../../../map/channel.h" -#include "../../../map/chat.h" -#include "../../../map/chrif.h" -#include "../../../map/clif.h" -#include "../../../map/duel.h" -#include "../../../map/elemental.h" -#include "../../../map/homunculus.h" -#include "../../../map/instance.h" -#include "../../../map/intif.h" -#include "../../../map/irc-bot.h" -#include "../../../map/itemdb.h" -#include "../../../map/mail.h" -#include "../../../map/mapreg.h" -#include "../../../map/mercenary.h" -#include "../../../map/mob.h" -#include "../../../map/npc.h" -#include "../../../map/party.h" -#include "../../../map/pet.h" -#include "../../../map/pc.h" -#include "../../../map/script.h" -#include "../../../map/storage.h" -#include "../../../map/trade.h" -#include "../../../map/quest.h" - -#include "common/config.h" -#include "common/init.h" -#include "map/atcommand.h" -#include "map/clif.h" -#include "map/itemdb.h" -#include "map/lang.h" -#include "map/mail.h" -#include "map/map.h" -#include "map/mob.h" -#include "map/npc.h" -#include "map/unit.h" -#include "map/parse.h" -#include "map/permission.h" -#include "map/pc.h" -#include "map/quest.h" -#include "map/script.h" -#include "map/skill.h" -#include "map/status.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) */ - -extern int langScriptId; - -HPExport struct hplugin_info pinfo = -{ - "evol_map", - SERVER_TYPE_MAP, - "0.1", - HPM_VERSION -}; - -HPExport void plugin_init (void) -{ -// HPM_map_add_group_permission = GET_SYMBOL("addGroupPermission"); - - status_init(); - - addAtcommand("setskill", setSkill); - - addScriptCommand("setcamnpc", "*", setCamNpc); - addScriptCommand("setcam", "ii", setCam); - addScriptCommand("movecam", "ii", moveCam); - addScriptCommand("restorecam", "", restoreCam); - addScriptCommand("npctalk3", "s", npcTalk3); - addScriptCommand("closedialog", "", closeDialog); - addScriptCommand("shop", "s", shop); - addScriptCommand("getitemlink", "s", getItemLink); - addScriptCommand("l", "s*", l); - addScriptCommand("lg", "s*", lg); - addScriptCommand("requestlang", "v", requestLang); - addScriptCommand("requestitem", "v", requestItem); - addScriptCommand("requestitems", "v*", requestItems); - addScriptCommand("getq", "i", getq); - addScriptCommand("setq", "ii", setq); - addScriptCommand("setnpcdir", "*", setNpcDir); - addScriptCommand("rif", "is*", rif); - addScriptCommand("countitemcolor", "v*", countItemColor); - addScriptCommand("misceffect", "i*", miscEffect); - addScriptCommand("setmapmask", "si", setMapMask); - addScriptCommand("addmapmask", "si", addMapMask); - addScriptCommand("removemapmask", "si", removeMapMask); - addScriptCommand("getmapmask", "s", getMapMask); - addScriptCommand("setnpcsex", "*", setNpcSex); - addScriptCommand("showavatar", "*", showAvatar); - addScriptCommand("setavatardir", "i", setAvatarDir); - addScriptCommand("setavataraction", "i", setAvatarAction); - addScriptCommand("clear", "", clear); - addScriptCommand("changemusic", "ss", changeMusic); - addScriptCommand("setnpcdialogtitle", "s", setNpcDialogTitle); - addScriptCommand("getmapname", "", getMapName); - addScriptCommand("unequipbyid", "i", unequipById); - addScriptCommand("ispcdead", "", isPcDead); - addScriptCommand("areatimer", "siiiii*", areaTimer); - addScriptCommand("getareadropitem", "siiiiv*", getAreaDropItem); - addScriptCommand("setmount", "?", setMount); - addScriptCommand("clientcommand", "s", clientCommand); - addScriptCommand("isunitwalking", "?", isUnitWalking); - - do_init_langs(); - - addPacket(0x7530, 22, map_parse_version, hpClif_Parse); - addPacket(0xb07, 26, map_parse_join_channel, hpClif_Parse); - addPacket(0xb09, 26, map_parse_part_channel, hpClif_Parse); - addPacket(0xb0c, -1, map_parse_pet_say, hpClif_Parse); - addPacket(0xb0d, 3, map_parse_pet_emote, hpClif_Parse); - addPacket(0xb0e, 4, map_parse_set_status, hpClif_Parse); - addPacket(0xb0f, 2, map_parse_get_online_list, hpClif_Parse); - addPacket(0xb11, 10, map_parse_pet_move, hpClif_Parse); - addPacket(0xb12, 9, map_parse_pet_dir, hpClif_Parse); - addPacket(0xb13, -1, map_parse_homun_say, hpClif_Parse); - addPacket(0xb14, 3, map_parse_homun_emote, hpClif_Parse); - addPacket(0xb15, 9, map_parse_homun_dir, hpClif_Parse); - - addHookPre("atcommand->msgfd", eatcommand_msgfd); - addHookPre("atcommand->msgsd", eatcommand_msgsd); - addHookPre("pc->readparam", epc_readparam_pre); - addHookPre("pc->setregistry", epc_setregistry); - addHookPre("pc->equipitem_pos", epc_equipitem_pos); - addHookPre("pc->unequipitem_pos", epc_unequipitem_pos); - addHookPre("pc->can_attack", epc_can_attack); - addHookPre("pc->takeitem", epc_takeitem); - addHookPre("pc->validate_levels", epc_validate_levels); - addHookPre("pc->check_job_name", epc_check_job_name); - addHookPre("mob->deleteslave_sub", emob_deleteslave_sub); - addHookPre("npc->parse_unknown_mapflag", enpc_parse_unknown_mapflag); - addHookPre("npc->buysellsel", enpc_buysellsel); - addHookPre("npc->db_checkid", enpc_db_checkid); - addHookPre("clif->quest_send_list", eclif_quest_send_list); - addHookPre("clif->quest_add", eclif_quest_add); - addHookPre("clif->charnameack", eclif_charnameack); - addHookPre("clif->sendlook", eclif_sendlook); - addHookPre("clif->send", eclif_send); - addHookPre("clif->set_unit_idle", eclif_set_unit_idle); - addHookPre("clif->send_actual", eclif_send_actual); - addHookPre("itemdb->is_item_usable", eitemdb_is_item_usable); - addHookPre("itemdb->readdb_additional_fields", eitemdb_readdb_additional_fields); - addHookPre("unit->can_move", eunit_can_move); - addHookPre("unit->walktoxy", eunit_walktoxy); - addHookPre("mail->invalid_operation", email_invalid_operation); - - addHookPost("clif->getareachar_unit", eclif_getareachar_unit_post); - addHookPost("clif->authok", eclif_authok_post); - addHookPost("clif->changemap", eclif_changemap_post); - addHookPost("clif->set_unit_idle", eclif_set_unit_idle_post); - addHookPost("status->set_viewdata", estatus_set_viewdata_post); - addHookPost("status->read_job_db_sub", estatus_read_job_db_sub); - addHookPost("status->calc_pc_", estatus_calc_pc_); - addHookPost("clif->set_unit_walking", eclif_set_unit_walking); - addHookPost("clif->move", eclif_move); - addHookPost("map->addflooritem", emap_addflooritem_post); - addHookPost("skill->check_condition_castend", eskill_check_condition_castend_post); - addHookPost("pc->isequip", epc_isuseequip_post); - addHookPost("pc->isUseitem", epc_isuseequip_post); - addHookPost("pc->useitem", epc_useitem_post); - addHookPost("pc->equipitem", epc_equipitem_post); - addHookPost("pc->unequipitem", epc_unequipitem_post); - addHookPost("pc->setnewpc", epc_setnewpc); - - langScriptId = script->add_str("Lang"); -} - -HPExport void server_preinit (void) -{ - interfaces_init_common(); - - atcommand = GET_SYMBOL("atcommand"); - battle = GET_SYMBOL("battle"); - bg = GET_SYMBOL("battlegrounds"); - buyingstore = GET_SYMBOL("buyingstore"); - clif = GET_SYMBOL("clif"); - chrif = GET_SYMBOL("chrif"); - guild = GET_SYMBOL("guild"); - gstorage = GET_SYMBOL("gstorage"); - homun = GET_SYMBOL("homun"); - map = GET_SYMBOL("map"); - ircbot = GET_SYMBOL("ircbot"); - itemdb = GET_SYMBOL("itemdb"); - logs = GET_SYMBOL("logs"); - mail = GET_SYMBOL("mail"); - instance = GET_SYMBOL("instance"); - script = GET_SYMBOL("script"); - searchstore = GET_SYMBOL("searchstore"); - skill = GET_SYMBOL("skill"); - vending = GET_SYMBOL("vending"); - pc = GET_SYMBOL("pc"); - pcg = GET_SYMBOL("pc_groups"); - party = GET_SYMBOL("party"); - storage = GET_SYMBOL("storage"); - trade = GET_SYMBOL("trade"); - status = GET_SYMBOL("status"); - chat = GET_SYMBOL("chat"); - duel = GET_SYMBOL("duel"); - elemental = GET_SYMBOL("elemental"); - intif = GET_SYMBOL("intif"); - mercenary = GET_SYMBOL("mercenary"); - mob = GET_SYMBOL("mob"); - unit = GET_SYMBOL("unit"); - npc = GET_SYMBOL("npc"); - mapreg = GET_SYMBOL("mapreg"); - pet = GET_SYMBOL("pet"); - path = GET_SYMBOL("path"); - quest = GET_SYMBOL("quest"); - npc_chat = GET_SYMBOL("npc_chat"); - libpcre = GET_SYMBOL("libpcre"); - mapit = GET_SYMBOL("mapit"); - mapindex = GET_SYMBOL("mapindex"); - channel = GET_SYMBOL("channel"); - - setDefaultMap(); - addMapInterConf("default_map", config_default_map); - addMapInterConf("default_x", config_default_x); - addMapInterConf("default_y", config_default_y); - - addHookPre("quest->read_db_sub", equest_read_db_sub); - addGroupPermission("send_gm", permission_send_gm_flag); - addGroupPermission("show_client_version", permission_show_client_version_flag); -} - -HPExport void server_online (void) -{ -} - -HPExport void plugin_final (void) -{ - do_final_langs(); - commonClean(); -} diff --git a/src/map/itemdb.c b/src/map/itemdb.c deleted file mode 100644 index 13c56cf..0000000 --- a/src/map/itemdb.c +++ /dev/null @@ -1,91 +0,0 @@ -// 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 "../../../map/itemdb.h" -#include "../../../map/map.h" -#include "../../../map/npc.h" -#include "../../../map/pc.h" - -#include "map/data/itemd.h" -#include "map/struct/itemdext.h" -#include "map/npc.h" - -bool eitemdb_is_item_usable(struct item_data *item) -{ - hookStop(); - if (!item) - return false; - return item->type == IT_HEALING || item->type == IT_USABLE || item->type == IT_CASH || item->type == IT_PETEGG; -} - -void eitemdb_readdb_additional_fields(int *itemid, - config_setting_t *it, - int *n __attribute__ ((unused)), - const char *source __attribute__ ((unused))) -{ - struct item_data *item = itemdb->exists(*itemid); - int i32 = 0; - if (!item) - { - hookStop(); - return; - } - struct ItemdExt *data = itemd_get(item); - if (!data) - { - hookStop(); - return; - } - - config_setting_t *t = NULL; - - if (libconfig->setting_lookup_int(it, "FloorLifeTime", &i32) && i32 >= 0) - data->floorLifeTime = i32; - if ((t = libconfig->setting_get_member(it, "AllowPickup"))) - data->allowPickup = libconfig->setting_get_bool(t) ? 1 : 0; - if (libconfig->setting_lookup_int(it, "RequiredStr", &i32) && i32 >= 0) - data->requiredStr = i32; - if (libconfig->setting_lookup_int(it, "RequiredAgi", &i32) && i32 >= 0) - data->requiredAgi = i32; - if (libconfig->setting_lookup_int(it, "RequiredVit", &i32) && i32 >= 0) - data->requiredVit = i32; - if (libconfig->setting_lookup_int(it, "RequiredInt", &i32) && i32 >= 0) - data->requiredInt = i32; - if (libconfig->setting_lookup_int(it, "RequiredDex", &i32) && i32 >= 0) - data->requiredDex = i32; - if (libconfig->setting_lookup_int(it, "RequiredLuk", &i32) && i32 >= 0) - data->requiredLuk = i32; - if (libconfig->setting_lookup_int(it, "RequiredMaxHp", &i32) && i32 >= 0) - data->requiredMaxHp = i32; - if (libconfig->setting_lookup_int(it, "RequiredMaxSp", &i32) && i32 >= 0) - data->requiredMaxSp = i32; - if (libconfig->setting_lookup_int(it, "RequiredAtk", &i32) && i32 >= 0) - data->requiredAtk = i32; - if (libconfig->setting_lookup_int(it, "RequiredMAtkMin", &i32) && i32 >= 0) - data->requiredMAtkMin = i32; - if (libconfig->setting_lookup_int(it, "RequiredMAtkMax", &i32) && i32 >= 0) - data->requiredMAtkMax = i32; - if (libconfig->setting_lookup_int(it, "RequiredDef", &i32) && i32 >= 0) - data->requiredDef = i32; - if (libconfig->setting_lookup_int(it, "RequiredMDef", &i32) && i32 >= 0) - data->requiredMDef = i32; - - if (itemdb->lookup_const(it, "UseEffect", &i32)) - data->useEffect = i32; - if (itemdb->lookup_const(it, "UseFailEffect", &i32)) - data->useFailEffect = i32; - if (itemdb->lookup_const(it, "UnequipEffect", &i32)) - data->unequipEffect = i32; - if (itemdb->lookup_const(it, "UnequipFailEffect", &i32)) - data->unequipFailEffect = i32; - hookStop(); -} diff --git a/src/map/itemdb.h b/src/map/itemdb.h deleted file mode 100644 index 5e35d57..0000000 --- a/src/map/itemdb.h +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. -// Copyright (c) 2014 Evol developers - -#ifndef EVOL_MAP_ITEMDB -#define EVOL_MAP_ITEMDB - -bool eitemdb_is_item_usable(struct item_data *item); - -void eitemdb_readdb_additional_fields(int *itemid, config_setting_t *it, int *n, const char *source); - -#endif // EVOL_MAP_ITEMDB diff --git a/src/map/lang.c b/src/map/lang.c deleted file mode 100644 index ffc682d..0000000 --- a/src/map/lang.c +++ /dev/null @@ -1,234 +0,0 @@ -// 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 "../../../map/npc.h" -#include "../../../map/pc.h" - -#include "map/lang.h" -#include "map/data/session.h" -#include "map/struct/sessionext.h" - -#define MAX_LANGS 100 - -struct DBMap *translate_db = NULL; -char *lang_langs[MAX_LANGS]; -int lang_num = 0; - -static int langsdb_readdb (void); -static int langsdb_readlangs (void); - -void do_init_langs (void) -{ - translate_db = strdb_alloc(DB_OPT_RELEASE_BOTH, 1000); - - langsdb_readlangs (); - langsdb_readdb (); -} - -static int delete_lang_sub(DBKey key __attribute__ ((unused)), - DBData *data, - va_list args __attribute__ ((unused))) -{ - int f; - char **strings = DB->data2ptr(data); - for (f = 0; f < lang_num; f ++) - { - aFree(strings[f]); - strings[f] = NULL; - } - return 0; -} - -void do_final_langs(void) -{ - translate_db->destroy(translate_db, delete_lang_sub); - int f; - for (f = 0; f < lang_num; f ++) - aFree(lang_langs[f]); -} - -static int langsdb_readlangs (void) -{ - FILE *fp; - lang_num = 0; - fp = fopen("langs/langs.txt", "r"); - if (fp == NULL) - { - printf ("can't read langs/langs.txt\n"); - return 1; - } - char line[100]; - char text[101]; - while (fgets (line, 99, fp)) - { - if (sscanf(line, "%99s\n", text) < 1) - continue; - - lang_langs[lang_num] = aStrdup (text); - lang_num ++; - } - fclose(fp); - return 0; -} - -static int langsdb_readdb (void) -{ - char line[1020], line1[1020], line2[1020]; - char filename[1000]; - char **strings = NULL; - char *idx; - int i; - int sz; - for (i = 0; i < lang_num; i ++) - { - strcpy (filename, "langs/lang_"); - strcat (filename, lang_langs[i]); - strcat (filename, ".txt"); - - FILE *fp = fopen(filename, "r"); - if (fp == NULL) - { - printf ("can't read %s\n", filename); - return 1; - } - - if (!fgets (line, 1010, fp)) - { - printf ("can't read %s\n", filename); - continue; - } - - line1[0] = 0; - line2[0] = 0; - while (fgets (line, 1010, fp)) - { - if (*line) - { - idx = strrchr (line, '\n'); - if (idx) - *idx = 0; - } - - if (!*line) - { - line1[0] = 0; - line2[0] = 0; - continue; - } - else if (!*line1) - { - strcpy (line1, line); - continue; - } - strcpy (line2, line); - - strings = (char **)strdb_get(translate_db, line1); - if (!strings) - { - strings = aCalloc (lang_num, sizeof(int*)); - sz = strlen(line1) + 1; - strings[0] = aCalloc (sz < 24 ? 24 : sz, sizeof(char)); - strcpy (strings[0], line2); - strdb_put(translate_db, aStrdup (line1), strings); - } - else - { - sz = strlen(line2) + 1; - strings[i] = aCalloc (sz < 24 ? 24 : sz, sizeof(char)); - strcpy (strings[i], line2); - } - - *line1 = 0; - *line2 = 0; - } - fclose (fp); - } - return 0; -} - -const char* lang_trans(const char *str, int lng, int flg) -{ - if (!str) - return 0; - - if (lng < 0 || lng >= lang_num) - return str; - - char **strings = (char **)strdb_get(translate_db, str); - if (!strings) - { - if (flg) - printf ("no translations for: %s\n", str); - return str; - } - - if (!strings[lng]) - { - if (flg) - printf ("no lang string (%s) for: %s\n", lang_langs[lng], str); - return str; - } - - return strings[lng]; -} - -const char* lang_pctrans(const char *str, TBL_PC *sd) -{ - int lng = 0; - int flg = 1; - if (!str) - return 0; - - if (*str == '#') - flg = 0; - if (sd) - { - struct SessionExt *data = session_get_bysd(sd); - if (data) - lng = data->language; - } - - return lang_trans(str, lng, flg); -} - -int lang_getId(const char *str) -{ - char *str1 = aStrdup(str); - char *str2 = NULL; - int f; - - if ((str2 = strchr(str, '.'))) - *str2 = 0; - - for (f = 0; f < MAX_LANGS && lang_langs[f]; f ++) - { - if (!strcmp(str, lang_langs[f])) - { - aFree (str1); - return f; - } - } - - if ((str2 = strchr(str1, '_'))) - *str2 = 0; - - for (f = 0; f < MAX_LANGS && lang_langs[f]; f ++) - { - if (strstr(lang_langs[f], str1) == lang_langs[f]) - { - aFree (str1); - return f; - } - } - aFree (str1); - return -1; -} diff --git a/src/map/lang.h b/src/map/lang.h deleted file mode 100644 index 4afc6b9..0000000 --- a/src/map/lang.h +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. -// Copyright (c) 2014 Evol developers - -#ifndef EVOL_MAP_LANG -#define EVOL_MAP_LANG - -extern struct DBMap *translate_db; - -void do_init_langs (void); -void do_final_langs(void); -const char* lang_trans(const char *str, int lng, int flg); -const char* lang_pctrans(const char *str, TBL_PC *sd); -int lang_getId(const char *str); - -#endif // EVOL_MAP_LANG diff --git a/src/map/mail.c b/src/map/mail.c deleted file mode 100644 index d136192..0000000 --- a/src/map/mail.c +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. -// Copyright (c) 2014 Evol developers - -#include -#include -#include - -#include "../../../common/db.h" -#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 "../../../map/battle.h" -#include "../../../map/itemdb.h" -#include "../../../map/map.h" -#include "../../../map/pc.h" - -bool email_invalid_operation(struct map_session_data *sd) -{ - if (!sd) - { - hookStop(); - return true; - } - - if (!map->list[sd->bl.m].flag.town) - { - ShowWarning("clif->parse_Mail: char '%s' trying to do invalid mail operations.\n", sd->status.name); - hookStop(); - return true; - } - hookStop(); - return false; -} diff --git a/src/map/mail.h b/src/map/mail.h deleted file mode 100644 index 2c3aca2..0000000 --- a/src/map/mail.h +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. -// Copyright (c) 2014 Evol developers - -#ifndef EVOL_MAP_MAIL -#define EVOL_MAP_MAIL - -bool email_invalid_operation(struct map_session_data *sd); - -#endif // EVOL_MAP_MAIL diff --git a/src/map/map.c b/src/map/map.c deleted file mode 100644 index c1d6299..0000000 --- a/src/map/map.c +++ /dev/null @@ -1,133 +0,0 @@ -// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. -// Copyright (c) 2014 Evol developers - -#include -#include -#include - -#include "../../../common/db.h" -#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 "../../../map/battle.h" -#include "../../../map/itemdb.h" -#include "../../../map/map.h" -#include "../../../map/pc.h" - -#include "map/permission.h" -#include "map/send.h" -#include "map/data/itemd.h" -#include "map/data/session.h" -#include "map/struct/itemdext.h" -#include "map/struct/sessionext.h" - -int emap_addflooritem_post(int retVal, - struct item *item, - int *amount __attribute__ ((unused)), - int16 *m __attribute__ ((unused)), - int16 *x __attribute__ ((unused)), - int16 *y __attribute__ ((unused)), - int *first_charid __attribute__ ((unused)), - int *second_charid __attribute__ ((unused)), - int *third_charid __attribute__ ((unused)), - int *flags __attribute__ ((unused))) -{ - TBL_ITEM* fitem = (TBL_ITEM*)idb_get(map->id_db, retVal); - if (fitem && fitem->cleartimer != INVALID_TIMER) - { - int timeout = battle->bc->flooritem_lifetime; - struct ItemdExt *data = itemd_get_by_item(item); - if (data) - timeout = data->floorLifeTime; - timer->delete(fitem->cleartimer, map->clearflooritem_timer); - if (timeout >= 0) - fitem->cleartimer = timer->add(timer->gettick() + timeout, map->clearflooritem_timer, fitem->bl.id, 0); - } - return retVal; -} - -void emap_online_list(int fd) -{ - char *buf = aCalloc (1, 20000); - char *ptr = buf; - TBL_PC* sd; - - struct SessionExt *data1 = session_get(fd); - if (!data1) - { - aFree(buf); - return; - } - - const time_t t = time(NULL); - if (data1->onlinelistlasttime + 15 >= t) - { // not more than 1 per 15 seconds - data1->onlinelistlasttime = t; - aFree(buf); - return; - } - - TBL_PC* ssd = (TBL_PC*)session[fd]->session_data; - if (!ssd) - { - aFree(buf); - return; - } - - const bool showVersion = pc_has_permission(ssd, permission_show_client_version_flag); - const int gpoupLevel = pc_get_group_level(ssd); - data1->onlinelistlasttime = t; - - DBIterator* iter = db_iterator(map->pc_db); - - for (sd = dbi_first(iter); dbi_exists(iter); sd = dbi_next(iter)) - { - if (!sd) - continue; - - if (ptr - buf > 19500) - break; - - if (pc_isinvisible(sd) && gpoupLevel < pc_get_group_level(sd)) - continue; - - struct SessionExt *data = session_get_bysd(sd); - if (!data) - continue; - - uint8 state = data->state; - if (sd->status.sex == 1) - state |= 128; - else - state = (state | 128) ^ 128; - - if (pc_has_permission(sd, permission_send_gm_flag)) - state |= 64; - else - state = (state | 64) ^ 64; - - *ptr = state; - ptr ++; - - *ptr = sd->status.base_level; - ptr ++; - - if (showVersion) - *ptr = data->clientVersion; - else - *ptr = 0; - ptr ++; - - strcpy(ptr, sd->status.name); - ptr += strlen(sd->status.name); - *ptr = 0; - ptr ++; - - } - dbi_destroy(iter); - send_online_list(fd, buf, ptr - buf); - aFree(buf); -} diff --git a/src/map/map.h b/src/map/map.h deleted file mode 100644 index 3b9afce..0000000 --- a/src/map/map.h +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. -// Copyright (c) 2014 Evol developers - -#ifndef EVOL_MAP_MAP -#define EVOL_MAP_MAP - -int emap_addflooritem_post(int retVal, struct item *item, int *amount, int16 *m, int16 *x, int16 *y, int *first_charid, int *second_charid, int *third_charid, int *flags); -void emap_online_list(int fd); - -#endif // EVOL_MAP_MAP diff --git a/src/map/mob.c b/src/map/mob.c deleted file mode 100644 index 5e029f0..0000000 --- a/src/map/mob.c +++ /dev/null @@ -1,48 +0,0 @@ -// 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 "../../../map/battle.h" -#include "../../../map/itemdb.h" -#include "../../../map/mob.h" - -int emob_deleteslave_sub(struct block_list *bl, va_list ap) -{ - if (!bl) - { - hookStop(); - return 0; - } - TBL_MOB *md = (TBL_MOB *)bl; - if (!md) - { - hookStop(); - return 0; - } - - const int id = va_arg(ap, int); - if (md->master_id > 0 && md->master_id == id) - { - if (md->db->status.mode & 0x8000) - { - md->master_id = 0; - md->master_dist = 0; - } - else - { - status_kill(bl); - } - } - - hookStop(); - return 0; -} diff --git a/src/map/mob.h b/src/map/mob.h deleted file mode 100644 index d0d9e87..0000000 --- a/src/map/mob.h +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. -// Copyright (c) 2014 Evol developers - -#ifndef EVOL_MAP_MOB -#define EVOL_MAP_MOB - -int emob_deleteslave_sub(struct block_list *bl, va_list ap); - -#endif // EVOL_MAP_MOB diff --git a/src/map/npc.c b/src/map/npc.c deleted file mode 100644 index 64ee0f3..0000000 --- a/src/map/npc.c +++ /dev/null @@ -1,127 +0,0 @@ -// 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 "../../../map/map.h" -#include "../../../map/npc.h" -#include "../../../map/pc.h" - -#include "map/data/mapd.h" -#include "map/data/npcd.h" -#include "map/struct/mapdext.h" -#include "map/struct/npcdext.h" -#include "map/npc.h" - -void enpc_parse_unknown_mapflag(const char *name, char *w3, char *w4, const char* start, - const char* buffer, const char* filepath, int *retval) -{ - if (!strcmpi(w3, "invisible")) - { - int16 m = map->mapname2mapid(name); - struct MapdExt *data = mapd_get(m); - if (data) - data->invisible = true; - } - else if (!strcmpi(w3, "mask")) - { - int16 m = map->mapname2mapid(name); - struct MapdExt *data = mapd_get(m); - if (data) - data->mask = atoi(w4); - } - else if (!strcmpi(w3, "nopve")) - { - int16 m = map->mapname2mapid(name); - struct MapdExt *data = mapd_get(m); - if (data) - data->flag.nopve = 1; - } - else - { - ShowError("npc_parse_mapflag: unrecognized mapflag '%s' in file '%s', line '%d'.\n", w3, filepath, strline(buffer,start-buffer)); - if (retval) - *retval = EXIT_FAILURE; - } - hookStop(); -} - -int enpc_buysellsel(TBL_PC* sd, int *id, int *type) -{ - TBL_NPC *nd; - - if (!sd) - return 1; - - if ((nd = npc->checknear(sd, map->id2bl(*id))) == NULL) - { - hookStop(); - return 1; - } - - if (nd->option & OPTION_INVISIBLE) // can't buy if npc is not visible (hack?) - { - hookStop(); - return 1; - } - - if (*type == 0 && nd->subtype == SCRIPT && nd->u.scr.shop && nd->u.scr.shop->type == NST_MARKET) - { - clif->npc_market_open(sd, nd); - hookStop(); - return 0; - } - - if (nd->subtype != SHOP && !(nd->subtype == SCRIPT && nd->u.scr.shop && nd->u.scr.shop->items)) - { - if (nd->subtype == SCRIPT) - ShowError("npc_buysellsel: trader '%s' has no shop list!\n", nd->exname); - else - ShowError("npc_buysellsel: no such shop npc %d (%s)\n", *id, nd->exname); - - if (sd->npc_id == *id) - sd->npc_id = 0; - hookStop(); - return 1; - } - - if (nd->class_ < 0 && !sd->state.callshop) - { // not called through a script and is not a visible NPC so an invalid call - hookStop(); - return 1; - } - - // reset the callshop state for future calls - sd->state.callshop = 0; - sd->npc_shopid = *id; - - if (*type == 0) - clif->buylist(sd, nd); - else - clif->selllist(sd); - - hookStop(); - return 0; -} - -bool enpc_db_checkid(int *idPtr) -{ - const int id = *idPtr; - hookStop(); - - if (id == HIDDEN_WARP_CLASS || id == INVISIBLE_CLASS) // Special IDs not included in the valid ranges - return true; - if (id >= 45 && id < MAX_NPC_CLASS) // Second subrange - return true; - if (id >= MAX_NPC_CLASS2_START && id < MAX_NPC_CLASS2_END) // Second range - return true; - // Anything else is invalid - return false; -} diff --git a/src/map/npc.h b/src/map/npc.h deleted file mode 100644 index 4f584fe..0000000 --- a/src/map/npc.h +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. -// Copyright (c) 2014 Evol developers - -#ifndef EVOL_MAP_NPC -#define EVOL_MAP_NPC - -void enpc_parse_unknown_mapflag(const char *name, char *w3, char *w4, const char* start, - const char* buffer, const char* filepath, int *retval); - -int enpc_buysellsel(TBL_PC* sd, int *id, int *type); - -bool enpc_db_checkid(int *idPtr); - -#endif // EVOL_MAP_NPC diff --git a/src/map/parse.c b/src/map/parse.c deleted file mode 100644 index 38e42f3..0000000 --- a/src/map/parse.c +++ /dev/null @@ -1,220 +0,0 @@ -// 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 "../../../map/channel.h" -#include "../../../map/clif.h" -#include "../../../map/homunculus.h" -#include "../../../map/mercenary.h" -#include "../../../map/pc.h" -#include "../../../map/pet.h" -#include "../../../map/unit.h" - -#include "map/parse.h" -#include "map/send.h" -#include "map/map.h" -#include "map/data/session.h" -#include "map/struct/sessionext.h" - -void map_parse_version(int fd) -{ - struct SessionExt *data = session_get(fd); - if (!data) - return; - data->clientVersion = RFIFOL(fd, 2); -} - -void map_parse_join_channel(int fd) -{ - char name[24]; - char *p; - TBL_PC* sd = (TBL_PC*)session[fd]->session_data; - int res = 0; - if (!sd) - return; - - safestrncpy(name, (char*)RFIFOP(fd, 2), 24); - if (name[0] == '#') - p = name + 1; - else - p = name; - - struct channel_data *chan = channel->search(p, sd); - - if (chan) - { - int k; - ARR_FIND(0, sd->channel_count, k, sd->channels[k] == chan); - if (k < sd->channel_count || channel->join(chan, sd, NULL, true) == HCS_STATUS_OK) - res = 1; - else - res = 0; - } - - send_join_ack(fd, name, res); -} - -void map_parse_part_channel(int fd) -{ - char name[24]; - char *p; - TBL_PC* sd = (TBL_PC*)session[fd]->session_data; - int k; - if (!sd) - return; - - safestrncpy(name, (char*)RFIFOP(fd, 2), 24); - if (name[0] == '#') - p = name + 1; - else - p = name; - - for (k = 0; k < sd->channel_count; k ++) - { - if (strcmpi(p, sd->channels[k]->name) == 0) - break; - } - - if (k == sd->channel_count) - return; - - if (sd->channels[k]->type == HCS_TYPE_ALLY) - { - do - { - for (k = 0; k < sd->channel_count; k++) - { - if (sd->channels[k]->type == HCS_TYPE_ALLY) - { - channel->leave(sd->channels[k], sd); - break; - } - } - } - while (k != sd->channel_count); - } - else - { - channel->leave(sd->channels[k], sd); - } -} - -void map_parse_pet_say(int fd) -{ - char message[500]; - - TBL_PC* sd = (TBL_PC*)session[fd]->session_data; - if (!sd || !sd->pd) - return; - - const int len = RFIFOW(fd, 2); - if (len > 500 || len < 6) - return; - safestrncpy(message, (char*)RFIFOP(fd, 4), len - 4); - send_slave_say(sd, &sd->pd->bl, sd->pd->pet.name, message); -} - -void map_parse_pet_emote(int fd) -{ - TBL_PC* sd = (TBL_PC*)session[fd]->session_data; - if (!sd || !sd->pd) - return; - const time_t t = time(NULL); - if (sd->emotionlasttime + 1 >= t) - { // not more than 1 per second - sd->emotionlasttime = t; - return; - } - - sd->emotionlasttime = t; - clif->emotion(&sd->pd->bl, RFIFOB(fd, 2)); -} - -void map_parse_set_status(int fd) -{ - struct SessionExt *data = session_get(fd); - if (!data) - return; - data->state = RFIFOB(fd, 2); -} - -void map_parse_get_online_list(int fd) -{ - emap_online_list(fd); -} - -void map_parse_pet_move(int fd) -{ - TBL_PC* sd = (TBL_PC*)session[fd]->session_data; - if (!sd || !sd->pd) - return; - short x = RFIFOW(fd, 6); - short y = RFIFOW(fd, 8); - - struct block_list *pdBl = &sd->pd->bl; - if (map->getcell(pdBl->m, x, y, CELL_CHKPASS)) - unit->walktoxy(pdBl, x, y, 0); -} - -void map_parse_pet_dir(int fd) -{ - TBL_PC* sd = (TBL_PC*)session[fd]->session_data; - if (!sd || !sd->pd) - return; - unit->setdir(&sd->pd->bl, RFIFOB(fd, 8)); -} - -void map_parse_homun_say(int fd) -{ - char message[500]; - - TBL_PC* sd = (TBL_PC*)session[fd]->session_data; - if (!sd) - return; - const int len = RFIFOW(fd, 2); - if (len > 500 || len < 6) - return; - safestrncpy(message, (char*)RFIFOP(fd, 4), len - 4); - if (sd->md && sd->md->db) - send_slave_say(sd, &sd->md->bl, sd->md->db->name, message); - else if (sd->hd && homun_alive(sd->hd)) - send_slave_say(sd, &sd->hd->bl, sd->hd->homunculus.name, message); -} - -void map_parse_homun_emote(int fd) -{ - TBL_PC* sd = (TBL_PC*)session[fd]->session_data; - if (!sd) - return; - const time_t t = time(NULL); - if (sd->emotionlasttime + 1 >= t) - { // not more than 1 per second - sd->emotionlasttime = t; - return; - } - - sd->emotionlasttime = t; - if (sd->md && sd->md->db) - clif->emotion(&sd->md->bl, RFIFOB(fd, 2)); - else if (sd->hd && homun_alive(sd->hd)) - clif->emotion(&sd->hd->bl, RFIFOB(fd, 2)); -} - -void map_parse_homun_dir(int fd) -{ - TBL_PC* sd = (TBL_PC*)session[fd]->session_data; - if (!sd || !sd->pd) - return; - if (sd->md && sd->md->db) - unit->setdir(&sd->md->bl, RFIFOB(fd, 8)); - else if (sd->hd && homun_alive(sd->hd)) - unit->setdir(&sd->hd->bl, RFIFOB(fd, 8)); -} diff --git a/src/map/parse.h b/src/map/parse.h deleted file mode 100644 index 8d137ad..0000000 --- a/src/map/parse.h +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. -// Copyright (c) 2014 Evol developers - -#ifndef EVOL_MAP_PARSE -#define EVOL_MAP_PARSE - -void map_parse_version(int fd); -void map_parse_join_channel(int fd); -void map_parse_part_channel(int fd); -void map_parse_pet_say(int fd); -void map_parse_pet_emote(int fd); -void map_parse_set_status(int fd); -void map_parse_get_online_list(int fd); -void map_parse_pet_move(int fd); -void map_parse_pet_dir(int fd); -void map_parse_homun_say(int fd); -void map_parse_homun_emote(int fd); -void map_parse_homun_dir(int fd); - -#endif // EVOL_MAP_PARSE diff --git a/src/map/pc.c b/src/map/pc.c deleted file mode 100644 index c24c758..0000000 --- a/src/map/pc.c +++ /dev/null @@ -1,309 +0,0 @@ -// 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 "../../../map/itemdb.h" -#include "../../../map/pc.h" - -#include "map/pc.h" -#include "map/data/itemd.h" -#include "map/data/mapd.h" -#include "map/data/session.h" -#include "map/struct/itemdext.h" -#include "map/struct/mapdext.h" -#include "map/struct/sessionext.h" - -int langScriptId; - -int epc_readparam_pre(TBL_PC* sd, int *type) -{ - if (*type == Const_ClientVersion) - { - struct SessionExt *data = session_get_bysd(sd); - hookStop(); - if (!data) - return 0; - return data->clientVersion; - } - return 0; -} - -int epc_setregistry(TBL_PC *sd, int64 *reg, int *val) -{ - if (*reg == langScriptId) - { - struct SessionExt *data = session_get_bysd(sd); - if (!data) - return 0; - - data->language = *val; - } - - return 0; -} - -#define equipPos(mask, field, lookf) \ - if (pos & mask) \ - { \ - if (id) \ - sd->status.field = id->look; \ - else \ - sd->status.field = 0; \ - clif->changelook(&sd->bl, lookf, sd->status.field); \ - hookStop(); \ - } - -#define equipPos2(mask, lookf) \ - if (pos & mask) \ - { \ - if (id) \ - clif->changelook(&sd->bl, lookf, id->look); \ - else \ - clif->changelook(&sd->bl, lookf, 0); \ - hookStop(); \ - } - -void epc_equipitem_pos(TBL_PC *sd, struct item_data *id, int *posPtr) -{ - int pos = *posPtr; - - if (!id) - return; - - equipPos(EQP_HEAD_LOW, head_bottom, LOOK_HEAD_BOTTOM); - equipPos(EQP_HEAD_TOP, head_top, LOOK_HEAD_TOP); - equipPos(EQP_HEAD_MID, head_mid, LOOK_HEAD_MID); - equipPos(EQP_GARMENT, robe, LOOK_ROBE); - //skip EQP_ARMOR - equipPos2(EQP_SHOES, LOOK_SHOES); - equipPos2(EQP_COSTUME_HEAD_TOP, 13); - equipPos2(EQP_COSTUME_HEAD_MID, 14); - equipPos2(EQP_COSTUME_HEAD_LOW, 15); - equipPos2(EQP_COSTUME_GARMENT, 16); - equipPos2(EQP_ARMOR, 17); - //skipping SHADOW slots -} - -#undef equipPos -#undef equipPos2 - -#define unequipPos(mask, field, lookf) \ - if (pos & mask) \ - { \ - sd->status.field = 0; \ - clif->changelook(&sd->bl, lookf, sd->status.field); \ - hookStop(); \ - } - -#define unequipPos2(mask, lookf) \ - if (pos & mask) \ - { \ - clif->changelook(&sd->bl, lookf, 0); \ - hookStop(); \ - } - -void epc_unequipitem_pos(TBL_PC *sd, - int *nPtr __attribute__ ((unused)), - int *posPtr) -{ - if (!sd) - return; - - int pos = *posPtr; - - unequipPos(EQP_HEAD_LOW, head_bottom, LOOK_HEAD_BOTTOM); - unequipPos(EQP_HEAD_TOP, head_top, LOOK_HEAD_TOP); - unequipPos(EQP_HEAD_MID, head_mid, LOOK_HEAD_MID); - unequipPos(EQP_GARMENT, robe, LOOK_ROBE); - unequipPos2(EQP_SHOES, LOOK_SHOES); - unequipPos2(EQP_COSTUME_HEAD_TOP, 13); - unequipPos2(EQP_COSTUME_HEAD_MID, 14); - unequipPos2(EQP_COSTUME_HEAD_LOW, 15); - unequipPos2(EQP_COSTUME_GARMENT, 16); - unequipPos2(EQP_ARMOR, 17); - //skipping SHADOW slots -} - -#undef unequipPos -#undef unequipPos2 - -bool epc_can_attack (TBL_PC *sd, int *target_id) -{ - if (!sd) - return false; - - struct MapdExt *data = mapd_get(sd->bl.m); - if (!data) - return true; - if (data->flag.nopve) - { - if (map->id2md(*target_id)) - { - hookStop(); - return false; - } - } - return true; -} - -int epc_takeitem(TBL_PC *sd __attribute__ ((unused)), - TBL_ITEM *fitem) -{ - if (!fitem) - return 0; - - struct ItemdExt *data = itemd_get_by_item(&fitem->item_data); - if (!data) - return 1; - - if (!data->allowPickup) - { - hookStop(); - return 0; - } - return 1; -} - -void epc_validate_levels(void) -{ - int i; - for (i = 0; i < 7; i++) { - if (!pc->db_checkid(i)) continue; - if (i == JOB_WEDDING || i == JOB_XMAS || i == JOB_SUMMER) - continue; //Classes that do not need exp tables. - int j = pc->class2idx(i); - if (!pc->max_level[j][0]) - ShowWarning("Class %d does not has a base exp table.\n", i); - if (!pc->max_level[j][1]) - ShowWarning("Class %d does not has a job exp table.\n", i); - } - hookStop(); -} - -int epc_isuseequip_post(int retVal, struct map_session_data *sd, int *nPtr) -{ - const int n = *nPtr; - if (retVal) - { - if (!sd) - return 0; - - if (n < 0 || n >= MAX_INVENTORY) - return 0; - - struct ItemdExt *data = itemd_get(sd->inventory_data[n]); - if (!data) - return retVal; - - if (sd->battle_status.str < data->requiredStr || - sd->battle_status.agi < data->requiredAgi || - sd->battle_status.vit < data->requiredVit || - sd->battle_status.int_ < data->requiredInt || - sd->battle_status.dex < data->requiredDex || - sd->battle_status.luk < data->requiredLuk || - sd->battle_status.max_hp < data->requiredMaxHp || - sd->battle_status.max_sp < data->requiredMaxSp || - sd->battle_status.batk < data->requiredAtk || - sd->battle_status.matk_min < data->requiredMAtkMin || - sd->battle_status.matk_max < data->requiredMAtkMax || - sd->battle_status.def < data->requiredDef || - sd->battle_status.mdef < data->requiredMDef - ) - { - return 0; - } - } - return retVal; -} - -int epc_useitem_post(int retVal, struct map_session_data *sd, int *nPtr) -{ - const int n = *nPtr; - if (!sd) - return retVal; - - if (n < 0 || n >= MAX_INVENTORY) - return retVal; - - struct ItemdExt *data = itemd_get(sd->inventory_data[n]); - if (!data) - return retVal; - - const int effect = retVal ? data->useEffect : data->useFailEffect; - if (effect != -1) - clif->specialeffect(&sd->bl, effect, AREA); - return retVal; -} - -static void equippost_effect(struct map_session_data *const sd, const int n, const bool retVal, const bool equip) -{ - if (!sd) - return; - - if (n < 0 || n >= MAX_INVENTORY) - return; - - struct ItemdExt *data = itemd_get(sd->inventory_data[n]); - if (!data) - return; - - int effect; - if (equip) - effect = retVal ? data->useEffect : data->useFailEffect; - else - effect = retVal ? data->unequipEffect : data->unequipFailEffect; - - if (effect != -1) - clif->specialeffect(&sd->bl, effect, AREA); - return; -} - -int epc_equipitem_post(int retVal, struct map_session_data *sd, - int *nPtr, int *data __attribute__ ((unused))) -{ - equippost_effect(sd, *nPtr, retVal, true); - return retVal; -} - -int epc_unequipitem_post(int retVal, struct map_session_data *sd, - int *nPtr, int *data __attribute__ ((unused))) -{ - equippost_effect(sd, *nPtr, retVal, false); - return retVal; -} - -int epc_check_job_name(const char *name) -{ - int val = -1; - if (script->get_constant(name, &val)) - { - hookStop(); - return val; - } - hookStop(); - return -1; -} - -int epc_setnewpc(int retVal, struct map_session_data *sd, - int *account_id __attribute__ ((unused)), - int *char_id __attribute__ ((unused)), - int *login_id1 __attribute__ ((unused)), - unsigned int *client_tick __attribute__ ((unused)), - int *sex __attribute__ ((unused)), - int *fd __attribute__ ((unused))) -{ - if (sd) - { - sd->battle_status.speed = 150; - sd->base_status.speed = 150; - } - return retVal; -} diff --git a/src/map/pc.h b/src/map/pc.h deleted file mode 100644 index e850b81..0000000 --- a/src/map/pc.h +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. -// Copyright (c) 2014 Evol developers - -#ifndef EVOL_MAP_PC -#define EVOL_MAP_PC - -enum VarConst -{ - Const_ClientVersion = 10000 -}; - -int epc_readparam_pre(TBL_PC* sd, int *type); - -int epc_setregistry(TBL_PC *sd, int64 *reg, int *val); - -void epc_equipitem_pos(TBL_PC *sd, struct item_data *id, int *posPtr); - -void epc_unequipitem_pos(TBL_PC *sd, int *nPtr, int *posPtr); - -bool epc_can_attack (TBL_PC *sd, int *target_id); - -int epc_takeitem(TBL_PC *sd, TBL_ITEM *fitem); - -void epc_validate_levels(void); - -int epc_isuseequip_post(int retVal, struct map_session_data *sd, int *nPtr); - -int epc_useitem_post(int retVal, struct map_session_data *sd, int *nPtr); - -int epc_equipitem_post(int retVal, struct map_session_data *sd, - int *nPtr, int *data); - -int epc_unequipitem_post(int retVal, struct map_session_data *sd, - int *nPtr, int *data); - -int epc_check_job_name(const char *name); - -int epc_setnewpc(int retVal, struct map_session_data *sd, - int *account_id, int *char_id, int *login_id1, - unsigned int *client_tick, int *sex, int *fd); - -#endif // EVOL_MAP_PC diff --git a/src/map/permission.c b/src/map/permission.c deleted file mode 100644 index 03026d0..0000000 --- a/src/map/permission.c +++ /dev/null @@ -1,18 +0,0 @@ -// 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 "../../../map/map.h" -#include "../../../map/npc.h" -#include "../../../map/status.h" - -unsigned int permission_send_gm_flag = UINT_MAX - 1; -unsigned int permission_show_client_version_flag = UINT_MAX - 2; diff --git a/src/map/permission.h b/src/map/permission.h deleted file mode 100644 index a585c98..0000000 --- a/src/map/permission.h +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. -// Copyright (c) 2014 Evol developers - -#ifndef EVOL_MAP_PERMISSION -#define EVOL_MAP_PERMISSION - -extern unsigned int permission_send_gm_flag; -extern unsigned int permission_show_client_version_flag; - -#endif // EVOL_MAP_PERMISSION diff --git a/src/map/quest.c b/src/map/quest.c deleted file mode 100644 index c2b85bf..0000000 --- a/src/map/quest.c +++ /dev/null @@ -1,132 +0,0 @@ -// 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 "../../../map/itemdb.h" -#include "../../../map/quest.h" - -#include "map/quest.h" - -/** - * Reads and parses an entry from the quest_db. - * - * @param cs The config setting containing the entry. - * @param n The sequential index of the current config setting. - * @param source The source configuration file. - * @return The parsed quest entry. - * @retval NULL in case of errors. - */ -struct quest_db *equest_read_db_sub(config_setting_t *cs, int *nPtr, const char *source) -{ - struct quest_db *entry = NULL; - config_setting_t *t = NULL; - int i32 = 0, quest_id; - const char *str = NULL; - const int n = *nPtr; - - /* - * Id: Quest ID [int] - * Name: Quest Name [string] - * TimeLimit: Time Limit (seconds) [int, optional] - * Targets: ( [array, optional] - * { - * MobId: Mob ID [int] - * Count: [int] - * }, - * ... (can repeated up to MAX_QUEST_OBJECTIVES times) - * ) - * Drops: ( - * { - * ItemId: Item ID to drop [int] - * Rate: Drop rate [int] - * MobId: Mob ID to match [int, optional] - * }, - * ... (can be repeated) - * ) - */ - - if (!libconfig->setting_lookup_int(cs, "Id", &quest_id)) { - ShowWarning("quest_read_db: Missing id in \"%s\", entry #%d, skipping.\n", source, n); - hookStop(); - return NULL; - } - if (quest_id < 0 || quest_id >= MAX_QUEST_DB) { - ShowWarning("quest_read_db: Invalid quest ID '%d' in \"%s\", entry #%d (min: 0, max: %d), skipping.\n", quest_id, source, n, MAX_QUEST_DB); - hookStop(); - return NULL; - } - - if (!libconfig->setting_lookup_string(cs, "Name", &str) || !*str) { - ShowWarning("quest_read_db_sub: Missing Name in quest %d of \"%s\", skipping.\n", quest_id, source); - hookStop(); - return NULL; - } - - CREATE(entry, struct quest_db, 1); - entry->id = quest_id; - //safestrncpy(entry->name, str, sizeof(entry->name)); - - if (libconfig->setting_lookup_int(cs, "TimeLimit", &i32)) // This is an unsigned value, do not check for >= 0 - entry->time = (unsigned int)i32; - - if ((t=libconfig->setting_get_member(cs, "Targets")) && config_setting_is_list(t)) { -/* - int i, len = libconfig->setting_length(t); - for (i = 0; i < len && entry->objectives_count < MAX_QUEST_OBJECTIVES; i++) { - // Note: We ensure that objectives_count < MAX_QUEST_OBJECTIVES because - // quest_log (as well as the client) expect this maximum size. - config_setting_t *tt = libconfig->setting_get_elem(t, i); - int mob_id = 0, count = 0; - if (!tt) - break; - if (!config_setting_is_group(tt)) - continue; - if (!libconfig->setting_lookup_int(tt, "MobId", &mob_id) || mob_id <= 0) - continue; - if (!libconfig->setting_lookup_int(tt, "Count", &count) || count <= 0) - continue; - RECREATE(entry->objectives, struct quest_objective, ++entry->objectives_count); - entry->objectives[entry->objectives_count-1].mob = mob_id; - entry->objectives[entry->objectives_count-1].count = count; - } -*/ - entry->objectives_count = 1; - RECREATE(entry->objectives, struct quest_objective, 1); - entry->objectives[0].mob = 1; - entry->objectives[0].count = 0; - } - - if ((t=libconfig->setting_get_member(cs, "Drops")) && config_setting_is_list(t)) { - int i, len = libconfig->setting_length(t); - for (i = 0; i < len; i++) { - config_setting_t *tt = libconfig->setting_get_elem(t, i); - int mob_id = 0, nameid = 0, rate = 0; - if (!tt) - break; - if (!config_setting_is_group(tt)) - continue; - if (!libconfig->setting_lookup_int(tt, "MobId", &mob_id)) - mob_id = 0; // Zero = any monster - if (mob_id < 0) - continue; - if (!libconfig->setting_lookup_int(tt, "ItemId", &nameid) || !itemdb->exists(nameid)) - continue; - if (!libconfig->setting_lookup_int(tt, "Rate", &rate) || rate <= 0) - continue; - RECREATE(entry->dropitem, struct quest_dropitem, ++entry->dropitem_count); - entry->dropitem[entry->dropitem_count-1].mob_id = mob_id; - entry->dropitem[entry->dropitem_count-1].nameid = nameid; - entry->dropitem[entry->dropitem_count-1].rate = rate; - } - } - hookStop(); - return entry; -} diff --git a/src/map/quest.h b/src/map/quest.h deleted file mode 100644 index c947bcc..0000000 --- a/src/map/quest.h +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. -// Copyright (c) 2014 Evol developers - -#ifndef EVOL_MAP_QUEST -#define EVOL_MAP_QUEST - -struct quest_db *equest_read_db_sub(config_setting_t *cs, int *nPtr, const char *source); - -#endif // EVOL_MAP_QUEST diff --git a/src/map/script.c b/src/map/script.c deleted file mode 100644 index 02e34a4..0000000 --- a/src/map/script.c +++ /dev/null @@ -1,1148 +0,0 @@ -// 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 "../../../map/chrif.h" -#include "../../../map/clif.h" -#include "../../../map/npc.h" -#include "../../../map/pc.h" -#include "../../../map/script.h" -#include "../../../map/quest.h" -#include "../../../map/unit.h" - -#include "map/script.h" -#include "map/clif.h" -#include "map/lang.h" -#include "map/scriptdefines.h" -#include "map/send.h" -#include "map/data/mapd.h" -#include "map/data/npcd.h" -#include "map/data/session.h" -#include "map/struct/mapdext.h" -#include "map/struct/npcdext.h" -#include "map/struct/sessionext.h" -#include "map/utils/formatutils.h" - -BUILDIN(l) -{ - format_sub(st, 1); - return true; -} - -BUILDIN(lg) -{ - format_sub(st, 2); - return true; -} - -BUILDIN(setCamNpc) -{ - getSD(); - TBL_NPC *nd = NULL; - - int x = 0; - int y = 0; - - if (script_hasdata(st, 2)) - { - nd = npc->name2id (script_getstr(st, 2)); - } - else - { - if (!st->oid) - { - ShowWarning("npc not attached\n"); - script->reportsrc(st); - return false; - } - - nd = (TBL_NPC *) map->id2bl (st->oid); - } - if (!nd) - { - ShowWarning("npc not found\n"); - script->reportsrc(st); - return false; - } - if (sd->bl.m != nd->bl.m) - { - ShowWarning("npc and player located in other maps\n"); - script->reportsrc(st); - return false; - } - - if (script_hasdata(st, 3) && script_hasdata(st, 4)) - { - x = script_getnum(st, 3); - y = script_getnum(st, 4); - } - - send_npccommand2(script->rid2sd (st), st->oid, 2, nd->bl.id, x, y); - - return true; -} - -BUILDIN(setCam) -{ - send_npccommand2(script->rid2sd (st), st->oid, 2, 0, - script_getnum(st, 2), script_getnum(st, 3)); - - return true; -} - -BUILDIN(moveCam) -{ - send_npccommand2(script->rid2sd (st), st->oid, 4, 0, - script_getnum(st, 2), script_getnum(st, 3)); - - return true; -} - -BUILDIN(restoreCam) -{ - getSD(); - send_npccommand(sd, st->oid, 3); - return true; -} - -BUILDIN(npcTalk3) -{ - const char *str; - char *msg; - TBL_NPC *nd = NULL; - - getSD(); - - if (script_hasdata(st, 3)) - { - nd = npc->name2id (script_getstr(st, 2)); - str = script_getstr(st, 3); - } - else - { - nd = (TBL_NPC *) map->id2bl (st->oid); - str = script_getstr(st, 2); - } - - if (!nd) - { - ShowWarning("npc not found\n"); - script->reportsrc(st); - return false; - } - - if (!str) - { - ShowWarning("error in string\n"); - script->reportsrc(st); - return false; - } - - if (sd) - msg = (char*)lang_pctrans (nd->name, sd); - else - msg = nd->name; - - if (!msg) - { - ShowWarning("error in string\n"); - script->reportsrc(st); - return false; - } - if (strlen(str) + strlen(msg) > 450) - { - ShowWarning("text message too big\n"); - script->reportsrc(st); - return false; - } - - if (nd) - { - char message[500]; - char name[500]; - strcpy (name, msg); - strtok(name, "#"); - strcpy (message, name); - strcat (message, " : "); - strcat (message, str); - send_local_message (sd->fd, &(nd->bl), message); - } - - return true; -} - -BUILDIN(closeDialog) -{ - getSD(); - send_npccommand(script->rid2sd (st), st->oid, 5); - return true; -} - -BUILDIN(shop) -{ - getSD(); - TBL_NPC *nd = npc->name2id (script_getstr(st, 2)); - if (!nd) - { - ShowWarning("shop npc not found\n"); - script->reportsrc(st); - return false; - } - - st->state = sd->state.dialog == 1 ? CLOSE : END; - clif->scriptclose(sd, st->oid); - - clif->npcbuysell (sd, nd->bl.id); - return true; -} - -BUILDIN(getItemLink) -{ - struct item_data *i_data; - char *item_name; - int item_id = 0; - - if (script_isstringtype(st, 2)) - { - i_data = itemdb->search_name (script_getstr(st, 2)); - } - else - { - item_id = script_getnum (st, 2); - i_data = itemdb->search (item_id); - } - - item_name = (char *) aCalloc (100, sizeof (char)); - TBL_PC *sd = script->rid2sd(st); - - if (sd) - { - int version = 0; - struct SessionExt *data = session_get_bysd(sd); - if (data) - version = data->clientVersion; - - if (i_data && version >= 7) - sprintf(item_name, "[@@%u|@@]", (unsigned)i_data->nameid); - else if (i_data) - sprintf(item_name, "[@@%u|%s@@]", (unsigned)i_data->nameid, lang_pctrans (i_data->jname, sd)); - else if (item_id > 0) - sprintf(item_name, "[@@%u|Unknown Item@@]", (unsigned)item_id); - else - sprintf(item_name, "[Unknown Item]"); - } - else - { - if (i_data) - sprintf(item_name, "[%s]", lang_pctrans (i_data->jname, sd)); - else - sprintf(item_name, "[Unknown Item]"); - } - - script_pushstr(st, item_name); - - return true; -} - -BUILDIN(requestLang) -{ - getSD(); - struct script_data* data; - int64 uid; - const char* name; - - data = script_getdata(st, 2); - if (!data_isreference(data)) - { - ShowError("script:requestlang: not a variable\n"); - script->reportsrc(st); - st->state = END; - return false; - } - uid = reference_getuid(data); - name = reference_getname(data); - - if (is_string_variable(name)) - { - ShowError("script:requestlang: not a variable\n"); - script->reportsrc(st); - return false; - } - - if (!sd->state.menu_or_input) - { - // first invocation, display npc input box - sd->state.menu_or_input = 1; - st->state = RERUNLINE; - - // send lang request - send_npccommand(script->rid2sd(st), st->oid, 0); - clif->scriptinputstr(sd, st->oid); - } - else - { - // take received text/value and store it in the designated variable - sd->state.menu_or_input = 0; - - int lng = -1; - if (*sd->npc_str) - lng = lang_getId(sd->npc_str); - script->set_reg(st, sd, uid, name, (void*)h64BPTRSIZE(lng), script_getref(st,2)); - st->state = RUN; - } - return true; -} - -BUILDIN(requestItem) -{ - getSD(); - struct script_data* data; - int64 uid; - const char* name; - - data = script_getdata(st, 2); - if (!data_isreference(data)) - { - ShowError("script:requestitem: not a variable\n"); - script->reportsrc(st); - st->state = END; - return false; - } - uid = reference_getuid(data); - name = reference_getname(data); - - if (is_string_variable(name)) - { - ShowError("script:requestlang: not a variable\n"); - script->reportsrc(st); - return false; - } - - if (!sd->state.menu_or_input) - { - // first invocation, display npc input box - sd->state.menu_or_input = 1; - st->state = RERUNLINE; - - // send item request - send_npccommand(script->rid2sd(st), st->oid, 10); - } - else - { - // take received text/value and store it in the designated variable - sd->state.menu_or_input = 0; - - int item = 0; - - if (!sd->npc_str) - { - ShowWarning("npc string not found\n"); - script->reportsrc(st); - return false; - } - - if (sscanf (sd->npc_str, "%5d", &item) < 1) - { - ShowWarning("input data is not item id\n"); - script->reportsrc(st); - return false; - } - - script->set_reg(st, sd, uid, name, (void*)h64BPTRSIZE(item), script_getref(st,2)); - st->state = RUN; - } - return true; -} - -BUILDIN(requestItems) -{ - getSD(); - struct script_data* data; - int64 uid; - const char* name; - - data = script_getdata(st, 2); - if (!data_isreference(data)) - { - ShowError("script:requestitem: not a variable\n"); - script->reportsrc(st); - st->state = END; - return false; - } - uid = reference_getuid(data); - name = reference_getname(data); - - if (!is_string_variable(name)) - { - ShowWarning("parameter is not variable\n"); - script->reportsrc(st); - return false; - } - - int count = 1; - - if (script_hasdata(st, 3)) - { - count = script_getnum(st, 3); - if (count < 0) - count = 1; - } - - if (!sd->state.menu_or_input) - { - // first invocation, display npc input box - sd->state.menu_or_input = 1; - st->state = RERUNLINE; - - // send item request with limit count - send_npccommand2(script->rid2sd (st), st->oid, 10, count, 0, 0); - } - else - { - // take received text/value and store it in the designated variable - sd->state.menu_or_input = 0; - - if (!sd->npc_str) - { - ShowWarning("npc string not found\n"); - script->reportsrc(st); - return false; - } - - script->set_reg(st, sd, uid, name, (void*)sd->npc_str, script_getref(st, 2)); - st->state = RUN; - } - return true; -} - -BUILDIN(setq) -{ - int i; - getSD(); - - int quest_id = script_getnum(st, 2); - int quest_value = script_getnum(st, 3); - - if (quest->check(sd, quest_id, HAVEQUEST) < 0) - quest->add(sd, quest_id); - ARR_FIND(0, sd->num_quests, i, sd->quest_log[i].quest_id == quest_id); - if (i == sd->num_quests) - { - ShowError("Quest with id=%d not found\n", quest_id); - script->reportsrc(st); - return false; - } - - sd->quest_log[i].count[0] = quest_value; - sd->save_quest = true; - if (map->save_settings & 64) - chrif->save(sd,0); - - eclif_quest_add(sd, &sd->quest_log[i]); - return true; -} - -BUILDIN(getq) -{ - int i; - getSDReturn(0); - - int quest_id = script_getnum(st, 2); - if (quest->check(sd, quest_id, HAVEQUEST) < 0) - { - script_pushint(st, 0); - return true; - } - ARR_FIND(0, sd->num_quests, i, sd->quest_log[i].quest_id == quest_id); - if (i == sd->num_quests) - { - script_pushint(st, 0); - return true; - } - script_pushint(st, sd->quest_log[i].count[0]); - return true; -} - -BUILDIN(setNpcDir) -{ - int newdir; - TBL_NPC *nd = 0; - - if (script_hasdata(st, 3)) - { - nd = npc->name2id (script_getstr(st, 2)); - newdir = script_getnum(st, 3); - } - else if (script_hasdata(st, 2)) - { - if (!st->oid) - { - ShowWarning("npc not found\n"); - script->reportsrc(st); - return false; - } - - nd = (TBL_NPC *) map->id2bl (st->oid); - newdir = script_getnum(st, 2); - } - if (!nd) - { - ShowWarning("npc not found\n"); - script->reportsrc(st); - return false; - } - - if (newdir < 0) - newdir = 0; - else if (newdir > 7) - newdir = 7; - - nd->dir = newdir; - npc->enable (nd->name, 1); - - return true; -} - -BUILDIN(rif) -{ - const char *str = 0; - if (script_getnum(st, 2)) - { - str = script_getstr(st, 3); - if (str) - script_pushstr(st, aStrdup(str)); - else - script_pushconststr(st, (char *)""); - } - else if (script_hasdata(st, 4)) - { - str = script_getstr(st, 4); - if (str) - script_pushstr(st, aStrdup(str)); - else - script_pushconststr(st, (char *)""); - } - else - { - script_pushconststr(st, (char *)""); - } - - return true; -} - -BUILDIN(countItemColor) -{ - int nameid, i; - int count = 0; - struct item_data* id = NULL; - - TBL_PC* sd = script->rid2sd(st); - if (!sd) - { - ShowWarning("player not attached\n"); - script->reportsrc(st); - return false; - } - - if (script_isstringtype(st, 2)) - { - // item name - id = itemdb->search_name(script_getstr(st, 2)); - } - else - { - // item id - id = itemdb->exists(script_getnum(st, 2)); - } - - if (id == NULL) - { - ShowError("buildin_countitem: Invalid item '%s'.\n", script_getstr(st,2)); // returns string, regardless of what it was - script->reportsrc(st); - script_pushint(st,0); - return false; - } - - nameid = id->nameid; - - for(i = 0; i < MAX_INVENTORY; i++) - { - if(sd->status.inventory[i].nameid == nameid) - count += sd->status.inventory[i].amount; - } - - script_pushint(st, count); - return true; -} - -BUILDIN(miscEffect) -{ - int type = script_getnum(st, 2); - struct block_list *bl = NULL; - - if (script_hasdata(st, 3)) - { - if (script_isstring(st, 3)) - { - TBL_PC *sd = map->nick2sd(script_getstr(st, 3)); - if (sd) - bl = &sd->bl; - } - else if (script_isint(st, 3)) - { - bl = map->id2bl(script_getnum(st, 3)); - } - } - - if (!bl) - { - TBL_PC *sd = script->rid2sd (st); - if (sd) - bl = &sd->bl; - } - if (bl) - clif->specialeffect(bl, type, AREA); - return true; -} - -BUILDIN(setMapMask) -{ - const char *const mapName = script_getstr(st, 2); - if (!mapName) - { - ShowWarning("invalid map name\n"); - script->reportsrc(st); - return false; - } - const int m = map->mapname2mapid(mapName); - if (m < 0) - { - ShowWarning("map not found\n"); - script->reportsrc(st); - return false; - } - getMapData(m); - - const int val = script_getnum(st, 3); - const unsigned int old = mapData->mask; - mapData->mask = val; - if (old != mapData->mask) - send_mapmask_brodcast(m, mapData->mask); - return true; -} - -BUILDIN(getMapMask) -{ - const char *const mapName = script_getstr(st, 2); - if (!mapName) - { - script_pushint(st, 0); - ShowWarning("invalid map name\n"); - script->reportsrc(st); - return false; - } - const int m = map->mapname2mapid(mapName); - if (m < 0) - { - script_pushint(st, 0); - ShowWarning("map not found\n"); - script->reportsrc(st); - return false; - } - getMapDataReturn(m, 0); - script_pushint(st, mapData->mask); - return true; -} - -BUILDIN(addMapMask) -{ - const char *const mapName = script_getstr(st, 2); - if (!mapName) - { - ShowWarning("invalid map name\n"); - script->reportsrc(st); - return false; - } - const int m = map->mapname2mapid(mapName); - if (m < 0) - { - ShowWarning("map not found\n"); - script->reportsrc(st); - return false; - } - getMapData(m); - const int val = script_getnum(st, 3); - const unsigned int old = mapData->mask; - mapData->mask |= val; - if (old != mapData->mask) - send_mapmask_brodcast(m, mapData->mask); - - return true; -} - -BUILDIN(removeMapMask) -{ - const char *const mapName = script_getstr(st, 2); - if (!mapName) - { - ShowWarning("invalid map name\n"); - script->reportsrc(st); - return true; - } - const int m = map->mapname2mapid(mapName); - if (m < 0) - { - ShowWarning("map not found\n"); - script->reportsrc(st); - return false; - } - getMapData(m); - const int val = script_getnum(st, 3); - const unsigned int old = mapData->mask; - mapData->mask |= val; - mapData->mask ^= val; - if (old != mapData->mask) - send_mapmask_brodcast(m, mapData->mask); - return true; -} - -BUILDIN(setNpcSex) -{ - TBL_NPC *nd = NULL; - int sex = 0; - if (script_hasdata(st, 3)) - { - nd = npc->name2id (script_getstr(st, 2)); - sex = script_getnum(st, 3); - } - else if (script_hasdata(st, 2)) - { - sex = script_getnum(st, 2); - } - else - { - ShowWarning("no parameters provided\n"); - script->reportsrc(st); - return false; - } - - if (!nd && !st->oid) - { - ShowWarning("npc not found\n"); - script->reportsrc(st); - return false; - } - - if (!nd) - nd = (TBL_NPC *) map->id2bl(st->oid); - - if (!nd || !nd->vd) - { - ShowWarning("npc not found\n"); - script->reportsrc(st); - return false; - } - - clif->clearunit_area(&nd->bl, CLR_OUTSIGHT); - nd->vd->sex = sex; - clif->spawn(&nd->bl); - return true; -} - -BUILDIN(showAvatar) -{ - int id = 0; - if (script_hasdata(st, 2)) - id = script_getnum(st, 2); - - send_npccommand2(script->rid2sd (st), st->oid, 6, id, 0, 0); - return true; -} - -BUILDIN(setAvatarDir) -{ - int newdir = script_getnum(st, 2); - - if (newdir < 0) - newdir = 0; - else if (newdir > 7) - newdir = 7; - - send_npccommand2(script->rid2sd (st), st->oid, 7, newdir, 0, 0); - return true; -} - -BUILDIN(setAvatarAction) -{ - send_npccommand2(script->rid2sd (st), st->oid, 8, script_getnum(st, 2), 0, 0); - return true; -} - -BUILDIN(clear) -{ - send_npccommand(script->rid2sd (st), st->oid, 9); - return true; -} - -BUILDIN(changeMusic) -{ - const char *const mapName = script_getstr(st, 2); - const char *const music = script_getstr(st, 3); - if (!music) - { - ShowWarning("invalid music file\n"); - script->reportsrc(st); - return false; - } - if (!mapName) - { - ShowWarning("invalid map file\n"); - script->reportsrc(st); - return false; - } - const int m = map->mapname2mapid(mapName); - if (m < 0) - { - ShowWarning("map not found\n"); - script->reportsrc(st); - return false; - } - - send_changemusic_brodcast(m, music); - return true; -} - -BUILDIN(setNpcDialogTitle) -{ - const char *const name = script_getstr(st, 2); - if (!name) - { - ShowWarning("invalid window title\n"); - script->reportsrc(st); - return false; - } - TBL_PC *sd = script->rid2sd (st); - if (!sd) - { - ShowWarning("player not attached\n"); - script->reportsrc(st); - return false; - } - - send_changenpc_title(sd, st->oid, name); - return true; -} - -BUILDIN(getMapName) -{ - TBL_PC *sd = script->rid2sd(st); - if (!sd) - { - script_pushstr(st, aStrdup("")); - ShowWarning("player not attached\n"); - script->reportsrc(st); - return false; - } - if (sd->bl.m == -1) - { - script_pushstr(st, aStrdup("")); - ShowWarning("invalid map\n"); - script->reportsrc(st); - return false; - } - script_pushstr(st, aStrdup(map->list[sd->bl.m].name)); - return true; -} - -BUILDIN(unequipById) -{ - int nameid = 0; - int i; - struct item_data *item_data; - TBL_PC *sd = script->rid2sd(st); - - if (sd == NULL) - { - ShowWarning("player not attached\n"); - script->reportsrc(st); - return false; - } - - nameid = script_getnum(st, 2); - if((item_data = itemdb->exists(nameid)) == NULL) - { - ShowWarning("item %d not found\n", nameid); - script->reportsrc(st); - return false; - } - for (i = 0; i < EQI_MAX; i++) - { - const int idx = sd->equip_index[i]; - if (idx >= 0) - { - if (sd->status.inventory[idx].nameid == nameid) - pc->unequipitem(sd, idx, 1 | 2); - } - } - return true; -} - -BUILDIN(isPcDead) -{ - TBL_PC *sd = script->rid2sd(st); - - if (sd == NULL) - { - ShowWarning("player not attached\n"); - script->reportsrc(st); - return false; - } - - script_pushint(st, pc_isdead(sd) ? 1 : 0); - return true; -} - -static int areatimer_sub(struct block_list *bl, va_list ap) -{ - int tick; - char *event; - TBL_PC *sd; - - tick = va_arg(ap, int); - event = va_arg(ap, char*); - - sd = (TBL_PC *)bl; - if (!pc->addeventtimer(sd, tick, event)) - { - if (sd) - ShowWarning("buildin_addtimer: Event timer is full, can't add new event timer. (cid:%d timer:%s)\n", sd->status.char_id, event); - } - return 0; -} - -BUILDIN(areaTimer) -{ - const char *const mapname = script_getstr(st, 2); - const int x1 = script_getnum(st, 3); - const int y1 = script_getnum(st, 4); - const int x2 = script_getnum(st, 5); - const int y2 = script_getnum(st, 6); - const int time = script_getnum(st, 7); - const char *const eventName = script_getstr(st, 8); - int m; - - if ((m = map->mapname2mapid(mapname)) < 0) - { - ShowWarning("map not found\n"); - script->reportsrc(st); - return false; - } - - map->foreachinarea(areatimer_sub, m, x1, y1, x2, y2, BL_PC, time, eventName); - - return true; -} - -static int buildin_getareadropitem_sub_del(struct block_list *bl, va_list ap) -{ - if (!bl) - return 0; - - const int item = va_arg(ap, int); - int *const amount = va_arg(ap, int *); - TBL_ITEM *drop = (TBL_ITEM *)bl; - - if (drop->item_data.nameid == item) - { - (*amount) += drop->item_data.amount; - map->clearflooritem(&drop->bl); - } - - return 0; -} - -BUILDIN(getAreaDropItem) -{ - const char *const str = script_getstr(st, 2); - int16 m; - int x0 = script_getnum(st, 3); - int y0 = script_getnum(st, 4); - int x1 = script_getnum(st, 5); - int y1 = script_getnum(st, 6); - int item; - int amount = 0; - - if (script_isstringtype(st, 7)) - { - const char *name = script_getstr(st, 7); - struct item_data *item_data = itemdb->search_name(name); - item = UNKNOWN_ITEM_ID; - if (item_data) - item = item_data->nameid; - } - else - { - item = script_getnum(st, 7); - } - - if ((m = map->mapname2mapid(str)) < 0) - { - script_pushint(st, -1); - ShowWarning("map not found\n"); - script->reportsrc(st); - return false; - } - - if (script_hasdata(st, 8) && script_getnum(st, 8)) - { - map->foreachinarea(buildin_getareadropitem_sub_del, - m, x0, y0, x1, y1, BL_ITEM, item, &amount); - } - else - { - map->foreachinarea(script->buildin_getareadropitem_sub, - m, x0, y0, x1, y1, BL_ITEM, item, &amount); - } - script_pushint(st, amount); - return true; -} - -enum setmount_type -{ - SETMOUNT_TYPE_NONE = 0, - SETMOUNT_TYPE_PECO = 1, - SETMOUNT_TYPE_WUG = 2, - SETMOUNT_TYPE_MADO = 3, - SETMOUNT_TYPE_DRAGON_GREEN = 4, - SETMOUNT_TYPE_DRAGON_BROWN = 5, - SETMOUNT_TYPE_DRAGON_GRAY = 6, - SETMOUNT_TYPE_DRAGON_BLUE = 7, - SETMOUNT_TYPE_DRAGON_RED = 8, - SETMOUNT_TYPE_MAX, - SETMOUNT_TYPE_DRAGON = SETMOUNT_TYPE_DRAGON_GREEN, -}; - -BUILDIN(setMount) -{ - int flag = SETMOUNT_TYPE_NONE; - TBL_PC* sd = script->rid2sd(st); - - if (sd == NULL) - return true; // no player attached, report source - - if (script_hasdata(st, 2)) - flag = script_getnum(st, 2); - - // Sanity checks and auto-detection - if (flag >= SETMOUNT_TYPE_DRAGON_GREEN && flag <= SETMOUNT_TYPE_DRAGON_RED) - { - if (pc->checkskill(sd, RK_DRAGONTRAINING)) - { - // Rune Knight (Dragon) - unsigned int option; - option = ( flag == SETMOUNT_TYPE_DRAGON_GREEN ? OPTION_DRAGON1 : - flag == SETMOUNT_TYPE_DRAGON_BROWN ? OPTION_DRAGON2 : - flag == SETMOUNT_TYPE_DRAGON_GRAY ? OPTION_DRAGON3 : - flag == SETMOUNT_TYPE_DRAGON_BLUE ? OPTION_DRAGON4 : - flag == SETMOUNT_TYPE_DRAGON_RED ? OPTION_DRAGON5 : - OPTION_DRAGON1); // default value - pc->setridingdragon(sd, option); - } - } - else if (flag == SETMOUNT_TYPE_WUG) - { - // Ranger (Warg) - if (pc->checkskill(sd, RA_WUGRIDER)) - pc->setridingwug(sd, true); - } - else if (flag == SETMOUNT_TYPE_MADO) - { - // Mechanic (Mado Gear) - if (pc->checkskill(sd, NC_MADOLICENCE)) - pc->setmadogear(sd, true); - } - else if (flag == SETMOUNT_TYPE_PECO) - { - // Knight / Crusader (Peco Peco) - if (pc->checkskill(sd, KN_RIDING)) - pc->setridingpeco(sd, true); - } - else if (flag == SETMOUNT_TYPE_NONE && pc_hasmount(sd)) - { - if (pc_isridingdragon(sd)) - { - pc->setridingdragon(sd, 0); - } - if (pc_isridingwug(sd)) - { - pc->setridingwug(sd, false); - } - if (pc_ismadogear(sd)) - { - pc->setmadogear(sd, false); - } - if (pc_isridingpeco(sd)) - { - pc->setridingpeco(sd, false); - } - } - - return true; -} - -BUILDIN(clientCommand) -{ - TBL_PC* sd = script->rid2sd(st); - - if (sd == NULL) - { - ShowWarning("player not attached\n"); - script->reportsrc(st); - return false; - } - const char *const command = script_getstr(st, 2); - if (!command) - { - ShowWarning("invalid client command\n"); - script->reportsrc(st); - return false; - } - send_client_command(sd, command); - return true; -} - -BUILDIN(isUnitWalking) -{ - int id = 0; - if (script_hasdata(st, 2)) - id = script_getnum(st, 2); - else - id = st->oid; - struct block_list *bl = map->id2bl(id); - if (!bl) - { - ShowWarning("invalid unit id\n"); - script->reportsrc(st); - script_pushint(st, 0); - return false; - } - struct unit_data *ud = unit->bl2ud(bl); - if (!ud) - { - ShowWarning("invalid unit data\n"); - script->reportsrc(st); - script_pushint(st, 0); - return false; - } - script_pushint(st, ud->walktimer != INVALID_TIMER); - return true; -} diff --git a/src/map/script.h b/src/map/script.h deleted file mode 100644 index 41c96ee..0000000 --- a/src/map/script.h +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. -// Copyright (c) 2014 Evol developers - -#ifndef EVOL_MAP_SCRIPT -#define EVOL_MAP_SCRIPT - -BUILDIN(l); -BUILDIN(lg); -BUILDIN(setCamNpc); -BUILDIN(setCam); -BUILDIN(moveCam); -BUILDIN(restoreCam); -BUILDIN(npcTalk3); -BUILDIN(closeDialog); -BUILDIN(shop); -BUILDIN(getItemLink); -BUILDIN(requestLang); -BUILDIN(requestItem); -BUILDIN(requestItems); -BUILDIN(getq); -BUILDIN(setq); -BUILDIN(setNpcDir); -BUILDIN(rif); -BUILDIN(countItemColor); -BUILDIN(miscEffect); -BUILDIN(setMapMask); -BUILDIN(getMapMask); -BUILDIN(addMapMask); -BUILDIN(removeMapMask); -BUILDIN(setNpcSex); -BUILDIN(showAvatar); -BUILDIN(setAvatarDir); -BUILDIN(setAvatarAction); -BUILDIN(clear); -BUILDIN(changeMusic); -BUILDIN(setNpcDialogTitle); -BUILDIN(getMapName); -BUILDIN(unequipById); -BUILDIN(isPcDead); -BUILDIN(areaTimer); -BUILDIN(getAreaDropItem); -BUILDIN(setMount); -BUILDIN(clientCommand); -BUILDIN(isUnitWalking); - -#endif // EVOL_MAP_SCRIPT diff --git a/src/map/scriptdefines.h b/src/map/scriptdefines.h deleted file mode 100644 index 1a6cf14..0000000 --- a/src/map/scriptdefines.h +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. -// Copyright (c) 2014 Evol developers - -#ifndef EVOL_MAP_SCRIPTDEFINES -#define EVOL_MAP_SCRIPTDEFINES - -#define getSessionDataReturn(def) \ - if (!st->rid) \ - { \ - script_pushint(st, def); \ - return true; \ - } \ - TBL_PC *sd = script->rid2sd(st); \ - if (!sd) \ - { \ - script_pushint(st, def); \ - return true; \ - } \ - struct SessionExt *data = session_get(sd->fd) - -#define getSessionData() \ - if (!st->rid) \ - return true; \ - TBL_PC *sd = script->rid2sd(st); \ - if (!sd) \ - return true; \ - struct SessionExt *data = session_get(sd->fd) - -#define getMapData(m) \ - struct MapdExt *mapData = mapd_get(m); \ - if (!mapData) \ - return true; - -#define getMapDataReturn(m, def) \ - struct MapdExt *mapData = mapd_get(m); \ - if (!mapData) \ - { \ - script_pushint(st, def); \ - return true; \ - } - -#define getSD() \ - TBL_PC *sd = script->rid2sd(st); \ - if (!sd) \ - return true - -#define getSDReturn(def) \ - TBL_PC *sd = script->rid2sd(st); \ - if (!sd) \ - { \ - script_pushint(st, def); \ - return true; \ - } - -#endif // EVOL_MAP_SCRIPTDEFINES diff --git a/src/map/send.c b/src/map/send.c deleted file mode 100644 index b9d826e..0000000 --- a/src/map/send.c +++ /dev/null @@ -1,305 +0,0 @@ -// 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 "../../../map/clif.h" -#include "../../../map/mob.h" -#include "../../../map/npc.h" -#include "../../../map/pc.h" -#include "../../../map/pet.h" -#include "../../../map/unit.h" - -#include "map/send.h" -#include "map/permission.h" -#include "map/data/session.h" -#include "map/struct/sessionext.h" - -void send_npccommand (TBL_PC *sd, int npcId, int cmd) -{ - if (!sd) - return; - - int fd = sd->fd; - WFIFOHEAD (fd, 16); - WFIFOW (fd, 0) = 0xB00; - WFIFOL (fd, 2) = npcId; - WFIFOW (fd, 6) = cmd; - WFIFOL (fd, 8) = 0; - WFIFOW (fd, 12) = 0; - WFIFOW (fd, 14) = 0; - WFIFOSET (fd, 16); -} - -// 0 - get client lang -void send_npccommand2 (TBL_PC *sd, int npcId, int cmd, int id, int x, int y) -{ - if (!sd) - return; - - int fd = sd->fd; - WFIFOHEAD (fd, 16); - WFIFOW (fd, 0) = 0xB00; - WFIFOL (fd, 2) = npcId; - WFIFOW (fd, 6) = cmd; - WFIFOL (fd, 8) = id; - WFIFOW (fd, 12) = x; - WFIFOW (fd, 14) = y; - WFIFOSET (fd, 16); -} - -void send_local_message(int fd, struct block_list* bl, const char* msg) -{ - if (!msg || !bl) - return; - unsigned short msg_len = strlen(msg) + 1; - uint8 buf[256]; - - int len = sizeof(buf) - 8; - if (msg_len > len) - { - ShowWarning("clif_message: Truncating too long message '%s' (len=%u).\n", msg, msg_len); - msg_len = len; - } - - WFIFOHEAD (fd, msg_len + 8); - WFIFOW (fd, 0) = 0x8d; - WFIFOW (fd, 2) = msg_len + 8; - WFIFOL (fd, 4) = bl->id; - safestrncpy((char*)WFIFOP(fd, 8), msg, msg_len); - WFIFOSET (fd, msg_len + 8); -} - -void send_changelook(int fd, int id, int type, int val) -{ - WFIFOHEAD (fd, 11); - WFIFOW (fd, 0) = 0x1d7; - WFIFOL (fd, 2) = id; - WFIFOB (fd, 6) = type; - WFIFOW (fd, 7) = val; - WFIFOW (fd, 9) = 0; - WFIFOSET (fd, 11); -} - -void send_mapmask(int fd, int mask) -{ - WFIFOHEAD (fd, 10); - WFIFOW (fd, 0) = 0xb02; - WFIFOL (fd, 2) = mask; - WFIFOL (fd, 6) = 0; - WFIFOSET (fd, 10); -} - -void send_mapmask_brodcast(const int map, const int mask) -{ - struct block_list bl; - char buf[10]; - - bl.m = map; - WBUFW (buf, 0) = 0xb02; - WBUFL (buf, 2) = mask; - WBUFL (buf, 6) = 0; - clif->send(buf, 10, &bl, ALL_SAMEMAP); -} - -void send_mob_info(struct block_list* bl1, struct block_list* bl2, - enum send_target target) -{ - if (!bl1 || bl1->type != BL_MOB) - return; - - char buf[12]; - TBL_MOB *md = (TBL_MOB *)bl1; - - WBUFW (buf, 0) = 0xb03; - WBUFW (buf, 2) = 12; // len - WBUFL (buf, 4) = md->bl.id; - WBUFL (buf, 8) = md->status.rhw.range; - - clif->send(&buf, sizeof(buf), bl2, target); -} - -void send_pc_info(struct block_list* bl1, - struct block_list* bl2, - enum send_target target) -{ - if (!bl1 || bl1->type != BL_PC) - return; - - char buf[12]; - TBL_PC *sd = (TBL_PC *)bl1; - struct SessionExt *data = session_get_bysd(sd); - if (!data) - return; - - TBL_PC *tsd = (TBL_PC *)bl2; - if (tsd) - { - struct SessionExt *tdata = session_get_bysd(tsd); - if (!tdata || tdata->clientVersion < 4) - return; - } - - WBUFW (buf, 0) = 0xb0a; - WBUFW (buf, 2) = 12; // len - WBUFL (buf, 4) = sd->bl.id; - if (pc_has_permission(sd, permission_send_gm_flag)) - WBUFL (buf, 8) = sd->group_id; - else - WBUFL (buf, 8) = 0; - - clif->send(&buf, sizeof(buf), bl2, target); -} - -void send_npc_info(struct block_list* bl1, - struct block_list* bl2, - enum send_target target) -{ - if (!bl1 || bl1->type != BL_NPC) - return; - - TBL_PC *tsd = (TBL_PC *)bl2; - if (tsd) - { - struct SessionExt *tdata = session_get_bysd(tsd); - if (!tdata || tdata->clientVersion < 5) - return; - } - - TBL_NPC *const nd = (TBL_NPC*)bl1; - - char buf[12]; - WBUFW (buf, 0) = 0xb0b; - WBUFW (buf, 2) = 12; // len - WBUFL (buf, 4) = nd->bl.id; - WBUFL (buf, 8) = nd->area_size; - - clif->send(&buf, sizeof(buf), bl2, target); -} - -void send_advmoving(struct unit_data* ud, struct block_list *tbl, enum send_target target) -{ - if (!ud) - return; - - struct block_list *bl = ud->bl; - - if (ud->walkpath.path_len <= ud->walkpath.path_pos) - return; - const bool haveMoves = (ud->walkpath.path_len > ud->walkpath.path_pos); - - int i = 14; - const int len = ud->walkpath.path_len - ud->walkpath.path_pos; - if (haveMoves) - i += len; - - char *buf; - CREATE(buf, char, i); - WBUFW (buf, 0) = 0xb04; - WBUFW (buf, 2) = i; - WBUFL (buf, 4) = bl->id; - WBUFW (buf, 8) = status->get_speed(bl); - WBUFW (buf, 10) = bl->x; - WBUFW (buf, 12) = bl->y; - if (haveMoves) - memcpy(buf + 14, ud->walkpath.path + ud->walkpath.path_pos, len); - clif->send(buf, i, tbl, target); - aFree(buf); -} - -void send_changemusic_brodcast(const int map, const char *music) -{ - if (!music) - return; - - struct block_list bl; - const int sz = strlen (music) + 5; - char *buf; - - CREATE(buf, char, sz); - bl.m = map; - WBUFW (buf, 0) = 0xb05; - WBUFW (buf, 2) = sz; - strcpy ((char *)WBUFP (buf, 4), music); - clif->send (buf, sz, &bl, ALL_SAMEMAP); - aFree(buf); -} - -void send_changenpc_title (TBL_PC *sd, const int npcId, const char *name) -{ - if (!sd || !name) - return; - - const int fd = sd->fd; - const int len = strlen (name); - const int sz = len + 5 + 4 + 2; - WFIFOHEAD (fd, sz); - WFIFOW (fd, 0) = 0xb06; - WFIFOW (fd, 2) = sz; - WFIFOL (fd, 4) = npcId; - WFIFOW (fd, 8) = len; - strcpy ((char*)WFIFOP (fd, 10), name); - WFIFOSET (fd, sz); -} - -void send_join_ack(int fd, const char *const name, int flag) -{ - if (!name) - return; - - WFIFOHEAD (fd, 27); - WFIFOW (fd, 0) = 0xb08; - safestrncpy ((char*)WFIFOP (fd, 2), name, 24); - WFIFOB (fd, 26) = flag; - WFIFOSET (fd, 27); -} - -void send_slave_say(TBL_PC *sd, - struct block_list *bl, - const char *const name, - const char *const message) -{ - const int len = 24 + 7 + strlen(message); - char *buf = NULL; - CREATE(buf, char, len); - - snprintf(buf, len, "%s's %s : %s", sd->status.name, name, message); - buf[len - 1] = 0; - clif->GlobalMessage(bl, buf); - aFree(buf); -} - -void send_online_list(int fd, const char *buf, unsigned size) -{ - if (!buf) - return; - const unsigned int len = size + 4 + 1; - WFIFOHEAD (fd, len); - WFIFOW (fd, 0) = 0xb10; - WFIFOW (fd, 2) = len; - memcpy (WFIFOP (fd, 4), buf, size); - WFIFOB (fd, size + 4) = 0; - WFIFOSET (fd, len); -} - -void send_client_command(TBL_PC *sd, const char *const command) -{ - struct SessionExt *data = session_get_bysd(sd); - if (!data || data->clientVersion < 8) - return; - - const unsigned int len = strlen(command); - const int fd = sd->fd; - WFIFOHEAD (fd, len); - WFIFOW (fd, 0) = 0xb16; - WFIFOW (fd, 2) = len + 4; - memcpy (WFIFOP (fd, 4), command, len); - WFIFOSET (fd, len + 4); -} diff --git a/src/map/send.h b/src/map/send.h deleted file mode 100644 index efa89ad..0000000 --- a/src/map/send.h +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. -// Copyright (c) 2014 Evol developers - -#ifndef EVOL_MAP_PC -#define EVOL_MAP_PC - -void send_npccommand (TBL_PC *sd, int npcId, int cmd); -void send_npccommand2 (TBL_PC *sd, int npcId, int cmd, int id, int x, int y); -void send_local_message(int fd, struct block_list* bl, const char* msg); -void send_changelook(int fd, int id, int type, int val); -void send_mapmask(int fd, int mask); -void send_mapmask_brodcast(const int map, const int mask); -void send_mob_info(struct block_list* bl1, struct block_list* bl2, enum send_target target); -void send_advmoving(struct unit_data* ud, struct block_list *tbl, enum send_target target); -void send_changemusic_brodcast(const int map, const char *music); -void send_changenpc_title (TBL_PC *sd, const int npcId, const char *name); -void send_join_ack(int fd, const char *const name, int flag); -void send_pc_info(struct block_list* bl1, - struct block_list* bl2, - enum send_target target); -void send_npc_info(struct block_list* bl1, - struct block_list* bl2, - enum send_target target); -void send_slave_say(TBL_PC *sd, - struct block_list *bl, - const char *const name, - const char *const message); -void send_online_list(int fd, const char *buf, unsigned size); -void send_client_command(TBL_PC *sd, const char *const command); - -#endif // EVOL_MAP_PC diff --git a/src/map/skill.c b/src/map/skill.c deleted file mode 100644 index 37ada8d..0000000 --- a/src/map/skill.c +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. -// Copyright (c) 2014 Evol developers - -#include -#include -#include - -#include "../../../common/db.h" -#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 "../../../map/pc.h" -#include "../../../map/npc.h" -#include "../../../map/script.h" - -int eskill_check_condition_castend_post(int retVal, - TBL_PC* sd, - uint16 *skill_id, - uint16 *skill_lv) -{ - if (retVal && sd) - { - struct linkdb_node **label_linkdb = strdb_get(npc->ev_label_db, "OnSkillInvoke"); - if (label_linkdb == NULL) - return retVal; - - struct linkdb_node *node = *label_linkdb; - while (node) - { - struct event_data* ev = node->data; - if (ev) - { - pc->setreg(sd, script->add_str("@skillId"), *skill_id); - pc->setreg(sd, script->add_str("@skillLv"), *skill_lv); - script->run(ev->nd->u.scr.script, ev->pos, sd->bl.id, ev->nd->bl.id); - } - node = node->next; - } - } - return retVal; -} diff --git a/src/map/skill.h b/src/map/skill.h deleted file mode 100644 index 132e909..0000000 --- a/src/map/skill.h +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. -// Copyright (c) 2014 Evol developers - -#ifndef EVOL_MAP_SKILL -#define EVOL_MAP_SKILL - -int eskill_check_condition_castend_post(int retVal, - TBL_PC* sd, - uint16 *skill_id, - uint16 *skill_lv); - -#endif // EVOL_MAP_SKILL diff --git a/src/map/status.c b/src/map/status.c deleted file mode 100644 index 916ee78..0000000 --- a/src/map/status.c +++ /dev/null @@ -1,70 +0,0 @@ -// 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 "../../../map/itemdb.h" -#include "../../../map/map.h" -#include "../../../map/npc.h" -#include "../../../map/pc.h" -#include "../../../map/status.h" - -#include "map/data/npcd.h" -#include "map/struct/npcdext.h" - -int class_move_speed[CLASS_COUNT]; - -void status_init(void) -{ - int f; - for (f = 0; f < CLASS_COUNT; f ++) - class_move_speed[f] = 150; -} - -void estatus_set_viewdata_post(struct block_list *bl, - int *class_ __attribute__ ((unused))) -{ - if (!bl) - return; - if (bl->type != BL_NPC) - return; - TBL_NPC *const npc = (TBL_NPC*)bl; - struct NpcdExt *data = npcd_get(npc); - if (data && data->init == false && npc->vd) - { - data->init = true; - npc->vd->sex = 3; - } -} - -void estatus_read_job_db_sub(int *idxPtr, - const char *name __attribute__ ((unused)), - config_setting_t *jdb) -{ - int i32 = 0; - const int idx = *idxPtr; - if (itemdb->lookup_const(jdb, "MoveSpeed", &i32)) - class_move_speed[idx] = i32; -} - -int estatus_calc_pc_(int retVal, - struct map_session_data *sd, - enum e_status_calc_opt *opt __attribute__ ((unused))) -{ - if (!sd) - return retVal; - - if (!sd->state.permanent_speed) - { - const int idx = pc->class2idx(sd->status.class_); - sd->base_status.speed = class_move_speed[idx]; - } - return retVal; -} diff --git a/src/map/status.h b/src/map/status.h deleted file mode 100644 index fb0198b..0000000 --- a/src/map/status.h +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. -// Copyright (c) 2014 Evol developers - -#ifndef EVOL_MAP_STATUS -#define EVOL_MAP_STATUS - -void status_init(void); -void estatus_set_viewdata_post(struct block_list *bl, int *class_); -void estatus_read_job_db_sub(int *idxPtr, const char *name, config_setting_t *jdb); -int estatus_calc_pc_(int retVal, struct map_session_data* sd, enum e_status_calc_opt *opt); - -#endif // EVOL_MAP_STATUS diff --git a/src/map/struct/itemdext.h b/src/map/struct/itemdext.h deleted file mode 100644 index 8d4a555..0000000 --- a/src/map/struct/itemdext.h +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. -// Copyright (c) 2014 Evol developers - -#ifndef EVOL_MAP_ITEMDEXT -#define EVOL_MAP_ITEMDEXT - -struct ItemdExt -{ - int floorLifeTime; - - int requiredStr; - int requiredAgi; - int requiredVit; - int requiredInt; - int requiredDex; - int requiredLuk; - int requiredMaxHp; - int requiredMaxSp; - int requiredAtk; - int requiredMAtkMin; - int requiredMAtkMax; - int requiredDef; - int requiredMDef; - - int useEffect; - int useFailEffect; - int unequipEffect; - int unequipFailEffect; - - bool allowPickup; -}; - -#endif // EVOL_MAP_ITEMDEXT diff --git a/src/map/struct/mapdext.h b/src/map/struct/mapdext.h deleted file mode 100644 index 15fee7f..0000000 --- a/src/map/struct/mapdext.h +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. -// Copyright (c) 2014 Evol developers - -#ifndef EVOL_MAP_MAPDEXT -#define EVOL_MAP_MAPDEXT - -struct MapdExt -{ - unsigned int mask; - bool invisible; - struct MapdExtFlag - { - unsigned nopve : 1; - } flag; -}; - -#endif // EVOL_MAP_MAPDEXT diff --git a/src/map/struct/npcdext.h b/src/map/struct/npcdext.h deleted file mode 100644 index 2158f2c..0000000 --- a/src/map/struct/npcdext.h +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. -// Copyright (c) 2014 Evol developers - -#ifndef EVOL_MAP_NPCDEXT -#define EVOL_MAP_NPCDEXT - -struct NpcdExt -{ - bool init; -}; - -#endif // EVOL_MAP_NPCDEXT diff --git a/src/map/struct/sessionext.h b/src/map/struct/sessionext.h deleted file mode 100644 index a592e50..0000000 --- a/src/map/struct/sessionext.h +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. -// Copyright (c) 2014 Evol developers - -#ifndef EVOL_MAP_SESSIONEXT -#define EVOL_MAP_SESSIONEXT - -struct SessionExt -{ - time_t onlinelistlasttime; - int clientVersion; - int language; - uint8 state; -}; - -#endif // EVOL_MAP_SESSIONEXT diff --git a/src/map/unit.c b/src/map/unit.c deleted file mode 100644 index 97860e1..0000000 --- a/src/map/unit.c +++ /dev/null @@ -1,163 +0,0 @@ -// 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 "../../../map/unit.h" -#include "../../../map/map.h" -#include "../../../map/mob.h" -#include "../../../map/pc.h" -#include "../../../map/skill.h" -#include "../../../map/status.h" - -#include "map/unit.h" - -int eunit_can_move(struct block_list *bl) -{ - TBL_PC *sd; - struct unit_data *ud; - struct status_change *sc; - - if (!bl) - { - hookStop(); - return 0; - } - ud = unit->bl2ud(bl); - sc = status->get_sc(bl); - sd = BL_CAST(BL_PC, bl); - - if (!ud) - { - hookStop(); - return 0; - } - - if (ud->skilltimer != INVALID_TIMER - && ud->skill_id != LG_EXEEDBREAK - && (!sd - || !pc->checkskill(sd, SA_FREECAST) - || skill->get_inf2(ud->skill_id)&INF2_GUILD_SKILL)) - { - hookStop(); - return 0; // prevent moving while casting - } - - if (DIFF_TICK(ud->canmove_tick, timer->gettick()) > 0) - { - hookStop(); - return 0; - } - - if (sd && ( - sd->state.vending || - sd->state.buyingstore || - sd->state.blockedmove)) - { - hookStop(); - return 0; //Can't move - } - - // Status changes that block movement - if (sc) - { - if (sc->count && ( - sc->data[SC_ANKLESNARE] - || sc->data[SC_AUTOCOUNTER] - || sc->data[SC_TRICKDEAD] - || sc->data[SC_BLADESTOP] - || sc->data[SC_BLADESTOP_WAIT] - || (sc->data[SC_GOSPEL] && sc->data[SC_GOSPEL]->val4 == BCT_SELF) // cannot move while gospel is in effect - || (sc->data[SC_BASILICA] && sc->data[SC_BASILICA]->val4 == bl->id) // Basilica caster cannot move - || sc->data[SC_STOP] - || sc->data[SC_FALLENEMPIRE] - || sc->data[SC_RG_CCONFINE_M] - || sc->data[SC_RG_CCONFINE_S] - || sc->data[SC_GS_MADNESSCANCEL] - || (sc->data[SC_GRAVITATION] && sc->data[SC_GRAVITATION]->val3 == BCT_SELF) - || sc->data[SC_WHITEIMPRISON] - || sc->data[SC_ELECTRICSHOCKER] - || sc->data[SC_WUGBITE] - || sc->data[SC_THORNS_TRAP] - || ( sc->data[SC_MAGNETICFIELD] && !sc->data[SC_HOVERING] ) - || sc->data[SC__MANHOLE] - || sc->data[SC_CURSEDCIRCLE_ATKER] - || sc->data[SC_CURSEDCIRCLE_TARGET] - || (sc->data[SC_COLD] && bl->type != BL_MOB) - || sc->data[SC_DEEP_SLEEP] - || (sc->data[SC_CAMOUFLAGE] && sc->data[SC_CAMOUFLAGE]->val1 < 3 && !(sc->data[SC_CAMOUFLAGE]->val3&1)) - || sc->data[SC_MEIKYOUSISUI] - || sc->data[SC_KG_KAGEHUMI] - || sc->data[SC_NEEDLE_OF_PARALYZE] - || sc->data[SC_VACUUM_EXTREME] - || (sc->data[SC_FEAR] && sc->data[SC_FEAR]->val2 > 0) - || (sc->data[SC_SPIDERWEB] && sc->data[SC_SPIDERWEB]->val1) - || (sc->data[SC_CLOAKING] && sc->data[SC_CLOAKING]->val1 < 3 && !(sc->data[SC_CLOAKING]->val4&1)) //Need wall at level 1-2 - || ( - sc->data[SC_DANCING] && sc->data[SC_DANCING]->val4 - && ( - !sc->data[SC_LONGING] - || (sc->data[SC_DANCING]->val1&0xFFFF) == CG_MOONLIT - || (sc->data[SC_DANCING]->val1&0xFFFF) == CG_HERMODE)))) - { - hookStop(); - return 0; - } - if (sc->opt1 > 0 - && sc->opt1 != OPT1_STONEWAIT - && sc->opt1 != OPT1_BURNING - && !(sc->opt1 == OPT1_CRYSTALIZE - && bl->type == BL_MOB)) - { - hookStop(); - return 0; - } - - if ((sc->option & OPTION_HIDE) && (!sd || pc->checkskill(sd, RG_TUNNELDRIVE) <= 0)) - { - hookStop(); - return 0; - } - } - - // Icewall walk block special trapped monster mode - if(bl->type == BL_MOB) - { - TBL_MOB *md = BL_CAST(BL_MOB, bl); - if(md && ((md->status.mode&MD_BOSS && battle->bc->boss_icewall_walk_block == 1 && map->getcell(bl->m,bl->x,bl->y,CELL_CHKICEWALL)) - || (!(md->status.mode&MD_BOSS) && battle->bc->mob_icewall_walk_block == 1 && map->getcell(bl->m,bl->x,bl->y,CELL_CHKICEWALL)))) - { - md->walktoxy_fail_count = 1; //Make sure rudeattacked skills are invoked - hookStop(); - return 0; - } - } - - hookStop(); - return 1; -} - -int eunit_walktoxy(struct block_list *bl __attribute__ ((unused)), - short *x __attribute__ ((unused)), - short *y __attribute__ ((unused)), - int *flagPtr) -{ - // reset flag "Search for an unoccupied cell and cancel if none available" - // this reduce CPU usage and allow mobs to walk on each other. - if ((*flagPtr)&8) - *flagPtr = ((*flagPtr) | 8) ^ 8; - - TBL_PC *sd = BL_CAST(BL_PC, bl); - if (sd && pc_issit(sd)) - pc->setstand(sd); - - return 1; -} diff --git a/src/map/unit.h b/src/map/unit.h deleted file mode 100644 index 675bf0e..0000000 --- a/src/map/unit.h +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. -// Copyright (c) 2014 Evol developers - -#ifndef EVOL_MAP_UNIT -#define EVOL_MAP_UNIT - -int eunit_can_move(struct block_list *bl); -int eunit_walktoxy(struct block_list *bl, short *x, short *y, int *flagPtr); - -#endif // EVOL_MAP_UNIT diff --git a/src/map/utils/formatutils.c b/src/map/utils/formatutils.c deleted file mode 100644 index 6777423..0000000 --- a/src/map/utils/formatutils.c +++ /dev/null @@ -1,116 +0,0 @@ -// 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 "../../../../map/script.h" - -#include "../../../../map/chrif.h" -#include "../../../../map/clif.h" -#include "../../../../map/npc.h" -#include "../../../../map/pc.h" -#include "../../../../map/script.h" -#include "../../../../map/quest.h" - -#include "map/utils/formatutils.h" -#include "map/lang.h" - -int format_sub(struct script_state* st, int translate) -{ - TBL_PC *sd = NULL; - if (translate) - sd = script->rid2sd(st); - - if (!script_hasdata(st, 3)) - { - if (sd) - { - if (translate == 2) - { - char *buf = aCalloc (strlen(script_getstr(st, 2)) + 3, sizeof(char)); - strcpy (buf, script_getstr(st, 2)); - if (sd->status.sex) - strcat (buf, "#1"); - else - strcat (buf, "#0"); - script_pushstr(st, aStrdup(lang_pctrans(buf, sd))); - aFree (buf); - } - else - { - script_pushstr(st, aStrdup(lang_pctrans(script_getstr(st, 2), sd))); - } - } - else - { - script_pushstr(st, aStrdup(script_getstr(st, 2))); - } - return 1; - } - - char *line = (char *) aCalloc (550, sizeof (char)); - int idx = 3; - if (sd) - { - if (translate == 2) - { - const char *str = NULL; - char *buf = NULL; - if (sd->status.sex) - { - str = script_getstr(st, 3); - buf = aCalloc (strlen(str) + 3, sizeof(char)); - strcpy (buf, str); - strcat (buf, "#1"); - } - else - { - str = script_getstr(st, 2); - buf = aCalloc (strlen(str) + 3, sizeof(char)); - strcpy (buf, str); - strcat (buf, "#0"); - } - strcpy(line, lang_pctrans(buf, sd)); - aFree (buf); - idx = 4; - } - else - { - strcpy(line, lang_pctrans(script_getstr(st, 2), sd)); - } - } - else - { - strcpy(line, script_getstr(st, 2)); - } - - char *ptr = line; - int sz = strlen(line); - while (script_hasdata(st, idx)) - { - char *tmp = strstr(ptr, "@@"); - if (!tmp) - break; - const char *item = script_getstr(st, idx); - int len = strlen(item); - if (len > 50) - break; - sz += len - 2; - if (sz > 490) - break; - memmove(tmp + len, tmp + 2, strlen(tmp + 2)); - memcpy(tmp, item, len); - ptr = tmp + len; - idx ++; - } - - script_pushstr(st, line); - return 0; -} diff --git a/src/map/utils/formatutils.h b/src/map/utils/formatutils.h deleted file mode 100644 index 361ad84..0000000 --- a/src/map/utils/formatutils.h +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. -// Copyright (c) 2014 Evol developers - -#ifndef EVOL_MAP_UTILS_FORMATUTILS -#define EVOL_MAP_UTILS_FORMATUTILS - -int format_sub(struct script_state* st, int translate); - -#endif // EVOL_MAP_UTILS_FORMATUTILS -- cgit v1.2.3-70-g09d2