summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYohann Ferreira <bertram@cegetel.net>2005-12-18 00:58:24 +0000
committerYohann Ferreira <bertram@cegetel.net>2005-12-18 00:58:24 +0000
commitf83ed8b03c85fb485e0a85439f36c555ca1910ee (patch)
tree59dcfd81e73603582a698a294e6fee925d629b5b
parent5b13f9cb7d2c86e8c6b95f953c3afdb808016375 (diff)
downloadmanaserv-f83ed8b03c85fb485e0a85439f36c555ca1910ee.tar.gz
manaserv-f83ed8b03c85fb485e0a85439f36c555ca1910ee.tar.bz2
manaserv-f83ed8b03c85fb485e0a85439f36c555ca1910ee.tar.xz
manaserv-f83ed8b03c85fb485e0a85439f36c555ca1910ee.zip
Made use of AccountPtr instead of Account*.
-rw-r--r--ChangeLog3
-rw-r--r--src/accounthandler.cpp18
-rw-r--r--src/netcomputer.cpp25
-rw-r--r--src/netcomputer.h10
4 files changed, 29 insertions, 27 deletions
diff --git a/ChangeLog b/ChangeLog
index 18f6d44d..66ea1a1b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -5,7 +5,8 @@
src/gamehandler.cpp, src/connectionhandler.h, src/state.h,
src/state.cpp: Made the handlers use the countedPtr for Beings
as they should. Fixed a segfault when removing a being from the
- world.
+ world. Also made use of AccountPtr instead of Account* to fix a
+ not seen but yet present account reselection segfault bug.
2005-12-17 Bjorn Steinbrink <B.Steinbrink@gmx.de>
diff --git a/src/accounthandler.cpp b/src/accounthandler.cpp
index aaac1118..27865577 100644
--- a/src/accounthandler.cpp
+++ b/src/accounthandler.cpp
@@ -63,7 +63,7 @@ void AccountHandler::receiveMessage(NetComputer &computer, MessageIn &message)
std::string password = message.readString();
std::cout << username << " is trying to login." << std::endl;
- if (computer.getAccount() != NULL) {
+ if (computer.getAccount().get() != NULL) {
std::cout << "Already logged in as " << computer.getAccount()->getName()
<< "." << std::endl;
std::cout << "Please logout first." << std::endl;
@@ -73,9 +73,9 @@ void AccountHandler::receiveMessage(NetComputer &computer, MessageIn &message)
}
// see if the account exists
- Account *acc = store.getAccount(username);
+ tmwserv::AccountPtr acc = tmwserv::AccountPtr(store.getAccount(username));
- if (!acc) {
+ if (!acc.get()) {
// account doesn't exist -- send error to client
std::cout << username << ": Account does not exist." << std::endl;
@@ -114,7 +114,7 @@ void AccountHandler::receiveMessage(NetComputer &computer, MessageIn &message)
case CMSG_LOGOUT:
{
- if ( computer.getAccount() == NULL )
+ if ( computer.getAccount().get() == NULL )
{
std::cout << "Can't logout. Not even logged in." << std::endl;
result.writeShort(SMSG_LOGOUT_ERROR);
@@ -245,7 +245,7 @@ void AccountHandler::receiveMessage(NetComputer &computer, MessageIn &message)
// If the account to delete is the current account we're logged in.
// Get out of it in memory.
- if (computer.getAccount() != NULL )
+ if (computer.getAccount().get() != NULL )
{
if (computer.getAccount()->getName() == username )
{
@@ -265,7 +265,7 @@ void AccountHandler::receiveMessage(NetComputer &computer, MessageIn &message)
case CMSG_CHAR_CREATE:
{
- if (computer.getAccount() == NULL) {
+ if (computer.getAccount().get() == NULL) {
result.writeShort(SMSG_CHAR_CREATE_RESPONSE);
result.writeByte(CREATE_NOLOGIN);
std::cout << "Not logged in. Can't create a Character." << std::endl;
@@ -319,7 +319,7 @@ void AccountHandler::receiveMessage(NetComputer &computer, MessageIn &message)
case CMSG_CHAR_SELECT:
{
- if (computer.getAccount() == NULL)
+ if (computer.getAccount().get() == NULL)
{
result.writeShort(SMSG_CHAR_SELECT_RESPONSE);
result.writeByte(SELECT_NOLOGIN);
@@ -357,7 +357,7 @@ void AccountHandler::receiveMessage(NetComputer &computer, MessageIn &message)
case CMSG_CHAR_DELETE:
{
- if (computer.getAccount() == NULL)
+ if (computer.getAccount().get() == NULL)
{
result.writeShort(SMSG_CHAR_DELETE_RESPONSE);
result.writeByte(DELETE_NOLOGIN);
@@ -405,7 +405,7 @@ void AccountHandler::receiveMessage(NetComputer &computer, MessageIn &message)
case CMSG_CHAR_LIST:
{
- if (computer.getAccount() == NULL)
+ if (computer.getAccount().get() == NULL)
{
result.writeShort(SMSG_CHAR_LIST_RESPONSE);
result.writeByte(CHAR_LIST_NOLOGIN);
diff --git a/src/netcomputer.cpp b/src/netcomputer.cpp
index c00061fc..2bf04db8 100644
--- a/src/netcomputer.cpp
+++ b/src/netcomputer.cpp
@@ -29,13 +29,14 @@
NetComputer::NetComputer(ConnectionHandler *handler, TCPsocket sock):
handler(handler),
socket(sock),
- account(NULL),
- character(NULL)
+ accountPtr(NULL),
+ characterPtr(NULL)
{
}
NetComputer::~NetComputer()
{
+ unsetAccount();
}
void NetComputer::disconnect(const std::string &reason)
@@ -49,34 +50,34 @@ void NetComputer::send(const Packet *p)
SDLNet_TCP_Send(socket, p->data, p->length);
}
-void NetComputer::setAccount(tmwserv::Account *acc)
+void NetComputer::setAccount(tmwserv::AccountPtr acc)
{
- account = acc;
+ accountPtr = acc;
}
void NetComputer::setCharacter(tmwserv::BeingPtr ch)
{
tmwserv::State &state = tmwserv::State::instance();
- if (character.get() != NULL)
+ if (characterPtr.get() != NULL)
{
- // Remove being from the world : This is buggy for now.
- state.removeBeing(character);
+ // Remove being from the world.
+ state.removeBeing(characterPtr);
}
- character = ch;
- state.addBeing(character, character->getMap());
+ characterPtr = ch;
+ state.addBeing(characterPtr, characterPtr->getMap());
}
void NetComputer::unsetAccount()
{
unsetCharacter();
- account = NULL;
+ accountPtr = tmwserv::AccountPtr(NULL);
}
void NetComputer::unsetCharacter()
{
// remove being from world
tmwserv::State &state = tmwserv::State::instance();
- state.removeBeing(character);
- character = tmwserv::BeingPtr(NULL);
+ state.removeBeing(characterPtr);
+ characterPtr = tmwserv::BeingPtr(NULL);
}
diff --git a/src/netcomputer.h b/src/netcomputer.h
index d1ac11f2..2d4b5cf5 100644
--- a/src/netcomputer.h
+++ b/src/netcomputer.h
@@ -81,7 +81,7 @@ class NetComputer
/**
* Set the account associated with the connection
*/
- void setAccount(tmwserv::Account *acc);
+ void setAccount(tmwserv::AccountPtr acc);
/**
* Unset the account associated with the connection
@@ -91,7 +91,7 @@ class NetComputer
/**
* Get account associated with the connection
*/
- tmwserv::Account *getAccount() { return account; }
+ tmwserv::AccountPtr getAccount() { return accountPtr; }
/**
* Set the selected character associated with connection
@@ -107,7 +107,7 @@ class NetComputer
/**
* Get character associated with the connection
*/
- tmwserv::BeingPtr getCharacter() { return character; }
+ tmwserv::BeingPtr getCharacter() { return characterPtr; }
private:
ConnectionHandler *handler;
@@ -115,8 +115,8 @@ class NetComputer
std::queue<Packet*> queue; /**< Message Queue (FIFO) */
TCPsocket socket; /**< Client socket */
- tmwserv::Account *account; /**< Account associated with connection */
- tmwserv::BeingPtr character; /**< Selected character */
+ tmwserv::AccountPtr accountPtr; /**< Account associated with connection */
+ tmwserv::BeingPtr characterPtr; /**< Selected character */
};
#endif