Fixes for issues Sonar view as 'critical'

This commit is contained in:
Ivan Savenko
2026-06-19 12:54:08 +03:00
parent 3d181d5188
commit 30458c35ce
15 changed files with 51 additions and 26 deletions
+4 -1
View File
@@ -460,6 +460,8 @@ void ApplyClientNetPackVisitor::visitRemoveBonus(RemoveBonus & pack)
void ApplyFirstClientNetPackVisitor::visitRemoveObject(RemoveObject & pack)
{
const CGObjectInstance *o = cl.gameInfo().getObj(pack.objectID);
if(!o)
return;
const auto * h = dynamic_cast<const CGHeroInstance*>(o);
GAME->map().onObjectFadeOut(o, pack.initiator);
@@ -474,7 +476,8 @@ void ApplyFirstClientNetPackVisitor::visitRemoveObject(RemoveObject & pack)
{
//below line contains little cheat for AI so it will be aware of deletion of enemy heroes that moved or got re-covered by FoW
//TODO: loose requirements as next AI related crashes appear, for example another pack.player collects object that got re-covered by FoW, unsure if AI code workarounds this
if(gs.isVisibleFor(o, i->first) || (!cl.gameInfo().getPlayerState(i->first)->human && o->ID == Obj::HERO && o->tempOwner != i->first))
const auto * playerState = cl.gameInfo().getPlayerState(i->first);
if(gs.isVisibleFor(o, i->first) || (playerState && !playerState->human && o->ID == Obj::HERO && o->tempOwner != i->first))
{
i->second->objectRemoved(o, pack.initiator);
if (h && h->inBoat())
+1 -1
View File
@@ -168,7 +168,7 @@ void CQuestLog::recreateLabelList()
toSeer.replaceRawString(seersHut->seerName);
text.replaceRawString(toSeer.toString());
}
else
else if(questObject)
text.replaceRawString(questObject->getObjectName()); //get name of the object
}
auto label = std::make_shared<CQuestLabel>(Rect(13, 195, 149,31), FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE, text.toString());
@@ -411,7 +411,7 @@ CStackWindow::StackExperienceDetailsWindow::StackExperienceDetailsWindow(const C
return PreferredRowPresentation{LIBRARY->generaltexth->translate("vcmi.stackExperience.table.maxDamage"), ImagePath::builtin("stackExperienceIconMaxDamage"), LIBRARY->generaltexth->translate("vcmi.stackExperience.desc.maxDamage"), std::nullopt};
if(key.type == BonusType::STACK_HEALTH)
{
auto override = [selector = makeStackExpSelector(key)](const CStackInstance & stackInst)
auto valueOverride = [selector = makeStackExpSelector(key)](const CStackInstance & stackInst)
{
int result = 0;
auto bonuses = stackInst.getBonuses(selector);
@@ -419,7 +419,7 @@ CStackWindow::StackExperienceDetailsWindow::StackExperienceDetailsWindow(const C
result += b->val;
return result;
};
return PreferredRowPresentation{LIBRARY->generaltexth->allTexts[388], ImagePath::builtin("stackExperienceIconHealth"), LIBRARY->generaltexth->translate("vcmi.stackExperience.desc.health"), override};
return PreferredRowPresentation{LIBRARY->generaltexth->allTexts[388], ImagePath::builtin("stackExperienceIconHealth"), LIBRARY->generaltexth->translate("vcmi.stackExperience.desc.health"), valueOverride};
}
if(key.type == BonusType::STACKS_SPEED)
return PreferredRowPresentation{LIBRARY->generaltexth->allTexts[193], ImagePath::builtin("stackExperienceIconSpeed"), LIBRARY->generaltexth->translate("vcmi.stackExperience.desc.speed"), std::nullopt};
+3 -1
View File
@@ -12,6 +12,7 @@
#include "StdInc.h"
#include "../Global.h"
#include <vstd/DateUtils.h>
#include "../client/ClientCommandManager.h"
#include "../client/CMT.h"
@@ -109,8 +110,9 @@ static void prog_version()
static void prog_help(const po::options_description &opts)
{
auto time = std::time(nullptr);
std::tm tm = vstd::safeLocalTime(time);
printf("%s - A Heroes of Might and Magic 3 clone\n", GameConstants::VCMI_PROJECT_NAME_VERSIONED);
printf("Copyright (C) 2007-%d VCMI dev team - see AUTHORS file\n", std::localtime(&time)->tm_year + 1900);
printf("Copyright (C) 2007-%d VCMI dev team - see AUTHORS file\n", tm.tm_year + 1900);
printf("This is free software; see the source for copying conditions. There is NO\n");
printf("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n");
printf("\n");
@@ -8,6 +8,6 @@
<a href="https://github.com/vcmi/vcmi">GitHub</a>
</h4>
<h5>
<a href="https://m.do.co/c/b2d5cf698ed1"><img src="https://opensource.nyc3.cdn.digitaloceanspaces.com/attribution/assets/PoweredByDO/DO_Powered_by_Badge_black.svg" width="201px"></a>
<a href="https://m.do.co/c/b2d5cf698ed1"><img src="https://opensource.nyc3.cdn.digitaloceanspaces.com/attribution/assets/PoweredByDO/DO_Powered_by_Badge_black.svg" width="201px" alt="Powered by DigitalOcean"></a>
</h5>
</body></html>
+11
View File
@@ -8,6 +8,17 @@ namespace vstd
DLL_LINKAGE std::string getFormattedDateTime(std::time_t dt, std::string format);
DLL_LINKAGE std::string getDateTimeISO8601Basic(std::time_t dt);
inline std::tm safeLocalTime(std::time_t dt)
{
std::tm tm{};
#ifdef _WIN32
localtime_s(&tm, &dt);
#else
localtime_r(&dt, &tm);
#endif
return tm;
}
}
VCMI_LIB_NAMESPACE_END
+1 -1
View File
@@ -10,7 +10,7 @@ for binary in "../$EXECUTABLE_NAME" $(find . -type f -iname '*.dylib'); do
echo "checking $binary"
# dyld_info sample output: @rpath/libogg.0.dylib
for lib in $(dyld_info -linked_dylibs "$binary" | awk -F / '/@rpath/ {print $2}'); do
if [ -L "$lib" ]; then
if [[ -L "$lib" ]]; then
echo "- symlink: $lib"
rpathSymlinks+=("$lib")
fi
+11 -5
View File
@@ -165,13 +165,19 @@ const ResourceSet::nziterator::ResEntry * ResourceSet::nziterator::operator->()
void ResourceSet::nziterator::advance()
{
do
const auto resourceCount = static_cast<int>(LIBRARY->resourceTypeHandler->getAllObjects().size());
while(true)
{
++cur.resType;
} while(static_cast<int>(cur.resType) < LIBRARY->resourceTypeHandler->getAllObjects().size() && !(cur.resVal=rs[cur.resType]));
if(static_cast<int>(cur.resType) >= LIBRARY->resourceTypeHandler->getAllObjects().size())
cur.resVal = -1;
if(static_cast<int>(cur.resType) >= resourceCount)
{
cur.resVal = -1;
return;
}
cur.resVal = rs[cur.resType];
if(cur.resVal)
return;
}
}
ResourceSet::nziterator::nziterator(const ResourceSet &RS)
+9 -7
View File
@@ -11,6 +11,8 @@
#include "StdInc.h"
#include "CZipSaver.h"
#include <vstd/DateUtils.h>
VCMI_LIB_NAMESPACE_BEGIN
///CZipOutputStream
@@ -23,13 +25,13 @@ CZipOutputStream::CZipOutputStream(CZipSaver * owner_, zipFile archive, const st
std::time_t t = time(nullptr);
fileInfo.dosDate = 0;
struct tm * localTime = std::localtime(&t);
fileInfo.tmz_date.tm_hour = localTime->tm_hour;
fileInfo.tmz_date.tm_mday = localTime->tm_mday;
fileInfo.tmz_date.tm_min = localTime->tm_min;
fileInfo.tmz_date.tm_mon = localTime->tm_mon;
fileInfo.tmz_date.tm_sec = localTime->tm_sec;
fileInfo.tmz_date.tm_year = localTime->tm_year;
std::tm localTime = vstd::safeLocalTime(t);
fileInfo.tmz_date.tm_hour = localTime.tm_hour;
fileInfo.tmz_date.tm_mday = localTime.tm_mday;
fileInfo.tmz_date.tm_min = localTime.tm_min;
fileInfo.tmz_date.tm_mon = localTime.tm_mon;
fileInfo.tmz_date.tm_sec = localTime.tm_sec;
fileInfo.tmz_date.tm_year = localTime.tm_year;
fileInfo.external_fa = 0; //???
fileInfo.internal_fa = 0;
-2
View File
@@ -658,7 +658,6 @@ struct DLL_LINKAGE HireHero : public CPackForServer
HeroTypeID hid; //available hero serial
HeroTypeID nhid; //next hero
ObjectInstanceID tid; //town (tavern) id
PlayerColor player;
void visitTyped(ICPackVisitor & visitor) override;
@@ -668,7 +667,6 @@ struct DLL_LINKAGE HireHero : public CPackForServer
h & hid;
h & nhid;
h & tid;
h & player;
}
};
+1 -1
View File
@@ -16,7 +16,7 @@ CSaveFile::CSaveFile()
: serializer(this)
{
saveData.reserve(128*1024);
static const char * SAVE_HEADER = "VCMI";
static constexpr const char * SAVE_HEADER = "VCMI";
write(reinterpret_cast<const std::byte*>(SAVE_HEADER), 4); //write magic identifier
serializer & ESerializationVersion::CURRENT; //write format version
+1 -1
View File
@@ -17,7 +17,7 @@ namespace vstd
DLL_LINKAGE std::string getFormattedDateTime(std::time_t dt, std::string format)
{
std::tm tm = *std::localtime(&dt);
std::tm tm = safeLocalTime(dt);
std::stringstream s;
s << std::put_time(&tm, format.c_str());
return s.str();
+1 -1
View File
@@ -120,7 +120,7 @@ public:
void pushMetatable(lua_State * L) const final
{
static const auto KEY = api::Registry::get()->getTypeName<UDataType>();
static auto S_KEY = api::Registry::get()->getTypeName<CUDataType>();
static const auto S_KEY = api::Registry::get()->getTypeName<CUDataType>();
LuaStack S(L);
+1 -1
View File
@@ -467,7 +467,7 @@ void ApplyOnServerNetPackVisitor::visitLobbyDelete(LobbyDelete & pack)
}
LobbyUpdateState lus;
lus.state = srv;
lus.state = *static_cast<LobbyState*>(&srv);
lus.refreshList = true;
srv.announcePack(lus);
}
+4 -1
View File
@@ -9,6 +9,8 @@
*/
#include "StdInc.h"
#include <vstd/DateUtils.h>
#include "../server/CVCMIServer.h"
#include "../lib/CConsoleHandler.h"
@@ -253,8 +255,9 @@ static void handleCommandOptions(int argc, const char * argv[], boost::program_o
if(options.count("help"))
{
auto time = std::time(nullptr);
std::tm tm = vstd::safeLocalTime(time);
printf("%s - A Heroes of Might and Magic 3 clone\n", GameConstants::VCMI_PROJECT_NAME_VERSIONED);
printf("Copyright (C) 2007-%d VCMI dev team - see AUTHORS file\n", std::localtime(&time)->tm_year + 1900);
printf("Copyright (C) 2007-%d VCMI dev team - see AUTHORS file\n", tm.tm_year + 1900);
printf("This is free software; see the source for copying conditions. There is NO\n");
printf("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n");
printf("\n");