From bcca812ecc1c50220d1588ae8b69c5962ad35e65 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 7 Apr 2019 13:11:02 +0200 Subject: [PATCH 01/20] Bug 2576: additional logging. increase log verbosity, decrease some log levels. --- scripts/eressea/tunnels.lua | 16 +++++++++++++--- src/creport.c | 9 ++++----- src/magic.c | 2 +- src/main.c | 4 ++-- src/reports.c | 2 +- 5 files changed, 21 insertions(+), 12 deletions(-) diff --git a/scripts/eressea/tunnels.lua b/scripts/eressea/tunnels.lua index 4a787a373..6b7a8e8d1 100644 --- a/scripts/eressea/tunnels.lua +++ b/scripts/eressea/tunnels.lua @@ -27,11 +27,21 @@ end local function tunnel_action(b, param) local units = tunnel_travelers(b) local rto = get_target(param) + eressea.log.info("Tunnel from " .. tostring(b) .. " [" .. param .. "]") if rto and units then - eressea.log.debug("Tunnel from " .. tostring(b) .. " [" .. param .. "]") - for key, u in pairs(units) do + for _, u in pairs(units) do u.region = rto - eressea.log.debug("teleported " .. tostring(u) .. " to " .. tostring(rto)) + eressea.log.info("teleported " .. tostring(u) .. " to " .. tostring(rto)) + end + elseif not units then + eressea.log.info("No units in tunnel " .. tostring(b) .. " [" .. param .. "]") + elseif not rto then + eressea.log.error("No target for tunnel " .. tostring(b) .. " [" .. param .. "]") + end + -- debug code to find bugs: + for u in b.region.units do + if u.building == b then + eressea.log.error("Did not teleport " .. tostring(u) .. " from tunnel " .. tostring(b)) end end end diff --git a/src/creport.c b/src/creport.c index 45400f241..0458f7271 100644 --- a/src/creport.c +++ b/src/creport.c @@ -848,13 +848,12 @@ void cr_output_unit(stream *out, const faction * f, pzTmp = get_racename(u->attribs); if (pzTmp) { - const char *pzRace = LOC(lang, mkname("race", pzTmp)); - pzTmp = pzRace ? pzRace : pzTmp; - stream_printf(out, "\"%s\";Typ\n", translate(pzTmp, LOC(lang, pzTmp))); + const char *pzRace = locale_string(lang, mkname("race", pzTmp), false); + pzTmp = pzRace ? translate(pzRace, LOC(lang, pzRace)) : pzTmp; + stream_printf(out, "\"%s\";Typ\n", pzTmp); if (u->faction == f && fval(u_race(u), RCF_SHAPESHIFTANY)) { pzRace = rc_name_s(u_race(u), NAME_PLURAL); - stream_printf(out, "\"%s\";wahrerTyp\n", - translate(pzRace, LOC(lang, pzRace))); + stream_printf(out, "\"%s\";wahrerTyp\n", pzTmp); } } else { diff --git a/src/magic.c b/src/magic.c index d7b57f24d..fdd74d55e 100644 --- a/src/magic.c +++ b/src/magic.c @@ -2237,7 +2237,7 @@ static void equip_familiar(unit *fam) { snprintf(eqname, sizeof(eqname), "fam_%s", rc->_name); if (!equip_unit(fam, eqname)) { - log_info("could not perform initialization for familiar %s.\n", rc->_name); + log_debug("could not perform initialization for familiar %s.\n", rc->_name); } } diff --git a/src/main.c b/src/main.c index 6b80c0cb0..4216d3046 100644 --- a/src/main.c +++ b/src/main.c @@ -53,7 +53,7 @@ static const char *logfile = "eressea.log"; static const char *luafile = 0; static const char *inifile = "eressea.ini"; static int memdebug = 0; -static int verbosity = 1; +static int verbosity = 2; static void load_inifile(void) { @@ -183,7 +183,7 @@ static int verbosity_to_flags(int verbosity) { static int parse_args(int argc, char **argv) { int i; - int log_stderr, log_flags = 2; + int log_stderr, log_flags = 3; for (i = 1; i != argc; ++i) { char *argi = argv[i]; diff --git a/src/reports.c b/src/reports.c index 4b950b73b..306fe0e10 100644 --- a/src/reports.c +++ b/src/reports.c @@ -713,7 +713,7 @@ void bufunit(const faction * f, const unit * u, const faction *fv, pzTmp = get_racename(u->attribs); if (pzTmp) { - const char *name = LOC(lang, mkname("race", pzTmp)); + const char *name = locale_string(lang, mkname("race", pzTmp), false); sbs_strcat(sbp, name ? name : pzTmp); if (u->faction == f && fval(u_race(u), RCF_SHAPESHIFTANY)) { sbs_strcat(sbp, " ("); From ca5e7b82ae3c20e2e2087175f67fafcdc621c9a5 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 7 Apr 2019 15:27:11 +0200 Subject: [PATCH 02/20] =?UTF-8?q?Bug=202570:=20Linie=20vor=20jeder=20Regio?= =?UTF-8?q?n,=20Leerzeilen=20aufger=C3=A4umt.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/report.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/report.c b/src/report.c index 961f5227e..61cb915b8 100644 --- a/src/report.c +++ b/src/report.c @@ -1607,7 +1607,6 @@ static void allies(struct stream *out, const faction * f) } g = g->next; } - rpline(out); } static void guards(struct stream *out, const region * r, const faction * see) @@ -1703,8 +1702,6 @@ static void list_address(struct stream *out, const faction * uf, selist * seenfa } selist_advance(&flist, &qi, 1); } - newline(out); - rpline(out); } static void @@ -2130,9 +2127,10 @@ report_plaintext(const char *filename, report_context * ctx, continue; /* Beschreibung */ + rpline(out); + newline(out); if (r->seen.mode >= seen_unit) { anyunits = 1; - newline(out); report_region(out, r, f); if (markets_module() && r->land) { const item_type *lux = r_luxury(r); @@ -2169,20 +2167,21 @@ report_plaintext(const char *filename, report_context * ctx, newline(out); report_travelthru(out, r, f); } - newline(out); if (wants_stats && r->seen.mode >= seen_travel) { if (r->land || r->seen.mode >= seen_unit) { - statistics(out, r, f); newline(out); + statistics(out, r, f); } } /* Nachrichten an REGION in der Region */ if (r->seen.mode >= seen_travel) { message_list *mlist = r_getmessages(r, f); + newline(out); if (mlist) { struct mlist **split = merge_messages(mlist, r->msgs); + newline(out); rp_messages(out, mlist, f, 0, false); split_messages(mlist, split); } @@ -2236,7 +2235,6 @@ report_plaintext(const char *filename, report_context * ctx, assert(!u); newline(out); - rpline(out); ERRNO_CHECK(); } if (!is_monsters(f)) { From c92f7505e5134255520a2cdac7e2f7206574dfe2 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 7 Apr 2019 13:11:02 +0200 Subject: [PATCH 03/20] Bug 2576: additional logging. increase log verbosity, decrease some log levels. --- scripts/eressea/tunnels.lua | 16 +++++++++++++--- src/creport.c | 9 ++++----- src/magic.c | 2 +- src/main.c | 4 ++-- src/reports.c | 2 +- 5 files changed, 21 insertions(+), 12 deletions(-) diff --git a/scripts/eressea/tunnels.lua b/scripts/eressea/tunnels.lua index 4a787a373..6b7a8e8d1 100644 --- a/scripts/eressea/tunnels.lua +++ b/scripts/eressea/tunnels.lua @@ -27,11 +27,21 @@ end local function tunnel_action(b, param) local units = tunnel_travelers(b) local rto = get_target(param) + eressea.log.info("Tunnel from " .. tostring(b) .. " [" .. param .. "]") if rto and units then - eressea.log.debug("Tunnel from " .. tostring(b) .. " [" .. param .. "]") - for key, u in pairs(units) do + for _, u in pairs(units) do u.region = rto - eressea.log.debug("teleported " .. tostring(u) .. " to " .. tostring(rto)) + eressea.log.info("teleported " .. tostring(u) .. " to " .. tostring(rto)) + end + elseif not units then + eressea.log.info("No units in tunnel " .. tostring(b) .. " [" .. param .. "]") + elseif not rto then + eressea.log.error("No target for tunnel " .. tostring(b) .. " [" .. param .. "]") + end + -- debug code to find bugs: + for u in b.region.units do + if u.building == b then + eressea.log.error("Did not teleport " .. tostring(u) .. " from tunnel " .. tostring(b)) end end end diff --git a/src/creport.c b/src/creport.c index 45400f241..0458f7271 100644 --- a/src/creport.c +++ b/src/creport.c @@ -848,13 +848,12 @@ void cr_output_unit(stream *out, const faction * f, pzTmp = get_racename(u->attribs); if (pzTmp) { - const char *pzRace = LOC(lang, mkname("race", pzTmp)); - pzTmp = pzRace ? pzRace : pzTmp; - stream_printf(out, "\"%s\";Typ\n", translate(pzTmp, LOC(lang, pzTmp))); + const char *pzRace = locale_string(lang, mkname("race", pzTmp), false); + pzTmp = pzRace ? translate(pzRace, LOC(lang, pzRace)) : pzTmp; + stream_printf(out, "\"%s\";Typ\n", pzTmp); if (u->faction == f && fval(u_race(u), RCF_SHAPESHIFTANY)) { pzRace = rc_name_s(u_race(u), NAME_PLURAL); - stream_printf(out, "\"%s\";wahrerTyp\n", - translate(pzRace, LOC(lang, pzRace))); + stream_printf(out, "\"%s\";wahrerTyp\n", pzTmp); } } else { diff --git a/src/magic.c b/src/magic.c index d7b57f24d..fdd74d55e 100644 --- a/src/magic.c +++ b/src/magic.c @@ -2237,7 +2237,7 @@ static void equip_familiar(unit *fam) { snprintf(eqname, sizeof(eqname), "fam_%s", rc->_name); if (!equip_unit(fam, eqname)) { - log_info("could not perform initialization for familiar %s.\n", rc->_name); + log_debug("could not perform initialization for familiar %s.\n", rc->_name); } } diff --git a/src/main.c b/src/main.c index 6b80c0cb0..4216d3046 100644 --- a/src/main.c +++ b/src/main.c @@ -53,7 +53,7 @@ static const char *logfile = "eressea.log"; static const char *luafile = 0; static const char *inifile = "eressea.ini"; static int memdebug = 0; -static int verbosity = 1; +static int verbosity = 2; static void load_inifile(void) { @@ -183,7 +183,7 @@ static int verbosity_to_flags(int verbosity) { static int parse_args(int argc, char **argv) { int i; - int log_stderr, log_flags = 2; + int log_stderr, log_flags = 3; for (i = 1; i != argc; ++i) { char *argi = argv[i]; diff --git a/src/reports.c b/src/reports.c index 056ee8dd0..42deefb12 100644 --- a/src/reports.c +++ b/src/reports.c @@ -715,7 +715,7 @@ void bufunit(const faction * f, const unit * u, const faction *fv, pzTmp = get_racename(u->attribs); if (pzTmp) { - const char *name = LOC(lang, mkname("race", pzTmp)); + const char *name = locale_string(lang, mkname("race", pzTmp), false); sbs_strcat(sbp, name ? name : pzTmp); if (u->faction == f && fval(u_race(u), RCF_SHAPESHIFTANY)) { sbs_strcat(sbp, " ("); From de5181f3fef66d034fc09151ae78e74120b73033 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 6 Apr 2019 11:29:19 +0200 Subject: [PATCH 04/20] I am moving my library dependency folder to c:\libraries build.bat needed to know that. --- CMakeLists.txt | 7 ++----- cmake/Modules/FindToLua.cmake | 4 +++- vs2017-build.bat | 11 +++++++---- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4b91565da..aa4e746c0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,9 +31,6 @@ ELSE (HAVE_LIBBSD) CHECK_FUNCTION_EXISTS(strlcat HAVE_STRLCAT) ENDIF(HAVE_LIBBSD) -endif (MSVC) - -if (MSVC) find_package (PDCurses) SET(CURSES_FOUND ${PDCURSES_FOUND}) SET(CURSES_LIBRARIES ${PDCURSES_LIBRARY}) @@ -42,7 +39,8 @@ else (MSVC) find_package (Curses) endif (MSVC) -find_package (Readline) +# find_package (Readline) +find_package (EXPAT REQUIRED) if (ERESSEA_DB STREQUAL "db") find_package (BerkeleyDB REQUIRED QUIET) @@ -50,7 +48,6 @@ else() find_package (SQLite3 REQUIRED QUIET) endif() -find_package(EXPAT REQUIRED) find_package (ToLua REQUIRED) if (TOLUA_FOUND) if (${TOLUA_VERSION_STRING} VERSION_EQUAL "5.2") diff --git a/cmake/Modules/FindToLua.cmake b/cmake/Modules/FindToLua.cmake index 52c721112..92732981b 100644 --- a/cmake/Modules/FindToLua.cmake +++ b/cmake/Modules/FindToLua.cmake @@ -58,7 +58,9 @@ elseif(TOLUA_INCLUDE_DIR AND EXISTS "${TOLUA_INCLUDE_DIR}/tolua.h") string(REGEX REPLACE "^#define[\t ]+TOLUA_VERSION[\t ]+\"tolua ([^\"]*)\".*" "\\1" TOLUA_VERSION_STRING "${tolua_version_str}") unset(tolua_version_str) -endif() +else(PC_TOLUA_VERSION) +message(ERROR "TOLUA_VERSION_STRING cannot be determined") +endif(PC_TOLUA_VERSION) # handle the QUIETLY and REQUIRED arguments and set TOLUA_FOUND to TRUE if # all listed variables are TRUE diff --git a/vs2017-build.bat b/vs2017-build.bat index 7503153fe..22e153874 100644 --- a/vs2017-build.bat +++ b/vs2017-build.bat @@ -1,13 +1,16 @@ @ECHO OFF +IF "%WIN32_DEV%" == "" SET WIN32_DEV="C:\Libraries" +SET CMAKE_ROOT=%ProgramFiles%\CMake +IF "%LUA_DEV%" == "" SET LUA_DEV="%ProgramFiles(x86)%/Lua/5.1" SET VSVERSION=15 SET SRCDIR=%CD% -CD .. -SET ERESSEA=%CD% +REM CD .. +REM SET ERESSEA=%CD% +REM CD %SRCDIR% -CD %SRCDIR% IF exist build-vs%VSVERSION% goto HAVEDIR mkdir build-vs%VSVERSION% :HAVEDIR cd build-vs%VSVERSION% -"%ProgramFiles%\CMake\bin\cmake.exe" -G "Visual Studio %VSVERSION%" -DCMAKE_PREFIX_PATH="%ProgramFiles(x86)%/Lua/5.1;%ERESSEA%/dependencies-win32" -DCMAKE_MODULE_PATH="%SRCDIR%/cmake/Modules" -DCMAKE_SUPPRESS_REGENERATION=TRUE .. +"%CMAKE_ROOT%\bin\cmake.exe" -G "Visual Studio %VSVERSION%" -DCMAKE_PREFIX_PATH="%LUA_DEV%;%WIN32_DEV%" -DCMAKE_MODULE_PATH="%SRCDIR%/cmake/Modules" -DCMAKE_SUPPRESS_REGENERATION=TRUE .. PAUSE From 2c03c67075fccd61be73f04960a072dc544dd7a0 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 6 Apr 2019 11:41:56 +0200 Subject: [PATCH 05/20] fix cmake syntax. --- CMakeLists.txt | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index aa4e746c0..2d2635f05 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,41 +6,38 @@ FILE(TO_CMAKE_PATH "${CMAKE_PREFIX_PATH}" CMAKE_PREFIX_PATH ) endif(WIN32) project (eressea-server C) -set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules/" ${CMAKE_MODULE_PATH}) +set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/") if (MSVC) -include(MSVC) +find_package (PDCurses) +set (CURSES_FOUND ${PDCURSES_FOUND}) +set (CURSES_LIBRARIES ${PDCURSES_LIBRARY}) +set (CURSES_INCLUDE_DIR ${PDCURSES_INCLUDE_DIR}) set (HAVE_STRDUP 0) set (HAVE_STRLCAT 0) set (HAVE_LIBBSD 0) set (HAVE_SIGNAL_H 0) set (HAVE_EXECINFO_H 0) +include (MSVC) else (MSVC) -INCLUDE (CheckIncludeFile) +find_package (Curses) +include (CheckIncludeFile) CHECK_INCLUDE_FILE(signal.h HAVE_SIGNAL_H) CHECK_INCLUDE_FILE(execinfo.h HAVE_EXECINFO_H) CHECK_INCLUDE_FILE(bsd/string.h HAVE_LIBBSD) -INCLUDE (CheckFunctionExists) +include (CheckFunctionExists) CHECK_FUNCTION_EXISTS(strdup HAVE_STRDUP) -IF (HAVE_LIBBSD) -INCLUDE (CheckLibraryExists) +if (HAVE_LIBBSD) +include (CheckLibraryExists) CHECK_LIBRARY_EXISTS(bsd strlcat "bsd/string.h" HAVE_STRLCAT) -ELSE (HAVE_LIBBSD) +else (HAVE_LIBBSD) CHECK_FUNCTION_EXISTS(strlcat HAVE_STRLCAT) -ENDIF(HAVE_LIBBSD) - -find_package (PDCurses) -SET(CURSES_FOUND ${PDCURSES_FOUND}) -SET(CURSES_LIBRARIES ${PDCURSES_LIBRARY}) -SET(CURSES_INCLUDE_DIR ${PDCURSES_INCLUDE_DIR}) -else (MSVC) -find_package (Curses) +endif (HAVE_LIBBSD) endif (MSVC) -# find_package (Readline) -find_package (EXPAT REQUIRED) +find_package (Readline) if (ERESSEA_DB STREQUAL "db") find_package (BerkeleyDB REQUIRED QUIET) @@ -48,6 +45,7 @@ else() find_package (SQLite3 REQUIRED QUIET) endif() +find_package(EXPAT REQUIRED) find_package (ToLua REQUIRED) if (TOLUA_FOUND) if (${TOLUA_VERSION_STRING} VERSION_EQUAL "5.2") From 21e226b0682554cf1cc0856fcbcc4c58510f1cef Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 7 Apr 2019 16:05:00 +0200 Subject: [PATCH 06/20] Bug 2576: fix indexing of portals. --- scripts/eressea/tunnels.lua | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/scripts/eressea/tunnels.lua b/scripts/eressea/tunnels.lua index 6b7a8e8d1..96d482abd 100644 --- a/scripts/eressea/tunnels.lua +++ b/scripts/eressea/tunnels.lua @@ -16,12 +16,17 @@ local function tunnel_travelers(b) end local function get_target(param) - local ntargets = table.maxn(targets) - if ntargets==0 then + local ntargets = #targets + if ntargets == 0 then + eressea.log.error("Zero tunnel targets for [" .. param .. "]") return nil end local rn = math.fmod(rng_int(), ntargets) - return targets[rn] + local t = targets[rn + 1] + if not t then + eressea.log.error("NULL target for [" .. param .. "]" .. " at index " .. rn) + end + return t end local function tunnel_action(b, param) @@ -50,7 +55,7 @@ function tunnels.init() local r, b for r in regions() do if r:get_key('tnnL') then - targets[table.maxn(targets)+1] = r + table.insert(targets, r) if (r:get_flag(0)) then -- target region is chaotic? nope. r:set_flag(0, false) @@ -62,10 +67,11 @@ function tunnels.init() end for b in r.buildings do if b.type == 'portal' then - buildings[table.maxn(buildings)+1] = b + table.insert(buildings, b) end end end + eressea.log.info("Found " .. #targets .. " tunnel targets") end function tunnels.update() From 3f021b21cd0976d677128356046ef0e64420ebae Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 7 Apr 2019 17:55:04 +0200 Subject: [PATCH 07/20] Bug 1982: disable the clone spell. --- res/e3a/spellbooks/gray.xml | 2 +- res/e3a/spellbooks/illaun.xml | 2 +- res/e3a/spells.xml | 4 ++-- res/eressea/spellbooks/gray.xml | 2 +- res/eressea/spellbooks/illaun.xml | 2 +- res/eressea/spells.xml | 5 +++-- src/attributes/seenspell.c | 11 ++++++----- src/creport.c | 16 +++++++++++----- vs2017-build.bat | 3 +++ 9 files changed, 29 insertions(+), 18 deletions(-) diff --git a/res/e3a/spellbooks/gray.xml b/res/e3a/spellbooks/gray.xml index 998405b03..f3f4e496d 100644 --- a/res/e3a/spellbooks/gray.xml +++ b/res/e3a/spellbooks/gray.xml @@ -25,7 +25,7 @@ - + diff --git a/res/e3a/spellbooks/illaun.xml b/res/e3a/spellbooks/illaun.xml index 0392842c2..8d820bf71 100644 --- a/res/e3a/spellbooks/illaun.xml +++ b/res/e3a/spellbooks/illaun.xml @@ -27,7 +27,7 @@ - + diff --git a/res/e3a/spells.xml b/res/e3a/spells.xml index 94d7cbc08..d72386803 100644 --- a/res/e3a/spells.xml +++ b/res/e3a/spells.xml @@ -79,13 +79,13 @@ + - + --> diff --git a/res/eressea/spellbooks/gray.xml b/res/eressea/spellbooks/gray.xml index 942b50237..74486f004 100644 --- a/res/eressea/spellbooks/gray.xml +++ b/res/eressea/spellbooks/gray.xml @@ -30,7 +30,7 @@ - + diff --git a/res/eressea/spellbooks/illaun.xml b/res/eressea/spellbooks/illaun.xml index 83ffcfc27..6552a4bd8 100644 --- a/res/eressea/spellbooks/illaun.xml +++ b/res/eressea/spellbooks/illaun.xml @@ -20,7 +20,7 @@ - + diff --git a/res/eressea/spells.xml b/res/eressea/spells.xml index 1931a4c74..5725b8768 100644 --- a/res/eressea/spells.xml +++ b/res/eressea/spells.xml @@ -446,12 +446,13 @@ - + diff --git a/src/attributes/seenspell.c b/src/attributes/seenspell.c index e20976015..698a83076 100644 --- a/src/attributes/seenspell.c +++ b/src/attributes/seenspell.c @@ -54,11 +54,12 @@ static int read_seenspells(variant *var, void *owner, struct gamedata *data) READ_TOK(store, token, sizeof(token)); while (token[0]) { spell *sp = find_spell(token); - if (!sp) { - log_info("read_seenspells: could not find spell '%s'\n", token); - return AT_READ_FAIL; + if (sp) { + selist_push(&ql, sp); + } + else { + log_info("read_seenspells: could not find spell '%s'\n", token); } - selist_push(&ql, sp); READ_TOK(store, token, sizeof(token)); } var->v = ql; @@ -70,8 +71,8 @@ static bool cb_write_spell(void *data, void *more) { storage *store = (storage *)more; WRITE_TOK(store, sp->sname); return true; - } + static void write_seenspells(const variant *var, const void *owner, struct storage *store) { diff --git a/src/creport.c b/src/creport.c index 0458f7271..23e0f7c8a 100644 --- a/src/creport.c +++ b/src/creport.c @@ -108,8 +108,8 @@ struct locale *crtag_locale(void) { static const char *crtag(const char *key) { const char *result; - result = LOC(crtag_locale(), key); - return result; + result = locale_string(crtag_locale(), key, false); + return result ? result : key; } /* * translation table @@ -849,11 +849,17 @@ void cr_output_unit(stream *out, const faction * f, pzTmp = get_racename(u->attribs); if (pzTmp) { const char *pzRace = locale_string(lang, mkname("race", pzTmp), false); - pzTmp = pzRace ? translate(pzRace, LOC(lang, pzRace)) : pzTmp; - stream_printf(out, "\"%s\";Typ\n", pzTmp); + if (pzRace) { + pzTmp = pzRace; + } + pzRace = translate(pzTmp, locale_string(lang, pzTmp, false)); + if (!pzRace) { + pzRace = pzTmp; + } + stream_printf(out, "\"%s\";Typ\n", pzRace); if (u->faction == f && fval(u_race(u), RCF_SHAPESHIFTANY)) { pzRace = rc_name_s(u_race(u), NAME_PLURAL); - stream_printf(out, "\"%s\";wahrerTyp\n", pzTmp); + stream_printf(out, "\"%s\";wahrerTyp\n", pzRace); } } else { diff --git a/vs2017-build.bat b/vs2017-build.bat index 22e153874..b79a81e85 100644 --- a/vs2017-build.bat +++ b/vs2017-build.bat @@ -12,5 +12,8 @@ IF exist build-vs%VSVERSION% goto HAVEDIR mkdir build-vs%VSVERSION% :HAVEDIR cd build-vs%VSVERSION% +IF NOT EXIST CMakeCache.txt GOTO NOCACHE +DEL CMakeCache.txt +:NOCACHE "%CMAKE_ROOT%\bin\cmake.exe" -G "Visual Studio %VSVERSION%" -DCMAKE_PREFIX_PATH="%LUA_DEV%;%WIN32_DEV%" -DCMAKE_MODULE_PATH="%SRCDIR%/cmake/Modules" -DCMAKE_SUPPRESS_REGENERATION=TRUE .. PAUSE From 91e40b706138e0175e311942a7dccbc48e3b3ebc Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 7 Apr 2019 21:37:06 +0200 Subject: [PATCH 08/20] =?UTF-8?q?Bug=201982:=20Klone=20aufl=C3=B6sen,=20un?= =?UTF-8?q?d=20Magiern=20ihre=20permanete=20Aura=20und=20Trank=20zur=C3=BC?= =?UTF-8?q?ck=20geben.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/kernel/gamedata.h | 3 +- src/kernel/save.c | 70 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 71 insertions(+), 2 deletions(-) diff --git a/src/kernel/gamedata.h b/src/kernel/gamedata.h index 587ee0a40..d4293d461 100644 --- a/src/kernel/gamedata.h +++ b/src/kernel/gamedata.h @@ -42,8 +42,9 @@ #define FAMILIAR_FIXMAGE_VERSION 364 /* familiar links are fixed */ #define FAMILIAR_FIXSPELLBOOK_VERSION 365 /* familiar spells are fixed */ #define FIX_STARTLEVEL_VERSION 366 /* fixing resource startlevels */ +#define FIX_CLONES_VERSION 367 /* dissolve clones */ -#define RELEASE_VERSION FIX_STARTLEVEL_VERSION /* current datafile */ +#define RELEASE_VERSION FIX_CLONES_VERSION /* current datafile */ #define MIN_VERSION UIDHASH_VERSION /* minimal datafile we support */ #define MAX_VERSION RELEASE_VERSION /* change this if we can need to read the future datafile, and we can do so */ diff --git a/src/kernel/save.c b/src/kernel/save.c index 0b3ade593..70c75f62a 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -1368,6 +1368,72 @@ static void fix_fam_triggers(unit *u) { } } +static void fix_clone(unit *uc) { + attrib * a; + assert(uc); + assert(uc->number > 0); + ADDMSG(&uc->faction->msgs, msg_message("dissolve_units_5", + "unit region number race", uc, uc->region, uc->number, u_race(uc))); + a_removeall(&uc->attribs, &at_clonemage); + a = a_new(&at_unitdissolve); + a->data.ca[0] = 0; + a->data.ca[1] = 100; + a_add(&uc->attribs, a); +} + +static void fix_clone_mage(unit *um, const item_type *itype) { + i_change(&um->items, itype, 1); + change_maxspellpoints(um, 20); + a_removeall(&um->attribs, &at_clone); +} + +static void fix_clones(void) { + const race *rc_clone = rc_find("clone"); + const item_type *it_potion = it_find("lifepotion"); + + if (rc_clone && it_potion) { + region *r; + for (r = regions; r; r = r->next) { + unit * u; + for (u = r->units; u; u = u->next) { + if (!fval(u, UFL_MARK)) { + if (u_race(u) == rc_clone) { + attrib *a = a_find(u->attribs, &at_clonemage); + unit * um = NULL; + fset(u, UFL_MARK); + if (a) { + um = (unit *)a->data.v; + fset(um, UFL_MARK); + } + } + else { + attrib *a = a_find(u->attribs, &at_clone); + if (a) { + unit *uc = (unit *)a->data.v; + fset(u, UFL_MARK); + fset(uc, UFL_MARK); + } + } + } + } + } + for (r = regions; r; r = r->next) { + unit * u; + for (u = r->units; u; u = u->next) { + if (fval(u, UFL_MARK)) { + if (u_race(u) == rc_clone) { + fix_clone(u); + } + else { + fix_clone_mage(u, it_potion); + } + freset(u, UFL_MARK); + } + } + } + } +} + static void fix_familiars(void (*callback)(unit *)) { region *r; for (r = regions; r; r = r->next) { @@ -1559,7 +1625,9 @@ int read_game(gamedata *data) } } } - + if (data->version < FIX_CLONES_VERSION) { + fix_clones(); + } if (data->version < FAMILIAR_FIX_VERSION) { fix_familiars(fix_fam_triggers); } From bb3ce32be6451cf547280e928ef3a7e8fb1fbd01 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 8 Apr 2019 14:56:44 +0200 Subject: [PATCH 09/20] fix default crtag locale --- src/creport.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/creport.c b/src/creport.c index 23e0f7c8a..fce3b8bff 100644 --- a/src/creport.c +++ b/src/creport.c @@ -100,7 +100,7 @@ struct locale *crtag_locale(void) { static int config; if (config_changed(&config)) { const char *lname = config_get("creport.tags"); - lang = get_locale(lname ? lname : "de"); + lang = lname ? get_locale(lname) : default_locale; } return lang; } From adb626df3d83c74e3bd33e5a52b15211fa31ff1f Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 19 Apr 2019 20:14:43 +0200 Subject: [PATCH 10/20] stop using the turn column from gamedb --- process/epasswd.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/process/epasswd.py b/process/epasswd.py index bdb3c4a6d..3e0033236 100755 --- a/process/epasswd.py +++ b/process/epasswd.py @@ -45,9 +45,7 @@ class EPasswd: def load_database(self, file): conn = sqlite3.connect(file) c = conn.cursor() - c.execute('SELECT MAX(turn) FROM factions') - args = c.fetchone() - for row in c.execute('SELECT no, email, password FROM factions WHERE turn=?', args): + for row in c.execute('SELECT no, email, password FROM factions ORDER BY turn'): (no, email, passwd) = row self.set_data(baseconvert(no, 36), email, passwd) conn.close() From 6fcfca27ca20279a1ca0bea46d27e27d4734b5c9 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 20 Apr 2019 08:15:27 +0200 Subject: [PATCH 11/20] Revert "stop using the turn column from gamedb" This reverts commit adb626df3d83c74e3bd33e5a52b15211fa31ff1f. --- process/epasswd.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/process/epasswd.py b/process/epasswd.py index 3e0033236..bdb3c4a6d 100755 --- a/process/epasswd.py +++ b/process/epasswd.py @@ -45,7 +45,9 @@ class EPasswd: def load_database(self, file): conn = sqlite3.connect(file) c = conn.cursor() - for row in c.execute('SELECT no, email, password FROM factions ORDER BY turn'): + c.execute('SELECT MAX(turn) FROM factions') + args = c.fetchone() + for row in c.execute('SELECT no, email, password FROM factions WHERE turn=?', args): (no, email, passwd) = row self.set_data(baseconvert(no, 36), email, passwd) conn.close() From aab234a3f4c30c1b16ca24ae1059a2c4a38e4a2f Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 23 Apr 2019 13:18:51 +0200 Subject: [PATCH 12/20] update to schema version 1 - factions table is now faction - no turn column - new update logic --- process/epasswd.py | 4 +- src/creport.c | 2 +- src/gamedb.c | 29 +++++--- src/kernel/database.test.c | 17 +++-- src/kernel/db/driver.h | 14 +++- src/kernel/db/sqlite.c | 132 +++++++++++++++++++++++++------------ tests/runtests.bat | 6 +- 7 files changed, 139 insertions(+), 65 deletions(-) diff --git a/process/epasswd.py b/process/epasswd.py index bdb3c4a6d..c5e1712b9 100755 --- a/process/epasswd.py +++ b/process/epasswd.py @@ -45,9 +45,7 @@ class EPasswd: def load_database(self, file): conn = sqlite3.connect(file) c = conn.cursor() - c.execute('SELECT MAX(turn) FROM factions') - args = c.fetchone() - for row in c.execute('SELECT no, email, password FROM factions WHERE turn=?', args): + for row in c.execute('SELECT `no`, `email`, `password` FROM `faction`'): (no, email, passwd) = row self.set_data(baseconvert(no, 36), email, passwd) conn.close() diff --git a/src/creport.c b/src/creport.c index 23e0f7c8a..fce3b8bff 100644 --- a/src/creport.c +++ b/src/creport.c @@ -100,7 +100,7 @@ struct locale *crtag_locale(void) { static int config; if (config_changed(&config)) { const char *lname = config_get("creport.tags"); - lang = get_locale(lname ? lname : "de"); + lang = lname ? get_locale(lname) : default_locale; } return lang; } diff --git a/src/gamedb.c b/src/gamedb.c index 5f53d9120..9af580a9f 100644 --- a/src/gamedb.c +++ b/src/gamedb.c @@ -9,9 +9,25 @@ #include "kernel/faction.h" #include "kernel/db/driver.h" +#include "util/strings.h" + +static int generate_factions(void *data, db_faction *results, int nresults) +{ + int i; + faction **iter = (faction **)data; + for (i = 0; *iter && i != nresults; ++i) { + faction *f = *iter; + results[i].p_uid = &f->uid; + results[i].no = f->no; + results[i].email = faction_getemail(f); + str_strlcpy(results[i].pwhash, faction_getpassword(f), sizeof(results[i].pwhash)); + *iter = f->next; + } + return i; +} + int gamedb_update(void) { - faction *f; int err; const char *dbname; @@ -19,14 +35,9 @@ int gamedb_update(void) err = db_driver_open(DB_GAME, dbname); if (err == 0) { - for (f = factions; f; f = f->next) { - int uid = db_driver_faction_save(f->uid, f->no, turn, - faction_getemail(f), - faction_getpassword(f)); - if (uid > 0) { - f->uid = uid; - } - } + faction *list = factions; + db_driver_update_factions(generate_factions, &list); + db_driver_compact(turn); db_driver_close(DB_GAME); } return err; diff --git a/src/kernel/database.test.c b/src/kernel/database.test.c index c5aae1af6..a84a4b286 100644 --- a/src/kernel/database.test.c +++ b/src/kernel/database.test.c @@ -47,19 +47,26 @@ static void test_save_load_order(CuTest *tc) { static void test_update_faction(CuTest *tc) { faction *f; - int uid; + int err; + dbrow_id id; test_setup(); db_driver_open(DB_GAME, NULL); f = test_create_faction(NULL); - uid = db_driver_faction_save(f->uid, f->no, 0, + CuAssertIntEquals(tc, 0, f->uid); + id = 0; + err = db_driver_faction_save(&id, f->no, faction_getemail(f), faction_getpassword(f)); - f->uid = uid; - uid = db_driver_faction_save(f->uid, f->no, 0, + CuAssertTrue(tc, 0 != id); + f->uid = (int)id; + db_driver_close(DB_GAME); + + db_driver_open(DB_GAME, NULL); + db_driver_faction_save(&id, f->no, faction_getemail(f), faction_getpassword(f)); - CuAssertIntEquals(tc, f->uid, uid); + CuAssertIntEquals(tc, f->uid, id); db_driver_close(DB_GAME); test_teardown(); } diff --git a/src/kernel/db/driver.h b/src/kernel/db/driver.h index 341653991..91fcfbb27 100644 --- a/src/kernel/db/driver.h +++ b/src/kernel/db/driver.h @@ -1,6 +1,7 @@ #pragma once #include +#include struct order_data; @@ -17,6 +18,17 @@ int db_driver_open(database_t db, const char *dbname); void db_driver_close(database_t db); dbrow_id db_driver_order_save(const char *str); struct order_data *db_driver_order_load(dbrow_id id); -dbrow_id db_driver_faction_save(dbrow_id id, int no, int turn, const char *email, const char *password); dbrow_id db_driver_string_save(const char *s); const char *db_driver_string_load(dbrow_id id, size_t *size); +void db_driver_compact(int turn); + +typedef struct db_faction { + int *p_uid; + int no; + const char *email; + char pwhash[128]; +} db_faction; + +typedef int (*db_faction_generator)(void *, db_faction *, int); +int db_driver_update_factions(db_faction_generator gen, void *data); +int db_driver_faction_save(dbrow_id * p_id, int no, const char *email, const char *password); diff --git a/src/kernel/db/sqlite.c b/src/kernel/db/sqlite.c index 29638d900..676dc5028 100644 --- a/src/kernel/db/sqlite.c +++ b/src/kernel/db/sqlite.c @@ -95,68 +95,104 @@ dbrow_id db_driver_order_save(const char *str) { return (dbrow_id)id; } - -dbrow_id db_driver_faction_save(dbrow_id id, int no, int turn, const char *email, const char *password) +int db_driver_faction_save(dbrow_id * p_id, int no, const char *email, const char *password) { - sqlite3_int64 row_id; + dbrow_id id = *p_id; int err; + sqlite3_stmt *stmt = (id > 0) ? g_stmt_update_faction : g_stmt_insert_faction; assert(g_game_db); - if (id != 0) { - int rows; - err = sqlite3_reset(g_stmt_update_faction); - assert(err == SQLITE_OK); - err = sqlite3_bind_int(g_stmt_update_faction, 1, no); - assert(err == SQLITE_OK); - err = sqlite3_bind_int(g_stmt_update_faction, 2, turn); - assert(err == SQLITE_OK); - err = sqlite3_bind_text(g_stmt_update_faction, 3, email, -1, SQLITE_STATIC); - assert(err == SQLITE_OK); - err = sqlite3_bind_text(g_stmt_update_faction, 4, password, -1, SQLITE_STATIC); - assert(err == SQLITE_OK); - err = sqlite3_bind_int(g_stmt_update_faction, 5, id); - assert(err == SQLITE_OK); - err = sqlite3_step(g_stmt_update_faction); - assert(err == SQLITE_DONE); - rows = sqlite3_changes(g_game_db); - if (rows != 0) { - return id; - } + err = sqlite3_reset(stmt); + if (err != SQLITE_OK) return err; + err = sqlite3_bind_int(stmt, 1, no); + if (err != SQLITE_OK) return err; + err = sqlite3_bind_text(stmt, 2, email, -1, SQLITE_STATIC); + if (err != SQLITE_OK) return err; + err = sqlite3_bind_text(stmt, 3, password, -1, SQLITE_STATIC); + if (err != SQLITE_OK) return err; + + if (id > 0) { + err = sqlite3_bind_int(stmt, 4, id); + if (err != SQLITE_OK) return err; } - err = sqlite3_reset(g_stmt_insert_faction); - assert(err == SQLITE_OK); - err = sqlite3_bind_int(g_stmt_insert_faction, 1, no); - assert(err == SQLITE_OK); - err = sqlite3_bind_int(g_stmt_insert_faction, 2, turn); - assert(err == SQLITE_OK); - err = sqlite3_bind_text(g_stmt_insert_faction, 3, email, -1, SQLITE_STATIC); - assert(err == SQLITE_OK); - err = sqlite3_bind_text(g_stmt_insert_faction, 4, password, -1, SQLITE_STATIC); - assert(err == SQLITE_OK); - err = sqlite3_step(g_stmt_insert_faction); - assert(err == SQLITE_DONE); + err = sqlite3_step(stmt); + if (err != SQLITE_DONE) return err; ERRNO_CHECK(); - row_id = sqlite3_last_insert_rowid(g_game_db); - assert(row_id>0 && row_id <= UINT_MAX); - return (dbrow_id)row_id; + if (id <= 0) { + sqlite3_int64 row_id; + row_id = sqlite3_last_insert_rowid(g_game_db); + assert(row_id > 0 && row_id <= UINT_MAX); + *p_id = (dbrow_id)row_id; + } + return SQLITE_OK; +} + +int db_driver_update_factions(db_faction_generator gen, void *data) +{ + db_faction results[32]; + int num, err; + + err = sqlite3_exec(g_game_db, "BEGIN TRANSACTION", NULL, NULL, NULL); + assert(err == SQLITE_OK); + err = sqlite3_exec(g_game_db, "DELETE FROM `faction`", NULL, NULL, NULL); + if (err != SQLITE_OK) { + sqlite3_exec(g_game_db, "ROLLBACK", NULL, NULL, NULL); + return err; + } + num = gen(data, results, 32); + while (num > 0) { + int i; + for (i = 0; i != num; ++i) { + db_faction *dbf = results + i; + dbrow_id id = (dbrow_id)*dbf->p_uid; + err = db_driver_faction_save(&id, dbf->no, dbf->email, dbf->pwhash); + if (err != SQLITE_OK) { + sqlite3_exec(g_game_db, "ROLLBACK", NULL, NULL, NULL); + return err; + } + assert(id > 0 && id <= INT_MAX); + *dbf->p_uid = (int)id; + } + num = gen(data, results, 32); + } + err = sqlite3_exec(g_game_db, "COMMIT", NULL, NULL, NULL); + return err; +} + +static int cb_int_col(void *data, int ncols, char **text, char **name) { + int *p_int = (int *)data; + *p_int = atoi(text[0]); + return SQLITE_OK; } static int db_open_game(const char *dbname) { - int err; + int err, version = 0; err = sqlite3_open(dbname, &g_game_db); assert(err == SQLITE_OK); - err = sqlite3_exec(g_game_db, "CREATE TABLE IF NOT EXISTS factions (id INTEGER PRIMARY KEY, no INTEGER NOT NULL, email VARCHAR(128), password VARCHAR(128), turn INTEGER NOT NULL)", NULL, NULL, NULL); + + err = sqlite3_exec(g_game_db, "PRAGMA user_version", cb_int_col, &version, NULL); assert(err == SQLITE_OK); - err = sqlite3_prepare_v2(g_game_db, "UPDATE factions SET no=?, turn=?, email=?, password=? WHERE id=?", -1, &g_stmt_update_faction, NULL); + if (version < 1) { + /* drop deprecated table */ + err = sqlite3_exec(g_game_db, "DROP TABLE IF EXISTS `factions`", NULL, NULL, NULL); + assert(err == SQLITE_OK); + /* install schema version 1: */ + err = sqlite3_exec(g_game_db, "CREATE TABLE IF NOT EXISTS `faction` (`id` INTEGER PRIMARY KEY, `no` INTEGER NOT NULL UNIQUE, `email` VARCHAR(128), `password` VARCHAR(128))", NULL, NULL, NULL); + assert(err == SQLITE_OK); + err = sqlite3_exec(g_game_db, "PRAGMA user_version = 1", NULL, NULL, NULL); + assert(err == SQLITE_OK); + } + /* create prepared statments: */ + err = sqlite3_prepare_v2(g_game_db, "INSERT INTO `faction` (`no`, `email`, `password`, `id`) VALUES (?,?,?,?)", -1, &g_stmt_update_faction, NULL); assert(err == SQLITE_OK); - err = sqlite3_prepare_v2(g_game_db, "INSERT INTO factions (no, turn, email, password) VALUES (?,?,?,?)", -1, &g_stmt_insert_faction, NULL); + err = sqlite3_prepare_v2(g_game_db, "INSERT INTO `faction` (`no`, `email`, `password`) VALUES (?,?,?)", -1, &g_stmt_insert_faction, NULL); assert(err == SQLITE_OK); ERRNO_CHECK(); - return 0; + return err; } static int db_open_swap(const char *dbname) { @@ -303,3 +339,13 @@ const char *db_driver_string_load(dbrow_id id, size_t *size) { ERRNO_CHECK(); return NULL; } + +void db_driver_compact(int turn) +{ + int err; + + /* repack database: */ + err = sqlite3_exec(g_game_db, "VACUUM", 0, 0, 0); + assert(err == SQLITE_OK); +} + diff --git a/tests/runtests.bat b/tests/runtests.bat index 88afc8d31..e73580851 100644 --- a/tests/runtests.bat +++ b/tests/runtests.bat @@ -7,9 +7,9 @@ IF EXIST ..\build-vs15 SET BUILD=..\build-vs15\eressea\Debug SET SERVER=%BUILD%\eressea.exe %BUILD%\test_eressea.exe -%SERVER% ..\scripts\run-tests.lua -%SERVER% -re2 ..\scripts\run-tests-e2.lua -%SERVER% -re3 ..\scripts\run-tests-e3.lua +%SERVER% -v1 ..\scripts\run-tests.lua +%SERVER% -v1 -re2 ..\scripts\run-tests-e2.lua +%SERVER% -v1 -re3 ..\scripts\run-tests-e3.lua %SERVER% --version PAUSE RMDIR /s /q reports From 7298968921a638c0c5bdce3ac06a8b759043174d Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 24 Apr 2019 08:08:50 +0200 Subject: [PATCH 13/20] schema version 2 faction no is a char(4), not an int. --- src/kernel/db/sqlite.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/kernel/db/sqlite.c b/src/kernel/db/sqlite.c index 676dc5028..e92f8cd57 100644 --- a/src/kernel/db/sqlite.c +++ b/src/kernel/db/sqlite.c @@ -3,6 +3,7 @@ #include #include +#include #include "driver.h" @@ -105,7 +106,7 @@ int db_driver_faction_save(dbrow_id * p_id, int no, const char *email, const cha err = sqlite3_reset(stmt); if (err != SQLITE_OK) return err; - err = sqlite3_bind_int(stmt, 1, no); + err = sqlite3_bind_text(stmt, 1, itoa36(no), -1, SQLITE_STATIC); if (err != SQLITE_OK) return err; err = sqlite3_bind_text(stmt, 2, email, -1, SQLITE_STATIC); if (err != SQLITE_OK) return err; @@ -179,10 +180,12 @@ static int db_open_game(const char *dbname) { /* drop deprecated table */ err = sqlite3_exec(g_game_db, "DROP TABLE IF EXISTS `factions`", NULL, NULL, NULL); assert(err == SQLITE_OK); - /* install schema version 1: */ - err = sqlite3_exec(g_game_db, "CREATE TABLE IF NOT EXISTS `faction` (`id` INTEGER PRIMARY KEY, `no` INTEGER NOT NULL UNIQUE, `email` VARCHAR(128), `password` VARCHAR(128))", NULL, NULL, NULL); + } + if (version < 2) { + /* install schema version 2: */ + err = sqlite3_exec(g_game_db, "CREATE TABLE IF NOT EXISTS `faction` (`id` INTEGER PRIMARY KEY, `no` CHAR(4) NOT NULL UNIQUE, `email` VARCHAR(128), `password` VARCHAR(128))", NULL, NULL, NULL); assert(err == SQLITE_OK); - err = sqlite3_exec(g_game_db, "PRAGMA user_version = 1", NULL, NULL, NULL); + err = sqlite3_exec(g_game_db, "PRAGMA user_version = 2", NULL, NULL, NULL); assert(err == SQLITE_OK); } /* create prepared statments: */ From 75dfed808211d483dae56206a17278af16c74108 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 24 Apr 2019 12:55:41 +0200 Subject: [PATCH 14/20] Leerzeichen aus Beschreibungen trimmen. --- res/eressea/spells.xml | 2 +- src/laws.c | 16 +++++++++---- src/laws.test.c | 53 +++++++++++++++++++++++++++++++++--------- src/util/parser.c | 4 ++-- src/util/parser.h | 4 ++-- src/util/unicode.c | 2 ++ 6 files changed, 61 insertions(+), 20 deletions(-) diff --git a/res/eressea/spells.xml b/res/eressea/spells.xml index 5725b8768..a56b147ef 100644 --- a/res/eressea/spells.xml +++ b/res/eressea/spells.xml @@ -314,7 +314,7 @@ - + diff --git a/src/laws.c b/src/laws.c index f7eba8c97..fda3f434f 100644 --- a/src/laws.c +++ b/src/laws.c @@ -1488,7 +1488,7 @@ int display_cmd(unit * u, struct order *ord) { char token[128]; char **s = NULL; - const char *str; + char *str; region *r = u->region; init_order_depr(ord); @@ -1525,11 +1525,19 @@ int display_cmd(unit * u, struct order *ord) break; case P_UNIT: - unit_setinfo(u, getstrtoken()); + str = getstrtoken(); + if (str) { + unicode_utf8_trim(str); + } + unit_setinfo(u, str); break; case P_PRIVAT: - usetprivate(u, getstrtoken()); + str = getstrtoken(); + if (str) { + unicode_utf8_trim(str); + } + usetprivate(u, str); break; case P_REGION: @@ -1664,7 +1672,7 @@ int name_cmd(struct unit *u, struct order *ord) bool foreign = false; const char *str; - init_order_depr(ord); + init_order(ord, u->faction->locale); str = gettoken(token, sizeof(token)); p = findparam_ex(str, u->faction->locale); diff --git a/src/laws.test.c b/src/laws.test.c index 0896b54f3..cead8605a 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -221,6 +221,21 @@ static void test_display_cmd(CuTest *tc) { CuAssertStrEquals(tc, "Hodor", unit_getinfo(u)); free_order(ord); + ord = create_order(K_DISPLAY, f->locale, "%s ' Klabautermann '", LOC(f->locale, parameters[P_UNIT])); + CuAssertIntEquals(tc, 0, display_cmd(u, ord)); + CuAssertStrEquals(tc, "Klabautermann", unit_getinfo(u)); + free_order(ord); + + ord = create_order(K_DISPLAY, f->locale, "%s Hodor", LOC(f->locale, parameters[P_PRIVAT])); + CuAssertIntEquals(tc, 0, display_cmd(u, ord)); + CuAssertStrEquals(tc, "Hodor", uprivate(u)); + free_order(ord); + + ord = create_order(K_DISPLAY, f->locale, "%s ' Klabautermann '", LOC(f->locale, parameters[P_PRIVAT])); + CuAssertIntEquals(tc, 0, display_cmd(u, ord)); + CuAssertStrEquals(tc, "Klabautermann", uprivate(u)); + free_order(ord); + ord = create_order(K_DISPLAY, f->locale, LOC(f->locale, parameters[P_UNIT])); CuAssertIntEquals(tc, 0, display_cmd(u, ord)); CuAssertPtrEquals(tc, NULL, (void *)unit_getinfo(u)); @@ -940,6 +955,12 @@ static void test_name_unit(CuTest *tc) { u = setup_name_cmd(); f = u->faction; + + ord = create_order(K_NAME, f->locale, "%s ' Klabauterfrau '", LOC(f->locale, parameters[P_UNIT])); + name_cmd(u, ord); + CuAssertStrEquals(tc, "Klabauterfrau", u->_name); + free_order(ord); + ord = create_order(K_NAME, f->locale, "%s Hodor", LOC(f->locale, parameters[P_UNIT])); name_cmd(u, ord); CuAssertStrEquals(tc, "Hodor", u->_name); @@ -960,10 +981,15 @@ static void test_name_region(CuTest *tc) { order *ord; u = setup_name_cmd(); + u_set_building(u, test_create_building(u->region, NULL)); f = u->faction; + ord = create_order(K_NAME, f->locale, "%s ' Hodor Hodor '", LOC(f->locale, parameters[P_REGION])); + name_cmd(u, ord); + CuAssertStrEquals(tc, "Hodor Hodor", u->region->land->name); + free_order(ord); + ord = create_order(K_NAME, f->locale, "%s Hodor", LOC(f->locale, parameters[P_REGION])); - u_set_building(u, test_create_building(u->region, NULL)); name_cmd(u, ord); CuAssertStrEquals(tc, "Hodor", u->region->land->name); free_order(ord); @@ -980,6 +1006,7 @@ static void test_name_region(CuTest *tc) { static void test_name_building(CuTest *tc) { unit *uo, *u, *ux; faction *f; + order *ord; u = setup_name_cmd(); u->building = test_create_building(u->region, NULL); @@ -989,29 +1016,33 @@ static void test_name_building(CuTest *tc) { ux = test_create_unit(f, test_create_region(0, 0, NULL)); u_set_building(ux, u->building); - u->thisorder = create_order(K_NAME, f->locale, "%s Hodor", LOC(f->locale, parameters[P_BUILDING])); - + ord = create_order(K_NAME, f->locale, "%s ' Hodor Hodor '", LOC(f->locale, parameters[P_BUILDING])); building_set_owner(uo); - name_cmd(u, u->thisorder); + name_cmd(u, ord); CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error148")); test_clear_messages(f); - building_set_owner(u); - name_cmd(u, u->thisorder); + name_cmd(u, ord); + CuAssertStrEquals(tc, "Hodor Hodor", u->building->name); + free_order(ord); + + ord = create_order(K_NAME, f->locale, "%s Hodor", LOC(f->locale, parameters[P_BUILDING])); + name_cmd(u, ord); CuAssertStrEquals(tc, "Hodor", u->building->name); building_setname(u->building, "Home"); building_set_owner(ux); - name_cmd(u, u->thisorder); + name_cmd(u, ord); CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "error148")); CuAssertStrEquals(tc, "Hodor", u->building->name); - test_clear_messages(f); - free_order(u->thisorder); - u->thisorder = create_order(K_NAME, f->locale, LOC(f->locale, parameters[P_BUILDING])); - name_cmd(u, u->thisorder); + free_order(ord); + + ord = create_order(K_NAME, f->locale, LOC(f->locale, parameters[P_BUILDING])); + name_cmd(u, ord); CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error84")); CuAssertStrEquals(tc, "Hodor", u->building->name); + free_order(ord); /* TODO: test BTF_NAMECHANGE: btype->flags |= BTF_NAMECHANGE; diff --git a/src/util/parser.c b/src/util/parser.c index 3d1ba250d..bd187b5f8 100644 --- a/src/util/parser.c +++ b/src/util/parser.c @@ -233,12 +233,12 @@ const char *parse_token_depr(const char **str) return parse_token(str, pbuf, MAXTOKENSIZE); } -const char *getstrtoken(void) +char *getstrtoken(void) { return parse_token((const char **)&states->current_token, pbuf, MAXTOKENSIZE); } -const char *gettoken(char *lbuf, size_t bufsize) +char *gettoken(char *lbuf, size_t bufsize) { return parse_token((const char **)&states->current_token, lbuf, bufsize); } diff --git a/src/util/parser.h b/src/util/parser.h index a540aa2ac..329d6f654 100644 --- a/src/util/parser.h +++ b/src/util/parser.h @@ -26,8 +26,8 @@ extern "C" { void parser_pushstate(void); void parser_popstate(void); bool parser_end(void); - const char *getstrtoken(void); - const char *gettoken(char *lbuf, size_t bufsize); + char *getstrtoken(void); + char *gettoken(char *lbuf, size_t bufsize); int getuint(void); int getint(void); int getid(void); diff --git a/src/util/unicode.c b/src/util/unicode.c index 90b63205d..b4bb803dd 100644 --- a/src/util/unicode.c +++ b/src/util/unicode.c @@ -11,6 +11,7 @@ #include #include "unicode.h" +#include #include #include #include @@ -36,6 +37,7 @@ int unicode_utf8_trim(utf8_t *buf) { int result = 0, ts = 0; utf8_t *op = buf, *ip = buf, *lc = buf; + assert(buf); while (*ip) { size_t size = 1; wint_t wc = *ip; From 5acfdf5cd04f6927d5f73af900c2fa251648268f Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 24 Apr 2019 15:13:27 +0200 Subject: [PATCH 15/20] fix unused variable warning. --- src/kernel/database.test.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/kernel/database.test.c b/src/kernel/database.test.c index a84a4b286..975d98f7d 100644 --- a/src/kernel/database.test.c +++ b/src/kernel/database.test.c @@ -58,14 +58,16 @@ static void test_update_faction(CuTest *tc) { err = db_driver_faction_save(&id, f->no, faction_getemail(f), faction_getpassword(f)); + CuAssertIntEquals(tc, 0, err); CuAssertTrue(tc, 0 != id); f->uid = (int)id; db_driver_close(DB_GAME); db_driver_open(DB_GAME, NULL); - db_driver_faction_save(&id, f->no, + err = db_driver_faction_save(&id, f->no, faction_getemail(f), faction_getpassword(f)); + CuAssertIntEquals(tc, 0, err); CuAssertIntEquals(tc, f->uid, id); db_driver_close(DB_GAME); test_teardown(); From 692cdcea13cd82a5fed64f12e7c681fb863338b5 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 25 Apr 2019 08:44:48 +0200 Subject: [PATCH 16/20] Rechtschreibung Dragon Evolution: hitpoint tweaking. --- src/races/dragons.c | 2 +- src/spells/combatspells.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/races/dragons.c b/src/races/dragons.c index 5ab877c40..872893b64 100644 --- a/src/races/dragons.c +++ b/src/races/dragons.c @@ -32,9 +32,9 @@ static int age_chance(int a, int b, int p) { static void evolve_dragon(unit * u, const struct race *rc) { scale_number(u, 1); + u->hp = unit_max_hp(u); u_setrace(u, rc); u->irace = NULL; - u->hp = unit_max_hp(u); } void age_firedragon(unit * u) diff --git a/src/spells/combatspells.c b/src/spells/combatspells.c index 2eae5dc6a..e8a1be274 100644 --- a/src/spells/combatspells.c +++ b/src/spells/combatspells.c @@ -62,7 +62,7 @@ static const char *spell_damage(int sp) { switch (sp) { case 0: - /* meist toetlich 20-65 HP */ + /* meist toedlich 20-65 HP */ return "5d10+15"; case 1: /* sehr variabel 4-48 HP */ @@ -71,7 +71,7 @@ static const char *spell_damage(int sp) /* leicht verwundet 4-18 HP */ return "2d8+2"; case 3: - /* fast immer toetlich 30-50 HP */ + /* fast immer toedlich 30-50 HP */ return "5d5+25"; case 4: /* verwundet 11-26 HP */ From 2442aed1dbdce908f331bb24d9888bdcbaa74473 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 25 Apr 2019 16:31:35 +0200 Subject: [PATCH 17/20] null pointer handling for strlcpy --- src/gamedb.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/gamedb.c b/src/gamedb.c index 9af580a9f..abd738ffc 100644 --- a/src/gamedb.c +++ b/src/gamedb.c @@ -17,10 +17,12 @@ static int generate_factions(void *data, db_faction *results, int nresults) faction **iter = (faction **)data; for (i = 0; *iter && i != nresults; ++i) { faction *f = *iter; + const char *pwhash; results[i].p_uid = &f->uid; results[i].no = f->no; results[i].email = faction_getemail(f); - str_strlcpy(results[i].pwhash, faction_getpassword(f), sizeof(results[i].pwhash)); + pwhash = faction_getpassword(f); + str_strlcpy(results[i].pwhash, pwhash ? pwhash : "", sizeof(results[i].pwhash)); *iter = f->next; } return i; From 97afaa29c34bd507e0ad0f895595db3092c2c4b5 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 26 Apr 2019 06:10:17 +0200 Subject: [PATCH 18/20] increase maximum number of submissions per week from 20 to 30. --- process/accept-orders.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/process/accept-orders.py b/process/accept-orders.py index 69a6ce28f..237184861 100755 --- a/process/accept-orders.py +++ b/process/accept-orders.py @@ -54,7 +54,7 @@ hostname = gethostname() orderbase = "orders.dir" sendmail = True # maximum number of reports per sender: -maxfiles = 20 +maxfiles = 30 # write headers to file? writeheaders = True # reject all html email? From cffcac8af7c8904ee1f9ede68ff934ba752ed3a6 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 26 Apr 2019 23:54:22 +0200 Subject: [PATCH 19/20] fix binding faction.no to sqlite statement. --- src/kernel/db/sqlite.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/kernel/db/sqlite.c b/src/kernel/db/sqlite.c index e92f8cd57..6b88ad6c5 100644 --- a/src/kernel/db/sqlite.c +++ b/src/kernel/db/sqlite.c @@ -100,13 +100,20 @@ int db_driver_faction_save(dbrow_id * p_id, int no, const char *email, const cha { dbrow_id id = *p_id; int err; + char dbno[4]; + size_t len; + const char *str; sqlite3_stmt *stmt = (id > 0) ? g_stmt_update_faction : g_stmt_insert_faction; assert(g_game_db); err = sqlite3_reset(stmt); if (err != SQLITE_OK) return err; - err = sqlite3_bind_text(stmt, 1, itoa36(no), -1, SQLITE_STATIC); + str = itoa36(no); + len = strlen(str); + assert(len <= 4); + memcpy(dbno, str, len); + err = sqlite3_bind_text(stmt, 1, dbno, len, SQLITE_STATIC); if (err != SQLITE_OK) return err; err = sqlite3_bind_text(stmt, 2, email, -1, SQLITE_STATIC); if (err != SQLITE_OK) return err; From 968f67a567c249cac1616bd58a247559dcd6e198 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 27 Apr 2019 18:30:30 +0200 Subject: [PATCH 20/20] delete intermittent test: ents have no special guarding powers. --- scripts/eressea/wedding.lua | 2 +- scripts/tests/e2/init.lua | 6 ------ scripts/tests/economy.lua | 18 ------------------ src/bind_unit.c | 28 ++++++++++++++++++++++++++-- src/monsters.c | 2 +- 5 files changed, 28 insertions(+), 28 deletions(-) diff --git a/scripts/eressea/wedding.lua b/scripts/eressea/wedding.lua index 71664eec9..1732392fb 100644 --- a/scripts/eressea/wedding.lua +++ b/scripts/eressea/wedding.lua @@ -15,7 +15,7 @@ local function wedding_travellers(b) local units = {} for u in b.units do - if u:get_flag('wdgt') then + if u:get_key('wdgt') then units[u] = u end end diff --git a/scripts/tests/e2/init.lua b/scripts/tests/e2/init.lua index 55feab5bf..fde840f98 100644 --- a/scripts/tests/e2/init.lua +++ b/scripts/tests/e2/init.lua @@ -1,9 +1,3 @@ -function dump_messages(f) - for k, v in ipairs(f.messages) do - print(v) - end -end - require 'tests.e2.movement' require 'tests.e2.astral' require 'tests.e2.spells' diff --git a/scripts/tests/economy.lua b/scripts/tests/economy.lua index 3379b2ab7..9c72e7e70 100644 --- a/scripts/tests/economy.lua +++ b/scripts/tests/economy.lua @@ -216,21 +216,3 @@ function test_sawmill() assert_equal(6, u:get_item("log")) assert_equal(97, r:get_resource("tree")) end - -function test_ent_guards_trees() - local r = region.create(0, 0, "plain") - r:set_resource("tree", 100) - local u = unit.create(faction.create("human"), r) - u:set_skill("mining", 1) - local guard = unit.create(get_monsters(), r, 1, "ent") - u:set_skill("forestry", 1) - guard:clear_orders() - u:clear_orders() - - guard:add_order("BEWACHEN") - u:add_order("MACHE HOLZ") - process_orders() - assert_equal(1, u:get_item("log")) - process_orders() - assert_equal(1, u:get_item("log")) -end diff --git a/src/bind_unit.c b/src/bind_unit.c index d75323f0b..c5954082b 100644 --- a/src/bind_unit.c +++ b/src/bind_unit.c @@ -760,7 +760,7 @@ static int tolua_unit_has_attrib(lua_State *L) { return 1; } -static int tolua_unit_get_flag(lua_State * L) +static int tolua_unit_get_key(lua_State * L) { unit *self = (unit *)tolua_tousertype(L, 1, 0); const char *name = tolua_tostring(L, 2, 0); @@ -769,7 +769,7 @@ static int tolua_unit_get_flag(lua_State * L) return 1; } -static int tolua_unit_set_flag(lua_State * L) +static int tolua_unit_set_key(lua_State * L) { unit *self = (unit *)tolua_tousertype(L, 1, 0); const char *name = tolua_tostring(L, 2, 0); @@ -784,6 +784,28 @@ static int tolua_unit_set_flag(lua_State * L) return 0; } +static int tolua_unit_get_flag(lua_State * L) +{ + unit *self = (unit *)tolua_tousertype(L, 1, NULL); + int bit = (int)tolua_tonumber(L, 2, 0); + + lua_pushboolean(L, (self->flags & (1 << bit))); + return 1; +} + +static int tolua_unit_set_flag(lua_State * L) +{ + unit *self = (unit *)tolua_tousertype(L, 1, NULL); + int bit = (int)tolua_tonumber(L, 2, 0); + int set = tolua_toboolean(L, 3, 1); + + if (set) + self->flags |= (1 << bit); + else + self->flags &= ~(1 << bit); + return 0; +} + static int tolua_unit_get_weight(lua_State * L) { unit *self = (unit *)tolua_tousertype(L, 1, 0); @@ -959,6 +981,8 @@ void tolua_unit_open(lua_State * L) tolua_function(L, TOLUA_CAST "has_attrib", tolua_unit_has_attrib); /* key-attributes for named flags: */ + tolua_function(L, TOLUA_CAST "set_key", tolua_unit_set_key); + tolua_function(L, TOLUA_CAST "get_key", tolua_unit_get_key); tolua_function(L, TOLUA_CAST "set_flag", tolua_unit_set_flag); tolua_function(L, TOLUA_CAST "get_flag", tolua_unit_get_flag); tolua_variable(L, TOLUA_CAST "guard", tolua_unit_get_guard, diff --git a/src/monsters.c b/src/monsters.c index 290cbdb87..535e03166 100644 --- a/src/monsters.c +++ b/src/monsters.c @@ -442,7 +442,7 @@ static order *monster_move(region * r, unit * u) if (fval(u_race(u), RCF_DRAGON)) { d = richest_neighbour(r, u->faction, 1); } - else if (get_race(RC_TREEMAN)==u_race(u)) { + else if (get_race(RC_TREEMAN) == u_race(u)) { d = treeman_neighbour(r); } else {