summaryrefslogtreecommitdiff
path: root/src/net
diff options
context:
space:
mode:
authorJared Adams <jaxad0127@gmail.com>2010-04-12 21:52:27 -0600
committerJared Adams <jaxad0127@gmail.com>2010-04-16 17:43:52 -0600
commitcf4a1da4eaffe19090a2246e0d3111b885a64ace (patch)
tree6187c8c7a91796e485c71ea7c88c819bec902b66 /src/net
parent11a6f342e579c26320334b9ae9735701386e3b25 (diff)
downloadmana-cf4a1da4eaffe19090a2246e0d3111b885a64ace.tar.gz
mana-cf4a1da4eaffe19090a2246e0d3111b885a64ace.tar.bz2
mana-cf4a1da4eaffe19090a2246e0d3111b885a64ace.tar.xz
mana-cf4a1da4eaffe19090a2246e0d3111b885a64ace.zip
Fix canceling game connection
Reviewed-by: Bertram
Diffstat (limited to 'src/net')
-rw-r--r--src/net/ea/charserverhandler.cpp1
-rw-r--r--src/net/manaserv/charhandler.cpp20
-rw-r--r--src/net/manaserv/charhandler.h4
-rw-r--r--src/net/manaserv/gamehandler.cpp7
-rw-r--r--src/net/manaserv/generalhandler.cpp16
5 files changed, 38 insertions, 10 deletions
diff --git a/src/net/ea/charserverhandler.cpp b/src/net/ea/charserverhandler.cpp
index 8706727a..6f1506b5 100644
--- a/src/net/ea/charserverhandler.cpp
+++ b/src/net/ea/charserverhandler.cpp
@@ -277,6 +277,7 @@ void CharServerHandler::requestCharacters()
void CharServerHandler::chooseCharacter(Net::Character *character)
{
mSelectedCharacter = character;
+ mCharSelectDialog = 0;
MessageOut outMsg(CMSG_CHAR_SELECT);
outMsg.writeInt8(mSelectedCharacter->slot);
diff --git a/src/net/manaserv/charhandler.cpp b/src/net/manaserv/charhandler.cpp
index 4b574821..c070ab23 100644
--- a/src/net/manaserv/charhandler.cpp
+++ b/src/net/manaserv/charhandler.cpp
@@ -68,6 +68,11 @@ CharHandler::CharHandler()
charHandler = this;
}
+CharHandler::~CharHandler()
+{
+ clear();
+}
+
void CharHandler::handleMessage(Net::MessageIn &msg)
{
switch (msg.getId())
@@ -225,16 +230,10 @@ void CharHandler::handleCharacterSelectResponse(Net::MessageIn &msg)
logger->log("Chat server: %s:%d", chatServer.hostname.c_str(),
chatServer.port);
- gameServerConnection->connect(gameServer.hostname, gameServer.port);
- chatServerConnection->connect(chatServer.hostname, chatServer.port);
-
// Prevent the selected local player from being deleted
player_node = mSelectedCharacter->dummy;
mSelectedCharacter->dummy = 0;
- mCachedCharacterInfos.clear();
- updateCharacters();
-
Client::setState(STATE_CONNECT_GAME);
}
else if (errMsg == ERRMSG_FAILURE)
@@ -381,4 +380,13 @@ void CharHandler::updateCharacters()
updateCharSelectDialog();
}
+void CharHandler::clear()
+{
+ setCharCreateDialog(0);
+ setCharSelectDialog(0);
+
+ mCachedCharacterInfos.clear();
+ updateCharacters();
+}
+
} // namespace ManaServ
diff --git a/src/net/manaserv/charhandler.h b/src/net/manaserv/charhandler.h
index d2f50850..26a7bf4e 100644
--- a/src/net/manaserv/charhandler.h
+++ b/src/net/manaserv/charhandler.h
@@ -40,6 +40,8 @@ class CharHandler : public MessageHandler, public Net::CharHandler
public:
CharHandler();
+ ~CharHandler();
+
void handleMessage(Net::MessageIn &msg);
void setCharSelectDialog(CharSelectDialog *window);
@@ -69,6 +71,8 @@ class CharHandler : public MessageHandler, public Net::CharHandler
int maxSprite() const;
+ void clear();
+
private:
/**
* Character information needs to be cached since we receive it before
diff --git a/src/net/manaserv/gamehandler.cpp b/src/net/manaserv/gamehandler.cpp
index 4c6c8e38..271fff15 100644
--- a/src/net/manaserv/gamehandler.cpp
+++ b/src/net/manaserv/gamehandler.cpp
@@ -35,9 +35,11 @@ extern ManaServ::ChatHandler *chatHandler;
namespace ManaServ {
+extern Connection *chatServerConnection;
extern Connection *gameServerConnection;
extern std::string netToken;
extern ServerInfo gameServer;
+extern ServerInfo chatServer;
GameHandler::GameHandler()
{
@@ -60,7 +62,7 @@ void GameHandler::handleMessage(Net::MessageIn &msg)
if (errMsg == ERRMSG_OK)
{
netToken = msg.readString(32);
-\
+
if (!netToken.empty())
{
Client::setState(STATE_SWITCH_CHARACTER);
@@ -91,7 +93,8 @@ void GameHandler::handleMessage(Net::MessageIn &msg)
void GameHandler::connect()
{
- //
+ gameServerConnection->connect(gameServer.hostname, gameServer.port);
+ chatServerConnection->connect(chatServer.hostname, chatServer.port);
}
bool GameHandler::isConnected()
diff --git a/src/net/manaserv/generalhandler.cpp b/src/net/manaserv/generalhandler.cpp
index 0e030aa8..454052f7 100644
--- a/src/net/manaserv/generalhandler.cpp
+++ b/src/net/manaserv/generalhandler.cpp
@@ -122,8 +122,20 @@ void GeneralHandler::load()
void GeneralHandler::reload()
{
- static_cast<CharHandler*>(mCharHandler.get())->setCharCreateDialog(0);
- static_cast<CharHandler*>(mCharHandler.get())->setCharSelectDialog(0);
+ static_cast<CharHandler*>(Net::getCharHandler())->clear();
+
+ if (accountServerConnection)
+ accountServerConnection->disconnect();
+
+ if (gameServerConnection)
+ gameServerConnection->disconnect();
+
+ if (chatServerConnection)
+ chatServerConnection->disconnect();
+
+ netToken.clear();
+ gameServer.clear();
+ chatServer.clear();
}
void GeneralHandler::unload()