summaryrefslogtreecommitdiff
path: root/src/net/tmwserv
diff options
context:
space:
mode:
Diffstat (limited to 'src/net/tmwserv')
-rw-r--r--src/net/tmwserv/charhandler.cpp (renamed from src/net/tmwserv/charserverhandler.cpp)155
-rw-r--r--src/net/tmwserv/charhandler.h (renamed from src/net/tmwserv/charserverhandler.h)9
-rw-r--r--src/net/tmwserv/chathandler.cpp46
-rw-r--r--src/net/tmwserv/chathandler.h8
-rw-r--r--src/net/tmwserv/connection.cpp5
-rw-r--r--src/net/tmwserv/connection.h1
-rw-r--r--src/net/tmwserv/gamehandler.cpp132
-rw-r--r--src/net/tmwserv/gamehandler.h (renamed from src/net/tmwserv/maphandler.h)18
-rw-r--r--src/net/tmwserv/generalhandler.cpp60
-rw-r--r--src/net/tmwserv/generalhandler.h7
-rw-r--r--src/net/tmwserv/loginhandler.cpp78
-rw-r--r--src/net/tmwserv/loginhandler.h12
-rw-r--r--src/net/tmwserv/logouthandler.cpp275
-rw-r--r--src/net/tmwserv/logouthandler.h58
-rw-r--r--src/net/tmwserv/maphandler.cpp66
15 files changed, 436 insertions, 494 deletions
diff --git a/src/net/tmwserv/charserverhandler.cpp b/src/net/tmwserv/charhandler.cpp
index 93181a93..ec260d84 100644
--- a/src/net/tmwserv/charserverhandler.cpp
+++ b/src/net/tmwserv/charhandler.cpp
@@ -19,7 +19,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include "net/tmwserv/charserverhandler.h"
+#include "net/tmwserv/charhandler.h"
#include "net/tmwserv/connection.h"
#include "net/tmwserv/protocol.h"
@@ -28,7 +28,9 @@
#include "net/tmwserv/accountserver/account.h"
#include "net/logindata.h"
+#include "net/loginhandler.h"
#include "net/messagein.h"
+#include "net/net.h"
#include "game.h"
#include "localplayer.h"
@@ -42,14 +44,34 @@
#include "utils/gettext.h"
+extern Net::Connection *accountServerConnection;
extern Net::Connection *gameServerConnection;
extern Net::Connection *chatServerConnection;
Net::CharHandler *charHandler;
+struct CharInfo {
+ unsigned char slot;
+ std::string name;
+ Gender gender;
+ int hs, hc;
+ unsigned short level;
+ unsigned short charPoints;
+ unsigned short corrPoints;
+ unsigned int money;
+ unsigned char attr[7];
+};
+
+typedef std::vector<CharInfo> CharInfos;
+CharInfos chars;
+
namespace TmwServ {
-CharServerHandler::CharServerHandler():
+extern std::string netToken;
+extern ServerInfo gameServer;
+extern ServerInfo chatServer;
+
+CharHandler::CharHandler():
mCharCreateDialog(0)
{
static const Uint16 _messages[] = {
@@ -63,11 +85,8 @@ CharServerHandler::CharServerHandler():
charHandler = this;
}
-void CharServerHandler::handleMessage(MessageIn &msg)
+void CharHandler::handleMessage(MessageIn &msg)
{
- int slot;
- LocalPlayer *tempPlayer;
-
switch (msg.getId())
{
case APMSG_CHAR_CREATE_RESPONSE:
@@ -107,17 +126,26 @@ void CharServerHandler::handleMessage(MessageIn &msg)
break;
case APMSG_CHAR_INFO:
- tempPlayer = readPlayerData(msg, slot);
- mCharInfo->unlock();
- mCharInfo->select(slot);
- mCharInfo->setEntry(tempPlayer);
-
- // Close the character create dialog
- if (mCharCreateDialog)
+ {
+ CharInfo info;
+ info.slot = msg.readInt8(); // character slot
+ info.name = msg.readString();
+ info.gender = msg.readInt8() == GENDER_MALE ? GENDER_MALE :
+ GENDER_FEMALE;
+ info.hs = msg.readInt8();
+ info.hc = msg.readInt8();
+ info.level = msg.readInt16();
+ info.charPoints = msg.readInt16();
+ info.corrPoints = msg.readInt16();
+ info.money = msg.readInt32();
+
+ for (int i = 0; i < 7; i++)
{
- mCharCreateDialog->scheduleDelete();
- mCharCreateDialog = 0;
+ info.attr[i] = msg.readInt8();
}
+
+ chars.push_back(info);
+ }
break;
case APMSG_CHAR_SELECT_RESPONSE:
@@ -126,7 +154,7 @@ void CharServerHandler::handleMessage(MessageIn &msg)
}
}
-void CharServerHandler::handleCharCreateResponse(MessageIn &msg)
+void CharHandler::handleCharCreateResponse(MessageIn &msg)
{
int errMsg = msg.readInt8();
@@ -177,23 +205,27 @@ void CharServerHandler::handleCharCreateResponse(MessageIn &msg)
mCharCreateDialog->unlock();
}
-void CharServerHandler::handleCharSelectResponse(MessageIn &msg)
+void CharHandler::handleCharSelectResponse(MessageIn &msg)
{
int errMsg = msg.readInt8();
if (errMsg == ERRMSG_OK)
{
- token = msg.readString(32);
- std::string gameServer = msg.readString();
- unsigned short gameServerPort = msg.readInt16();
- std::string chatServer = msg.readString();
- unsigned short chatServerPort = msg.readInt16();
+ netToken = msg.readString(32);
- logger->log("Game server: %s:%d", gameServer.c_str(), gameServerPort);
- logger->log("Chat server: %s:%d", chatServer.c_str(), chatServerPort);
+ gameServer.hostname.assign(msg.readString());
+ gameServer.port = msg.readInt16();
- gameServerConnection->connect(gameServer, gameServerPort);
- chatServerConnection->connect(chatServer, chatServerPort);
+ chatServer.hostname.assign(msg.readString());
+ chatServer.port = msg.readInt16();
+
+ logger->log("Game server: %s:%d", gameServer.hostname.c_str(),
+ gameServer.port);
+ logger->log("Chat server: %s:%d", chatServer.hostname.c_str(),
+ chatServer.port);
+
+ gameServerConnection->connect(gameServer.hostname, gameServer.port);
+ chatServerConnection->connect(chatServer.hostname, chatServer.port);
// Keep the selected character and delete the others
player_node = mCharInfo->getEntry();
@@ -224,28 +256,7 @@ void CharServerHandler::handleCharSelectResponse(MessageIn &msg)
}
}
-LocalPlayer* CharServerHandler::readPlayerData(MessageIn &msg, int &slot)
-{
- LocalPlayer *tempPlayer = new LocalPlayer;
- slot = msg.readInt8(); // character slot
- tempPlayer->setName(msg.readString());
- tempPlayer->setGender(msg.readInt8() == GENDER_MALE ? GENDER_MALE : GENDER_FEMALE);
- int hs = msg.readInt8(), hc = msg.readInt8();
- tempPlayer->setSprite(Player::HAIR_SPRITE, hs * -1, ColorDB::get(hc));
- tempPlayer->setLevel(msg.readInt16());
- tempPlayer->setCharacterPoints(msg.readInt16());
- tempPlayer->setCorrectionPoints(msg.readInt16());
- tempPlayer->setMoney(msg.readInt32());
-
- for (int i = 0; i < 7; i++)
- {
- tempPlayer->setAttributeBase(i, msg.readInt8());
- }
-
- return tempPlayer;
-}
-
-void CharServerHandler::setCharCreateDialog(CharCreateDialog *window)
+void CharHandler::setCharCreateDialog(CharCreateDialog *window)
{
mCharCreateDialog = window;
@@ -262,12 +273,54 @@ void CharServerHandler::setCharCreateDialog(CharCreateDialog *window)
mCharCreateDialog->setAttributes(attributes, 60, 1, 20);
}
-void CharServerHandler::chooseCharacter(int slot, LocalPlayer* character)
+void CharHandler::getCharacters()
+{
+ if (!accountServerConnection->isConnected())
+ Net::getLoginHandler()->connect();
+ else
+ {
+ mCharInfo->unlock();
+ LocalPlayer *tempPlayer;
+ for (CharInfos::const_iterator it = chars.begin(); it != chars.end(); it++)
+ {
+ const CharInfo info = (CharInfo) (*it);
+ mCharInfo->select(info.slot);
+
+ tempPlayer = new LocalPlayer();
+ tempPlayer->setName(info.name);
+ tempPlayer->setGender(info.gender);
+ tempPlayer->setSprite(Player::HAIR_SPRITE, info.hs * -1,
+ ColorDB::get(info.hc));
+ tempPlayer->setLevel(info.level);
+ tempPlayer->setCharacterPoints(info.charPoints);
+ tempPlayer->setCorrectionPoints(info.corrPoints);
+ tempPlayer->setMoney(info.money);
+
+ for (int i = 0; i < 7; i++)
+ {
+ tempPlayer->setAttributeBase(i, info.attr[i]);
+ }
+
+ mCharInfo->setEntry(tempPlayer);
+ }
+
+ // Close the character create dialog
+ if (mCharCreateDialog)
+ {
+ mCharCreateDialog->scheduleDelete();
+ mCharCreateDialog = 0;
+ }
+
+ state = STATE_CHAR_SELECT;
+ }
+}
+
+void CharHandler::chooseCharacter(int slot, LocalPlayer* character)
{
Net::AccountServer::Account::selectCharacter(slot);
}
-void CharServerHandler::newCharacter(const std::string &name, int slot, bool gender,
+void CharHandler::newCharacter(const std::string &name, int slot, bool gender,
int hairstyle, int hairColor, std::vector<int> stats)
{
Net::AccountServer::Account::createCharacter(name, hairstyle, hairColor,
@@ -281,7 +334,7 @@ void CharServerHandler::newCharacter(const std::string &name, int slot, bool gen
);
}
-void CharServerHandler::deleteCharacter(int slot, LocalPlayer* character)
+void CharHandler::deleteCharacter(int slot, LocalPlayer* character)
{
Net::AccountServer::Account::deleteCharacter(slot);
}
diff --git a/src/net/tmwserv/charserverhandler.h b/src/net/tmwserv/charhandler.h
index 4d79d60e..2c62c1d0 100644
--- a/src/net/tmwserv/charserverhandler.h
+++ b/src/net/tmwserv/charhandler.h
@@ -32,10 +32,10 @@ namespace TmwServ {
/**
* Deals with incoming messages related to character selection.
*/
-class CharServerHandler : public MessageHandler, public Net::CharHandler
+class CharHandler : public MessageHandler, public Net::CharHandler
{
public:
- CharServerHandler();
+ CharHandler();
void handleMessage(MessageIn &msg);
@@ -51,7 +51,7 @@ class CharServerHandler : public MessageHandler, public Net::CharHandler
*/
void setCharCreateDialog(CharCreateDialog *window);
- void connect(LoginData *loginData) {} // Unused
+ void getCharacters();
void chooseCharacter(int slot, LocalPlayer* character);
@@ -68,9 +68,6 @@ class CharServerHandler : public MessageHandler, public Net::CharHandler
LockedArray<LocalPlayer*> *mCharInfo;
CharCreateDialog *mCharCreateDialog;
-
- LocalPlayer*
- readPlayerData(MessageIn &msg, int &slot);
};
} // namespace TmwServ
diff --git a/src/net/tmwserv/chathandler.cpp b/src/net/tmwserv/chathandler.cpp
index c95f6ac5..229f09be 100644
--- a/src/net/tmwserv/chathandler.cpp
+++ b/src/net/tmwserv/chathandler.cpp
@@ -35,9 +35,10 @@
#include "being.h"
#include "beingmanager.h"
-#include "game.h"
#include "channel.h"
#include "channelmanager.h"
+#include "game.h"
+#include "main.h"
#include "gui/widgets/channeltab.h"
#include "gui/chat.h"
@@ -53,8 +54,13 @@ extern Being *player_node;
Net::ChatHandler *chatHandler;
+extern Net::Connection *chatServerConnection;
+
namespace TmwServ {
+extern std::string netToken;
+extern ServerInfo chatServer;
+
ChatHandler::ChatHandler()
{
static const Uint16 _messages[] = {
@@ -68,6 +74,7 @@ ChatHandler::ChatHandler()
CPMSG_LIST_CHANNELUSERS_RESPONSE,
CPMSG_CHANNEL_EVENT,
CPMSG_WHO_RESPONSE,
+ CPMSG_DISCONNECT_RESPONSE,
0
};
handledMessages = _messages;
@@ -117,6 +124,28 @@ void ChatHandler::handleMessage(MessageIn &msg)
case CPMSG_WHO_RESPONSE:
handleWhoResponse(msg);
break;
+ case CPMSG_DISCONNECT_RESPONSE:
+ {
+ int errMsg = msg.readInt8();
+ // Successful logout
+ if (errMsg == ERRMSG_OK)
+ {
+ // TODO: Handle logout
+ }
+ else
+ {
+ switch (errMsg) {
+ case ERRMSG_NO_LOGIN:
+ errorMessage = "Chatserver: Not logged in";
+ break;
+ default:
+ errorMessage = "Chatserver: Unknown error";
+ break;
+ }
+ state = STATE_ERROR;
+ }
+ }
+ break;
}
}
@@ -323,6 +352,21 @@ void ChatHandler::handleWhoResponse(MessageIn &msg)
}
}
+void ChatHandler::connect()
+{
+ Net::ChatServer::connect(chatServerConnection, netToken);
+}
+
+bool ChatHandler::isConnected()
+{
+ return chatServerConnection->isConnected();
+}
+
+void ChatHandler::disconnect()
+{
+ chatServerConnection->disconnect();
+}
+
void ChatHandler::talk(const std::string &text)
{
MessageOut msg(PGMSG_SAY);
diff --git a/src/net/tmwserv/chathandler.h b/src/net/tmwserv/chathandler.h
index bc30de7c..85bc2054 100644
--- a/src/net/tmwserv/chathandler.h
+++ b/src/net/tmwserv/chathandler.h
@@ -25,6 +25,8 @@
#include "net/chathandler.h"
#include "net/messagehandler.h"
+#include "net/serverinfo.h"
+
namespace TmwServ {
class ChatHandler : public MessageHandler, public Net::ChatHandler
@@ -37,6 +39,12 @@ class ChatHandler : public MessageHandler, public Net::ChatHandler
*/
void handleMessage(MessageIn &msg);
+ void connect();
+
+ bool isConnected();
+
+ void disconnect();
+
void talk(const std::string &text);
void me(const std::string &text);
diff --git a/src/net/tmwserv/connection.cpp b/src/net/tmwserv/connection.cpp
index 6762af89..9346e3cc 100644
--- a/src/net/tmwserv/connection.cpp
+++ b/src/net/tmwserv/connection.cpp
@@ -32,6 +32,7 @@
Net::Connection::Connection(ENetHost *client):
mConnection(0), mClient(client)
{
+ mPort = 0;
Net::connections++;
}
@@ -66,6 +67,8 @@ bool Net::Connection::connect(const std::string &address, short port)
return false;
}
+ mPort = port;
+
return true;
}
@@ -95,8 +98,6 @@ void Net::Connection::send(const MessageOut &msg)
return;
}
- //logger->log("Sending message of size %d...", msg.getDataSize());
-
ENetPacket *packet = enet_packet_create(msg.getData(),
msg.getDataSize(),
ENET_PACKET_FLAG_RELIABLE);
diff --git a/src/net/tmwserv/connection.h b/src/net/tmwserv/connection.h
index 447cf71c..8d1c2924 100644
--- a/src/net/tmwserv/connection.h
+++ b/src/net/tmwserv/connection.h
@@ -71,6 +71,7 @@ namespace Net
friend Connection *Net::getConnection();
Connection(ENetHost *client);
+ short mPort;
ENetPeer *mConnection;
ENetHost *mClient;
State mState;
diff --git a/src/net/tmwserv/gamehandler.cpp b/src/net/tmwserv/gamehandler.cpp
new file mode 100644
index 00000000..ec2f33c4
--- /dev/null
+++ b/src/net/tmwserv/gamehandler.cpp
@@ -0,0 +1,132 @@
+/*
+ * 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/tmwserv/gamehandler.h"
+
+#include "net/tmwserv/chathandler.h"
+#include "net/tmwserv/connection.h"
+#include "net/tmwserv/protocol.h"
+
+#include "net/tmwserv/chatserver/chatserver.h"
+#include "net/tmwserv/gameserver/gameserver.h"
+
+#include "main.h"
+
+Net::GameHandler *gameHandler;
+
+extern TmwServ::ChatHandler *chatHandler;
+
+extern Net::Connection *gameServerConnection;
+
+namespace TmwServ {
+
+extern std::string netToken;
+extern ServerInfo gameServer;
+
+GameHandler::GameHandler()
+{
+ static const Uint16 _messages[] = {
+ GPMSG_DISCONNECT_RESPONSE,
+ 0
+ };
+ handledMessages = _messages;
+ gameHandler = this;
+}
+
+void GameHandler::handleMessage(MessageIn &msg)
+{
+ switch (msg.getId())
+ {
+ case GPMSG_DISCONNECT_RESPONSE:
+ {
+ int errMsg = msg.readInt8();
+ // Successful logout
+ if (errMsg == ERRMSG_OK)
+ {
+ // TODO: Handle logout
+ }
+ // Logout failed
+ else
+ {
+ switch (errMsg) {
+ case ERRMSG_NO_LOGIN:
+ errorMessage = "Gameserver: Not logged in";
+ break;
+ default:
+ errorMessage = "Gameserver: Unknown error";
+ break;
+ }
+ state = STATE_ERROR;
+ }
+ }
+ break;
+ }
+}
+
+void GameHandler::connect()
+{
+ //
+}
+
+bool GameHandler::isConnected()
+{
+ return gameServerConnection->isConnected() &&
+ chatHandler->isConnected();
+}
+
+void GameHandler::disconnect()
+{
+ gameServerConnection->disconnect();
+ chatHandler->disconnect();
+}
+
+void GameHandler::inGame()
+{
+ Net::GameServer::connect(gameServerConnection, netToken);
+ chatHandler->connect();
+}
+
+void GameHandler::mapLoaded(const std::string &mapName)
+{
+ // TODO
+}
+
+void GameHandler::who()
+{
+ // TODO
+}
+
+void GameHandler::quit()
+{
+ // TODO
+}
+
+void GameHandler::ping(int tick)
+{
+ // TODO
+}
+
+void GameHandler::clear()
+{
+ disconnect();
+}
+
+} // namespace TmwServ
diff --git a/src/net/tmwserv/maphandler.h b/src/net/tmwserv/gamehandler.h
index 099ec7e0..4721d634 100644
--- a/src/net/tmwserv/maphandler.h
+++ b/src/net/tmwserv/gamehandler.h
@@ -22,19 +22,27 @@
#ifndef NET_TMWSERV_MAPHANDLER_H
#define NET_TMWSERV_MAPHANDLER_H
-#include "net/maphandler.h"
+#include "net/gamehandler.h"
#include "net/messagehandler.h"
+#include "net/serverinfo.h"
+
namespace TmwServ {
-class MapHandler : public MessageHandler, public Net::MapHandler
+class GameHandler : public MessageHandler, public Net::GameHandler
{
public:
- MapHandler();
+ GameHandler();
void handleMessage(MessageIn &msg);
- void connect(LoginData *loginData);
+ void connect();
+
+ bool isConnected();
+
+ void disconnect();
+
+ void inGame();
void mapLoaded(const std::string &mapName);
@@ -43,6 +51,8 @@ class MapHandler : public MessageHandler, public Net::MapHandler
void quit();
void ping(int tick);
+
+ void clear();
};
} // namespace TmwServ
diff --git a/src/net/tmwserv/generalhandler.cpp b/src/net/tmwserv/generalhandler.cpp
index 011433fe..81bb46be 100644
--- a/src/net/tmwserv/generalhandler.cpp
+++ b/src/net/tmwserv/generalhandler.cpp
@@ -19,28 +19,28 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+#include "net/tmwserv/generalhandler.h"
+
#include "gui/inventorywindow.h"
#include "gui/partywindow.h"
+#include "gui/register.h"
#include "gui/skilldialog.h"
#include "gui/specialswindow.h"
#include "gui/statuswindow.h"
-#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/charhandler.h"
#include "net/tmwserv/chathandler.h"
#include "net/tmwserv/effecthandler.h"
+#include "net/tmwserv/gamehandler.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"
@@ -49,6 +49,8 @@
#include "utils/gettext.h"
+#include "main.h"
+
#include <list>
Net::GeneralHandler *generalHandler;
@@ -59,24 +61,29 @@ Net::Connection *accountServerConnection = 0;
namespace TmwServ {
+std::string netToken = "";
+ServerInfo gameServer;
+ServerInfo chatServer;
+
GeneralHandler::GeneralHandler():
- mBeingHandler(new BeingHandler),
- mBuySellHandler(new BuySellHandler),
- mCharServerHandler(new CharServerHandler),
- mChatHandler(new ChatHandler),
- mEffectHandler(new EffectHandler),
- mGuildHandler(new GuildHandler),
- mInventoryHandler(new InventoryHandler),
- mItemHandler(new ItemHandler),
- mLoginHandler(new LoginHandler),
- mLogoutHandler(new LogoutHandler),
- mMapHandler(new MapHandler),
- mNpcHandler(new NpcHandler),
- mPartyHandler(new PartyHandler),
- mPlayerHandler(new PlayerHandler),
- mTradeHandler(new TradeHandler),
- mSpecialHandler(new SpecialHandler)
+ mBeingHandler(new BeingHandler),
+ mBuySellHandler(new BuySellHandler),
+ mCharHandler(new CharHandler),
+ mChatHandler(new ChatHandler),
+ mEffectHandler(new EffectHandler),
+ mGameHandler(new GameHandler),
+ mGuildHandler(new GuildHandler),
+ mInventoryHandler(new InventoryHandler),
+ mItemHandler(new ItemHandler),
+ mLoginHandler(new LoginHandler),
+ mNpcHandler(new NpcHandler),
+ mPartyHandler(new PartyHandler),
+ mPlayerHandler(new PlayerHandler),
+ mTradeHandler(new TradeHandler),
+ mSpecialHandler(new SpecialHandler)
{
+ Net::initialize();
+
accountServerConnection = Net::getConnection();
gameServerConnection = Net::getConnection();
chatServerConnection = Net::getConnection();
@@ -98,15 +105,14 @@ void GeneralHandler::load()
{
Net::registerHandler(mBeingHandler.get());
Net::registerHandler(mBuySellHandler.get());
- Net::registerHandler(mCharServerHandler.get());
+ Net::registerHandler(mCharHandler.get());
Net::registerHandler(mChatHandler.get());
Net::registerHandler(mEffectHandler.get());
+ Net::registerHandler(mGameHandler.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());
@@ -151,6 +157,7 @@ void GeneralHandler::guiWindowsLoaded()
{
inventoryWindow->setSplitAllowed(true);
partyWindow->clearPartyName();
+ RegisterDialog::setGender(NULL);
skillDialog->loadSkills("tmw-skills.xml");
specialsWindow->loadSpecials("specials.xml");
@@ -169,4 +176,9 @@ void GeneralHandler::guiWindowsUnloaded()
// TODO
}
+void GeneralHandler::clearHandlers()
+{
+ Net::clearHandlers();
+}
+
} // namespace TmwServ
diff --git a/src/net/tmwserv/generalhandler.h b/src/net/tmwserv/generalhandler.h
index 40166ca0..6c1d849f 100644
--- a/src/net/tmwserv/generalhandler.h
+++ b/src/net/tmwserv/generalhandler.h
@@ -47,18 +47,19 @@ class GeneralHandler : public Net::GeneralHandler
void guiWindowsUnloaded();
+ void clearHandlers();
+
protected:
MessageHandlerPtr mBeingHandler;
MessageHandlerPtr mBuySellHandler;
- MessageHandlerPtr mCharServerHandler;
+ MessageHandlerPtr mCharHandler;
MessageHandlerPtr mChatHandler;
MessageHandlerPtr mEffectHandler;
+ MessageHandlerPtr mGameHandler;
MessageHandlerPtr mGuildHandler;
MessageHandlerPtr mInventoryHandler;
MessageHandlerPtr mItemHandler;
MessageHandlerPtr mLoginHandler;
- MessageHandlerPtr mLogoutHandler;
- MessageHandlerPtr mMapHandler;
MessageHandlerPtr mNpcHandler;
MessageHandlerPtr mPartyHandler;
MessageHandlerPtr mPlayerHandler;
diff --git a/src/net/tmwserv/loginhandler.cpp b/src/net/tmwserv/loginhandler.cpp
index f728d831..74b8abad 100644
--- a/src/net/tmwserv/loginhandler.cpp
+++ b/src/net/tmwserv/loginhandler.cpp
@@ -48,6 +48,8 @@ LoginHandler::LoginHandler()
APMSG_RECONNECT_RESPONSE,
APMSG_PASSWORD_CHANGE_RESPONSE,
APMSG_EMAIL_CHANGE_RESPONSE,
+ APMSG_LOGOUT_RESPONSE,
+ APMSG_UNREGISTER_RESPONSE,
0
};
handledMessages = _messages;
@@ -156,7 +158,54 @@ void LoginHandler::handleMessage(MessageIn &msg)
}
}
break;
+ case APMSG_LOGOUT_RESPONSE:
+ {
+ int errMsg = msg.readInt8();
+ // Successful logout
+ if (errMsg == ERRMSG_OK)
+ {
+ // TODO: handle logout
+ }
+ // Logout failed
+ else
+ {
+ switch (errMsg) {
+ case ERRMSG_NO_LOGIN:
+ errorMessage = "Accountserver: Not logged in";
+ break;
+ default:
+ errorMessage = "Accountserver: Unknown error";
+ break;
+ }
+ state = STATE_ERROR;
+ }
+ }
+ break;
+ case APMSG_UNREGISTER_RESPONSE:
+ {
+ int errMsg = msg.readInt8();
+ // Successful unregistration
+ if (errMsg == ERRMSG_OK)
+ {
+ state = STATE_UNREGISTER;
+ }
+ // Unregistration failed
+ else
+ {
+ switch (errMsg) {
+ case ERRMSG_INVALID_ARGUMENT:
+ errorMessage =
+ "Accountserver: Wrong username or password";
+ break;
+ default:
+ errorMessage = "Accountserver: Unknown error";
+ break;
+ }
+ state = STATE_ACCOUNTCHANGE_ERROR;
+ }
+ }
+ break;
}
}
@@ -167,7 +216,8 @@ void LoginHandler::handleLoginResponse(MessageIn &msg)
if (errMsg == ERRMSG_OK)
{
readUpdateHost(msg);
- state = STATE_CHAR_SELECT;
+ // No worlds atm, but future use :-D
+ state = STATE_WORLD_SELECT;
}
else
{
@@ -199,7 +249,7 @@ void LoginHandler::handleRegisterResponse(MessageIn &msg)
if (errMsg == ERRMSG_OK)
{
readUpdateHost(msg);
- state = STATE_CHAR_SELECT;
+ state = STATE_WORLD_SELECT;
}
else
{
@@ -233,6 +283,23 @@ void LoginHandler::readUpdateHost(MessageIn &msg)
}
}
+void LoginHandler::connect()
+{
+ accountServerConnection->connect(mServer.hostname, mServer.port);
+ /*if (state == STATE_CONNECT_SERVER)
+ state = STATE_LOGIN;*/
+}
+
+bool LoginHandler::isConnected()
+{
+ return accountServerConnection->isConnected();
+}
+
+void LoginHandler::disconnect()
+{
+ accountServerConnection->disconnect();
+}
+
void LoginHandler::loginAccount(LoginData *loginData)
{
mLoginData = loginData;
@@ -255,7 +322,7 @@ void LoginHandler::changePassword(const std::string &username,
newPassword);
}
-void LoginHandler::chooseServer(int server)
+void LoginHandler::chooseServer(unsigned int server)
{
// TODO
}
@@ -275,4 +342,9 @@ void LoginHandler::unregisterAccount(const std::string &username,
Net::AccountServer::Account::unregister(username, password);
}
+Worlds LoginHandler::getWorlds()
+{
+ return Worlds();
+}
+
} // namespace TmwServ
diff --git a/src/net/tmwserv/loginhandler.h b/src/net/tmwserv/loginhandler.h
index f3bc0c6d..50b3d8c7 100644
--- a/src/net/tmwserv/loginhandler.h
+++ b/src/net/tmwserv/loginhandler.h
@@ -25,6 +25,8 @@
#include "net/loginhandler.h"
#include "net/messagehandler.h"
+#include "net/serverinfo.h"
+
class LoginData;
namespace TmwServ {
@@ -36,6 +38,12 @@ class LoginHandler : public MessageHandler, public Net::LoginHandler
void handleMessage(MessageIn &msg);
+ void connect();
+
+ bool isConnected();
+
+ void disconnect();
+
void loginAccount(LoginData *loginData);
void changeEmail(const std::string &email);
@@ -44,13 +52,15 @@ class LoginHandler : public MessageHandler, public Net::LoginHandler
const std::string &oldPassword,
const std::string &newPassword);
- void chooseServer(int server);
+ void chooseServer(unsigned int server);
void registerAccount(LoginData *loginData);
void unregisterAccount(const std::string &username,
const std::string &password);
+ Worlds getWorlds();
+
private:
void handleLoginResponse(MessageIn &msg);
void handleRegisterResponse(MessageIn &msg);
diff --git a/src/net/tmwserv/logouthandler.cpp b/src/net/tmwserv/logouthandler.cpp
deleted file mode 100644
index 9ac6c7d4..00000000
--- a/src/net/tmwserv/logouthandler.cpp
+++ /dev/null
@@ -1,275 +0,0 @@
-/*
- * The Mana World
- * Copyright (C) 2004 The Mana World Development Team
- *
- * This file is part of The Mana World.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include "net/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),
- mLoggedOutAccount(false),
- mLoggedOutGame(false),
- mLoggedOutChat(false)
-{
- static const Uint16 _messages[] = {
- APMSG_LOGOUT_RESPONSE,
- APMSG_UNREGISTER_RESPONSE,
- GPMSG_DISCONNECT_RESPONSE,
- CPMSG_DISCONNECT_RESPONSE,
- 0
- };
- handledMessages = _messages;
- logoutHandler = this;
-}
-
-void LogoutHandler::handleMessage(MessageIn &msg)
-{
- switch (msg.getId())
- {
- case APMSG_LOGOUT_RESPONSE:
- {
- int errMsg = msg.readInt8();
-
- // Successful logout
- if (errMsg == ERRMSG_OK)
- {
- mLoggedOutAccount = true;
-
- switch (mScenario)
- {
- case LOGOUT_SWITCH_LOGIN:
- if (mLoggedOutGame && mLoggedOutChat)
- state = STATE_SWITCH_ACCOUNTSERVER;
- break;
-
- case LOGOUT_EXIT:
- default:
- if (mLoggedOutGame && mLoggedOutChat)
- state = STATE_FORCE_QUIT;
- break;
- }
- }
- // Logout failed
- else
- {
- switch (errMsg) {
- case ERRMSG_NO_LOGIN:
- errorMessage = "Accountserver: Not logged in";
- break;
- default:
- errorMessage = "Accountserver: Unknown error";
- break;
- }
- state = STATE_ERROR;
- }
- }
- break;
- case APMSG_UNREGISTER_RESPONSE:
- {
- int errMsg = msg.readInt8();
- // Successful unregistration
- if (errMsg == ERRMSG_OK)
- {
- state = STATE_UNREGISTER;
- }
- // Unregistration failed
- else
- {
- switch (errMsg) {
- case ERRMSG_INVALID_ARGUMENT:
- errorMessage =
- "Accountserver: Wrong username or password";
- break;
- default:
- errorMessage = "Accountserver: Unknown error";
- break;
- }
- state = STATE_ACCOUNTCHANGE_ERROR;
- }
- }
- break;
- case GPMSG_DISCONNECT_RESPONSE:
- {
- int errMsg = msg.readInt8();
- // Successful logout
- if (errMsg == ERRMSG_OK)
- {
- mLoggedOutGame = true;
-
- switch (mScenario)
- {
- case LOGOUT_SWITCH_CHARACTER:
- if (mPassToken)
- {
- *mPassToken = msg.readString(32);
- mPassToken = NULL;
- }
- if (mLoggedOutChat) state = STATE_RECONNECT_ACCOUNT;
- break;
-
- case LOGOUT_SWITCH_LOGIN:
- if (mLoggedOutAccount && mLoggedOutChat)
- state = STATE_SWITCH_ACCOUNTSERVER;
- break;
-
- case LOGOUT_EXIT:
- default:
- if (mLoggedOutAccount && mLoggedOutChat)
- state = STATE_FORCE_QUIT;
- break;
- }
- }
- // Logout failed
- else
- {
- switch (errMsg) {
- case ERRMSG_NO_LOGIN:
- errorMessage = "Gameserver: Not logged in";
- break;
- default:
- errorMessage = "Gameserver: Unknown error";
- break;
- }
- state = STATE_ERROR;
- }
- }
- break;
- case CPMSG_DISCONNECT_RESPONSE:
- {
- int errMsg = msg.readInt8();
- // Successful logout
- if (errMsg == ERRMSG_OK)
- {
- mLoggedOutChat = true;
-
- switch (mScenario)
- {
- case LOGOUT_SWITCH_CHARACTER:
- if (mLoggedOutGame) state = STATE_RECONNECT_ACCOUNT;
- break;
-
- case LOGOUT_SWITCH_LOGIN:
- if (mLoggedOutAccount && mLoggedOutGame)
- state = STATE_SWITCH_ACCOUNTSERVER;
- break;
-
- case LOGOUT_EXIT:
- default:
- if (mLoggedOutAccount && mLoggedOutGame)
- {
- state = STATE_FORCE_QUIT;
- }
- break;
- }
- }
- else
- {
- switch (errMsg) {
- case ERRMSG_NO_LOGIN:
- errorMessage = "Chatserver: Not logged in";
- break;
- default:
- errorMessage = "Chatserver: Unknown error";
- break;
- }
- state = STATE_ERROR;
- }
- }
- break;
- }
-}
-
-void LogoutHandler::setScenario(unsigned short scenario,
- std::string *passToken)
-{
- 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()
-{
- mPassToken = NULL;
- mScenario = LOGOUT_EXIT;
- mLoggedOutAccount = false;
- mLoggedOutGame = false;
- mLoggedOutChat = false;
-}
-
-} // namespace TmwServ
diff --git a/src/net/tmwserv/logouthandler.h b/src/net/tmwserv/logouthandler.h
deleted file mode 100644
index 19b6d43a..00000000
--- a/src/net/tmwserv/logouthandler.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * The Mana World
- * Copyright (C) 2004 The Mana World Development Team
- *
- * This file is part of The Mana World.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#ifndef NET_TMWSERV_LOGOUTHANDLER_H
-#define NET_TMWSERV_LOGOUTHANDLER_H
-
-#include "net/logouthandler.h"
-#include "net/messagehandler.h"
-
-#include <string>
-
-namespace TmwServ {
-
-class LogoutHandler : public MessageHandler, public Net::LogoutHandler
-{
- public:
- LogoutHandler();
-
- void handleMessage(MessageIn &msg);
-
- void setScenario(unsigned short scenario,
- std::string *passToken = NULL);
-
- void reset();
-
- void setAccountLoggedOut() { mLoggedOutAccount = true; }
- void setGameLoggedOut() { mLoggedOutGame = true; }
- void setChatLoggedOut() { mLoggedOutChat = true; }
-
- private:
- std::string* mPassToken;
- unsigned short mScenario;
- bool mLoggedOutAccount;
- bool mLoggedOutGame;
- bool mLoggedOutChat;
-};
-
-} // namespace TmwServ
-
-#endif
diff --git a/src/net/tmwserv/maphandler.cpp b/src/net/tmwserv/maphandler.cpp
deleted file mode 100644
index d64ea13b..00000000
--- a/src/net/tmwserv/maphandler.cpp
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * The Mana World
- * Copyright (C) 2004 The Mana World Development Team
- *
- * This file is part of The Mana World.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include "net/tmwserv/maphandler.h"
-
-Net::MapHandler *mapHandler;
-
-namespace TmwServ {
-
-MapHandler::MapHandler()
-{
- static const Uint16 _messages[] = {
- 0
- };
- handledMessages = _messages;
- mapHandler = this;
-}
-
-void MapHandler::handleMessage(MessageIn &msg)
-{
-}
-
-void MapHandler::connect(LoginData *loginData)
-{
- // TODO
-}
-
-void MapHandler::mapLoaded(const std::string &mapName)
-{
- // TODO
-}
-
-void MapHandler::who()
-{
- // TODO
-}
-
-void MapHandler::quit()
-{
- // TODO
-}
-
-void MapHandler::ping(int tick)
-{
- // TODO
-}
-
-} // namespace TmwServ