From cf4a1da4eaffe19090a2246e0d3111b885a64ace Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Mon, 12 Apr 2010 21:52:27 -0600 Subject: Fix canceling game connection Reviewed-by: Bertram --- src/client.cpp | 9 +++++---- src/gui/charselectdialog.cpp | 1 + src/gui/widgets/playerbox.cpp | 2 ++ src/net/ea/charserverhandler.cpp | 1 + src/net/manaserv/charhandler.cpp | 20 ++++++++++++++------ src/net/manaserv/charhandler.h | 4 ++++ src/net/manaserv/gamehandler.cpp | 7 +++++-- src/net/manaserv/generalhandler.cpp | 16 ++++++++++++++-- 8 files changed, 46 insertions(+), 14 deletions(-) diff --git a/src/client.cpp b/src/client.cpp index 0a66645e..49266a4e 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -523,14 +523,14 @@ int Client::exec() if (mLimitFps) SDL_framerateDelay(&mFpsManager); - // TODO: Add connect timeouts if (mState == STATE_CONNECT_GAME && Net::getGameHandler()->isConnected()) { Net::getLoginHandler()->disconnect(); } - else if (mState == STATE_CONNECT_SERVER && mOldState == STATE_CHOOSE_SERVER) + else if (mState == STATE_CONNECT_SERVER && + mOldState == STATE_CHOOSE_SERVER) { Net::connectToServer(mCurrentServer); } @@ -775,7 +775,8 @@ int Client::exec() Net::getGameHandler()->connect(); mCurrentDialog = new ConnectionDialog( _("Connecting to the game server"), - STATE_GET_CHARACTERS); + Net::getNetworkType() == ServerInfo::EATHENA ? + STATE_CHOOSE_SERVER : STATE_SWITCH_CHARACTER); break; case STATE_CHANGE_MAP: @@ -927,7 +928,7 @@ int Client::exec() // Done with game Net::getGameHandler()->disconnect(); - Net::getCharHandler()->requestCharacters(); + mState = STATE_GET_CHARACTERS; break; case STATE_LOGOUT_ATTEMPT: diff --git a/src/gui/charselectdialog.cpp b/src/gui/charselectdialog.cpp index c2c63248..e22c4daf 100644 --- a/src/gui/charselectdialog.cpp +++ b/src/gui/charselectdialog.cpp @@ -253,6 +253,7 @@ void CharSelectDialog::attemptCharacterSelect(int index) if (mLocked) return; + setVisible(false); mCharHandler->chooseCharacter(mCharacterEntries[index]->getCharacter()); lock(); } diff --git a/src/gui/widgets/playerbox.cpp b/src/gui/widgets/playerbox.cpp index d2c16dbc..57cbec6f 100644 --- a/src/gui/widgets/playerbox.cpp +++ b/src/gui/widgets/playerbox.cpp @@ -72,6 +72,8 @@ PlayerBox::~PlayerBox() { instances--; + mPlayer = 0; + if (instances == 0) { for_each(background.grid, background.grid + 9, dtor()); 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(mCharHandler.get())->setCharCreateDialog(0); - static_cast(mCharHandler.get())->setCharSelectDialog(0); + static_cast(Net::getCharHandler())->clear(); + + if (accountServerConnection) + accountServerConnection->disconnect(); + + if (gameServerConnection) + gameServerConnection->disconnect(); + + if (chatServerConnection) + chatServerConnection->disconnect(); + + netToken.clear(); + gameServer.clear(); + chatServer.clear(); } void GeneralHandler::unload() -- cgit v1.2.3-70-g09d2