diff options
Diffstat (limited to 'src/account-server')
-rw-r--r-- | src/account-server/account.cpp | 8 | ||||
-rw-r--r-- | src/account-server/account.h | 2 | ||||
-rw-r--r-- | src/account-server/accounthandler.cpp | 12 | ||||
-rw-r--r-- | src/account-server/character.cpp | 2 | ||||
-rw-r--r-- | src/account-server/character.h | 4 | ||||
-rw-r--r-- | src/account-server/main-account.cpp | 10 | ||||
-rw-r--r-- | src/account-server/serverhandler.cpp | 26 | ||||
-rw-r--r-- | src/account-server/storage.cpp | 59 |
8 files changed, 61 insertions, 62 deletions
diff --git a/src/account-server/account.cpp b/src/account-server/account.cpp index 10869294..6fd86842 100644 --- a/src/account-server/account.cpp +++ b/src/account-server/account.cpp @@ -24,7 +24,7 @@ Account::~Account() { - for (Characters::iterator i = mCharacters.begin(), + for (auto i = mCharacters.begin(), i_end = mCharacters.end(); i != i_end; ++i) { delete (*i).second; @@ -43,7 +43,7 @@ void Account::setCharacters(const Characters &characters) void Account::addCharacter(CharacterData *character) { - unsigned slot = (unsigned) character->getCharacterSlot(); + auto slot = (unsigned) character->getCharacterSlot(); assert(isSlotEmpty(slot)); mCharacters[slot] = character; @@ -51,8 +51,8 @@ void Account::addCharacter(CharacterData *character) void Account::delCharacter(unsigned slot) { - for (Characters::iterator iter = mCharacters.begin(), - iter_end = mCharacters.end(); iter != iter_end; ++iter) + for (auto iter = mCharacters.begin(), + iter_end = mCharacters.end(); iter != iter_end; ++iter) { if ((*iter).second->getCharacterSlot() == slot) { diff --git a/src/account-server/account.h b/src/account-server/account.h index 05c73c96..175d4bcd 100644 --- a/src/account-server/account.h +++ b/src/account-server/account.h @@ -235,6 +235,6 @@ class Account time_t mLastLogin; /**< Date and time of the last login */ }; -typedef std::vector< Account * > Accounts; +using Accounts = std::vector<Account *>; #endif // ACCOUNT_H diff --git a/src/account-server/accounthandler.cpp b/src/account-server/accounthandler.cpp index 856f07d0..2275e015 100644 --- a/src/account-server/accounthandler.cpp +++ b/src/account-server/accounthandler.cpp @@ -77,11 +77,11 @@ protected: /** * Processes account related messages. */ - void processMessage(NetComputer *client, MessageIn &message); + void processMessage(NetComputer *client, MessageIn &message) override; - NetComputer *computerConnected(ENetPeer *peer); + NetComputer *computerConnected(ENetPeer *peer) override; - void computerDisconnected(NetComputer *comp); + void computerDisconnected(NetComputer *comp) override; private: void handleLoginRandTriggerMessage(AccountClient &client, MessageIn &msg); @@ -128,7 +128,7 @@ private: std::string mUpdateHost; std::string mDataUrl; - typedef std::map<int, time_t> IPsToTime; + using IPsToTime = std::map<int, time_t>; IPsToTime mLastLoginAttemptForIP; }; @@ -256,7 +256,7 @@ NetComputer *AccountHandler::computerConnected(ENetPeer *peer) void AccountHandler::computerDisconnected(NetComputer *comp) { - AccountClient *client = static_cast<AccountClient *>(comp); + auto client = static_cast<AccountClient *>(comp); if (client->status == CLIENT_QUEUED) // Delete it from the pendingClient list @@ -801,7 +801,7 @@ void AccountHandler::handleCharacterCreateMessage(AccountClient &client, } else { - CharacterData *newCharacter = new CharacterData(name); + auto newCharacter = new CharacterData(name); // Set the initial attributes provided by the client for (unsigned i = 0; i < mModifiableAttributes.size(); ++i) diff --git a/src/account-server/character.cpp b/src/account-server/character.cpp index 80b28b55..e22a84e9 100644 --- a/src/account-server/character.cpp +++ b/src/account-server/character.cpp @@ -106,7 +106,7 @@ void CharacterData::serialize(MessageOut &msg) const EquipData &equipData = poss.getEquipment(); const InventoryData &inventoryData = poss.getInventory(); - for (InventoryData::const_iterator itemIt = inventoryData.begin(), + for (auto itemIt = inventoryData.begin(), itemIt_end = inventoryData.end(); itemIt != itemIt_end; ++itemIt) { int slot = itemIt->first; diff --git a/src/account-server/character.h b/src/account-server/character.h index 3af6c7d0..d7e905cc 100644 --- a/src/account-server/character.h +++ b/src/account-server/character.h @@ -75,7 +75,7 @@ struct QuestInfo /** * Stores attributes by their id. */ -typedef std::map<unsigned, AttributeValue> AttributeMap; +using AttributeMap = std::map<unsigned int, AttributeValue>; class CharacterData { @@ -278,6 +278,6 @@ class CharacterData /** * Type definition for a list of Characters. */ -typedef std::map<unsigned, CharacterData* > Characters; +using Characters = std::map<unsigned int, CharacterData *>; #endif diff --git a/src/account-server/main-account.cpp b/src/account-server/main-account.cpp index e14b301f..9d3a800a 100644 --- a/src/account-server/main-account.cpp +++ b/src/account-server/main-account.cpp @@ -249,11 +249,11 @@ static void parseOptions(int argc, char *argv[], CommandLineOptions &options) const struct option longOptions[] = { - { "help", no_argument, 0, 'h' }, - { "config", required_argument, 0, 'c' }, - { "verbosity", required_argument, 0, 'v' }, - { "port", required_argument, 0, 'p' }, - { 0, 0, 0, 0 } + { "help", no_argument, nullptr, 'h' }, + { "config", required_argument, nullptr, 'c' }, + { "verbosity", required_argument, nullptr, 'v' }, + { "port", required_argument, nullptr, 'p' }, + { nullptr, 0, nullptr, 0 } }; while (optind < argc) diff --git a/src/account-server/serverhandler.cpp b/src/account-server/serverhandler.cpp index 273642b2..49aa2839 100644 --- a/src/account-server/serverhandler.cpp +++ b/src/account-server/serverhandler.cpp @@ -51,14 +51,14 @@ struct MapStatistics unsigned short nbMonsters; }; -typedef std::map<unsigned short, MapStatistics> ServerStatistics; +using ServerStatistics = std::map<unsigned short, MapStatistics>; /** * Stores address, maps, and statistics, of a connected game server. */ struct GameServer: NetComputer { - GameServer(ENetPeer *peer): NetComputer(peer), server(0), port(0) {} + GameServer(ENetPeer *peer): NetComputer(peer), server(nullptr), port(0) {} std::string name; std::string address; @@ -81,18 +81,18 @@ class ServerHandler: public ConnectionHandler /** * Processes server messages. */ - void processMessage(NetComputer *computer, MessageIn &message); + void processMessage(NetComputer *computer, MessageIn &message) override; /** * Called when a game server connects. Initializes a simple NetComputer * as these connections are stateless. */ - NetComputer *computerConnected(ENetPeer *peer); + NetComputer *computerConnected(ENetPeer *peer) override; /** * Called when a game server disconnects. */ - void computerDisconnected(NetComputer *comp); + void computerDisconnected(NetComputer *comp) override; }; static ServerHandler *serverHandler; @@ -133,7 +133,7 @@ static GameServer *getGameServerFromMap(int mapId) i = serverHandler->clients.begin(), i_end = serverHandler->clients.end(); i != i_end; ++i) { - GameServer *server = static_cast< GameServer * >(*i); + auto server = static_cast< GameServer * >(*i); ServerStatistics::const_iterator it = server->maps.find(mapId); if (it == server->maps.end()) continue; return server; @@ -175,7 +175,7 @@ void GameServerHandler::registerClient(const std::string &token, void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg) { - GameServer *server = static_cast<GameServer *>(comp); + auto server = static_cast<GameServer *>(comp); switch (msg.getId()) { @@ -234,7 +234,7 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg) << " asks for maps to activate."); const std::map<int, std::string> &maps = MapManager::getMaps(); - for (std::map<int, std::string>::const_iterator it = maps.begin(), + for (auto it = maps.begin(), it_end = maps.end(); it != it_end; ++it) { int id = it->first; @@ -267,7 +267,7 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg) outMsg.writeInt16(items.size()); //number of floor items // Send each map item: item_id, amount, pos_x, pos_y - for (std::list<FloorItem>::iterator i = items.begin(); + for (auto i = items.begin(); i != items.end(); ++i) { outMsg.writeInt32(i->getItemId()); @@ -431,7 +431,7 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg) while (msg.getUnreadLength()) { int mapId = msg.readInt16(); - ServerStatistics::iterator i = server->maps.find(mapId); + auto i = server->maps.find(mapId); if (i == server->maps.end()) { LOG_ERROR("Server " << server->address << ':' @@ -536,7 +536,7 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg) // save the letter LOG_DEBUG("Creating letter"); - Letter *letter = new Letter(0, sender, receiver); + auto letter = new Letter(0, sender, receiver); letter->addText(contents); for (unsigned i = 0; i < items.size(); ++i) { @@ -620,7 +620,7 @@ void GameServerHandler::dumpStatistics(std::ostream &os) i = serverHandler->clients.begin(), i_end = serverHandler->clients.end(); i != i_end; ++i) { - GameServer *server = static_cast< GameServer * >(*i); + auto server = static_cast< GameServer * >(*i); if (!server->port) continue; @@ -633,7 +633,7 @@ void GameServerHandler::dumpStatistics(std::ostream &os) const MapStatistics &m = j->second; os << "<map id=\"" << j->first << "\" nb_entities=\"" << m.nbEntities << "\" nb_monsters=\"" << m.nbMonsters << "\">\n"; - for (std::vector< int >::const_iterator k = m.players.begin(), + for (auto k = m.players.begin(), k_end = m.players.end(); k != k_end; ++k) { os << "<character id=\"" << *k << "\"/>\n"; 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); |