Skip to content

Commit

Permalink
Merge branch 'main' into safecall
Browse files Browse the repository at this point in the history
  • Loading branch information
mehah authored Nov 4, 2024
2 parents 37a76d2 + b82568a commit 364a16b
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 13 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
1 change: 0 additions & 1 deletion src/creatures/combat/spells.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ class Spells final : public Scripts {
std::list<uint16_t> getSpellsByVocation(uint16_t vocationId);

[[nodiscard]] const std::map<std::string, std::shared_ptr<InstantSpell>> &getInstantSpells() const;
;

[[nodiscard]] bool hasInstantSpell(const std::string &word) const;

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
4 changes: 1 addition & 3 deletions src/creatures/players/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9133,8 +9133,6 @@ void Player::forgeTransferItemTier(ForgeAction_t actionType, uint16_t donorItemI
g_logger().error("[Log 8] Failed to remove transfer dusts from player with name {}", getName());
sendForgeError(RETURNVALUE_CONTACTADMINISTRATOR);
return;
} else {
setForgeDusts(getForgeDusts() - g_configManager().getNumber(configKey));
}

setForgeDusts(getForgeDusts() - g_configManager().getNumber(configKey));
Expand Down Expand Up @@ -10068,7 +10066,7 @@ bool Player::setAccount(uint32_t accountId) {
}

uint8_t Player::getAccountType() const {
return account ? account->getAccountType() : static_cast<uint8_t>(AccountType::ACCOUNT_TYPE_NORMAL);
return account ? account->getAccountType() : AccountType::ACCOUNT_TYPE_NORMAL;
}

uint32_t Player::getAccountId() const {
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
1 change: 0 additions & 1 deletion src/io/functions/iologindata_save_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ bool IOLoginDataSave::saveItems(const std::shared_ptr<Player> &player, const Ite
// Serialize item attributes
propWriteStream.clear();
item->serializeAttr(propWriteStream);
item->stopDecaying();

size_t attributesSize;
const char* attributes = propWriteStream.getStream(attributesSize);
Expand Down

0 comments on commit 364a16b

Please sign in to comment.