diff options
author | Jared Adams <jaxad0127@gmail.com> | 2010-04-12 14:46:06 -0600 |
---|---|---|
committer | Jared Adams <jaxad0127@gmail.com> | 2010-04-12 15:15:37 -0600 |
commit | 612c842f32fec68ece4244ac672a1b889cf2eb18 (patch) | |
tree | 8682f225a4681e281505bd0f4c501be701228a9e /src | |
parent | f30f3e6a51fc20bded8a3a04cd3a0f328a064469 (diff) | |
download | mana-612c842f32fec68ece4244ac672a1b889cf2eb18.tar.gz mana-612c842f32fec68ece4244ac672a1b889cf2eb18.tar.bz2 mana-612c842f32fec68ece4244ac672a1b889cf2eb18.tar.xz mana-612c842f32fec68ece4244ac672a1b889cf2eb18.zip |
Add support for map-server switching under eAthena
Also do some cleanup that's been needed for a while.
Reviewed-by: Bertram
Diffstat (limited to 'src')
-rw-r--r-- | src/client.cpp | 15 | ||||
-rw-r--r-- | src/commandhandler.cpp | 2 | ||||
-rw-r--r-- | src/game.cpp | 29 | ||||
-rw-r--r-- | src/game.h | 2 | ||||
-rw-r--r-- | src/net/ea/charserverhandler.cpp | 25 | ||||
-rw-r--r-- | src/net/ea/gamehandler.cpp | 21 | ||||
-rw-r--r-- | src/net/ea/gamehandler.h | 6 | ||||
-rw-r--r-- | src/net/ea/generalhandler.cpp | 5 | ||||
-rw-r--r-- | src/net/ea/generalhandler.h | 2 | ||||
-rw-r--r-- | src/net/ea/protocol.h | 1 | ||||
-rw-r--r-- | src/net/generalhandler.h | 5 | ||||
-rw-r--r-- | src/net/manaserv/gamehandler.cpp | 22 | ||||
-rw-r--r-- | src/net/manaserv/gamehandler.h | 2 | ||||
-rw-r--r-- | src/net/manaserv/generalhandler.cpp | 9 | ||||
-rw-r--r-- | src/net/manaserv/generalhandler.h | 2 |
15 files changed, 109 insertions, 39 deletions
diff --git a/src/client.cpp b/src/client.cpp index eebdaace..2e136e39 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -574,6 +574,10 @@ int Client::exec() if (mState != mOldState) { + Net::GeneralHandler *generalHandler = Net::getGeneralHandler(); + if (generalHandler) + generalHandler->stateChanged(mOldState, mState); + if (mOldState == STATE_GAME) { delete game; @@ -774,13 +778,20 @@ int Client::exec() STATE_SWITCH_CHARACTER); break; + case STATE_CHANGE_MAP: + logger->log("State: CHANGE_MAP"); + + Net::getGameHandler()->connect(); + mCurrentDialog = new ConnectionDialog( + _("Changing game servers"), + STATE_SWITCH_CHARACTER); + break; + case STATE_GAME: logger->log("Memorizing selected character %s", player_node->getName().c_str()); config.setValue("lastCharacter", player_node->getName()); - Net::getGameHandler()->inGame(); - // Fade out logon-music here too to give the desired effect // of "flowing" into the game. sound.fadeOutMusic(1000); diff --git a/src/commandhandler.cpp b/src/commandhandler.cpp index d6b03545..8d70b717 100644 --- a/src/commandhandler.cpp +++ b/src/commandhandler.cpp @@ -313,7 +313,7 @@ void CommandHandler::handleHelp(const std::string &args, ChatTab *tab) void CommandHandler::handleWhere(const std::string &args, ChatTab *tab) { std::ostringstream where; - where << map_path << ", coordinates: " + where << Game::instance()->getCurrentMapName() << ", coordinates: " << ((player_node->getPixelX() - 16) / 32) << ", " << ((player_node->getPixelY() - 32) / 32); diff --git a/src/game.cpp b/src/game.cpp index e0aa7313..88c74de6 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -92,8 +92,6 @@ #include <sstream> #include <string> -std::string map_path; - Joystick *joystick = NULL; OkDialog *weightNotice = NULL; @@ -232,12 +230,7 @@ Game::Game(): initEngines(); - // This part is eAthena specific - // For Manaserv, the map is obtained - // with the GPMSG_PLAYER_MAP_CHANGE flag. - map_path = map_path.substr(0, map_path.rfind(".")); - if (!map_path.empty()) - changeMap(map_path); + Net::getGameHandler()->inGame(); // Initialize beings beingManager->setPlayer(player_node); @@ -269,7 +262,8 @@ Game::~Game() destroyGuiWindows(); del_0(beingManager) - del_0(player_node) + if (Client::getState() != STATE_CHANGE_MAP) + del_0(player_node) del_0(floorItemManager) del_0(channelManager) del_0(commandHandler) @@ -277,7 +271,6 @@ Game::~Game() del_0(particleEngine) del_0(viewport) del_0(mCurrentMap) - map_path = ""; mInstance = 0; } @@ -349,6 +342,9 @@ void Game::logic() // Handle network stuff if (!Net::getGameHandler()->isConnected()) { + if (Client::getState() == STATE_CHANGE_MAP) + return; // Not a problem here + if (Client::getState() != STATE_ERROR) { errorMessage = _("The connection to the server was lost."); @@ -930,20 +926,19 @@ void Game::changeMap(const std::string &mapPath) mMapName = mapPath; - // Store full map path in global var - map_path = "maps/" + mapPath + ".tmx"; + std::string fullMap = "maps/" + mapPath + ".tmx"; ResourceManager *resman = ResourceManager::getInstance(); - if (!resman->exists(map_path)) - map_path += ".gz"; + if (!resman->exists(fullMap)) + fullMap += ".gz"; // Attempt to load the new map - Map *newMap = MapReader::readMap(map_path); + Map *newMap = MapReader::readMap(fullMap); if (!newMap) { - logger->log("Error while loading %s", map_path.c_str()); + logger->log("Error while loading %s", fullMap.c_str()); new OkDialog(_("Could Not Load Map"), - strprintf(_("Error while loading %s"), map_path.c_str())); + strprintf(_("Error while loading %s"), fullMap.c_str())); } // Notify the minimap and beingManager about the map change @@ -24,8 +24,6 @@ #include <string> -extern std::string map_path; // TODO: Get rid of this global - class Map; class WindowMenu; diff --git a/src/net/ea/charserverhandler.cpp b/src/net/ea/charserverhandler.cpp index f0a13f43..64e1d427 100644 --- a/src/net/ea/charserverhandler.cpp +++ b/src/net/ea/charserverhandler.cpp @@ -33,6 +33,7 @@ #include "net/messageout.h" #include "net/net.h" +#include "net/ea/gamehandler.h" #include "net/ea/loginhandler.h" #include "net/ea/network.h" #include "net/ea/protocol.h" @@ -60,6 +61,7 @@ CharServerHandler::CharServerHandler() SMSG_CHAR_DELETE_SUCCEEDED, SMSG_CHAR_DELETE_FAILED, SMSG_CHAR_MAP_INFO, + SMSG_CHANGE_MAP_SERVER, 0 }; handledMessages = _messages; @@ -153,8 +155,10 @@ void CharServerHandler::handleMessage(Net::MessageIn &msg) break; case SMSG_CHAR_MAP_INFO: + { msg.skip(4); // CharID, must be the same as player_node->charID - map_path = msg.readString(16); + GameHandler *gh = static_cast<GameHandler*>(Net::getGameHandler()); + gh->setMap(msg.readString(16)); mapServer.hostname = ipToString(msg.readInt32()); mapServer.port = msg.readInt16(); @@ -168,7 +172,24 @@ void CharServerHandler::handleMessage(Net::MessageIn &msg) mNetwork->disconnect(); Client::setState(STATE_CONNECT_GAME); - break; + } + break; + + case SMSG_CHANGE_MAP_SERVER: + { + GameHandler *gh = static_cast<GameHandler*>(Net::getGameHandler()); + gh->setMap(msg.readString(16)); + int x = msg.readInt16(); + int y = msg.readInt16(); + mapServer.hostname = ipToString(msg.readInt32()); + mapServer.port = msg.readInt16(); + + mNetwork->disconnect(); + Client::setState(STATE_CHANGE_MAP); + player_node->setTileCoords(x, y); + player_node->setMap(0); + } + break; } } diff --git a/src/net/ea/gamehandler.cpp b/src/net/ea/gamehandler.cpp index 3625b9ab..cabaf763 100644 --- a/src/net/ea/gamehandler.cpp +++ b/src/net/ea/gamehandler.cpp @@ -22,6 +22,7 @@ #include "net/ea/gamehandler.h" #include "client.h" +#include "game.h" #include "localplayer.h" #include "log.h" @@ -110,17 +111,22 @@ void GameHandler::connect() const Token &token = static_cast<LoginHandler*>(Net::getLoginHandler())->getToken(); + + if (Client::getState() == STATE_CONNECT_GAME) + { + mCharID = player_node->getId(); + // Change the player's ID to the account ID to match what eAthena uses + player_node->setId(token.account_ID); + } + // Send login infos MessageOut outMsg(CMSG_MAP_SERVER_CONNECT); outMsg.writeInt32(token.account_ID); - outMsg.writeInt32(player_node->getId()); + outMsg.writeInt32(mCharID); outMsg.writeInt32(token.session_ID1); outMsg.writeInt32(token.session_ID2); outMsg.writeInt8((token.sex == GENDER_MALE) ? 1 : 0); - // Change the player's ID to the account ID to match what eAthena uses - player_node->setId(token.account_ID); - // We get 4 useless bytes before the real answer comes in (what are these?) mNetwork->skip(4); } @@ -137,7 +143,7 @@ void GameHandler::disconnect() void GameHandler::inGame() { - // TODO + Game::instance()->changeMap(mMap); } void GameHandler::mapLoaded(const std::string &mapName) @@ -160,4 +166,9 @@ void GameHandler::ping(int tick) msg.writeInt32(tick); } +void GameHandler::setMap(const std::string map) +{ + mMap = map.substr(0, map.rfind(".")); +} + } // namespace EAthena diff --git a/src/net/ea/gamehandler.h b/src/net/ea/gamehandler.h index a6340bad..b8b6626d 100644 --- a/src/net/ea/gamehandler.h +++ b/src/net/ea/gamehandler.h @@ -57,6 +57,12 @@ class GameHandler : public MessageHandler, public Net::GameHandler bool removeDeadBeings() const { return true; } void clear(); + + void setMap(const std::string map); + + private: + std::string mMap; + int mCharID; /// < Saved for map-server switching }; } // namespace EAthena diff --git a/src/net/ea/generalhandler.cpp b/src/net/ea/generalhandler.cpp index 6ff4accd..047aee63 100644 --- a/src/net/ea/generalhandler.cpp +++ b/src/net/ea/generalhandler.cpp @@ -247,4 +247,9 @@ void GeneralHandler::clearHandlers() mNetwork->clearHandlers(); } +void GeneralHandler::stateChanged(State oldState, State newState) +{ + // +} + } // namespace EAthena diff --git a/src/net/ea/generalhandler.h b/src/net/ea/generalhandler.h index 464f8bc8..f0857abe 100644 --- a/src/net/ea/generalhandler.h +++ b/src/net/ea/generalhandler.h @@ -53,6 +53,8 @@ class GeneralHandler : public MessageHandler, public Net::GeneralHandler void clearHandlers(); + void stateChanged(State oldState, State newState); + protected: MessageHandlerPtr mAdminHandler; MessageHandlerPtr mBeingHandler; diff --git a/src/net/ea/protocol.h b/src/net/ea/protocol.h index 24fe5ba5..2d9c13c3 100644 --- a/src/net/ea/protocol.h +++ b/src/net/ea/protocol.h @@ -83,6 +83,7 @@ static const int STORAGE_OFFSET = 1; #define SMSG_CHAR_PASSWORD_RESPONSE 0x0062 /**< Custom packet reply to password change request */ #define SMSG_CHAR_SWITCH_RESPONSE 0x00b3 +#define SMSG_CHANGE_MAP_SERVER 0x0092 #define SMSG_MAP_LOGIN_SUCCESS 0x0073 /**< Contains starting location */ #define SMSG_MAP_QUIT_RESPONSE 0x018b diff --git a/src/net/generalhandler.h b/src/net/generalhandler.h index d4b762f2..222b430a 100644 --- a/src/net/generalhandler.h +++ b/src/net/generalhandler.h @@ -19,6 +19,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +#include "client.h" #include "main.h" #ifndef GENERALHANDLER_H @@ -29,6 +30,8 @@ namespace Net { class GeneralHandler { public: + virtual ~GeneralHandler() {} + virtual void load() = 0; virtual void reload() = 0; @@ -43,7 +46,7 @@ class GeneralHandler virtual void clearHandlers() = 0; - virtual ~GeneralHandler() {} + virtual void stateChanged(State oldState, State newState) = 0; }; } // namespace Net diff --git a/src/net/manaserv/gamehandler.cpp b/src/net/manaserv/gamehandler.cpp index dd6120ae..4c6c8e38 100644 --- a/src/net/manaserv/gamehandler.cpp +++ b/src/net/manaserv/gamehandler.cpp @@ -108,15 +108,7 @@ void GameHandler::disconnect() void GameHandler::inGame() { - - MessageOut msg(PGMSG_CONNECT); - msg.writeString(netToken, 32); - gameServerConnection->send(msg); - - chatHandler->connect(); - - // Attack range from item DB - player_node->setAttackRange(-1); + // TODO } void GameHandler::mapLoaded(const std::string &mapName) @@ -141,4 +133,16 @@ void GameHandler::ping(int tick) // TODO } +void GameHandler::gameLoading() +{ + MessageOut msg(PGMSG_CONNECT); + msg.writeString(netToken, 32); + gameServerConnection->send(msg); + + chatHandler->connect(); + + // Attack range from item DB + player_node->setAttackRange(-1); +} + } // namespace ManaServ diff --git a/src/net/manaserv/gamehandler.h b/src/net/manaserv/gamehandler.h index b021555f..dde1748f 100644 --- a/src/net/manaserv/gamehandler.h +++ b/src/net/manaserv/gamehandler.h @@ -57,6 +57,8 @@ class GameHandler : public MessageHandler, public Net::GameHandler bool removeDeadBeings() const { return false; } void clear(); + + void gameLoading(); }; } // namespace ManaServ diff --git a/src/net/manaserv/generalhandler.cpp b/src/net/manaserv/generalhandler.cpp index 6e1639af..0e030aa8 100644 --- a/src/net/manaserv/generalhandler.cpp +++ b/src/net/manaserv/generalhandler.cpp @@ -182,4 +182,13 @@ void GeneralHandler::clearHandlers() clearNetworkHandlers(); } +void GeneralHandler::stateChanged(State oldState, State newState) +{ + if (newState == STATE_GAME) + { + GameHandler *game = static_cast<GameHandler*>(Net::getGameHandler()); + game->gameLoading(); + } +} + } // namespace ManaServ diff --git a/src/net/manaserv/generalhandler.h b/src/net/manaserv/generalhandler.h index 61fa4aa3..58b95529 100644 --- a/src/net/manaserv/generalhandler.h +++ b/src/net/manaserv/generalhandler.h @@ -48,6 +48,8 @@ class GeneralHandler : public Net::GeneralHandler void clearHandlers(); + void stateChanged(State oldState, State newState); + protected: MessageHandlerPtr mBeingHandler; MessageHandlerPtr mBuySellHandler; |