diff options
Diffstat (limited to 'src/net/ea')
-rw-r--r-- | src/net/ea/charserverhandler.cpp | 48 | ||||
-rw-r--r-- | src/net/ea/charserverhandler.h | 8 | ||||
-rw-r--r-- | src/net/ea/gamehandler.cpp (renamed from src/net/ea/maphandler.cpp) | 60 | ||||
-rw-r--r-- | src/net/ea/gamehandler.h (renamed from src/net/ea/maphandler.h) | 20 | ||||
-rw-r--r-- | src/net/ea/generalhandler.cpp | 22 | ||||
-rw-r--r-- | src/net/ea/generalhandler.h | 6 | ||||
-rw-r--r-- | src/net/ea/loginhandler.cpp | 94 | ||||
-rw-r--r-- | src/net/ea/loginhandler.h | 12 | ||||
-rw-r--r-- | src/net/ea/logouthandler.cpp | 65 | ||||
-rw-r--r-- | src/net/ea/logouthandler.h | 47 | ||||
-rw-r--r-- | src/net/ea/network.cpp | 39 | ||||
-rw-r--r-- | src/net/ea/network.h | 10 | ||||
-rw-r--r-- | src/net/ea/playerhandler.cpp | 2 | ||||
-rw-r--r-- | src/net/ea/protocol.h | 6 |
14 files changed, 233 insertions, 206 deletions
diff --git a/src/net/ea/charserverhandler.cpp b/src/net/ea/charserverhandler.cpp index 47d454a8..f854841f 100644 --- a/src/net/ea/charserverhandler.cpp +++ b/src/net/ea/charserverhandler.cpp @@ -21,6 +21,7 @@ #include "net/ea/charserverhandler.h" +#include "net/ea/generalhandler.h" #include "net/ea/network.h" #include "net/ea/protocol.h" @@ -43,6 +44,9 @@ Net::CharHandler *charHandler; namespace EAthena { +extern Token netToken; +extern ServerInfo charServer; +extern ServerInfo mapServer; CharServerHandler::CharServerHandler(): mCharCreateDialog(0) @@ -145,8 +149,8 @@ void CharServerHandler::handleMessage(MessageIn &msg) slot = mCharInfo->getPos(); msg.skip(4); // CharID, must be the same as player_node->charID map_path = msg.readString(16); - mLoginData->hostname = ipToString(msg.readInt32()); - mLoginData->port = msg.readInt16(); + mapServer.hostname = ipToString(msg.readInt32()); + mapServer.port = msg.readInt16(); mCharInfo->unlock(); mCharInfo->select(0); // Clear unselected players infos @@ -162,7 +166,8 @@ void CharServerHandler::handleMessage(MessageIn &msg) } while (mCharInfo->getPos()); mCharInfo->select(slot); - state = STATE_CONNECTING; + mNetwork->disconnect(); + state = STATE_CONNECT_GAME; break; } } @@ -170,7 +175,7 @@ void CharServerHandler::handleMessage(MessageIn &msg) LocalPlayer *CharServerHandler::readPlayerData(MessageIn &msg, int &slot) { LocalPlayer *tempPlayer = new LocalPlayer(msg.readInt32(), 0, NULL); - tempPlayer->setGender(mLoginData->sex); + tempPlayer->setGender(netToken.sex); tempPlayer->setExp(msg.readInt32()); tempPlayer->setMoney(msg.readInt32()); @@ -229,24 +234,12 @@ void CharServerHandler::setCharCreateDialog(CharCreateDialog *window) attributes.push_back(_("Luck:")); mCharCreateDialog->setAttributes(attributes, 30, 1, 9); - mCharCreateDialog->setFixedGender(true, mLoginData->sex); + mCharCreateDialog->setFixedGender(true, netToken.sex); } -void CharServerHandler::connect(LoginData *loginData) +void CharServerHandler::getCharacters() { - mLoginData = loginData; - - MessageOut outMsg(CMSG_CHAR_SERVER_CONNECT); - outMsg.writeInt32(loginData->account_ID); - outMsg.writeInt32(loginData->session_ID1); - outMsg.writeInt32(loginData->session_ID2); - // [Fate] The next word is unused by the old char server, so we squeeze in - // tmw client version information - outMsg.writeInt16(CLIENT_PROTOCOL_VERSION); - outMsg.writeInt8((loginData->sex == GENDER_MALE) ? 1 : 0); - - // We get 4 useless bytes before the real answer comes in (what are these?) - mNetwork->skip(4); + connect(); } void CharServerHandler::chooseCharacter(int slot, LocalPlayer* character) @@ -276,4 +269,21 @@ void CharServerHandler::deleteCharacter(int slot, LocalPlayer* character) outMsg.writeString("a@a.com", 40); } +void CharServerHandler::connect() +{ + mNetwork->disconnect(); + mNetwork->connect(charServer); + MessageOut outMsg(CMSG_CHAR_SERVER_CONNECT); + outMsg.writeInt32(netToken.account_ID); + outMsg.writeInt32(netToken.session_ID1); + outMsg.writeInt32(netToken.session_ID2); + // [Fate] The next word is unused by the old char server, so we squeeze in + // tmw client version information + outMsg.writeInt16(CLIENT_PROTOCOL_VERSION); + outMsg.writeInt8((netToken.sex == GENDER_MALE) ? 1 : 0); + + // We get 4 useless bytes before the real answer comes in (what are these?) + mNetwork->skip(4); +} + } // namespace EAthena diff --git a/src/net/ea/charserverhandler.h b/src/net/ea/charserverhandler.h index 3ebac16e..aa36f873 100644 --- a/src/net/ea/charserverhandler.h +++ b/src/net/ea/charserverhandler.h @@ -24,6 +24,9 @@ #include "net/messagehandler.h" #include "net/charhandler.h" +#include "net/serverinfo.h" + +#include "net/ea/token.h" class LoginData; @@ -49,7 +52,7 @@ class CharServerHandler : public MessageHandler, public Net::CharHandler */ void setCharCreateDialog(CharCreateDialog *window); - void connect(LoginData *loginData); + void getCharacters(); void chooseCharacter(int slot, LocalPlayer* character); @@ -58,8 +61,9 @@ class CharServerHandler : public MessageHandler, public Net::CharHandler void deleteCharacter(int slot, LocalPlayer* character); + void connect(); + protected: - LoginData *mLoginData; LockedArray<LocalPlayer*> *mCharInfo; CharCreateDialog *mCharCreateDialog; diff --git a/src/net/ea/maphandler.cpp b/src/net/ea/gamehandler.cpp index c3c9437c..f84688a3 100644 --- a/src/net/ea/maphandler.cpp +++ b/src/net/ea/gamehandler.cpp @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "net/ea/maphandler.h" +#include "net/ea/gamehandler.h" #include "net/ea/network.h" #include "net/ea/protocol.h" @@ -37,12 +37,14 @@ #include "utils/gettext.h" #include "utils/stringutils.h" -Net::MapHandler *mapHandler; +Net::GameHandler *gameHandler; extern Game *game; namespace EAthena { +extern Token netToken; +extern ServerInfo mapServer; -MapHandler::MapHandler() +GameHandler::GameHandler() { static const Uint16 _messages[] = { SMSG_MAP_LOGIN_SUCCESS, @@ -51,10 +53,10 @@ MapHandler::MapHandler() 0 }; handledMessages = _messages; - mapHandler = this; + gameHandler = this; } -void MapHandler::handleMessage(MessageIn &msg) +void GameHandler::handleMessage(MessageIn &msg) { unsigned char direction; @@ -68,9 +70,9 @@ void MapHandler::handleMessage(MessageIn &msg) msg.skip(2); // unknown logger->log("Protocol: Player start position: (%d, %d), Direction: %d", x, y, direction); - state = STATE_GAME; + // Switch now or we'll have problems + // state = STATE_GAME; player_node->setTileCoords(x, y); - game = new Game; } break; case SMSG_SERVER_PING: @@ -85,43 +87,63 @@ void MapHandler::handleMessage(MessageIn &msg) } } -#include <fstream> - -void MapHandler::connect(LoginData *loginData) +void GameHandler::connect() { + mNetwork->connect(mapServer); + // Send login infos MessageOut outMsg(CMSG_MAP_SERVER_CONNECT); - outMsg.writeInt32(loginData->account_ID); + outMsg.writeInt32(netToken.account_ID); outMsg.writeInt32(player_node->getId()); - outMsg.writeInt32(loginData->session_ID1); - outMsg.writeInt32(loginData->session_ID2); - outMsg.writeInt8((loginData->sex == GENDER_MALE) ? 1 : 0); + outMsg.writeInt32(netToken.session_ID1); + outMsg.writeInt32(netToken.session_ID2); + outMsg.writeInt8((netToken.sex == GENDER_MALE) ? 1 : 0); // Change the player's ID to the account ID to match what eAthena uses - player_node->setId(loginData->account_ID); + player_node->setId(netToken.account_ID); // We get 4 useless bytes before the real answer comes in (what are these?) mNetwork->skip(4); } -void MapHandler::mapLoaded(const std::string &mapName) +bool GameHandler::isConnected() +{ + return mNetwork->isConnected(); +} + +void GameHandler::disconnect() +{ + mNetwork->disconnect(); +} + +void GameHandler::inGame() +{ + // TODO +} + +void GameHandler::mapLoaded(const std::string &mapName) { MessageOut outMsg(CMSG_MAP_LOADED); } -void MapHandler::who() +void GameHandler::who() { } -void MapHandler::quit() +void GameHandler::quit() { MessageOut outMsg(CMSG_CLIENT_QUIT); } -void MapHandler::ping(int tick) +void GameHandler::ping(int tick) { MessageOut msg(CMSG_CLIENT_PING); msg.writeInt32(tick); } +void GameHandler::clear() +{ + disconnect(); +} + } // namespace EAthena diff --git a/src/net/ea/maphandler.h b/src/net/ea/gamehandler.h index 205ee18d..6cb640c1 100644 --- a/src/net/ea/maphandler.h +++ b/src/net/ea/gamehandler.h @@ -22,20 +22,29 @@ #ifndef NET_EA_MAPHANDLER_H #define NET_EA_MAPHANDLER_H -#include "net/maphandler.h" +#include "net/gamehandler.h" #include "net/messagehandler.h" #include "net/net.h" +#include "net/serverinfo.h" + +#include "net/ea/token.h" namespace EAthena { -class MapHandler : public MessageHandler, public Net::MapHandler +class GameHandler : public MessageHandler, public Net::GameHandler { public: - MapHandler(); + GameHandler(); void handleMessage(MessageIn &msg); - void connect(LoginData *loginData); + void connect(); + + bool isConnected(); + + void disconnect(); + + void inGame(); void mapLoaded(const std::string &mapName); @@ -44,6 +53,9 @@ class MapHandler : public MessageHandler, public Net::MapHandler void quit(); void ping(int tick); + + void clear(); + }; } // namespace EAthena diff --git a/src/net/ea/generalhandler.cpp b/src/net/ea/generalhandler.cpp index 1d500d62..1dde3b3f 100644 --- a/src/net/ea/generalhandler.cpp +++ b/src/net/ea/generalhandler.cpp @@ -22,11 +22,13 @@ #include "net/ea/generalhandler.h" #include "gui/inventorywindow.h" +#include "gui/register.h" #include "gui/skilldialog.h" #include "gui/statuswindow.h" #include "net/ea/network.h" #include "net/ea/protocol.h" +#include "net/ea/token.h" #include "net/ea/adminhandler.h" #include "net/ea/beinghandler.h" @@ -34,11 +36,10 @@ #include "net/ea/chathandler.h" #include "net/ea/charserverhandler.h" #include "net/ea/equipmenthandler.h" +#include "net/ea/gamehandler.h" #include "net/ea/inventoryhandler.h" #include "net/ea/itemhandler.h" #include "net/ea/loginhandler.h" -#include "net/ea/logouthandler.h" -#include "net/ea/maphandler.h" #include "net/ea/npchandler.h" #include "net/ea/playerhandler.h" #include "net/ea/partyhandler.h" @@ -63,6 +64,9 @@ Net::GeneralHandler *generalHandler; namespace EAthena { +Token netToken; +ServerInfo charServer; +ServerInfo mapServer; GeneralHandler::GeneralHandler(): mAdminHandler(new AdminHandler), @@ -71,11 +75,10 @@ GeneralHandler::GeneralHandler(): mCharHandler(new CharServerHandler), mChatHandler(new ChatHandler), mEquipmentHandler(new EquipmentHandler), + mGameHandler(new GameHandler), mInventoryHandler(new InventoryHandler), mItemHandler(new ItemHandler), mLoginHandler(new LoginHandler), - mLogoutHandler(new LogoutHandler), - mMapHandler(new MapHandler), mNpcHandler(new NpcHandler), mPartyHandler(new PartyHandler), mPlayerHandler(new PlayerHandler), @@ -146,17 +149,18 @@ void GeneralHandler::handleMessage(MessageIn &msg) void GeneralHandler::load() { + (new Network)->registerHandler(this); + mNetwork->registerHandler(mAdminHandler.get()); mNetwork->registerHandler(mBeingHandler.get()); mNetwork->registerHandler(mBuySellHandler.get()); mNetwork->registerHandler(mChatHandler.get()); mNetwork->registerHandler(mCharHandler.get()); mNetwork->registerHandler(mEquipmentHandler.get()); + mNetwork->registerHandler(mGameHandler.get()); mNetwork->registerHandler(mInventoryHandler.get()); mNetwork->registerHandler(mItemHandler.get()); mNetwork->registerHandler(mLoginHandler.get()); - mNetwork->registerHandler(mLogoutHandler.get()); - mNetwork->registerHandler(mMapHandler.get()); mNetwork->registerHandler(mNpcHandler.get()); mNetwork->registerHandler(mPlayerHandler.get()); mNetwork->registerHandler(mSpecialHandler.get()); @@ -203,6 +207,7 @@ void GeneralHandler::guiWindowsLoaded() { partyTab = new PartyTab; inventoryWindow->setSplitAllowed(false); + RegisterDialog::setGender(&netToken.sex); skillDialog->loadSkills("ea-skills.xml"); statusWindow->addAttribute(STR, _("Strength"), true); @@ -226,4 +231,9 @@ void GeneralHandler::guiWindowsUnloaded() delete partyTab; } +void GeneralHandler::clearHandlers() +{ + mNetwork->clearHandlers(); +} + } // namespace EAthena diff --git a/src/net/ea/generalhandler.h b/src/net/ea/generalhandler.h index 98364e5d..099bed0b 100644 --- a/src/net/ea/generalhandler.h +++ b/src/net/ea/generalhandler.h @@ -25,6 +25,7 @@ #include "net/generalhandler.h" #include "net/messagehandler.h" #include "net/net.h" +#include "net/serverinfo.h" namespace EAthena { @@ -51,6 +52,8 @@ class GeneralHandler : public MessageHandler, public Net::GeneralHandler void guiWindowsUnloaded(); + void clearHandlers(); + protected: MessageHandlerPtr mAdminHandler; MessageHandlerPtr mBeingHandler; @@ -58,11 +61,10 @@ class GeneralHandler : public MessageHandler, public Net::GeneralHandler MessageHandlerPtr mCharHandler; MessageHandlerPtr mChatHandler; MessageHandlerPtr mEquipmentHandler; + MessageHandlerPtr mGameHandler; MessageHandlerPtr mInventoryHandler; MessageHandlerPtr mItemHandler; MessageHandlerPtr mLoginHandler; - MessageHandlerPtr mLogoutHandler; - MessageHandlerPtr mMapHandler; MessageHandlerPtr mNpcHandler; MessageHandlerPtr mPartyHandler; MessageHandlerPtr mPlayerHandler; diff --git a/src/net/ea/loginhandler.cpp b/src/net/ea/loginhandler.cpp index 8e7187c0..d2e2adc0 100644 --- a/src/net/ea/loginhandler.cpp +++ b/src/net/ea/loginhandler.cpp @@ -21,24 +21,27 @@ #include "net/ea/loginhandler.h" +#include "net/ea/network.h" #include "net/ea/protocol.h" #include "net/logindata.h" #include "net/messagein.h" #include "net/messageout.h" -#include "net/serverinfo.h" #include "log.h" #include "main.h" +#include "utils/dtor.h" #include "utils/gettext.h" #include "utils/stringutils.h" -extern SERVER_INFO **server_info; +Worlds worlds; Net::LoginHandler *loginHandler; namespace EAthena { +extern Token netToken; +extern ServerInfo charServer; LoginHandler::LoginHandler() { @@ -47,6 +50,7 @@ LoginHandler::LoginHandler() SMSG_LOGIN_DATA, SMSG_LOGIN_ERROR, SMSG_CHAR_PASSWORD_RESPONSE, + SMSG_SERVER_VERSION_RESPONSE, 0 }; handledMessages = _messages; @@ -55,7 +59,7 @@ LoginHandler::LoginHandler() void LoginHandler::handleMessage(MessageIn &msg) { - int code; + int code, worldCount; switch (msg.getId()) { @@ -104,33 +108,34 @@ void LoginHandler::handleMessage(MessageIn &msg) // Skip the length word msg.skip(2); - n_server = (msg.getLength() - 47) / 32; - server_info = - (SERVER_INFO**) malloc(sizeof(SERVER_INFO*) * n_server); + delete_all(worlds); + worldCount = (msg.getLength() - 47) / 32; - mLoginData->session_ID1 = msg.readInt32(); - mLoginData->account_ID = msg.readInt32(); - mLoginData->session_ID2 = msg.readInt32(); + netToken.session_ID1 = msg.readInt32(); + netToken.account_ID = msg.readInt32(); + netToken.session_ID2 = msg.readInt32(); msg.skip(30); // unknown - mLoginData->sex = msg.readInt8() ? GENDER_MALE : GENDER_FEMALE; + netToken.sex = msg.readInt8() ? GENDER_MALE : GENDER_FEMALE; - for (int i = 0; i < n_server; i++) + for (int i = 0; i < worldCount; i++) { - server_info[i] = new SERVER_INFO; + WorldInfo *world = new WorldInfo; - server_info[i]->address = msg.readInt32(); - server_info[i]->port = msg.readInt16(); - server_info[i]->name = msg.readString(20); - server_info[i]->online_users = msg.readInt32(); - server_info[i]->updateHost = mUpdateHost; + world->address = msg.readInt32(); + world->port = msg.readInt16(); + world->name = msg.readString(20); + world->online_users = msg.readInt32(); + world->updateHost = mUpdateHost; msg.skip(2); // unknown logger->log("Network: Server: %s (%s:%d)", - server_info[i]->name.c_str(), - ipToString(server_info[i]->address), - server_info[i]->port); + world->name.c_str(), + ipToString(world->address), + world->port); + + worlds.push_back(world); } - state = STATE_CHAR_SERVER; + state = STATE_WORLD_SELECT; break; case SMSG_LOGIN_ERROR: @@ -171,9 +176,40 @@ void LoginHandler::handleMessage(MessageIn &msg) } state = STATE_ERROR; break; + case SMSG_SERVER_VERSION_RESPONSE: + { + // TODO: verify these! + msg.readInt8(); // -1 + msg.readInt8(); // T + msg.readInt8(); // M + msg.readInt8(); // W + msg.readInt8(); // (space) + msg.readInt8(); // e + msg.readInt8(); // A + + //state = STATE_LOGIN; + } + break; } } +void LoginHandler::connect() +{ + mNetwork->connect(mServer); + MessageOut outMsg(CMSG_SERVER_VERSION_REQUEST); +} + +bool LoginHandler::isConnected() +{ + return mNetwork->isConnected(); +} + +void LoginHandler::disconnect() +{ + if (mNetwork->getServer() == mServer) + mNetwork->disconnect(); +} + void LoginHandler::loginAccount(LoginData *loginData) { mLoginData = loginData; @@ -194,9 +230,14 @@ void LoginHandler::changePassword(const std::string &username, outMsg.writeString(newPassword, 24); } -void LoginHandler::chooseServer(int server) +void LoginHandler::chooseServer(unsigned int server) { - // TODO + if (server >= worlds.size()) + return; + + charServer.clear(); + charServer.hostname = ipToString(worlds[server]->address); + charServer.port = worlds[server]->port; } void LoginHandler::registerAccount(LoginData *loginData) @@ -204,7 +245,7 @@ void LoginHandler::registerAccount(LoginData *loginData) mLoginData = loginData; std::string username = loginData->username; - username.append((loginData->sex == GENDER_FEMALE) ? "_F" : "_M"); + username.append((netToken.sex == GENDER_FEMALE) ? "_F" : "_M"); sendLoginRegister(username, loginData->password); } @@ -232,4 +273,9 @@ void LoginHandler::sendLoginRegister(const std::string &username, outMsg.writeInt8(0x03); } +Worlds LoginHandler::getWorlds() +{ + return worlds; +} + } // namespace EAthena diff --git a/src/net/ea/loginhandler.h b/src/net/ea/loginhandler.h index 93f21754..bc1aa816 100644 --- a/src/net/ea/loginhandler.h +++ b/src/net/ea/loginhandler.h @@ -25,6 +25,8 @@ #include "net/loginhandler.h" #include "net/messagehandler.h" +#include "net/ea/token.h" + #include <string> struct LoginData; @@ -38,6 +40,12 @@ class LoginHandler : public MessageHandler, public Net::LoginHandler void handleMessage(MessageIn &msg); + void connect(); + + bool isConnected(); + + void disconnect(); + void loginAccount(LoginData *loginData); void changeEmail(const std::string &email); @@ -46,13 +54,15 @@ class LoginHandler : public MessageHandler, public Net::LoginHandler const std::string &oldPassword, const std::string &newPassword); - void chooseServer(int server); + void chooseServer(unsigned int server); void registerAccount(LoginData *loginData); void unregisterAccount(const std::string &username, const std::string &password); + Worlds getWorlds(); + private: void sendLoginRegister(const std::string &username, const std::string &password); diff --git a/src/net/ea/logouthandler.cpp b/src/net/ea/logouthandler.cpp deleted file mode 100644 index 7de87c6a..00000000 --- a/src/net/ea/logouthandler.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/* - * The Mana World - * Copyright (C) 2004 The Mana World Development Team - * - * This file is part of The Mana World. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "net/ea/logouthandler.h" - -#include "net/ea/protocol.h" - -#include "net/logindata.h" -#include "net/messagein.h" -#include "net/messageout.h" -#include "net/serverinfo.h" - -#include "log.h" -#include "main.h" - -#include "utils/gettext.h" -#include "utils/stringutils.h" - -Net::LogoutHandler *logoutHandler; - -namespace EAthena { - -LogoutHandler::LogoutHandler() -{ - static const Uint16 _messages[] = { - 0 - }; - handledMessages = _messages; - logoutHandler = this; -} - -void LogoutHandler::handleMessage(MessageIn &msg) -{ -} - -void LogoutHandler::setScenario(unsigned short scenario, - std::string *passToken) -{ - // TODO -} - -void LogoutHandler::reset() -{ - // TODO -} - -} // namespace EAthena diff --git a/src/net/ea/logouthandler.h b/src/net/ea/logouthandler.h deleted file mode 100644 index 0d118ab0..00000000 --- a/src/net/ea/logouthandler.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * The Mana World - * Copyright (C) 2004 The Mana World Development Team - * - * This file is part of The Mana World. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef NET_EA_LOGOUTHANDLER_H -#define NET_EA_LOGOUTHANDLER_H - -#include "net/logouthandler.h" -#include "net/messagehandler.h" - -#include <string> - -namespace EAthena { - -class LogoutHandler : public MessageHandler, public Net::LogoutHandler -{ - public: - LogoutHandler(); - - void handleMessage(MessageIn &msg); - - void setScenario(unsigned short scenario, - std::string *passToken = NULL); - - void reset(); -}; - -} // namespace EAthena - -#endif // NET_EA_LOGOUTHANDLER_H diff --git a/src/net/ea/network.cpp b/src/net/ea/network.cpp index c6bc712c..68bdc870 100644 --- a/src/net/ea/network.cpp +++ b/src/net/ea/network.cpp @@ -21,12 +21,16 @@ #include "net/ea/network.h" +#include "net/ea/protocol.h" + #include "net/messagehandler.h" #include "net/messagein.h" -#include "log.h" #include "utils/stringutils.h" +#include "log.h" + +#include <assert.h> #include <sstream> /** Warning: buffers and other variables are shared, @@ -95,7 +99,6 @@ Network *Network::mInstance = 0; Network::Network(): mSocket(0), - mAddress(), mPort(0), mInBuffer(new char[BUFFER_SIZE]), mOutBuffer(new char[BUFFER_SIZE]), mInSize(0), mOutSize(0), @@ -125,24 +128,26 @@ Network::~Network() SDLNet_Quit(); } -bool Network::connect(const std::string &address, short port) +bool Network::connect(ServerInfo server) { if (mState != IDLE && mState != NET_ERROR) { logger->log("Tried to connect an already connected socket!"); + assert(false); return false; } - if (address.empty()) + if (server.hostname.empty()) { setError("Empty address given to Network::connect()!"); return false; } - logger->log("Network::Connecting to %s:%i", address.c_str(), port); + logger->log("Network::Connecting to %s:%i", server.hostname.c_str(), + server.port); - mAddress = address; - mPort = port; + mServer.hostname = server.hostname; + mServer.port = server.port; // Reset to sane values mOutSize = 0; @@ -269,12 +274,16 @@ void Network::skip(int len) bool Network::messageReady() { - int len = -1; + int len = -1, msgId; SDL_mutexP(mMutex); if (mInSize >= 2) { - len = packet_lengths[readWord(0)]; + msgId = readWord(0); + if (msgId == SMSG_SERVER_VERSION_RESPONSE) + len = 10; + else + len = packet_lengths[msgId]; if (len == -1 && mInSize > 4) len = readWord(2); @@ -297,7 +306,11 @@ MessageIn Network::getNextMessage() SDL_mutexP(mMutex); int msgId = readWord(0); - int len = packet_lengths[msgId]; + int len; + if (msgId == SMSG_SERVER_VERSION_RESPONSE) + len = 10; + else + len = packet_lengths[msgId]; if (len == -1) len = readWord(2); @@ -316,9 +329,11 @@ bool Network::realConnect() { IPaddress ipAddress; - if (SDLNet_ResolveHost(&ipAddress, mAddress.c_str(), mPort) == -1) + if (SDLNet_ResolveHost(&ipAddress, mServer.hostname.c_str(), + mServer.port) == -1) { - std::string errorMessage = "Unable to resolve host \"" + mAddress + "\""; + std::string errorMessage = "Unable to resolve host \"" + + mServer.hostname + "\""; setError(errorMessage); logger->log("SDLNet_ResolveHost: %s", errorMessage.c_str()); return false; diff --git a/src/net/ea/network.h b/src/net/ea/network.h index 741a8297..b61f363b 100644 --- a/src/net/ea/network.h +++ b/src/net/ea/network.h @@ -22,6 +22,8 @@ #ifndef EA_NETWORK_H #define EA_NETWORK_H +#include "net/serverinfo.h" + #include <SDL_net.h> #include <SDL_thread.h> @@ -47,10 +49,13 @@ class Network ~Network(); - bool connect(const std::string &address, short port); + bool connect(ServerInfo server); void disconnect(); + ServerInfo getServer() + { return mServer; } + void registerHandler(MessageHandler *handler); void unregisterHandler(MessageHandler *handler); @@ -97,8 +102,7 @@ class Network TCPsocket mSocket; - std::string mAddress; - short mPort; + ServerInfo mServer; char *mInBuffer, *mOutBuffer; unsigned int mInSize, mOutSize; diff --git a/src/net/ea/playerhandler.cpp b/src/net/ea/playerhandler.cpp index 3e379d82..ae94ab92 100644 --- a/src/net/ea/playerhandler.cpp +++ b/src/net/ea/playerhandler.cpp @@ -548,7 +548,7 @@ void PlayerHandler::changeAction(Being::Action action) void PlayerHandler::respawn() { - MessageOut outMsg(CMSG_PLAYER_RESPAWN); + MessageOut outMsg(CMSG_PLAYER_RESTART); outMsg.writeInt8(0); } diff --git a/src/net/ea/protocol.h b/src/net/ea/protocol.h index 07350841..8f3e40b5 100644 --- a/src/net/ea/protocol.h +++ b/src/net/ea/protocol.h @@ -47,6 +47,8 @@ static const int STORAGE_OFFSET = 1; /********************************* * Packets from server to client * *********************************/ +#define SMSG_SERVER_VERSION_RESPONSE 0x7531 + #define SMSG_SERVER_PING 0x007f /**< Contains server tick */ #define SMSG_CONNECTION_PROBLEM 0x0081 @@ -162,6 +164,8 @@ static const int STORAGE_OFFSET = 1; /********************************** * Packets from client to server * **********************************/ +#define CMSG_SERVER_VERSION_REQUEST 0x7530 + #define CMSG_CHAR_PASSWORD_CHANGE 0x0061 /**< Custom change password packet */ #define CMSG_CHAR_SERVER_CONNECT 0x0065 #define CMSG_CHAR_SELECT 0x0066 @@ -195,7 +199,7 @@ static const int STORAGE_OFFSET = 1; #define CMSG_PLAYER_CHANGE_DIR 0x009b #define CMSG_PLAYER_CHANGE_DEST 0x0085 #define CMSG_PLAYER_CHANGE_ACT 0x0089 -#define CMSG_PLAYER_RESPAWN 0x00b2 +#define CMSG_PLAYER_RESTART 0x00b2 #define CMSG_PLAYER_EMOTE 0x00bf #define CMSG_PLAYER_ATTACK 0x0089 #define CMSG_WHO_REQUEST 0x00c1 |