summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt7
-rw-r--r--src/Makefile.am7
-rw-r--r--src/game.cpp88
-rw-r--r--src/game.h36
-rw-r--r--src/main.cpp214
-rw-r--r--src/net/charhandler.h7
-rw-r--r--src/net/ea/charserverhandler.cpp46
-rw-r--r--src/net/ea/charserverhandler.h8
-rw-r--r--src/net/ea/chathandler.cpp2
-rw-r--r--src/net/ea/generalhandler.cpp164
-rw-r--r--src/net/ea/generalhandler.h69
-rw-r--r--src/net/ea/loginhandler.cpp77
-rw-r--r--src/net/ea/loginhandler.h26
-rw-r--r--src/net/ea/logouthandler.cpp66
-rw-r--r--src/net/ea/logouthandler.h47
-rw-r--r--src/net/ea/maphandler.cpp23
-rw-r--r--src/net/generalhandler.h10
-rw-r--r--src/net/loginhandler.h15
-rw-r--r--src/net/logouthandler.h49
-rw-r--r--src/net/messagehandler.h7
-rw-r--r--src/net/net.cpp15
-rw-r--r--src/net/net.h2
-rw-r--r--src/net/tmwserv/charserverhandler.cpp5
-rw-r--r--src/net/tmwserv/charserverhandler.h5
-rw-r--r--src/net/tmwserv/generalhandler.cpp126
-rw-r--r--src/net/tmwserv/generalhandler.h66
-rw-r--r--src/net/tmwserv/loginhandler.cpp59
-rw-r--r--src/net/tmwserv/loginhandler.h26
-rw-r--r--src/net/tmwserv/logouthandler.cpp63
-rw-r--r--src/net/tmwserv/logouthandler.h14
-rw-r--r--src/net/tmwserv/maphandler.cpp4
-rw-r--r--src/net/tmwserv/maphandler.h5
32 files changed, 959 insertions, 399 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index a3356fd2..ce8880de 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -241,6 +241,7 @@ SET(SRCS
net/guildhandler.h
net/inventoryhandler.h
net/loginhandler.h
+ net/logouthandler.h
net/maphandler.h
net/messagehandler.cpp
net/messagehandler.h
@@ -433,12 +434,16 @@ SET(SRCS_EA
net/ea/chathandler.h
net/ea/equipmenthandler.cpp
net/ea/equipmenthandler.h
+ net/ea/generalhandler.cpp
+ net/ea/generalhandler.h
net/ea/inventoryhandler.cpp
net/ea/inventoryhandler.h
net/ea/itemhandler.cpp
net/ea/itemhandler.h
net/ea/loginhandler.cpp
net/ea/loginhandler.h
+ net/ea/logouthandler.cpp
+ net/ea/logouthandler.h
net/ea/maphandler.cpp
net/ea/maphandler.h
net/ea/network.cpp
@@ -518,6 +523,8 @@ SET(SRCS_TMW
net/tmwserv/connection.h
net/tmwserv/effecthandler.cpp
net/tmwserv/effecthandler.h
+ net/tmwserv/generalhandler.cpp
+ net/tmwserv/generalhandler.h
net/tmwserv/guildhandler.cpp
net/tmwserv/guildhandler.h
net/tmwserv/internal.cpp
diff --git a/src/Makefile.am b/src/Makefile.am
index ec767317..12f20620 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -189,6 +189,7 @@ tmw_SOURCES = gui/widgets/avatar.cpp \
net/guildhandler.h \
net/inventoryhandler.h \
net/loginhandler.h \
+ net/logouthandler.h \
net/maphandler.h \
net/messagehandler.cpp \
net/messagehandler.h \
@@ -420,6 +421,8 @@ tmw_SOURCES += \
net/tmwserv/connection.h \
net/tmwserv/effecthandler.cpp \
net/tmwserv/effecthandler.h \
+ net/tmwserv/generalhandler.cpp \
+ net/tmwserv/generalhandler.h \
net/tmwserv/guildhandler.cpp \
net/tmwserv/guildhandler.h \
net/tmwserv/internal.cpp \
@@ -476,12 +479,16 @@ tmw_SOURCES += \
net/ea/chathandler.h \
net/ea/equipmenthandler.cpp \
net/ea/equipmenthandler.h \
+ net/ea/generalhandler.cpp \
+ net/ea/generalhandler.h \
net/ea/inventoryhandler.cpp \
net/ea/inventoryhandler.h \
net/ea/itemhandler.cpp \
net/ea/itemhandler.h \
net/ea/loginhandler.cpp \
net/ea/loginhandler.h \
+ net/ea/logouthandler.cpp \
+ net/ea/logouthandler.h \
net/ea/maphandler.cpp \
net/ea/maphandler.h \
net/ea/network.cpp \
diff --git a/src/game.cpp b/src/game.cpp
index a181fc2a..71e22dca 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -85,6 +85,7 @@
#include "gui/storagewindow.h"
#endif
+#include "net/generalhandler.h"
#include "net/maphandler.h"
#include "net/net.h"
@@ -104,7 +105,6 @@
#include "net/tmwserv/guildhandler.h"
#include "net/tmwserv/partyhandler.h"
#else
-#include "net/ea/gui/partytab.h"
#include "net/ea/adminhandler.h"
#include "net/ea/chathandler.h"
#include "net/ea/beinghandler.h"
@@ -311,6 +311,8 @@ static void createGuiWindows()
{
logger->setChatWindow(chatWindow);
}
+
+ Net::getGeneralHandler()->guiWindowsLoaded();
}
/**
@@ -355,38 +357,7 @@ static void destroyGuiWindows()
#endif
}
-#ifdef TMWSERV_SUPPORT
Game::Game():
- mBeingHandler(new BeingHandler),
- mGuildHandler(new GuildHandler),
- mEffectHandler(new EffectHandler),
-#else
-Game::Game(Network *network):
- mNetwork(network),
- mBeingHandler(new BeingHandler(config.getValue("EnableSync", 0) == 1)),
- mAdminHandler(new EAthena::AdminHandler),
- mEquipmentHandler(new EquipmentHandler),
- mSkillHandler(new EAthena::SkillHandler),
-#endif
- mPartyHandler(new PartyHandler),
- mBuySellHandler(new BuySellHandler),
-#ifdef TMWSERV_SUPPORT
- mChatHandler(new TmwServ::ChatHandler),
- mInventoryHandler(new TmwServ::InventoryHandler),
-#else
- mChatHandler(new EAthena::ChatHandler),
- mInventoryHandler(new EAthena::InventoryHandler),
-#endif
- mItemHandler(new ItemHandler),
-#ifdef TMWSERV_SUPPORT
- mNpcHandler(new TmwServ::NpcHandler),
- mPlayerHandler(new TmwServ::PlayerHandler),
- mTradeHandler(new TmwServ::TradeHandler),
-#else
- mNpcHandler(new EAthena::NpcHandler),
- mPlayerHandler(new EAthena::PlayerHandler),
- mTradeHandler(new EAthena::TradeHandler),
-#endif
mLastTarget(Being::UNKNOWN),
mLogicCounterId(0), mSecondsCounterId(0)
{
@@ -422,33 +393,12 @@ Game::Game(Network *network):
if (Joystick::getNumberOfJoysticks() > 0)
joystick = new Joystick(0);
-#ifdef TMWSERV_SUPPORT
- Net::registerHandler(mBeingHandler.get());
- Net::registerHandler(mBuySellHandler.get());
- Net::registerHandler(mChatHandler.get());
- Net::registerHandler(mGuildHandler.get());
- Net::registerHandler(mInventoryHandler.get());
- Net::registerHandler(mItemHandler.get());
- Net::registerHandler(mNpcHandler.get());
- Net::registerHandler(mPartyHandler.get());
- Net::registerHandler(mPlayerHandler.get());
- Net::registerHandler(mTradeHandler.get());
- Net::registerHandler(mEffectHandler.get());
-#else
- network->registerHandler(mAdminHandler.get());
- network->registerHandler(mBeingHandler.get());
- network->registerHandler(mBuySellHandler.get());
- network->registerHandler(mChatHandler.get());
- network->registerHandler(mEquipmentHandler.get());
- network->registerHandler(mInventoryHandler.get());
- network->registerHandler(mItemHandler.get());
- network->registerHandler(mNpcHandler.get());
- network->registerHandler(mPlayerHandler.get());
- network->registerHandler(mSkillHandler.get());
- network->registerHandler(mTradeHandler.get());
- network->registerHandler(mPartyHandler.get());
-
- partyTab = new PartyTab();
+#ifdef EATHENA_SUPPORT
+ map_path = map_path.substr(0, map_path.rfind("."));
+ engine->changeMap(map_path);
+#endif
+
+ setupWindow->setInGame(true);
/*
* To prevent the server from sending data before the client
@@ -460,20 +410,13 @@ Game::Game(Network *network):
* is ignored by the client
*/
Net::getMapHandler()->ping(tick_time);
-
- map_path = map_path.substr(0, map_path.rfind("."));
- engine->changeMap(map_path);
-#endif
-
- setupWindow->setInGame(true);
}
Game::~Game()
{
+ Net::getGeneralHandler()->unload();
#ifdef TMWSERV_SUPPORT
Net::clearHandlers();
-#else
- delete partyTab;
#endif
destroyGuiWindows();
@@ -608,14 +551,9 @@ void Game::logic()
}
// Handle network stuff
-#ifdef TMWSERV_SUPPORT
- Net::flush();
- // TODO: Fix notification when the connection is lost
-#else
- mNetwork->flush();
- mNetwork->dispatchMessages();
-
- if (!mNetwork->isConnected())
+ Net::getGeneralHandler()->flushNetwork();
+#ifdef EATHENA_SUPPORT // TODO: TMWServ notification
+ if (!Net::getGeneralHandler()->isNetworkConnected())
{
if (!disconnectedDialog)
{
diff --git a/src/game.h b/src/game.h
index 60de5cd9..ddda7cfc 100644
--- a/src/game.h
+++ b/src/game.h
@@ -22,17 +22,12 @@
#ifndef GAME_H
#define GAME_H
-#include <memory>
+//#include <memory>
#include "SDL.h"
#include "configlistener.h"
-class MessageHandler;
-#ifdef EATHENA_SUPPORT
-class Network;
-#endif
-
extern std::string map_path;
extern volatile int fps;
extern volatile int tick_time;
@@ -40,11 +35,8 @@ extern volatile int tick_time;
class Game : public ConfigListener
{
public:
-#ifdef TMWSERV_SUPPORT
Game();
-#else
- Game(Network *network);
-#endif
+
~Game();
void logic();
@@ -54,36 +46,12 @@ class Game : public ConfigListener
void optionChanged(const std::string &name);
private:
-#ifdef EATHENA_SUPPORT
- Network *mNetwork;
-#endif
-
/** Used to determine whether to draw the next frame. */
int mDrawTime;
/** The minimum frame time (used for frame limiting). */
int mMinFrameTime;
- typedef const std::auto_ptr<MessageHandler> MessageHandlerPtr;
- MessageHandlerPtr mBeingHandler;
-#ifdef TMWSERV_SUPPORT
- MessageHandlerPtr mGuildHandler;
- MessageHandlerPtr mEffectHandler;
-#else
- MessageHandlerPtr mAdminHandler;
- MessageHandlerPtr mEquipmentHandler;
- MessageHandlerPtr mSkillHandler;
-#endif
- MessageHandlerPtr mPartyHandler;
- MessageHandlerPtr mBuySellHandler;
- MessageHandlerPtr mChatHandler;
- MessageHandlerPtr mInventoryHandler;
- MessageHandlerPtr mItemHandler;
- MessageHandlerPtr mNpcHandler;
- MessageHandlerPtr mPlayerHandler;
- MessageHandlerPtr mPostHandler;
- MessageHandlerPtr mTradeHandler;
-
int mLastTarget;
SDL_TimerID mLogicCounterId;
diff --git a/src/main.cpp b/src/main.cpp
index a9f37d82..a121dad8 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -61,18 +61,21 @@
#endif
#include "gui/updatewindow.h"
+#include "net/charhandler.h"
+#include "net/generalhandler.h"
+#include "net/loginhandler.h"
+#include "net/maphandler.h"
+#include "net/net.h"
#ifdef TMWSERV_SUPPORT
#include "net/tmwserv/charserverhandler.h"
#include "net/tmwserv/connection.h"
+#include "net/tmwserv/generalhandler.h"
#include "net/tmwserv/loginhandler.h"
#include "net/tmwserv/logouthandler.h"
#include "net/tmwserv/network.h"
#else
-#include "net/ea/charserverhandler.h"
-#include "net/ea/loginhandler.h"
+#include "net/ea/generalhandler.h"
#include "net/ea/network.h"
-#include "net/ea/maphandler.h"
-#include "net/messageout.h"
#endif
#ifdef TMWSERV_SUPPORT
@@ -137,6 +140,10 @@ namespace
#ifdef TMWSERV_SUPPORT
std::string token; //used to store magic_token
+
+extern Net::Connection *gameServerConnection;
+extern Net::Connection *chatServerConnection;
+extern Net::Connection *accountServerConnection;
#else
// Account infos
char n_server, n_character;
@@ -159,20 +166,13 @@ Configuration branding; /**< XML branding information reader */
Logger *logger; /**< Log object */
KeyboardConfig keyboard;
-#ifdef TMWSERV_SUPPORT
+/*#ifdef TMWSERV_SUPPORT
Net::Connection *gameServerConnection = 0;
Net::Connection *chatServerConnection = 0;
Net::Connection *accountServerConnection = 0;
-#endif
+#endif*/
LoginData loginData;
-#ifdef TMWSERV_SUPPORT
-LoginHandler loginHandler;
-LogoutHandler logoutHandler;
-TmwServ::CharServerHandler charServerHandler;
-#else
-EAthena::CharServerHandler charServerHandler;
-#endif
LockedArray<LocalPlayer*> charInfo(maxSlot + 1);
Palette *guiPalette;
@@ -184,10 +184,6 @@ std::string homeDir;
std::string updateHost;
std::string updatesDir;
-#ifdef EATHENA_SUPPORT
-LoginHandler loginHandler;
-#endif
-
SDL_Surface *icon;
/**
@@ -732,36 +728,15 @@ static void accountLogin(Network *network, LoginData *loginData)
logger->log("Username is %s", loginData->username.c_str());
#ifdef EATHENA_SUPPORT
network->connect(loginData->hostname, loginData->port);
- network->registerHandler(&loginHandler);
+ // network->registerHandler(&loginHandler);
#endif
- loginHandler.setLoginData(loginData);
-#ifdef TMWSERV_SUPPORT
- Net::registerHandler(&loginHandler);
- charServerHandler.setCharInfo(&charInfo);
- Net::registerHandler(&charServerHandler);
+#ifdef TMWSERV_SUPPORT
+ Net::getCharHandler()->setCharInfo(&charInfo);
#endif
// Send login infos
-#ifdef TMWSERV_SUPPORT
- Net::AccountServer::login(accountServerConnection,
- 0, // client version
- loginData->username,
- loginData->password);
-#else
- 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);
-#endif
+ Net::getLoginHandler()->loginAccount(loginData);
// Clear the password, avoids auto login when returning to login
loginData->password = "";
@@ -798,22 +773,11 @@ static void charLogin(Network *network, LoginData *loginData)
{
logger->log("Trying to connect to char server...");
network->connect(loginData->hostname, loginData->port);
- network->registerHandler(&charServerHandler);
- charServerHandler.setCharInfo(&charInfo);
- charServerHandler.setLoginData(loginData);
+ // network->registerHandler(&charServerHandler);
+ Net::getCharHandler()->setCharInfo(&charInfo);
// Send login infos
- 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
- network->skip(4);
+ Net::getCharHandler()->connect(loginData);
}
static void mapLogin(Network *network, LoginData *loginData)
@@ -825,15 +789,10 @@ static void mapLogin(Network *network, LoginData *loginData)
logger->log("Trying to connect to map server...");
logger->log("Map: %s", map_path.c_str());
- EAthena::MapHandler *mapHandler = new EAthena::MapHandler;
+ // EAthena::MapHandler *mapHandler = new EAthena::MapHandler;
network->connect(loginData->hostname, loginData->port);
- //network->registerHandler(mapHandler);
- network->registerHandler(mapHandler);
-
- mapHandler->connect(loginData);
- // We get 4 useless bytes before the real answer comes in (what are these?)
- network->skip(4);
+ Net::getMapHandler()->connect(loginData);
}
#else
@@ -842,132 +801,52 @@ static void accountRegister(LoginData *loginData)
{
logger->log("Username is %s", loginData->username.c_str());
- Net::registerHandler(&loginHandler);
+ Net::getCharHandler()->setCharInfo(&charInfo);
- charServerHandler.setCharInfo(&charInfo);
- Net::registerHandler(&charServerHandler);
-
- Net::AccountServer::registerAccount(accountServerConnection,
- 0, // client version
- loginData->username,
- loginData->password,
- loginData->email);
+ Net::getLoginHandler()->registerAccount(loginData->username,
+ loginData->password, loginData->email);
}
static void accountUnRegister(LoginData *loginData)
{
- Net::registerHandler(&logoutHandler);
-
- Net::AccountServer::Account::unregister(loginData->username,
+ Net::getLoginHandler()->unregisterAccount(loginData->username,
loginData->password);
}
static void accountChangePassword(LoginData *loginData)
{
- Net::registerHandler(&loginHandler);
-
- Net::AccountServer::Account::changePassword(loginData->username,
+ Net::getLoginHandler()->changePassword(loginData->username,
loginData->password,
loginData->newPassword);
}
static void accountChangeEmail(LoginData *loginData)
{
- Net::registerHandler(&loginHandler);
-
- Net::AccountServer::Account::changeEmail(loginData->newEmail);
+ Net::getLoginHandler()->changeEmail(loginData->newEmail);
}
static void switchCharacter(std::string *passToken)
{
- Net::registerHandler(&logoutHandler);
-
- logoutHandler.reset();
- logoutHandler.setScenario(LOGOUT_SWITCH_CHARACTER, passToken);
-
- Net::GameServer::logout(true);
- Net::ChatServer::logout();
+ Net::getLogoutHandler()->reset();
+ Net::getLogoutHandler()->setScenario(LOGOUT_SWITCH_CHARACTER, passToken);
}
static void switchAccountServer()
{
- Net::registerHandler(&logoutHandler);
-
- logoutHandler.reset();
- logoutHandler.setScenario(LOGOUT_SWITCH_ACCOUNTSERVER);
-
- //Can't logout if we were not logged in ...
- if (accountServerConnection->isConnected())
- {
- Net::AccountServer::logout();
- }
- else
- {
- logoutHandler.setAccountLoggedOut();
- }
-
- if (gameServerConnection->isConnected())
- {
- Net::GameServer::logout(false);
- }
- else
- {
- logoutHandler.setGameLoggedOut();
- }
-
- if (chatServerConnection->isConnected())
- {
- Net::ChatServer::logout();
- }
- else
- {
- logoutHandler.setChatLoggedOut();
- }
+ Net::getLogoutHandler()->reset();
+ Net::getLogoutHandler()->setScenario(LOGOUT_SWITCH_LOGIN);
}
static void logoutThenExit()
{
- Net::registerHandler(&logoutHandler);
-
- logoutHandler.reset();
- logoutHandler.setScenario(LOGOUT_EXIT);
-
- // Can't logout if we were not logged in ...
- if (accountServerConnection->isConnected())
- {
- Net::AccountServer::logout();
- }
- else
- {
- logoutHandler.setAccountLoggedOut();
- }
-
- if (gameServerConnection->isConnected())
- {
- Net::GameServer::logout(false);
- }
- else
- {
- logoutHandler.setGameLoggedOut();
- }
-
- if (chatServerConnection->isConnected())
- {
- Net::ChatServer::logout();
- }
- else
- {
- logoutHandler.setChatLoggedOut();
- }
+ Net::getLogoutHandler()->reset();
+ Net::getLogoutHandler()->setScenario(LOGOUT_EXIT);
}
static void reconnectAccount(const std::string &passToken)
{
- Net::registerHandler(&loginHandler);
-
- charServerHandler.setCharInfo(&charInfo);
- Net::registerHandler(&charServerHandler);
+ Net::getCharHandler()->setCharInfo(&charInfo);
Net::AccountServer::reconnectAccount(accountServerConnection, passToken);
}
@@ -1113,14 +992,16 @@ int main(int argc, char *argv[])
#ifdef TMWSERV_SUPPORT
Net::initialize();
- accountServerConnection = Net::getConnection();
- gameServerConnection = Net::getConnection();
- chatServerConnection = Net::getConnection();
+ TmwServ::GeneralHandler *generalHandler = new TmwServ::GeneralHandler;
#else
SDLNet_Init();
Network *network = new Network;
+ EAthena::GeneralHandler *generalHandler = new EAthena::GeneralHandler;
+ network->registerHandler(generalHandler);
#endif
+ Net::getGeneralHandler()->load();
+
// Set the most appropriate wallpaper, based on screen width
int screenWidth = (int) config.getValue("screenwidth", defaultScreenWidth);
#ifdef EATHENA_SUPPORT
@@ -1561,7 +1442,6 @@ int main(int argc, char *argv[])
default:
network->disconnect();
- network->clearHandlers();
break;
}
@@ -1686,7 +1566,7 @@ int main(int argc, char *argv[])
login_wallpaper = NULL;
logger->log("State: GAME");
- game = new Game(network);
+ game = new Game();
game->logic();
delete game;
state = STATE_EXIT;
@@ -1773,18 +1653,8 @@ int main(int argc, char *argv[])
delete setup;
delete setupWindow;
+ Net::getGeneralHandler()->unload();
#ifdef TMWSERV_SUPPORT
- if (accountServerConnection)
- accountServerConnection->disconnect();
- if (gameServerConnection)
- gameServerConnection->disconnect();
- if (chatServerConnection)
- chatServerConnection->disconnect();
-
- delete accountServerConnection;
- delete gameServerConnection;
- delete chatServerConnection;
- Net::finalize();
#else
delete network;
SDLNet_Quit();
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);