From a8ea71211ba50f0ad147c581aca1d45d7f41aca1 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Sun, 20 Aug 2006 18:26:13 +0000 Subject: GPMSG_PLAYER_MAP_CHANGE is now partly handled. --- src/engine.cpp | 2 +- src/net/playerhandler.cpp | 81 +++++++++++++++++++++++++++-------------------- src/net/playerhandler.h | 7 +++- src/net/protocol.h | 2 ++ 4 files changed, 55 insertions(+), 37 deletions(-) (limited to 'src') diff --git a/src/engine.cpp b/src/engine.cpp index 77f7f8ac..a6ce9533 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -115,7 +115,7 @@ void Engine::changeMap(const std::string &mapPath) beingManager->clear(); // Store full map path in global var - map_path = "maps/" + mapPath.substr(0, mapPath.rfind(".")) + ".tmx.gz"; + map_path = "maps/" + mapPath; // Attempt to load the new map Map *newMap = MapReader::readMap(map_path); diff --git a/src/net/playerhandler.cpp b/src/net/playerhandler.cpp index f6065aaf..c73aa2da 100644 --- a/src/net/playerhandler.cpp +++ b/src/net/playerhandler.cpp @@ -68,15 +68,14 @@ namespace { PlayerHandler::PlayerHandler() { static const Uint16 _messages[] = { - SMSG_WALK_RESPONSE, - SMSG_PLAYER_WARP, - SMSG_PLAYER_STAT_UPDATE_1, - SMSG_PLAYER_STAT_UPDATE_2, - SMSG_PLAYER_STAT_UPDATE_3, - SMSG_PLAYER_STAT_UPDATE_4, - SMSG_PLAYER_STAT_UPDATE_5, - SMSG_PLAYER_STAT_UPDATE_6, - SMSG_PLAYER_ARROW_MESSAGE, + //SMSG_PLAYER_STAT_UPDATE_1, + //SMSG_PLAYER_STAT_UPDATE_2, + //SMSG_PLAYER_STAT_UPDATE_3, + //SMSG_PLAYER_STAT_UPDATE_4, + //SMSG_PLAYER_STAT_UPDATE_5, + //SMSG_PLAYER_STAT_UPDATE_6, + //SMSG_PLAYER_ARROW_MESSAGE, + GPMSG_PLAYER_MAP_CHANGE, 0 }; handledMessages = _messages; @@ -86,32 +85,8 @@ void PlayerHandler::handleMessage(MessageIn &msg) { switch (msg.getId()) { - case SMSG_WALK_RESPONSE: - // It is assumed by the client any request to walk actually - // succeeds on the server. The plan is to have a correction - // message when the server senses the client has the wrong - // idea. - break; - - case SMSG_PLAYER_WARP: - { - std::string mapPath = msg.readString(16); - Uint16 x = msg.readShort(); - Uint16 y = msg.readShort(); - - logger->log("Warping to %s (%d, %d)", mapPath.c_str(), x, y); - - // Switch the actual map, deleting the previous one - engine->changeMap(mapPath); - - current_npc = 0; - - player_node->setAction(Being::STAND); - player_node->stopAttack(); - player_node->mFrame = 0; - player_node->mX = x; - player_node->mY = y; - } + case GPMSG_PLAYER_MAP_CHANGE: + handleMapChangeMessage(msg); break; case SMSG_PLAYER_STAT_UPDATE_1: @@ -323,3 +298,39 @@ void PlayerHandler::handleMessage(MessageIn &msg) //break; } } + +void +PlayerHandler::handleMapChangeMessage(MessageIn &msg) +{ + // { "mapname", x, y, B new server [, token, "gameserver", W port] } + + std::string mapName = msg.readString(); + unsigned short x = msg.readShort(); + unsigned short y = msg.readShort(); + unsigned char newServer = msg.readByte(); + + logger->log("Changing map to %s (%d, %d) on %s server", + mapName.c_str(), x, y, (newServer) ? "another" : "same"); + + // Switch the actual map, deleting the previous one + engine->changeMap(mapName); + + current_npc = 0; + + player_node->setAction(Being::STAND); + player_node->stopAttack(); + player_node->mFrame = 0; + + // TODO: Server is sending pixel coordinates. Client will need to work with + // these instead of converting them to tile coordinates. + player_node->mX = x / 32; + player_node->mY = y / 32; + + if (newServer) + { + // TODO: Implement reconnecting to another game server + //std::string token = msg.readString(32); + //std::string gameServer = msg.readString(); + //unsigned short gameServerPort = msg.readShort(); + } +} diff --git a/src/net/playerhandler.h b/src/net/playerhandler.h index 6d0baef7..9b6c9e01 100644 --- a/src/net/playerhandler.h +++ b/src/net/playerhandler.h @@ -31,7 +31,12 @@ class PlayerHandler : public MessageHandler public: PlayerHandler(); - void handleMessage(MessageIn &msg); + void + handleMessage(MessageIn &msg); + + private: + void + handleMapChangeMessage(MessageIn &msg); }; #endif diff --git a/src/net/protocol.h b/src/net/protocol.h index 528b2fd5..6927f3fd 100644 --- a/src/net/protocol.h +++ b/src/net/protocol.h @@ -148,6 +148,8 @@ enum { CPMSG_CONNECT_RESPONSE = 0x0054, // B error // Game + GPMSG_PLAYER_MAP_CHANGE = 0x0100, // S filename, W x, W y, B newserv + // [, S32 token, S server, W port] PGMSG_PICKUP = 0x0110, GPMSG_PICKUP_RESPONSE = 0x0111, GPMSG_BEING_ENTER = 0x0200, // B type, L being id -- cgit v1.2.3-70-g09d2