diff --git a/CMakeLists.txt b/CMakeLists.txt index 5befe9a..408e568 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -70,6 +70,7 @@ endif() add_subdirectory(conf) add_subdirectory(files) +add_subdirectory(lib/fmt) add_subdirectory(man) add_subdirectory(src) if(WITH_LUA) diff --git a/lib/fmt/CMakeLists.txt b/lib/fmt/CMakeLists.txt index 8a7030c..e559e74 100644 --- a/lib/fmt/CMakeLists.txt +++ b/lib/fmt/CMakeLists.txt @@ -11,4 +11,10 @@ set(FMT_SOURCES ${FMT_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/time.h ) -add_library(fmt STATIC ${FMT_SOURCES}) \ No newline at end of file +add_library(fmt ${FMT_SOURCES}) + +target_include_directories(fmt + PUBLIC + $ + $ +) \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1204505..7ede5d5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -37,7 +37,6 @@ if (WITH_WIN32_GUI) endif (WITH_WIN32_GUI) subdirs(compat common win32 bntrackd client bniutils bnpass) -include_directories(${CMAKE_SOURCE_DIR}/lib) if(WITH_BNETD) add_subdirectory(bnetd) diff --git a/src/bnetd/CMakeLists.txt b/src/bnetd/CMakeLists.txt index bf57408..9492d87 100644 --- a/src/bnetd/CMakeLists.txt +++ b/src/bnetd/CMakeLists.txt @@ -53,9 +53,14 @@ else(WITH_WIN32_GUI) add_executable(bnetd ${BNETD_SOURCES} ${BNETD_CONSOLE_RESOURCES}) endif(WITH_WIN32_GUI) -target_include_directories(bnetd PUBLIC ${CMAKE_SOURCE_DIR}/fmt) +target_include_directories(bnetd + PUBLIC + $ + $ + PRIVATE + ${CMAKE_SOURCE_DIR}/src +) -target_link_libraries(bnetd PUBLIC fmt common compat win32 ${NETWORK_LIBRARIES} - ${ZLIB_LIBRARIES} ${MYSQL_LIBRARIES} ${SQLITE3_LIBRARIES} ${PGSQL_LIBRARIES} ${ODBC_LIBRARIES} ${LUA_LIBRARIES}) +target_link_libraries(bnetd common compat fmt win32 ${NETWORK_LIBRARIES} ${ZLIB_LIBRARIES} ${MYSQL_LIBRARIES} ${SQLITE3_LIBRARIES} ${PGSQL_LIBRARIES} ${ODBC_LIBRARIES} ${LUA_LIBRARIES}) - install(TARGETS bnetd DESTINATION ${SBINDIR}) +install(TARGETS bnetd DESTINATION ${SBINDIR}) diff --git a/src/bnetd/handle_bnet.cpp b/src/bnetd/handle_bnet.cpp index 63f71d5..d7e58b1 100644 --- a/src/bnetd/handle_bnet.cpp +++ b/src/bnetd/handle_bnet.cpp @@ -2923,7 +2923,7 @@ namespace pvpgn // read text from bnmotd_w3.txt { - fmt::MemoryWriter serverinfo; + fmt::memory_buffer serverinfo; std::string filename = i18n_filename(prefs_get_motdw3file(), conn_get_gamelang_localized(c)); std::FILE* fp = std::fopen(filename.c_str(), "r"); @@ -2932,7 +2932,7 @@ namespace pvpgn while (char* buff = file_get_line(fp)) { char* line = message_format_line(c, buff); - serverinfo << (line + 1) << '\n'; + fmt::format_to(serverinfo, "{}" + '\n', (line + 1)); xfree((void*)line); } @@ -2941,7 +2941,7 @@ namespace pvpgn eventlog(eventlog_level_error, __FUNCTION__, "could not close motdw3 file \"{}\" after reading (std::fopen: {})", filename, std::strerror(errno)); } } - packet_append_string(rpacket, serverinfo.c_str()); + packet_append_string(rpacket, fmt::to_string(serverinfo).c_str()); } conn_push_outqueue(c, rpacket); diff --git a/src/bnetd/i18n.h b/src/bnetd/i18n.h index 84a1135..5e5f973 100644 --- a/src/bnetd/i18n.h +++ b/src/bnetd/i18n.h @@ -18,6 +18,10 @@ #ifndef INCLUDED_LOCALIZATION_TYPES #define INCLUDED_LOCALIZATION_TYPES +#include + +#include "common/tag.h" + namespace pvpgn { namespace bnetd @@ -42,6 +46,7 @@ namespace pvpgn #define JUST_NEED_TYPES # include # include "connection.h" + #include #undef JUST_NEED_TYPES @@ -53,6 +58,8 @@ namespace pvpgn extern int i18n_load(void); extern int i18n_reload(void); + const char * _find_string(char const * text, t_gamelang gamelang); + extern std::string i18n_filename(const char * filename, t_tag gamelang); extern t_language language_find_by_country(const char * code, bool &found); extern t_language language_find_by_tag(t_gamelang gamelang, bool &found); @@ -70,21 +77,26 @@ namespace pvpgn template std::string _localize(t_connection * c, const char * func, fmt::string_view format_str, const Args& ... args) { - const char *format = fmt; - std::string output(fmt); - t_gamelang lang; - - if (!c) { + if (!c) + { eventlog(eventlog_level_error, __FUNCTION__, "got bad connection"); - return format; + return fmt::to_string(format_str); } + + std::string output; try { + t_gamelang lang; + const char *format = fmt::to_string(format_str).c_str(); if (lang = conn_get_gamelang_localized(c)) - if (!(format = _find_string(fmt, lang))) - format = fmt; // if not found use original + { + if (!(format = _find_string(fmt::to_string(format_str).c_str(), lang))) + { + format = fmt::to_string(format_str).c_str(); // if not found use original + } + } - output = fmt::format(format, args); + output = fmt::format(format, args...); char tmp[MAX_MESSAGE_LEN]; std::snprintf(tmp, sizeof tmp, "%s", output.c_str()); @@ -94,7 +106,7 @@ namespace pvpgn } catch (const std::exception& e) { - WARN2("Can't format translation string \"{}\" ({})", fmt, e.what()); + WARN2("Can't format translation string \"{}\" ({})", format_str, e.what()); } return output; diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index eacc22c..729c697 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -20,7 +20,15 @@ set(COMMON_SOURCES xstring.cpp xstring.h gui_printf.h gui_printf.cpp bigint.cpp bigint.h bnetsrp3.cpp bnetsrp3.h peerchat.cpp peerchat.h wol_gameres_protocol.h pugiconfig.h pugixml.cpp pugixml.h) -add_library(common - ${COMMON_SOURCES} + +add_library(common ${COMMON_SOURCES}) + +target_include_directories(common + PUBLIC + $ + $ + PRIVATE + ${CMAKE_SOURCE_DIR}/src ) -target_link_libraries(common fmt) \ No newline at end of file + +target_link_libraries(common PUBLIC fmt) \ No newline at end of file