Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use TFS code style on comparison and boolean check #3725

Merged
merged 4 commits into from
Oct 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ban.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,5 @@ bool IOBan::isIpBanned(uint32_t clientIP, BanInfo& banInfo)

bool IOBan::isPlayerNamelocked(uint32_t playerId)
{
return Database::getInstance().storeQuery(fmt::format("SELECT 1 FROM `player_namelocks` WHERE `player_id` = {:d}", playerId)).get() != nullptr;
return Database::getInstance().storeQuery(fmt::format("SELECT 1 FROM `player_namelocks` WHERE `player_id` = {:d}", playerId)).get();
}
2 changes: 1 addition & 1 deletion src/bed.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class BedItem final : public Item
void serializeAttr(PropWriteStream& propWriteStream) const override;

bool canRemove() const override {
return house == nullptr;
return !house;
}

uint32_t getSleeper() const {
Expand Down
16 changes: 8 additions & 8 deletions src/container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ std::string Container::getName(bool addArticle /* = false*/) const {

bool Container::hasParent() const
{
return getID() != ITEM_BROWSEFIELD && dynamic_cast<const Player*>(getParent()) == nullptr;
return getID() != ITEM_BROWSEFIELD && !dynamic_cast<const Player*>(getParent());
}

void Container::addItem(Item* item)
Expand Down Expand Up @@ -281,7 +281,7 @@ ReturnValue Container::queryAdd(int32_t index, const Thing& thing, uint32_t coun
}

const Item* item = thing.getItem();
if (item == nullptr) {
if (!item) {
return RETURNVALUE_NOTPOSSIBLE;
}

Expand Down Expand Up @@ -346,7 +346,7 @@ ReturnValue Container::queryMaxCount(int32_t index, const Thing& thing, uint32_t
uint32_t& maxQueryCount, uint32_t flags) const
{
const Item* item = thing.getItem();
if (item == nullptr) {
if (!item) {
maxQueryCount = 0;
return RETURNVALUE_NOTPOSSIBLE;
}
Expand Down Expand Up @@ -401,7 +401,7 @@ ReturnValue Container::queryRemove(const Thing& thing, uint32_t count, uint32_t
}

const Item* item = thing.getItem();
if (item == nullptr) {
if (!item) {
return RETURNVALUE_NOTPOSSIBLE;
}

Expand Down Expand Up @@ -506,7 +506,7 @@ void Container::addThing(int32_t index, Thing* thing)
}

Item* item = thing->getItem();
if (item == nullptr) {
if (!item) {
return /*RETURNVALUE_NOTPOSSIBLE*/;
}

Expand Down Expand Up @@ -539,7 +539,7 @@ void Container::updateThing(Thing* thing, uint16_t itemId, uint32_t count)
}

Item* item = thing->getItem();
if (item == nullptr) {
if (!item) {
return /*RETURNVALUE_NOTPOSSIBLE*/;
}

Expand Down Expand Up @@ -581,7 +581,7 @@ void Container::replaceThing(uint32_t index, Thing* thing)
void Container::removeThing(Thing* thing, uint32_t count)
{
Item* item = thing->getItem();
if (item == nullptr) {
if (!item) {
return /*RETURNVALUE_NOTPOSSIBLE*/;
}

Expand Down Expand Up @@ -712,7 +712,7 @@ void Container::internalAddThing(Thing* thing)
void Container::internalAddThing(uint32_t, Thing* thing)
{
Item* item = thing->getItem();
if (item == nullptr) {
if (!item) {
return;
}

Expand Down
4 changes: 2 additions & 2 deletions src/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ void Creature::onDeath()
if (mostDamageCreature) {
if (mostDamageCreature != lastHitCreature && mostDamageCreature != lastHitCreatureMaster) {
Creature* mostDamageCreatureMaster = mostDamageCreature->getMaster();
if (lastHitCreature != mostDamageCreatureMaster && (lastHitCreatureMaster == nullptr || mostDamageCreatureMaster != lastHitCreatureMaster)) {
if (lastHitCreature != mostDamageCreatureMaster && (!lastHitCreatureMaster || mostDamageCreatureMaster != lastHitCreatureMaster)) {
mostDamageUnjustified = mostDamageCreature->onKilledCreature(this, false);
}
}
Expand Down Expand Up @@ -1181,7 +1181,7 @@ bool Creature::setMaster(Creature* newMaster) {

bool Creature::addCondition(Condition* condition, bool force/* = false*/)
{
if (condition == nullptr) {
if (!condition) {
return false;
}

Expand Down
12 changes: 6 additions & 6 deletions src/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ extern ConfigManager g_config;

Database::~Database()
{
if (handle != nullptr) {
if (handle) {
mysql_close(handle);
}
}
Expand Down Expand Up @@ -137,7 +137,7 @@ DBResult_ptr Database::storeQuery(const std::string& query)
// we should call that every time as someone would call executeQuery('SELECT...')
// as it is described in MySQL manual: "it doesn't hurt" :P
MYSQL_RES* res = mysql_store_result(handle);
if (res == nullptr) {
if (!res) {
std::cout << "[Error - mysql_store_result] Query: " << query << std::endl << "Message: " << mysql_error(handle) << std::endl;
auto error = mysql_errno(handle);
if (error != CR_SERVER_LOST && error != CR_SERVER_GONE_ERROR && error != CR_CONN_HOST_ERROR && error != 1053/*ER_SERVER_SHUTDOWN*/ && error != CR_CONNECTION_ERROR) {
Expand Down Expand Up @@ -209,7 +209,7 @@ std::string DBResult::getString(const std::string& s) const
return std::string();
}

if (row[it->second] == nullptr) {
if (!row[it->second]) {
return std::string();
}

Expand All @@ -225,7 +225,7 @@ const char* DBResult::getStream(const std::string& s, unsigned long& size) const
return nullptr;
}

if (row[it->second] == nullptr) {
if (!row[it->second]) {
size = 0;
return nullptr;
}
Expand All @@ -236,13 +236,13 @@ const char* DBResult::getStream(const std::string& s, unsigned long& size) const

bool DBResult::hasNext() const
{
return row != nullptr;
return row;
}

bool DBResult::next()
{
row = mysql_fetch_row(handle);
return row != nullptr;
return row;
}

DBInsert::DBInsert(std::string query) : query(std::move(query))
Expand Down
2 changes: 1 addition & 1 deletion src/database.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class DBResult
return static_cast<T>(0);
}

if (row[it->second] == nullptr) {
if (!row[it->second]) {
return static_cast<T>(0);
}

Expand Down
4 changes: 2 additions & 2 deletions src/databasemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ bool DatabaseManager::optimizeTables()
bool DatabaseManager::tableExists(const std::string& tableName)
{
Database& db = Database::getInstance();
return db.storeQuery(fmt::format("SELECT `TABLE_NAME` FROM `information_schema`.`tables` WHERE `TABLE_SCHEMA` = {:s} AND `TABLE_NAME` = {:s} LIMIT 1", db.escapeString(g_config.getString(ConfigManager::MYSQL_DB)), db.escapeString(tableName))).get() != nullptr;
return db.storeQuery(fmt::format("SELECT `TABLE_NAME` FROM `information_schema`.`tables` WHERE `TABLE_SCHEMA` = {:s} AND `TABLE_NAME` = {:s} LIMIT 1", db.escapeString(g_config.getString(ConfigManager::MYSQL_DB)), db.escapeString(tableName))).get();
}

bool DatabaseManager::isDatabaseSetup()
{
Database& db = Database::getInstance();
return db.storeQuery(fmt::format("SELECT `TABLE_NAME` FROM `information_schema`.`tables` WHERE `TABLE_SCHEMA` = {:s}", db.escapeString(g_config.getString(ConfigManager::MYSQL_DB)))).get() != nullptr;
return db.storeQuery(fmt::format("SELECT `TABLE_NAME` FROM `information_schema`.`tables` WHERE `TABLE_SCHEMA` = {:s}", db.escapeString(g_config.getString(ConfigManager::MYSQL_DB)))).get();
}

int32_t DatabaseManager::getDatabaseVersion()
Expand Down
6 changes: 3 additions & 3 deletions src/depotchest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ ReturnValue DepotChest::queryAdd(int32_t index, const Thing& thing, uint32_t cou
uint32_t flags, Creature* actor/* = nullptr*/) const
{
const Item* item = thing.getItem();
if (item == nullptr) {
if (!item) {
return RETURNVALUE_NOTPOSSIBLE;
}

Expand Down Expand Up @@ -60,15 +60,15 @@ ReturnValue DepotChest::queryAdd(int32_t index, const Thing& thing, uint32_t cou
void DepotChest::postAddNotification(Thing* thing, const Cylinder* oldParent, int32_t index, cylinderlink_t)
{
Cylinder* parent = getParent();
if (parent != nullptr) {
if (parent) {
parent->postAddNotification(thing, oldParent, index, LINK_PARENT);
}
}

void DepotChest::postRemoveNotification(Thing* thing, const Cylinder* newParent, int32_t index, cylinderlink_t)
{
Cylinder* parent = getParent();
if (parent != nullptr) {
if (parent) {
parent->postRemoveNotification(thing, newParent, index, LINK_PARENT);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/depotlocker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ ReturnValue DepotLocker::queryAdd(int32_t, const Thing&, uint32_t, uint32_t, Cre

void DepotLocker::postAddNotification(Thing* thing, const Cylinder* oldParent, int32_t index, cylinderlink_t)
{
if (parent != nullptr) {
if (parent) {
parent->postAddNotification(thing, oldParent, index, LINK_PARENT);
}
}

void DepotLocker::postRemoveNotification(Thing* thing, const Cylinder* newParent, int32_t index, cylinderlink_t)
{
if (parent != nullptr) {
if (parent) {
parent->postRemoveNotification(thing, newParent, index, LINK_PARENT);
}
}
Expand Down
30 changes: 15 additions & 15 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ Player* Game::getPlayerByAccount(uint32_t acc)

bool Game::internalPlaceCreature(Creature* creature, const Position& pos, bool extendedPos /*=false*/, bool forced /*= false*/)
{
if (creature->getParent() != nullptr) {
if (creature->getParent()) {
return false;
}

Expand Down Expand Up @@ -804,7 +804,7 @@ ReturnValue Game::internalMoveCreature(Creature* creature, Direction direction,
//try to go up
if (currentPos.z != 8 && creature->getTile()->hasHeight(3)) {
Tile* tmpTile = map.getTile(currentPos.x, currentPos.y, currentPos.getZ() - 1);
if (tmpTile == nullptr || (tmpTile->getGround() == nullptr && !tmpTile->hasFlag(TILESTATE_BLOCKSOLID))) {
if (!tmpTile || (!tmpTile->getGround() && !tmpTile->hasFlag(TILESTATE_BLOCKSOLID))) {
tmpTile = map.getTile(destPos.x, destPos.y, destPos.getZ() - 1);
if (tmpTile && tmpTile->getGround() && !tmpTile->hasFlag(TILESTATE_BLOCKSOLID)) {
flags |= FLAG_IGNOREBLOCKITEM | FLAG_IGNOREBLOCKCREATURE;
Expand All @@ -820,7 +820,7 @@ ReturnValue Game::internalMoveCreature(Creature* creature, Direction direction,
//try to go down
if (currentPos.z != 7 && currentPos.z == destPos.z) {
Tile* tmpTile = map.getTile(destPos.x, destPos.y, destPos.z);
if (tmpTile == nullptr || (tmpTile->getGround() == nullptr && !tmpTile->hasFlag(TILESTATE_BLOCKSOLID))) {
if (!tmpTile || (!tmpTile->getGround() && !tmpTile->hasFlag(TILESTATE_BLOCKSOLID))) {
tmpTile = map.getTile(destPos.x, destPos.y, destPos.z + 1);
if (tmpTile && tmpTile->hasHeight(3)) {
flags |= FLAG_IGNOREBLOCKITEM | FLAG_IGNOREBLOCKCREATURE;
Expand Down Expand Up @@ -913,7 +913,7 @@ void Game::playerMoveItem(Player* player, const Position& fromPos,

player->setNextActionTask(nullptr);

if (item == nullptr) {
if (!item) {
uint8_t fromIndex = 0;
if (fromPos.x == 0xFFFF) {
if (fromPos.y & 0x40) {
Expand All @@ -940,14 +940,14 @@ void Game::playerMoveItem(Player* player, const Position& fromPos,
}

Cylinder* fromCylinder = internalGetCylinder(player, fromPos);
if (fromCylinder == nullptr) {
if (!fromCylinder) {
player->sendCancelMessage(RETURNVALUE_NOTPOSSIBLE);
return;
}

if (toCylinder == nullptr) {
if (!toCylinder) {
toCylinder = internalGetCylinder(player, toPos);
if (toCylinder == nullptr) {
if (!toCylinder) {
player->sendCancelMessage(RETURNVALUE_NOTPOSSIBLE);
return;
}
Expand Down Expand Up @@ -1281,7 +1281,7 @@ ReturnValue Game::internalAddItem(Cylinder* toCylinder, Item* item, int32_t inde
ReturnValue Game::internalAddItem(Cylinder* toCylinder, Item* item, int32_t index,
uint32_t flags, bool test, uint32_t& remainderCount)
{
if (toCylinder == nullptr || item == nullptr) {
if (!toCylinder || !item) {
return RETURNVALUE_NOTPOSSIBLE;
}

Expand Down Expand Up @@ -1364,7 +1364,7 @@ ReturnValue Game::internalAddItem(Cylinder* toCylinder, Item* item, int32_t inde
ReturnValue Game::internalRemoveItem(Item* item, int32_t count /*= -1*/, bool test /*= false*/, uint32_t flags /*= 0*/)
{
Cylinder* cylinder = item->getParent();
if (cylinder == nullptr) {
if (!cylinder) {
return RETURNVALUE_NOTPOSSIBLE;
}

Expand Down Expand Up @@ -1432,7 +1432,7 @@ ReturnValue Game::internalPlayerAddItem(Player* player, Item* item, bool dropOnM
Item* Game::findItemOfType(Cylinder* cylinder, uint16_t itemId,
bool depthSearch /*= true*/, int32_t subType /*= -1*/) const
{
if (cylinder == nullptr) {
if (!cylinder) {
return nullptr;
}

Expand Down Expand Up @@ -1479,7 +1479,7 @@ Item* Game::findItemOfType(Cylinder* cylinder, uint16_t itemId,

bool Game::removeMoney(Cylinder* cylinder, uint64_t money, uint32_t flags /*= 0*/)
{
if (cylinder == nullptr) {
if (!cylinder) {
return false;
}

Expand Down Expand Up @@ -1606,7 +1606,7 @@ Item* Game::transformItem(Item* item, uint16_t newId, int32_t newCount /*= -1*/)
}

Cylinder* cylinder = item->getParent();
if (cylinder == nullptr) {
if (!cylinder) {
return nullptr;
}

Expand Down Expand Up @@ -1646,7 +1646,7 @@ Item* Game::transformItem(Item* item, uint16_t newId, int32_t newCount /*= -1*/)
cylinder->addThing(item);

Cylinder* newParent = item->getParent();
if (newParent == nullptr) {
if (!newParent) {
ReleaseItem(item);
return nullptr;
}
Expand All @@ -1673,7 +1673,7 @@ Item* Game::transformItem(Item* item, uint16_t newId, int32_t newCount /*= -1*/)
} else if (newItemId != newId) {
//Replacing the the old item with the new while maintaining the old position
Item* newItem = Item::CreateItem(newItemId, 1);
if (newItem == nullptr) {
if (!newItem) {
return nullptr;
}

Expand Down Expand Up @@ -1718,7 +1718,7 @@ Item* Game::transformItem(Item* item, uint16_t newId, int32_t newCount /*= -1*/)
newItem = Item::CreateItem(newId, newCount);
}

if (newItem == nullptr) {
if (!newItem) {
return nullptr;
}

Expand Down
4 changes: 2 additions & 2 deletions src/house.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ bool House::canEditAccessList(uint32_t listId, const Player* player)

HouseTransferItem* House::getTransferItem()
{
if (transferItem != nullptr) {
if (transferItem) {
return nullptr;
}

Expand Down Expand Up @@ -537,7 +537,7 @@ Attr_ReadValue Door::readAttr(AttrTypes_t attr, PropStream& propStream)

void Door::setHouse(House* house)
{
if (this->house != nullptr) {
if (this->house) {
return;
}

Expand Down
4 changes: 2 additions & 2 deletions src/inbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ ReturnValue Inbox::queryAdd(int32_t, const Thing& thing, uint32_t,
void Inbox::postAddNotification(Thing* thing, const Cylinder* oldParent, int32_t index, cylinderlink_t)
{
Cylinder* parent = getParent();
if (parent != nullptr) {
if (parent) {
parent->postAddNotification(thing, oldParent, index, LINK_PARENT);
}
}

void Inbox::postRemoveNotification(Thing* thing, const Cylinder* newParent, int32_t index, cylinderlink_t)
{
Cylinder* parent = getParent();
if (parent != nullptr) {
if (parent) {
parent->postRemoveNotification(thing, newParent, index, LINK_PARENT);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/iologindata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,7 @@ void IOLoginData::increaseBankBalance(uint32_t guid, uint64_t bankBalance)
bool IOLoginData::hasBiddedOnHouse(uint32_t guid)
{
Database& db = Database::getInstance();
return db.storeQuery(fmt::format("SELECT `id` FROM `houses` WHERE `highest_bidder` = {:d} LIMIT 1", guid)).get() != nullptr;
return db.storeQuery(fmt::format("SELECT `id` FROM `houses` WHERE `highest_bidder` = {:d} LIMIT 1", guid)).get();
}

std::forward_list<VIPEntry> IOLoginData::getVIPEntries(uint32_t accountId)
Expand Down
Loading