summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--src/accounthandler.cpp12
-rw-r--r--src/dalstorage.cpp11
-rw-r--r--src/dalstorage.h2
-rw-r--r--src/storage.h2
5 files changed, 18 insertions, 14 deletions
diff --git a/ChangeLog b/ChangeLog
index 72912d47..0b0b4dae 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,8 +1,11 @@
-2005-12-29 Bjørn Lindeijer <bjorn@lindeijer.nl>
+2005-12-29 Yohann Ferreira <bjorn@lindeijer.nl>
* src/main.cpp, src/connectionhandler.cpp, src/defines.h,
src/chathandler.cpp: Adding changes thought by Elven and an option for
setting the port to listen on at startup.
+ * src/accounthandler.cpp, src/dalstorage.cpp, src/dalstorage.h,
+ src/storage.h: Fixing a bug in the Storage::getAccount() function that
+ made the server crash when the first login had a bad password.
2005-12-29 Bjørn Lindeijer <bjorn@lindeijer.nl>
diff --git a/src/accounthandler.cpp b/src/accounthandler.cpp
index ca65cd1e..fff2223f 100644
--- a/src/accounthandler.cpp
+++ b/src/accounthandler.cpp
@@ -73,7 +73,7 @@ void AccountHandler::receiveMessage(NetComputer &computer, MessageIn &message)
}
// see if the account exists
- tmwserv::AccountPtr acc = tmwserv::AccountPtr(store.getAccount(username));
+ tmwserv::AccountPtr acc = store.getAccount(username);
if (!acc.get()) {
// account doesn't exist -- send error to client
@@ -190,8 +190,8 @@ void AccountHandler::receiveMessage(NetComputer &computer, MessageIn &message)
}
// see if the account exists
- Account *accPtr = store.getAccount(username);
- if ( accPtr ) // Account already exists.
+ tmwserv::AccountPtr accPtr = store.getAccount(username);
+ if ( accPtr.get() ) // Account already exists.
{
result.writeShort(SMSG_REGISTER_RESPONSE);
result.writeByte(REGISTER_EXISTS_USERNAME);
@@ -236,15 +236,15 @@ void AccountHandler::receiveMessage(NetComputer &computer, MessageIn &message)
LOG_INFO(username << " wants to be deleted from our accounts.", 1)
// see if the account exists
- Account *acc = store.getAccount(username);
+ tmwserv::AccountPtr accPtr = store.getAccount(username);
- if (!acc) {
+ if (!accPtr.get()) {
// account doesn't exist -- send error to client
LOG_INFO(username << ": Account doesn't exist anyway.", 1)
result.writeShort(SMSG_UNREGISTER_RESPONSE);
result.writeByte(UNREGISTER_INVALID_USERNAME);
- } else if (acc->getPassword() != password) {
+ } else if (accPtr->getPassword() != password) {
// bad password -- send error to client
LOG_INFO("Won't delete it : Bad password for " << username << ".", 1)
diff --git a/src/dalstorage.cpp b/src/dalstorage.cpp
index 5723a040..c0359754 100644
--- a/src/dalstorage.cpp
+++ b/src/dalstorage.cpp
@@ -158,7 +158,7 @@ DALStorage::close(void)
/**
* Get an account by user name.
*/
-Account*
+AccountPtr
DALStorage::getAccount(const std::string& userName)
{
// connect to the database (if not connected yet).
@@ -173,7 +173,7 @@ DALStorage::getAccount(const std::string& userName)
);
if (it != mAccounts.end()) {
- return (it->first).get();
+ return it->first;
}
using namespace dal;
@@ -190,7 +190,7 @@ DALStorage::getAccount(const std::string& userName)
// if the account is not even in the database then
// we have no choice but to return nothing.
if (accountInfo.isEmpty()) {
- return NULL;
+ return AccountPtr(NULL);
}
// create an Account instance
@@ -288,10 +288,10 @@ DALStorage::getAccount(const std::string& userName)
account->setCharacters(beings);
} // End if there are characters.
- return account.get();
+ return account;
}
catch (const DbSqlQueryExecFailure& e) {
- return NULL; // TODO: Throw exception here
+ return AccountPtr(NULL); // TODO: Throw exception here
}
}
@@ -303,6 +303,7 @@ void
DALStorage::addAccount(const AccountPtr& account)
{
if (account.get() == 0) {
+ LOG_WARN("Cannot add a NULL Account.", 0)
// maybe we should throw an exception instead
return;
}
diff --git a/src/dalstorage.h b/src/dalstorage.h
index af109dc2..d3785568 100644
--- a/src/dalstorage.h
+++ b/src/dalstorage.h
@@ -71,7 +71,7 @@ class DALStorage: public Storage
*
* @return the account associated to the user name.
*/
- Account*
+ AccountPtr
getAccount(const std::string& userName);
diff --git a/src/storage.h b/src/storage.h
index 6381fea7..534eca0a 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -259,7 +259,7 @@ class Storage
*
* @return the account associated to the user name.
*/
- virtual Account*
+ virtual AccountPtr
getAccount(const std::string& userName) = 0;