From 8150191686759b13a239c25970924c3c186140ff Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 27 Mar 2013 19:05:24 +0300 Subject: improve charserverhandler class. --- src/net/ea/charserverhandler.cpp | 73 ++++++++++++++++++++++++++++++++++++---- src/net/ea/charserverhandler.h | 41 +++++++++++++--------- 2 files changed, 93 insertions(+), 21 deletions(-) (limited to 'src/net/ea') diff --git a/src/net/ea/charserverhandler.cpp b/src/net/ea/charserverhandler.cpp index e6e7e022e..3d665af22 100644 --- a/src/net/ea/charserverhandler.cpp +++ b/src/net/ea/charserverhandler.cpp @@ -23,12 +23,15 @@ #include "net/ea/charserverhandler.h" #include "client.h" +#include "configuration.h" #include "gui/charcreatedialog.h" #include "gui/okdialog.h" #include "net/ea/loginhandler.h" #include "net/ea/eaprotocol.h" +#include "net/ea/gamehandler.h" +#include "net/ea/network.h" #include "utils/dtor.h" #include "utils/gettext.h" @@ -37,23 +40,25 @@ #include "debug.h" -extern Net::CharHandler *charHandler; +extern Net::CharServerHandler *charServerHandler; namespace Ea { +extern ServerInfo mapServer; + CharServerHandler::CharServerHandler() : - Net::CharHandler() + Net::CharServerHandler() { } -void CharServerHandler::setCharSelectDialog(CharSelectDialog *window) +void CharServerHandler::setCharSelectDialog(CharSelectDialog *const window) { mCharSelectDialog = window; updateCharSelectDialog(); } -void CharServerHandler::setCharCreateDialog(CharCreateDialog *window) +void CharServerHandler::setCharCreateDialog(CharCreateDialog *const window) { mCharCreateDialog = window; @@ -105,7 +110,7 @@ unsigned int CharServerHandler::maxSprite() const return EA_SPRITE_VECTOREND; } -void CharServerHandler::processCharLoginError(Net::MessageIn &msg) +void CharServerHandler::processCharLoginError(Net::MessageIn &msg) const { switch (msg.readInt8()) { @@ -123,7 +128,8 @@ void CharServerHandler::processCharLoginError(Net::MessageIn &msg) Client::setState(STATE_ERROR); } -void CharServerHandler::processCharCreate(Net::MessageIn &msg, bool withColors) +void CharServerHandler::processCharCreate(Net::MessageIn &msg, + const bool withColors) { Net::Character *const character = new Net::Character; readPlayerData(msg, character, withColors); @@ -192,4 +198,59 @@ void CharServerHandler::clear() mCharacters.clear(); } +void CharServerHandler::processCharMapInfo(Net::MessageIn &msg, + Network *const network, + ServerInfo &server) +{ +// msg.skip(4); // CharID, must be the same as player_node->charID + PlayerInfo::setCharId(msg.readInt32()); + GameHandler *const gh = static_cast(Net::getGameHandler()); + gh->setMap(msg.readString(16)); + if (config.getBoolValue("usePersistentIP")) + { + msg.readInt32(); + server.hostname = Client::getServerName(); + } + else + { + server.hostname = ipToString(msg.readInt32()); + } + server.port = msg.readInt16(); + + // Prevent the selected local player from being deleted + player_node = mSelectedCharacter->dummy; + PlayerInfo::setBackend(mSelectedCharacter->data); + + mSelectedCharacter->dummy = nullptr; + + Net::getCharServerHandler()->clear(); + updateCharSelectDialog(); + + if (network) + network->disconnect(); + Client::setState(STATE_CONNECT_GAME); +} + +void CharServerHandler::processChangeMapServer(Net::MessageIn &msg, + Network *const network, + ServerInfo &server) const +{ + GameHandler *const gh = static_cast(Net::getGameHandler()); + if (!gh || !network) + return; + gh->setMap(msg.readString(16)); + const int x = msg.readInt16(); + const int y = msg.readInt16(); + server.hostname = ipToString(msg.readInt32()); + server.port = msg.readInt16(); + + network->disconnect(); + Client::setState(STATE_CHANGE_MAP); + if (player_node) + { + player_node->setTileCoords(x, y); + player_node->setMap(nullptr); + } +} + } // namespace Ea diff --git a/src/net/ea/charserverhandler.h b/src/net/ea/charserverhandler.h index 0b9908fee..6622371b3 100644 --- a/src/net/ea/charserverhandler.h +++ b/src/net/ea/charserverhandler.h @@ -23,7 +23,7 @@ #ifndef NET_EA_CHARSERVERHANDLER_H #define NET_EA_CHARSERVERHANDLER_H -#include "net/charhandler.h" +#include "net/charserverhandler.h" #include "net/messagein.h" #include "net/net.h" @@ -32,40 +32,43 @@ class LoginData; namespace Ea { +class Network; + /** * Deals with incoming messages from the character server. */ -class CharServerHandler : public Net::CharHandler +class CharServerHandler : public Net::CharServerHandler { public: CharServerHandler(); A_DELETE_COPY(CharServerHandler) - virtual void setCharSelectDialog(CharSelectDialog *window); + virtual void setCharSelectDialog(CharSelectDialog *const window) + override; /** * Sets the character create dialog. The handler will clean up this * dialog when a new character is succesfully created, and will unlock * the dialog when a new character failed to be created. */ - virtual void setCharCreateDialog(CharCreateDialog *window); + virtual void setCharCreateDialog(CharCreateDialog *const window) + override; - virtual void requestCharacters(); + virtual void requestCharacters() override; - virtual unsigned int baseSprite() const A_WARN_UNUSED; + virtual unsigned int baseSprite() const override A_WARN_UNUSED; - virtual unsigned int hairSprite() const A_WARN_UNUSED; + virtual unsigned int hairSprite() const override A_WARN_UNUSED; - virtual unsigned int maxSprite() const A_WARN_UNUSED; + virtual unsigned int maxSprite() const override A_WARN_UNUSED; virtual void connect() = 0; - virtual void processCharLogin(Net::MessageIn &msg) = 0; - - virtual void processCharLoginError(Net::MessageIn &msg); + virtual void processCharLoginError(Net::MessageIn &msg) const; - virtual void processCharCreate(Net::MessageIn &msg, bool withColors); + virtual void processCharCreate(Net::MessageIn &msg, + const bool withColors); virtual void processCharCreateFailed(Net::MessageIn &msg); @@ -73,12 +76,20 @@ class CharServerHandler : public Net::CharHandler virtual void processCharDeleteFailed(Net::MessageIn &msg); - virtual void clear(); + virtual void processCharMapInfo(Net::MessageIn &msg, + Network *const network, + ServerInfo &mapServer); + + virtual void processChangeMapServer(Net::MessageIn &msg, + Network *const network, + ServerInfo &mapServer) const; + + virtual void clear() override; protected: virtual void readPlayerData(Net::MessageIn &msg, - Net::Character *character, - bool withColors) = 0; + Net::Character *const character, + const bool withColors) const = 0; }; } // namespace Ea -- cgit v1.2.3-70-g09d2