From 8b5370313dcc00a45ea5c3e8b4c497bc00fd8e13 Mon Sep 17 00:00:00 2001 From: Ben Longbons Date: Tue, 11 Jun 2013 21:55:13 -0700 Subject: Allegedly remove all manual memory management --- Makefile | 1 + src/char/char.cpp | 74 +- src/char/int_party.cpp | 54 +- src/char/inter.cpp | 2 +- src/common/const_array.hpp | 38 +- src/common/core.cpp | 12 + src/common/db.hpp | 69 +- src/common/dumb_ptr.hpp | 199 +++ src/common/intern-pool.hpp | 35 + src/common/matrix.hpp | 50 + src/common/md5calc.cpp | 4 +- src/common/mmo.hpp | 2 +- src/common/socket.cpp | 51 +- src/common/utils.cpp | 2 +- src/common/utils.hpp | 34 - src/common/utils2.hpp | 12 +- src/ladmin/ladmin.cpp | 71 +- src/login/login.cpp | 145 +- src/map/atcommand.cpp | 447 ++---- src/map/atcommand.hpp | 2 +- src/map/battle.cpp | 19 +- src/map/battle.hpp | 1 - src/map/battle.t.hpp | 6 + src/map/chrif.cpp | 33 +- src/map/clif.cpp | 296 ++-- src/map/intif.cpp | 56 +- src/map/itemdb.cpp | 6 +- src/map/itemdb.hpp | 8 +- src/map/magic-expr-eval.hpp | 6 +- src/map/magic-expr.cpp | 327 ++-- src/map/magic-expr.hpp | 22 +- src/map/magic-interpreter-aux.hpp | 6 - src/map/magic-interpreter-base.cpp | 217 +-- src/map/magic-interpreter-lexer.lpp | 23 +- src/map/magic-interpreter-parser.ypp | 506 +++---- src/map/magic-interpreter.hpp | 321 ++-- src/map/magic-stmt.cpp | 341 ++--- src/map/magic.cpp | 79 +- src/map/magic.hpp | 10 +- src/map/map.cpp | 435 +++--- src/map/map.hpp | 137 +- src/map/mob.cpp | 342 ++--- src/map/mob.hpp | 2 +- src/map/npc.cpp | 611 +++----- src/map/npc.hpp | 11 +- src/map/party.cpp | 2 +- src/map/party.hpp | 2 +- src/map/path.cpp | 17 +- src/map/path.hpp | 8 + src/map/pc.cpp | 282 ++-- src/map/pc.hpp | 10 +- src/map/script.cpp | 2736 +++++++++++++++------------------- src/map/script.hpp | 90 +- src/map/skill.cpp | 34 +- src/map/skill.hpp | 6 +- src/map/storage.cpp | 36 +- src/map/tmw.cpp | 2 +- src/map/trade.cpp | 12 +- src/poison.hpp | 57 +- src/tool/eathena-monitor.cpp | 14 +- src/warnings.hpp | 11 +- 61 files changed, 3927 insertions(+), 4517 deletions(-) create mode 100644 src/common/intern-pool.hpp create mode 100644 src/common/matrix.hpp create mode 100644 src/map/path.hpp diff --git a/Makefile b/Makefile index c071f82..1e78b51 100644 --- a/Makefile +++ b/Makefile @@ -45,6 +45,7 @@ most: ${MOSTPROGS} clean: rm -rf ${PROGS} ${BUILD_DIR}/ common: ${BUILD_DIR}/common/core.o ${BUILD_DIR}/common/db.o ${BUILD_DIR}/common/lock.o ${BUILD_DIR}/common/md5calc.o ${BUILD_DIR}/common/random.o ${BUILD_DIR}/common/nullpo.o ${BUILD_DIR}/common/socket.o ${BUILD_DIR}/common/timer.o ${BUILD_DIR}/common/utils.o ${BUILD_DIR}/common/cxxstdio.o ${BUILD_DIR}/common/extract.o +magic: ${BUILD_DIR}/map/magic-interpreter-lexer.o ${BUILD_DIR}/map/magic-interpreter-parser.o ${BUILD_DIR}/map/magic-expr.o ${BUILD_DIR}/map/magic-interpreter-base.o ${BUILD_DIR}/map/magic-stmt.o ${BUILD_DIR}/map/magic.o # Top level programs login-server: ${BUILD_DIR}/login/login diff --git a/src/char/char.cpp b/src/char/char.cpp index cb2fae2..496f5fd 100644 --- a/src/char/char.cpp +++ b/src/char/char.cpp @@ -81,9 +81,9 @@ char char_log_filename[1024] = "log/char.log"; static char lan_map_ip[128]; static -int subneti[4]; +uint8_t subneti[4]; static -int subnetmaski[4]; +uint8_t subnetmaski[4]; static int name_ignoring_case = 0; // Allow or not identical name for characters but with a different case by [Yor] static @@ -101,7 +101,7 @@ struct char_session_data : SessionData void SessionDeleter::operator()(SessionData *sd) { - delete static_cast(sd); + really_delete1 static_cast(sd); } struct AuthFifoEntry @@ -710,8 +710,7 @@ mmo_charstatus *make_new_char(int fd, const uint8_t *dat) } char ip[16]; - unsigned char *sin_addr = - (unsigned char *) &session[fd]->client_addr.sin_addr; + uint8_t *sin_addr = reinterpret_cast(&session[fd]->client_addr.sin_addr); sprintf(ip, "%d.%d.%d.%d", sin_addr[0], sin_addr[1], sin_addr[2], sin_addr[3]); @@ -1502,7 +1501,7 @@ void parse_tologin(int fd) gm_accounts.resize((RFIFOW(fd, 2) - 4) / 5); for (int i = 4; i < RFIFOW(fd, 2); i = i + 5) { - gm_accounts.push_back({(int) RFIFOL(fd, i), (int) RFIFOB(fd, i + 4)}); + gm_accounts.push_back({static_cast(RFIFOL(fd, i)), RFIFOB(fd, i + 4)}); } PRINTF("From login-server: receiving of %zu GM accounts information.\n", gm_accounts.size()); @@ -1633,7 +1632,7 @@ void parse_frommap(int fd) j++; } { - unsigned char *p = (unsigned char *) &server[id].ip; + uint8_t *p = reinterpret_cast(&server[id].ip); PRINTF("Map-Server %d connected: %d maps, from IP %d.%d.%d.%d port %d.\n", id, j, p[0], p[1], p[2], p[3], server[id].port); PRINTF("Map-server %d loading complete.\n", id); @@ -2239,7 +2238,7 @@ static void parse_char(int fd) { char email[40]; - unsigned char *p = (unsigned char *) &session[fd]->client_addr.sin_addr; + uint8_t *p = reinterpret_cast(&session[fd]->client_addr.sin_addr); if (login_fd < 0 || session[fd]->eof) { // disconnect any player (already connected to char-server or coming back from map-server) if login-server is diconnected. @@ -2290,8 +2289,8 @@ void parse_char(int fd) RFIFOL(fd, 2)); if (sd == NULL) { - sd = new char_session_data(); - session[fd]->session_data.reset(sd); + session[fd]->session_data = make_unique(); + sd = static_cast(session[fd]->session_data.get()); memcpy(sd->email, "no mail", 40); // put here a mail without '@' to refuse deletion if we don't receive the e-mail sd->connect_until_time = TimeT(); // unknow or illimited (not displaying on map-server) } @@ -2487,8 +2486,8 @@ void parse_char(int fd) if (server_fd[i] < 0) break; } - if (i == MAX_MAP_SERVERS || strcmp((const char *)RFIFOP(fd, 2), userid) - || strcmp((const char *)RFIFOP(fd, 26), passwd)) + if (i == MAX_MAP_SERVERS || strcmp(static_cast(RFIFOP(fd, 2)), userid) + || strcmp(static_cast(RFIFOP(fd, 26)), passwd)) { WFIFOB(fd, 2) = 3; WFIFOSET(fd, 3); @@ -2516,7 +2515,7 @@ void parse_char(int fd) for (const GM_Account& gma : gm_accounts) { WFIFOL(fd, len) = gma.account_id; - WFIFOB(fd, len + 4) = (unsigned char) gma.level; + WFIFOB(fd, len + 4) = gma.level; len += 5; } WFIFOW(fd, 2) = len; @@ -2704,10 +2703,10 @@ int lan_config_read(const char *lancfgName) if (h != NULL) { sprintf(lan_map_ip, "%d.%d.%d.%d", - (unsigned char) h->h_addr[0], - (unsigned char) h->h_addr[1], - (unsigned char) h->h_addr[2], - (unsigned char) h->h_addr[3]); + static_cast(h->h_addr[0]), + static_cast(h->h_addr[1]), + static_cast(h->h_addr[2]), + static_cast(h->h_addr[3])); } else { @@ -2724,11 +2723,11 @@ int lan_config_read(const char *lancfgName) if (h != NULL) { for (int j = 0; j < 4; j++) - subneti[j] = (unsigned char) h->h_addr[j]; + subneti[j] = h->h_addr[j]; } else { - SSCANF(w2, "%d.%d.%d.%d", &subneti[0], &subneti[1], + SSCANF(w2, "%hhu.%hhu.%hhu.%hhu", &subneti[0], &subneti[1], &subneti[2], &subneti[3]); } PRINTF("Sub-network of the map-server: %d.%d.%d.%d.\n", @@ -2743,11 +2742,11 @@ int lan_config_read(const char *lancfgName) if (h != NULL) { for (int j = 0; j < 4; j++) - subnetmaski[j] = (unsigned char) h->h_addr[j]; + subnetmaski[j] = h->h_addr[j]; } else { - SSCANF(w2, "%d.%d.%d.%d", &subnetmaski[0], &subnetmaski[1], + SSCANF(w2, "%hhu.%hhu.%hhu.%hhu", &subnetmaski[0], &subnetmaski[1], &subnetmaski[2], &subnetmaski[3]); } PRINTF("Sub-network mask of the map-server: %d.%d.%d.%d.\n", @@ -2816,15 +2815,15 @@ int char_config_read(const char *cfgName) if (h != NULL) { PRINTF("Login server IP address : %s -> %d.%d.%d.%d\n", w2, - (unsigned char) h->h_addr[0], - (unsigned char) h->h_addr[1], - (unsigned char) h->h_addr[2], - (unsigned char) h->h_addr[3]); + static_cast(h->h_addr[0]), + static_cast(h->h_addr[1]), + static_cast(h->h_addr[2]), + static_cast(h->h_addr[3])); sprintf(login_ip_str, "%d.%d.%d.%d", - (unsigned char) h->h_addr[0], - (unsigned char) h->h_addr[1], - (unsigned char) h->h_addr[2], - (unsigned char) h->h_addr[3]); + static_cast(h->h_addr[0]), + static_cast(h->h_addr[1]), + static_cast(h->h_addr[2]), + static_cast(h->h_addr[3])); } else strzcpy(login_ip_str, w2.c_str(), 16); @@ -2839,15 +2838,16 @@ int char_config_read(const char *cfgName) if (h != NULL) { PRINTF("Character server IP address : %s -> %d.%d.%d.%d\n", - w2, (unsigned char) h->h_addr[0], - (unsigned char) h->h_addr[1], - (unsigned char) h->h_addr[2], - (unsigned char) h->h_addr[3]); + w2, + static_cast(h->h_addr[0]), + static_cast(h->h_addr[1]), + static_cast(h->h_addr[2]), + static_cast(h->h_addr[3])); sprintf(char_ip_str, "%d.%d.%d.%d", - (unsigned char) h->h_addr[0], - (unsigned char) h->h_addr[1], - (unsigned char) h->h_addr[2], - (unsigned char) h->h_addr[3]); + static_cast(h->h_addr[0]), + static_cast(h->h_addr[1]), + static_cast(h->h_addr[2]), + static_cast(h->h_addr[3])); } else strzcpy(char_ip_str, w2.c_str(), 16); diff --git a/src/char/int_party.cpp b/src/char/int_party.cpp index 8566f3c..7e6f8b6 100644 --- a/src/char/int_party.cpp +++ b/src/char/int_party.cpp @@ -625,40 +625,60 @@ int inter_party_parse_frommap(int fd) switch (RFIFOW(fd, 0)) { case 0x3020: - mapif_parse_CreateParty(fd, RFIFOL(fd, 2), (const char *)RFIFOP(fd, 6), - (const char *)RFIFOP(fd, 30), (const char *)RFIFOP(fd, 54), - RFIFOW(fd, 70)); + mapif_parse_CreateParty(fd, + RFIFOL(fd, 2), + static_cast(RFIFOP(fd, 6)), + static_cast(RFIFOP(fd, 30)), + static_cast(RFIFOP(fd, 54)), + RFIFOW(fd, 70)); break; case 0x3021: mapif_parse_PartyInfo(fd, RFIFOL(fd, 2)); break; case 0x3022: - mapif_parse_PartyAddMember(fd, RFIFOL(fd, 2), RFIFOL(fd, 6), - (const char *)RFIFOP(fd, 10), (const char *)RFIFOP(fd, 34), - RFIFOW(fd, 50)); + mapif_parse_PartyAddMember(fd, + RFIFOL(fd, 2), + RFIFOL(fd, 6), + static_cast(RFIFOP(fd, 10)), + static_cast(RFIFOP(fd, 34)), + RFIFOW(fd, 50)); break; case 0x3023: - mapif_parse_PartyChangeOption(fd, RFIFOL(fd, 2), RFIFOL(fd, 6), - RFIFOW(fd, 10), RFIFOW(fd, 12)); + mapif_parse_PartyChangeOption(fd, + RFIFOL(fd, 2), + RFIFOL(fd, 6), + RFIFOW(fd, 10), + RFIFOW(fd, 12)); break; case 0x3024: - mapif_parse_PartyLeave(fd, RFIFOL(fd, 2), RFIFOL(fd, 6)); + mapif_parse_PartyLeave(fd, + RFIFOL(fd, 2), + RFIFOL(fd, 6)); break; case 0x3025: - mapif_parse_PartyChangeMap(fd, RFIFOL(fd, 2), RFIFOL(fd, 6), - (const char *)RFIFOP(fd, 10), RFIFOB(fd, 26), - RFIFOW(fd, 27)); + mapif_parse_PartyChangeMap(fd, + RFIFOL(fd, 2), + RFIFOL(fd, 6), + static_cast(RFIFOP(fd, 10)), + RFIFOB(fd, 26), + RFIFOW(fd, 27)); break; case 0x3026: - mapif_parse_BreakParty(fd, RFIFOL(fd, 2)); + mapif_parse_BreakParty(fd, + RFIFOL(fd, 2)); break; case 0x3027: - mapif_parse_PartyMessage(fd, RFIFOL(fd, 4), RFIFOL(fd, 8), - (const char *)RFIFOP(fd, 12), RFIFOW(fd, 2) - 12); + mapif_parse_PartyMessage(fd, + RFIFOL(fd, 4), + RFIFOL(fd, 8), + static_cast(RFIFOP(fd, 12)), + RFIFOW(fd, 2) - 12); break; case 0x3028: - mapif_parse_PartyCheck(fd, RFIFOL(fd, 2), RFIFOL(fd, 6), - (const char *)RFIFOP(fd, 10)); + mapif_parse_PartyCheck(fd, + RFIFOL(fd, 2), + RFIFOL(fd, 6), + static_cast(RFIFOP(fd, 10))); break; default: return 0; diff --git a/src/char/inter.cpp b/src/char/inter.cpp index 59a2945..04523f7 100644 --- a/src/char/inter.cpp +++ b/src/char/inter.cpp @@ -404,7 +404,7 @@ int mapif_parse_WisRequest(int fd) // to be sure of the correct name, rewrite it strzcpy(static_cast(const_cast(RFIFOP(fd, 28))), mcs->name, 24); // if source is destination, don't ask other servers. - if (strcmp((const char *)RFIFOP(fd, 4), (const char *)RFIFOP(fd, 28)) == 0) + if (strcmp(static_cast(RFIFOP(fd, 4)), static_cast(RFIFOP(fd, 28))) == 0) { unsigned char buf[27]; WBUFW(buf, 0) = 0x3802; diff --git a/src/common/const_array.hpp b/src/common/const_array.hpp index 93ae337..06045dc 100644 --- a/src/common/const_array.hpp +++ b/src/common/const_array.hpp @@ -70,55 +70,59 @@ public: // but disallow conversion from a temporary const_array(std::vector&&) = delete; - // All methods are non-const to "encourage" you - // to always pass a const_array by value. - // After all, "const const_array" looks funny. + // Oops. see src/warnings.hpp constexpr - const T *data() { return d; } + const T *data() const { return d; } constexpr - size_t size() { return n; } + size_t size() const { return n; } constexpr - bool empty() { return not n; } + bool empty() const { return not n; } constexpr explicit - operator bool() { return n; } + operator bool() const { return n; } constexpr - std::pair cut(size_t o) + std::pair cut(size_t o) const { return {const_array(d, o), const_array(d + o, n - o)}; } constexpr - const_array first(size_t o) + const_array first(size_t o) const { return cut(o).first; } constexpr - const_array last(size_t l) + const_array last(size_t l) const { return cut(size() - l).second; } constexpr - const_array after(size_t o) + const_array after(size_t o) const { return cut(o).second; } constexpr - iterator begin() { return d; } + iterator begin() const { return d; } constexpr - iterator end() { return d + n; } + iterator end() const { return d + n; } constexpr - reverse_iterator rbegin() { return reverse_iterator(end()); } + reverse_iterator rbegin() const { return reverse_iterator(end()); } constexpr - reverse_iterator rend() { return reverse_iterator(begin()); } + reverse_iterator rend() const { return reverse_iterator(begin()); } constexpr - const T& front() { return *begin(); } + const T& front() const { return *begin(); } constexpr - const T& back() { return *rbegin(); } + const T& back() const { return *rbegin(); } + + // This probably shouldn't be used, but I'm adding it for porting. + T& operator[](size_t i) + { + return const_cast(d[i]); + } }; // subclass just provides a simpler name and some conversions diff --git a/src/common/core.cpp b/src/common/core.cpp index 994de93..153414d 100644 --- a/src/common/core.cpp +++ b/src/common/core.cpp @@ -36,7 +36,10 @@ sigfunc compat_signal(int signo, sigfunc func) sact.sa_flags = 0; if (sigaction(signo, &sact, &oact) < 0) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wold-style-cast" return SIG_ERR; +#pragma GCC diagnostic pop return oact.sa_handler; } @@ -50,7 +53,10 @@ static __attribute__((noreturn)) void sig_proc(int) { for (int i = 1; i < 31; ++i) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wold-style-cast" compat_signal(i, SIG_IGN); +#pragma GCC diagnostic pop term_func(); _exit(0); } @@ -74,17 +80,23 @@ int main(int argc, char **argv) // set up exit handlers *after* the initialization has happened. // This is because term_func is likely to depend on successful init. +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wold-style-cast" compat_signal(SIGPIPE, SIG_IGN); +#pragma GCC diagnostic pop compat_signal(SIGTERM, sig_proc); compat_signal(SIGINT, sig_proc); compat_signal(SIGCHLD, chld_proc); // Signal to create coredumps by system when necessary (crash) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wold-style-cast" compat_signal(SIGSEGV, SIG_DFL); compat_signal(SIGBUS, SIG_DFL); compat_signal(SIGTRAP, SIG_DFL); compat_signal(SIGILL, SIG_DFL); compat_signal(SIGFPE, SIG_DFL); +#pragma GCC diagnostic pop atexit(term_func); diff --git a/src/common/db.hpp b/src/common/db.hpp index bd47928..927db22 100644 --- a/src/common/db.hpp +++ b/src/common/db.hpp @@ -22,6 +22,7 @@ # include "sanity.hpp" # include +# include template class Map @@ -56,7 +57,7 @@ public: return nullptr; return &it->second; } - void insert(K k, V v) + void insert(const K& k, V v) { // As far as I can tell, this is the simplest way to // implement move-only insert-with-replacement. @@ -69,7 +70,7 @@ public: return (void)&it->second; } - V *init(K k) + V *init(const K& k) { return &impl[k]; } @@ -81,10 +82,14 @@ public: { impl.clear(); } - bool empty() + bool empty() const { return impl.empty(); } + size_t size() const + { + return impl.size(); + } }; template @@ -102,22 +107,74 @@ public: const_iterator begin() const { return impl.begin(); } const_iterator end() const { return impl.end(); } - V get(K k) + // const V& ? with a static default V? + V get(const K& k) { V *vp = impl.search(k); return vp ? *vp : V(); } - void put(K k, V v) + void put(const K& k, V v) { if (v == V()) impl.erase(k); else - impl.insert(k, v); + impl.insert(k, std::move(v)); } void clear() { impl.clear(); } + bool empty() const + { + return impl.empty(); + } + size_t size() const + { + return impl.size(); + } +}; + +template +class UPMap +{ + typedef std::unique_ptr U; + typedef Map Impl; + + Impl impl; +public: + typedef typename Impl::iterator iterator; + typedef typename Impl::const_iterator const_iterator; + + iterator begin() { return impl.begin(); } + iterator end() { return impl.end(); } + const_iterator begin() const { return impl.begin(); } + const_iterator end() const { return impl.end(); } + + // const V& ? with a static default V? + V *get(const K& k) + { + U *up = impl.search(k); + return up ? up->get() : nullptr; + } + void put(const K& k, U v) + { + if (!v) + impl.erase(k); + else + impl.insert(k, std::move(v)); + } + void clear() + { + impl.clear(); + } + bool empty() const + { + return impl.empty(); + } + size_t size() const + { + return impl.size(); + } }; #endif // DB_HPP diff --git a/src/common/dumb_ptr.hpp b/src/common/dumb_ptr.hpp index 1a0b4a1..e10ca3a 100644 --- a/src/common/dumb_ptr.hpp +++ b/src/common/dumb_ptr.hpp @@ -21,8 +21,12 @@ #include "sanity.hpp" +#include + #include +#include "const_array.hpp" + // unmanaged new/delete-able pointer // should be replaced by std::unique_ptr template @@ -176,4 +180,199 @@ public: } }; +struct dumb_string +{ + dumb_ptr impl; + + dumb_string() + : impl() + {} + dumb_string(char *) = delete; + // copy ctor, copy assign, and dtor are all default + + static dumb_string copy(const char *b, const char *e) + { + dumb_string rv; + rv.impl.new_((e - b) + 1); + std::copy(b, e, &rv.impl[0]); + return rv; + } + static dumb_string copy(const char *sz) + { + return dumb_string::copy(sz, sz + strlen(sz)); + } + static dumb_string copys(const std::string& s) + { + return dumb_string::copy(&*s.begin(), &*s.end()); + } + static dumb_string copyn(const char *sn, size_t n) + { + return dumb_string::copy(sn, sn + strnlen(sn, n)); + } + static dumb_string copyc(const_string s) + { + return dumb_string::copy(s.begin(), s.end()); + } + + static + dumb_string fake(const char *p) + { + dumb_string rv; + rv.impl = dumb_ptr(const_cast(p), strlen(p)); + return rv; + } + + dumb_string dup() const + { + return dumb_string::copy(&impl[0]); + } + void delete_() + { + impl.delete_(); + } + + const char *c_str() const + { + return &impl[0]; + } + + std::string str() const + { + return c_str(); + } + + operator const_string() const + { + return const_string(c_str()); + } + + char& operator[](size_t i) const + { + return impl[i]; + } + + explicit + operator bool() const + { + return bool(impl); + } + bool operator !() const + { + return !impl; + } + +#if 0 + friend bool operator == (dumb_string l, dumb_string r) + { + return l.impl == r.impl; + } + friend bool operator != (dumb_string l, dumb_string r) + { + return !(l == r); + } +#endif +}; + +namespace operators +{ + inline + bool operator == (dumb_string l, dumb_string r) + { + return strcmp(l.c_str(), r.c_str()) == 0; + } + inline + bool operator != (dumb_string l, dumb_string r) + { + return strcmp(l.c_str(), r.c_str()) != 0; + } + inline + bool operator < (dumb_string l, dumb_string r) + { + return strcmp(l.c_str(), r.c_str()) < 0; + } + inline + bool operator <= (dumb_string l, dumb_string r) + { + return strcmp(l.c_str(), r.c_str()) <= 0; + } + inline + bool operator > (dumb_string l, dumb_string r) + { + return strcmp(l.c_str(), r.c_str()) > 0; + } + inline + bool operator >= (dumb_string l, dumb_string r) + { + return strcmp(l.c_str(), r.c_str()) >= 0; + } + + inline + bool operator == (const char *l, dumb_string r) + { + return strcmp(l, r.c_str()) == 0; + } + inline + bool operator != (const char *l, dumb_string r) + { + return strcmp(l, r.c_str()) != 0; + } + inline + bool operator < (const char *l, dumb_string r) + { + return strcmp(l, r.c_str()) < 0; + } + inline + bool operator <= (const char *l, dumb_string r) + { + return strcmp(l, r.c_str()) <= 0; + } + inline + bool operator > (const char *l, dumb_string r) + { + return strcmp(l, r.c_str()) > 0; + } + inline + bool operator >= (const char *l, dumb_string r) + { + return strcmp(l, r.c_str()) >= 0; + } + + inline + bool operator == (dumb_string l, const char *r) + { + return strcmp(l.c_str(), r) == 0; + } + inline + bool operator != (dumb_string l, const char *r) + { + return strcmp(l.c_str(), r) != 0; + } + inline + bool operator < (dumb_string l, const char *r) + { + return strcmp(l.c_str(), r) < 0; + } + inline + bool operator <= (dumb_string l, const char *r) + { + return strcmp(l.c_str(), r) <= 0; + } + inline + bool operator > (dumb_string l, const char *r) + { + return strcmp(l.c_str(), r) > 0; + } + inline + bool operator >= (dumb_string l, const char *r) + { + return strcmp(l.c_str(), r) >= 0; + } +} + +inline +const char *convert_for_printf(dumb_string ds) +{ + return ds.c_str(); +} + #endif // TMWA_COMMON_DUMB_PTR_HPP diff --git a/src/common/intern-pool.hpp b/src/common/intern-pool.hpp new file mode 100644 index 0000000..caa54e4 --- /dev/null +++ b/src/common/intern-pool.hpp @@ -0,0 +1,35 @@ +#ifndef INTERN_POOL_HPP +#define INTERN_POOL_HPP + +#include + +#include +#include +#include + +class InternPool +{ + std::map known; + std::vector names; +public: + size_t intern(const std::string& name) + { + auto pair = known.insert({name, known.size()}); + if (pair.second) + names.push_back(name); + assert (known.size() == names.size()); + return pair.first->second; + } + + const std::string& outtern(size_t sz) const + { + return names[sz]; + } + + size_t size() const + { + return known.size(); + } +}; + +#endif //INTERN_POOL_HPP diff --git a/src/common/matrix.hpp b/src/common/matrix.hpp new file mode 100644 index 0000000..8595191 --- /dev/null +++ b/src/common/matrix.hpp @@ -0,0 +1,50 @@ +#ifndef TMWA_COMMON_MATRIX_HPP +#define TMWA_COMMON_MATRIX_HPP + +template +class Matrix +{ + std::unique_ptr _data; + size_t _xs, _ys; +public: + Matrix() + : _data() + , _xs() + , _ys() + {} + Matrix(size_t x, size_t y) + : _data(new T[x * y]()) + , _xs(x) + , _ys(y) + {} + // no copy-ctor or copy-assign + + void reset(size_t x, size_t y) + { + *this = Matrix(x, y); + } + void clear() + { + *this = Matrix(); + } + + T& ref(size_t x, size_t y) + { + return _data[x + y * _xs]; + } + const T& ref(size_t x, size_t y) const + { + return _data[x + y * _xs]; + } + + size_t xs() const + { + return _xs; + } + size_t ys() const + { + return _ys; + } +}; + +#endif // TMWA_COMMON_MATRIX_HPP diff --git a/src/common/md5calc.cpp b/src/common/md5calc.cpp index 1625912..36f220d 100644 --- a/src/common/md5calc.cpp +++ b/src/common/md5calc.cpp @@ -210,7 +210,7 @@ MD5_state MD5_from_string(const char* msg, const size_t msglen) if (64 - rem > 8) { for (int i=0; i<8; i++) - buf[0x38+i] = ((uint64_t)msglen*8) >> (i*8); + buf[0x38+i] = (static_cast(msglen)*8) >> (i*8); } for (int i=0; i<0x10; i++) X[i] = buf[4*i+0] | buf[4*i+1]<<8 | buf[4*i+2]<<16 | buf[4*i+3]<<24; @@ -219,7 +219,7 @@ MD5_state MD5_from_string(const char* msg, const size_t msglen) { memset(buf,'\0', 0x38); for (int i=0; i<8; i++) - buf[0x38+i] = ((uint64_t)msglen*8) >> (i*8); + buf[0x38+i] = (static_cast(msglen)*8) >> (i*8); for (int i=0; i<0x10; i++) X[i] = buf[4*i+0] | buf[4*i+1]<<8 | buf[4*i+2]<<16 | buf[4*i+3]<<24; MD5_do_block(&state, block); diff --git a/src/common/mmo.hpp b/src/common/mmo.hpp index e72bf80..a04fd34 100644 --- a/src/common/mmo.hpp +++ b/src/common/mmo.hpp @@ -206,7 +206,7 @@ struct map_session_data; struct GM_Account { int account_id; - int level; + uint8_t level; }; struct party_member diff --git a/src/common/socket.cpp b/src/common/socket.cpp index db944cc..0ee8712 100644 --- a/src/common/socket.cpp +++ b/src/common/socket.cpp @@ -29,7 +29,10 @@ const uint32_t RFIFO_SIZE = 65536; static const uint32_t WFIFO_SIZE = 65536; +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wold-style-cast" std::array, FD_SETSIZE> session; +#pragma GCC diagnostic pop /// clean up by discarding handled bytes inline @@ -119,7 +122,7 @@ void connect_client(int listen_fd) struct sockaddr_in client_address; socklen_t len = sizeof(client_address); - int fd = accept(listen_fd, (struct sockaddr *) &client_address, &len); + int fd = accept(listen_fd, reinterpret_cast(&client_address), &len); if (fd == -1) { perror("accept"); @@ -156,11 +159,14 @@ void connect_client(int listen_fd) setsockopt(fd, IPPROTO_TCP, TCP_THIN_DUPACK, &yes, sizeof yes); #endif +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wold-style-cast" FD_SET(fd, &readfds); +#pragma GCC diagnostic pop fcntl(fd, F_SETFL, O_NONBLOCK); - session[fd].reset(new socket_data()); + session[fd] = make_unique(); session[fd]->rdata.new_(RFIFO_SIZE); session[fd]->wdata.new_(WFIFO_SIZE); @@ -202,10 +208,13 @@ int make_listen_port(uint16_t port) setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof yes); server_address.sin_family = AF_INET; +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wold-style-cast" server_address.sin_addr.s_addr = htonl(INADDR_ANY); server_address.sin_port = htons(port); +#pragma GCC diagnostic pop - if (bind(fd, (struct sockaddr *) &server_address, + if (bind(fd, reinterpret_cast(&server_address), sizeof(server_address)) == -1) { perror("bind"); @@ -217,9 +226,12 @@ int make_listen_port(uint16_t port) exit(1); } +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wold-style-cast" FD_SET(fd, &readfds); +#pragma GCC diagnostic pop - session[fd].reset(new socket_data()); + session[fd] = make_unique(); session[fd]->func_recv = connect_client; session[fd]->created = TimeT::now(); @@ -254,18 +266,24 @@ int make_connection(uint32_t ip, uint16_t port) server_address.sin_family = AF_INET; server_address.sin_addr.s_addr = ip; +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wold-style-cast" server_address.sin_port = htons(port); +#pragma GCC diagnostic pop fcntl(fd, F_SETFL, O_NONBLOCK); /// Errors not caught - we must not block /// Let the main select() loop detect when we know the state - connect(fd, (struct sockaddr *) &server_address, + connect(fd, reinterpret_cast(&server_address), sizeof(struct sockaddr_in)); +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wold-style-cast" FD_SET(fd, &readfds); +#pragma GCC diagnostic pop - session[fd].reset(new socket_data()); + session[fd] = make_unique(); session[fd]->rdata.new_(RFIFO_SIZE); session[fd]->wdata.new_(WFIFO_SIZE); @@ -283,14 +301,20 @@ int make_connection(uint32_t ip, uint16_t port) void delete_session(int fd) { +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wold-style-cast" if (fd < 0 || fd >= FD_SETSIZE) +#pragma GCC diagnostic pop return; // If this was the highest fd, decrease it // We could add a loop to decrement fd_max further for every null session, // but this is cheap and good enough for the typical case if (fd == fd_max - 1) fd_max--; +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wold-style-cast" FD_CLR(fd, &readfds); +#pragma GCC diagnostic pop if (session[fd]) { session[fd]->rdata.delete_(); @@ -343,11 +367,17 @@ void WFIFOSET(int fd, size_t len) void do_sendrecv(interval_t next_ms) { fd_set rfd = readfds, wfd; +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wold-style-cast" FD_ZERO(&wfd); +#pragma GCC diagnostic pop for (int i = 0; i < fd_max; i++) { if (session[i] && session[i]->wdata_size) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wold-style-cast" FD_SET(i, &wfd); +#pragma GCC diagnostic pop } struct timeval timeout; { @@ -362,13 +392,19 @@ void do_sendrecv(interval_t next_ms) { if (!session[i]) continue; +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wold-style-cast" if (FD_ISSET(i, &wfd)) +#pragma GCC diagnostic pop { if (session[i]->func_send) //send_from_fifo(i); session[i]->func_send(i); } +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wold-style-cast" if (FD_ISSET(i, &rfd)) +#pragma GCC diagnostic pop { if (session[i]->func_recv) //recv_to_fifo(i); @@ -406,7 +442,10 @@ void do_parsepacket(void) void do_socket(void) { +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wold-style-cast" FD_ZERO(&readfds); +#pragma GCC diagnostic pop currentuse = 3; } diff --git a/src/common/utils.cpp b/src/common/utils.cpp index e3867eb..4e00808 100644 --- a/src/common/utils.cpp +++ b/src/common/utils.cpp @@ -87,7 +87,7 @@ int config_switch (const char *str) const char *ip2str(struct in_addr ip, bool extra_dot) { - const uint8_t *p = (const uint8_t *)(&ip); + const uint8_t *p = reinterpret_cast(&ip); static char buf[17]; if (extra_dot) sprintf(buf, "%d.%d.%d.%d.", p[0], p[1], p[2], p[3]); diff --git a/src/common/utils.hpp b/src/common/utils.hpp index f2a2117..caa39ed 100644 --- a/src/common/utils.hpp +++ b/src/common/utils.hpp @@ -12,40 +12,6 @@ #include "operators.hpp" #include "utils2.hpp" -/* -Notes about memory allocation in tmwAthena: -There used to be 3 sources of allocation: these macros, -a{C,M,Re}alloc in common/malloc.{h,c}, and direct calls. -I deleted malloc.{h,c} because it was redundant; -future calls should either use this or depend on the coming segfault. -*/ -template -void create_impl(T *& result, size_t number) -{ - result = (T *)calloc(number, sizeof(T)); - if (!result && number) - { - perror("SYSERR: malloc failure"); - abort(); - } -} -template -void recreate_impl(T *& result, size_t number) -{ - result = (T *)realloc(result, sizeof(T) * number); - if (!result && number) - { - perror("SYSERR: realloc failure"); - abort(); - } -} - -# define CREATE(result, type, number) \ - create_impl(result, number) - -# define RECREATE(result, type, number) \ - recreate_impl(result, number) - int remove_control_chars(char *str); int e_mail_check(const char *email); int config_switch (const char *str); diff --git a/src/common/utils2.hpp b/src/common/utils2.hpp index 5f02beb..2218625 100644 --- a/src/common/utils2.hpp +++ b/src/common/utils2.hpp @@ -214,17 +214,17 @@ struct is_array_of_unknown_bound : std::is_same::type[]> {}; -template -typename std::enable_if::value, std::unique_ptr>::type make_unique(A&&... a) +template, class... A> +typename std::enable_if::value, std::unique_ptr>::type make_unique(A&&... a) { - return std::unique_ptr(new T(a...)); + return std::unique_ptr(new T(a...)); } -template -typename std::enable_if::value, std::unique_ptr>::type make_unique(size_t sz) +template> +typename std::enable_if::value, std::unique_ptr>::type make_unique(size_t sz) { typedef typename std::remove_extent::type E; - return std::unique_ptr(new E[sz]); + return std::unique_ptr(new E[sz]()); } #endif // UTILS2_HPP diff --git a/src/ladmin/ladmin.cpp b/src/ladmin/ladmin.cpp index 458df39..f5940dd 100644 --- a/src/ladmin/ladmin.cpp +++ b/src/ladmin/ladmin.cpp @@ -1115,12 +1115,12 @@ int banaddaccount(const char *param) WFIFOW(login_fd, 0) = 0x794c; memcpy(WFIFOP(login_fd, 2), name, 24); - WFIFOW(login_fd, 26) = (short) year; - WFIFOW(login_fd, 28) = (short) month; - WFIFOW(login_fd, 30) = (short) day; - WFIFOW(login_fd, 32) = (short) hour; - WFIFOW(login_fd, 34) = (short) minute; - WFIFOW(login_fd, 36) = (short) second; + WFIFOW(login_fd, 26) = year; + WFIFOW(login_fd, 28) = month; + WFIFOW(login_fd, 30) = day; + WFIFOW(login_fd, 32) = hour; + WFIFOW(login_fd, 34) = minute; + WFIFOW(login_fd, 36) = second; WFIFOSET(login_fd, 38); bytes_to_read = 1; @@ -2227,12 +2227,12 @@ int timeaddaccount(const char *param) WFIFOW(login_fd, 0) = 0x7950; memcpy(WFIFOP(login_fd, 2), name, 24); - WFIFOW(login_fd, 26) = (short) year; - WFIFOW(login_fd, 28) = (short) month; - WFIFOW(login_fd, 30) = (short) day; - WFIFOW(login_fd, 32) = (short) hour; - WFIFOW(login_fd, 34) = (short) minute; - WFIFOW(login_fd, 36) = (short) second; + WFIFOW(login_fd, 26) = year; + WFIFOW(login_fd, 28) = month; + WFIFOW(login_fd, 30) = day; + WFIFOW(login_fd, 32) = hour; + WFIFOW(login_fd, 34) = minute; + WFIFOW(login_fd, 36) = second; WFIFOSET(login_fd, 38); bytes_to_read = 1; @@ -2757,14 +2757,14 @@ void parse_fromlogin(int fd) md5key[sizeof(md5key) - 1] = '0'; if (passenc == 1) { - strncpy(md5str, (const char *)RFIFOP(fd, 4), RFIFOW(fd, 2) - 4); + strncpy(md5str, static_cast(RFIFOP(fd, 4)), RFIFOW(fd, 2) - 4); strcat(md5str, loginserveradminpassword); } else if (passenc == 2) { strncpy(md5str, loginserveradminpassword, sizeof(loginserveradminpassword)); - strcat(md5str, (const char *)RFIFOP(fd, 4)); + strcat(md5str, static_cast(RFIFOP(fd, 4))); } MD5_to_bin(MD5_from_cstring(md5str), md5bin); WFIFOW(login_fd, 0) = 0x7918; // Request for administation login (encrypted password) @@ -2785,21 +2785,21 @@ void parse_fromlogin(int fd) return; Iprintf(" Login-Server [%s:%d]\n", loginserverip, loginserverport); - if (((int) RFIFOB(login_fd, 5)) == 0) + if (RFIFOB(login_fd, 5) == 0) { Iprintf(" eAthena version stable-%d.%d", - (int) RFIFOB(login_fd, 2), - (int) RFIFOB(login_fd, 3)); + RFIFOB(login_fd, 2), + RFIFOB(login_fd, 3)); } else { Iprintf(" eAthena version dev-%d.%d", - (int) RFIFOB(login_fd, 2), - (int) RFIFOB(login_fd, 3)); + RFIFOB(login_fd, 2), + RFIFOB(login_fd, 3)); } - if (((int) RFIFOB(login_fd, 4)) == 0) - Iprintf(" revision %d", (int) RFIFOB(login_fd, 4)); - if (((int) RFIFOB(login_fd, 6)) == 0) + if (RFIFOB(login_fd, 4) == 0) + Iprintf(" revision %d", RFIFOB(login_fd, 4)); + if (RFIFOB(login_fd, 6) == 0) { Iprintf("%d.\n", RFIFOW(login_fd, 8)); } @@ -2859,7 +2859,7 @@ void parse_fromlogin(int fd) if (RFIFOB(fd, i + 4) == 0) PRINTF(" "); else - PRINTF("%2d ", (int) RFIFOB(fd, i + 4)); + PRINTF("%2d ", RFIFOB(fd, i + 4)); PRINTF("%-24s", userid); if (RFIFOB(fd, i + 29) == 0) PRINTF("%-5s ", "Femal"); @@ -3213,7 +3213,7 @@ void parse_fromlogin(int fd) case 0x7947: // answer of an account name search if (RFIFOREST(fd) < 30) return; - if (strcmp((const char *)RFIFOP(fd, 6), "") == 0) + if (strcmp(static_cast(RFIFOP(fd, 6)), "") == 0) { PRINTF("Unable to find the account [%d] name. Account doesn't exist.\n", RFIFOL(fd, 2)); @@ -3340,7 +3340,7 @@ void parse_fromlogin(int fd) case 0x794f: // answer of a broadcast if (RFIFOREST(fd) < 4) return; - if (RFIFOW(fd, 2) == (unsigned short) -1) + if (RFIFOW(fd, 2) == static_cast(-1)) { PRINTF("Message sending failed. No online char-server.\n"); LADMIN_LOG("Message sending failed. No online char-server.\n"); @@ -3415,7 +3415,7 @@ void parse_fromlogin(int fd) connect_until_time = static_cast(RFIFOL(fd, 140)); ban_until_time = static_cast(RFIFOL(fd, 144)); memset(memo, '\0', sizeof(memo)); - strncpy(memo, (const char *)RFIFOP(fd, 150), RFIFOW(fd, 148)); + strncpy(memo, static_cast(RFIFOP(fd, 150)), RFIFOW(fd, 148)); if (RFIFOL(fd, 2) == -1) { PRINTF("Unabled to find the account [%s]. Account doesn't exist.\n", @@ -3441,7 +3441,7 @@ void parse_fromlogin(int fd) else { PRINTF(" Id: %d (GM level %d)\n", - RFIFOL(fd, 2), (int) RFIFOB(fd, 6)); + RFIFOL(fd, 2), RFIFOB(fd, 6)); } PRINTF(" Name: '%s'\n", userid); if (RFIFOB(fd, 31) == 0) @@ -3600,15 +3600,16 @@ int ladmin_config_read(const char *cfgName) if (h != NULL) { Iprintf("Login server IP address: %s -> %d.%d.%d.%d\n", - w2, (unsigned char) h->h_addr[0], - (unsigned char) h->h_addr[1], - (unsigned char) h->h_addr[2], - (unsigned char) h->h_addr[3]); + w2, + static_cast(h->h_addr[0]), + static_cast(h->h_addr[1]), + static_cast(h->h_addr[2]), + static_cast(h->h_addr[3])); sprintf(loginserverip, "%d.%d.%d.%d", - (unsigned char) h->h_addr[0], - (unsigned char) h->h_addr[1], - (unsigned char) h->h_addr[2], - (unsigned char) h->h_addr[3]); + static_cast(h->h_addr[0]), + static_cast(h->h_addr[1]), + static_cast(h->h_addr[2]), + static_cast(h->h_addr[3])); } else strzcpy(loginserverip, w2.c_str(), 16); diff --git a/src/login/login.cpp b/src/login/login.cpp index 8d526f6..baa1097 100644 --- a/src/login/login.cpp +++ b/src/login/login.cpp @@ -72,9 +72,9 @@ int login_port = 6900; static char lan_char_ip[16]; static -int subneti[4]; +uint8_t subneti[4]; static -int subnetmaski[4]; +uint8_t subnetmaski[4]; static char update_host[128] = ""; static @@ -87,8 +87,7 @@ char GM_account_filename[1024] = "conf/GM_account.txt"; static char login_log_filename[1024] = "log/login.log"; static -char login_log_unknown_packets_filename[1024] = - "log/login_unknown_packets.log"; +char login_log_unknown_packets_filename[1024] = "log/login_unknown_packets.log"; static int save_unknown_packets = 0; static @@ -151,7 +150,7 @@ struct login_session_data : SessionData void SessionDeleter::operator()(SessionData *sd) { - delete static_cast(sd); + really_delete1 static_cast(sd); } constexpr int AUTH_FIFO_SIZE = 256; @@ -230,7 +229,7 @@ void login_log(const_string line) // and returns its level (or 0 if it isn't a GM account or if not found) //---------------------------------------------------------------------- static -int isGM(int account_id) +uint8_t isGM(int account_id) { GM_Account *p = gm_account_db.search(account_id); if (p == NULL) @@ -271,8 +270,8 @@ int read_gm_account(void) || line[0] == '\n' || line[0] == '\r') continue; GM_Account p {}; - if (sscanf(line, "%d %d", &p.account_id, &p.level) != 2 - && sscanf(line, "%d: %d", &p.account_id, &p.level) != 2) + if (sscanf(line, "%d %hhu", &p.account_id, &p.level) != 2 + && sscanf(line, "%d: %hhu", &p.account_id, &p.level) != 2) PRINTF("read_gm_account: file [%s], invalid 'id_acount level' format.\n", GM_account_filename); else if (p.level <= 0) @@ -329,8 +328,8 @@ static int check_ipmask(struct in_addr ip, const char *str) { unsigned int mask = 0, ip2; - unsigned char *p = (unsigned char *) &ip2, - *p2 = (unsigned char *) &mask; + uint8_t *p = reinterpret_cast(&ip2), + *p2 = reinterpret_cast(&mask); int i = 0; unsigned int m; @@ -1216,7 +1215,7 @@ void parse_fromchar(int fd) WBUFW(buf, 0) = 0x2721; WBUFL(buf, 2) = acc; WBUFL(buf, 6) = 0; - if (strcmp((const char *)RFIFOP(fd, 8), gm_pass) == 0) + if (strcmp(static_cast(RFIFOP(fd, 8)), gm_pass) == 0) { // only non-GM can become GM if (isGM(acc) == 0) @@ -1396,12 +1395,12 @@ void parse_fromchar(int fd) else timestamp = ad.ban_until_time; struct tm tmtime = timestamp; - tmtime.tm_year += (short) RFIFOW(fd, 6); - tmtime.tm_mon += (short) RFIFOW(fd, 8); - tmtime.tm_mday += (short) RFIFOW(fd, 10); - tmtime.tm_hour += (short) RFIFOW(fd, 12); - tmtime.tm_min += (short) RFIFOW(fd, 14); - tmtime.tm_sec += (short) RFIFOW(fd, 16); + tmtime.tm_year += static_cast(RFIFOW(fd, 6)); + tmtime.tm_mon += static_cast(RFIFOW(fd, 8)); + tmtime.tm_mday += static_cast(RFIFOW(fd, 10)); + tmtime.tm_hour += static_cast(RFIFOW(fd, 12)); + tmtime.tm_min += static_cast(RFIFOW(fd, 14)); + tmtime.tm_sec += static_cast(RFIFOW(fd, 16)); timestamp = tmtime; if (timestamp.okay()) { @@ -1762,7 +1761,7 @@ void parse_admin(int fd) if (account_id >= st && account_id <= ed) { WFIFOL(fd, len) = account_id; - WFIFOB(fd, len + 4) = (unsigned char) isGM(account_id); + WFIFOB(fd, len + 4) = isGM(account_id); memcpy(WFIFOP(fd, len + 5), ad.userid, 24); WFIFOB(fd, len + 29) = ad.sex; WFIFOL(fd, len + 30) = ad.logincount; @@ -2128,7 +2127,7 @@ void parse_admin(int fd) if (new_gm_level < 0 || new_gm_level > 99) { LOGIN_LOG("'ladmin': Attempt to give an invalid GM level (account: %s, received GM level: %d, ip: %s)\n", - account_name, (int) new_gm_level, ip); + account_name, new_gm_level, ip); } else { @@ -2223,13 +2222,13 @@ void parse_admin(int fd) { LOGIN_LOG("'ladmin': Attempt to modify of a GM level - impossible to read GM accounts file (account: %s (%d), received GM level: %d, ip: %s)\n", ad->userid, acc, - (int) new_gm_level, ip); + new_gm_level, ip); } lock_fclose(fp2, GM_account_filename, &lock); WFIFOL(fd, 2) = acc; LOGIN_LOG("'ladmin': Modification of a GM level (account: %s (%d), new GM level: %d, ip: %s)\n", ad->userid, acc, - (int) new_gm_level, ip); + new_gm_level, ip); // read and send new GM informations read_gm_account(); send_GM_accounts(); @@ -2238,20 +2237,20 @@ void parse_admin(int fd) { LOGIN_LOG("'ladmin': Attempt to modify of a GM level - impossible to write GM accounts file (account: %s (%d), received GM level: %d, ip: %s)\n", ad->userid, acc, - (int) new_gm_level, ip); + new_gm_level, ip); } } else { LOGIN_LOG("'ladmin': Attempt to modify of a GM level, but the GM level is already the good GM level (account: %s (%d), GM level: %d, ip: %s)\n", ad->userid, acc, - (int) new_gm_level, ip); + new_gm_level, ip); } } else { LOGIN_LOG("'ladmin': Attempt to modify the GM level of an unknown account (account: %s, received GM level: %d, ip: %s)\n", - account_name, (int) new_gm_level, + account_name, new_gm_level, ip); } } @@ -2383,7 +2382,7 @@ void parse_admin(int fd) { if (ad.account_id == RFIFOL(fd, 2)) { - strncpy((char *)WFIFOP(fd, 6), ad.userid, 24); + strncpy(static_cast(WFIFOP(fd, 6)), ad.userid, 24); LOGIN_LOG("'ladmin': Request (by id) of an account name (account: %s, id: %d, ip: %s)\n", ad.userid, RFIFOL(fd, 2), ip); goto x7946_out; @@ -2391,7 +2390,7 @@ void parse_admin(int fd) } LOGIN_LOG("'ladmin': Name request (by id) of an unknown account (id: %d, ip: %s)\n", RFIFOL(fd, 2), ip); - strncpy((char *)WFIFOP(fd, 6), "", 24); + strncpy(static_cast(WFIFOP(fd, 6)), "", 24); x7946_out: WFIFOSET(fd, 30); RFIFOSKIP(fd, 6); @@ -2512,12 +2511,12 @@ void parse_admin(int fd) else timestamp = ad->ban_until_time; struct tm tmtime = timestamp; - tmtime.tm_year += (short) RFIFOW(fd, 26); - tmtime.tm_mon += (short) RFIFOW(fd, 28); - tmtime.tm_mday += (short) RFIFOW(fd, 30); - tmtime.tm_hour += (short) RFIFOW(fd, 32); - tmtime.tm_min += (short) RFIFOW(fd, 34); - tmtime.tm_sec += (short) RFIFOW(fd, 36); + tmtime.tm_year += static_cast(RFIFOW(fd, 26)); + tmtime.tm_mon += static_cast(RFIFOW(fd, 28)); + tmtime.tm_mday += static_cast(RFIFOW(fd, 30)); + tmtime.tm_hour += static_cast(RFIFOW(fd, 32)); + tmtime.tm_min += static_cast(RFIFOW(fd, 34)); + tmtime.tm_sec += static_cast(RFIFOW(fd, 36)); timestamp = tmtime; if (timestamp.okay()) { @@ -2528,9 +2527,9 @@ void parse_admin(int fd) stamp_time(tmpstr, ×tamp); LOGIN_LOG("'ladmin': Adjustment of a final date of a banishment (account: %s, (%+d y %+d m %+d d %+d h %+d mn %+d s) -> new validity: %lld (%s), ip: %s)\n", ad->userid, - (short) RFIFOW(fd, 26), (short) RFIFOW(fd, 28), - (short) RFIFOW(fd, 30), (short) RFIFOW(fd, 32), - (short) RFIFOW(fd, 34), (short) RFIFOW(fd, 36), + static_cast(RFIFOW(fd, 26)), static_cast(RFIFOW(fd, 28)), + static_cast(RFIFOW(fd, 30)), static_cast(RFIFOW(fd, 32)), + static_cast(RFIFOW(fd, 34)), static_cast(RFIFOW(fd, 36)), timestamp, tmpstr, ip); @@ -2561,9 +2560,9 @@ void parse_admin(int fd) ad->userid, ad->ban_until_time, tmpstr, - (short) RFIFOW(fd, 26), (short) RFIFOW(fd, 28), - (short) RFIFOW(fd, 30), (short) RFIFOW(fd, 32), - (short) RFIFOW(fd, 34), (short) RFIFOW(fd, 36), + static_cast(RFIFOW(fd, 26)), static_cast(RFIFOW(fd, 28)), + static_cast(RFIFOW(fd, 30)), static_cast(RFIFOW(fd, 32)), + static_cast(RFIFOW(fd, 34)), static_cast(RFIFOW(fd, 36)), ip); } WFIFOL(fd, 30) = static_cast(ad->ban_until_time); @@ -2653,12 +2652,12 @@ void parse_admin(int fd) if (!timestamp || timestamp < now) timestamp = now; struct tm tmtime = timestamp; - tmtime.tm_year += (short) RFIFOW(fd, 26); - tmtime.tm_mon += (short) RFIFOW(fd, 28); - tmtime.tm_mday += (short) RFIFOW(fd, 30); - tmtime.tm_hour += (short) RFIFOW(fd, 32); - tmtime.tm_min += (short) RFIFOW(fd, 34); - tmtime.tm_sec += (short) RFIFOW(fd, 36); + tmtime.tm_year += static_cast(RFIFOW(fd, 26)); + tmtime.tm_mon += static_cast(RFIFOW(fd, 28)); + tmtime.tm_mday += static_cast(RFIFOW(fd, 30)); + tmtime.tm_hour += static_cast(RFIFOW(fd, 32)); + tmtime.tm_min += static_cast(RFIFOW(fd, 34)); + tmtime.tm_sec += static_cast(RFIFOW(fd, 36)); timestamp = tmtime; if (timestamp.okay()) { @@ -2672,12 +2671,12 @@ void parse_admin(int fd) ad->userid, ad->connect_until_time, tmpstr, - (short) RFIFOW(fd, 26), - (short) RFIFOW(fd, 28), - (short) RFIFOW(fd, 30), - (short) RFIFOW(fd, 32), - (short) RFIFOW(fd, 34), - (short) RFIFOW(fd, 36), + static_cast(RFIFOW(fd, 26)), + static_cast(RFIFOW(fd, 28)), + static_cast(RFIFOW(fd, 30)), + static_cast(RFIFOW(fd, 32)), + static_cast(RFIFOW(fd, 34)), + static_cast(RFIFOW(fd, 36)), timestamp, tmpstr2, ip); @@ -2693,12 +2692,12 @@ void parse_admin(int fd) ad->userid, ad->connect_until_time, tmpstr, - (short) RFIFOW(fd, 26), - (short) RFIFOW(fd, 28), - (short) RFIFOW(fd, 30), - (short) RFIFOW(fd, 32), - (short) RFIFOW(fd, 34), - (short) RFIFOW(fd, 36), + static_cast(RFIFOW(fd, 26)), + static_cast(RFIFOW(fd, 28)), + static_cast(RFIFOW(fd, 30)), + static_cast(RFIFOW(fd, 32)), + static_cast(RFIFOW(fd, 34)), + static_cast(RFIFOW(fd, 36)), ip); WFIFOL(fd, 30) = 0; } @@ -2728,7 +2727,7 @@ void parse_admin(int fd) if (ad) { WFIFOL(fd, 2) = ad->account_id; - WFIFOB(fd, 6) = (unsigned char) isGM(ad->account_id); + WFIFOB(fd, 6) = isGM(ad->account_id); memcpy(WFIFOP(fd, 7), ad->userid, 24); WFIFOB(fd, 31) = ad->sex; WFIFOL(fd, 32) = ad->logincount; @@ -2774,8 +2773,7 @@ void parse_admin(int fd) { LOGIN_LOG("'ladmin': Sending information of an account (request by the id; account: %s, id: %d, ip: %s)\n", ad.userid, RFIFOL(fd, 2), ip); - WFIFOB(fd, 6) = - (unsigned char) isGM(ad.account_id); + WFIFOB(fd, 6) = isGM(ad.account_id); memcpy(WFIFOP(fd, 7), ad.userid, 24); WFIFOB(fd, 31) = ad.sex; WFIFOL(fd, 32) = ad.logincount; @@ -2799,7 +2797,7 @@ void parse_admin(int fd) { LOGIN_LOG("'ladmin': Attempt to obtain information (by the id) of an unknown account (id: %d, ip: %s)\n", RFIFOL(fd, 2), ip); - strncpy((char *)WFIFOP(fd, 7), "", 24); + strncpy(static_cast(WFIFOP(fd, 7)), "", 24); WFIFOW(fd, 148) = 0; WFIFOSET(fd, 150); } @@ -2912,7 +2910,7 @@ void parse_login(int fd) { struct mmo_account account; int result, j; - unsigned char *p = (unsigned char *) &session[fd]->client_addr.sin_addr; + uint8_t *p = reinterpret_cast(&session[fd]->client_addr.sin_addr); int host_len; const char *ip = ip2str(session[fd]->client_addr.sin_addr); @@ -3029,7 +3027,7 @@ void parse_login(int fd) */ // if (version_2 & VERSION_2_UPDATEHOST) { - host_len = (int) strlen(update_host); + host_len = strlen(update_host); if (host_len > 0) { WFIFOW(fd, 0) = 0x63; @@ -3142,7 +3140,8 @@ void parse_login(int fd) session[fd]->eof = 1; return; } - std::unique_ptr ld{new login_session_data()}; + std::unique_ptr ld; + ld = make_unique(); if (RFIFOW(fd, 0) == 0x01db) { LOGIN_LOG("Sending request of the coding key (ip: %s)\n", @@ -3465,10 +3464,10 @@ int login_lan_config_read(const char *lancfgName) if (h != NULL) { sprintf(lan_char_ip, "%d.%d.%d.%d", - (unsigned char) h->h_addr[0], - (unsigned char) h->h_addr[1], - (unsigned char) h->h_addr[2], - (unsigned char) h->h_addr[3]); + static_cast(h->h_addr[0]), + static_cast(h->h_addr[1]), + static_cast(h->h_addr[2]), + static_cast(h->h_addr[3])); } else { @@ -3485,11 +3484,11 @@ int login_lan_config_read(const char *lancfgName) if (h != NULL) { for (int j = 0; j < 4; j++) - subneti[j] = (unsigned char) h->h_addr[j]; + subneti[j] = h->h_addr[j]; } else { - SSCANF(w2, "%d.%d.%d.%d", &subneti[0], &subneti[1], + SSCANF(w2, "%hhu.%hhu.%hhu.%hhu", &subneti[0], &subneti[1], &subneti[2], &subneti[3]); } PRINTF("Sub-network of the char-server: %d.%d.%d.%d.\n", @@ -3503,11 +3502,11 @@ int login_lan_config_read(const char *lancfgName) if (h != NULL) { for (int j = 0; j < 4; j++) - subnetmaski[j] = (unsigned char) h->h_addr[j]; + subnetmaski[j] = h->h_addr[j]; } else { - SSCANF(w2, "%d.%d.%d.%d", &subnetmaski[0], &subnetmaski[1], + SSCANF(w2, "%hhu.%hhu.%hhu.%hhu", &subnetmaski[0], &subnetmaski[1], &subnetmaski[2], &subnetmaski[3]); } PRINTF("Sub-network mask of the char-server: %d.%d.%d.%d.\n", @@ -3990,8 +3989,8 @@ void save_config_in_log(void) if (gm_account_filename_check_timer == interval_t::zero()) LOGIN_LOG("- to NOT check GM accounts file modifications.\n"); else - LOGIN_LOG("- to check GM accounts file modifications every %d seconds.\n", - (int)gm_account_filename_check_timer.count()); + LOGIN_LOG("- to check GM accounts file modifications every %lld seconds.\n", + static_cast(gm_account_filename_check_timer.count())); // not necessary to log the 'login_log_filename', we are inside :) diff --git a/src/map/atcommand.cpp b/src/map/atcommand.cpp index 56ff2ab..c066a46 100644 --- a/src/map/atcommand.cpp +++ b/src/map/atcommand.cpp @@ -127,10 +127,6 @@ ATCOMMAND_FUNC(enablenpc); ATCOMMAND_FUNC(disablenpc); ATCOMMAND_FUNC(servertime); // by Yor ATCOMMAND_FUNC(chardelitem); // by Yor -ATCOMMAND_FUNC(ignorelist); // by Yor -ATCOMMAND_FUNC(charignorelist); // by Yor -ATCOMMAND_FUNC(inall); // by Yor -ATCOMMAND_FUNC(exall); // by Yor ATCOMMAND_FUNC(email); // by Yor ATCOMMAND_FUNC(effect); //by Apple ATCOMMAND_FUNC(character_item_list); // by Yor @@ -293,10 +289,6 @@ AtCommandInfo atcommand_info[] = {"@servertime", 0, atcommand_servertime}, // by Yor {"@chardelitem", 60, atcommand_chardelitem}, // by Yor {"@listnearby", 40, atcommand_list_nearby}, // by Yor - {"@ignorelist", 0, atcommand_ignorelist}, // by Yor - {"@charignorelist", 20, atcommand_charignorelist}, // by Yor - {"@inall", 20, atcommand_inall}, // by Yor - {"@exall", 20, atcommand_exall}, // by Yor {"@email", 0, atcommand_email}, // by Yor {"@effect", 40, atcommand_effect}, // by Apple {"@charitemlist", 40, atcommand_character_item_list}, // by Yor @@ -372,19 +364,19 @@ void log_atcommand(dumb_ptr sd, const_string cmd) stamp_time(tmpstr); fprintf(fp, "[%s] %s(%d,%d) %s(%d) : ", tmpstr, - map[sd->bl_m].name, sd->bl_x, sd->bl_y, + sd->bl_m->name, sd->bl_x, sd->bl_y, sd->status.name, sd->status.account_id); fwrite(cmd.data(), 1, cmd.size(), fp); } -char *gm_logfile_name = NULL; +std::string gm_logfile_name; /*========================================== * Log a timestamped line to GM log file *------------------------------------------ */ FILE *get_gm_log() { - if (!gm_logfile_name) + if (gm_logfile_name.empty()) return NULL; struct tm ctime = TimeT::now(); @@ -410,7 +402,7 @@ FILE *get_gm_log() if (!gm_logfile) { perror("GM log file"); - gm_logfile_name = NULL; + gm_logfile_name.clear(); } return gm_logfile; } @@ -642,7 +634,6 @@ int atcommand_charwarp(const int fd, dumb_ptr sd, char character[100]; int x = 0, y = 0; dumb_ptr pl_sd; - int m; memset(map_name, '\0', sizeof(map_name)); memset(character, '\0', sizeof(character)); @@ -669,15 +660,15 @@ int atcommand_charwarp(const int fd, dumb_ptr sd, { // you can rura+ only lower or same GM level if (x > 0 && x < 800 && y > 0 && y < 800) { - m = map_mapname2mapid(map_name); - if (m >= 0 && map[m].flag.nowarpto + map_local *m = map_mapname2mapid(map_name); + if (m != nullptr && m->flag.nowarpto && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(fd, "You are not authorised to warp someone to this map."); return -1; } - if (pl_sd->bl_m >= 0 && map[pl_sd->bl_m].flag.nowarp + if (pl_sd->bl_m != nullptr && pl_sd->bl_m->flag.nowarp && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(fd, @@ -725,7 +716,6 @@ int atcommand_warp(const int fd, dumb_ptr sd, { char map_name[100]; int x = 0, y = 0; - int m; memset(map_name, '\0', sizeof(map_name)); @@ -747,15 +737,15 @@ int atcommand_warp(const int fd, dumb_ptr sd, if (x > 0 && x < 800 && y > 0 && y < 800) { - m = map_mapname2mapid(map_name); - if (m >= 0 && map[m].flag.nowarpto + map_local *m = map_mapname2mapid(map_name); + if (m != nullptr && m->flag.nowarpto && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(fd, "You are not authorised to warp you to this map."); return -1; } - if (sd->bl_m >= 0 && map[sd->bl_m].flag.nowarp + if (sd->bl_m != nullptr && sd->bl_m->flag.nowarp && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(fd, @@ -834,14 +824,14 @@ int atcommand_goto(const int fd, dumb_ptr sd, if ((pl_sd = map_nick2sd(character)) != NULL) { - if (pl_sd->bl_m >= 0 && map[pl_sd->bl_m].flag.nowarpto + if (pl_sd->bl_m != nullptr && pl_sd->bl_m->flag.nowarpto && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(fd, "You are not authorised to warp you to the map of this player."); return -1; } - if (sd->bl_m >= 0 && map[sd->bl_m].flag.nowarp + if (sd->bl_m != nullptr && sd->bl_m->flag.nowarp && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(fd, @@ -877,14 +867,14 @@ int atcommand_jump(const int fd, dumb_ptr sd, y = random_::in(1, 399); if (x > 0 && x < 800 && y > 0 && y < 800) { - if (sd->bl_m >= 0 && map[sd->bl_m].flag.nowarpto + if (sd->bl_m != nullptr && sd->bl_m->flag.nowarpto && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(fd, "You are not authorised to warp you to your actual map."); return -1; } - if (sd->bl_m >= 0 && map[sd->bl_m].flag.nowarp + if (sd->bl_m != nullptr && sd->bl_m->flag.nowarp && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(fd, @@ -1056,7 +1046,7 @@ int atcommand_whomap(const int fd, dumb_ptr sd, { int count; int pl_GM_level, GM_level; - int map_id; + map_local *map_id; char map_name[100]; memset(map_name, '\0', sizeof(map_name)); @@ -1068,7 +1058,8 @@ int atcommand_whomap(const int fd, dumb_ptr sd, sscanf(message, "%99s", map_name); if (strstr(map_name, ".gat") == NULL && strstr(map_name, ".afm") == NULL && strlen(map_name) < 13) // 16 - 4 (.gat) strcat(map_name, ".gat"); - if ((map_id = map_mapname2mapid(map_name)) < 0) + map_id = map_mapname2mapid(map_name); + if (map_id == nullptr) map_id = sd->bl_m; } @@ -1108,7 +1099,7 @@ int atcommand_whomap(const int fd, dumb_ptr sd, } std::string output = STRPRINTF("%d players found in map '%s'.", - count, map[map_id].name); + count, map_id->name); clif_displaymessage(fd, output); return 0; @@ -1123,12 +1114,12 @@ int atcommand_whomapgroup(const int fd, dumb_ptr sd, { int count; int pl_GM_level, GM_level; - int map_id = 0; char map_name[100]; struct party *p; memset(map_name, '\0', sizeof(map_name)); + map_local *map_id; if (!message || !*message) map_id = sd->bl_m; else @@ -1136,7 +1127,8 @@ int atcommand_whomapgroup(const int fd, dumb_ptr sd, sscanf(message, "%99s", map_name); if (strstr(map_name, ".gat") == NULL && strstr(map_name, ".afm") == NULL && strlen(map_name) < 13) // 16 - 4 (.gat) strcat(map_name, ".gat"); - if ((map_id = map_mapname2mapid(map_name)) < 0) + map_id = map_mapname2mapid(map_name); + if (map_id == nullptr) map_id = sd->bl_m; } @@ -1176,12 +1168,12 @@ int atcommand_whomapgroup(const int fd, dumb_ptr sd, std::string output; if (count == 0) - output = STRPRINTF("No player found in map '%s'.", map[map_id].name); + output = STRPRINTF("No player found in map '%s'.", map_id->name); else if (count == 1) - output = STRPRINTF("1 player found in map '%s'.", map[map_id].name); + output = STRPRINTF("1 player found in map '%s'.", map_id->name); else { - output = STRPRINTF("%d players found in map '%s'.", count, map[map_id].name); + output = STRPRINTF("%d players found in map '%s'.", count, map_id->name); } clif_displaymessage(fd, output); @@ -1295,17 +1287,15 @@ int atcommand_save(const int fd, dumb_ptr sd, int atcommand_load(const int fd, dumb_ptr sd, const char *, const char *) { - int m; - - m = map_mapname2mapid(sd->status.save_point.map); - if (m >= 0 && map[m].flag.nowarpto + map_local *m = map_mapname2mapid(sd->status.save_point.map); + if (m != nullptr && m->flag.nowarpto && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(fd, "You are not authorised to warp you to your save map."); return -1; } - if (sd->bl_m >= 0 && map[sd->bl_m].flag.nowarp + if (sd->bl_m != nullptr && sd->bl_m->flag.nowarp && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(fd, @@ -1894,9 +1884,9 @@ int atcommand_pvpoff(const int fd, dumb_ptr sd, return -1; } - if (map[sd->bl_m].flag.pvp) + if (sd->bl_m->flag.pvp) { - map[sd->bl_m].flag.pvp = 0; + sd->bl_m->flag.pvp = 0; for (int i = 0; i < fd_max; i++) { if (!session[i]) @@ -1934,9 +1924,9 @@ int atcommand_pvpon(const int fd, dumb_ptr sd, return -1; } - if (!map[sd->bl_m].flag.pvp && !map[sd->bl_m].flag.nopvp) + if (!sd->bl_m->flag.pvp && !sd->bl_m->flag.nopvp) { - map[sd->bl_m].flag.pvp = 1; + sd->bl_m->flag.pvp = 1; for (int i = 0; i < fd_max; i++) { if (!session[i]) @@ -2210,23 +2200,27 @@ static void atcommand_killmonster_sub(const int fd, dumb_ptr sd, const char *message, const int drop) { - int map_id; char map_name[100]; memset(map_name, '\0', sizeof(map_name)); + map_local *map_id; if (!message || !*message || sscanf(message, "%99s", map_name) < 1) map_id = sd->bl_m; else { if (strstr(map_name, ".gat") == NULL && strstr(map_name, ".afm") == NULL && strlen(map_name) < 13) // 16 - 4 (.gat) strcat(map_name, ".gat"); - if ((map_id = map_mapname2mapid(map_name)) < 0) + map_id = map_mapname2mapid(map_name); + if (map_id == nullptr) map_id = sd->bl_m; } - map_foreachinarea(std::bind(atkillmonster_sub, ph::_1, drop), map_id, 0, 0, map[map_id].xs, - map[map_id].ys, BL::MOB); + map_foreachinarea(std::bind(atkillmonster_sub, ph::_1, drop), + map_id, + 0, 0, + map_id->xs, map_id->ys, + BL::MOB); clif_displaymessage(fd, "All monsters killed!"); @@ -2268,8 +2262,10 @@ int atcommand_list_nearby(const int fd, dumb_ptr sd, { clif_displaymessage(fd, "Nearby players:"); map_foreachinarea(std::bind(atlist_nearby_sub, ph::_1, fd), - sd->bl_m, sd->bl_x - 1, sd->bl_y - 1, - sd->bl_x + 1, sd->bl_x + 1, BL::PC); + sd->bl_m, + sd->bl_x - 1, sd->bl_y - 1, + sd->bl_x + 1, sd->bl_x + 1, + BL::PC); return 0; } @@ -2299,7 +2295,7 @@ int atcommand_gat(const int fd, dumb_ptr sd, { std::string output = STRPRINTF( "%s (x= %d, y= %d) %02X %02X %02X %02X %02X", - map[sd->bl_m].name, sd->bl_x - 2, sd->bl_y + y, + sd->bl_m->name, sd->bl_x - 2, sd->bl_y + y, map_getcell(sd->bl_m, sd->bl_x - 2, sd->bl_y + y), map_getcell(sd->bl_m, sd->bl_x - 1, sd->bl_y + y), map_getcell(sd->bl_m, sd->bl_x, sd->bl_y + y), @@ -2348,15 +2344,15 @@ int atcommand_statuspoint(const int fd, dumb_ptr sd, return -1; } - new_status_point = (int) sd->status.status_point + point; + new_status_point = sd->status.status_point + point; if (point > 0 && (point > 0x7FFF || new_status_point > 0x7FFF)) // fix positiv overflow new_status_point = 0x7FFF; else if (point < 0 && (point < -0x7FFF || new_status_point < 0)) // fix negativ overflow new_status_point = 0; - if (new_status_point != (int) sd->status.status_point) + if (new_status_point != sd->status.status_point) { - sd->status.status_point = (short) new_status_point; + sd->status.status_point = new_status_point; clif_updatestatus(sd, SP::STATUSPOINT); clif_displaymessage(fd, "Number of status points changed!"); } @@ -2388,15 +2384,15 @@ int atcommand_skillpoint(const int fd, dumb_ptr sd, return -1; } - new_skill_point = (int) sd->status.skill_point + point; + new_skill_point = sd->status.skill_point + point; if (point > 0 && (point > 0x7FFF || new_skill_point > 0x7FFF)) // fix positiv overflow new_skill_point = 0x7FFF; else if (point < 0 && (point < -0x7FFF || new_skill_point < 0)) // fix negativ overflow new_skill_point = 0; - if (new_skill_point != (int) sd->status.skill_point) + if (new_skill_point != sd->status.skill_point) { - sd->status.skill_point = (short) new_skill_point; + sd->status.skill_point = new_skill_point; clif_updatestatus(sd, SP::SKILLPOINT); clif_displaymessage(fd, "Number of skill points changed!"); } @@ -2473,7 +2469,7 @@ int atcommand_param(const int fd, dumb_ptr sd, return -1; } - new_value = (int) sd->status.attrs[attr] + value; + new_value = sd->status.attrs[attr] + value; if (value > 0 && (value > battle_config.max_parameter || new_value > battle_config.max_parameter)) // fix positiv overflow new_value = battle_config.max_parameter; else if (value < 0 && (value < -battle_config.max_parameter || new_value < 1)) // fix negativ overflow @@ -2569,14 +2565,14 @@ int atcommand_recall(const int fd, dumb_ptr sd, { if (pc_isGM(sd) >= pc_isGM(pl_sd)) { // you can recall only lower or same level - if (sd->bl_m >= 0 && map[sd->bl_m].flag.nowarpto + if (sd->bl_m != nullptr && sd->bl_m->flag.nowarpto && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(fd, "You are not authorised to warp somenone to your actual map."); return -1; } - if (pl_sd->bl_m >= 0 && map[pl_sd->bl_m].flag.nowarp + if (pl_sd->bl_m != nullptr && pl_sd->bl_m->flag.nowarp && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(fd, @@ -3094,7 +3090,6 @@ int atcommand_character_save(const int fd, dumb_ptr sd, char character[100]; dumb_ptr pl_sd; int x = 0, y = 0; - int m; memset(map_name, '\0', sizeof(map_name)); memset(character, '\0', sizeof(character)); @@ -3114,16 +3109,17 @@ int atcommand_character_save(const int fd, dumb_ptr sd, if ((pl_sd = map_nick2sd(character)) != NULL) { if (pc_isGM(sd) >= pc_isGM(pl_sd)) - { // you can change save point only to lower or same gm level - m = map_mapname2mapid(map_name); - if (m < 0) + { + // you can change save point only to lower or same gm level + map_local *m = map_mapname2mapid(map_name); + if (m == nullptr) { clif_displaymessage(fd, "Map not found."); return -1; } else { - if (m >= 0 && map[m].flag.nowarpto + if (m != nullptr && m->flag.nowarpto && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(fd, @@ -4113,12 +4109,12 @@ int atcommand_charskpoint(const int fd, dumb_ptr, if ((pl_sd = map_nick2sd(character)) != NULL) { - new_skill_point = (int) pl_sd->status.skill_point + point; + new_skill_point = pl_sd->status.skill_point + point; if (point > 0 && (point > 0x7FFF || new_skill_point > 0x7FFF)) // fix positiv overflow new_skill_point = 0x7FFF; else if (point < 0 && (point < -0x7FFF || new_skill_point < 0)) // fix negativ overflow new_skill_point = 0; - if (new_skill_point != (int) pl_sd->status.skill_point) + if (new_skill_point != pl_sd->status.skill_point) { pl_sd->status.skill_point = new_skill_point; clif_updatestatus(pl_sd, SP::SKILLPOINT); @@ -4167,12 +4163,12 @@ int atcommand_charstpoint(const int fd, dumb_ptr, if ((pl_sd = map_nick2sd(character)) != NULL) { - new_status_point = (int) pl_sd->status.status_point + point; + new_status_point = pl_sd->status.status_point + point; if (point > 0 && (point > 0x7FFF || new_status_point > 0x7FFF)) // fix positiv overflow new_status_point = 0x7FFF; else if (point < 0 && (point < -0x7FFF || new_status_point < 0)) // fix negativ overflow new_status_point = 0; - if (new_status_point != (int) pl_sd->status.status_point) + if (new_status_point != pl_sd->status.status_point) { pl_sd->status.status_point = new_status_point; clif_updatestatus(pl_sd, SP::STATUSPOINT); @@ -4257,7 +4253,7 @@ int atcommand_recallall(const int fd, dumb_ptr sd, { int count; - if (sd->bl_m >= 0 && map[sd->bl_m].flag.nowarpto + if (sd->bl_m != nullptr && sd->bl_m->flag.nowarpto && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(fd, @@ -4277,7 +4273,7 @@ int atcommand_recallall(const int fd, dumb_ptr sd, && pc_isGM(sd) >= pc_isGM(pl_sd)) { // you can recall only lower or same level - if (pl_sd->bl_m >= 0 && map[pl_sd->bl_m].flag.nowarp + if (pl_sd->bl_m != nullptr && pl_sd->bl_m->flag.nowarp && battle_config.any_warp_GM_min_level > pc_isGM(sd)) count++; else @@ -4317,7 +4313,7 @@ int atcommand_partyrecall(const int fd, dumb_ptr sd, return -1; } - if (sd->bl_m >= 0 && map[sd->bl_m].flag.nowarpto + if (sd->bl_m != nullptr && sd->bl_m->flag.nowarpto && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(fd, @@ -4338,7 +4334,7 @@ int atcommand_partyrecall(const int fd, dumb_ptr sd, && sd->status.account_id != pl_sd->status.account_id && pl_sd->status.party_id == p->party_id) { - if (pl_sd->bl_m >= 0 && map[pl_sd->bl_m].flag.nowarp + if (pl_sd->bl_m != nullptr && pl_sd->bl_m->flag.nowarp && battle_config.any_warp_GM_min_level > pc_isGM(sd)) count++; else @@ -4448,7 +4444,7 @@ int atcommand_mapinfo(const int fd, dumb_ptr sd, dumb_ptr nd = NULL; char map_name[100]; const char *direction = NULL; - int m_id, list = 0; + int list = 0; memset(map_name, '\0', sizeof(map_name)); @@ -4466,7 +4462,8 @@ int atcommand_mapinfo(const int fd, dumb_ptr sd, if (strstr(map_name, ".gat") == NULL && strstr(map_name, ".afm") == NULL && strlen(map_name) < 13) // 16 - 4 (.gat) strcat(map_name, ".gat"); - if ((m_id = map_mapname2mapid(map_name)) < 0) + map_local *m_id = map_mapname2mapid(map_name); + if (m_id != nullptr) { clif_displaymessage(fd, "Map not found."); return -1; @@ -4475,38 +4472,38 @@ int atcommand_mapinfo(const int fd, dumb_ptr sd, clif_displaymessage(fd, "------ Map Info ------"); std::string output = STRPRINTF("Map Name: %s", map_name); clif_displaymessage(fd, output); - output = STRPRINTF("Players In Map: %d", map[m_id].users); + output = STRPRINTF("Players In Map: %d", m_id->users); clif_displaymessage(fd, output); - output = STRPRINTF("NPCs In Map: %d", map[m_id].npc_num); + output = STRPRINTF("NPCs In Map: %d", m_id->npc_num); clif_displaymessage(fd, output); clif_displaymessage(fd, "------ Map Flags ------"); output = STRPRINTF("Player vs Player: %s | No Party: %s", - (map[m_id].flag.pvp) ? "True" : "False", - (map[m_id].flag.pvp_noparty) ? "True" : "False"); + (m_id->flag.pvp) ? "True" : "False", + (m_id->flag.pvp_noparty) ? "True" : "False"); clif_displaymessage(fd, output); output = STRPRINTF("No Dead Branch: %s", - (map[m_id].flag.nobranch) ? "True" : "False"); + (m_id->flag.nobranch) ? "True" : "False"); clif_displaymessage(fd, output); output = STRPRINTF("No Memo: %s", - (map[m_id].flag.nomemo) ? "True" : "False"); + (m_id->flag.nomemo) ? "True" : "False"); clif_displaymessage(fd, output); output = STRPRINTF("No Penalty: %s", - (map[m_id].flag.nopenalty) ? "True" : "False"); + (m_id->flag.nopenalty) ? "True" : "False"); clif_displaymessage(fd, output); output = STRPRINTF("No Return: %s", - (map[m_id].flag.noreturn) ? "True" : "False"); + (m_id->flag.noreturn) ? "True" : "False"); clif_displaymessage(fd, output); output = STRPRINTF("No Save: %s", - (map[m_id].flag.nosave) ? "True" : "False"); + (m_id->flag.nosave) ? "True" : "False"); clif_displaymessage(fd, output); output = STRPRINTF("No Teleport: %s", - (map[m_id].flag.noteleport) ? "True" : "False"); + (m_id->flag.noteleport) ? "True" : "False"); clif_displaymessage(fd, output); output = STRPRINTF("No Monster Teleport: %s", - (map[m_id].flag.monster_noteleport) ? "True" : "False"); + (m_id->flag.monster_noteleport) ? "True" : "False"); clif_displaymessage(fd, output); output = STRPRINTF("No Zeny Penalty: %s", - (map[m_id].flag.nozenypenalty) ? "True" : "False"); + (m_id->flag.nozenypenalty) ? "True" : "False"); clif_displaymessage(fd, output); switch (list) @@ -4533,9 +4530,9 @@ int atcommand_mapinfo(const int fd, dumb_ptr sd, break; case 2: clif_displaymessage(fd, "----- NPCs in Map -----"); - for (int i = 0; i < map[m_id].npc_num;) + for (int i = 0; i < m_id->npc_num;) { - nd = map[m_id].npc[i]; + nd = m_id->npc[i]; switch (nd->dir) { case DIR::S: @@ -4844,249 +4841,6 @@ int atcommand_localbroadcast(const int fd, dumb_ptr sd, return 0; } -/*========================================== - * @ignorelist by [Yor] - *------------------------------------------ - */ -int atcommand_ignorelist(const int fd, dumb_ptr sd, - const char *, const char *) -{ - int count; - int i; - - count = 0; - for (i = 0; i < (int)(sizeof(sd->ignore) / sizeof(sd->ignore[0])); i++) - if (sd->ignore[i].name[0]) - count++; - - if (sd->ignoreAll == 0) - if (count == 0) - clif_displaymessage(fd, "You accept any wisp (no wisper is refused)."); - else - { - std::string output = STRPRINTF( - "You accept any wisp, except thoses from %d player (s):", - count); - clif_displaymessage(fd, output); - } - else if (count == 0) - clif_displaymessage(fd, "You refuse all wisps (no specifical wisper is refused)."); - else - { - std::string output = STRPRINTF( - "You refuse all wisps, AND refuse wisps from %d player (s):", - count); - clif_displaymessage(fd, output); - } - - if (count > 0) - for (i = 0; i < (int)(sizeof(sd->ignore) / sizeof(sd->ignore[0])); - i++) - if (sd->ignore[i].name[0]) - clif_displaymessage(fd, sd->ignore[i].name); - - return 0; -} - -/*========================================== - * @charignorelist by [Yor] - *------------------------------------------ - */ -int atcommand_charignorelist(const int fd, dumb_ptr, - const char *, const char *message) -{ - char character[100]; - dumb_ptr pl_sd; - int count; - int i; - - memset(character, '\0', sizeof(character)); - - if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1) - { - clif_displaymessage(fd, - "Please, enter a player name (usage: @charignorelist )."); - return -1; - } - - if ((pl_sd = map_nick2sd(character)) != NULL) - { - count = 0; - for (i = 0; - i < (int)(sizeof(pl_sd->ignore) / sizeof(pl_sd->ignore[0])); - i++) - if (pl_sd->ignore[i].name[0]) - count++; - - if (pl_sd->ignoreAll == 0) - if (count == 0) - { - std::string output = STRPRINTF( - "'%s' accept any wisp (no wisper is refused).", - pl_sd->status.name); - clif_displaymessage(fd, output); - } - else - { - std::string output = STRPRINTF( - "'%s' accept any wisp, except thoses from %d player(s):", - pl_sd->status.name, count); - clif_displaymessage(fd, output); - } - else if (count == 0) - { - std::string output = STRPRINTF( - "'%s' refuse all wisps (no specifical wisper is refused).", - pl_sd->status.name); - clif_displaymessage(fd, output); - } - else - { - std::string output = STRPRINTF( - "'%s' refuse all wisps, AND refuse wisps from %d player(s):", - pl_sd->status.name, count); - clif_displaymessage(fd, output); - } - - if (count > 0) - for (i = 0; - i < (int)(sizeof(pl_sd->ignore) / sizeof(pl_sd->ignore[0])); - i++) - if (pl_sd->ignore[i].name[0]) - clif_displaymessage(fd, pl_sd->ignore[i].name); - - } - else - { - clif_displaymessage(fd, "Character not found."); - return -1; - } - - return 0; -} - -/*========================================== - * @inall by [Yor] - *------------------------------------------ - */ -int atcommand_inall(const int fd, dumb_ptr sd, - const char *, const char *message) -{ - char character[100]; - dumb_ptr pl_sd; - - memset(character, '\0', sizeof(character)); - - if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1) - { - clif_displaymessage(fd, - "Please, enter a player name (usage: @inall )."); - return -1; - } - - if ((pl_sd = map_nick2sd(character)) != NULL) - { - if (pc_isGM(sd) >= pc_isGM(pl_sd)) - { // you can change wisp option only to lower or same level - if (pl_sd->ignoreAll == 0) - { - std::string output = STRPRINTF( - "'%s' already accepts all wispers.", - pl_sd->status.name); - clif_displaymessage(fd, output); - return -1; - } - else - { - pl_sd->ignoreAll = 0; - std::string output = STRPRINTF( - "'%s' now accepts all wispers.", - pl_sd->status.name); - clif_displaymessage(fd, output); - // message to player - clif_displaymessage(pl_sd->fd, "A GM has authorised all wispers for you."); - WFIFOW(pl_sd->fd, 0) = 0x0d2; // R 00d2 .B .B: type: 0: deny, 1: allow, fail: 0: success, 1: fail - WFIFOB(pl_sd->fd, 2) = 1; - WFIFOB(pl_sd->fd, 3) = 0; // success - WFIFOSET(pl_sd->fd, 4); // packet_len_table[0x0d2] - } - } - else - { - clif_displaymessage(fd, "Your GM level don't authorise you to do this action on this player."); - return -1; - } - } - else - { - clif_displaymessage(fd, "Character not found."); - return -1; - } - - return 0; -} - -/*========================================== - * @exall by [Yor] - *------------------------------------------ - */ -int atcommand_exall(const int fd, dumb_ptr sd, - const char *, const char *message) -{ - char character[100]; - dumb_ptr pl_sd; - - memset(character, '\0', sizeof(character)); - - if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1) - { - clif_displaymessage(fd, - "Please, enter a player name (usage: @exall )."); - return -1; - } - - if ((pl_sd = map_nick2sd(character)) != NULL) - { - if (pc_isGM(sd) >= pc_isGM(pl_sd)) - { // you can change wisp option only to lower or same level - if (pl_sd->ignoreAll == 1) - { - std::string output = STRPRINTF( - "'%s' already blocks all wispers.", - pl_sd->status.name); - clif_displaymessage(fd, output); - return -1; - } - else - { - pl_sd->ignoreAll = 1; - std::string output = STRPRINTF( - "'%s' blocks now all wispers.", - pl_sd->status.name); - clif_displaymessage(fd, output); - // message to player - clif_displaymessage(pl_sd->fd, "A GM has blocked all wispers for you."); - WFIFOW(pl_sd->fd, 0) = 0x0d2; // R 00d2 .B .B: type: 0: deny, 1: allow, fail: 0: success, 1: fail - WFIFOB(pl_sd->fd, 2) = 0; - WFIFOB(pl_sd->fd, 3) = 0; // success - WFIFOSET(pl_sd->fd, 4); // packet_len_table[0x0d2] - } - } - else - { - clif_displaymessage(fd, "Your GM level don't authorise you to do this action on this player."); - return -1; - } - } - else - { - clif_displaymessage(fd, "Character not found."); - return -1; - } - - return 0; -} - /*========================================== * @email by [Yor] *------------------------------------------ @@ -5901,10 +5655,10 @@ int atcommand_rain(const int, dumb_ptr sd, int effno = 0; effno = 161; nullpo_retr(-1, sd); - if (effno < 0 || map[sd->bl_m].flag.rain) + if (effno < 0 || sd->bl_m->flag.rain) return -1; - map[sd->bl_m].flag.rain = 1; + sd->bl_m->flag.rain = 1; clif_specialeffect(sd, effno, 2); return 0; } @@ -5919,10 +5673,10 @@ int atcommand_snow(const int, dumb_ptr sd, int effno = 0; effno = 162; nullpo_retr(-1, sd); - if (effno < 0 || map[sd->bl_m].flag.snow) + if (effno < 0 || sd->bl_m->flag.snow) return -1; - map[sd->bl_m].flag.snow = 1; + sd->bl_m->flag.snow = 1; clif_specialeffect(sd, effno, 2); return 0; } @@ -5937,10 +5691,10 @@ int atcommand_sakura(const int, dumb_ptr sd, int effno = 0; effno = 163; nullpo_retr(-1, sd); - if (effno < 0 || map[sd->bl_m].flag.sakura) + if (effno < 0 || sd->bl_m->flag.sakura) return -1; - map[sd->bl_m].flag.sakura = 1; + sd->bl_m->flag.sakura = 1; clif_specialeffect(sd, effno, 2); return 0; } @@ -5955,10 +5709,10 @@ int atcommand_fog(const int, dumb_ptr sd, int effno = 0; effno = 233; nullpo_retr(-1, sd); - if (effno < 0 || map[sd->bl_m].flag.fog) + if (effno < 0 || sd->bl_m->flag.fog) return -1; - map[sd->bl_m].flag.fog = 1; + sd->bl_m->flag.fog = 1; clif_specialeffect(sd, effno, 2); return 0; @@ -5974,10 +5728,10 @@ int atcommand_leaves(const int, dumb_ptr sd, int effno = 0; effno = 333; nullpo_retr(-1, sd); - if (effno < 0 || map[sd->bl_m].flag.leaves) + if (effno < 0 || sd->bl_m->flag.leaves) return -1; - map[sd->bl_m].flag.leaves = 1; + sd->bl_m->flag.leaves = 1; clif_specialeffect(sd, effno, 2); return 0; } @@ -6077,7 +5831,8 @@ int atcommand_adjgmlvl(const int fd, dumb_ptr, dumb_ptr pl_sd; if (!message || !*message - || sscanf(message, "%d %s", &newlev, user) != 2) + || sscanf(message, "%d %s", &newlev, user) != 2 + || newlev < 0 || newlev > 99) { clif_displaymessage(fd, "usage: @adjgmlvl ."); return -1; @@ -6301,21 +6056,21 @@ int atcommand_jump_iterate(const int fd, dumb_ptr sd, pl_sd = get_start(); } - if (pl_sd->bl_m >= 0 && map[pl_sd->bl_m].flag.nowarpto + if (pl_sd->bl_m != nullptr && pl_sd->bl_m->flag.nowarpto && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(fd, "You are not authorised to warp you to the map of this player."); return -1; } - if (sd->bl_m >= 0 && map[sd->bl_m].flag.nowarp + if (sd->bl_m != nullptr && sd->bl_m->flag.nowarp && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(fd, "You are not authorised to warp you from your actual map."); return -1; } - pc_setpos(sd, map[pl_sd->bl_m].name, pl_sd->bl_x, pl_sd->bl_y, BeingRemoveWhy::WARPED); + pc_setpos(sd, pl_sd->bl_m->name, pl_sd->bl_x, pl_sd->bl_y, BeingRemoveWhy::WARPED); std::string output = STRPRINTF("Jump to %s", pl_sd->status.name); clif_displaymessage(fd, output); @@ -6395,7 +6150,7 @@ int atcommand_skillpool_info(const int fd, dumb_ptr, for (i = 0; i < skill_pool_skills_size; ++i) { - const char *name = skill_name(skill_pool_skills[i]); + const std::string& name = skill_name(skill_pool_skills[i]); int lvl = pl_sd->status.skill[skill_pool_skills[i]].lv; if (lvl) @@ -6522,7 +6277,7 @@ int atcommand_ipcheck(const int fd, dumb_ptr, return -1; } - if (getpeername(pl_sd->fd, (struct sockaddr *)&sai, &sa_len)) + if (getpeername(pl_sd->fd, reinterpret_cast(&sai), &sa_len)) { clif_displaymessage(fd, "Guru Meditation Error: getpeername() failed"); @@ -6541,7 +6296,7 @@ int atcommand_ipcheck(const int fd, dumb_ptr, pl_sd = dumb_ptr(static_cast(session[i]->session_data.get())); if (pl_sd && pl_sd->state.auth) { - if (getpeername(pl_sd->fd, (struct sockaddr *)&sai, &sa_len)) + if (getpeername(pl_sd->fd, reinterpret_cast(&sai), &sa_len)) continue; // Is checking GM levels really needed here? diff --git a/src/map/atcommand.hpp b/src/map/atcommand.hpp index 7033972..d81f04d 100644 --- a/src/map/atcommand.hpp +++ b/src/map/atcommand.hpp @@ -13,6 +13,6 @@ int atcommand_config_read(const char *cfgName); void log_atcommand(dumb_ptr sd, const_string cmd); // only used by map.cpp -extern char *gm_logfile_name; +extern std::string gm_logfile_name; #endif // ATCOMMAND_HPP diff --git a/src/map/battle.cpp b/src/map/battle.cpp index 8e7b174..81e606f 100644 --- a/src/map/battle.cpp +++ b/src/map/battle.cpp @@ -12,6 +12,7 @@ #include "itemdb.hpp" #include "map.hpp" #include "mob.hpp" +#include "path.hpp" #include "pc.hpp" #include "skill.hpp" @@ -2039,8 +2040,8 @@ ATK battle_weapon_attack(dumb_ptr src, dumb_ptr target, && bool(sd->status.inventory[weapon_index].equip & EPOS::WEAPON)) weapon = sd->inventory_data[weapon_index]->nameid; - MAP_LOG("PC%d %d:%d,%d WPNDMG %s%d %d FOR %d WPN %d", - sd->status.char_id, src->bl_m, src->bl_x, src->bl_y, + MAP_LOG("PC%d %s:%d,%d WPNDMG %s%d %d FOR %d WPN %d", + sd->status.char_id, src->bl_m->name, src->bl_x, src->bl_y, (target->bl_type == BL::PC) ? "PC" : "MOB", (target->bl_type == BL::PC) ? target->as_player()-> status.char_id @@ -2052,8 +2053,8 @@ ATK battle_weapon_attack(dumb_ptr src, dumb_ptr target, if (target->bl_type == BL::PC) { dumb_ptr sd2 = target->as_player(); - MAP_LOG("PC%d %d:%d,%d WPNINJURY %s%d %d FOR %d", - sd2->status.char_id, target->bl_m, target->bl_x, target->bl_y, + MAP_LOG("PC%d %s:%d,%d WPNINJURY %s%d %d FOR %d", + sd2->status.char_id, target->bl_m->name, target->bl_x, target->bl_y, (src->bl_type == BL::PC) ? "PC" : "MOB", (src->bl_type == BL::PC) ? src->as_player()->status.char_id @@ -2226,12 +2227,12 @@ int battle_check_target(dumb_ptr src, dumb_ptr target, if (ss->bl_type == BL::PC && target->bl_type == BL::PC) { // 両方PVPモードなら否定(敵) - if (map[ss->bl_m].flag.pvp + if (ss->bl_m->flag.pvp || pc_iskiller(ss->as_player(), target->as_player())) { // [MouseJstr] if (battle_config.pk_mode) return 1; // prevent novice engagement in pk_mode [Valaris] - else if (map[ss->bl_m].flag.pvp_noparty && s_p > 0 && t_p > 0 + else if (ss->bl_m->flag.pvp_noparty && s_p > 0 && t_p > 0 && s_p == t_p) return 1; return 0; @@ -2313,7 +2314,7 @@ int battle_config_read(const char *cfgName) battle_config.defnotenemy = 1; battle_config.random_monster_checklv = 1; battle_config.attr_recover = 1; - battle_config.flooritem_lifetime = (int)std::chrono::duration_cast(LIFETIME_FLOORITEM).count(); + battle_config.flooritem_lifetime = std::chrono::duration_cast(LIFETIME_FLOORITEM).count(); battle_config.item_auto_get = 0; battle_config.drop_pickup_safety_zone = 20; battle_config.item_first_get_time = 3000; @@ -2341,7 +2342,6 @@ int battle_config_read(const char *cfgName) battle_config.wp_rate = 100; battle_config.pp_rate = 100; battle_config.monster_active_enable = 1; - battle_config.monster_loot_type = 0; battle_config.mob_skill_use = 1; battle_config.mob_count_rate = 100; battle_config.quest_skill_learn = 0; @@ -2524,7 +2524,6 @@ int battle_config_read(const char *cfgName) {"weapon_produce_rate", &battle_config.wp_rate}, {"potion_produce_rate", &battle_config.pp_rate}, {"monster_active_enable", &battle_config.monster_active_enable}, - {"monster_loot_type", &battle_config.monster_loot_type}, {"mob_skill_use", &battle_config.mob_skill_use}, {"mob_count_rate", &battle_config.mob_count_rate}, {"quest_skill_learn", &battle_config.quest_skill_learn}, @@ -2666,7 +2665,7 @@ int battle_config_read(const char *cfgName) if (--count == 0) { if (static_cast(battle_config.flooritem_lifetime) < std::chrono::seconds(1)) - battle_config.flooritem_lifetime = (int)std::chrono::duration_cast(LIFETIME_FLOORITEM).count(); + battle_config.flooritem_lifetime = std::chrono::duration_cast(LIFETIME_FLOORITEM).count(); if (battle_config.restart_hp_rate < 0) battle_config.restart_hp_rate = 0; else if (battle_config.restart_hp_rate > 100) diff --git a/src/map/battle.hpp b/src/map/battle.hpp index 8b7c1bd..168cf60 100644 --- a/src/map/battle.hpp +++ b/src/map/battle.hpp @@ -132,7 +132,6 @@ extern struct Battle_Config int wp_rate; int pp_rate; int monster_active_enable; - int monster_loot_type; int mob_skill_use; int mob_count_rate; int quest_skill_learn; diff --git a/src/map/battle.t.hpp b/src/map/battle.t.hpp index e374298..f730cc5 100644 --- a/src/map/battle.t.hpp +++ b/src/map/battle.t.hpp @@ -25,6 +25,10 @@ ENUM_BITWISE_OPERATORS(BF) } using e::BF; +namespace e +{ +// not actually an enum, but put in the namespace to hide the operators +// from non-ADL. struct BCT { // former representation: @@ -56,6 +60,8 @@ constexpr bool operator == (BCT l, BCT r) { return l.lo == r.lo && l.mid == r.mid && l.classic == r.classic && l.level == r.level && l.unused == r.unused; } constexpr bool operator != (BCT l, BCT r) { return !(l == r); } +} // namespace e +using e::BCT; constexpr BCT BCT_NOENEMY = {0x00, 0x00, 0x0, 0x0, 0x00}; diff --git a/src/map/chrif.cpp b/src/map/chrif.cpp index aaa727e..ebed281 100644 --- a/src/map/chrif.cpp +++ b/src/map/chrif.cpp @@ -145,14 +145,17 @@ int chrif_connect(int fd) static int chrif_sendmap(int fd) { - int i; + int i = 0; WFIFOW(fd, 0) = 0x2afa; - for (i = 0; i < map_num; i++) - if (map[i].alias[0] != '\0') // [MouseJstr] map aliasing - memcpy(WFIFOP(fd, 4 + i * 16), map[i].alias, 16); - else - memcpy(WFIFOP(fd, 4 + i * 16), map[i].name, 16); + for (auto& pair : maps_db) + { + map_abstract *ma = pair.second.get(); + if (!ma->gat) + continue; + memcpy(WFIFOP(fd, 4 + i * 16), ma->name, 16); + i++; + } WFIFOW(fd, 2) = 4 + i * 16; WFIFOSET(fd, WFIFOW(fd, 2)); @@ -176,7 +179,7 @@ int chrif_recvmap(int fd) port = RFIFOW(fd, 8); for (i = 10, j = 0; i < RFIFOW(fd, 2); i += 16, j++) { - map_setipport((const char *)RFIFOP(fd, i), ip, port); + map_setipport(static_cast(RFIFOP(fd, i)), ip, port); // if (battle_config.etc_log) // PRINTF("recv map %d %s\n", j, RFIFOP(fd,i)); } @@ -241,7 +244,7 @@ int chrif_changemapserverack(int fd) pc_authfail(sd->fd); return 0; } - clif_changemapserver(sd, (const char *)RFIFOP(fd, 18), RFIFOW(fd, 34), + clif_changemapserver(sd, static_cast(RFIFOP(fd, 18)), RFIFOW(fd, 34), RFIFOW(fd, 36), in_addr{RFIFOL(fd, 38)}, RFIFOW(fd, 42)); return 0; @@ -989,9 +992,8 @@ void ladmin_itemfrob_c2(dumb_ptr bl, int source_id, int dest_id) case BL::MOB: { dumb_ptr mob = bl->as_mob(); - int i; - for (i = 0; i < mob->lootitem_count; i++) - FIX(mob->lootitem[i]); + for (struct item& itm : mob->lootitemv) + FIX(itm); break; } @@ -1017,10 +1019,11 @@ void ladmin_itemfrob(int fd) { int source_id = RFIFOL(fd, 2); int dest_id = RFIFOL(fd, 6); - dumb_ptr bl = (dumb_ptr) map_get_first_session(); + dumb_ptr bl = map_get_first_session(); // flooritems - map_foreachobject(std::bind(ladmin_itemfrob_c, ph::_1, source_id, dest_id), BL::NUL /* any object */); + map_foreachobject(std::bind(ladmin_itemfrob_c, ph::_1, source_id, dest_id), + BL::NUL /* any object */); // player characters (and, hopefully, mobs) while (bl->bl_next) @@ -1097,7 +1100,7 @@ void chrif_parse(int fd) case 0x2afd: pc_authok(RFIFOL(fd, 4), RFIFOL(fd, 8), static_cast(RFIFOL(fd, 12)), RFIFOW(fd, 16), - (const struct mmo_charstatus *) RFIFOP(fd, 18)); + static_cast(RFIFOP(fd, 18))); break; case 0x2afe: pc_authfail(RFIFOL(fd, 2)); @@ -1115,7 +1118,7 @@ void chrif_parse(int fd) chrif_changemapserverack(fd); break; case 0x2b09: - map_addchariddb(RFIFOL(fd, 2), (const char *)RFIFOP(fd, 6)); + map_addchariddb(RFIFOL(fd, 2), static_cast(RFIFOP(fd, 6))); break; case 0x2b0b: chrif_changedgm(fd); diff --git a/src/map/clif.cpp b/src/map/clif.cpp index fbba044..f20c887 100644 --- a/src/map/clif.cpp +++ b/src/map/clif.cpp @@ -203,9 +203,16 @@ static void clif_emotion_towards(dumb_ptr bl, dumb_ptr target, int type); + +enum class ChatType +{ + Party, + Whisper, + Global, +}; + static -char *clif_validate_chat(dumb_ptr sd, int type, - const char **message, size_t *message_len); +std::string clif_validate_chat(dumb_ptr sd, ChatType type); /*========================================== * clif_sendでSendWho::AREA*指定時用 @@ -337,13 +344,17 @@ int clif_send(const uint8_t *buf, int len, dumb_ptr bl, SendWho type case SendWho::AREA: case SendWho::AREA_WOS: map_foreachinarea(std::bind(clif_send_sub, ph::_1, buf, len, bl, type), - bl->bl_m, bl->bl_x - AREA_SIZE, bl->bl_y - AREA_SIZE, - bl->bl_x + AREA_SIZE, bl->bl_y + AREA_SIZE, BL::PC); + bl->bl_m, + bl->bl_x - AREA_SIZE, bl->bl_y - AREA_SIZE, + bl->bl_x + AREA_SIZE, bl->bl_y + AREA_SIZE, + BL::PC); break; case SendWho::AREA_CHAT_WOC: map_foreachinarea(std::bind(clif_send_sub, ph::_1, buf, len, bl, SendWho::AREA_CHAT_WOC), - bl->bl_m, bl->bl_x - (AREA_SIZE), bl->bl_y - (AREA_SIZE), - bl->bl_x + (AREA_SIZE), bl->bl_y + (AREA_SIZE), BL::PC); + bl->bl_m, + bl->bl_x - (AREA_SIZE), bl->bl_y - (AREA_SIZE), + bl->bl_x + (AREA_SIZE), bl->bl_y + (AREA_SIZE), + BL::PC); break; case SendWho::PARTY_AREA: // 同じ画面内の全パーティーメンバに送信 @@ -912,15 +923,15 @@ int clif_spawnpc(dumb_ptr sd) WBUFW(buf, 51) = 0; clif_send(buf, clif_parse_func_table[0x1d9].len, sd, SendWho::AREA_WOS); - if (map[sd->bl_m].flag.snow) + if (sd->bl_m->flag.snow) clif_specialeffect(sd, 162, 1); - if (map[sd->bl_m].flag.fog) + if (sd->bl_m->flag.fog) clif_specialeffect(sd, 233, 1); - if (map[sd->bl_m].flag.sakura) + if (sd->bl_m->flag.sakura) clif_specialeffect(sd, 163, 1); - if (map[sd->bl_m].flag.leaves) + if (sd->bl_m->flag.leaves) clif_specialeffect(sd, 333, 1); - if (map[sd->bl_m].flag.rain) + if (sd->bl_m->flag.rain) clif_specialeffect(sd, 161, 1); // clif_changelook_accessories(sd, NULL); @@ -1281,7 +1292,7 @@ int clif_scriptmes(dumb_ptr sd, int npcid, const char *mes) WFIFOW(fd, 0) = 0xb4; WFIFOW(fd, 2) = strlen(mes) + 9; WFIFOL(fd, 4) = npcid; - strcpy((char *)WFIFOP(fd, 8), mes); + strcpy(static_cast(WFIFOP(fd, 8)), mes); WFIFOSET(fd, WFIFOW(fd, 2)); return 0; @@ -1337,7 +1348,7 @@ int clif_scriptmenu(dumb_ptr sd, int npcid, const char *mes) WFIFOW(fd, 0) = 0xb7; WFIFOW(fd, 2) = strlen(mes) + 8; WFIFOL(fd, 4) = npcid; - strcpy((char *)WFIFOP(fd, 8), mes); + strcpy(static_cast(WFIFOP(fd, 8)), mes); WFIFOSET(fd, WFIFOW(fd, 2)); return 0; @@ -1469,7 +1480,7 @@ int clif_additem(dumb_ptr sd, int n, int amount, PickupFail fa WFIFOB(fd, 10) = sd->status.inventory[n].refine; if (sd->status.inventory[n].card[0] == 0x00ff || sd->status.inventory[n].card[0] == 0x00fe - || sd->status.inventory[n].card[0] == (short) 0xff00) + || sd->status.inventory[n].card[0] == static_cast(0xff00)) { WFIFOW(fd, 11) = sd->status.inventory[n].card[0]; WFIFOW(fd, 13) = sd->status.inventory[n].card[1]; @@ -1617,7 +1628,7 @@ int clif_equiplist(dumb_ptr sd) WFIFOB(fd, n * 20 + 15) = sd->status.inventory[i].refine; if (sd->status.inventory[i].card[0] == 0x00ff || sd->status.inventory[i].card[0] == 0x00fe - || sd->status.inventory[i].card[0] == (short) 0xff00) + || sd->status.inventory[i].card[0] == static_cast(0xff00)) { WFIFOW(fd, n * 20 + 16) = sd->status.inventory[i].card[0]; WFIFOW(fd, n * 20 + 18) = sd->status.inventory[i].card[1]; @@ -1742,7 +1753,7 @@ int clif_storageequiplist(dumb_ptr sd, struct storage *stor) WFIFOB(fd, n * 20 + 15) = stor->storage_[i].refine; if (stor->storage_[i].card[0] == 0x00ff || stor->storage_[i].card[0] == 0x00fe - || stor->storage_[i].card[0] == (short) 0xff00) + || stor->storage_[i].card[0] == static_cast(0xff00)) { WFIFOW(fd, n * 20 + 16) = stor->storage_[i].card[0]; WFIFOW(fd, n * 20 + 18) = stor->storage_[i].card[1]; @@ -2312,7 +2323,7 @@ int clif_traderequest(dumb_ptr sd, const char *name) fd = sd->fd; WFIFOW(fd, 0) = 0xe5; - strcpy((char *)WFIFOP(fd, 2), name); + strcpy(static_cast(WFIFOP(fd, 2)), name); WFIFOSET(fd, clif_parse_func_table[0xe5].len); return 0; @@ -2378,7 +2389,7 @@ int clif_tradeadditem(dumb_ptr sd, WFIFOB(fd, 10) = sd->status.inventory[index].refine; //refine if (sd->status.inventory[index].card[0] == 0x00ff || sd->status.inventory[index].card[0] == 0x00fe - || sd->status.inventory[index].card[0] == (short) 0xff00) + || sd->status.inventory[index].card[0] == static_cast(0xff00)) { WFIFOW(fd, 11) = sd->status.inventory[index].card[0]; //card (4w) WFIFOW(fd, 13) = sd->status.inventory[index].card[1]; //card (4w) @@ -2541,7 +2552,7 @@ int clif_storageitemadded(dumb_ptr sd, struct storage *stor, WFIFOB(fd, 12) = stor->storage_[index].refine; //refine if (stor->storage_[index].card[0] == 0x00ff || stor->storage_[index].card[0] == 0x00fe - || stor->storage_[index].card[0] == (short) 0xff00) + || stor->storage_[index].card[0] == static_cast(0xff00)) { WFIFOW(fd, 13) = stor->storage_[index].card[0]; //card (4w) WFIFOW(fd, 15) = stor->storage_[index].card[1]; //card (4w) @@ -3790,7 +3801,7 @@ void clif_parse_LoadEndAck(int, dumb_ptr sd) if (!battle_config.pk_mode) sd->pvp_timer.cancel(); - if (map[sd->bl_m].flag.pvp) + if (sd->bl_m->flag.pvp) { if (!battle_config.pk_mode) { @@ -3832,9 +3843,11 @@ void clif_parse_LoadEndAck(int, dumb_ptr sd) // clif_changelook_accessories(sd, NULL); - map_foreachinarea(std::bind(clif_getareachar, ph::_1, sd), sd->bl_m, sd->bl_x - AREA_SIZE, - sd->bl_y - AREA_SIZE, sd->bl_x + AREA_SIZE, - sd->bl_y + AREA_SIZE, BL::NUL); + map_foreachinarea(std::bind(clif_getareachar, ph::_1, sd), + sd->bl_m, + sd->bl_x - AREA_SIZE, sd->bl_y - AREA_SIZE, + sd->bl_x + AREA_SIZE, sd->bl_y + AREA_SIZE, + BL::NUL); } /*========================================== @@ -3998,7 +4011,7 @@ void clif_parse_GetCharNameRequest(int fd, dumb_ptr sd) case BL::NPC: memcpy(WFIFOP(fd, 6), bl->as_npc()->name, 24); { - char *start = (char *)WFIFOP(fd, 6); + char *start = static_cast(WFIFOP(fd, 6)); char *end = strchr(start, '#'); // [fate] elim hashed out/invisible names for the client if (end) while (*end) @@ -4038,52 +4051,41 @@ void clif_parse_GetCharNameRequest(int fd, dumb_ptr sd) static void clif_parse_GlobalMessage(int fd, dumb_ptr sd) { - int msg_len = RFIFOW(fd, 2) - 4; /* Header(2) + length(2). */ - size_t message_len = 0; - // sometimes uint8_t - char *buf = NULL; - const char *message = NULL; /* The message text only. */ - nullpo_retv(sd); - if (!(buf = clif_validate_chat(sd, 2, &message, &message_len))) + std::string mbuf = clif_validate_chat(sd, ChatType::Global); + if (mbuf.empty()) { clif_displaymessage(fd, "Your message could not be sent."); return; } - if (is_atcommand(fd, sd, message, 0)) //チャット禁止 - { - free(buf); + if (is_atcommand(fd, sd, mbuf.c_str(), 0)) return; - } - if (!magic_message(sd, buf, msg_len)) + if (!magic_message(sd, mbuf)) { /* Don't send chat that results in an automatic ban. */ - if (tmw_CheckChatSpam(sd, message)) + if (tmw_CheckChatSpam(sd, mbuf.c_str())) { - free(buf); clif_displaymessage(fd, "Your message could not be sent."); return; } /* It's not a spell/magic message, so send the message to others. */ - WBUFW(reinterpret_cast(buf), 0) = 0x8d; - WBUFW(reinterpret_cast(buf), 2) = msg_len + 8; /* Header(2) + length(2) + ID(4). */ - WBUFL(reinterpret_cast(buf), 4) = sd->bl_id; + uint8_t sendbuf[mbuf.size() + 8]; + WBUFW(sendbuf, 0) = 0x8d; + WBUFW(sendbuf, 2) = mbuf.size() + 8; /* Header(2) + length(2) + ID(4). */ + WBUFL(sendbuf, 4) = sd->bl_id; + memcpy(WBUFP(sendbuf, 8), mbuf.data(), mbuf.size()); - // evil multiuse buffer! - clif_send((const uint8_t *)buf, msg_len + 8, sd, SendWho::AREA_CHAT_WOC); + clif_send(sendbuf, mbuf.size() + 8, sd, SendWho::AREA_CHAT_WOC); } /* Send the message back to the speaker. */ memcpy(WFIFOP(fd, 0), RFIFOP(fd, 0), RFIFOW(fd, 2)); WFIFOW(fd, 0) = 0x8e; WFIFOSET(fd, WFIFOW(fd, 2)); - - free(buf); - return; } int clif_message(dumb_ptr bl, const char *msg) @@ -4290,29 +4292,25 @@ void clif_parse_Restart(int fd, dumb_ptr sd) static void clif_parse_Wis(int fd, dumb_ptr sd) { - size_t message_len = 0; - char *buf = NULL; - const char *message = NULL; /* The message text only. */ dumb_ptr dstsd = NULL; nullpo_retv(sd); - if (!(buf = clif_validate_chat(sd, 1, &message, &message_len))) + std::string mbuf = clif_validate_chat(sd, ChatType::Whisper); + if (mbuf.empty()) { clif_displaymessage(fd, "Your message could not be sent."); return; } - if (is_atcommand(fd, sd, message, 0)) + if (is_atcommand(fd, sd, mbuf.c_str(), 0)) { - free(buf); return; } /* Don't send chat that results in an automatic ban. */ - if (tmw_CheckChatSpam(sd, message)) + if (tmw_CheckChatSpam(sd, mbuf.c_str())) { - free(buf); clif_displaymessage(fd, "Your message could not be sent."); return; } @@ -4323,9 +4321,10 @@ void clif_parse_Wis(int fd, dumb_ptr sd) * conflict (for instance, "Test" versus "test"), the char-server must * settle the discrepancy. */ - if (!(dstsd = map_nick2sd((const char *)RFIFOP(fd, 4))) - || strcmp(dstsd->status.name, (const char *)RFIFOP(fd, 4)) != 0) - intif_wis_message(sd, (const char *)RFIFOP(fd, 4), message, RFIFOW(fd, 2) - 28); + const char *tname = static_cast(RFIFOP(fd, 4)); + if (!(dstsd = map_nick2sd(tname)) + || strcmp(dstsd->status.name, tname) != 0) + intif_wis_message(sd, tname, mbuf.c_str(), RFIFOW(fd, 2) - 28); else { /* Refuse messages addressed to self. */ @@ -4336,28 +4335,10 @@ void clif_parse_Wis(int fd, dumb_ptr sd) } else { - /* The target is ignoring all whispers. */ - if (dstsd->ignoreAll == 1) - /* Ignored by target. */ - clif_wis_end(fd, 2); - else { - int i; - size_t end = sizeof(dstsd->ignore) / sizeof(dstsd->ignore[0]); - - /* See if the source player is being ignored. */ - for (i = 0; i < end; ++i) - if (strcmp(dstsd->ignore[i].name, sd->status.name) == 0) - { - /* Ignored by target. */ - clif_wis_end(fd, 2); - break; - } - /* The player is not being ignored. */ - if (i == end) { - clif_wis_message(dstsd->fd, sd->status.name, message, + clif_wis_message(dstsd->fd, sd->status.name, mbuf.c_str(), RFIFOW(fd, 2) - 28); /* The whisper was sent successfully. */ clif_wis_end(fd, 0); @@ -4365,8 +4346,6 @@ void clif_parse_Wis(int fd, dumb_ptr sd) } } } - - free(buf); } /*========================================== @@ -4423,7 +4402,7 @@ void clif_parse_DropItem(int fd, dumb_ptr sd) clif_clearchar(sd, BeingRemoveWhy::DEAD); return; } - if (map[sd->bl_m].flag.no_player_drops) + if (sd->bl_m->flag.no_player_drops) { clif_displaymessage(sd->fd, "Can't drop items here."); return; @@ -4765,7 +4744,7 @@ void clif_parse_NpcStringInput(int fd, dumb_ptr sd) } if (len > 0) - strncpy(sd->npc_str, (const char *)RFIFOP(fd, 8), len); + strncpy(sd->npc_str, static_cast(RFIFOP(fd, 8)), len); sd->npc_str[len] = '\0'; map_scriptcont(sd, RFIFOL(fd, 4)); @@ -4851,7 +4830,7 @@ void clif_parse_CreateParty(int fd, dumb_ptr sd) if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, SkillID::NV_PARTY) >= 2) { - party_create(sd, (const char *)RFIFOP(fd, 2)); + party_create(sd, static_cast(RFIFOP(fd, 2))); } else clif_skill_fail(sd, SkillID::ONE, 0, 4); @@ -4909,7 +4888,7 @@ void clif_parse_LeaveParty(int, dumb_ptr sd) static void clif_parse_RemovePartyMember(int fd, dumb_ptr sd) { - party_removemember(sd, RFIFOL(fd, 2), (const char *)RFIFOP(fd, 6)); + party_removemember(sd, RFIFOL(fd, 2), static_cast(RFIFOP(fd, 6))); } /*========================================== @@ -4933,81 +4912,26 @@ void clif_parse_PartyChangeOption(int fd, dumb_ptr sd) static void clif_parse_PartyMessage(int fd, dumb_ptr sd) { - size_t message_len = 0; - char *buf = NULL; - const char *message = NULL; /* The message text only. */ - nullpo_retv(sd); - if (!(buf = clif_validate_chat(sd, 0, &message, &message_len))) + std::string mbuf = clif_validate_chat(sd, ChatType::Party); + if (mbuf.empty()) { clif_displaymessage(fd, "Your message could not be sent."); return; } - if (is_atcommand(fd, sd, message, 0)) //チャット禁止 - { - free(buf); + if (is_atcommand(fd, sd, mbuf.c_str(), 0)) return; - } /* Don't send chat that results in an automatic ban. */ - if (tmw_CheckChatSpam(sd, message)) + if (tmw_CheckChatSpam(sd, mbuf.c_str())) { - free(buf); clif_displaymessage(fd, "Your message could not be sent."); return; } - party_send_message(sd, message, RFIFOW(fd, 2) - 4); - free(buf); -} - -// 4144 wants this, but I don't like it ... -static -void clif_parse_PMIgnoreAll(int fd, dumb_ptr sd) -{ // Rewritten by [Yor] - //PRINTF("Ignore all: state: %d\n", RFIFOB(fd,2)); - if (RFIFOB(fd, 2) == 0) - { // S 00d0 len.B: 00 (/exall) deny all speech, 01 (/inall) allow all speech - WFIFOW(fd, 0) = 0x0d2; // R 00d2 .B .B: type: 0: deny, 1: allow, fail: 0: success, 1: fail - WFIFOB(fd, 2) = 0; - if (sd->ignoreAll == 0) - { - sd->ignoreAll = 1; - WFIFOB(fd, 3) = 0; // success - WFIFOSET(fd, clif_parse_func_table[0x0d2].len); - } - else - { - WFIFOB(fd, 3) = 1; // fail - WFIFOSET(fd, clif_parse_func_table[0x0d2].len); - clif_wis_message(fd, wisp_server_name, - "You already block everyone.", - strlen("You already block everyone.") + 1); - } - } - else - { - WFIFOW(fd, 0) = 0x0d2; // R 00d2 .B .B: type: 0: deny, 1: allow, fail: 0: success, 1: fail - WFIFOB(fd, 2) = 1; - if (sd->ignoreAll == 1) - { - sd->ignoreAll = 0; - WFIFOB(fd, 3) = 0; // success - WFIFOSET(fd, clif_parse_func_table[0x0d2].len); - } - else - { - WFIFOB(fd, 3) = 1; // fail - WFIFOSET(fd, clif_parse_func_table[0x0d2].len); - clif_wis_message(fd, wisp_server_name, - "You already allow everyone.", - strlen("You already allow everyone.") + 1); - } - } - - return; + party_send_message(sd, mbuf.c_str(), RFIFOW(fd, 2) - 4); } func_table clif_parse_func_table[0x0220] = @@ -5220,7 +5144,7 @@ func_table clif_parse_func_table[0x0220] = {0, 6, NULL, }, // 0x00cd {0, 2, NULL, }, // 0x00ce {0, 27, NULL, }, // 0x00cf - {0, 3, clif_parse_PMIgnoreAll, }, // 0x00d0 + {0, 3, NULL, }, // 0x00d0 {0, 4, NULL, }, // 0x00d1 {0, 4, NULL, }, // 0x00d2 {0, 2, NULL, }, // 0x00d3 @@ -5653,35 +5577,22 @@ void WARN_MALFORMED_MSG(dumb_ptr sd, const char *msg) * 0 for when the sender's name is not included (party chat) * 1 for when the target's name is included (whisper chat) * 2 for when the sender's name is given ("sender : text", public/guild chat) - * @param[out] message the message text (pointing within return value, or NULL) - * @param[out] message_len the length of the actual text, excluding NUL - * @return a dynamically allocated copy of the message, or NULL upon failure + * @return a dynamically allocated copy of the message, or empty string upon failure */ static -char *clif_validate_chat(dumb_ptr sd, int type, - const char **message, size_t *message_len) +std::string clif_validate_chat(dumb_ptr sd, ChatType type) { - int fd; - unsigned int buf_len; /* Actual message length. */ - unsigned int msg_len; /* Reported message length. */ - unsigned int min_len; /* Minimum message length. */ - size_t name_len; /* Sender's name length. */ - char *buf = NULL; /* Copy of actual message data. */ - - *message = NULL; - *message_len = 0; - - nullpo_retr(NULL, sd); + nullpo_retr(std::string(), sd); /* * Don't send chat in the period between the ban and the connection's * closure. */ - if (type < 0 || type > 2 || sd->auto_ban_info.in_progress) - return NULL; + if (sd->auto_ban_info.in_progress) + return std::string(); - fd = sd->fd; - msg_len = RFIFOW(fd, 2) - 4; - name_len = strlen(sd->status.name); + int fd = sd->fd; + size_t msg_len = RFIFOW(fd, 2) - 4; + size_t name_len = strlen(sd->status.name); /* * At least one character is required in all instances. * Notes for length checks: @@ -5692,33 +5603,42 @@ char *clif_validate_chat(dumb_ptr sd, int type, * For type 2, the message must be longer than the sender's name length * plus the length of the separator (" : "). */ - min_len = (type == 1) ? 24 : (type == 2) ? name_len + 3 : 0; + size_t min_len = + (type == ChatType::Whisper) ? 24 + : (type == ChatType::Global) ? name_len + 3 + : 0; /* The player just sent the header (2) and length (2) words. */ if (!msg_len) { WARN_MALFORMED_MSG(sd, "no message sent"); - return NULL; + return std::string(); } /* The client sent (or claims to have sent) an empty message. */ if (msg_len == min_len) { WARN_MALFORMED_MSG(sd, "empty message"); - return NULL; + return std::string(); } /* The protocol specifies that the target must be 24 bytes long. */ - if (type == 1 && msg_len < min_len) + if (type == ChatType::Whisper && msg_len < min_len) { /* Disallow malformed messages. */ clif_setwaitclose(fd); WARN_MALFORMED_MSG(sd, "illegal target name"); - return NULL; + return std::string(); } - const char *p = static_cast((type != 1) ? RFIFOP(fd, 4) : RFIFOP(fd, 28)); - buf_len = (type == 1) ? msg_len - min_len: msg_len; + const char *p = static_cast(RFIFOP(fd, 4)); + size_t buf_len = msg_len; + if (type == ChatType::Whisper) + { + p += 24; + buf_len -= 24; + } + const char *pend = p + buf_len; /* * The client attempted to exceed the maximum message length. @@ -5730,43 +5650,25 @@ char *clif_validate_chat(dumb_ptr sd, int type, if (buf_len >= battle_config.chat_maxline) { WARN_MALFORMED_MSG(sd, "exceeded maximum message length"); - return NULL; + return std::string(); } - /* We're leaving an extra eight bytes for public/global chat, 1 for NUL. */ - buf_len += (type == 2) ? 8 + 1 : 1; - - buf = (char *) malloc(buf_len); - memcpy((type != 2) ? buf : buf + 8, p, - (type != 2) ? buf_len - 1 : buf_len - 8 - 1); - buf[buf_len - 1] = '\0'; - p = (type != 2) ? buf : buf + 8; - - if (type != 2) - { - *message = buf; - /* Don't count the NUL. */ - *message_len = buf_len - 1; - } - else + if (type == ChatType::Global) { - const char *pos = NULL; - if (!(pos = strstr(p, " : ")) - || strncmp(p, sd->status.name, name_len) - || pos - p != name_len) + const char *pos = strstr(p, " : "); + if (!pos || pos != p + name_len || memcmp(p, sd->status.name, name_len)) { - free(buf); /* Disallow malformed/spoofed messages. */ clif_setwaitclose(fd); WARN_MALFORMED_MSG(sd, "spoofed name/invalid format"); - return NULL; + return std::string(); } /* Step beyond the separator. */ - *message = pos + 3; - /* Don't count the sender's name, the extra eight bytes, or the NUL. */ - *message_len = buf_len - min_len - 8 - 1; + p = pos + 3; } + std::string buf(p, pend); + return buf; } diff --git a/src/map/intif.cpp b/src/map/intif.cpp index 53ff80e..1010047 100644 --- a/src/map/intif.cpp +++ b/src/map/intif.cpp @@ -88,7 +88,7 @@ int intif_wis_message_to_gm(const char *Wisp_name, int min_gm_level, const char WFIFOW(char_fd, 0) = 0x3003; WFIFOW(char_fd, 2) = mes_len + 30; memcpy(WFIFOP(char_fd, 4), Wisp_name, 24); - WFIFOW(char_fd, 28) = (short) min_gm_level; + WFIFOW(char_fd, 28) = min_gm_level; memcpy(WFIFOP(char_fd, 30), mes, mes_len); WFIFOSET(char_fd, WFIFOW(char_fd, 2)); @@ -159,7 +159,7 @@ int intif_create_party(dumb_ptr sd, const char *name) WFIFOL(char_fd, 2) = sd->status.account_id; memcpy(WFIFOP(char_fd, 6), name, 24); memcpy(WFIFOP(char_fd, 30), sd->status.name, 24); - memcpy(WFIFOP(char_fd, 54), map[sd->bl_m].name, 16); + memcpy(WFIFOP(char_fd, 54), sd->bl_m->name, 16); WFIFOW(char_fd, 70) = sd->status.base_level; WFIFOSET(char_fd, 72); // if(battle_config.etc_log) @@ -191,7 +191,7 @@ int intif_party_addmember(int party_id, int account_id) WFIFOL(char_fd, 2) = party_id; WFIFOL(char_fd, 6) = account_id; memcpy(WFIFOP(char_fd, 10), sd->status.name, 24); - memcpy(WFIFOP(char_fd, 34), map[sd->bl_m].name, 16); + memcpy(WFIFOP(char_fd, 34), sd->bl_m->name, 16); WFIFOW(char_fd, 50) = sd->status.base_level; WFIFOSET(char_fd, 52); } @@ -230,7 +230,7 @@ int intif_party_changemap(dumb_ptr sd, int online) WFIFOW(char_fd, 0) = 0x3025; WFIFOL(char_fd, 2) = sd->status.party_id; WFIFOL(char_fd, 6) = sd->status.account_id; - memcpy(WFIFOP(char_fd, 10), map[sd->bl_m].name, 16); + memcpy(WFIFOP(char_fd, 10), sd->bl_m->name, 16); WFIFOB(char_fd, 26) = online; WFIFOW(char_fd, 27) = sd->status.base_level; WFIFOSET(char_fd, 29); @@ -273,7 +273,6 @@ static int intif_parse_WisMessage(int fd) { // rewritten by [Yor] dumb_ptr sd; - int i; if (battle_config.etc_log) PRINTF("intif_parse_wismessage: id: %d, from: %s, to: %s, message: '%s'\n", @@ -281,27 +280,14 @@ int intif_parse_WisMessage(int fd) static_cast(RFIFOP(fd, 8)), static_cast(RFIFOP(fd, 32)), static_cast(RFIFOP(fd, 56))); - sd = map_nick2sd((const char *)RFIFOP(fd, 32)); // Searching destination player - if (sd != NULL && strcmp(sd->status.name, (const char *)RFIFOP(fd, 32)) == 0) - { // exactly same name (inter-server have checked the name before) - // if player ignore all - if (sd->ignoreAll == 1) - intif_wis_replay(RFIFOL(fd, 4), 2); // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target - else + sd = map_nick2sd(static_cast(RFIFOP(fd, 32))); // Searching destination player + if (sd != NULL && strcmp(sd->status.name, static_cast(RFIFOP(fd, 32))) == 0) + { + // exactly same name (inter-server have checked the name before) { - const char *wisp_source = (const char *)RFIFOP(fd, 8); // speed up - // if player ignore the source character - for (i = 0; i < (sizeof(sd->ignore) / sizeof(sd->ignore[0])); - i++) - if (strcmp(sd->ignore[i].name, wisp_source) == 0) - { - intif_wis_replay(RFIFOL(fd, 4), 2); // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target - break; - } // if source player not found in ignore list - if (i == (sizeof(sd->ignore) / sizeof(sd->ignore[0]))) { - clif_wis_message(sd->fd, (const char *)RFIFOP(fd, 8), (const char *)RFIFOP(fd, 56), + clif_wis_message(sd->fd, static_cast(RFIFOP(fd, 8)), static_cast(RFIFOP(fd, 56)), RFIFOW(fd, 2) - 56); intif_wis_replay(RFIFOL(fd, 4), 0); // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target } @@ -322,7 +308,7 @@ int intif_parse_WisEnd(int fd) // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target PRINTF("intif_parse_wisend: player: %s, flag: %d\n", static_cast(RFIFOP(fd, 2)), RFIFOB(fd, 26)); - sd = map_nick2sd((const char *)RFIFOP(fd, 2)); + sd = map_nick2sd(static_cast(RFIFOP(fd, 2))); if (sd != NULL) clif_wis_end(sd->fd, RFIFOB(fd, 26)); @@ -336,19 +322,18 @@ int mapif_parse_WisToGM(int fd) // 0x3003/0x3803 .w .24B .w .?B int min_gm_level, len; char Wisp_name[24]; - char mbuf[255]; if (RFIFOW(fd, 2) - 30 <= 0) return 0; len = RFIFOW(fd, 2) - 30; - char *message = ((len) >= 255) ? (char *) malloc(len) : mbuf; + char message[len + 1]; - min_gm_level = (int) RFIFOW(fd, 28); + min_gm_level = RFIFOW(fd, 28); memcpy(Wisp_name, RFIFOP(fd, 4), 24); Wisp_name[23] = '\0'; memcpy(message, RFIFOP(fd, 30), len); - message[len - 1] = '\0'; + message[len] = '\0'; // information is sended to all online GM for (int i = 0; i < fd_max; i++) { @@ -361,9 +346,6 @@ int mapif_parse_WisToGM(int fd) strlen(message) + 1); } - if (message != mbuf) - free(message); - return 0; } @@ -457,7 +439,7 @@ int intif_parse_PartyCreated(int fd) if (battle_config.etc_log) PRINTF("intif: party created\n"); party_created(RFIFOL(fd, 2), RFIFOB(fd, 6), RFIFOL(fd, 7), - (const char *)RFIFOP(fd, 11)); + static_cast(RFIFOP(fd, 11))); return 0; } @@ -511,8 +493,8 @@ int intif_parse_PartyMemberLeaved(int fd) { if (battle_config.etc_log) PRINTF("intif: party member leaved %d %d %s\n", RFIFOL(fd, 2), - RFIFOL(fd, 6), (const char *)RFIFOP(fd, 10)); - party_member_leaved(RFIFOL(fd, 2), RFIFOL(fd, 6), (const char *)RFIFOP(fd, 10)); + RFIFOL(fd, 6), static_cast(RFIFOP(fd, 10))); + party_member_leaved(RFIFOL(fd, 2), RFIFOL(fd, 6), static_cast(RFIFOP(fd, 10))); return 0; } @@ -530,7 +512,7 @@ int intif_parse_PartyMove(int fd) { // if(battle_config.etc_log) // PRINTF("intif: party move %d %d %s %d %d\n",RFIFOL(fd,2),RFIFOL(fd,6),RFIFOP(fd,10),RFIFOB(fd,26),RFIFOW(fd,27)); - party_recv_movemap(RFIFOL(fd, 2), RFIFOL(fd, 6), (const char *)RFIFOP(fd, 10), + party_recv_movemap(RFIFOL(fd, 2), RFIFOL(fd, 6), static_cast(RFIFOP(fd, 10)), RFIFOB(fd, 26), RFIFOW(fd, 27)); return 0; } @@ -541,7 +523,7 @@ int intif_parse_PartyMessage(int fd) { // if(battle_config.etc_log) // PRINTF("intif_parse_PartyMessage: %s\n",RFIFOP(fd,12)); - party_recv_message(RFIFOL(fd, 4), RFIFOL(fd, 8), (const char *)RFIFOP(fd, 12), + party_recv_message(RFIFOL(fd, 4), RFIFOL(fd, 8), static_cast(RFIFOP(fd, 12)), RFIFOW(fd, 2) - 12); return 0; } @@ -581,7 +563,7 @@ int intif_parse(int fd) { case 0x3800: clif_GMmessage(NULL, - const_string((const char *)RFIFOP(fd, 4), + const_string(static_cast(RFIFOP(fd, 4)), (packet_len - 4) - 1), 0); break; case 0x3801: diff --git a/src/map/itemdb.cpp b/src/map/itemdb.cpp index f60dc53..147db91 100644 --- a/src/map/itemdb.cpp +++ b/src/map/itemdb.cpp @@ -367,10 +367,8 @@ int itemdb_read_noequip(void) static void itemdb_final(struct item_data *id) { - if (id->use_script) - free(const_cast(id->use_script)); - if (id->equip_script) - free(const_cast(id->equip_script)); + id->use_script.reset(); + id->equip_script.reset(); } void itemdb_reload(void) diff --git a/src/map/itemdb.hpp b/src/map/itemdb.hpp index 279c7a8..02da73a 100644 --- a/src/map/itemdb.hpp +++ b/src/map/itemdb.hpp @@ -27,8 +27,8 @@ struct item_data int elv; int wlv; int refine; - const ScriptCode *use_script; - const ScriptCode *equip_script; + std::unique_ptr use_script; + std::unique_ptr equip_script; struct { unsigned available:1; @@ -67,9 +67,9 @@ int itemdb_weight(int n) return itemdb_search(n)->weight; } inline -const ScriptCode *itemdb_equipscript(int n) +const ScriptBuffer *itemdb_equipscript(int n) { - return itemdb_search(n)->equip_script; + return itemdb_search(n)->equip_script.get(); } inline int itemdb_wlv(int n) diff --git a/src/map/magic-expr-eval.hpp b/src/map/magic-expr-eval.hpp index bc5ce6e..9c9591b 100644 --- a/src/map/magic-expr-eval.hpp +++ b/src/map/magic-expr-eval.hpp @@ -10,13 +10,13 @@ int magic_signature_check(const char *opname, const char *funname, const char *signature, int args_nr, val_t *args, int line, int column); -void magic_area_rect(int *m, int *x, int *y, int *width, int *height, - area_t *area); +void magic_area_rect(map_local **m, int *x, int *y, int *width, int *height, + area_t& area); #define ARGINT(x) args[x].v.v_int #define ARGDIR(x) args[x].v.v_dir #define ARGSTR(x) args[x].v.v_string -#define ARGENTITY(x) dumb_ptr(args[x].v.v_entity) +#define ARGENTITY(x) args[x].v.v_entity #define ARGLOCATION(x) args[x].v.v_location #define ARGAREA(x) args[x].v.v_area #define ARGSPELL(x) args[x].v.v_spell diff --git a/src/map/magic-expr.cpp b/src/map/magic-expr.cpp index c0eaf9f..7739847 100644 --- a/src/map/magic-expr.cpp +++ b/src/map/magic-expr.cpp @@ -16,7 +16,7 @@ #include "../poison.hpp" static -void free_area(area_t *area) +void free_area(dumb_ptr area) { if (!area) return; @@ -31,13 +31,13 @@ void free_area(area_t *area) break; } - free(area); + area.delete_(); } static -area_t *dup_area(area_t *area) +dumb_ptr dup_area(dumb_ptr area) { - area_t *retval = (area_t *)malloc(sizeof(area_t)); + dumb_ptr retval = dumb_ptr::make(); *retval = *area; switch (area->ty) @@ -60,7 +60,7 @@ void magic_copy_var(val_t *dest, val_t *src) switch (dest->ty) { case TYPE::STRING: - dest->v.v_string = strdup(dest->v.v_string); + dest->v.v_string = dest->v.v_string.dup(); break; case TYPE::AREA: dest->v.v_area = dup_area(dest->v.v_area); @@ -76,7 +76,7 @@ void magic_clear_var(val_t *v) switch (v->ty) { case TYPE::STRING: - free(v->v.v_string); + v->v.v_string.delete_(); break; case TYPE::AREA: free_area(v->v.v_area); @@ -139,12 +139,12 @@ void stringify(val_t *v, int within_op) break; case TYPE::ENTITY: - buf = show_entity(dumb_ptr(v->v.v_entity)); + buf = show_entity(v->v.v_entity); break; case TYPE::LOCATION: buf = STRPRINTF("<\"%s\", %d, %d>", - map[v->v.v_location.m].name, + v->v.v_location.m->name, v->v.v_location.x, v->v.v_location.y); break; @@ -161,7 +161,7 @@ void stringify(val_t *v, int within_op) case TYPE::INVOCATION: { dumb_ptr invocation_ = within_op - ? dumb_ptr(v->v.v_invocation) + ? v->v.v_invocation : map_id2bl(v->v.v_int)->as_spell(); buf = invocation_->spell->name; } @@ -173,7 +173,7 @@ void stringify(val_t *v, int within_op) return; } - v->v.v_string = strdup(buf.c_str()); + v->v.v_string = dumb_string::copys(buf); v->ty = TYPE::STRING; } @@ -189,18 +189,17 @@ void intify(val_t *v) } static -area_t *area_new(AREA ty) +dumb_ptr area_new(AREA ty) { - area_t *retval; - CREATE(retval, area_t, 1); + auto retval = dumb_ptr::make(); retval->ty = ty; return retval; } static -area_t *area_union(area_t *area, area_t *other_area) +dumb_ptr area_union(dumb_ptr area, dumb_ptr other_area) { - area_t *retval = area_new(AREA::UNION); + dumb_ptr retval = area_new(AREA::UNION); retval->a.a_union[0] = area; retval->a.a_union[1] = other_area; retval->size = area->size + other_area->size; /* Assume no overlap */ @@ -215,7 +214,7 @@ void make_area(val_t *v) { if (v->ty == TYPE::LOCATION) { - area_t *a = (area_t *)malloc(sizeof(area_t)); + auto a = dumb_ptr::make(); v->ty = TYPE::AREA; a->ty = AREA::LOCATION; a->a.a_loc = v->v.v_location; @@ -240,7 +239,7 @@ void make_spell(val_t *v) { if (v->ty == TYPE::INVOCATION) { - dumb_ptr invoc = dumb_ptr(v->v.v_invocation); + dumb_ptr invoc = v->v.v_invocation; //invoc = (dumb_ptr) map_id2bl(v->v.v_int); if (!invoc) v->ty = TYPE::FAIL; @@ -253,7 +252,7 @@ void make_spell(val_t *v) } static -int fun_add(env_t *, int, val_t *result, val_t *args) +int fun_add(dumb_ptr, val_t *result, const_array args) { if (ARG_TYPE(0) == TYPE::INT && ARG_TYPE(1) == TYPE::INT) { @@ -277,31 +276,29 @@ int fun_add(env_t *, int, val_t *result, val_t *args) stringify(&args[0], 1); stringify(&args[1], 1); /* Yes, we could speed this up. */ - RESULTSTR = - (char *) malloc(1 + strlen(ARGSTR(0)) + strlen(ARGSTR(1))); - strcpy(RESULTSTR, ARGSTR(0)); - strcat(RESULTSTR, ARGSTR(1)); + // ugh + RESULTSTR = dumb_string::copys(ARGSTR(0).str() + ARGSTR(1).str()); result->ty = TYPE::STRING; } return 0; } static -int fun_sub(env_t *, int, val_t *result, val_t *args) +int fun_sub(dumb_ptr, val_t *result, const_array args) { RESULTINT = ARGINT(0) - ARGINT(1); return 0; } static -int fun_mul(env_t *, int, val_t *result, val_t *args) +int fun_mul(dumb_ptr, val_t *result, const_array args) { RESULTINT = ARGINT(0) * ARGINT(1); return 0; } static -int fun_div(env_t *, int, val_t *result, val_t *args) +int fun_div(dumb_ptr, val_t *result, const_array args) { if (!ARGINT(1)) return 1; /* division by zero */ @@ -310,7 +307,7 @@ int fun_div(env_t *, int, val_t *result, val_t *args) } static -int fun_mod(env_t *, int, val_t *result, val_t *args) +int fun_mod(dumb_ptr, val_t *result, const_array args) { if (!ARGINT(1)) return 1; /* division by zero */ @@ -319,41 +316,42 @@ int fun_mod(env_t *, int, val_t *result, val_t *args) } static -int fun_or(env_t *, int, val_t *result, val_t *args) +int fun_or(dumb_ptr, val_t *result, const_array args) { RESULTINT = ARGINT(0) || ARGINT(1); return 0; } static -int fun_and(env_t *, int, val_t *result, val_t *args) +int fun_and(dumb_ptr, val_t *result, const_array args) { RESULTINT = ARGINT(0) && ARGINT(1); return 0; } static -int fun_not(env_t *, int, val_t *result, val_t *args) +int fun_not(dumb_ptr, val_t *result, const_array args) { RESULTINT = !ARGINT(0); return 0; } static -int fun_neg(env_t *, int, val_t *result, val_t *args) +int fun_neg(dumb_ptr, val_t *result, const_array args) { RESULTINT = ~ARGINT(0); return 0; } static -int fun_gte(env_t *, int, val_t *result, val_t *args) +int fun_gte(dumb_ptr, val_t *result, const_array args) { if (ARG_TYPE(0) == TYPE::STRING || ARG_TYPE(1) == TYPE::STRING) { stringify(&args[0], 1); stringify(&args[1], 1); - RESULTINT = strcmp(ARGSTR(0), ARGSTR(1)) >= 0; + using namespace operators; + RESULTINT = ARGSTR(0) >= ARGSTR(1); } else { @@ -365,13 +363,14 @@ int fun_gte(env_t *, int, val_t *result, val_t *args) } static -int fun_gt(env_t *, int, val_t *result, val_t *args) +int fun_gt(dumb_ptr, val_t *result, const_array args) { if (ARG_TYPE(0) == TYPE::STRING || ARG_TYPE(1) == TYPE::STRING) { stringify(&args[0], 1); stringify(&args[1], 1); - RESULTINT = strcmp(ARGSTR(0), ARGSTR(1)) > 0; + using namespace operators; + RESULTINT = ARGSTR(0) > ARGSTR(1); } else { @@ -383,13 +382,14 @@ int fun_gt(env_t *, int, val_t *result, val_t *args) } static -int fun_eq(env_t *, int, val_t *result, val_t *args) +int fun_eq(dumb_ptr, val_t *result, const_array args) { if (ARG_TYPE(0) == TYPE::STRING || ARG_TYPE(1) == TYPE::STRING) { stringify(&args[0], 1); stringify(&args[1], 1); - RESULTINT = strcmp(ARGSTR(0), ARGSTR(1)) == 0; + using namespace operators; + RESULTINT = ARGSTR(0) == ARGSTR(1); } else if (ARG_TYPE(0) == TYPE::DIR && ARG_TYPE(1) == TYPE::DIR) RESULTINT = ARGDIR(0) == ARGDIR(1); @@ -415,56 +415,56 @@ int fun_eq(env_t *, int, val_t *result, val_t *args) } static -int fun_bitand(env_t *, int, val_t *result, val_t *args) +int fun_bitand(dumb_ptr, val_t *result, const_array args) { RESULTINT = ARGINT(0) & ARGINT(1); return 0; } static -int fun_bitor(env_t *, int, val_t *result, val_t *args) +int fun_bitor(dumb_ptr, val_t *result, const_array args) { RESULTINT = ARGINT(0) | ARGINT(1); return 0; } static -int fun_bitxor(env_t *, int, val_t *result, val_t *args) +int fun_bitxor(dumb_ptr, val_t *result, const_array args) { RESULTINT = ARGINT(0) ^ ARGINT(1); return 0; } static -int fun_bitshl(env_t *, int, val_t *result, val_t *args) +int fun_bitshl(dumb_ptr, val_t *result, const_array args) { RESULTINT = ARGINT(0) << ARGINT(1); return 0; } static -int fun_bitshr(env_t *, int, val_t *result, val_t *args) +int fun_bitshr(dumb_ptr, val_t *result, const_array args) { RESULTINT = ARGINT(0) >> ARGINT(1); return 0; } static -int fun_max(env_t *, int, val_t *result, val_t *args) +int fun_max(dumb_ptr, val_t *result, const_array args) { RESULTINT = max(ARGINT(0), ARGINT(1)); return 0; } static -int fun_min(env_t *, int, val_t *result, val_t *args) +int fun_min(dumb_ptr, val_t *result, const_array args) { RESULTINT = min(ARGINT(0), ARGINT(1)); return 0; } static -int fun_if_then_else(env_t *, int, val_t *result, val_t *args) +int fun_if_then_else(dumb_ptr, val_t *result, const_array args) { if (ARGINT(0)) magic_copy_var(result, &args[1]); @@ -473,9 +473,10 @@ int fun_if_then_else(env_t *, int, val_t *result, val_t *args) return 0; } -void magic_area_rect(int *m, int *x, int *y, int *width, int *height, - area_t *area) +void magic_area_rect(map_local **m, int *x, int *y, int *width, int *height, + area_t& area_) { + area_t *area = &area_; // diff hack switch (area->ty) { case AREA::UNION: @@ -547,7 +548,7 @@ void magic_area_rect(int *m, int *x, int *y, int *width, int *height, } } -int magic_location_in_area(int m, int x, int y, area_t *area) +int magic_location_in_area(map_local *m, int x, int y, dumb_ptr area) { switch (area->ty) { @@ -558,9 +559,9 @@ int magic_location_in_area(int m, int x, int y, area_t *area) case AREA::RECT: case AREA::BAR: { - int am; + map_local *am; int ax, ay, awidth, aheight; - magic_area_rect(&am, &ax, &ay, &awidth, &aheight, area); + magic_area_rect(&am, &ax, &ay, &awidth, &aheight, *area); return (am == m && (x >= ax) && (y >= ay) && (x < ax + awidth) && (y < ay + aheight)); @@ -572,7 +573,7 @@ int magic_location_in_area(int m, int x, int y, area_t *area) } static -int fun_is_in(env_t *, int, val_t *result, val_t *args) +int fun_is_in(dumb_ptr, val_t *result, const_array args) { RESULTINT = magic_location_in_area(ARGLOCATION(0).m, ARGLOCATION(0).x, @@ -581,7 +582,7 @@ int fun_is_in(env_t *, int, val_t *result, val_t *args) } static -int fun_skill(env_t *, int, val_t *result, val_t *args) +int fun_skill(dumb_ptr, val_t *result, const_array args) { if (ENTITY_TYPE(0) != BL::PC // don't convert to enum until after the range check @@ -599,7 +600,7 @@ int fun_skill(env_t *, int, val_t *result, val_t *args) } static -int fun_has_shroud(env_t *, int, val_t *result, val_t *args) +int fun_has_shroud(dumb_ptr, val_t *result, const_array args) { RESULTINT = (ENTITY_TYPE(0) == BL::PC && ARGPC(0)->state.shroud_active); return 0; @@ -607,7 +608,7 @@ int fun_has_shroud(env_t *, int, val_t *result, val_t *args) #define BATTLE_GETTER(name) \ static \ -int fun_get_##name(env_t *, int, val_t *result, val_t *args) \ +int fun_get_##name(dumb_ptr, val_t *result, const_array args) \ { \ RESULTINT = battle_get_##name(ARGENTITY(0)); \ return 0; \ @@ -625,7 +626,7 @@ BATTLE_GETTER(mdef) BATTLE_GETTER(def) BATTLE_GETTER(max_hp) static -int fun_get_dir(env_t *, int, val_t *result, val_t *args) +int fun_get_dir(dumb_ptr, val_t *result, const_array args) { RESULTDIR = battle_get_dir(ARGENTITY(0)); return 0; @@ -633,7 +634,7 @@ int fun_get_dir(env_t *, int, val_t *result, val_t *args) #define MMO_GETTER(name) \ static \ -int fun_get_##name(env_t *, int, val_t *result, val_t *args) \ +int fun_get_##name(dumb_ptr, val_t *result, const_array args) \ { \ if (ENTITY_TYPE(0) == BL::PC) \ RESULTINT = ARGPC(0)->status.name; \ @@ -646,21 +647,21 @@ MMO_GETTER(sp) MMO_GETTER(max_sp) static -int fun_name_of(env_t *, int, val_t *result, val_t *args) +int fun_name_of(dumb_ptr, val_t *result, const_array args) { if (ARG_TYPE(0) == TYPE::ENTITY) { - RESULTSTR = strdup(show_entity(ARGENTITY(0))); + RESULTSTR = dumb_string::copy(show_entity(ARGENTITY(0))); return 0; } else if (ARG_TYPE(0) == TYPE::SPELL) { - RESULTSTR = strdup(ARGSPELL(0)->name); + RESULTSTR = dumb_string::copys(ARGSPELL(0)->name); return 0; } else if (ARG_TYPE(0) == TYPE::INVOCATION) { - RESULTSTR = strdup(ARGINVOCATION(0)->spell->name); + RESULTSTR = dumb_string::copys(ARGINVOCATION(0)->spell->name); return 0; } return 1; @@ -668,7 +669,7 @@ int fun_name_of(env_t *, int, val_t *result, val_t *args) /* [Freeyorp] I'm putting this one in as name_of seems to have issues with summoned or spawned mobs. */ static -int fun_mob_id(env_t *, int, val_t *result, val_t *args) +int fun_mob_id(dumb_ptr, val_t *result, const_array args) { if (ENTITY_TYPE(0) != BL::MOB) return 1; @@ -693,14 +694,14 @@ void COPY_LOCATION(location_t& dest, block_list& src) } static -int fun_location(env_t *, int, val_t *result, val_t *args) +int fun_location(dumb_ptr, val_t *result, const_array args) { COPY_LOCATION(RESULTLOCATION, *(ARGENTITY(0))); return 0; } static -int fun_random(env_t *, int, val_t *result, val_t *args) +int fun_random(dumb_ptr, val_t *result, const_array args) { int delta = ARGINT(0); if (delta < 0) @@ -718,7 +719,7 @@ int fun_random(env_t *, int, val_t *result, val_t *args) } static -int fun_random_dir(env_t *, int, val_t *result, val_t *args) +int fun_random_dir(dumb_ptr, val_t *result, const_array args) { if (ARGINT(0)) RESULTDIR = random_::choice({DIR::S, DIR::SW, DIR::W, DIR::NW, DIR::N, DIR::NE, DIR::E, DIR::SE}); @@ -728,14 +729,14 @@ int fun_random_dir(env_t *, int, val_t *result, val_t *args) } static -int fun_hash_entity(env_t *, int, val_t *result, val_t *args) +int fun_hash_entity(dumb_ptr, val_t *result, const_array args) { RESULTINT = ARGENTITY(0)->bl_id; return 0; } int // ret -1: not a string, ret 1: no such item, ret 0: OK -magic_find_item(val_t *args, int index, struct item *item, int *stackable) +magic_find_item(const_array args, int index, struct item *item, int *stackable) { struct item_data *item_data; int must_add_sequentially; @@ -743,7 +744,7 @@ magic_find_item(val_t *args, int index, struct item *item, int *stackable) if (ARG_TYPE(index) == TYPE::INT) item_data = itemdb_exists(ARGINT(index)); else if (ARG_TYPE(index) == TYPE::STRING) - item_data = itemdb_searchname(ARGSTR(index)); + item_data = itemdb_searchname(ARGSTR(index).c_str()); else return -1; @@ -768,7 +769,7 @@ magic_find_item(val_t *args, int index, struct item *item, int *stackable) } static -int fun_count_item(env_t *, int, val_t *result, val_t *args) +int fun_count_item(dumb_ptr, val_t *result, const_array args) { dumb_ptr chr = (ENTITY_TYPE(0) == BL::PC) ? ARGPC(0) : NULL; int stackable; @@ -784,7 +785,7 @@ int fun_count_item(env_t *, int, val_t *result, val_t *args) } static -int fun_is_equipped(env_t *, int, val_t *result, val_t *args) +int fun_is_equipped(dumb_ptr, val_t *result, const_array args) { dumb_ptr chr = (ENTITY_TYPE(0) == BL::PC) ? ARGPC(0) : NULL; int stackable; @@ -810,33 +811,33 @@ int fun_is_equipped(env_t *, int, val_t *result, val_t *args) } static -int fun_is_married(env_t *, int, val_t *result, val_t *args) +int fun_is_married(dumb_ptr, val_t *result, const_array args) { RESULTINT = (ENTITY_TYPE(0) == BL::PC && ARGPC(0)->status.partner_id); return 0; } static -int fun_is_dead(env_t *, int, val_t *result, val_t *args) +int fun_is_dead(dumb_ptr, val_t *result, const_array args) { RESULTINT = (ENTITY_TYPE(0) == BL::PC && pc_isdead(ARGPC(0))); return 0; } static -int fun_is_pc(env_t *, int, val_t *result, val_t *args) +int fun_is_pc(dumb_ptr, val_t *result, const_array args) { RESULTINT = (ENTITY_TYPE(0) == BL::PC); return 0; } static -int fun_partner(env_t *, int, val_t *result, val_t *args) +int fun_partner(dumb_ptr, val_t *result, const_array args) { if (ENTITY_TYPE(0) == BL::PC && ARGPC(0)->status.partner_id) { RESULTENTITY = - map_nick2sd(map_charid2nick(ARGPC(0)->status.partner_id)).operator->(); + map_nick2sd(map_charid2nick(ARGPC(0)->status.partner_id)); return 0; } else @@ -844,14 +845,14 @@ int fun_partner(env_t *, int, val_t *result, val_t *args) } static -int fun_awayfrom(env_t *, int, val_t *result, val_t *args) +int fun_awayfrom(dumb_ptr, val_t *result, const_array args) { location_t *loc = &ARGLOCATION(0); int dx = dirx[ARGDIR(1)]; int dy = diry[ARGDIR(1)]; int distance = ARGINT(2); while (distance-- - && !bool(read_gat(loc->m, loc->x + dx, loc->y + dy) + && !bool(read_gatp(loc->m, loc->x + dx, loc->y + dy) & MapCell::UNWALKABLE)) { loc->x += dx; @@ -863,28 +864,28 @@ int fun_awayfrom(env_t *, int, val_t *result, val_t *args) } static -int fun_failed(env_t *, int, val_t *result, val_t *args) +int fun_failed(dumb_ptr, val_t *result, const_array args) { RESULTINT = ARG_TYPE(0) == TYPE::FAIL; return 0; } static -int fun_npc(env_t *, int, val_t *result, val_t *args) +int fun_npc(dumb_ptr, val_t *result, const_array args) { - RESULTENTITY = npc_name2id(ARGSTR(0)).operator->(); + RESULTENTITY = npc_name2id(ARGSTR(0).c_str()); return RESULTENTITY == NULL; } static -int fun_pc(env_t *, int, val_t *result, val_t *args) +int fun_pc(dumb_ptr, val_t *result, const_array args) { - RESULTENTITY = map_nick2sd(ARGSTR(0)).operator->(); + RESULTENTITY = map_nick2sd(ARGSTR(0).c_str()); return RESULTENTITY == NULL; } static -int fun_distance(env_t *, int, val_t *result, val_t *args) +int fun_distance(dumb_ptr, val_t *result, const_array args) { if (ARGLOCATION(0).m != ARGLOCATION(1).m) RESULTINT = 0x7fffffff; @@ -895,7 +896,7 @@ int fun_distance(env_t *, int, val_t *result, val_t *args) } static -int fun_rdistance(env_t *, int, val_t *result, val_t *args) +int fun_rdistance(dumb_ptr, val_t *result, const_array args) { if (ARGLOCATION(0).m != ARGLOCATION(1).m) RESULTINT = 0x7fffffff; @@ -903,15 +904,15 @@ int fun_rdistance(env_t *, int, val_t *result, val_t *args) { int dx = ARGLOCATION(0).x - ARGLOCATION(1).x; int dy = ARGLOCATION(0).y - ARGLOCATION(1).y; - RESULTINT = (int)(sqrt((dx * dx) + (dy * dy))); + RESULTINT = static_cast(sqrt((dx * dx) + (dy * dy))); } return 0; } static -int fun_anchor(env_t *env, int, val_t *result, val_t *args) +int fun_anchor(dumb_ptr env, val_t *result, const_array args) { - teleport_anchor_t *anchor = magic_find_anchor(ARGSTR(0)); + dumb_ptr anchor = magic_find_anchor(ARGSTR(0).str()); if (!anchor) return 1; @@ -929,7 +930,7 @@ int fun_anchor(env_t *env, int, val_t *result, val_t *args) } static -int fun_line_of_sight(env_t *, int, val_t *result, val_t *args) +int fun_line_of_sight(dumb_ptr, val_t *result, const_array args) { block_list e1, e2; @@ -941,7 +942,7 @@ int fun_line_of_sight(env_t *, int, val_t *result, val_t *args) return 0; } -void magic_random_location(location_t *dest, area_t *area) +void magic_random_location(location_t *dest, dumb_ptr area) { switch (area->ty) { @@ -958,8 +959,9 @@ void magic_random_location(location_t *dest, area_t *area) case AREA::RECT: case AREA::BAR: { - int m, x, y, w, h; - magic_area_rect(&m, &x, &y, &w, &h, area); + map_local *m; + int x, y, w, h; + magic_area_rect(&m, &x, &y, &w, &h, *area); if (w <= 1) w = 1; @@ -984,27 +986,27 @@ void magic_random_location(location_t *dest, area_t *area) } static -int fun_pick_location(env_t *, int, val_t *result, val_t *args) +int fun_pick_location(dumb_ptr, val_t *result, const_array args) { magic_random_location(&result->v.v_location, ARGAREA(0)); return 0; } static -int fun_read_script_int(env_t *, int, val_t *result, val_t *args) +int fun_read_script_int(dumb_ptr, val_t *result, const_array args) { dumb_ptr subject_p = ARGENTITY(0); - char *var_name = ARGSTR(1); + dumb_string var_name = ARGSTR(1); if (subject_p->bl_type != BL::PC) return 1; - RESULTINT = pc_readglobalreg(subject_p->as_player(), var_name); + RESULTINT = pc_readglobalreg(subject_p->as_player(), var_name.c_str()); return 0; } static -int fun_rbox(env_t *, int, val_t *result, val_t *args) +int fun_rbox(dumb_ptr, val_t *result, const_array args) { location_t loc = ARGLOCATION(0); int radius = ARGINT(1); @@ -1020,7 +1022,7 @@ int fun_rbox(env_t *, int, val_t *result, val_t *args) } static -int fun_running_status_update(env_t *, int, val_t *result, val_t *args) +int fun_running_status_update(dumb_ptr, val_t *result, const_array args) { if (ENTITY_TYPE(0) != BL::PC && ENTITY_TYPE(0) != BL::MOB) return 1; @@ -1031,66 +1033,67 @@ int fun_running_status_update(env_t *, int, val_t *result, val_t *args) } static -int fun_status_option(env_t *, int, val_t *result, val_t *args) +int fun_status_option(dumb_ptr, val_t *result, const_array args) { RESULTINT = (bool((ARGPC(0))->status.option & static_cast