diff options
Diffstat (limited to 'src/net')
27 files changed, 888 insertions, 118 deletions
diff --git a/src/net/charhandler.h b/src/net/charhandler.h index 7d1b9ab2..56bfbbb4 100644 --- a/src/net/charhandler.h +++ b/src/net/charhandler.h @@ -23,16 +23,23 @@ #define CHARHANDLER_H #include "localplayer.h" +#include "lockedarray.h" +#include "logindata.h" #include <iosfwd> #include <vector> class CharCreateDialog; +class LocalPlayer; namespace Net { class CharHandler { public: + virtual void setCharInfo(LockedArray<LocalPlayer*> *charInfo) = 0; + + virtual void connect(LoginData *loginData) = 0; + virtual void setCharCreateDialog(CharCreateDialog *window) = 0; virtual void chooseCharacter(int slot, LocalPlayer* character) = 0; diff --git a/src/net/ea/charserverhandler.cpp b/src/net/ea/charserverhandler.cpp index 377cd2dd..0fcc2cb0 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/network.h" #include "net/ea/protocol.h" #include "net/messagein.h" @@ -45,7 +46,6 @@ CharServerHandler::CharServerHandler(): mCharCreateDialog(0) { static const Uint16 _messages[] = { - SMSG_CONNECTION_PROBLEM, 0x006b, 0x006c, 0x006d, @@ -68,33 +68,6 @@ void CharServerHandler::handleMessage(MessageIn &msg) msg.getId(), msg.getLength()); switch (msg.getId()) { - case SMSG_CONNECTION_PROBLEM: - code = msg.readInt8(); - logger->log("Connection problem: %i", code); - - switch (code) { - case 0: - errorMessage = _("Authentication failed"); - break; - case 1: - errorMessage = _("Map server(s) offline"); - break; - case 2: - errorMessage = _("This account is already logged in"); - break; - case 3: - errorMessage = _("Speed hack detected"); - break; - case 8: - errorMessage = _("Duplicated login"); - break; - default: - errorMessage = _("Unknown connection error"); - break; - } - state = STATE_ERROR; - break; - case 0x006b: msg.skip(2); // Length word flags = msg.readInt32(); // Aethyra extensions flags @@ -259,6 +232,23 @@ void CharServerHandler::setCharCreateDialog(CharCreateDialog *window) mCharCreateDialog->setFixedGender(true); } +void CharServerHandler::connect(LoginData *loginData) +{ + mLoginData = loginData; + + MessageOut outMsg(0x0065); + 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); + + // We get 4 useless bytes before the real answer comes in (what are these?) + mNetwork->skip(4); +} + void CharServerHandler::chooseCharacter(int slot, LocalPlayer* character) { MessageOut outMsg(CMSG_CHAR_SELECT); diff --git a/src/net/ea/charserverhandler.h b/src/net/ea/charserverhandler.h index 48392ac4..3ebac16e 100644 --- a/src/net/ea/charserverhandler.h +++ b/src/net/ea/charserverhandler.h @@ -25,9 +25,6 @@ #include "net/messagehandler.h" #include "net/charhandler.h" -#include "lockedarray.h" - -class LocalPlayer; class LoginData; namespace EAthena { @@ -45,9 +42,6 @@ class CharServerHandler : public MessageHandler, public Net::CharHandler void setCharInfo(LockedArray<LocalPlayer*> *charInfo) { mCharInfo = charInfo; } - void setLoginData(LoginData *loginData) - { mLoginData = loginData; } - /** * Sets the character create dialog. The handler will clean up this * dialog when a new character is succesfully created, and will unlock @@ -55,6 +49,8 @@ class CharServerHandler : public MessageHandler, public Net::CharHandler */ void setCharCreateDialog(CharCreateDialog *window); + void connect(LoginData *loginData); + void chooseCharacter(int slot, LocalPlayer* character); void newCharacter(const std::string &name, int slot, bool gender, diff --git a/src/net/ea/chathandler.cpp b/src/net/ea/chathandler.cpp index 13593ed1..997881f8 100644 --- a/src/net/ea/chathandler.cpp +++ b/src/net/ea/chathandler.cpp @@ -148,7 +148,7 @@ void ChatHandler::handleMessage(MessageIn &msg) if (msg.getId() == SMSG_PLAYER_CHAT) { - localChatTab->chatLog(chatMsg, BY_PLAYER); + if (localChatTab) localChatTab->chatLog(chatMsg, BY_PLAYER); if (pos != std::string::npos) chatMsg.erase(0, pos + 3); diff --git a/src/net/ea/generalhandler.cpp b/src/net/ea/generalhandler.cpp new file mode 100644 index 00000000..5d204ab5 --- /dev/null +++ b/src/net/ea/generalhandler.cpp @@ -0,0 +1,164 @@ +/* + * The Mana World + * Copyright (C) 2009 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/generalhandler.h" + +#include "net/ea/network.h" +#include "net/ea/protocol.h" + +#include "net/ea/adminhandler.h" +#include "net/ea/beinghandler.h" +#include "net/ea/buysellhandler.h" +#include "net/ea/chathandler.h" +#include "net/ea/charserverhandler.h" +#include "net/ea/equipmenthandler.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" +#include "net/ea/tradehandler.h" +#include "net/ea/skillhandler.h" + +#include "net/ea/gui/partytab.h" + +#include "net/messagein.h" +#include "net/messageout.h" + +#include "configuration.h" +#include "log.h" +#include "main.h" + +#include "utils/gettext.h" + +Net::GeneralHandler *generalHandler; + +namespace EAthena { + +GeneralHandler::GeneralHandler(): + mAdminHandler(new AdminHandler), + mBeingHandler(new BeingHandler(config.getValue("EnableSync", 0) == 1)), + mBuySellHandler(new BuySellHandler), + mCharHandler(new CharServerHandler), + mChatHandler(new ChatHandler), + mEquipmentHandler(new EquipmentHandler), + mInventoryHandler(new InventoryHandler), + mItemHandler(new ItemHandler), + mLoginHandler(new LoginHandler), + mLogoutHandler(new LogoutHandler), + mMapHandler(new MapHandler), + mNpcHandler(new NpcHandler), + mPartyHandler(new PartyHandler), + mPlayerHandler(new PlayerHandler), + mSkillHandler(new SkillHandler), + mTradeHandler(new TradeHandler) +{ + static const Uint16 _messages[] = { + SMSG_CONNECTION_PROBLEM, + 0 + }; + handledMessages = _messages; + generalHandler = this; +} + +void GeneralHandler::handleMessage(MessageIn &msg) +{ + int code; + unsigned char direction; + + switch (msg.getId()) + { + case SMSG_CONNECTION_PROBLEM: + code = msg.readInt8(); + logger->log("Connection problem: %i", code); + + switch (code) { + case 0: + errorMessage = _("Authentication failed"); + break; + case 1: + errorMessage = _("No servers available"); + break; + case 2: + errorMessage = _("This account is already logged in"); + break; + case 3: + errorMessage = _("Speed hack detected"); + break; + case 8: + errorMessage = _("Duplicated login"); + break; + default: + errorMessage = _("Unknown connection error"); + break; + } + state = STATE_ERROR; + break; + } +} + +void GeneralHandler::load() +{ + 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(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(mSkillHandler.get()); + mNetwork->registerHandler(mTradeHandler.get()); + mNetwork->registerHandler(mPartyHandler.get()); +} + +void GeneralHandler::unload() +{ + mNetwork->clearHandlers(); + + delete partyTab; +} + +void GeneralHandler::flushNetwork() +{ + mNetwork->flush(); + mNetwork->dispatchMessages(); +} + +bool GeneralHandler::isNetworkConnected() +{ + return mNetwork->isConnected(); +} + +void GeneralHandler::guiWindowsLoaded() +{ + partyTab = new PartyTab(); +} + +} // namespace EAthena diff --git a/src/net/ea/generalhandler.h b/src/net/ea/generalhandler.h new file mode 100644 index 00000000..3e2a6707 --- /dev/null +++ b/src/net/ea/generalhandler.h @@ -0,0 +1,69 @@ +/* + * The Mana World + * Copyright (C) 2009 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_GENERALHANDLER_H +#define NET_EA_GENERALHANDLER_H + +#include "net/generalhandler.h" +#include "net/messagehandler.h" +#include "net/net.h" + +namespace EAthena { + +class GeneralHandler : public MessageHandler, public Net::GeneralHandler +{ + public: + GeneralHandler(); + + void handleMessage(MessageIn &msg); + + void load(); + + void unload(); + + void flushNetwork(); + + bool isNetworkConnected(); + + void guiWindowsLoaded(); + + protected: + MessageHandlerPtr mAdminHandler; + MessageHandlerPtr mBeingHandler; + MessageHandlerPtr mBuySellHandler; + MessageHandlerPtr mCharHandler; + MessageHandlerPtr mChatHandler; + MessageHandlerPtr mEquipmentHandler; + MessageHandlerPtr mInventoryHandler; + MessageHandlerPtr mItemHandler; + MessageHandlerPtr mLoginHandler; + MessageHandlerPtr mLogoutHandler; + MessageHandlerPtr mMapHandler; + MessageHandlerPtr mNpcHandler; + MessageHandlerPtr mPartyHandler; + MessageHandlerPtr mPlayerHandler; + MessageHandlerPtr mSkillHandler; + MessageHandlerPtr mTradeHandler; +}; + +} // namespace EAthena + +#endif // NET_EA_GENERALHANDLER_H diff --git a/src/net/ea/loginhandler.cpp b/src/net/ea/loginhandler.cpp index 06bdb4bc..1031ee05 100644 --- a/src/net/ea/loginhandler.cpp +++ b/src/net/ea/loginhandler.cpp @@ -24,6 +24,7 @@ #include "net/ea/protocol.h" #include "net/messagein.h" +#include "net/messageout.h" #include "log.h" #include "logindata.h" @@ -36,16 +37,20 @@ extern SERVER_INFO **server_info; +Net::LoginHandler *loginHandler; + +namespace EAthena { + LoginHandler::LoginHandler() { static const Uint16 _messages[] = { - SMSG_CONNECTION_PROBLEM, SMSG_UPDATE_HOST, 0x0069, 0x006a, 0 }; handledMessages = _messages; + loginHandler = this; } void LoginHandler::handleMessage(MessageIn &msg) @@ -54,27 +59,6 @@ void LoginHandler::handleMessage(MessageIn &msg) switch (msg.getId()) { - case SMSG_CONNECTION_PROBLEM: - code = msg.readInt8(); - logger->log("Connection problem: %i", code); - - switch (code) { - case 0: - errorMessage = _("Authentication failed"); - break; - case 1: - errorMessage = _("No servers available"); - break; - case 2: - errorMessage = _("This account is already logged in"); - break; - default: - errorMessage = _("Unknown connection error"); - break; - } - state = STATE_ERROR; - break; - case SMSG_UPDATE_HOST: int len; @@ -158,3 +142,52 @@ void LoginHandler::handleMessage(MessageIn &msg) break; } } + +void LoginHandler::loginAccount(LoginData *loginData) +{ + mLoginData = loginData; + MessageOut outMsg(0x0064); + outMsg.writeInt32(0); // client version + outMsg.writeString(loginData->username, 24); + outMsg.writeString(loginData->password, 24); + + /* + * eAthena calls the last byte "client version 2", but it isn't used at + * at all. We're retasking it, with bit 0 to indicate whether the client + * can handle the 0x63 "update host" packet. Clients prior to 0.0.25 send + * 0 here. + */ + outMsg.writeInt8(0x01); +} + +void LoginHandler::changeEmail(const std::string &email) +{ + // TODO +} + +void LoginHandler::changePassword(const std::string &username, + const std::string &oldPassword, + const std::string &newPassword) +{ + // TODO +} + +void LoginHandler::chooseServer(int server) +{ + // TODO +} + +void LoginHandler::registerAccount(const std::string &username, + const std::string &password, + const std::string &email = "") +{ + // TODO +} + +void LoginHandler::unregisterAccount(const std::string &username, + const std::string &password) +{ + // TODO +} + +} // namespace EAthena diff --git a/src/net/ea/loginhandler.h b/src/net/ea/loginhandler.h index 9afaab23..cdc59e4a 100644 --- a/src/net/ea/loginhandler.h +++ b/src/net/ea/loginhandler.h @@ -22,24 +22,44 @@ #ifndef NET_EA_LOGINHANDLER_H #define NET_EA_LOGINHANDLER_H +#include "net/loginhandler.h" #include "net/messagehandler.h" #include <string> struct LoginData; -class LoginHandler : public MessageHandler +namespace EAthena { + +class LoginHandler : public MessageHandler, public Net::LoginHandler { public: LoginHandler(); - virtual void handleMessage(MessageIn &msg); + void handleMessage(MessageIn &msg); + + void loginAccount(LoginData *loginData); + + void changeEmail(const std::string &email); + + void changePassword(const std::string &username, + const std::string &oldPassword, + const std::string &newPassword); - void setLoginData(LoginData *loginData) { mLoginData = loginData; } + void chooseServer(int server); + + void registerAccount(const std::string &username, + const std::string &password, + const std::string &email); + + void unregisterAccount(const std::string &username, + const std::string &password); private: LoginData *mLoginData; std::string mUpdateHost; }; +} // namespace EAthena + #endif // NET_EA_LOGINHANDLER_H diff --git a/src/net/ea/logouthandler.cpp b/src/net/ea/logouthandler.cpp new file mode 100644 index 00000000..19659a2f --- /dev/null +++ b/src/net/ea/logouthandler.cpp @@ -0,0 +1,66 @@ +/* + * 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/messagein.h" +#include "net/messageout.h" + +#include "log.h" +#include "logindata.h" +#include "main.h" +#include "serverinfo.h" + +#include "utils/gettext.h" +#include "utils/strprintf.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 new file mode 100644 index 00000000..0d118ab0 --- /dev/null +++ b/src/net/ea/logouthandler.h @@ -0,0 +1,47 @@ +/* + * 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/maphandler.cpp b/src/net/ea/maphandler.cpp index 6912176f..6fd27755 100644 --- a/src/net/ea/maphandler.cpp +++ b/src/net/ea/maphandler.cpp @@ -21,6 +21,7 @@ #include "net/ea/maphandler.h" +#include "net/ea/network.h" #include "net/ea/protocol.h" #include "net/messagein.h" @@ -42,7 +43,6 @@ namespace EAthena { MapHandler::MapHandler() { static const Uint16 _messages[] = { - SMSG_CONNECTION_PROBLEM, SMSG_LOGIN_SUCCESS, SMSG_SERVER_PING, SMSG_WHO_ANSWER, @@ -59,24 +59,6 @@ void MapHandler::handleMessage(MessageIn &msg) switch (msg.getId()) { - case SMSG_CONNECTION_PROBLEM: - code = msg.readInt8(); - logger->log("Connection problem: %i", code); - - switch (code) { - case 0: - errorMessage = _("Authentication failed"); - break; - case 2: - errorMessage = _("This account is already logged in"); - break; - default: - errorMessage = _("Unknown connection error"); - break; - } - state = STATE_ERROR; - break; - case SMSG_LOGIN_SUCCESS: msg.readInt32(); // server tick msg.readCoordinates(player_node->mX, player_node->mY, direction); @@ -107,6 +89,9 @@ void MapHandler::connect(LoginData *loginData) outMsg.writeInt32(loginData->session_ID1); outMsg.writeInt32(loginData->session_ID2); outMsg.writeInt8(loginData->sex); + + // We get 4 useless bytes before the real answer comes in (what are these?) + mNetwork->skip(4); } void MapHandler::mapLoaded(const std::string &mapName) diff --git a/src/net/generalhandler.h b/src/net/generalhandler.h index 573e5062..08c08b13 100644 --- a/src/net/generalhandler.h +++ b/src/net/generalhandler.h @@ -26,11 +26,15 @@ namespace Net { class GeneralHandler { public: - virtual void load() {} + virtual void load() = 0; - virtual void unload() {} + virtual void unload() = 0; - virtual void guiWindowsLoaded() {} + virtual void flushNetwork() = 0; + + virtual bool isNetworkConnected() = 0; + + virtual void guiWindowsLoaded() = 0; }; } diff --git a/src/net/loginhandler.h b/src/net/loginhandler.h index 19f8c90b..fcdee0da 100644 --- a/src/net/loginhandler.h +++ b/src/net/loginhandler.h @@ -22,29 +22,30 @@ #ifndef LOGINHANDLER_H #define LOGINHANDLER_H +#include "logindata.h" + #include <iosfwd> namespace Net { class LoginHandler { public: - virtual void loginAccount(const std::string &username, - const std::string &password) {} + virtual void loginAccount(LoginData *loginData) = 0; - virtual void changeEmail(const std::string &email) {} + virtual void changeEmail(const std::string &email) = 0; virtual void changePassword(const std::string &username, const std::string &oldPassword, - const std::string &newPassword) {} + const std::string &newPassword) = 0; - virtual void chooseServer(int server) {} + virtual void chooseServer(int server) = 0; virtual void registerAccount(const std::string &username, const std::string &password, - const std::string &email = "") {} + const std::string &email) = 0; virtual void unregisterAccount(const std::string &username, - const std::string &password) {} + const std::string &password) = 0; }; } diff --git a/src/net/logouthandler.h b/src/net/logouthandler.h new file mode 100644 index 00000000..f6c44e5c --- /dev/null +++ b/src/net/logouthandler.h @@ -0,0 +1,49 @@ +/* + * The Mana World + * Copyright (C) 2009 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 LOGOUTHANDLER_H +#define LOGOUTHANDLER_H + +#include "logindata.h" + +#include <iosfwd> + +/** + * The different scenarios for which LogoutHandler can be used + */ +enum { + LOGOUT_EXIT, + LOGOUT_SWITCH_LOGIN, + LOGOUT_SWITCH_CHARACTER +}; + +namespace Net { +class LogoutHandler +{ + public: + virtual void setScenario(unsigned short scenario, + std::string *passToken = NULL) = 0; + + virtual void reset() = 0; +}; +} + +#endif // LOGOUTHANDLER_H diff --git a/src/net/messagehandler.h b/src/net/messagehandler.h index 9b207dcc..1aa0b401 100644 --- a/src/net/messagehandler.h +++ b/src/net/messagehandler.h @@ -24,6 +24,8 @@ #include <SDL_types.h> +#include <memory> + class MessageIn; #ifdef EATHENA_SUPPORT class Network; @@ -42,7 +44,8 @@ class MessageHandler virtual void handleMessage(MessageIn &msg) = 0; -#ifdef EATHENA_SUPPORT +#ifdef TMWSERV_SUPPORT +#else void setNetwork(Network *network); protected: @@ -50,4 +53,6 @@ class MessageHandler #endif }; +typedef const std::auto_ptr<MessageHandler> MessageHandlerPtr; + #endif // NET_MESSAGEHANDLER_H diff --git a/src/net/net.cpp b/src/net/net.cpp index 5c36f4e1..a8aeae47 100644 --- a/src/net/net.cpp +++ b/src/net/net.cpp @@ -28,6 +28,7 @@ #include "net/guildhandler.h" #include "net/inventoryhandler.h" #include "net/loginhandler.h" +#include "net/logouthandler.h" #include "net/maphandler.h" #include "net/npchandler.h" #include "net/partyhandler.h" @@ -38,7 +39,10 @@ extern Net::AdminHandler *adminHandler; extern Net::CharHandler *charHandler; extern Net::ChatHandler *chatHandler; +extern Net::GeneralHandler *generalHandler; extern Net::InventoryHandler *inventoryHandler; +extern Net::LoginHandler *loginHandler; +extern Net::LogoutHandler *logoutHandler; extern Net::MapHandler *mapHandler; extern Net::NpcHandler *npcHandler; extern Net::PlayerHandler *playerHandler; @@ -62,8 +66,7 @@ Net::ChatHandler *Net::getChatHandler() Net::GeneralHandler *Net::getGeneralHandler() { - // TODO - return 0; + return generalHandler; } Net::GuildHandler *Net::getGuildHandler() @@ -79,8 +82,12 @@ Net::InventoryHandler *Net::getInventoryHandler() Net::LoginHandler *Net::getLoginHandler() { - // TODO - return 0; + return loginHandler; +} + +Net::LogoutHandler *Net::getLogoutHandler() +{ + return logoutHandler; } Net::MapHandler *Net::getMapHandler() diff --git a/src/net/net.h b/src/net/net.h index 75ee3aed..9154c1ef 100644 --- a/src/net/net.h +++ b/src/net/net.h @@ -31,6 +31,7 @@ class GeneralHandler; class GuildHandler; class InventoryHandler; class LoginHandler; +class LogoutHandler; class MapHandler; class NpcHandler; class PartyHandler; @@ -45,6 +46,7 @@ GeneralHandler *getGeneralHandler(); GuildHandler *getGuildHandler(); InventoryHandler *getInventoryHandler(); LoginHandler *getLoginHandler(); +LogoutHandler *getLogoutHandler(); MapHandler *getMapHandler(); NpcHandler *getNpcHandler(); PartyHandler *getPartyHandler(); diff --git a/src/net/tmwserv/charserverhandler.cpp b/src/net/tmwserv/charserverhandler.cpp index 9739367b..27ac62fb 100644 --- a/src/net/tmwserv/charserverhandler.cpp +++ b/src/net/tmwserv/charserverhandler.cpp @@ -254,6 +254,11 @@ void CharServerHandler::setCharCreateDialog(CharCreateDialog *window) mCharCreateDialog->setAttributes(attributes, 60, 1, 20); } +void connect(LoginData *loginData) +{ + // Uneeded +} + void CharServerHandler::chooseCharacter(int slot, LocalPlayer* character) { Net::AccountServer::Account::selectCharacter(slot); diff --git a/src/net/tmwserv/charserverhandler.h b/src/net/tmwserv/charserverhandler.h index a5e1fa50..4d79d60e 100644 --- a/src/net/tmwserv/charserverhandler.h +++ b/src/net/tmwserv/charserverhandler.h @@ -25,9 +25,6 @@ #include "net/charhandler.h" #include "net/messagehandler.h" -#include "lockedarray.h" - -class LocalPlayer; class LoginData; namespace TmwServ { @@ -54,6 +51,8 @@ class CharServerHandler : public MessageHandler, public Net::CharHandler */ void setCharCreateDialog(CharCreateDialog *window); + void connect(LoginData *loginData) {} // Unused + void chooseCharacter(int slot, LocalPlayer* character); void newCharacter(const std::string &name, int slot, diff --git a/src/net/tmwserv/generalhandler.cpp b/src/net/tmwserv/generalhandler.cpp new file mode 100644 index 00000000..c5f00624 --- /dev/null +++ b/src/net/tmwserv/generalhandler.cpp @@ -0,0 +1,126 @@ +/* + * The Mana World + * Copyright (C) 2009 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/tmwserv/generalhandler.h" + +#include "net/tmwserv/network.h" +#include "net/tmwserv/connection.h" + +#include "net/tmwserv/beinghandler.h" +#include "net/tmwserv/buysellhandler.h" +#include "net/tmwserv/charserverhandler.h" +#include "net/tmwserv/chathandler.h" +#include "net/tmwserv/effecthandler.h" +#include "net/tmwserv/guildhandler.h" +#include "net/tmwserv/inventoryhandler.h" +#include "net/tmwserv/itemhandler.h" +#include "net/tmwserv/loginhandler.h" +#include "net/tmwserv/logouthandler.h" +#include "net/tmwserv/maphandler.h" +#include "net/tmwserv/npchandler.h" +#include "net/tmwserv/partyhandler.h" +#include "net/tmwserv/playerhandler.h" +#include "net/tmwserv/tradehandler.h" + +Net::GeneralHandler *generalHandler; + +Net::Connection *gameServerConnection = 0; +Net::Connection *chatServerConnection = 0; +Net::Connection *accountServerConnection = 0; + +namespace TmwServ { + +GeneralHandler::GeneralHandler(): + mBeingHandler(new BeingHandler), + mBuySellHandler(new BuySellHandler), + mCharServerHandler(new TmwServ::CharServerHandler), + mChatHandler(new TmwServ::ChatHandler), + mEffectHandler(new EffectHandler), + mGuildHandler(new GuildHandler), + mInventoryHandler(new TmwServ::InventoryHandler), + mItemHandler(new ItemHandler), + mLoginHandler(new TmwServ::LoginHandler), + mLogoutHandler(new LogoutHandler), + mMapHandler(new TmwServ::MapHandler), + mNpcHandler(new TmwServ::NpcHandler), + mPartyHandler(new PartyHandler), + mPlayerHandler(new TmwServ::PlayerHandler), + mTradeHandler(new TmwServ::TradeHandler) +{ + accountServerConnection = Net::getConnection(); + gameServerConnection = Net::getConnection(); + chatServerConnection = Net::getConnection(); + + generalHandler = this; +} + +void GeneralHandler::load() +{ + Net::registerHandler(mBeingHandler.get()); + Net::registerHandler(mBuySellHandler.get()); + Net::registerHandler(mCharServerHandler.get()); + Net::registerHandler(mChatHandler.get()); + Net::registerHandler(mEffectHandler.get()); + Net::registerHandler(mGuildHandler.get()); + Net::registerHandler(mInventoryHandler.get()); + Net::registerHandler(mItemHandler.get()); + Net::registerHandler(mLoginHandler.get()); + Net::registerHandler(mLogoutHandler.get()); + Net::registerHandler(mMapHandler.get()); + Net::registerHandler(mNpcHandler.get()); + Net::registerHandler(mPartyHandler.get()); + Net::registerHandler(mPlayerHandler.get()); + Net::registerHandler(mTradeHandler.get()); +} + +void GeneralHandler::unload() +{ + if (accountServerConnection) + accountServerConnection->disconnect(); + if (gameServerConnection) + gameServerConnection->disconnect(); + if (chatServerConnection) + chatServerConnection->disconnect(); + + delete accountServerConnection; + delete gameServerConnection; + delete chatServerConnection; + + Net::finalize(); +} + +void GeneralHandler::flushNetwork() +{ + Net::flush(); +} + +bool GeneralHandler::isNetworkConnected() +{ + // TODO + return true; +} + +void GeneralHandler::guiWindowsLoaded() +{ + // TODO +} + +} // namespace TmwServ diff --git a/src/net/tmwserv/generalhandler.h b/src/net/tmwserv/generalhandler.h new file mode 100644 index 00000000..81a41608 --- /dev/null +++ b/src/net/tmwserv/generalhandler.h @@ -0,0 +1,66 @@ +/* + * The Mana World + * Copyright (C) 2009 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_TMWSERV_GENERALHANDLER_H +#define NET_TMWSERV_GENERALHANDLER_H + +#include "net/generalhandler.h" +#include "net/net.h" +#include "net/messagehandler.h" + +namespace TmwServ { + +class GeneralHandler : public Net::GeneralHandler +{ + public: + GeneralHandler(); + + void load(); + + void unload(); + + void flushNetwork(); + + bool isNetworkConnected(); + + void guiWindowsLoaded(); + + protected: + MessageHandlerPtr mBeingHandler; + MessageHandlerPtr mBuySellHandler; + MessageHandlerPtr mCharServerHandler; + MessageHandlerPtr mChatHandler; + MessageHandlerPtr mEffectHandler; + MessageHandlerPtr mGuildHandler; + MessageHandlerPtr mInventoryHandler; + MessageHandlerPtr mItemHandler; + MessageHandlerPtr mLoginHandler; + MessageHandlerPtr mLogoutHandler; + MessageHandlerPtr mMapHandler; + MessageHandlerPtr mNpcHandler; + MessageHandlerPtr mPartyHandler; + MessageHandlerPtr mPlayerHandler; + MessageHandlerPtr mTradeHandler; +}; + +} // namespace TmwServ + +#endif // NET_TMWSERV_GENERALHANDLER_H diff --git a/src/net/tmwserv/loginhandler.cpp b/src/net/tmwserv/loginhandler.cpp index ccba06ed..ef23546a 100644 --- a/src/net/tmwserv/loginhandler.cpp +++ b/src/net/tmwserv/loginhandler.cpp @@ -21,13 +21,23 @@ #include "net/tmwserv/loginhandler.h" +#include "net/tmwserv/connection.h" #include "net/tmwserv/protocol.h" +#include "net/tmwserv/accountserver/account.h" +#include "net/tmwserv/accountserver/accountserver.h" + #include "net/messagein.h" #include "logindata.h" #include "main.h" +Net::LoginHandler *loginHandler; + +extern Net::Connection *accountServerConnection; + +namespace TmwServ { + LoginHandler::LoginHandler() { static const Uint16 _messages[] = { @@ -39,11 +49,7 @@ LoginHandler::LoginHandler() 0 }; handledMessages = _messages; -} - -void LoginHandler::setLoginData(LoginData *loginData) -{ - mLoginData = loginData; + loginHandler = this; } void LoginHandler::handleMessage(MessageIn &msg) @@ -224,3 +230,46 @@ void LoginHandler::readUpdateHost(MessageIn &msg) mLoginData->updateHost = msg.readString(); } } + +void LoginHandler::loginAccount(LoginData *loginData) +{ + mLoginData = loginData; + Net::AccountServer::login(accountServerConnection, + 0, // client version + loginData->username, + loginData->password); +} + +void LoginHandler::changeEmail(const std::string &email) +{ + Net::AccountServer::Account::changeEmail(email); +} + +void LoginHandler::changePassword(const std::string &username, + const std::string &oldPassword, + const std::string &newPassword) +{ + Net::AccountServer::Account::changePassword(username, oldPassword, + newPassword); +} + +void LoginHandler::chooseServer(int server) +{ + // TODO +} + +void LoginHandler::registerAccount(const std::string &username, + const std::string &password, const std::string &email) +{ + Net::AccountServer::registerAccount(accountServerConnection, + 0, // client version + username, password, email); +} + +void LoginHandler::unregisterAccount(const std::string &username, + const std::string &password) +{ + Net::AccountServer::Account::unregister(username, password); +} + +} // namespace TmwServ diff --git a/src/net/tmwserv/loginhandler.h b/src/net/tmwserv/loginhandler.h index 81dd273c..93d55396 100644 --- a/src/net/tmwserv/loginhandler.h +++ b/src/net/tmwserv/loginhandler.h @@ -22,19 +22,37 @@ #ifndef NET_TMWSERV_LOGINHANDLER_H #define NET_TMWSERV_LOGINHANDLER_H +#include "net/loginhandler.h" #include "net/messagehandler.h" class LoginData; -class LoginHandler : public MessageHandler +namespace TmwServ { + +class LoginHandler : public MessageHandler, public Net::LoginHandler { public: LoginHandler(); - void setLoginData(LoginData *loginData); - void handleMessage(MessageIn &msg); + void loginAccount(LoginData *loginData); + + void changeEmail(const std::string &email); + + void changePassword(const std::string &username, + const std::string &oldPassword, + const std::string &newPassword); + + void chooseServer(int server); + + void registerAccount(const std::string &username, + const std::string &password, + const std::string &email); + + void unregisterAccount(const std::string &username, + const std::string &password); + private: void handleLoginResponse(MessageIn &msg); void handleRegisterResponse(MessageIn &msg); @@ -44,4 +62,6 @@ class LoginHandler : public MessageHandler LoginData *mLoginData; }; +} // namespace TmwServ + #endif // NET_TMWSERV_LOGINHANDLER_H diff --git a/src/net/tmwserv/logouthandler.cpp b/src/net/tmwserv/logouthandler.cpp index 8b0e2d6e..9ac6c7d4 100644 --- a/src/net/tmwserv/logouthandler.cpp +++ b/src/net/tmwserv/logouthandler.cpp @@ -21,12 +21,25 @@ #include "net/tmwserv/logouthandler.h" +#include "net/tmwserv/connection.h" #include "net/tmwserv/protocol.h" +#include "net/tmwserv/accountserver/accountserver.h" +#include "net/tmwserv/chatserver/chatserver.h" +#include "net/tmwserv/gameserver/gameserver.h" + #include "net/messagein.h" #include "main.h" +Net::LogoutHandler *logoutHandler; + +extern Net::Connection *gameServerConnection; +extern Net::Connection *chatServerConnection; +extern Net::Connection *accountServerConnection; + +namespace TmwServ { + LogoutHandler::LogoutHandler(): mPassToken(NULL), mScenario(LOGOUT_EXIT), @@ -42,6 +55,7 @@ LogoutHandler::LogoutHandler(): 0 }; handledMessages = _messages; + logoutHandler = this; } void LogoutHandler::handleMessage(MessageIn &msg) @@ -59,7 +73,7 @@ void LogoutHandler::handleMessage(MessageIn &msg) switch (mScenario) { - case LOGOUT_SWITCH_ACCOUNTSERVER: + case LOGOUT_SWITCH_LOGIN: if (mLoggedOutGame && mLoggedOutChat) state = STATE_SWITCH_ACCOUNTSERVER; break; @@ -129,7 +143,7 @@ void LogoutHandler::handleMessage(MessageIn &msg) if (mLoggedOutChat) state = STATE_RECONNECT_ACCOUNT; break; - case LOGOUT_SWITCH_ACCOUNTSERVER: + case LOGOUT_SWITCH_LOGIN: if (mLoggedOutAccount && mLoggedOutChat) state = STATE_SWITCH_ACCOUNTSERVER; break; @@ -170,7 +184,7 @@ void LogoutHandler::handleMessage(MessageIn &msg) if (mLoggedOutGame) state = STATE_RECONNECT_ACCOUNT; break; - case LOGOUT_SWITCH_ACCOUNTSERVER: + case LOGOUT_SWITCH_LOGIN: if (mLoggedOutAccount && mLoggedOutGame) state = STATE_SWITCH_ACCOUNTSERVER; break; @@ -206,6 +220,47 @@ void LogoutHandler::setScenario(unsigned short scenario, { mScenario = scenario; mPassToken = passToken; + + // Can't logout if we were not logged in ... + if (mScenario == LOGOUT_EXIT) + { + if (accountServerConnection->isConnected()) + Net::AccountServer::logout(); + else + setAccountLoggedOut(); + + if (gameServerConnection->isConnected()) + Net::GameServer::logout(false); + else + setGameLoggedOut(); + + if (chatServerConnection->isConnected()) + Net::ChatServer::logout(); + else + setChatLoggedOut(); + } + else if (mScenario == LOGOUT_SWITCH_LOGIN) + { + if (accountServerConnection->isConnected()) + Net::AccountServer::logout(); + else + setAccountLoggedOut(); + + if (gameServerConnection->isConnected()) + Net::GameServer::logout(false); + else + setGameLoggedOut(); + + if (chatServerConnection->isConnected()) + Net::ChatServer::logout(); + else + setChatLoggedOut(); + } + else if (mScenario == LOGOUT_SWITCH_CHARACTER) + { + Net::GameServer::logout(true); + Net::ChatServer::logout(); + } } void LogoutHandler::reset() @@ -216,3 +271,5 @@ void LogoutHandler::reset() mLoggedOutGame = false; mLoggedOutChat = false; } + +} // namespace TmwServ diff --git a/src/net/tmwserv/logouthandler.h b/src/net/tmwserv/logouthandler.h index 6c69c8be..19b6d43a 100644 --- a/src/net/tmwserv/logouthandler.h +++ b/src/net/tmwserv/logouthandler.h @@ -22,20 +22,14 @@ #ifndef NET_TMWSERV_LOGOUTHANDLER_H #define NET_TMWSERV_LOGOUTHANDLER_H +#include "net/logouthandler.h" #include "net/messagehandler.h" #include <string> -/** - * The different scenarios for which LogoutHandler can be used - */ -enum { - LOGOUT_EXIT, - LOGOUT_SWITCH_ACCOUNTSERVER, - LOGOUT_SWITCH_CHARACTER -}; +namespace TmwServ { -class LogoutHandler : public MessageHandler +class LogoutHandler : public MessageHandler, public Net::LogoutHandler { public: LogoutHandler(); @@ -59,4 +53,6 @@ class LogoutHandler : public MessageHandler bool mLoggedOutChat; }; +} // namespace TmwServ + #endif diff --git a/src/net/tmwserv/maphandler.cpp b/src/net/tmwserv/maphandler.cpp index bbdb873e..ff47c1a7 100644 --- a/src/net/tmwserv/maphandler.cpp +++ b/src/net/tmwserv/maphandler.cpp @@ -30,6 +30,10 @@ MapHandler::MapHandler() mapHandler = this; } +void MapHandler::handleMessage(MessageIn &msg) +{ +} + void MapHandler::connect(LoginData *loginData) { // TODO diff --git a/src/net/tmwserv/maphandler.h b/src/net/tmwserv/maphandler.h index 649feda6..099ec7e0 100644 --- a/src/net/tmwserv/maphandler.h +++ b/src/net/tmwserv/maphandler.h @@ -23,14 +23,17 @@ #define NET_TMWSERV_MAPHANDLER_H #include "net/maphandler.h" +#include "net/messagehandler.h" namespace TmwServ { -class MapHandler : public Net::MapHandler +class MapHandler : public MessageHandler, public Net::MapHandler { public: MapHandler(); + void handleMessage(MessageIn &msg); + void connect(LoginData *loginData); void mapLoaded(const std::string &mapName); |