diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2006-08-20 18:26:13 +0000 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2006-08-20 18:26:13 +0000 |
commit | a8ea71211ba50f0ad147c581aca1d45d7f41aca1 (patch) | |
tree | fd57cd6a9acad18e95021331bcad116eeeeaae88 | |
parent | 2fe42d32c6d368a66586c605cc1b38ee8d85ed1d (diff) | |
download | mana-a8ea71211ba50f0ad147c581aca1d45d7f41aca1.tar.gz mana-a8ea71211ba50f0ad147c581aca1d45d7f41aca1.tar.bz2 mana-a8ea71211ba50f0ad147c581aca1d45d7f41aca1.tar.xz mana-a8ea71211ba50f0ad147c581aca1d45d7f41aca1.zip |
GPMSG_PLAYER_MAP_CHANGE is now partly handled.
-rw-r--r-- | ChangeLog | 3 | ||||
-rw-r--r-- | src/engine.cpp | 2 | ||||
-rw-r--r-- | src/net/playerhandler.cpp | 81 | ||||
-rw-r--r-- | src/net/playerhandler.h | 7 | ||||
-rw-r--r-- | src/net/protocol.h | 2 |
5 files changed, 58 insertions, 37 deletions
@@ -28,6 +28,9 @@ * src/net/*: Changed MessageHandler::handleMessage to take a reference instead of a pointer. Removed unused Packet class. Added stub for handling GPMSG_BEING_ENTER. + * src/engine.cpp, src/net/playerhandler.h, src/net/protocol.h, + src/net/playerhandler.cpp: GPMSG_PLAYER_MAP_CHANGE is now partly + handled. 2006-08-19 Bjørn Lindeijer <bjorn@lindeijer.nl> 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 |