From b25b586dccd22569d119dd50590dbd9db2181819 Mon Sep 17 00:00:00 2001 From: Zach Toogood Date: Tue, 18 Mar 2025 10:27:50 +0000 Subject: [PATCH 1/2] Core: Replace socket.cpp with ASIO --- src/common/CMakeLists.txt | 2 - src/common/ipp.h | 31 ++- src/common/kernel.cpp | 7 +- src/common/kernel.h | 3 +- src/common/logging.h | 2 +- src/common/socket.cpp | 291 -------------------- src/common/socket.h | 179 ------------ src/common/utils.h | 13 + src/login/auth_session.cpp | 1 - src/login/login_helpers.h | 2 +- src/map/CMakeLists.txt | 2 + src/map/instance_loader.h | 1 - src/map/ipc_client.h | 2 +- src/map/items/item_linkshell.cpp | 1 - src/map/map_session.cpp | 5 + src/map/map_session.h | 2 + src/map/map_session_container.cpp | 1 - src/map/packet_system.cpp | 2 +- src/map/packets/action.cpp | 2 +- src/map/packets/auction_house.cpp | 1 - src/map/packets/basic.h | 2 +- src/map/packets/bazaar_check.cpp | 2 - src/map/packets/bazaar_close.cpp | 2 - src/map/packets/bazaar_confirmation.cpp | 2 - src/map/packets/bazaar_item.cpp | 1 - src/map/packets/bazaar_message.cpp | 2 - src/map/packets/bazaar_purchase.cpp | 2 - src/map/packets/blacklist_edit_response.cpp | 2 - src/map/packets/campaign_map.cpp | 2 - src/map/packets/caught_fish.cpp | 2 +- src/map/packets/caught_monster.cpp | 2 +- src/map/packets/change_music.cpp | 2 - src/map/packets/char_abilities.cpp | 2 - src/map/packets/char_appearance.cpp | 2 - src/map/packets/char_check.cpp | 1 - src/map/packets/char_emote_list.cpp | 2 +- src/map/packets/char_equip.cpp | 2 - src/map/packets/char_health.cpp | 2 - src/map/packets/char_job_extra.cpp | 2 - src/map/packets/char_jobs.cpp | 2 - src/map/packets/char_mounts.cpp | 2 - src/map/packets/char_recast.cpp | 1 - src/map/packets/char_skills.cpp | 1 - src/map/packets/char_spells.cpp | 2 - src/map/packets/char_stats.cpp | 1 - src/map/packets/char_status.cpp | 2 +- src/map/packets/char_sync.cpp | 2 - src/map/packets/char_update.cpp | 2 - src/map/packets/chat_message.cpp | 2 +- src/map/packets/chocobo_digging.cpp | 2 - src/map/packets/conquest_map.cpp | 2 - src/map/packets/cs_position.cpp | 2 - src/map/packets/delivery_box.cpp | 2 - src/map/packets/entity_animation.cpp | 2 - src/map/packets/entity_enable_list.cpp | 2 +- src/map/packets/entity_set_name.cpp | 2 +- src/map/packets/entity_update.cpp | 1 - src/map/packets/entity_visual.cpp | 2 - src/map/packets/event.cpp | 2 - src/map/packets/event_string.cpp | 2 - src/map/packets/event_update.cpp | 4 +- src/map/packets/event_update_string.cpp | 2 - src/map/packets/fish_ranking.cpp | 1 - src/map/packets/fishing.cpp | 2 - src/map/packets/furniture_interact.cpp | 1 - src/map/packets/guild_menu.cpp | 1 - src/map/packets/guild_menu_buy.cpp | 2 - src/map/packets/guild_menu_buy_update.cpp | 2 - src/map/packets/guild_menu_sell.cpp | 2 - src/map/packets/guild_menu_sell_update.cpp | 2 - src/map/packets/independent_animation.cpp | 2 +- src/map/packets/instance_entry.cpp | 1 - src/map/packets/inventory_assign.cpp | 2 - src/map/packets/inventory_finish.cpp | 2 - src/map/packets/inventory_item.cpp | 1 - src/map/packets/inventory_modify.cpp | 2 - src/map/packets/inventory_size.cpp | 4 +- src/map/packets/jobpoint_details.cpp | 2 - src/map/packets/jobpoint_update.cpp | 2 - src/map/packets/key_items.cpp | 2 - src/map/packets/linkshell_equip.cpp | 2 - src/map/packets/linkshell_message.cpp | 2 - src/map/packets/lock_on.cpp | 2 - src/map/packets/macroequipset.cpp | 1 - src/map/packets/menu_config.cpp | 2 - src/map/packets/menu_jobpoints.cpp | 2 - src/map/packets/menu_merit.cpp | 4 +- src/map/packets/menu_mog.cpp | 2 - src/map/packets/menu_raisetractor.cpp | 4 +- src/map/packets/menu_unity.cpp | 2 - src/map/packets/merit_points_categories.cpp | 2 - src/map/packets/message_basic.cpp | 2 - src/map/packets/message_combat.cpp | 2 - src/map/packets/message_special.cpp | 1 - src/map/packets/message_standard.cpp | 2 - src/map/packets/message_system.cpp | 2 - src/map/packets/message_text.cpp | 4 +- src/map/packets/monipulator1.cpp | 1 - src/map/packets/monipulator2.cpp | 1 - src/map/packets/objective_utility.cpp | 2 +- src/map/packets/party_define.cpp | 2 - src/map/packets/party_invite.cpp | 2 - src/map/packets/party_map.cpp | 2 - src/map/packets/party_member_update.cpp | 2 - src/map/packets/party_search.cpp | 2 - src/map/packets/pet_sync.cpp | 1 - src/map/packets/position.cpp | 4 +- src/map/packets/quest_mission_log.cpp | 2 - src/map/packets/release.cpp | 4 +- src/map/packets/roe_questlog.cpp | 2 - src/map/packets/roe_sparkupdate.cpp | 2 - src/map/packets/roe_update.cpp | 2 - src/map/packets/send_blacklist.cpp | 2 - src/map/packets/server_ip.cpp | 4 +- src/map/packets/server_message.cpp | 1 - src/map/packets/shop_appraise.cpp | 2 - src/map/packets/shop_buy.cpp | 2 - src/map/packets/shop_items.cpp | 2 - src/map/packets/shop_menu.cpp | 4 +- src/map/packets/synth_animation.cpp | 4 +- src/map/packets/synth_message.cpp | 4 +- src/map/packets/synth_result.cpp | 4 +- src/map/packets/synth_suggestion.cpp | 1 - src/map/packets/trade_action.cpp | 2 - src/map/packets/trade_item.cpp | 2 - src/map/packets/trade_request.cpp | 2 - src/map/packets/trade_update.cpp | 1 - src/map/packets/treasure_lot_item.cpp | 5 +- src/map/packets/wide_scan.cpp | 3 +- src/map/packets/wide_scan_track.cpp | 3 +- src/map/packets/world_pass.cpp | 3 +- src/map/packets/zone_visited.cpp | 3 +- src/map/pch.h | 2 +- src/map/utils/charutils.cpp | 1 - src/map/utils/synthutils.cpp | 1 - src/map/zone.cpp | 2 +- src/search/CMakeLists.txt | 4 +- src/search/packets/auction_history.cpp | 2 +- src/search/packets/auction_list.cpp | 2 +- src/search/packets/linkshell_list.cpp | 1 - src/search/packets/party_list.cpp | 1 - src/search/packets/search_comment.cpp | 1 - src/search/packets/search_list.cpp | 1 - src/search/search.h | 2 +- src/search/search_handler.cpp | 3 +- src/world/CMakeLists.txt | 4 +- src/world/ipc_server.h | 1 - 147 files changed, 96 insertions(+), 718 deletions(-) delete mode 100644 src/common/socket.cpp delete mode 100644 src/common/socket.h diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 41f0ef76dda..877d8011e3f 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -29,8 +29,6 @@ set(COMMON_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/mmo.h ${CMAKE_CURRENT_SOURCE_DIR}/settings.cpp ${CMAKE_CURRENT_SOURCE_DIR}/settings.h - ${CMAKE_CURRENT_SOURCE_DIR}/socket.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/socket.h ${CMAKE_CURRENT_SOURCE_DIR}/sql.cpp ${CMAKE_CURRENT_SOURCE_DIR}/sql.h ${CMAKE_CURRENT_SOURCE_DIR}/string.h diff --git a/src/common/ipp.h b/src/common/ipp.h index 2de1dc29e81..086c3569002 100644 --- a/src/common/ipp.h +++ b/src/common/ipp.h @@ -23,11 +23,40 @@ #include "cbasetypes.h" #include "logging.h" -#include "socket.h" #include #include +#include +#include +#include + +#include + +#ifdef _WIN32 +#include +#include +#include +#else // NOT _WIN32 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#endif // _WIN32 + +#include +#include +#include +#include + auto ip2str(uint32 ip) -> std::string; auto str2ip(const std::string& ip_str) -> uint32; auto sockaddr2netip(const sockaddr_in& addr) -> uint32; diff --git a/src/common/kernel.cpp b/src/common/kernel.cpp index 2f1e1aac24a..85873d47a70 100644 --- a/src/common/kernel.cpp +++ b/src/common/kernel.cpp @@ -25,7 +25,7 @@ #include "common/logging.h" #include "common/lua.h" #include "common/settings.h" -#include "common/socket.h" + #include "common/taskmgr.h" #include "common/timer.h" #include "common/version.h" @@ -242,11 +242,8 @@ int main(int argc, char** argv) usercheck(); - socket_init(); - do_init(argc, argv); - fd_set rfd = {}; { // Main runtime cycle duration next = std::chrono::milliseconds(200); @@ -289,7 +286,7 @@ int main(int argc, char** argv) while (gRunFlag) { next = CTaskMgr::getInstance()->DoTimer(server_clock::now()); - do_sockets(&rfd, next); + do_sockets(next); watchdog.update(); } } diff --git a/src/common/kernel.h b/src/common/kernel.h index 75951e57846..c122d3f6d33 100644 --- a/src/common/kernel.h +++ b/src/common/kernel.h @@ -24,7 +24,6 @@ #include "cbasetypes.h" #include "console_service.h" #include "settings.h" -#include "socket.h" // // Global variables @@ -39,6 +38,6 @@ extern std::unique_ptr gConsoleService; extern void log_init(int, char**); extern auto do_init(int32, char**) -> int32; -extern auto do_sockets(fd_set*, duration) -> int32; +extern auto do_sockets(duration) -> int32; extern void do_abort(void); extern void do_final(int); diff --git a/src/common/logging.h b/src/common/logging.h index 041bd9f8160..f9ebb0ecebd 100644 --- a/src/common/logging.h +++ b/src/common/logging.h @@ -43,7 +43,7 @@ #include #include -#include "spdlog/spdlog.h" +#include // Forward declaration namespace settings diff --git a/src/common/socket.cpp b/src/common/socket.cpp deleted file mode 100644 index 839c931a1d5..00000000000 --- a/src/common/socket.cpp +++ /dev/null @@ -1,291 +0,0 @@ -/* -=========================================================================== - - Copyright (c) 2010-2015 Darkstar Dev Teams - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see http://www.gnu.org/licenses/ - -=========================================================================== -*/ - -#include "common/cbasetypes.h" -#include "common/ipp.h" -#include "common/kernel.h" -#include "common/logging.h" -#include "common/mmo.h" -#include "common/taskmgr.h" -#include "common/timer.h" -#include "common/utils.h" - -#include "settings.h" -#include "socket.h" - -#include - -#include -#include -#include -#include - -#ifdef WIN32 -#include -#include -#else -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifndef SIOCGIFCONF -#include // SIOCGIFCONF on Solaris, maybe others? [Shinomori] -#endif - -#ifdef HAVE_SETRLIMIT -#include -#endif -#endif - -#if defined(WIN32) // windows portability layer - -typedef int socklen_t; - -#define sErrno WSAGetLastError() -#define S_ENOTSOCK WSAENOTSOCK -#define S_EWOULDBLOCK WSAEWOULDBLOCK -#define S_EINTR WSAEINTR -#define S_ECONNABORTED WSAECONNABORTED - -SOCKET sock_arr[MAX_FD]; -int sock_arr_len = 0; - -/// Returns the first fd associated with the socket. -/// Returns -1 if the socket is not found. -/// -/// @param s Socket -/// @return Fd or -1 -int sock2fd(SOCKET s) -{ - TracyZoneScoped; - int fd; - - // search for the socket - for (fd = 1; fd < sock_arr_len; ++fd) - if (sock_arr[fd] == s) - break; // found the socket - if (fd == sock_arr_len) - return -1; // not found - return fd; -} - -/// Inserts the socket into the global array of sockets. -/// Returns a new fd associated with the socket. -/// If there are too many sockets it closes the socket, sets an error and -// returns -1 instead. -/// Since fd 0 is reserved, it returns values in the range [1,MAX_FD[. -/// -/// @param s Socket -/// @return New fd or -1 -int sock2newfd(SOCKET s) -{ - TracyZoneScoped; - int fd; - - // find an empty position - for (fd = 1; fd < sock_arr_len; ++fd) - if (sock_arr[fd] == INVALID_SOCKET) - break; // empty position - if (fd == (sizeof(sock_arr) / sizeof(sock_arr[0]))) - { - // too many sockets - closesocket(s); - WSASetLastError(WSAEMFILE); - return -1; - } - sock_arr[fd] = s; - if (sock_arr_len <= fd) - sock_arr_len = fd + 1; - return fd; -} - -int sAccept(int fd, struct sockaddr* addr, int* addrlen) -{ - TracyZoneScoped; - SOCKET s; - - // accept connection - s = accept(fd2sock(fd), addr, addrlen); - if (s == INVALID_SOCKET) - return -1; // error - return sock2newfd(s); -} - -int sClose(int fd) -{ - TracyZoneScoped; - int ret = closesocket(fd2sock(fd)); - fd2sock(fd) = INVALID_SOCKET; - return ret; -} - -int sSocket(int af, int type, int protocol) -{ - TracyZoneScoped; - SOCKET s; - - // create socket - s = socket(af, type, protocol); - if (s == INVALID_SOCKET) - return -1; // error - return sock2newfd(s); -} -#else // *nix sys -#endif - -fd_set readfds; -int32 fd_max; -time_t last_tick; -time_t tick_time; - -void set_nonblocking(int fd, unsigned long yes) -{ - TracyZoneScoped; - // FIONBIO Use with a nonzero argp parameter to enable the nonblocking mode of socket s. - // The argp parameter is zero if nonblocking is to be disabled. - if (sIoctl(fd, FIONBIO, &yes) != 0) - { - ShowError("set_nonblocking: Failed to set socket #%d to non-blocking mode (code %d) - Please report this!!!", fd, sErrno); - } -} - -int32 makeBind_udp(uint32 ip, uint16 port) -{ - TracyZoneScoped; - sockaddr_in server_address{}; - int fd = 0; - int result = 0; - - fd = sSocket(AF_INET, SOCK_DGRAM, 0); - - if (fd == -1) - { - ShowError("make_listen_bind: socket creation failed (port %d, code %d)!", port, sErrno); - do_final(EXIT_FAILURE); - } - if (fd == 0) - { // reserved - ShowError("make_listen_bind: Socket #0 is reserved - Please report this!!!"); - sClose(fd); - return -1; - } - if (fd >= MAX_FD) - { // socket number too big - ShowError("make_listen_bind: New socket #%d is greater than can we handle! Increase the value of MAX_FD (currently %d) for your OS to fix this!", - fd, MAX_FD); - sClose(fd); - return -1; - } - - server_address.sin_family = AF_INET; - server_address.sin_addr.s_addr = htonl(ip); - server_address.sin_port = htons(port); - - result = sBind(fd, (struct sockaddr*)&server_address, sizeof(server_address)); - if (result == SOCKET_ERROR) - { - ShowError("make_listen_bind: bind failed (socket #%d, port %d, code %d)!", fd, port, sErrno); - do_final(EXIT_FAILURE); - } - - if (fd_max <= fd) - { - fd_max = fd + 1; - } - sFD_SET(fd, &readfds); - return fd; -} - -void socket_init_udp() -{ - TracyZoneScoped; -#ifdef WIN32 - { // Start up windows networking - WSADATA wsaData; - WORD wVersionRequested = MAKEWORD(2, 0); - if (WSAStartup(wVersionRequested, &wsaData) != 0) - { - ShowError("socket_init: WinSock not available!"); - return; - } - if (LOBYTE(wsaData.wVersion) != 2 || HIBYTE(wsaData.wVersion) != 0) - { - ShowError("socket_init: WinSock version mismatch (2.0 or compatible required)!"); - return; - } - } -#elif defined(HAVE_SETRLIMIT) && !defined(CYGWIN) - // NOTE: getrlimit and setrlimit have bogus behavior in cygwin. - // "Number of fds is virtually unlimited in cygwin" (sys/param.h) - { // set socket limit to MAX_FD - rlimit rlp; - if (0 == getrlimit(RLIMIT_NOFILE, &rlp)) - { - rlp.rlim_cur = MAX_FD; - if (0 != setrlimit(RLIMIT_NOFILE, &rlp)) - { // failed, try setting the maximum too (permission to change system limits is required) - rlp.rlim_max = MAX_FD; - if (0 != setrlimit(RLIMIT_NOFILE, &rlp)) - { // failed - // set to maximum allowed - getrlimit(RLIMIT_NOFILE, &rlp); - rlp.rlim_cur = rlp.rlim_max; - setrlimit(RLIMIT_NOFILE, &rlp); - // report limit - getrlimit(RLIMIT_NOFILE, &rlp); - ShowWarning("socket_init: failed to set socket limit to %d (current limit %d).", MAX_FD, (int)rlp.rlim_cur); - } - } - } - } -#endif - - sFD_ZERO(&readfds); - - // initialize last send-receive tick - last_tick = time(nullptr); -} - -int32 recvudp(int32 fd, void* buff, size_t nbytes, int32 flags, sockaddr* from, socklen_t* addrlen) -{ - TracyZoneScoped; - return sRecvfrom(fd, (char*)buff, (int)nbytes, flags, from, addrlen); -} - -int32 sendudp(int32 fd, void* buff, size_t nbytes, int32 flags, const sockaddr* from, socklen_t addrlen) -{ - TracyZoneScoped; - return sSendto(fd, (const char*)buff, (int)nbytes, flags, from, addrlen); -} - -void socket_init() -{ - TracyZoneScoped; - - socket_init_udp(); -} diff --git a/src/common/socket.h b/src/common/socket.h deleted file mode 100644 index 2161d34025a..00000000000 --- a/src/common/socket.h +++ /dev/null @@ -1,179 +0,0 @@ -/* -=========================================================================== - - Copyright (c) 2010-2015 Darkstar Dev Teams - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see http://www.gnu.org/licenses/ - -=========================================================================== -*/ - -#ifndef _SOCKET_H_ -#define _SOCKET_H_ - -#ifndef _CBASETYPES_H_ -#include "common/cbasetypes.h" -#endif - -class IPP; - -#ifdef __APPLE__ -#include -#endif - -#ifdef __APPLE__ -#define MAX_FD FD_SETSIZE -#else -#define MAX_FD 10240 -#endif - -#ifdef WIN32 -#include -#include -typedef long in_addr_t; -#else -#include -#include -#include -#include -#include -#endif - -#include -#include -#include -#include - -#if defined(WIN32) // windows portability layer -typedef int socklen_t; - -#define sErrno WSAGetLastError() -#define S_ENOTSOCK WSAENOTSOCK -#define S_EWOULDBLOCK WSAEWOULDBLOCK -#define S_EINTR WSAEINTR -#define S_ECONNABORTED WSAECONNABORTED - -#define SHUT_RD SD_RECEIVE -#define SHUT_WR SD_SEND -#define SHUT_RDWR SD_BOTH - -// global array of sockets (emulating linux) -// fd is the position in the array -extern SOCKET sock_arr[MAX_FD]; -extern int sock_arr_len; - -/// Returns the socket associated with the target fd. -/// -/// @param fd Target fd. -/// @return Socket -#define fd2sock(fd) sock_arr[fd] - -/// Returns the first fd associated with the socket. -/// Returns -1 if the socket is not found. -/// -/// @param s Socket -/// @return Fd or -1 -int sock2fd(SOCKET s); - -/// Inserts the socket into the global array of sockets. -/// Returns a new fd associated with the socket. -/// If there are too many sockets it closes the socket, sets an error and -// returns -1 instead. -/// Since fd 0 is reserved, it returns values in the range [1,MAX_FD[. -/// -/// @param s Socket -/// @return New fd or -1 -int sock2newfd(SOCKET s); - -int sAccept(int fd, struct sockaddr* addr, int* addrlen); - -int sClose(int fd); -int sSocket(int af, int type, int protocol); - -#define sBind(fd, name, namelen) bind(fd2sock(fd), name, namelen) -#define sListen(fd, backlog) listen(fd2sock(fd), backlog) -#define sIoctl(fd, cmd, argp) ioctlsocket(fd2sock(fd), cmd, argp) -#define sConnect(fd, name, namelen) connect(fd2sock(fd), name, namelen) -#define sRecv(fd, buf, len, flags) recv(fd2sock(fd), buf, len, flags) -#define sRecvfrom(fd, buf, len, flags, from, addrlen) recvfrom(fd2sock(fd), buf, len, flags, from, addrlen) -#define sSelect select -#define sSend(fd, buf, len, flags) send(fd2sock(fd), buf, len, flags) -#define sSendto(fd, buf, len, flags, to, addrlen) sendto(fd2sock(fd), buf, len, flags, to, addrlen) -#define sSetsockopt(fd, level, optname, optval, optlen) setsockopt(fd2sock(fd), level, optname, optval, optlen) -#define sShutdown(fd, how) shutdown(fd2sock(fd), how) -#define sFD_SET(fd, set) FD_SET(fd2sock(fd), set) -#define sFD_CLR(fd, set) FD_CLR(fd2sock(fd), set) -#define sFD_ISSET(fd, set) FD_ISSET(fd2sock(fd), set) -#define sFD_ZERO FD_ZERO -#else // nix portability layer - -#define SOCKET_ERROR (-1) - -#define sErrno errno -#define S_ENOTSOCK EBADF -#define S_EWOULDBLOCK EAGAIN -#define S_EINTR EINTR -#define S_ECONNABORTED ECONNABORTED - -#define sAccept accept -#define sClose close -#define sSocket socket - -#define sBind bind -#define sConnect connect -#define sIoctl ioctl -#define sListen listen -#define sRecv recv -#define sRecvfrom recvfrom -#define sSelect select -#define sSend send -#define sSendto sendto -#define sSetsockopt setsockopt -#define sShutdown shutdown -#define sFD_SET FD_SET -#define sFD_CLR FD_CLR -#define sFD_ISSET FD_ISSET -#define sFD_ZERO FD_ZERO - -#endif - -extern fd_set readfds; -extern int fd_max; -extern time_t last_tick; - -void socket_init(); - -void set_nonblocking(int fd, unsigned long yes); - -int32 makeBind_udp(uint32 ip, uint16 port); - -void socket_init_udp(void); - -int32 recvudp(int32 fd, void* buff, size_t nbytes, int32 flags, sockaddr* from, socklen_t* addrlen); -int32 sendudp(int32 fd, void* buff, size_t nbytes, int32 flags, const sockaddr* from, socklen_t addrlen); - -template -auto ref(U* buf, std::size_t index) -> T& -{ - return *reinterpret_cast(reinterpret_cast(buf) + index); -} - -template -auto as(U& object) -> T* -{ - static_assert(std::is_standard_layout_v, "Type must be standard layout (No virtual functions, inheritance, etc.)"); - return reinterpret_cast(&object); -} - -#endif // _SOCKET_H // diff --git a/src/common/utils.h b/src/common/utils.h index 9dd2d6f5a58..911f7f22991 100644 --- a/src/common/utils.h +++ b/src/common/utils.h @@ -34,6 +34,19 @@ #include #include +template +auto ref(U* buf, std::size_t index) -> T& +{ + return *reinterpret_cast(reinterpret_cast(buf) + index); +} + +template +auto as(U& object) -> T* +{ + static_assert(std::is_standard_layout_v, "Type must be standard layout (No virtual functions, inheritance, etc.)"); + return reinterpret_cast(&object); +} + constexpr size_t PacketNameLength = 16; // 15 + null terminator constexpr size_t DecodeStringLength = 21; // used for size of decoded strings of signature/linkshells diff --git a/src/login/auth_session.cpp b/src/login/auth_session.cpp index dac01c629eb..07f0a7c2955 100644 --- a/src/login/auth_session.cpp +++ b/src/login/auth_session.cpp @@ -22,7 +22,6 @@ #include "auth_session.h" #include "common/ipc.h" -#include "common/socket.h" // for ref #include "common/utils.h" #include diff --git a/src/login/login_helpers.h b/src/login/login_helpers.h index d853d3e0b5f..6a4cc188bdc 100644 --- a/src/login/login_helpers.h +++ b/src/login/login_helpers.h @@ -25,8 +25,8 @@ #include #include -#include // for ref #include +#include #include #include "login_errors.h" diff --git a/src/map/CMakeLists.txt b/src/map/CMakeLists.txt index 34c56dc55f5..c59b235dda1 100644 --- a/src/map/CMakeLists.txt +++ b/src/map/CMakeLists.txt @@ -77,6 +77,8 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/linkshell.h ${CMAKE_CURRENT_SOURCE_DIR}/map.cpp ${CMAKE_CURRENT_SOURCE_DIR}/map.h + ${CMAKE_CURRENT_SOURCE_DIR}/map_networking.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/map_networking.h ${CMAKE_CURRENT_SOURCE_DIR}/map_session_container.cpp ${CMAKE_CURRENT_SOURCE_DIR}/map_session_container.h ${CMAKE_CURRENT_SOURCE_DIR}/map_session.cpp diff --git a/src/map/instance_loader.h b/src/map/instance_loader.h index 87752e1bab4..ce7ee54dea4 100644 --- a/src/map/instance_loader.h +++ b/src/map/instance_loader.h @@ -23,7 +23,6 @@ #define _CINSTANCELOADER_H #include "common/cbasetypes.h" -#include "common/socket.h" class CCharEntity; class CInstance; diff --git a/src/map/ipc_client.h b/src/map/ipc_client.h index 5a8405192f0..a470a107aae 100644 --- a/src/map/ipc_client.h +++ b/src/map/ipc_client.h @@ -25,7 +25,7 @@ #include "common/ipc.h" #include "common/lua.h" #include "common/mmo.h" -#include "common/socket.h" + #include "common/sql.h" #include "common/zmq_dealer_wrapper.h" diff --git a/src/map/items/item_linkshell.cpp b/src/map/items/item_linkshell.cpp index 43f31174b96..c0afbb88822 100644 --- a/src/map/items/item_linkshell.cpp +++ b/src/map/items/item_linkshell.cpp @@ -21,7 +21,6 @@ #include "item_linkshell.h" -#include "common/socket.h" #include "common/utils.h" #include diff --git a/src/map/map_session.cpp b/src/map/map_session.cpp index 752f7682255..6a481fe1c9e 100644 --- a/src/map/map_session.cpp +++ b/src/map/map_session.cpp @@ -46,3 +46,8 @@ void MapSession::initBlowfish() } blowfish_init((int8*)blowfish.hash, 16, blowfish.P, blowfish.S[0]); } + +auto MapSession::toString() -> std::string +{ + return fmt::format("MapSession: client_ipp: {}", client_ipp.toString()); +} diff --git a/src/map/map_session.h b/src/map/map_session.h index 95ee4e9e570..6a8bf0aebd8 100644 --- a/src/map/map_session.h +++ b/src/map/map_session.h @@ -54,4 +54,6 @@ struct MapSession void incrementBlowfish(); void initBlowfish(); + + auto toString() -> std::string; }; diff --git a/src/map/map_session_container.cpp b/src/map/map_session_container.cpp index 86899678ad5..1c60b0ff010 100644 --- a/src/map/map_session_container.cpp +++ b/src/map/map_session_container.cpp @@ -25,7 +25,6 @@ #include "status_effect_container.h" #include "common/database.h" -#include "common/socket.h" #include "entities/charentity.h" diff --git a/src/map/packet_system.cpp b/src/map/packet_system.cpp index fe9b6df5dc6..bbf5c9acb6c 100644 --- a/src/map/packet_system.cpp +++ b/src/map/packet_system.cpp @@ -25,7 +25,7 @@ #include "common/logging.h" #include "common/md52.h" #include "common/mmo.h" -#include "common/socket.h" + #include "common/taskmgr.h" #include "common/timer.h" #include "common/utils.h" diff --git a/src/map/packets/action.cpp b/src/map/packets/action.cpp index 27c0ea9c069..7a5912ee47e 100644 --- a/src/map/packets/action.cpp +++ b/src/map/packets/action.cpp @@ -20,7 +20,7 @@ */ #include "common/logging.h" -#include "common/socket.h" + #include "common/utils.h" #include diff --git a/src/map/packets/auction_house.cpp b/src/map/packets/auction_house.cpp index d12a3baec9b..ce3c7cc55c7 100644 --- a/src/map/packets/auction_house.cpp +++ b/src/map/packets/auction_house.cpp @@ -21,7 +21,6 @@ #include "auction_house.h" -#include "common/socket.h" #include "common/vana_time.h" #include diff --git a/src/map/packets/basic.h b/src/map/packets/basic.h index 4521caa3964..8e539877078 100644 --- a/src/map/packets/basic.h +++ b/src/map/packets/basic.h @@ -22,8 +22,8 @@ #pragma once #include "common/cbasetypes.h" -#include "common/socket.h" #include "common/tracy.h" +#include "common/utils.h" #include #include diff --git a/src/map/packets/bazaar_check.cpp b/src/map/packets/bazaar_check.cpp index 8244400064f..1de16bf163b 100644 --- a/src/map/packets/bazaar_check.cpp +++ b/src/map/packets/bazaar_check.cpp @@ -19,8 +19,6 @@ =========================================================================== */ -#include "common/socket.h" - #include #include "bazaar_check.h" diff --git a/src/map/packets/bazaar_close.cpp b/src/map/packets/bazaar_close.cpp index be1d9556062..2e057d07afa 100644 --- a/src/map/packets/bazaar_close.cpp +++ b/src/map/packets/bazaar_close.cpp @@ -19,8 +19,6 @@ =========================================================================== */ -#include "common/socket.h" - #include #include "bazaar_close.h" diff --git a/src/map/packets/bazaar_confirmation.cpp b/src/map/packets/bazaar_confirmation.cpp index 7dbaa094dd4..255410c6175 100644 --- a/src/map/packets/bazaar_confirmation.cpp +++ b/src/map/packets/bazaar_confirmation.cpp @@ -19,8 +19,6 @@ =========================================================================== */ -#include "common/socket.h" - #include #include "bazaar_confirmation.h" diff --git a/src/map/packets/bazaar_item.cpp b/src/map/packets/bazaar_item.cpp index ca11bc4ac52..d89be1c36de 100644 --- a/src/map/packets/bazaar_item.cpp +++ b/src/map/packets/bazaar_item.cpp @@ -21,7 +21,6 @@ #include "bazaar_item.h" -#include "common/socket.h" #include "common/utils.h" #include "common/vana_time.h" diff --git a/src/map/packets/bazaar_message.cpp b/src/map/packets/bazaar_message.cpp index 17917bf8434..aabc9aa70ad 100644 --- a/src/map/packets/bazaar_message.cpp +++ b/src/map/packets/bazaar_message.cpp @@ -19,8 +19,6 @@ =========================================================================== */ -#include "common/socket.h" - #include #include "bazaar_message.h" diff --git a/src/map/packets/bazaar_purchase.cpp b/src/map/packets/bazaar_purchase.cpp index 8fe4e6436ef..e870cb06c1a 100644 --- a/src/map/packets/bazaar_purchase.cpp +++ b/src/map/packets/bazaar_purchase.cpp @@ -19,8 +19,6 @@ =========================================================================== */ -#include "common/socket.h" - #include "entities/charentity.h" #include diff --git a/src/map/packets/blacklist_edit_response.cpp b/src/map/packets/blacklist_edit_response.cpp index 6358c078502..8a33c1b9b50 100644 --- a/src/map/packets/blacklist_edit_response.cpp +++ b/src/map/packets/blacklist_edit_response.cpp @@ -19,8 +19,6 @@ =========================================================================== */ -#include "common/socket.h" - #include "blacklist_edit_response.h" #include "entities/charentity.h" diff --git a/src/map/packets/campaign_map.cpp b/src/map/packets/campaign_map.cpp index cbdf8f846cc..4add8aba182 100644 --- a/src/map/packets/campaign_map.cpp +++ b/src/map/packets/campaign_map.cpp @@ -19,8 +19,6 @@ =========================================================================== */ -#include "common/socket.h" - #include "campaign_map.h" #include "campaign_system.h" diff --git a/src/map/packets/caught_fish.cpp b/src/map/packets/caught_fish.cpp index cd77b69c05e..41d7c3ee345 100644 --- a/src/map/packets/caught_fish.cpp +++ b/src/map/packets/caught_fish.cpp @@ -20,7 +20,7 @@ */ #include "caught_fish.h" -#include "common/socket.h" + #include "entities/charentity.h" #include diff --git a/src/map/packets/caught_monster.cpp b/src/map/packets/caught_monster.cpp index af4f46dfa30..72af30d4276 100644 --- a/src/map/packets/caught_monster.cpp +++ b/src/map/packets/caught_monster.cpp @@ -20,7 +20,7 @@ */ #include "caught_monster.h" -#include "common/socket.h" + #include "entities/charentity.h" #include diff --git a/src/map/packets/change_music.cpp b/src/map/packets/change_music.cpp index e2fed2784ee..db0f8706c0e 100644 --- a/src/map/packets/change_music.cpp +++ b/src/map/packets/change_music.cpp @@ -19,8 +19,6 @@ =========================================================================== */ -#include "common/socket.h" - #include "change_music.h" CChangeMusicPacket::CChangeMusicPacket(uint16 BlockID, uint16 MusicTrackID) diff --git a/src/map/packets/char_abilities.cpp b/src/map/packets/char_abilities.cpp index 5a563f7ea96..37784351c0c 100644 --- a/src/map/packets/char_abilities.cpp +++ b/src/map/packets/char_abilities.cpp @@ -19,8 +19,6 @@ =========================================================================== */ -#include "common/socket.h" - #include #include "char_abilities.h" diff --git a/src/map/packets/char_appearance.cpp b/src/map/packets/char_appearance.cpp index 05026dbd59a..3a85b38e56f 100644 --- a/src/map/packets/char_appearance.cpp +++ b/src/map/packets/char_appearance.cpp @@ -19,8 +19,6 @@ =========================================================================== */ -#include "common/socket.h" - #include "char_appearance.h" #include "entities/charentity.h" diff --git a/src/map/packets/char_check.cpp b/src/map/packets/char_check.cpp index 67ec6b515e5..998b5a53c30 100644 --- a/src/map/packets/char_check.cpp +++ b/src/map/packets/char_check.cpp @@ -21,7 +21,6 @@ #include "char_check.h" -#include "common/socket.h" #include "common/utils.h" #include "common/vana_time.h" diff --git a/src/map/packets/char_emote_list.cpp b/src/map/packets/char_emote_list.cpp index a79ca6d7acd..d7bdd5b8b7d 100644 --- a/src/map/packets/char_emote_list.cpp +++ b/src/map/packets/char_emote_list.cpp @@ -20,7 +20,7 @@ */ #include "char_emote_list.h" -#include "common/socket.h" + #include "entities/baseentity.h" #include "lua/luautils.h" #include "utils/charutils.h" diff --git a/src/map/packets/char_equip.cpp b/src/map/packets/char_equip.cpp index f7d5bfc9816..6222e603822 100644 --- a/src/map/packets/char_equip.cpp +++ b/src/map/packets/char_equip.cpp @@ -19,8 +19,6 @@ =========================================================================== */ -#include "common/socket.h" - #include "char_equip.h" CEquipPacket::CEquipPacket(uint8 EquipSlot, uint8 SlotID, uint8 containerID) diff --git a/src/map/packets/char_health.cpp b/src/map/packets/char_health.cpp index 7bf90a6c3aa..822de0c6d13 100644 --- a/src/map/packets/char_health.cpp +++ b/src/map/packets/char_health.cpp @@ -19,8 +19,6 @@ =========================================================================== */ -#include "common/socket.h" - #include "char_health.h" #include "entities/charentity.h" diff --git a/src/map/packets/char_job_extra.cpp b/src/map/packets/char_job_extra.cpp index 3e370112594..b29cd56774a 100644 --- a/src/map/packets/char_job_extra.cpp +++ b/src/map/packets/char_job_extra.cpp @@ -19,8 +19,6 @@ =========================================================================== */ -#include "common/socket.h" - #include #include "char_job_extra.h" diff --git a/src/map/packets/char_jobs.cpp b/src/map/packets/char_jobs.cpp index 66481cbf71c..ee410dde70a 100644 --- a/src/map/packets/char_jobs.cpp +++ b/src/map/packets/char_jobs.cpp @@ -19,8 +19,6 @@ =========================================================================== */ -#include "common/socket.h" - #include #include "char_jobs.h" diff --git a/src/map/packets/char_mounts.cpp b/src/map/packets/char_mounts.cpp index 06517a40c67..28510e18e20 100644 --- a/src/map/packets/char_mounts.cpp +++ b/src/map/packets/char_mounts.cpp @@ -19,8 +19,6 @@ =========================================================================== */ -#include "common/socket.h" - #include #include "char_mounts.h" diff --git a/src/map/packets/char_recast.cpp b/src/map/packets/char_recast.cpp index 0704da5fae6..1e80b6f782c 100644 --- a/src/map/packets/char_recast.cpp +++ b/src/map/packets/char_recast.cpp @@ -19,7 +19,6 @@ =========================================================================== */ -#include "common/socket.h" #include "common/timer.h" #include diff --git a/src/map/packets/char_skills.cpp b/src/map/packets/char_skills.cpp index 6c351760517..8660117864a 100644 --- a/src/map/packets/char_skills.cpp +++ b/src/map/packets/char_skills.cpp @@ -19,7 +19,6 @@ =========================================================================== */ -#include "common/socket.h" #include "common/timer.h" #include diff --git a/src/map/packets/char_spells.cpp b/src/map/packets/char_spells.cpp index a65cb92c843..233fddb4bf2 100644 --- a/src/map/packets/char_spells.cpp +++ b/src/map/packets/char_spells.cpp @@ -19,8 +19,6 @@ =========================================================================== */ -#include "common/socket.h" - #include #include "char_spells.h" diff --git a/src/map/packets/char_stats.cpp b/src/map/packets/char_stats.cpp index 58540a61fcf..e316a021720 100644 --- a/src/map/packets/char_stats.cpp +++ b/src/map/packets/char_stats.cpp @@ -19,7 +19,6 @@ =========================================================================== */ -#include "common/socket.h" #include "common/utils.h" #include diff --git a/src/map/packets/char_status.cpp b/src/map/packets/char_status.cpp index d8097fdeda6..2f558d17499 100644 --- a/src/map/packets/char_status.cpp +++ b/src/map/packets/char_status.cpp @@ -22,7 +22,7 @@ #include "char_status.h" #include "common/logging.h" -#include "common/socket.h" + #include "common/vana_time.h" #include diff --git a/src/map/packets/char_sync.cpp b/src/map/packets/char_sync.cpp index db4db991bc1..7d38dada68f 100644 --- a/src/map/packets/char_sync.cpp +++ b/src/map/packets/char_sync.cpp @@ -19,8 +19,6 @@ =========================================================================== */ -#include "common/socket.h" - #include "char_sync.h" #include "entities/charentity.h" diff --git a/src/map/packets/char_update.cpp b/src/map/packets/char_update.cpp index 550ab9da544..5318fd22900 100644 --- a/src/map/packets/char_update.cpp +++ b/src/map/packets/char_update.cpp @@ -19,8 +19,6 @@ =========================================================================== */ -#include "common/socket.h" - #include #include "char_update.h" diff --git a/src/map/packets/chat_message.cpp b/src/map/packets/chat_message.cpp index b8c2ff7f9de..b00dbb3e69c 100644 --- a/src/map/packets/chat_message.cpp +++ b/src/map/packets/chat_message.cpp @@ -20,7 +20,7 @@ */ #include "chat_message.h" -#include "common/socket.h" + #include "entities/charentity.h" #include diff --git a/src/map/packets/chocobo_digging.cpp b/src/map/packets/chocobo_digging.cpp index 5a80380ab38..c244683d4c5 100644 --- a/src/map/packets/chocobo_digging.cpp +++ b/src/map/packets/chocobo_digging.cpp @@ -19,8 +19,6 @@ =========================================================================== */ -#include "common/socket.h" - #include "chocobo_digging.h" #include "entities/charentity.h" diff --git a/src/map/packets/conquest_map.cpp b/src/map/packets/conquest_map.cpp index 539fb19dcc4..f03f43a4ab9 100644 --- a/src/map/packets/conquest_map.cpp +++ b/src/map/packets/conquest_map.cpp @@ -19,8 +19,6 @@ =========================================================================== */ -#include "common/socket.h" - #include #include "besieged_system.h" diff --git a/src/map/packets/cs_position.cpp b/src/map/packets/cs_position.cpp index 601923ac51a..cd3297fa3af 100644 --- a/src/map/packets/cs_position.cpp +++ b/src/map/packets/cs_position.cpp @@ -19,8 +19,6 @@ =========================================================================== */ -#include "common/socket.h" - #include "cs_position.h" #include "entities/charentity.h" diff --git a/src/map/packets/delivery_box.cpp b/src/map/packets/delivery_box.cpp index 078c60ba226..35937b5e14c 100644 --- a/src/map/packets/delivery_box.cpp +++ b/src/map/packets/delivery_box.cpp @@ -19,8 +19,6 @@ =========================================================================== */ -#include "common/socket.h" - #include "utils/itemutils.h" #include diff --git a/src/map/packets/entity_animation.cpp b/src/map/packets/entity_animation.cpp index 3e1799d397d..c614156ad3d 100644 --- a/src/map/packets/entity_animation.cpp +++ b/src/map/packets/entity_animation.cpp @@ -19,8 +19,6 @@ =========================================================================== */ -#include "common/socket.h" - #include "entity_animation.h" #include "entities/baseentity.h" diff --git a/src/map/packets/entity_enable_list.cpp b/src/map/packets/entity_enable_list.cpp index 80267280ca8..e40c036785e 100644 --- a/src/map/packets/entity_enable_list.cpp +++ b/src/map/packets/entity_enable_list.cpp @@ -1,4 +1,4 @@ -#include "common/socket.h" + #include "entities/baseentity.h" diff --git a/src/map/packets/entity_set_name.cpp b/src/map/packets/entity_set_name.cpp index 307b67f83f0..f39fd6c844a 100644 --- a/src/map/packets/entity_set_name.cpp +++ b/src/map/packets/entity_set_name.cpp @@ -18,7 +18,7 @@ =========================================================================== */ -#include "common/socket.h" + #include "common/utils.h" #include "entity_set_name.h" diff --git a/src/map/packets/entity_update.cpp b/src/map/packets/entity_update.cpp index 2fbc15ba6f2..3fe1569aaa0 100644 --- a/src/map/packets/entity_update.cpp +++ b/src/map/packets/entity_update.cpp @@ -19,7 +19,6 @@ =========================================================================== */ -#include "common/socket.h" #include "common/timer.h" #include "common/utils.h" #include "common/vana_time.h" diff --git a/src/map/packets/entity_visual.cpp b/src/map/packets/entity_visual.cpp index 62cac6bcd38..609dbd4feff 100644 --- a/src/map/packets/entity_visual.cpp +++ b/src/map/packets/entity_visual.cpp @@ -19,8 +19,6 @@ =========================================================================== */ -#include "common/socket.h" - #include "entities/baseentity.h" #include "entity_visual.h" diff --git a/src/map/packets/event.cpp b/src/map/packets/event.cpp index 589be679ec2..6cab1bc317c 100644 --- a/src/map/packets/event.cpp +++ b/src/map/packets/event.cpp @@ -19,8 +19,6 @@ =========================================================================== */ -#include "common/socket.h" - #include #include "entities/charentity.h" diff --git a/src/map/packets/event_string.cpp b/src/map/packets/event_string.cpp index f4214082adf..81826f2c089 100644 --- a/src/map/packets/event_string.cpp +++ b/src/map/packets/event_string.cpp @@ -19,8 +19,6 @@ =========================================================================== */ -#include "common/socket.h" - #include #include "entities/charentity.h" diff --git a/src/map/packets/event_update.cpp b/src/map/packets/event_update.cpp index 9d3f1a222b3..d118373325d 100644 --- a/src/map/packets/event_update.cpp +++ b/src/map/packets/event_update.cpp @@ -19,10 +19,8 @@ =========================================================================== */ -#include "common/socket.h" - -#include "entities/charentity.h" #include "event_update.h" +#include "entities/charentity.h" CEventUpdatePacket::CEventUpdatePacket(std::vector> const& params) { diff --git a/src/map/packets/event_update_string.cpp b/src/map/packets/event_update_string.cpp index 75b9809083b..0048268f42d 100644 --- a/src/map/packets/event_update_string.cpp +++ b/src/map/packets/event_update_string.cpp @@ -19,8 +19,6 @@ =========================================================================== */ -#include "common/socket.h" - #include #include "entities/charentity.h" diff --git a/src/map/packets/fish_ranking.cpp b/src/map/packets/fish_ranking.cpp index c2e1bf50d96..9e7c759f67d 100644 --- a/src/map/packets/fish_ranking.cpp +++ b/src/map/packets/fish_ranking.cpp @@ -21,7 +21,6 @@ #include "fish_ranking.h" -#include "common/socket.h" #include "common/vana_time.h" #include "fishingcontest.h" diff --git a/src/map/packets/fishing.cpp b/src/map/packets/fishing.cpp index 60e4032bbad..7cd624fc11c 100644 --- a/src/map/packets/fishing.cpp +++ b/src/map/packets/fishing.cpp @@ -19,8 +19,6 @@ =========================================================================== */ -#include "common/socket.h" - #include #include "fishing.h" diff --git a/src/map/packets/furniture_interact.cpp b/src/map/packets/furniture_interact.cpp index 0a398bcd950..d93a920139a 100644 --- a/src/map/packets/furniture_interact.cpp +++ b/src/map/packets/furniture_interact.cpp @@ -19,7 +19,6 @@ =========================================================================== */ -#include "common/socket.h" #include "common/utils.h" #include diff --git a/src/map/packets/guild_menu.cpp b/src/map/packets/guild_menu.cpp index 382aa4c0164..aa24b4f1659 100644 --- a/src/map/packets/guild_menu.cpp +++ b/src/map/packets/guild_menu.cpp @@ -19,7 +19,6 @@ =========================================================================== */ -#include "common/socket.h" #include "common/utils.h" #include "guild_menu.h" diff --git a/src/map/packets/guild_menu_buy.cpp b/src/map/packets/guild_menu_buy.cpp index 3d54adc755a..5ee6c2136d3 100644 --- a/src/map/packets/guild_menu_buy.cpp +++ b/src/map/packets/guild_menu_buy.cpp @@ -19,8 +19,6 @@ =========================================================================== */ -#include "common/socket.h" - #include #include "guild_menu_buy.h" diff --git a/src/map/packets/guild_menu_buy_update.cpp b/src/map/packets/guild_menu_buy_update.cpp index 513eea055e4..9019af0203e 100644 --- a/src/map/packets/guild_menu_buy_update.cpp +++ b/src/map/packets/guild_menu_buy_update.cpp @@ -19,8 +19,6 @@ =========================================================================== */ -#include "common/socket.h" - #include #include "guild_menu_buy_update.h" diff --git a/src/map/packets/guild_menu_sell.cpp b/src/map/packets/guild_menu_sell.cpp index 6ded31e5edc..1d32df48e73 100644 --- a/src/map/packets/guild_menu_sell.cpp +++ b/src/map/packets/guild_menu_sell.cpp @@ -19,8 +19,6 @@ =========================================================================== */ -#include "common/socket.h" - #include #include "guild_menu_sell.h" diff --git a/src/map/packets/guild_menu_sell_update.cpp b/src/map/packets/guild_menu_sell_update.cpp index e0e0beb6640..5bef5319648 100644 --- a/src/map/packets/guild_menu_sell_update.cpp +++ b/src/map/packets/guild_menu_sell_update.cpp @@ -19,8 +19,6 @@ =========================================================================== */ -#include "common/socket.h" - #include #include "guild_menu_sell_update.h" diff --git a/src/map/packets/independent_animation.cpp b/src/map/packets/independent_animation.cpp index 73a82888c4a..ff8dc8dbb5c 100644 --- a/src/map/packets/independent_animation.cpp +++ b/src/map/packets/independent_animation.cpp @@ -1,4 +1,4 @@ -#include "common/socket.h" + #include "entities/baseentity.h" diff --git a/src/map/packets/instance_entry.cpp b/src/map/packets/instance_entry.cpp index 12adbc48faa..90f51bc696d 100644 --- a/src/map/packets/instance_entry.cpp +++ b/src/map/packets/instance_entry.cpp @@ -18,7 +18,6 @@ =========================================================================== */ -#include "common/socket.h" #include "instance_entry.h" diff --git a/src/map/packets/inventory_assign.cpp b/src/map/packets/inventory_assign.cpp index f1a88419a89..7f00570c9dd 100644 --- a/src/map/packets/inventory_assign.cpp +++ b/src/map/packets/inventory_assign.cpp @@ -19,8 +19,6 @@ =========================================================================== */ -#include "common/socket.h" - #include "utils/itemutils.h" #include "inventory_assign.h" diff --git a/src/map/packets/inventory_finish.cpp b/src/map/packets/inventory_finish.cpp index 65b24f9f660..de43d705fbb 100644 --- a/src/map/packets/inventory_finish.cpp +++ b/src/map/packets/inventory_finish.cpp @@ -19,8 +19,6 @@ =========================================================================== */ -#include "common/socket.h" - #include "inventory_finish.h" CInventoryFinishPacket::CInventoryFinishPacket() diff --git a/src/map/packets/inventory_item.cpp b/src/map/packets/inventory_item.cpp index 1f3db6a0e62..fe728d47b87 100644 --- a/src/map/packets/inventory_item.cpp +++ b/src/map/packets/inventory_item.cpp @@ -21,7 +21,6 @@ #include "inventory_item.h" -#include "common/socket.h" #include "common/utils.h" #include "common/vana_time.h" diff --git a/src/map/packets/inventory_modify.cpp b/src/map/packets/inventory_modify.cpp index 74e49be256f..2e8fd603768 100644 --- a/src/map/packets/inventory_modify.cpp +++ b/src/map/packets/inventory_modify.cpp @@ -19,8 +19,6 @@ =========================================================================== */ -#include "common/socket.h" - #include "inventory_modify.h" CInventoryModifyPacket::CInventoryModifyPacket(uint8 LocationID, uint8 slotID, uint32 quantity) diff --git a/src/map/packets/inventory_size.cpp b/src/map/packets/inventory_size.cpp index c5e96792077..342dc5feeb5 100644 --- a/src/map/packets/inventory_size.cpp +++ b/src/map/packets/inventory_size.cpp @@ -19,10 +19,8 @@ =========================================================================== */ -#include "common/socket.h" - -#include "entities/charentity.h" #include "inventory_size.h" +#include "entities/charentity.h" #include "item_container.h" #include "utils/charutils.h" diff --git a/src/map/packets/jobpoint_details.cpp b/src/map/packets/jobpoint_details.cpp index 03a9b30a3d0..e3ca3e2069d 100644 --- a/src/map/packets/jobpoint_details.cpp +++ b/src/map/packets/jobpoint_details.cpp @@ -14,8 +14,6 @@ =========================================================================== */ -#include "common/socket.h" - #include "jobpoint_details.h" #include "entities/charentity.h" diff --git a/src/map/packets/jobpoint_update.cpp b/src/map/packets/jobpoint_update.cpp index 75bce1d945c..28f19b2ac0d 100644 --- a/src/map/packets/jobpoint_update.cpp +++ b/src/map/packets/jobpoint_update.cpp @@ -14,8 +14,6 @@ =========================================================================== */ -#include "common/socket.h" - #include "jobpoint_update.h" #include "entities/charentity.h" diff --git a/src/map/packets/key_items.cpp b/src/map/packets/key_items.cpp index 75a13e12ecc..06f56233c16 100644 --- a/src/map/packets/key_items.cpp +++ b/src/map/packets/key_items.cpp @@ -19,8 +19,6 @@ =========================================================================== */ -#include "common/socket.h" - #include #include "entities/charentity.h" diff --git a/src/map/packets/linkshell_equip.cpp b/src/map/packets/linkshell_equip.cpp index 9412fc75fcc..1fb387aa7b9 100644 --- a/src/map/packets/linkshell_equip.cpp +++ b/src/map/packets/linkshell_equip.cpp @@ -19,8 +19,6 @@ =========================================================================== */ -#include "common/socket.h" - #include "linkshell_equip.h" #include "entities/charentity.h" diff --git a/src/map/packets/linkshell_message.cpp b/src/map/packets/linkshell_message.cpp index ff84904efbb..f5f47803570 100644 --- a/src/map/packets/linkshell_message.cpp +++ b/src/map/packets/linkshell_message.cpp @@ -19,8 +19,6 @@ =========================================================================== */ -#include "common/socket.h" - #include "linkshell_message.h" #include diff --git a/src/map/packets/lock_on.cpp b/src/map/packets/lock_on.cpp index 3d542d42f64..62dc90cdbed 100644 --- a/src/map/packets/lock_on.cpp +++ b/src/map/packets/lock_on.cpp @@ -19,8 +19,6 @@ =========================================================================== */ -#include "common/socket.h" - #include "lock_on.h" #include "entities/battleentity.h" diff --git a/src/map/packets/macroequipset.cpp b/src/map/packets/macroequipset.cpp index 92a159c34bc..559f8cfd62f 100644 --- a/src/map/packets/macroequipset.cpp +++ b/src/map/packets/macroequipset.cpp @@ -20,7 +20,6 @@ */ #include "macroequipset.h" -#include "common/socket.h" #include "item_container.h" #include "items/item_equipment.h" diff --git a/src/map/packets/menu_config.cpp b/src/map/packets/menu_config.cpp index 82b35df610d..ebc59bbfba7 100644 --- a/src/map/packets/menu_config.cpp +++ b/src/map/packets/menu_config.cpp @@ -19,8 +19,6 @@ =========================================================================== */ -#include "common/socket.h" - #include "menu_config.h" #include "entities/charentity.h" diff --git a/src/map/packets/menu_jobpoints.cpp b/src/map/packets/menu_jobpoints.cpp index bbf257b7f6a..3454e602693 100644 --- a/src/map/packets/menu_jobpoints.cpp +++ b/src/map/packets/menu_jobpoints.cpp @@ -14,8 +14,6 @@ =========================================================================== */ -#include "common/socket.h" - #include "menu_jobpoints.h" #include "entities/battleentity.h" diff --git a/src/map/packets/menu_merit.cpp b/src/map/packets/menu_merit.cpp index d1ede3aa9b6..e98358b60de 100644 --- a/src/map/packets/menu_merit.cpp +++ b/src/map/packets/menu_merit.cpp @@ -19,10 +19,8 @@ =========================================================================== */ -#include "common/socket.h" - -#include "job_points.h" #include "menu_merit.h" +#include "job_points.h" #include "entities/charentity.h" #include "utils/charutils.h" diff --git a/src/map/packets/menu_mog.cpp b/src/map/packets/menu_mog.cpp index d8ae8450773..29f23646ec8 100644 --- a/src/map/packets/menu_mog.cpp +++ b/src/map/packets/menu_mog.cpp @@ -19,8 +19,6 @@ =========================================================================== */ -#include "common/socket.h" - #include "menu_mog.h" CMenuMogPacket::CMenuMogPacket() diff --git a/src/map/packets/menu_raisetractor.cpp b/src/map/packets/menu_raisetractor.cpp index 1a873e7525c..1a5db7c6ddb 100644 --- a/src/map/packets/menu_raisetractor.cpp +++ b/src/map/packets/menu_raisetractor.cpp @@ -19,10 +19,8 @@ =========================================================================== */ -#include "common/socket.h" - -#include "entities/charentity.h" #include "menu_raisetractor.h" +#include "entities/charentity.h" CRaiseTractorMenuPacket::CRaiseTractorMenuPacket(CCharEntity* PChar, REVIVAL_TYPE type) { diff --git a/src/map/packets/menu_unity.cpp b/src/map/packets/menu_unity.cpp index fa1cf6d8aee..bc8ab9853ff 100644 --- a/src/map/packets/menu_unity.cpp +++ b/src/map/packets/menu_unity.cpp @@ -19,8 +19,6 @@ =========================================================================== */ -#include "common/socket.h" - #include "menu_unity.h" #include "entities/charentity.h" diff --git a/src/map/packets/merit_points_categories.cpp b/src/map/packets/merit_points_categories.cpp index b377516da15..afed8074bdb 100644 --- a/src/map/packets/merit_points_categories.cpp +++ b/src/map/packets/merit_points_categories.cpp @@ -19,8 +19,6 @@ =========================================================================== */ -#include "common/socket.h" - #include #include "merit_points_categories.h" diff --git a/src/map/packets/message_basic.cpp b/src/map/packets/message_basic.cpp index bde6d4025c6..f0c085f67db 100644 --- a/src/map/packets/message_basic.cpp +++ b/src/map/packets/message_basic.cpp @@ -19,8 +19,6 @@ =========================================================================== */ -#include "common/socket.h" - #include "message_basic.h" #include "message_standard.h" diff --git a/src/map/packets/message_combat.cpp b/src/map/packets/message_combat.cpp index 4620ff0a578..dc9141d4c63 100644 --- a/src/map/packets/message_combat.cpp +++ b/src/map/packets/message_combat.cpp @@ -19,8 +19,6 @@ =========================================================================== */ -#include "common/socket.h" - #include "message_combat.h" #include "entities/baseentity.h" diff --git a/src/map/packets/message_special.cpp b/src/map/packets/message_special.cpp index b16efde10d7..0dc32e49d60 100644 --- a/src/map/packets/message_special.cpp +++ b/src/map/packets/message_special.cpp @@ -19,7 +19,6 @@ =========================================================================== */ -#include "common/socket.h" #include "common/utils.h" #include diff --git a/src/map/packets/message_standard.cpp b/src/map/packets/message_standard.cpp index 0b661b9aa86..29caa20d116 100644 --- a/src/map/packets/message_standard.cpp +++ b/src/map/packets/message_standard.cpp @@ -19,8 +19,6 @@ =========================================================================== */ -#include "common/socket.h" - #include #include "message_standard.h" diff --git a/src/map/packets/message_system.cpp b/src/map/packets/message_system.cpp index 623eeecb6bf..d34a37950a4 100644 --- a/src/map/packets/message_system.cpp +++ b/src/map/packets/message_system.cpp @@ -19,8 +19,6 @@ =========================================================================== */ -#include "common/socket.h" - #include "message_system.h" CMessageSystemPacket::CMessageSystemPacket(uint32 param0, uint32 param1, MsgStd messageID) diff --git a/src/map/packets/message_text.cpp b/src/map/packets/message_text.cpp index 03c9ab6616d..aa6dbfab0c9 100644 --- a/src/map/packets/message_text.cpp +++ b/src/map/packets/message_text.cpp @@ -19,10 +19,8 @@ =========================================================================== */ -#include "common/socket.h" - -#include "entities/baseentity.h" #include "message_text.h" +#include "entities/baseentity.h" CMessageTextPacket::CMessageTextPacket(CBaseEntity* PEntity, uint16 messageID, bool showName, uint8 mode) { diff --git a/src/map/packets/monipulator1.cpp b/src/map/packets/monipulator1.cpp index 8f1cbb6a74b..71f10d738dd 100644 --- a/src/map/packets/monipulator1.cpp +++ b/src/map/packets/monipulator1.cpp @@ -21,7 +21,6 @@ #include "monipulator1.h" -#include "common/socket.h" #include "entities/charentity.h" #include "monstrosity.h" #include "utils/charutils.h" diff --git a/src/map/packets/monipulator2.cpp b/src/map/packets/monipulator2.cpp index e74751bd6e8..8945cfac9f8 100644 --- a/src/map/packets/monipulator2.cpp +++ b/src/map/packets/monipulator2.cpp @@ -21,7 +21,6 @@ #include "monipulator2.h" -#include "common/socket.h" #include "entities/charentity.h" #include "monstrosity.h" diff --git a/src/map/packets/objective_utility.cpp b/src/map/packets/objective_utility.cpp index 2dd18f56531..caa36b43e2b 100644 --- a/src/map/packets/objective_utility.cpp +++ b/src/map/packets/objective_utility.cpp @@ -1,4 +1,4 @@ -#include "common/socket.h" + #include "objective_utility.h" diff --git a/src/map/packets/party_define.cpp b/src/map/packets/party_define.cpp index 7aaddf7f3f4..f95b9e89b1c 100644 --- a/src/map/packets/party_define.cpp +++ b/src/map/packets/party_define.cpp @@ -19,8 +19,6 @@ =========================================================================== */ -#include "common/socket.h" - #include "party_define.h" #include "entities/charentity.h" diff --git a/src/map/packets/party_invite.cpp b/src/map/packets/party_invite.cpp index 387fcf9ad4f..e7e498e350b 100644 --- a/src/map/packets/party_invite.cpp +++ b/src/map/packets/party_invite.cpp @@ -19,8 +19,6 @@ =========================================================================== */ -#include "common/socket.h" - #include #include "party_invite.h" diff --git a/src/map/packets/party_map.cpp b/src/map/packets/party_map.cpp index bb6fb138501..ca6af20a70c 100644 --- a/src/map/packets/party_map.cpp +++ b/src/map/packets/party_map.cpp @@ -19,8 +19,6 @@ =========================================================================== */ -#include "common/socket.h" - #include "party_map.h" #include "entities/charentity.h" diff --git a/src/map/packets/party_member_update.cpp b/src/map/packets/party_member_update.cpp index bf711772508..57a9c2429be 100644 --- a/src/map/packets/party_member_update.cpp +++ b/src/map/packets/party_member_update.cpp @@ -19,8 +19,6 @@ =========================================================================== */ -#include "common/socket.h" - #include #include "party_member_update.h" diff --git a/src/map/packets/party_search.cpp b/src/map/packets/party_search.cpp index 1ee17b8d5f9..dee4673373b 100644 --- a/src/map/packets/party_search.cpp +++ b/src/map/packets/party_search.cpp @@ -19,8 +19,6 @@ =========================================================================== */ -#include "common/socket.h" - #include "party_search.h" #include "entities/charentity.h" diff --git a/src/map/packets/pet_sync.cpp b/src/map/packets/pet_sync.cpp index 352a9a5c9dc..c896043e7dd 100644 --- a/src/map/packets/pet_sync.cpp +++ b/src/map/packets/pet_sync.cpp @@ -19,7 +19,6 @@ =========================================================================== */ -#include "common/socket.h" #include "common/utils.h" #include "pet_sync.h" diff --git a/src/map/packets/position.cpp b/src/map/packets/position.cpp index 6da4ef6eb45..92519b3a2db 100644 --- a/src/map/packets/position.cpp +++ b/src/map/packets/position.cpp @@ -19,11 +19,9 @@ =========================================================================== */ -#include "common/socket.h" - +#include "position.h" #include "entities/baseentity.h" #include "entities/charentity.h" -#include "position.h" CPositionPacket::CPositionPacket(CBaseEntity* PEntity, position_t position, POSMODE mode) { diff --git a/src/map/packets/quest_mission_log.cpp b/src/map/packets/quest_mission_log.cpp index 5f8c94d0e4b..40c56d4aa95 100644 --- a/src/map/packets/quest_mission_log.cpp +++ b/src/map/packets/quest_mission_log.cpp @@ -19,8 +19,6 @@ =========================================================================== */ -#include "common/socket.h" - #include #include "entities/charentity.h" diff --git a/src/map/packets/release.cpp b/src/map/packets/release.cpp index 98e37fc3a46..5bfdbf1ddc6 100644 --- a/src/map/packets/release.cpp +++ b/src/map/packets/release.cpp @@ -19,10 +19,8 @@ =========================================================================== */ -#include "common/socket.h" - -#include "entities/charentity.h" #include "release.h" +#include "entities/charentity.h" CReleasePacket::CReleasePacket(CCharEntity* PChar, RELEASE_TYPE releaseType) { diff --git a/src/map/packets/roe_questlog.cpp b/src/map/packets/roe_questlog.cpp index 7a173b4893b..e8ac17ecd2f 100644 --- a/src/map/packets/roe_questlog.cpp +++ b/src/map/packets/roe_questlog.cpp @@ -19,8 +19,6 @@ =========================================================================== */ -#include "common/socket.h" - #include "roe_questlog.h" #include "entities/charentity.h" diff --git a/src/map/packets/roe_sparkupdate.cpp b/src/map/packets/roe_sparkupdate.cpp index ae19ec30614..ed722abd216 100644 --- a/src/map/packets/roe_sparkupdate.cpp +++ b/src/map/packets/roe_sparkupdate.cpp @@ -21,8 +21,6 @@ #include -#include "common/socket.h" - #include "roe_sparkupdate.h" #include "entities/charentity.h" diff --git a/src/map/packets/roe_update.cpp b/src/map/packets/roe_update.cpp index 1d5979c4480..8e6bcfdfe97 100644 --- a/src/map/packets/roe_update.cpp +++ b/src/map/packets/roe_update.cpp @@ -19,8 +19,6 @@ =========================================================================== */ -#include "common/socket.h" - #include "roe_update.h" #include "entities/charentity.h" diff --git a/src/map/packets/send_blacklist.cpp b/src/map/packets/send_blacklist.cpp index e644a102d21..3647a6827b4 100644 --- a/src/map/packets/send_blacklist.cpp +++ b/src/map/packets/send_blacklist.cpp @@ -19,8 +19,6 @@ =========================================================================== */ -#include "common/socket.h" - #include #include "entities/charentity.h" diff --git a/src/map/packets/server_ip.cpp b/src/map/packets/server_ip.cpp index 02bef20f17e..a76f8ad19bf 100644 --- a/src/map/packets/server_ip.cpp +++ b/src/map/packets/server_ip.cpp @@ -19,10 +19,8 @@ =========================================================================== */ -#include "common/socket.h" - -#include "entities/charentity.h" #include "server_ip.h" +#include "entities/charentity.h" #include "utils/zoneutils.h" CServerIPPacket::CServerIPPacket(CCharEntity* PChar, uint8 zone_type, IPP zone_ipp) diff --git a/src/map/packets/server_message.cpp b/src/map/packets/server_message.cpp index ac0882831d7..6ae7d0269ed 100644 --- a/src/map/packets/server_message.cpp +++ b/src/map/packets/server_message.cpp @@ -20,7 +20,6 @@ */ #include "server_message.h" -#include "common/socket.h" #include diff --git a/src/map/packets/shop_appraise.cpp b/src/map/packets/shop_appraise.cpp index c0b43c2997c..03db47d4ecf 100644 --- a/src/map/packets/shop_appraise.cpp +++ b/src/map/packets/shop_appraise.cpp @@ -19,8 +19,6 @@ =========================================================================== */ -#include "common/socket.h" - #include "shop_appraise.h" CShopAppraisePacket::CShopAppraisePacket(uint8 slotID, uint32 sellPrice) diff --git a/src/map/packets/shop_buy.cpp b/src/map/packets/shop_buy.cpp index 70712ff01a2..b9b2f5aa5bb 100644 --- a/src/map/packets/shop_buy.cpp +++ b/src/map/packets/shop_buy.cpp @@ -19,8 +19,6 @@ =========================================================================== */ -#include "common/socket.h" - #include "shop_buy.h" CShopBuyPacket::CShopBuyPacket(uint8 slotID, uint32 quantity) diff --git a/src/map/packets/shop_items.cpp b/src/map/packets/shop_items.cpp index 4be7dbb6c8f..9d0ad59b886 100644 --- a/src/map/packets/shop_items.cpp +++ b/src/map/packets/shop_items.cpp @@ -19,8 +19,6 @@ =========================================================================== */ -#include "common/socket.h" - #include #include "entities/charentity.h" diff --git a/src/map/packets/shop_menu.cpp b/src/map/packets/shop_menu.cpp index 4c72a3c3053..20aa0945868 100644 --- a/src/map/packets/shop_menu.cpp +++ b/src/map/packets/shop_menu.cpp @@ -19,10 +19,8 @@ =========================================================================== */ -#include "common/socket.h" - -#include "entities/charentity.h" #include "shop_menu.h" +#include "entities/charentity.h" #include "trade_container.h" CShopMenuPacket::CShopMenuPacket(CCharEntity* PChar) diff --git a/src/map/packets/synth_animation.cpp b/src/map/packets/synth_animation.cpp index ce5e38c5144..20b51a81388 100644 --- a/src/map/packets/synth_animation.cpp +++ b/src/map/packets/synth_animation.cpp @@ -19,10 +19,8 @@ =========================================================================== */ -#include "common/socket.h" - -#include "entities/charentity.h" #include "synth_animation.h" +#include "entities/charentity.h" CSynthAnimationPacket::CSynthAnimationPacket(CCharEntity* PChar, uint16 effect, uint8 param) { diff --git a/src/map/packets/synth_message.cpp b/src/map/packets/synth_message.cpp index f507b46a026..06fc9e8a293 100644 --- a/src/map/packets/synth_message.cpp +++ b/src/map/packets/synth_message.cpp @@ -19,10 +19,8 @@ =========================================================================== */ -#include "common/socket.h" - -#include "entities/charentity.h" #include "synth_message.h" +#include "entities/charentity.h" #include "trade_container.h" CSynthMessagePacket::CSynthMessagePacket(CCharEntity* PChar, SYNTH_MESSAGE messageID, uint16 itemID, uint8 quantity) diff --git a/src/map/packets/synth_result.cpp b/src/map/packets/synth_result.cpp index 8ac27651143..8b0265f8d15 100644 --- a/src/map/packets/synth_result.cpp +++ b/src/map/packets/synth_result.cpp @@ -19,11 +19,9 @@ =========================================================================== */ -#include "common/socket.h" - +#include "synth_result.h" #include "entities/charentity.h" #include "synth_message.h" -#include "synth_result.h" #include "trade_container.h" CSynthResultMessagePacket::CSynthResultMessagePacket(CCharEntity* PChar, SYNTH_MESSAGE messageID, uint16 itemID, uint8 quantity) diff --git a/src/map/packets/synth_suggestion.cpp b/src/map/packets/synth_suggestion.cpp index bafde39f449..805fa1a431b 100644 --- a/src/map/packets/synth_suggestion.cpp +++ b/src/map/packets/synth_suggestion.cpp @@ -19,7 +19,6 @@ =========================================================================== */ -#include "common/socket.h" #include "map.h" #include "synth_suggestion.h" diff --git a/src/map/packets/trade_action.cpp b/src/map/packets/trade_action.cpp index 59f0d3529b8..d36c6fd3029 100644 --- a/src/map/packets/trade_action.cpp +++ b/src/map/packets/trade_action.cpp @@ -19,8 +19,6 @@ =========================================================================== */ -#include "common/socket.h" - #include "entities/charentity.h" #include "trade_action.h" diff --git a/src/map/packets/trade_item.cpp b/src/map/packets/trade_item.cpp index cb56da56259..16e8be366ac 100644 --- a/src/map/packets/trade_item.cpp +++ b/src/map/packets/trade_item.cpp @@ -19,8 +19,6 @@ =========================================================================== */ -#include "common/socket.h" - #include "utils/itemutils.h" #include "trade_item.h" diff --git a/src/map/packets/trade_request.cpp b/src/map/packets/trade_request.cpp index a08d7fbcab0..669291a2a94 100644 --- a/src/map/packets/trade_request.cpp +++ b/src/map/packets/trade_request.cpp @@ -19,8 +19,6 @@ =========================================================================== */ -#include "common/socket.h" - #include "entities/charentity.h" #include "trade_request.h" diff --git a/src/map/packets/trade_update.cpp b/src/map/packets/trade_update.cpp index fec3c6e86ac..72b12abbdac 100644 --- a/src/map/packets/trade_update.cpp +++ b/src/map/packets/trade_update.cpp @@ -21,7 +21,6 @@ #include "trade_update.h" -#include "common/socket.h" #include "common/utils.h" #include "common/vana_time.h" diff --git a/src/map/packets/treasure_lot_item.cpp b/src/map/packets/treasure_lot_item.cpp index 35b55bc1661..1df22e46f79 100644 --- a/src/map/packets/treasure_lot_item.cpp +++ b/src/map/packets/treasure_lot_item.cpp @@ -19,13 +19,12 @@ =========================================================================== */ -#include "common/socket.h" +#include "treasure_lot_item.h" + #include "common/utils.h" #include -#include "treasure_lot_item.h" - #include "entities/baseentity.h" CTreasureLotItemPacket::CTreasureLotItemPacket(uint8 slotID, ITEMLOTTYPE MessageType) diff --git a/src/map/packets/wide_scan.cpp b/src/map/packets/wide_scan.cpp index afb28b54cbe..0cb85356f14 100644 --- a/src/map/packets/wide_scan.cpp +++ b/src/map/packets/wide_scan.cpp @@ -19,12 +19,11 @@ =========================================================================== */ -#include "common/socket.h" +#include "wide_scan.h" #include #include "entities/charentity.h" -#include "wide_scan.h" CWideScanPacket::CWideScanPacket(WIDESCAN_STATUS status) { diff --git a/src/map/packets/wide_scan_track.cpp b/src/map/packets/wide_scan_track.cpp index 026bac9a955..21061582d16 100644 --- a/src/map/packets/wide_scan_track.cpp +++ b/src/map/packets/wide_scan_track.cpp @@ -19,12 +19,11 @@ =========================================================================== */ -#include "common/socket.h" +#include "wide_scan_track.h" #include #include "entities/baseentity.h" -#include "wide_scan_track.h" CWideScanTrackPacket::CWideScanTrackPacket(const CBaseEntity* PEntity) { diff --git a/src/map/packets/world_pass.cpp b/src/map/packets/world_pass.cpp index 1acb80de894..3b6871e83a6 100644 --- a/src/map/packets/world_pass.cpp +++ b/src/map/packets/world_pass.cpp @@ -19,9 +19,8 @@ =========================================================================== */ -#include "common/socket.h" - #include "world_pass.h" + #include CWorldPassPacket::CWorldPassPacket(uint32 WorldPass) diff --git a/src/map/packets/zone_visited.cpp b/src/map/packets/zone_visited.cpp index a8f8f049603..9e6ceadcec5 100644 --- a/src/map/packets/zone_visited.cpp +++ b/src/map/packets/zone_visited.cpp @@ -19,12 +19,11 @@ =========================================================================== */ -#include "common/socket.h" +#include "zone_visited.h" #include #include "entities/charentity.h" -#include "zone_visited.h" CZoneVisitedPacket::CZoneVisitedPacket(CCharEntity* PChar) { diff --git a/src/map/pch.h b/src/map/pch.h index c5686f56fc2..68091696d97 100644 --- a/src/map/pch.h +++ b/src/map/pch.h @@ -87,7 +87,7 @@ #include "common/macros.h" #include "common/md52.h" #include "common/mmo.h" -#include "common/socket.h" + #include "common/sql.h" #include "common/taskmgr.h" #include "common/timer.h" diff --git a/src/map/utils/charutils.cpp b/src/map/utils/charutils.cpp index ef795325c0b..5be954611cb 100644 --- a/src/map/utils/charutils.cpp +++ b/src/map/utils/charutils.cpp @@ -21,7 +21,6 @@ #include "common/logging.h" #include "common/macros.h" -#include "common/socket.h" #include "common/sql.h" #include "common/timer.h" #include "common/utils.h" diff --git a/src/map/utils/synthutils.cpp b/src/map/utils/synthutils.cpp index d5ff40507a7..bfefdb6e6ce 100644 --- a/src/map/utils/synthutils.cpp +++ b/src/map/utils/synthutils.cpp @@ -23,7 +23,6 @@ #include "common/database.h" #include "common/logging.h" -#include "common/socket.h" #include "common/utils.h" #include "common/vana_time.h" diff --git a/src/map/zone.cpp b/src/map/zone.cpp index d90141e1c73..35cb9c61cea 100644 --- a/src/map/zone.cpp +++ b/src/map/zone.cpp @@ -26,7 +26,7 @@ #include "zone.h" #include "common/logging.h" -#include "common/socket.h" + #include "common/timer.h" #include "common/utils.h" #include "common/vana_time.h" diff --git a/src/search/CMakeLists.txt b/src/search/CMakeLists.txt index 1914ddf28c3..90217a89279 100644 --- a/src/search/CMakeLists.txt +++ b/src/search/CMakeLists.txt @@ -17,9 +17,7 @@ set(SOURCES # TODO: Remove this block list(REMOVE_ITEM SOURCES ${CMAKE_SOURCE_DIR}/src/common/kernel.cpp - ${CMAKE_SOURCE_DIR}/src/common/kernel.h - ${CMAKE_SOURCE_DIR}/src/common/socket.cpp - ${CMAKE_SOURCE_DIR}/src/common/socket.h) + ${CMAKE_SOURCE_DIR}/src/common/kernel.h) if(UNIX) set(resource "") diff --git a/src/search/packets/auction_history.cpp b/src/search/packets/auction_history.cpp index 5ba2560a957..991bf1cbe82 100644 --- a/src/search/packets/auction_history.cpp +++ b/src/search/packets/auction_history.cpp @@ -21,7 +21,7 @@ #include #include "common/logging.h" -#include "common/socket.h" +#include "common/utils.h" #include "data_loader.h" diff --git a/src/search/packets/auction_list.cpp b/src/search/packets/auction_list.cpp index 12095ea5316..ad3dfc33fef 100644 --- a/src/search/packets/auction_list.cpp +++ b/src/search/packets/auction_list.cpp @@ -21,7 +21,7 @@ #include #include "common/logging.h" -#include "common/socket.h" +#include "common/utils.h" #include "data_loader.h" diff --git a/src/search/packets/linkshell_list.cpp b/src/search/packets/linkshell_list.cpp index dc301f16091..af25fd8f15c 100644 --- a/src/search/packets/linkshell_list.cpp +++ b/src/search/packets/linkshell_list.cpp @@ -20,7 +20,6 @@ */ #include "common/logging.h" -#include "common/socket.h" #include "common/utils.h" #include "data_loader.h" diff --git a/src/search/packets/party_list.cpp b/src/search/packets/party_list.cpp index 0899a9e77eb..6009cd9dea1 100644 --- a/src/search/packets/party_list.cpp +++ b/src/search/packets/party_list.cpp @@ -20,7 +20,6 @@ */ #include "common/logging.h" -#include "common/socket.h" #include "common/utils.h" #include "data_loader.h" diff --git a/src/search/packets/search_comment.cpp b/src/search/packets/search_comment.cpp index ccf4a54f5d7..2c37eb4774f 100644 --- a/src/search/packets/search_comment.cpp +++ b/src/search/packets/search_comment.cpp @@ -2,7 +2,6 @@ #include "search_comment.h" #include "common/logging.h" -#include "common/socket.h" #include "common/utils.h" SearchCommentPacket::SearchCommentPacket(uint32 playerId, std::string const& comment) diff --git a/src/search/packets/search_list.cpp b/src/search/packets/search_list.cpp index a00bb38791c..f344cb38fc2 100644 --- a/src/search/packets/search_list.cpp +++ b/src/search/packets/search_list.cpp @@ -20,7 +20,6 @@ */ #include "common/logging.h" -#include "common/socket.h" #include "common/utils.h" #include "data_loader.h" diff --git a/src/search/search.h b/src/search/search.h index c82047ea406..d89de3ed52b 100644 --- a/src/search/search.h +++ b/src/search/search.h @@ -68,8 +68,8 @@ class searchPacket { return buff_.data(); } -private: +private: std::array buff_; uint16_t size; }; diff --git a/src/search/search_handler.cpp b/src/search/search_handler.cpp index a9a076dccf0..4f7d08c6106 100644 --- a/src/search/search_handler.cpp +++ b/src/search/search_handler.cpp @@ -21,8 +21,7 @@ #include "search_handler.h" #include "common/md52.h" -#include "common/socket.h" // for ref -#include "common/utils.h" // for unpack/pack bits +#include "common/utils.h" #include "data_loader.h" #include #include diff --git a/src/world/CMakeLists.txt b/src/world/CMakeLists.txt index 45da55b3be0..eb5fdd2b208 100644 --- a/src/world/CMakeLists.txt +++ b/src/world/CMakeLists.txt @@ -30,9 +30,7 @@ set(SOURCES # TODO: Remove this block list(REMOVE_ITEM SOURCES ${CMAKE_SOURCE_DIR}/src/common/kernel.cpp - ${CMAKE_SOURCE_DIR}/src/common/kernel.h - ${CMAKE_SOURCE_DIR}/src/common/socket.cpp - ${CMAKE_SOURCE_DIR}/src/common/socket.h) + ${CMAKE_SOURCE_DIR}/src/common/kernel.h) if(UNIX) set(resource "") diff --git a/src/world/ipc_server.h b/src/world/ipc_server.h index c9b9f5a9a57..6fe71218f8c 100644 --- a/src/world/ipc_server.h +++ b/src/world/ipc_server.h @@ -24,7 +24,6 @@ #include "common/ipc.h" #include "common/ipp.h" #include "common/mmo.h" -#include "common/socket.h" #include "common/zmq_dealer_wrapper.h" #include "character_cache.h" From 54de4028489843ba01e4bd8f4b36143a1d528e16 Mon Sep 17 00:00:00 2001 From: Zach Toogood Date: Tue, 18 Mar 2025 10:29:53 +0000 Subject: [PATCH 2/2] Core: Introduce MapSocket --- src/common/ipp.h | 13 +- src/map/CMakeLists.txt | 4 +- src/map/map.cpp | 276 +++++++++++-------------------- src/map/map.h | 28 ++-- src/map/map_socket.cpp | 114 +++++++++++++ src/map/map_socket.h | 54 ++++++ src/map/packets/campaign_map.cpp | 4 +- src/map/packets/campaign_map.h | 4 +- src/map/packets/synth_result.h | 4 + 9 files changed, 296 insertions(+), 205 deletions(-) create mode 100644 src/map/map_socket.cpp create mode 100644 src/map/map_socket.h diff --git a/src/common/ipp.h b/src/common/ipp.h index 086c3569002..9821806c83c 100644 --- a/src/common/ipp.h +++ b/src/common/ipp.h @@ -27,17 +27,11 @@ #include #include -#include -#include -#include - -#include - #ifdef _WIN32 #include #include #include -#else // NOT _WIN32 +#else #include #include #include @@ -50,9 +44,12 @@ #include #include #include -#endif // _WIN32 +#endif #include +#include +#include +#include #include #include #include diff --git a/src/map/CMakeLists.txt b/src/map/CMakeLists.txt index c59b235dda1..e8558976285 100644 --- a/src/map/CMakeLists.txt +++ b/src/map/CMakeLists.txt @@ -77,12 +77,12 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/linkshell.h ${CMAKE_CURRENT_SOURCE_DIR}/map.cpp ${CMAKE_CURRENT_SOURCE_DIR}/map.h - ${CMAKE_CURRENT_SOURCE_DIR}/map_networking.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/map_networking.h ${CMAKE_CURRENT_SOURCE_DIR}/map_session_container.cpp ${CMAKE_CURRENT_SOURCE_DIR}/map_session_container.h ${CMAKE_CURRENT_SOURCE_DIR}/map_session.cpp ${CMAKE_CURRENT_SOURCE_DIR}/map_session.h + ${CMAKE_CURRENT_SOURCE_DIR}/map_socket.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/map_socket.h ${CMAKE_CURRENT_SOURCE_DIR}/merit.cpp ${CMAKE_CURRENT_SOURCE_DIR}/merit.h ${CMAKE_CURRENT_SOURCE_DIR}/mob_modifier.h diff --git a/src/map/map.cpp b/src/map/map.cpp index 04754117a8e..7d9816a7b4f 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -28,7 +28,6 @@ #include "common/debug.h" #include "common/ipp.h" #include "common/logging.h" -#include "common/socket.h" #include "common/timer.h" #include "common/utils.h" #include "common/vana_time.h" @@ -103,18 +102,18 @@ std::unordered_map gProcessLoaded; +// TODO: This should eventually live inside a MapNetworking class +std::unique_ptr gMapSocket; + +// Forward declare +void handle_incoming_packet(const std::error_code& ec, std::span buffer, IPP ipp); + namespace { - // Map UDP socket file descriptor - int32 map_fd = 0; - // Map udp buffers - NetworkBuffer PBuff; // Global packet clipboard - NetworkBuffer PBuffCopy; // Copy of above, used to decrypt a second time if necessary. - NetworkBuffer PScratchBuff; // Temporary packet clipboard - - // ZMQ message thread - nonstd::jthread messageThread; + NetworkBuffer PBuff; // Global packet clipboard + NetworkBuffer PBuffCopy; // Copy of above, used to decrypt a second time if necessary. + NetworkBuffer PScratchBuffer; // Temporary packet clipboard // Runtime statistics uint32 TotalPacketsToSendPerTick = 0U; @@ -191,12 +190,6 @@ void initConsoleService() // clang-format on } -/************************************************************************ - * * - * do_init * - * * - ************************************************************************/ - int32 do_init(int32 argc, char** argv) { TracyZoneScoped; @@ -275,9 +268,6 @@ int32 do_init(int32 argc, char** argv) ShowInfo("do_init: loading plants"); gardenutils::Initialize(); - // One method to initialize all data in battleutils - // and one method to free this data - ShowInfo("do_init: loading spells"); spell::LoadSpellList(); mobSpellList::LoadMobSpellList(); @@ -323,8 +313,8 @@ int32 do_init(int32 argc, char** argv) monstrosity::LoadStaticData(); - ShowInfo("do_init: server is binding with port %u", gMapIPP.getPort() == 0 ? settings::get("network.MAP_PORT") : gMapIPP.getPort()); - map_fd = makeBind_udp(INADDR_ANY, gMapIPP.getPort() == 0 ? settings::get("network.MAP_PORT") : gMapIPP.getPort()); + const auto udpPort = gMapIPP.getPort() == 0 ? settings::get("network.MAP_PORT") : gMapIPP.getPort(); + gMapSocket = std::make_unique(udpPort); CVanaTime::getInstance()->setCustomEpoch(settings::get("map.VANADIEL_TIME_EPOCH")); @@ -341,8 +331,8 @@ int32 do_init(int32 argc, char** argv) ShowInfo("do_init: Removing expired database variables"); uint32 currentTimestamp = CVanaTime::getInstance()->getSysTime(); - _sql->Query("DELETE FROM char_vars WHERE expiry > 0 AND expiry <= %d", currentTimestamp); - _sql->Query("DELETE FROM server_variables WHERE expiry > 0 AND expiry <= %d", currentTimestamp); + db::preparedStmt("DELETE FROM char_vars WHERE expiry > 0 AND expiry <= ?", currentTimestamp); + db::preparedStmt("DELETE FROM server_variables WHERE expiry > 0 AND expiry <= ?", currentTimestamp); PacketGuard::Init(); @@ -368,11 +358,6 @@ int32 do_init(int32 argc, char** argv) return 0; } -/************************************************************************ - * * - * do_final * - * * - ************************************************************************/ void do_final(int code) { TracyZoneScoped; @@ -391,11 +376,6 @@ void do_final(int code) trustutils::FreeTrustList(); zoneutils::FreeZoneList(); - if (messageThread.joinable()) - { - messageThread.join(); - } - CTaskMgr::delInstance(); CVanaTime::delInstance(); Async::delInstance(); @@ -405,25 +385,12 @@ void do_final(int code) luautils::cleanup(); logging::ShutDown(); -#ifdef WIN32 - shutdown(map_fd, SD_SEND); -#else - shutdown(map_fd, SHUT_WR); -#endif - close(map_fd); - if (code != EXIT_SUCCESS) { std::exit(code); } } -/************************************************************************ - * * - * do_abort * - * * - ************************************************************************/ - void do_abort() { do_final(EXIT_FAILURE); @@ -467,107 +434,83 @@ void ReportTracyStats() TotalPacketsDelayedPerTick = 0; } -/************************************************************************ - * * - * do_sockets * - * * - ************************************************************************/ - -int32 do_sockets(fd_set* rfd, duration next) +void handle_incoming_packet(const std::error_code& ec, std::span buffer, IPP ipp) { - message::handle_incoming(); - - timeval timeout{}; - int32 ret = 0; - std::memcpy(rfd, &readfds, sizeof(*rfd)); - - timeout.tv_sec = std::chrono::duration_cast(next).count(); - timeout.tv_usec = std::chrono::duration_cast(next - std::chrono::duration_cast(next)).count(); - - ret = sSelect(fd_max, rfd, nullptr, nullptr, &timeout); - if (ret == SOCKET_ERROR) + if (!ec && !buffer.empty()) { - if (sErrno != S_EINTR) + // find player session + MapSession* map_session_data = gMapSessions.getSessionByIPP(ipp); + if (map_session_data == nullptr) { - ShowCritical("do_sockets: select() failed, error code %d!", sErrno); - do_final(EXIT_FAILURE); + map_session_data = gMapSessions.createSession(ipp); + if (map_session_data == nullptr) + { + gMapSessions.destroySession(ipp); + return; + } } - return 0; // interrupted by a signal, just loop and try again - } - last_tick = time(nullptr); + // TODO: Don't copy into PBuff, use buffer directly and smaller scratch buffers if required + std::memcpy(PBuff.data(), buffer.data(), buffer.size()); + size_t size = buffer.size(); - if (sFD_ISSET(map_fd, rfd)) - { - sockaddr_in from{}; - socklen_t fromlen = sizeof(from); - - ret = recvudp(map_fd, PBuff.data(), kMaxBufferSize, 0, (struct sockaddr*)&from, &fromlen); - if (ret != -1) + int32 decryptCount = recv_parse(PBuff.data(), &size, map_session_data); + if (decryptCount != -1) { - const auto ip = sockaddr2netip(from); - const auto port = sockaddr2hostport(from); - const auto ipp = IPP(ip, port); - - // find player char - MapSession* map_session_data = gMapSessions.getSessionByIPP(ipp); - if (map_session_data == nullptr) + // DecryptCount of 0 means the main key decrypted the packet + if (decryptCount == 0) { - map_session_data = gMapSessions.createSession(ipp); - if (map_session_data == nullptr) + // If the previous package was lost, then we do not collect a new one, + // and send the previous packet again + if (!parse(PBuff.data(), &size, map_session_data)) { - gMapSessions.destroySession(ipp); - return -1; + send_parse(PBuff.data(), &size, map_session_data, false); } } - - size_t size = ret; - - int32 decryptCount = recv_parse(PBuff.data(), &size, &from, map_session_data); - if (decryptCount != -1) + else if (decryptCount == 1 && map_session_data->blowfish.status == BLOWFISH_PENDING_ZONE) { - // DecryptCount of 0 means the main key decrypted the packet - if (decryptCount == 0) + // TODO: Client will send 0x00D in response to 0x00B, so we are probably always sending an extra 0x00B when we don't need to. + // However, the client will fail to decrypt this if they received it before, effectively being a no-op. + // It could be beneficial to parse 0x00D here anyway. + + // Client failed to receive 0x00B, resend it + if (auto PChar = map_session_data->PChar) { - // If the previous package was lost, then we do not collect a new one, - // and send the previous packet again - if (!parse(PBuff.data(), &size, &from, map_session_data)) - { - send_parse(PBuff.data(), &size, &from, map_session_data, false); - } + PChar->clearPacketList(); + PChar->pushPacket(PChar, map_session_data->zone_type, map_session_data->zone_ipp); } - else if (decryptCount == 1 && map_session_data->blowfish.status == BLOWFISH_PENDING_ZONE) - { - // TODO: Client will send 0x00D in response to 0x00B, so we are probably always sending an extra 0x00B when we don't need to. - // However, the client will fail to decrypt this if they received it before, effectively being a no-op. - // It could be beneficial to parse 0x00D here anyway. - // Client failed to receive 0x00B, resend it - if (auto PChar = map_session_data->PChar) - { - PChar->clearPacketList(); - PChar->pushPacket(PChar, map_session_data->zone_type, map_session_data->zone_ipp); - } - send_parse(PBuff.data(), &size, &from, map_session_data, true); + send_parse(PBuff.data(), &size, map_session_data, true); - // Increment sync count with every packet - // TODO: match incoming with a new parse that only cares about sync count - map_session_data->server_packet_id += 1; - } + // Increment sync count with every packet + // TODO: match incoming with a new parse that only cares about sync count + map_session_data->server_packet_id += 1; + } - ret = sendudp(map_fd, PBuff.data(), size, 0, (const struct sockaddr*)&from, fromlen); + gMapSocket->send(ipp, { PBuff.data(), size }); - std::swap(PBuff, map_session_data->server_packet_data); - std::swap(size, map_session_data->server_packet_size); - } + std::swap(PBuff, map_session_data->server_packet_data); + std::swap(size, map_session_data->server_packet_size); + } - // If client is logging out, just close it. - if (map_session_data->shuttingDown == 1) - { - gMapSessions.destroySession(map_session_data); - } + // If client is logging out, just close it. + if (map_session_data->shuttingDown == 1) + { + gMapSessions.destroySession(map_session_data); } } + else if (ec) + { + ShowErrorFmt("Receive error: {}", ec.message()); + } +} + +int32 do_sockets(duration next) +{ + message::handle_incoming(); + + const auto duration = std::chrono::duration_cast(next - std::chrono::duration_cast(next)); + gMapSocket->recvFor(duration, &handle_incoming_packet); ReportTracyStats(); @@ -576,13 +519,7 @@ int32 do_sockets(fd_set* rfd, duration next) return 0; } -/************************************************************************ - * * - * map_decipher_packet * - * * - ************************************************************************/ - -int32 map_decipher_packet(uint8* buff, size_t size, sockaddr_in* from, MapSession* PSession, blowfish_t* pbfkey) +int32 map_decipher_packet(uint8* buff, size_t buffsize, MapSession* PSession, blowfish_t* pbfkey) { TracyZoneScoped; @@ -590,17 +527,17 @@ int32 map_decipher_packet(uint8* buff, size_t size, sockaddr_in* from, MapSessio uint16 i = 0; // counting blocks whose size = 4 byte - tmp = (uint16)((size - FFXI_HEADER_SIZE) / 4); + tmp = (uint16)((buffsize - FFXI_HEADER_SIZE) / 4); tmp -= tmp % 2; - const auto ip = sockaddr2netip(*from); + const auto ip = PSession->client_ipp.getIP(); for (i = 0; i < tmp; i += 2) { blowfish_decipher((uint32*)buff + i + 7, (uint32*)buff + i + 8, pbfkey->P, pbfkey->S[0]); } - if (checksum((uint8*)(buff + FFXI_HEADER_SIZE), (uint32)(size - (FFXI_HEADER_SIZE + 16)), (char*)(buff + size - 16)) == 0) + if (checksum((uint8*)(buff + FFXI_HEADER_SIZE), (uint32)(buffsize - (FFXI_HEADER_SIZE + 16)), (char*)(buff + buffsize - 16)) == 0) { return 0; } @@ -610,16 +547,11 @@ int32 map_decipher_packet(uint8* buff, size_t size, sockaddr_in* from, MapSessio { ShowError(fmt::format("map_decipher_packet: bad packet from <{}>", ip2str(ip))); } + return -1; } -/************************************************************************ - * * - * main function to parse recv packets * - * * - ************************************************************************/ - -int32 recv_parse(uint8* buff, size_t* buffsize, sockaddr_in* from, MapSession* map_session_data) +int32 recv_parse(uint8* buff, size_t* buffsize, MapSession* map_session_data) { TracyZoneScoped; @@ -735,14 +667,15 @@ int32 recv_parse(uint8* buff, size_t* buffsize, sockaddr_in* from, MapSession* m // Copy buff into the backup buffer. Blowfish can't be rewound currently. std::memcpy(PBuffCopy.data(), buff, *buffsize); } + int decryptCount = 0; - // char packets - if (map_decipher_packet(buff, *buffsize, from, map_session_data, &map_session_data->blowfish) == -1) + + if (map_decipher_packet(buff, *buffsize, map_session_data, &map_session_data->blowfish) == -1) { // If the client is pending zone, they might not have received 0x00B, and thus not incremented their key // Check old blowfish data if (map_session_data->blowfish.status == BLOWFISH_PENDING_ZONE && - map_decipher_packet(PBuffCopy.data(), *buffsize, from, map_session_data, &map_session_data->prev_blowfish) != -1) + map_decipher_packet(PBuffCopy.data(), *buffsize, map_session_data, &map_session_data->prev_blowfish) != -1) { // Copy decrypted bytes back into buffer std::memcpy(buff, PBuffCopy.data(), *buffsize); @@ -759,14 +692,14 @@ int32 recv_parse(uint8* buff, size_t* buffsize, sockaddr_in* from, MapSession* m uint32 PacketDataSize = ref(buff, *buffsize - sizeof(int32) - 16); // it's decompressing data and getting new size - PacketDataSize = zlib_decompress((int8*)(buff + FFXI_HEADER_SIZE), PacketDataSize, (int8*)PScratchBuff.data(), kMaxBufferSize); + PacketDataSize = zlib_decompress((int8*)(buff + FFXI_HEADER_SIZE), PacketDataSize, (int8*)PScratchBuffer.data(), kMaxBufferSize); // Not sure why zlib_decompress is defined to return a uint32 when it returns -1 in situations. if (static_cast(PacketDataSize) != -1) { // it's making result buff // don't need std::memcpy header - std::memcpy(buff + FFXI_HEADER_SIZE, PScratchBuff.data(), PacketDataSize); + std::memcpy(buff + FFXI_HEADER_SIZE, PScratchBuffer.data(), PacketDataSize); *buffsize = FFXI_HEADER_SIZE + PacketDataSize; return decryptCount; @@ -774,15 +707,11 @@ int32 recv_parse(uint8* buff, size_t* buffsize, sockaddr_in* from, MapSession* m return decryptCount; } -} -/************************************************************************ - * * - * main function parsing the packets * - * * - ************************************************************************/ + // return -1; +} -int32 parse(uint8* buff, size_t* buffsize, sockaddr_in* from, MapSession* map_session_data) +int32 parse(uint8* buff, size_t* buffsize, MapSession* map_session_data) { TracyZoneScoped; @@ -893,10 +822,8 @@ int32 parse(uint8* buff, size_t* buffsize, sockaddr_in* from, MapSession* map_se if (ref(buff, 2) != map_session_data->server_packet_id) { - /* - * If the client and server have become out of sync, then caching takes place. However, caching - * zone packets will result in the client never properly connecting. Ignore those specifically. - */ + // If the client and server have become out of sync, then caching takes place. However, caching + // zone packets will result in the client never properly connecting. Ignore those specifically. if (SmallPD_Type == 0x0A) { return 0; @@ -920,13 +847,7 @@ int32 parse(uint8* buff, size_t* buffsize, sockaddr_in* from, MapSession* map_se return 0; } -/************************************************************************ - * * - * main function is building big packet * - * * - ************************************************************************/ - -int32 send_parse(uint8* buff, size_t* buffsize, sockaddr_in* from, MapSession* map_session_data, bool usePreviousKey) +int32 send_parse(uint8* buff, size_t* buffsize, MapSession* map_session_data, bool usePreviousKey) { TracyZoneScoped; @@ -1016,7 +937,7 @@ int32 send_parse(uint8* buff, size_t* buffsize, sockaddr_in* from, MapSession* m // Compress the data without regard to the header // The returned size is 8 times the real data - PacketSize = zlib_compress((int8*)(buff + FFXI_HEADER_SIZE), (uint32)(*buffsize - FFXI_HEADER_SIZE), (int8*)PScratchBuff.data(), kMaxBufferSize); + PacketSize = zlib_compress((int8*)(buff + FFXI_HEADER_SIZE), (uint32)(*buffsize - FFXI_HEADER_SIZE), (int8*)PScratchBuffer.data(), kMaxBufferSize); // handle compression error if (PacketSize == static_cast(-1)) @@ -1025,7 +946,7 @@ int32 send_parse(uint8* buff, size_t* buffsize, sockaddr_in* from, MapSession* m continue; } - ref(PScratchBuff.data(), zlib_compressed_size(PacketSize)) = PacketSize; + ref(PScratchBuffer.data(), zlib_compressed_size(PacketSize)) = PacketSize; PacketSize = (uint32)zlib_compressed_size(PacketSize) + 4; @@ -1045,23 +966,24 @@ int32 send_parse(uint8* buff, size_t* buffsize, sockaddr_in* from, MapSession* m } } } while (PacketSize == static_cast(-1)); + PChar->erasePackets(packets); TotalPacketsSentPerTick += packets; TracyZoneString(fmt::format("Sending {} packets", packets)); // Record data size excluding header uint8 hash[16]; - md5(PScratchBuff.data(), hash, PacketSize); - std::memcpy(PScratchBuff.data() + PacketSize, hash, 16); + md5(PScratchBuffer.data(), hash, PacketSize); + std::memcpy(PScratchBuffer.data() + PacketSize, hash, 16); PacketSize += 16; if (PacketSize > kMaxBufferSize) { - ShowCritical("Memory manager: PScratchBuff is overflowed (%u)", PacketSize); + ShowCritical("Network: PScratchBuffer is overflowed (%u) by %s", PacketSize, PChar->name); } - // Making total packet - std::memcpy(buff + FFXI_HEADER_SIZE, PScratchBuff.data(), PacketSize); + // Making total outgoing packet + std::memcpy(buff + FFXI_HEADER_SIZE, PScratchBuffer.data(), PacketSize); uint32 CypherSize = (PacketSize / 4) & -2; @@ -1089,7 +1011,6 @@ int32 send_parse(uint8* buff, size_t* buffsize, sockaddr_in* from, MapSession* m char session_key[20 * 2 + 1]; bin2hex(session_key, (uint8*)map_session_data->blowfish.key, 20); const char* fmtQuery = "UPDATE accounts_sessions SET session_key = x'%s' WHERE charid = %u"; - _sql->Query(fmtQuery, session_key, PChar->id); } @@ -1124,13 +1045,6 @@ int32 send_parse(uint8* buff, size_t* buffsize, sockaddr_in* from, MapSession* m return 0; } -/************************************************************************ - * * - * Timer function that cleans up all timed out players * - * and removes stale dynamic targIDs after some time * - * * - ************************************************************************/ - int32 map_cleanup(time_point tick, CTaskMgr::CTask* PTask) { TracyZoneScoped; diff --git a/src/map/map.h b/src/map/map.h index c506d01f71c..9ba8f098505 100644 --- a/src/map/map.h +++ b/src/map/map.h @@ -19,8 +19,7 @@ =========================================================================== */ -#ifndef _MAP_H -#define _MAP_H +#pragma once #include "common/cbasetypes.h" @@ -28,7 +27,6 @@ #include "common/kernel.h" #include "common/md52.h" #include "common/mmo.h" -#include "common/socket.h" #include "common/sql.h" #include "common/taskmgr.h" #include "common/xirand.h" @@ -40,25 +38,35 @@ #include "map_constants.h" #include "map_session.h" #include "map_session_container.h" +#include "map_socket.h" #include "zone.h" // // Exposed globals // +// TODO: These will eventually be members of the MapServer class extern MapSessionContainer gMapSessions; extern IPP gMapIPP; extern std::unique_ptr _sql; extern bool gLoadAllLua; +extern std::unique_ptr gMapSocket; -//======================================================================= +// +// Networking +// -int32 recv_parse(uint8* buff, size_t* buffsize, sockaddr_in* from, MapSession*); // main function to parse recv packets -int32 parse(uint8* buff, size_t* buffsize, sockaddr_in* from, MapSession*); // main function parsing the packets -int32 send_parse(uint8* buff, size_t* buffsize, sockaddr_in* from, MapSession*, bool usePreviousKey); // main function is building big packet +// TODO: Pass around std::span instead of uint8* and size_t* +// TODO: Stop changing the buffsize size_t as we go along +// TODO: Replace bool with named enum class +int32 map_decipher_packet(uint8*, size_t, MapSession*, blowfish_t*); // Decipher packet +int32 recv_parse(uint8*, size_t*, MapSession*); // main function to parse recv packets +int32 parse(uint8*, size_t*, MapSession*); // main function parsing the packets +int32 send_parse(uint8*, size_t*, MapSession*, bool); // main function is building big packet -int32 map_cleanup(time_point tick, CTaskMgr::CTask* PTask); // Clean up timed out players +// +// Maintenance +// +int32 map_cleanup(time_point tick, CTaskMgr::CTask* PTask); // Clean up timed out players int32 map_garbage_collect(time_point tick, CTaskMgr::CTask* PTask); - -#endif //_MAP_H diff --git a/src/map/map_socket.cpp b/src/map/map_socket.cpp new file mode 100644 index 00000000000..c4a70b38ab1 --- /dev/null +++ b/src/map/map_socket.cpp @@ -0,0 +1,114 @@ +/* +=========================================================================== + + Copyright (c) 2025 LandSandBoat Dev Teams + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see http://www.gnu.org/licenses/ + +=========================================================================== +*/ + +#include "map_socket.h" + +MapSocket::MapSocket(uint16 port) +: port_(port) +, socket_(io_context_) +{ + TracyZoneScoped; +} + +MapSocket::~MapSocket() +{ + TracyZoneScoped; + + if (socket_.is_open()) + { + socket_.close(); + } +} + +void MapSocket::startReceive(ReceiveFn onReceiveFn) +{ + TracyZoneScoped; + + socket_.async_receive_from( + asio::buffer(buffer_), remote_endpoint_, + [this, onReceiveFn](const std::error_code& ec, std::size_t bytes_recvd) + { + // NOTE: ASIO returns the address in host byte order, but we store it in network byte order, + // : so we convert it back. + const auto sender_ip = htonl(remote_endpoint_.address().to_v4().to_uint()); + const auto sender_port = remote_endpoint_.port(); + const auto ipp = IPP(sender_ip, sender_port); + + const auto buffer = std::span(buffer_.data(), bytes_recvd); + + DebugPacketsFmt("Received {} bytes from {}", buffer.size(), ipp.toString()); + + onReceiveFn(ec, buffer, ipp); + + startReceive(onReceiveFn); // Queue up more work + }); +} + +void MapSocket::recvFor(duration duration, ReceiveFn onReceiveFn) +{ + TracyZoneScoped; + + // Lazy initialization of the socket + if (!socket_.is_open()) + { + ShowInfoFmt("MapSocket: Starting on port {}", port_); + + asio::ip::udp::endpoint listen_endpoint(asio::ip::udp::v4(), port_); + socket_.open(listen_endpoint.protocol()); + socket_.bind(listen_endpoint); + + // Queue up first work + startReceive(onReceiveFn); + } + + io_context_.run_for(duration); // Blocks until the duration is up + + // Once run_for() or run() return the io_context enters a stopped state, + // even if there are still pending asynchronous operations. You need to + // call restart() to clear that state before you can run it again. + io_context_.restart(); +} + +void MapSocket::send(const IPP& ipp, std::span buffer) +{ + TracyZoneScoped; + + DebugPacketsFmt("Sending {} bytes to {}", buffer.size(), ipp.toString()); + + // Like with the ip from startReceive(), ASIO is expecting us to be handling it + // in host byte order, but we store it in network byte order. So, we need to convert it. + const auto ip = ntohl(ipp.getIP()); + const auto endpoint = asio::ip::udp::endpoint(asio::ip::address_v4(ip), ipp.getPort()); + + // clang-format off + socket_.async_send_to(asio::buffer(buffer), endpoint, + [](const std::error_code& ec, std::size_t /*bytes_sent*/) + { + if (ec) + { + ShowErrorFmt("Error sending data: {}", ec.message()); + } + }); + // clang-format on + + // This will only be called in the middle of a doSocketsFor() call, so we don't + // need to enqueue more work when we're done here. +} diff --git a/src/map/map_socket.h b/src/map/map_socket.h new file mode 100644 index 00000000000..ba8e5812fbb --- /dev/null +++ b/src/map/map_socket.h @@ -0,0 +1,54 @@ +/* +=========================================================================== + + Copyright (c) 2025 LandSandBoat Dev Teams + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see http://www.gnu.org/licenses/ + +=========================================================================== +*/ + +#pragma once + +#include "common/blowfish.h" +#include "common/cbasetypes.h" +#include "common/ipp.h" + +#include "map_constants.h" + +#include +#include +#include +#include + +class MapSocket +{ +public: + using ReceiveFn = std::function, IPP)>; + + MapSocket(uint16 port); + ~MapSocket(); + + void recvFor(duration duration, ReceiveFn onReceiveFn); + void send(const IPP& ipp, std::span buffer); + +private: + void startReceive(ReceiveFn onReceiveFn); + + uint16 port_; + asio::io_context io_context_; // TODO: Use Application::io_context_ when available + asio::ip::udp::socket socket_; + NetworkBuffer buffer_; // TODO: Pass in the global buffer, or only use this one + asio::ip::udp::endpoint remote_endpoint_; +}; diff --git a/src/map/packets/campaign_map.cpp b/src/map/packets/campaign_map.cpp index 4add8aba182..b6ab7578c6f 100644 --- a/src/map/packets/campaign_map.cpp +++ b/src/map/packets/campaign_map.cpp @@ -107,7 +107,7 @@ CCampaignPacket::CCampaignPacket(CCharEntity* PChar, CampaignState const& state, } } -void CCampaignPacket::SetRegions(std::vector regions, int start) +void CCampaignPacket::SetRegions(const std::vector& regions, int start) { for (int i = start; i < start + 13; i++) { @@ -123,7 +123,7 @@ void CCampaignPacket::SetRegions(std::vector regions, int start) } } -void CCampaignPacket::SetNations(std::vector nations) +void CCampaignPacket::SetNations(const std::vector& nations) { for (int i = 0; i < 7; i++) { diff --git a/src/map/packets/campaign_map.h b/src/map/packets/campaign_map.h index 5561c34007c..c6342ec2578 100644 --- a/src/map/packets/campaign_map.h +++ b/src/map/packets/campaign_map.h @@ -35,8 +35,8 @@ class CCampaignPacket : public CBasicPacket CCampaignPacket(CCharEntity* PChar, CampaignState const& state, uint8 number); private: - void SetRegions(std::vector areas, int start = 0); - void SetNations(std::vector nations); + void SetRegions(const std::vector& areas, int start = 0); + void SetNations(const std::vector& nations); }; #endif diff --git a/src/map/packets/synth_result.h b/src/map/packets/synth_result.h index a36def0a4cc..a58abce9011 100644 --- a/src/map/packets/synth_result.h +++ b/src/map/packets/synth_result.h @@ -23,10 +23,14 @@ #define _CSYNTHRESULTMESSAGEPACKET_H #include "common/cbasetypes.h" +#include "common/utils.h" + +#include "packets/synth_message.h" #include "basic.h" class CBaseEntity; +class CCharEntity; class CSynthResultMessagePacket : public CBasicPacket {