diff options
author | Guillaume Melquiond <guillaume.melquiond@gmail.com> | 2007-08-31 10:02:36 +0000 |
---|---|---|
committer | Guillaume Melquiond <guillaume.melquiond@gmail.com> | 2007-08-31 10:02:36 +0000 |
commit | 60f60de8aefeebd1de0bf6c940558902226d7747 (patch) | |
tree | ed3a5b3f9f721d559d29f872073bc293a66a99d0 | |
parent | e681c0024c1db3f93c501a0a9600371440986674 (diff) | |
download | manaserv-60f60de8aefeebd1de0bf6c940558902226d7747.tar.gz manaserv-60f60de8aefeebd1de0bf6c940558902226d7747.tar.bz2 manaserv-60f60de8aefeebd1de0bf6c940558902226d7747.tar.xz manaserv-60f60de8aefeebd1de0bf6c940558902226d7747.zip |
Plugged several account leaks on error. Prevented banned players from logging in.
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | src/account-server/accounthandler.cpp | 15 | ||||
-rw-r--r-- | src/account-server/dalstorage.cpp | 20 | ||||
-rw-r--r-- | src/account-server/dalstorage.hpp | 10 | ||||
-rw-r--r-- | src/defines.h | 3 |
5 files changed, 48 insertions, 6 deletions
@@ -12,6 +12,12 @@ src/account-server/accounthandler.cpp, src/account-server/accountclient.cpp: Removed selected character from client data. Cleaned account handler. + * src/account-server/dalstorage.cpp, src/account-server/dalstorage.hpp: + Added helper for querying existence of usernames. + * src/account-server/accounthandler.cpp: Plugged several account leaks + on error. + * src/defines.h, src/account-server/accounthandler.cpp: Prevented + banned users from logging in. 2007-08-30 Guillaume Melquiond <guillaume.melquiond@gmail.com> diff --git a/src/account-server/accounthandler.cpp b/src/account-server/accounthandler.cpp index 8c69b066..e7fc2ceb 100644 --- a/src/account-server/accounthandler.cpp +++ b/src/account-server/accounthandler.cpp @@ -180,7 +180,7 @@ AccountHandler::handleLoginMessage(AccountClient &computer, MessageIn &msg) return; } - unsigned long clientVersion = msg.readLong(); + int clientVersion = msg.readLong(); if (clientVersion < config.getValue("clientVersion", 0)) { @@ -213,6 +213,15 @@ AccountHandler::handleLoginMessage(AccountClient &computer, MessageIn &msg) { reply.writeByte(ERRMSG_INVALID_ARGUMENT); computer.send(reply); + delete acc; + return; + } + + if (acc->getLevel() == AL_BANNED) + { + reply.writeByte(LOGIN_BANNED); + computer.send(reply); + delete acc; return; } @@ -231,7 +240,6 @@ AccountHandler::handleLoginMessage(AccountClient &computer, MessageIn &msg) { sendCharacterData(computer, i, *chars[i]); } - return; } void @@ -320,7 +328,7 @@ AccountHandler::handleRegisterMessage(AccountClient &computer, MessageIn &msg) reply.writeByte(ERRMSG_INVALID_ARGUMENT); } // Check whether the account already exists. - else if (storage->getAccount(username)) + else if (storage->doesUserNameExist(username)) { reply.writeByte(REGISTER_EXISTS_USERNAME); } @@ -379,6 +387,7 @@ AccountHandler::handleUnregisterMessage(AccountClient &computer, { reply.writeByte(ERRMSG_INVALID_ARGUMENT); computer.send(reply); + delete acc; return; } diff --git a/src/account-server/dalstorage.cpp b/src/account-server/dalstorage.cpp index 31606e8f..70b1cdfb 100644 --- a/src/account-server/dalstorage.cpp +++ b/src/account-server/dalstorage.cpp @@ -429,6 +429,26 @@ DALStorage::getEmailList() } #endif +bool DALStorage::doesUserNameExist(std::string const &name) +{ + try { + std::ostringstream sql; + sql << "select count(username) from " << ACCOUNTS_TBL_NAME + << " where username = \"" << name << "\";"; + dal::RecordSet const &accountInfo = mDb->execSql(sql.str()); + + std::istringstream ssStream(accountInfo(0, 0)); + unsigned int iReturn = 1; + ssStream >> iReturn; + return iReturn != 0; + } catch (std::exception const &e) { + // TODO: throw an exception. + LOG_ERROR("(DALStorage::doesUserNameExist) SQL query failure: " << e.what()); + } + + return true; +} + /** * Tells if the email address already exists * @return true if the email address exists. diff --git a/src/account-server/dalstorage.hpp b/src/account-server/dalstorage.hpp index aa9ad7f0..abc9d314 100644 --- a/src/account-server/dalstorage.hpp +++ b/src/account-server/dalstorage.hpp @@ -129,14 +129,20 @@ class DALStorage #endif /** + * Tells if the user name already exists. + * @return true if the user name exists. + */ + bool doesUserNameExist(std::string const &name); + + /** * Tells if the email address already exists. * @return true if the email address exists. */ bool doesEmailAddressExist(std::string const &email); /** - * Tells if the character's name already exists - * @return true if character's name exists. + * Tells if the character name already exists. + * @return true if the character name exists. */ bool doesCharacterNameExist(std::string const &name); diff --git a/src/defines.h b/src/defines.h index fff197c5..cf1db301 100644 --- a/src/defines.h +++ b/src/defines.h @@ -270,7 +270,8 @@ enum { // Login specific return values enum { LOGIN_INVALID_VERSION = 0x40, // the user is using an incompatible protocol - LOGIN_SERVER_FULL // the server is overloaded + LOGIN_SERVER_FULL, // the server is overloaded + LOGIN_BANNED // the user is currently banned }; // Account register specific return values |