00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "net/ea/maphandler.h"
00023
00024 #include "net/ea/network.h"
00025 #include "net/ea/protocol.h"
00026
00027 #include "net/messagein.h"
00028 #include "net/messageout.h"
00029
00030 #include "localplayer.h"
00031 #include "log.h"
00032 #include "main.h"
00033
00034 #include "gui/widgets/chattab.h"
00035
00036 #include "utils/gettext.h"
00037 #include "utils/stringutils.h"
00038
00039 Net::MapHandler *mapHandler;
00040
00041 namespace EAthena {
00042
00043 MapHandler::MapHandler()
00044 {
00045 static const Uint16 _messages[] = {
00046 SMSG_MAP_LOGIN_SUCCESS,
00047 SMSG_SERVER_PING,
00048 SMSG_WHO_ANSWER,
00049 0
00050 };
00051 handledMessages = _messages;
00052 mapHandler = this;
00053 }
00054
00055 void MapHandler::handleMessage(MessageIn &msg)
00056 {
00057 unsigned char direction;
00058
00059 switch (msg.getId())
00060 {
00061 case SMSG_MAP_LOGIN_SUCCESS:
00062 msg.readInt32();
00063 msg.readCoordinates(player_node->mX, player_node->mY, direction);
00064 msg.skip(2);
00065 logger->log("Protocol: Player start position: (%d, %d), Direction: %d",
00066 player_node->mX, player_node->mY, direction);
00067 state = STATE_GAME;
00068 break;
00069
00070 case SMSG_SERVER_PING:
00071
00072
00073 break;
00074
00075 case SMSG_WHO_ANSWER:
00076 localChatTab->chatLog("Online users: " + toString(msg.readInt32()),
00077 BY_SERVER);
00078 break;
00079 }
00080 }
00081
00082 void MapHandler::connect(LoginData *loginData)
00083 {
00084
00085 MessageOut outMsg(CMSG_MAP_SERVER_CONNECT);
00086 outMsg.writeInt32(loginData->account_ID);
00087 outMsg.writeInt32(player_node->mCharId);
00088 outMsg.writeInt32(loginData->session_ID1);
00089 outMsg.writeInt32(loginData->session_ID2);
00090 outMsg.writeInt8((loginData->sex == GENDER_MALE) ? 1 : 0);
00091
00092
00093 mNetwork->skip(4);
00094 }
00095
00096 void MapHandler::mapLoaded(const std::string &mapName)
00097 {
00098 MessageOut outMsg(CMSG_MAP_LOADED);
00099 }
00100
00101 void MapHandler::who()
00102 {
00103
00104 }
00105
00106 void MapHandler::quit()
00107 {
00108 MessageOut outMsg(CMSG_CLIENT_QUIT);
00109 }
00110
00111 void MapHandler::ping(int tick)
00112 {
00113 MessageOut msg(CMSG_CLIENT_PING);
00114 msg.writeInt32(tick);
00115 }
00116
00117 }