Skip to content

Commit

Permalink
sonar issues
Browse files Browse the repository at this point in the history
  • Loading branch information
murilo09 committed Oct 27, 2024
1 parent f16662f commit 5801a39
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 56 deletions.
2 changes: 1 addition & 1 deletion src/creatures/players/player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1584,7 +1584,7 @@ class Player final : public Creature, public Cylinder, public Bankable {
}

BidErrorMessage canBidHouse(uint32_t houseId);
void sendCyclopediaHouseList(HouseMap houses) {
void sendCyclopediaHouseList(HouseMap &houses) {
if (client) {
client->sendCyclopediaHouseList(houses);
}
Expand Down
10 changes: 5 additions & 5 deletions src/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10241,7 +10241,7 @@ bool Game::removeFiendishMonster(uint32_t id, bool create /* = true*/) {
}

void Game::updateForgeableMonsters() {
if (auto influencedLimit = g_configManager().getNumber(FORGE_INFLUENCED_CREATURES_LIMIT, __FUNCTION__);
if (auto influencedLimit = g_configManager().getNumber(FORGE_INFLUENCED_CREATURES_LIMIT);
forgeableMonsters.size() < influencedLimit * 2) {
forgeableMonsters.clear();
for (const auto &[monsterId, monster] : monsters) {
Expand Down Expand Up @@ -10740,7 +10740,7 @@ const std::unordered_map<uint16_t, std::string> &Game::getHirelingOutfits() {
return m_hirelingOutfits;
}

void Game::playerCyclopediaHousesByTown(uint32_t playerId, const std::string townName) {
void Game::playerCyclopediaHousesByTown(uint32_t playerId, const std::string &townName) {
std::shared_ptr<Player> player = getPlayerByID(playerId);
if (!player) {
return;
Expand All @@ -10756,7 +10756,7 @@ void Game::playerCyclopediaHousesByTown(uint32_t playerId, const std::string tow
return;
}

const std::string houseTown = town->getName();
const std::string &houseTown = town->getName();
if (houseTown == townName) {
houses.emplace(house->getClientId(), house);
}
Expand All @@ -10781,7 +10781,7 @@ void Game::playerCyclopediaHousesByTown(uint32_t playerId, const std::string tow
}

void Game::playerCyclopediaHouseBid(uint32_t playerId, uint32_t houseId, uint64_t bidValue) {
if (!g_configManager().getBoolean(CYCLOPEDIA_HOUSE_AUCTION, __FUNCTION__)) {
if (!g_configManager().getBoolean(CYCLOPEDIA_HOUSE_AUCTION)) {
return;
}

Expand Down Expand Up @@ -10846,7 +10846,7 @@ void Game::playerCyclopediaHouseBid(uint32_t playerId, uint32_t houseId, uint64_
}

void Game::playerCyclopediaHouseLeave(uint32_t playerId, uint32_t houseId, uint32_t timestamp) {
if (!g_configManager().getBoolean(CYCLOPEDIA_HOUSE_AUCTION, __FUNCTION__)) {
if (!g_configManager().getBoolean(CYCLOPEDIA_HOUSE_AUCTION)) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/game/game.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ class Game {
static std::string getSkillNameById(uint8_t &skill);

// House Auction
void playerCyclopediaHousesByTown(uint32_t playerId, const std::string townName);
void playerCyclopediaHousesByTown(uint32_t playerId, const std::string &townName);
void playerCyclopediaHouseBid(uint32_t playerId, uint32_t houseId, uint64_t bidValue);
void playerCyclopediaHouseLeave(uint32_t playerId, uint32_t houseId, uint32_t timestamp);
bool processBankAuction(std::shared_ptr<Player> player, std::shared_ptr<House> house, uint64_t bid, bool replace = false);
Expand Down
38 changes: 19 additions & 19 deletions src/map/house/house.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ void House::setOwner(uint32_t guid, bool updateDatabase /* = true*/, std::shared
}

if (guid != 0) {
std::string strRentPeriod = asLowerCaseString(g_configManager().getString(HOUSE_RENT_PERIOD, __FUNCTION__));
std::string strRentPeriod = asLowerCaseString(g_configManager().getString(HOUSE_RENT_PERIOD));
time_t currentTime = time(nullptr);
if (strRentPeriod == "yearly") {
currentTime += 24 * 60 * 60 * 365;
Expand Down Expand Up @@ -140,7 +140,7 @@ void House::setOwner(uint32_t guid, bool updateDatabase /* = true*/, std::shared
owner = guid;
ownerName = name;
ownerAccountId = result->getNumber<uint32_t>("account_id");
state = 2;
m_state = 2;
}
}

Expand All @@ -155,14 +155,14 @@ void House::updateDoorDescription() const {
ss << "It belongs to house '" << houseName << "'. Nobody owns this house.";
}

if (!g_configManager().getBoolean(CYCLOPEDIA_HOUSE_AUCTION, __FUNCTION__)) {
if (!g_configManager().getBoolean(CYCLOPEDIA_HOUSE_AUCTION)) {
ss << " It is " << getSize() << " square meters.";
const int32_t housePrice = getPrice();
if (housePrice != -1) {
if (g_configManager().getBoolean(HOUSE_PURSHASED_SHOW_PRICE, __FUNCTION__) || owner == 0) {
if (g_configManager().getBoolean(HOUSE_PURSHASED_SHOW_PRICE) || owner == 0) {
ss << " It costs " << formatNumber(getPrice()) << " gold coins.";
}
std::string strRentPeriod = asLowerCaseString(g_configManager().getString(HOUSE_RENT_PERIOD, __FUNCTION__));
std::string strRentPeriod = asLowerCaseString(g_configManager().getString(HOUSE_RENT_PERIOD));
if (strRentPeriod != "never") {
ss << " The rent cost is " << formatNumber(getRent()) << " gold coins and it is billed " << strRentPeriod << ".";
}
Expand Down Expand Up @@ -484,19 +484,19 @@ void House::resetTransferItem() {
void House::calculateBidEndDate(uint8_t daysToEnd) {
auto currentTimeMs = std::chrono::system_clock::now().time_since_epoch();

std::chrono::system_clock::time_point now = std::chrono::system_clock::time_point(
auto now = std::chrono::system_clock::time_point(
std::chrono::duration_cast<std::chrono::milliseconds>(currentTimeMs)
);

// Truncate to whole days since epoch
days daysSinceEpoch = std::chrono::duration_cast<days>(now.time_since_epoch());

// Get today's date at 00:00:00 UTC
std::chrono::system_clock::time_point todayMidnight = std::chrono::system_clock::time_point(daysSinceEpoch);
auto todayMidnight = std::chrono::system_clock::time_point(daysSinceEpoch);

std::chrono::system_clock::time_point targetDay = todayMidnight + days(daysToEnd);

const auto serverSaveTime = g_configManager().getString(GLOBAL_SERVER_SAVE_TIME, __FUNCTION__);
const auto serverSaveTime = g_configManager().getString(GLOBAL_SERVER_SAVE_TIME);

std::vector<int32_t> params = vectorAtoi(explodeString(serverSaveTime, ":"));
int32_t hour = params.front();
Expand All @@ -513,9 +513,9 @@ void House::calculateBidEndDate(uint8_t daysToEnd) {

std::time_t resultTime = std::chrono::system_clock::to_time_t(targetTime);
std::tm* localTime = std::localtime(&resultTime);
uint32_t bidEndDate = static_cast<uint32_t>(std::mktime(localTime));
auto bidEndDate = static_cast<uint32_t>(std::mktime(localTime));

this->bidEndDate = bidEndDate;
this->m_bidEndDate = bidEndDate;
}

std::shared_ptr<HouseTransferItem> HouseTransferItem::createHouseTransferItem(std::shared_ptr<House> house) {
Expand Down Expand Up @@ -766,27 +766,27 @@ std::shared_ptr<House> Houses::getHouseByPlayerId(uint32_t playerId) {

std::vector<std::shared_ptr<House>> Houses::getAllHousesByPlayerId(uint32_t playerId) {
std::vector<std::shared_ptr<House>> playerHouses;
for (const auto &it : houseMap) {
if (it.second->getOwner() == playerId) {
playerHouses.emplace_back(it.second);
for (const auto &[id, house] : houseMap) {

Check warning on line 769 in src/map/house/house.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

[cppcheck] src/map/house/house.cpp#L769

Unused variable: id
Raw output
src/map/house/house.cpp:769:Unused variable: id
if (house->getOwner() == playerId) {
playerHouses.emplace_back(house);
}
}
return playerHouses;
}

std::shared_ptr<House> Houses::getHouseByBidderName(std::string bidderName) {
for (const auto &it : houseMap) {
if (it.second->getBidderName() == bidderName) {
return it.second;
std::shared_ptr<House> Houses::getHouseByBidderName(const std::string &bidderName) {
for (const auto &[id, house] : houseMap) {

Check warning on line 778 in src/map/house/house.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

[cppcheck] src/map/house/house.cpp#L778

Unused variable: id
Raw output
src/map/house/house.cpp:778:Unused variable: id
if (house->getBidderName() == bidderName) {
return house;
}
}
return nullptr;
}

uint16_t Houses::getHouseCountByAccount(uint32_t accountId) {
uint16_t count = 0;
for (const auto &it : houseMap) {
if (it.second->getOwnerAccountId() == accountId) {
for (const auto &[id, house] : houseMap) {

Check warning on line 788 in src/map/house/house.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

[cppcheck] src/map/house/house.cpp#L788

Unused variable: id
Raw output
src/map/house/house.cpp:788:Unused variable: id
if (house->getOwnerAccountId() == accountId) {
++count;
}
}
Expand Down
52 changes: 26 additions & 26 deletions src/map/house/house.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,60 +236,60 @@ class House : public SharedObject {
void setNewOwnership();

void setClientId(uint32_t newClientId) {
this->clientId = newClientId;
this->m_clientId = newClientId;
}
uint32_t getClientId() const {
return clientId;
return m_clientId;
}

void setBidder(int32_t bidder) {
this->bidder = bidder;
this->m_bidder = bidder;
}
int32_t getBidder() const {
return bidder;
return m_bidder;
}

void setBidderName(std::string bidderName) {
this->bidderName = bidderName;
void setBidderName(const std::string &bidderName) {
this->m_bidderName = bidderName;
}
std::string getBidderName() const {
return bidderName;
return m_bidderName;
}

void setHighestBid(uint64_t bidValue) {
this->highestBid = bidValue;
this->m_highestBid = bidValue;
}
uint64_t getHighestBid() const {
return highestBid;
return m_highestBid;
}

void setInternalBid(uint64_t bidValue) {
this->internalBid = bidValue;
this->m_internalBid = bidValue;
}
uint64_t getInternalBid() const {
return internalBid;
return m_internalBid;
}

void setBidHolderLimit(uint64_t bidValue) {
this->bidHolderLimit = bidValue;
this->m_bidHolderLimit = bidValue;
}
uint64_t getBidHolderLimit() const {
return bidHolderLimit;
return m_bidHolderLimit;
}

void calculateBidEndDate(uint8_t daysToEnd);
void setBidEndDate(uint32_t bidEndDate) {
this->bidEndDate = bidEndDate;
this->m_bidEndDate = bidEndDate;
};
uint32_t getBidEndDate() const {
return bidEndDate;
return m_bidEndDate;
}

void setState(uint8_t state) {
this->state = state;
this->m_state = state;
}
uint8_t getState() const {
return state;
return m_state;
}

void setOwnerAccountId(uint32_t accountId) {
Expand Down Expand Up @@ -341,14 +341,14 @@ class House : public SharedObject {
Position posEntry = {};

// House Auction
uint32_t clientId;
int32_t bidder = 0;
std::string bidderName = "";
uint64_t highestBid = 0;
uint64_t internalBid = 0;
uint64_t bidHolderLimit = 0;
uint32_t bidEndDate = 0;
uint8_t state = 0;
uint32_t m_clientId;
int32_t m_bidder = 0;
std::string m_bidderName = "";
uint64_t m_highestBid = 0;
uint64_t m_internalBid = 0;
uint64_t m_bidHolderLimit = 0;
uint32_t m_bidEndDate = 0;
uint8_t m_state = 0;

bool isLoaded = false;

Expand Down Expand Up @@ -401,7 +401,7 @@ class Houses {

std::shared_ptr<House> getHouseByPlayerId(uint32_t playerId);
std::vector<std::shared_ptr<House>> getAllHousesByPlayerId(uint32_t playerId);
std::shared_ptr<House> getHouseByBidderName(std::string bidderName);
std::shared_ptr<House> getHouseByBidderName(const std::string &bidderName);
uint16_t getHouseCountByAccount(uint32_t accountId);

bool loadHousesXML(const std::string &filename);
Expand Down
5 changes: 1 addition & 4 deletions src/server/network/protocol/protocolgame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9295,10 +9295,7 @@ void ProtocolGame::sendCyclopediaHouseList(HouseMap houses) {
NetworkMessage msg;
msg.addByte(0xC7);
msg.add<uint16_t>(houses.size());
for (const auto &house : houses) {
const auto clientId = house.first;
const auto &houseData = house.second;

for (const auto &[clientId, houseData] : houses) {
msg.add<uint32_t>(clientId);
msg.addByte(0x01); // 0x00 = Renovation; 0x01 = Available

Expand Down

0 comments on commit 5801a39

Please sign in to comment.