Skip to content

Commit

Permalink
Merge branch 'opentibiabr:main' into fix-dmg-console-msg
Browse files Browse the repository at this point in the history
  • Loading branch information
Aerwix authored Nov 5, 2024
2 parents 35361ce + b82568a commit 352081b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 8 deletions.
10 changes: 7 additions & 3 deletions src/creatures/combat/condition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2540,7 +2540,7 @@ void ConditionLight::addCondition(std::shared_ptr<Creature> creature, const std:
const auto &conditionLight = condition->static_self_cast<ConditionLight>();
lightInfo.level = conditionLight->lightInfo.level;
lightInfo.color = conditionLight->lightInfo.color;
lightChangeInterval = ticks / lightInfo.level;
lightChangeInterval = ticks / std::max<uint8_t>(1, lightInfo.level);
internalLightTicks = 0;
creature->setCreatureLight(lightInfo);
g_game().changeLight(creature);
Expand All @@ -2558,9 +2558,13 @@ bool ConditionLight::setParam(ConditionParam_t param, int32_t value) {
}

switch (param) {
case CONDITION_PARAM_LIGHT_LEVEL:
lightInfo.level = value;
case CONDITION_PARAM_LIGHT_LEVEL: {
if (value < 1) {
g_logger().warn("[ConditionLight::setParam] Trying to set invalid light value: '{}', defaulting to 1.", value);
}
lightInfo.level = std::max<uint8_t>(1, static_cast<uint8_t>(value));
return true;
}

case CONDITION_PARAM_LIGHT_COLOR:
lightInfo.color = value;
Expand Down
2 changes: 1 addition & 1 deletion src/creatures/combat/condition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ class ConditionLight final : public Condition {
bool unserializeProp(ConditionAttr_t attr, PropStream &propStream) override;

private:
LightInfo lightInfo;
LightInfo lightInfo { 1, 215 };
uint32_t internalLightTicks = 0;
uint32_t lightChangeInterval = 0;
};
Expand Down
3 changes: 2 additions & 1 deletion src/creatures/players/cyclopedia/player_badge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ std::vector<std::shared_ptr<Player>> PlayerBadge::getPlayersInfoByAccount(const
if (!namesList.empty()) {
namesList += ", ";
}
namesList += fmt::format("'{}'", name);
std::string escapedName = g_database().escapeString(name);
namesList += fmt::format("{}", escapedName);
}

auto query = fmt::format("SELECT name, level, vocation FROM players WHERE name IN ({})", namesList);
Expand Down
24 changes: 21 additions & 3 deletions src/io/functions/iologindata_load_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,28 @@ bool IOLoginDataLoad::loadPlayerBasicInfo(const std::shared_ptr<Player> &player,
player->setOfflineTrainingSkill(skill);
const auto &town = g_game().map.towns.getTown(result->getNumber<uint32_t>("town_id"));
if (!town) {
g_logger().error("Player {} has town id {} which doesn't exist", player->name, result->getNumber<uint16_t>("town_id"));
return false;
g_logger().error("Player {} has invalid town id {}. Attempting to set the correct town.", player->name, result->getNumber<uint16_t>("town_id"));

const auto &thaisTown = g_game().map.towns.getTown("Thais");
if (thaisTown) {
player->town = thaisTown;
g_logger().warn("Assigned town 'Thais' to player {}", player->name);
} else {
for (const auto &[townId, currentTown] : g_game().map.towns.getTowns()) {
if (townId != 0 && currentTown) {
player->town = currentTown;
g_logger().warn("Assigned first valid town {} (id: {}) to player {}", currentTown->getName(), townId, player->name);
}
}

if (!player->town) {
g_logger().error("Player {} has invalid town id {}. No valid town found to assign.", player->name, result->getNumber<uint16_t>("town_id"));
return false;
}
}
} else {
player->town = town;
}
player->town = town;

const Position &loginPos = player->loginPosition;
if (loginPos.x == 0 && loginPos.y == 0 && loginPos.z == 0) {
Expand Down

0 comments on commit 352081b

Please sign in to comment.