diff options
author | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2022-08-19 16:55:29 +0200 |
---|---|---|
committer | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2022-08-19 17:34:55 +0200 |
commit | 109b602701578b9f2b29282f84bf2757544f8d32 (patch) | |
tree | a2fd70556c86385a75bfb7651e865beb0a05fd37 /src/account-server/storage.cpp | |
parent | 6c6090991e17276de09f5f82d2fc8a6c1adf5bf4 (diff) | |
download | manaserv-109b602701578b9f2b29282f84bf2757544f8d32.tar.gz manaserv-109b602701578b9f2b29282f84bf2757544f8d32.tar.bz2 manaserv-109b602701578b9f2b29282f84bf2757544f8d32.tar.xz manaserv-109b602701578b9f2b29282f84bf2757544f8d32.zip |
Apply C++11 fixits
modernize-use-auto
modernize-use-nullptr
modernize-use-override
modernize-use-using
Diffstat (limited to 'src/account-server/storage.cpp')
-rw-r--r-- | src/account-server/storage.cpp | 59 |
1 files changed, 29 insertions, 30 deletions
diff --git a/src/account-server/storage.cpp b/src/account-server/storage.cpp index 308f96fa..d243b1e7 100644 --- a/src/account-server/storage.cpp +++ b/src/account-server/storage.cpp @@ -171,7 +171,7 @@ std::unique_ptr<Account> Storage::getAccountBySQL() // If the account is not even in the database then // we have no choice but to return nothing. if (accountInfo.isEmpty()) - return 0; + return nullptr; string_to< unsigned > toUint; unsigned id = toUint(accountInfo(0, 0)); @@ -188,7 +188,7 @@ std::unique_ptr<Account> Storage::getAccountBySQL() int level = toUint(accountInfo(0, 4)); // Check if the user is permanently banned, or temporarily banned. if (level == AL_BANNED - || time(0) <= (int) toUint(accountInfo(0, 5))) + || time(nullptr) <= (int) toUint(accountInfo(0, 5))) { account->setLevel(AL_BANNED); // It is, so skip character loading. @@ -245,7 +245,7 @@ std::unique_ptr<Account> Storage::getAccountBySQL() e); } - return 0; + return nullptr; } void Storage::fixCharactersSlot(int accountId) @@ -292,8 +292,7 @@ void Storage::fixCharactersSlot(int accountId) dal::PerformTransaction transaction(mDb); // Update the slots in database. - for (std::map<unsigned, unsigned>::iterator i = - slotsToUpdate.begin(), + for (auto i = slotsToUpdate.begin(), i_end = slotsToUpdate.end(); i != i_end; ++i) { // Update the character slot. @@ -324,7 +323,7 @@ std::unique_ptr<Account> Storage::getAccount(const std::string &userName) mDb->bindValue(1, userName); return getAccountBySQL(); } - return 0; + return nullptr; } std::unique_ptr<Account> Storage::getAccount(int accountID) @@ -336,12 +335,12 @@ std::unique_ptr<Account> Storage::getAccount(int accountID) mDb->bindValue(1, accountID); return getAccountBySQL(); } - return 0; + return nullptr; } CharacterData *Storage::getCharacterBySQL(Account *owner) { - CharacterData *character = 0; + CharacterData *character = nullptr; string_to< unsigned > toUint; string_to< int > toInt; @@ -353,7 +352,7 @@ CharacterData *Storage::getCharacterBySQL(Account *owner) // If the character is not even in the database then // we have no choice but to return nothing. if (charInfo.isEmpty()) - return 0; + return nullptr; string_to< unsigned short > toUshort; string_to< double > toDouble; @@ -538,7 +537,7 @@ CharacterData *Storage::getCharacter(int id, Account *owner) mDb->bindValue(1, id); return getCharacterBySQL(owner); } - return 0; + return nullptr; } CharacterData *Storage::getCharacter(const std::string &name) @@ -548,9 +547,9 @@ CharacterData *Storage::getCharacter(const std::string &name) if (mDb->prepareSql(sql.str())) { mDb->bindValue(1, name); - return getCharacterBySQL(0); + return getCharacterBySQL(nullptr); } - return 0; + return nullptr; } unsigned Storage::getCharacterId(const std::string &name) @@ -835,7 +834,7 @@ bool Storage::updateCharacter(CharacterData *character) const Possessions &poss = character->getPossessions(); const InventoryData &inventoryData = poss.getInventory(); - for (InventoryData::const_iterator itemIt = inventoryData.begin(), + for (auto itemIt = inventoryData.begin(), j_end = inventoryData.end(); itemIt != j_end; ++itemIt) { sql.str(""); @@ -969,7 +968,7 @@ void Storage::flush(const Account &account) const Characters &characters = account.getCharacters(); // Insert or update the characters. - for (Characters::const_iterator it = characters.begin(), + for (auto it = characters.begin(), it_end = characters.end(); it != it_end; ++it) { CharacterData *character = (*it).second; @@ -1040,7 +1039,7 @@ void Storage::flush(const Account &account) for (unsigned i = 0; i < charInMemInfo.rows(); ++i) // In database { charFound = false; - for (Characters::const_iterator it = characters.begin(), + for (auto it = characters.begin(), it_end = characters.end(); it != it_end; ++it) // In memory { if (charInMemInfo(i, 0) == (*it).second->getName()) @@ -1426,14 +1425,14 @@ std::map<int, Guild*> Storage::getGuildList() // Loop through every row in the table and assign it to a guild for (unsigned i = 0; i < guildInfo.rows(); ++i) { - Guild* guild = new Guild(guildInfo(i,1)); + auto guild = new Guild(guildInfo(i,1)); guild->setId(toShort(guildInfo(i,0))); guilds[guild->getId()] = guild; } string_to< unsigned > toUint; // Add the members to the guilds. - for (std::map<int, Guild*>::iterator it = guilds.begin(); + for (auto it = guilds.begin(); it != guilds.end(); ++it) { std::ostringstream memberSql; @@ -1452,7 +1451,7 @@ std::map<int, Guild*> Storage::getGuildList() std::list<std::pair<int, int> >::const_iterator i, i_end; for (i = members.begin(), i_end = members.end(); i != i_end; ++i) { - CharacterData *character = getCharacter((*i).first, 0); + CharacterData *character = getCharacter((*i).first, nullptr); if (character) { character->addGuild(it->second->getName()); @@ -1611,7 +1610,7 @@ void Storage::setWorldStateVar(const std::string &name, std::ostringstream updateStateVar; updateStateVar << "UPDATE " << WORLD_STATES_TBL_NAME << " SET value = '" << value << "', " - << " moddate = '" << time(0) << "' " + << " moddate = '" << time(nullptr) << "' " << " WHERE state_name = '" << name << "'" << " AND map_id = '" << mapId << "';"; mDb->execSql(updateStateVar.str()); @@ -1627,7 +1626,7 @@ void Storage::setWorldStateVar(const std::string &name, << "'" << name << "', " << "'" << mapId << "', " << "'" << value << "', " - << "'" << time(0) << "');"; + << "'" << time(nullptr) << "');"; mDb->execSql(insertStateVar.str()); } catch (const dal::DbSqlQueryExecFailure &e) @@ -1678,7 +1677,7 @@ void Storage::banCharacter(int id, int duration) return; } - uint64_t bantime = (uint64_t)time(0) + (uint64_t)duration * 60u; + uint64_t bantime = (uint64_t)time(nullptr) + (uint64_t)duration * 60u; // ban the character std::ostringstream sql; sql << "update " << ACCOUNTS_TBL_NAME @@ -1762,7 +1761,7 @@ void Storage::checkBannedAccounts() sql << "update " << ACCOUNTS_TBL_NAME << " set level = " << AL_PLAYER << ", banned = 0" << " where level = " << AL_BANNED - << " AND banned <= " << time(0) << ";"; + << " AND banned <= " << time(nullptr) << ";"; mDb->execSql(sql.str()); } catch (const dal::DbSqlQueryExecFailure &e) @@ -1802,7 +1801,7 @@ void Storage::storeLetter(Letter *letter) << letter->getSender()->getDatabaseID() << ", " << letter->getReceiver()->getDatabaseID() << ", " << letter->getExpiry() << ", " - << time(0) << ", " + << time(nullptr) << ", " << "?)"; if (mDb->prepareSql(sql.str())) { @@ -1831,7 +1830,7 @@ void Storage::storeLetter(Letter *letter) << letter->getReceiver()->getDatabaseID() << "', " << " letter_type = '" << letter->getType() << "', " << " expiration_date = '" << letter->getExpiry() << "', " - << " sending_date = '" << time(0) << "', " + << " sending_date = '" << time(nullptr) << "', " << " letter_text = ? " << " WHERE letter_id = '" << letter->getId() << "'"; @@ -1865,7 +1864,7 @@ void Storage::storeLetter(Letter *letter) Post *Storage::getStoredPost(int playerId) { - Post *p = new Post(); + auto p = new Post(); string_to< unsigned > toUint; @@ -1886,10 +1885,10 @@ Post *Storage::getStoredPost(int playerId) for (unsigned i = 0; i < post.rows(); i++ ) { // Load sender and receiver - CharacterData *sender = getCharacter(toUint(post(i, 1)), 0); - CharacterData *receiver = getCharacter(toUint(post(i, 2)), 0); + CharacterData *sender = getCharacter(toUint(post(i, 1)), nullptr); + CharacterData *receiver = getCharacter(toUint(post(i, 2)), nullptr); - Letter *letter = new Letter(toUint( post(0,3) ), sender, receiver); + auto letter = new Letter(toUint( post(0,3) ), sender, receiver); letter->setId( toUint(post(0, 0)) ); letter->setExpiry( toUint(post(0, 4)) ); @@ -2068,7 +2067,7 @@ void Storage::setOnlineStatus(int charId, bool online) sql.clear(); sql.str(""); sql << "INSERT INTO " << ONLINE_USERS_TBL_NAME - << " VALUES (" << charId << ", " << time(0) << ")"; + << " VALUES (" << charId << ", " << time(nullptr) << ")"; mDb->execSql(sql.str()); } else @@ -2096,7 +2095,7 @@ void Storage::addTransaction(const Transaction &trans) << " VALUES (NULL, " << trans.mCharacterId << ", " << trans.mAction << ", " << "?, " - << time(0) << ")"; + << time(nullptr) << ")"; if (mDb->prepareSql(sql.str())) { mDb->bindValue(1, trans.mMessage); |