Fix compilation
This commit is contained in:
parent
0a20cf448a
commit
0c6402841f
7 changed files with 53 additions and 22 deletions
|
@ -70,6 +70,7 @@ endif()
|
|||
|
||||
add_subdirectory(conf)
|
||||
add_subdirectory(files)
|
||||
add_subdirectory(lib/fmt)
|
||||
add_subdirectory(man)
|
||||
add_subdirectory(src)
|
||||
if(WITH_LUA)
|
||||
|
|
|
@ -11,4 +11,10 @@ set(FMT_SOURCES ${FMT_SOURCES}
|
|||
${CMAKE_CURRENT_SOURCE_DIR}/time.h
|
||||
)
|
||||
|
||||
add_library(fmt STATIC ${FMT_SOURCES})
|
||||
add_library(fmt ${FMT_SOURCES})
|
||||
|
||||
target_include_directories(fmt
|
||||
PUBLIC
|
||||
$<INSTALL_INTERFACE:lib>
|
||||
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/lib>
|
||||
)
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
$<INSTALL_INTERFACE:lib>
|
||||
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/lib>
|
||||
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})
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -18,6 +18,10 @@
|
|||
#ifndef INCLUDED_LOCALIZATION_TYPES
|
||||
#define INCLUDED_LOCALIZATION_TYPES
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "common/tag.h"
|
||||
|
||||
namespace pvpgn
|
||||
{
|
||||
namespace bnetd
|
||||
|
@ -42,6 +46,7 @@ namespace pvpgn
|
|||
#define JUST_NEED_TYPES
|
||||
# include <string>
|
||||
# include "connection.h"
|
||||
|
||||
#include <fmt/format.h>
|
||||
#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 <typename... Args>
|
||||
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;
|
||||
|
|
|
@ -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
|
||||
$<INSTALL_INTERFACE:lib>
|
||||
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/lib>
|
||||
PRIVATE
|
||||
${CMAKE_SOURCE_DIR}/src
|
||||
)
|
||||
target_link_libraries(common fmt)
|
||||
|
||||
target_link_libraries(common PUBLIC fmt)
|
Loading…
Reference in a new issue