summaryrefslogtreecommitdiff
path: root/src/net
diff options
context:
space:
mode:
authorJared Adams <jaxad0127@gmail.com>2009-09-30 19:54:06 -0600
committerJared Adams <jaxad0127@gmail.com>2009-09-30 19:54:06 -0600
commitd4f32a38fd498c180d562ced38a9129e0abf2252 (patch)
treee655b59ff686ad5fe2bdd11d6e072f5c3a4493b7 /src/net
parent6707d108790ab1fe1d4a3ef52d717966990fdf0a (diff)
downloadmana-client-d4f32a38fd498c180d562ced38a9129e0abf2252.tar.gz
mana-client-d4f32a38fd498c180d562ced38a9129e0abf2252.tar.bz2
mana-client-d4f32a38fd498c180d562ced38a9129e0abf2252.tar.xz
mana-client-d4f32a38fd498c180d562ced38a9129e0abf2252.zip
Merge login state machines for both clients
Also do some cleanup and refactoring of related code.
Diffstat (limited to 'src/net')
-rw-r--r--src/net/charhandler.h4
-rw-r--r--src/net/ea/charserverhandler.cpp48
-rw-r--r--src/net/ea/charserverhandler.h8
-rw-r--r--src/net/ea/gamehandler.cpp (renamed from src/net/ea/maphandler.cpp)60
-rw-r--r--src/net/ea/gamehandler.h (renamed from src/net/ea/maphandler.h)20
-rw-r--r--src/net/ea/generalhandler.cpp22
-rw-r--r--src/net/ea/generalhandler.h6
-rw-r--r--src/net/ea/loginhandler.cpp94
-rw-r--r--src/net/ea/loginhandler.h12
-rw-r--r--src/net/ea/logouthandler.cpp65
-rw-r--r--src/net/ea/logouthandler.h47
-rw-r--r--src/net/ea/network.cpp39
-rw-r--r--src/net/ea/network.h10
-rw-r--r--src/net/ea/playerhandler.cpp2
-rw-r--r--src/net/ea/protocol.h6
-rw-r--r--src/net/gamehandler.h (renamed from src/net/maphandler.h)12
-rw-r--r--src/net/generalhandler.h4
-rw-r--r--src/net/logindata.h25
-rw-r--r--src/net/loginhandler.h23
-rw-r--r--src/net/messagehandler.h2
-rw-r--r--src/net/messageout.cpp1
-rw-r--r--src/net/messageout.h2
-rw-r--r--src/net/net.cpp47
-rw-r--r--src/net/net.h13
-rw-r--r--src/net/serverinfo.h31
-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
-rw-r--r--src/net/worldinfo.h (renamed from src/net/logouthandler.h)37
41 files changed, 788 insertions, 782 deletions
diff --git a/src/net/charhandler.h b/src/net/charhandler.h
index 56bfbbb4..9ca36a9f 100644
--- a/src/net/charhandler.h
+++ b/src/net/charhandler.h
@@ -38,10 +38,10 @@ class CharHandler
public:
virtual void setCharInfo(LockedArray<LocalPlayer*> *charInfo) = 0;
- virtual void connect(LoginData *loginData) = 0;
-
virtual void setCharCreateDialog(CharCreateDialog *window) = 0;
+ virtual void getCharacters() = 0;
+
virtual void chooseCharacter(int slot, LocalPlayer* character) = 0;
virtual void newCharacter(const std::string &name, int slot,
diff --git a/src/net/ea/charserverhandler.cpp b/src/net/ea/charserverhandler.cpp
index 47d454a8..f854841f 100644
--- a/src/net/ea/charserverhandler.cpp
+++ b/src/net/ea/charserverhandler.cpp
@@ -21,6 +21,7 @@
#include "net/ea/charserverhandler.h"
+#include "net/ea/generalhandler.h"
#include "net/ea/network.h"
#include "net/ea/protocol.h"
@@ -43,6 +44,9 @@
Net::CharHandler *charHandler;
namespace EAthena {
+extern Token netToken;
+extern ServerInfo charServer;
+extern ServerInfo mapServer;
CharServerHandler::CharServerHandler():
mCharCreateDialog(0)
@@ -145,8 +149,8 @@ void CharServerHandler::handleMessage(MessageIn &msg)
slot = mCharInfo->getPos();
msg.skip(4); // CharID, must be the same as player_node->charID
map_path = msg.readString(16);
- mLoginData->hostname = ipToString(msg.readInt32());
- mLoginData->port = msg.readInt16();
+ mapServer.hostname = ipToString(msg.readInt32());
+ mapServer.port = msg.readInt16();
mCharInfo->unlock();
mCharInfo->select(0);
// Clear unselected players infos
@@ -162,7 +166,8 @@ void CharServerHandler::handleMessage(MessageIn &msg)
} while (mCharInfo->getPos());
mCharInfo->select(slot);
- state = STATE_CONNECTING;
+ mNetwork->disconnect();
+ state = STATE_CONNECT_GAME;
break;
}
}
@@ -170,7 +175,7 @@ void CharServerHandler::handleMessage(MessageIn &msg)
LocalPlayer *CharServerHandler::readPlayerData(MessageIn &msg, int &slot)
{
LocalPlayer *tempPlayer = new LocalPlayer(msg.readInt32(), 0, NULL);
- tempPlayer->setGender(mLoginData->sex);
+ tempPlayer->setGender(netToken.sex);
tempPlayer->setExp(msg.readInt32());
tempPlayer->setMoney(msg.readInt32());
@@ -229,24 +234,12 @@ void CharServerHandler::setCharCreateDialog(CharCreateDialog *window)
attributes.push_back(_("Luck:"));
mCharCreateDialog->setAttributes(attributes, 30, 1, 9);
- mCharCreateDialog->setFixedGender(true, mLoginData->sex);
+ mCharCreateDialog->setFixedGender(true, netToken.sex);
}
-void CharServerHandler::connect(LoginData *loginData)
+void CharServerHandler::getCharacters()
{
- mLoginData = loginData;
-
- MessageOut outMsg(CMSG_CHAR_SERVER_CONNECT);
- outMsg.writeInt32(loginData->account_ID);
- outMsg.writeInt32(loginData->session_ID1);
- outMsg.writeInt32(loginData->session_ID2);
- // [Fate] The next word is unused by the old char server, so we squeeze in
- // tmw client version information
- outMsg.writeInt16(CLIENT_PROTOCOL_VERSION);
- outMsg.writeInt8((loginData->sex == GENDER_MALE) ? 1 : 0);
-
- // We get 4 useless bytes before the real answer comes in (what are these?)
- mNetwork->skip(4);
+ connect();
}
void CharServerHandler::chooseCharacter(int slot, LocalPlayer* character)
@@ -276,4 +269,21 @@ void CharServerHandler::deleteCharacter(int slot, LocalPlayer* character)
outMsg.writeString("a@a.com", 40);
}
+void CharServerHandler::connect()
+{
+ mNetwork->disconnect();
+ mNetwork->connect(charServer);
+ MessageOut outMsg(CMSG_CHAR_SERVER_CONNECT);
+ outMsg.writeInt32(netToken.account_ID);
+ outMsg.writeInt32(netToken.session_ID1);
+ outMsg.writeInt32(netToken.session_ID2);
+ // [Fate] The next word is unused by the old char server, so we squeeze in
+ // tmw client version information
+ outMsg.writeInt16(CLIENT_PROTOCOL_VERSION);
+ outMsg.writeInt8((netToken.sex == GENDER_MALE) ? 1 : 0);
+
+ // We get 4 useless bytes before the real answer comes in (what are these?)
+ mNetwork->skip(4);
+}
+
} // namespace EAthena
diff --git a/src/net/ea/charserverhandler.h b/src/net/ea/charserverhandler.h
index 3ebac16e..aa36f873 100644
--- a/src/net/ea/charserverhandler.h
+++ b/src/net/ea/charserverhandler.h
@@ -24,6 +24,9 @@
#include "net/messagehandler.h"
#include "net/charhandler.h"
+#include "net/serverinfo.h"
+
+#include "net/ea/token.h"
class LoginData;
@@ -49,7 +52,7 @@ class CharServerHandler : public MessageHandler, public Net::CharHandler
*/
void setCharCreateDialog(CharCreateDialog *window);
- void connect(LoginData *loginData);
+ void getCharacters();
void chooseCharacter(int slot, LocalPlayer* character);
@@ -58,8 +61,9 @@ class CharServerHandler : public MessageHandler, public Net::CharHandler
void deleteCharacter(int slot, LocalPlayer* character);
+ void connect();
+
protected:
- LoginData *mLoginData;
LockedArray<LocalPlayer*> *mCharInfo;
CharCreateDialog *mCharCreateDialog;
diff --git a/src/net/ea/maphandler.cpp b/src/net/ea/gamehandler.cpp
index c3c9437c..f84688a3 100644
--- a/src/net/ea/maphandler.cpp
+++ b/src/net/ea/gamehandler.cpp
@@ -19,7 +19,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include "net/ea/maphandler.h"
+#include "net/ea/gamehandler.h"
#include "net/ea/network.h"
#include "net/ea/protocol.h"
@@ -37,12 +37,14 @@
#include "utils/gettext.h"
#include "utils/stringutils.h"
-Net::MapHandler *mapHandler;
+Net::GameHandler *gameHandler;
extern Game *game;
namespace EAthena {
+extern Token netToken;
+extern ServerInfo mapServer;
-MapHandler::MapHandler()
+GameHandler::GameHandler()
{
static const Uint16 _messages[] = {
SMSG_MAP_LOGIN_SUCCESS,
@@ -51,10 +53,10 @@ MapHandler::MapHandler()
0
};
handledMessages = _messages;
- mapHandler = this;
+ gameHandler = this;
}
-void MapHandler::handleMessage(MessageIn &msg)
+void GameHandler::handleMessage(MessageIn &msg)
{
unsigned char direction;
@@ -68,9 +70,9 @@ void MapHandler::handleMessage(MessageIn &msg)
msg.skip(2); // unknown
logger->log("Protocol: Player start position: (%d, %d), Direction: %d",
x, y, direction);
- state = STATE_GAME;
+ // Switch now or we'll have problems
+ // state = STATE_GAME;
player_node->setTileCoords(x, y);
- game = new Game;
} break;
case SMSG_SERVER_PING:
@@ -85,43 +87,63 @@ void MapHandler::handleMessage(MessageIn &msg)
}
}
-#include <fstream>
-
-void MapHandler::connect(LoginData *loginData)
+void GameHandler::connect()
{
+ mNetwork->connect(mapServer);
+
// Send login infos
MessageOut outMsg(CMSG_MAP_SERVER_CONNECT);
- outMsg.writeInt32(loginData->account_ID);
+ outMsg.writeInt32(netToken.account_ID);
outMsg.writeInt32(player_node->getId());
- outMsg.writeInt32(loginData->session_ID1);
- outMsg.writeInt32(loginData->session_ID2);
- outMsg.writeInt8((loginData->sex == GENDER_MALE) ? 1 : 0);
+ outMsg.writeInt32(netToken.session_ID1);
+ outMsg.writeInt32(netToken.session_ID2);
+ outMsg.writeInt8((netToken.sex == GENDER_MALE) ? 1 : 0);
// Change the player's ID to the account ID to match what eAthena uses
- player_node->setId(loginData->account_ID);
+ player_node->setId(netToken.account_ID);
// We get 4 useless bytes before the real answer comes in (what are these?)
mNetwork->skip(4);
}
-void MapHandler::mapLoaded(const std::string &mapName)
+bool GameHandler::isConnected()
+{
+ return mNetwork->isConnected();
+}
+
+void GameHandler::disconnect()
+{
+ mNetwork->disconnect();
+}
+
+void GameHandler::inGame()
+{
+ // TODO
+}
+
+void GameHandler::mapLoaded(const std::string &mapName)
{
MessageOut outMsg(CMSG_MAP_LOADED);
}
-void MapHandler::who()
+void GameHandler::who()
{
}
-void MapHandler::quit()
+void GameHandler::quit()
{
MessageOut outMsg(CMSG_CLIENT_QUIT);
}
-void MapHandler::ping(int tick)
+void GameHandler::ping(int tick)
{
MessageOut msg(CMSG_CLIENT_PING);
msg.writeInt32(tick);
}
+void GameHandler::clear()
+{
+ disconnect();
+}
+
} // namespace EAthena
diff --git a/src/net/ea/maphandler.h b/src/net/ea/gamehandler.h
index 205ee18d..6cb640c1 100644
--- a/src/net/ea/maphandler.h
+++ b/src/net/ea/gamehandler.h
@@ -22,20 +22,29 @@
#ifndef NET_EA_MAPHANDLER_H
#define NET_EA_MAPHANDLER_H
-#include "net/maphandler.h"
+#include "net/gamehandler.h"
#include "net/messagehandler.h"
#include "net/net.h"
+#include "net/serverinfo.h"
+
+#include "net/ea/token.h"
namespace EAthena {
-class MapHandler : public MessageHandler, public Net::MapHandler
+class GameHandler : public MessageHandler, public Net::GameHandler
{
public:
- MapHandler();
+ GameHandler();
void handleMessage(MessageIn &msg);
- void connect(LoginData *loginData);
+ void connect();
+
+ bool isConnected();
+
+ void disconnect();
+
+ void inGame();
void mapLoaded(const std::string &mapName);
@@ -44,6 +53,9 @@ class MapHandler : public MessageHandler, public Net::MapHandler
void quit();
void ping(int tick);
+
+ void clear();
+
};
} // namespace EAthena
diff --git a/src/net/ea/generalhandler.cpp b/src/net/ea/generalhandler.cpp
index 1d500d62..1dde3b3f 100644
--- a/src/net/ea/generalhandler.cpp
+++ b/src/net/ea/generalhandler.cpp
@@ -22,11 +22,13 @@
#include "net/ea/generalhandler.h"
#include "gui/inventorywindow.h"
+#include "gui/register.h"
#include "gui/skilldialog.h"
#include "gui/statuswindow.h"
#include "net/ea/network.h"
#include "net/ea/protocol.h"
+#include "net/ea/token.h"
#include "net/ea/adminhandler.h"
#include "net/ea/beinghandler.h"
@@ -34,11 +36,10 @@
#include "net/ea/chathandler.h"
#include "net/ea/charserverhandler.h"
#include "net/ea/equipmenthandler.h"
+#include "net/ea/gamehandler.h"
#include "net/ea/inventoryhandler.h"
#include "net/ea/itemhandler.h"
#include "net/ea/loginhandler.h"
-#include "net/ea/logouthandler.h"
-#include "net/ea/maphandler.h"
#include "net/ea/npchandler.h"
#include "net/ea/playerhandler.h"
#include "net/ea/partyhandler.h"
@@ -63,6 +64,9 @@
Net::GeneralHandler *generalHandler;
namespace EAthena {
+Token netToken;
+ServerInfo charServer;
+ServerInfo mapServer;
GeneralHandler::GeneralHandler():
mAdminHandler(new AdminHandler),
@@ -71,11 +75,10 @@ GeneralHandler::GeneralHandler():
mCharHandler(new CharServerHandler),
mChatHandler(new ChatHandler),
mEquipmentHandler(new EquipmentHandler),
+ mGameHandler(new GameHandler),
mInventoryHandler(new InventoryHandler),
mItemHandler(new ItemHandler),
mLoginHandler(new LoginHandler),
- mLogoutHandler(new LogoutHandler),
- mMapHandler(new MapHandler),
mNpcHandler(new NpcHandler),
mPartyHandler(new PartyHandler),
mPlayerHandler(new PlayerHandler),
@@ -146,17 +149,18 @@ void GeneralHandler::handleMessage(MessageIn &msg)
void GeneralHandler::load()
{
+ (new Network)->registerHandler(this);
+
mNetwork->registerHandler(mAdminHandler.get());
mNetwork->registerHandler(mBeingHandler.get());
mNetwork->registerHandler(mBuySellHandler.get());
mNetwork->registerHandler(mChatHandler.get());
mNetwork->registerHandler(mCharHandler.get());
mNetwork->registerHandler(mEquipmentHandler.get());
+ mNetwork->registerHandler(mGameHandler.get());
mNetwork->registerHandler(mInventoryHandler.get());
mNetwork->registerHandler(mItemHandler.get());
mNetwork->registerHandler(mLoginHandler.get());
- mNetwork->registerHandler(mLogoutHandler.get());
- mNetwork->registerHandler(mMapHandler.get());
mNetwork->registerHandler(mNpcHandler.get());
mNetwork->registerHandler(mPlayerHandler.get());
mNetwork->registerHandler(mSpecialHandler.get());
@@ -203,6 +207,7 @@ void GeneralHandler::guiWindowsLoaded()
{
partyTab = new PartyTab;
inventoryWindow->setSplitAllowed(false);
+ RegisterDialog::setGender(&netToken.sex);
skillDialog->loadSkills("ea-skills.xml");
statusWindow->addAttribute(STR, _("Strength"), true);
@@ -226,4 +231,9 @@ void GeneralHandler::guiWindowsUnloaded()
delete partyTab;
}
+void GeneralHandler::clearHandlers()
+{
+ mNetwork->clearHandlers();
+}
+
} // namespace EAthena
diff --git a/src/net/ea/generalhandler.h b/src/net/ea/generalhandler.h
index 98364e5d..099bed0b 100644
--- a/src/net/ea/generalhandler.h
+++ b/src/net/ea/generalhandler.h
@@ -25,6 +25,7 @@
#include "net/generalhandler.h"
#include "net/messagehandler.h"
#include "net/net.h"
+#include "net/serverinfo.h"
namespace EAthena {
@@ -51,6 +52,8 @@ class GeneralHandler : public MessageHandler, public Net::GeneralHandler
void guiWindowsUnloaded();
+ void clearHandlers();
+
protected:
MessageHandlerPtr mAdminHandler;
MessageHandlerPtr mBeingHandler;
@@ -58,11 +61,10 @@ class GeneralHandler : public MessageHandler, public Net::GeneralHandler
MessageHandlerPtr mCharHandler;
MessageHandlerPtr mChatHandler;
MessageHandlerPtr mEquipmentHandler;
+ MessageHandlerPtr mGameHandler;
MessageHandlerPtr mInventoryHandler;
MessageHandlerPtr mItemHandler;
MessageHandlerPtr mLoginHandler;
- MessageHandlerPtr mLogoutHandler;
- MessageHandlerPtr mMapHandler;
MessageHandlerPtr mNpcHandler;
MessageHandlerPtr mPartyHandler;
MessageHandlerPtr mPlayerHandler;
diff --git a/src/net/ea/loginhandler.cpp b/src/net/ea/loginhandler.cpp
index 8e7187c0..d2e2adc0 100644
--- a/src/net/ea/loginhandler.cpp
+++ b/src/net/ea/loginhandler.cpp
@@ -21,24 +21,27 @@
#include "net/ea/loginhandler.h"
+#include "net/ea/network.h"
#include "net/ea/protocol.h"
#include "net/logindata.h"
#include "net/messagein.h"
#include "net/messageout.h"
-#include "net/serverinfo.h"
#include "log.h"
#include "main.h"
+#include "utils/dtor.h"
#include "utils/gettext.h"
#include "utils/stringutils.h"
-extern SERVER_INFO **server_info;
+Worlds worlds;
Net::LoginHandler *loginHandler;
namespace EAthena {
+extern Token netToken;
+extern ServerInfo charServer;
LoginHandler::LoginHandler()
{
@@ -47,6 +50,7 @@ LoginHandler::LoginHandler()
SMSG_LOGIN_DATA,
SMSG_LOGIN_ERROR,
SMSG_CHAR_PASSWORD_RESPONSE,
+ SMSG_SERVER_VERSION_RESPONSE,
0
};
handledMessages = _messages;
@@ -55,7 +59,7 @@ LoginHandler::LoginHandler()
void LoginHandler::handleMessage(MessageIn &msg)
{
- int code;
+ int code, worldCount;
switch (msg.getId())
{
@@ -104,33 +108,34 @@ void LoginHandler::handleMessage(MessageIn &msg)
// Skip the length word
msg.skip(2);
- n_server = (msg.getLength() - 47) / 32;
- server_info =
- (SERVER_INFO**) malloc(sizeof(SERVER_INFO*) * n_server);
+ delete_all(worlds);
+ worldCount = (msg.getLength() - 47) / 32;
- mLoginData->session_ID1 = msg.readInt32();
- mLoginData->account_ID = msg.readInt32();
- mLoginData->session_ID2 = msg.readInt32();
+ netToken.session_ID1 = msg.readInt32();
+ netToken.account_ID = msg.readInt32();
+ netToken.session_ID2 = msg.readInt32();
msg.skip(30); // unknown
- mLoginData->sex = msg.readInt8() ? GENDER_MALE : GENDER_FEMALE;
+ netToken.sex = msg.readInt8() ? GENDER_MALE : GENDER_FEMALE;
- for (int i = 0; i < n_server; i++)
+ for (int i = 0; i < worldCount; i++)
{
- server_info[i] = new SERVER_INFO;
+ WorldInfo *world = new WorldInfo;
- server_info[i]->address = msg.readInt32();
- server_info[i]->port = msg.readInt16();
- server_info[i]->name = msg.readString(20);
- server_info[i]->online_users = msg.readInt32();
- server_info[i]->updateHost = mUpdateHost;
+ world->address = msg.readInt32();
+ world->port = msg.readInt16();
+ world->name = msg.readString(20);
+ world->online_users = msg.readInt32();
+ world->updateHost = mUpdateHost;
msg.skip(2); // unknown
logger->log("Network: Server: %s (%s:%d)",
- server_info[i]->name.c_str(),
- ipToString(server_info[i]->address),
- server_info[i]->port);
+ world->name.c_str(),
+ ipToString(world->address),
+ world->port);
+
+ worlds.push_back(world);
}
- state = STATE_CHAR_SERVER;
+ state = STATE_WORLD_SELECT;
break;
case SMSG_LOGIN_ERROR:
@@ -171,9 +176,40 @@ void LoginHandler::handleMessage(MessageIn &msg)
}
state = STATE_ERROR;
break;
+ case SMSG_SERVER_VERSION_RESPONSE:
+ {
+ // TODO: verify these!
+ msg.readInt8(); // -1
+ msg.readInt8(); // T
+ msg.readInt8(); // M
+ msg.readInt8(); // W
+ msg.readInt8(); // (space)
+ msg.readInt8(); // e
+ msg.readInt8(); // A
+
+ //state = STATE_LOGIN;
+ }
+ break;
}
}
+void LoginHandler::connect()
+{
+ mNetwork->connect(mServer);
+ MessageOut outMsg(CMSG_SERVER_VERSION_REQUEST);
+}
+
+bool LoginHandler::isConnected()
+{
+ return mNetwork->isConnected();
+}
+
+void LoginHandler::disconnect()
+{
+ if (mNetwork->getServer() == mServer)
+ mNetwork->disconnect();
+}
+
void LoginHandler::loginAccount(LoginData *loginData)
{
mLoginData = loginData;
@@ -194,9 +230,14 @@ void LoginHandler::changePassword(const std::string &username,
outMsg.writeString(newPassword, 24);
}
-void LoginHandler::chooseServer(int server)
+void LoginHandler::chooseServer(unsigned int server)
{
- // TODO
+ if (server >= worlds.size())
+ return;
+
+ charServer.clear();
+ charServer.hostname = ipToString(worlds[server]->address);
+ charServer.port = worlds[server]->port;
}
void LoginHandler::registerAccount(LoginData *loginData)
@@ -204,7 +245,7 @@ void LoginHandler::registerAccount(LoginData *loginData)
mLoginData = loginData;
std::string username = loginData->username;
- username.append((loginData->sex == GENDER_FEMALE) ? "_F" : "_M");
+ username.append((netToken.sex == GENDER_FEMALE) ? "_F" : "_M");
sendLoginRegister(username, loginData->password);
}
@@ -232,4 +273,9 @@ void LoginHandler::sendLoginRegister(const std::string &username,
outMsg.writeInt8(0x03);
}
+Worlds LoginHandler::getWorlds()
+{
+ return worlds;
+}
+
} // namespace EAthena
diff --git a/src/net/ea/loginhandler.h b/src/net/ea/loginhandler.h
index 93f21754..bc1aa816 100644
--- a/src/net/ea/loginhandler.h
+++ b/src/net/ea/loginhandler.h
@@ -25,6 +25,8 @@
#include "net/loginhandler.h"
#include "net/messagehandler.h"
+#include "net/ea/token.h"
+
#include <string>
struct LoginData;
@@ -38,6 +40,12 @@ class LoginHandler : public MessageHandler, public Net::LoginHandler
void handleMessage(MessageIn &msg);
+ void connect();
+
+ bool isConnected();
+
+ void disconnect();
+
void loginAccount(LoginData *loginData);
void changeEmail(const std::string &email);
@@ -46,13 +54,15 @@ class LoginHandler : public MessageHandler, public Net::LoginHandler
const std::string &oldPassword,
const std::string &newPassword);
- void chooseServer(int server);
+ void chooseServer(unsigned int server);
void registerAccount(LoginData *loginData);
void unregisterAccount(const std::string &username,
const std::string &password);
+ Worlds getWorlds();
+
private:
void sendLoginRegister(const std::string &username,
const std::string &password);
diff --git a/src/net/ea/logouthandler.cpp b/src/net/ea/logouthandler.cpp
deleted file mode 100644
index 7de87c6a..00000000
--- a/src/net/ea/logouthandler.cpp
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * The Mana World
- * Copyright (C) 2004 The Mana World Development Team
- *
- * This file is part of The Mana World.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include "net/ea/logouthandler.h"
-
-#include "net/ea/protocol.h"
-
-#include "net/logindata.h"
-#include "net/messagein.h"
-#include "net/messageout.h"
-#include "net/serverinfo.h"
-
-#include "log.h"
-#include "main.h"
-
-#include "utils/gettext.h"
-#include "utils/stringutils.h"
-
-Net::LogoutHandler *logoutHandler;
-
-namespace EAthena {
-
-LogoutHandler::LogoutHandler()
-{
- static const Uint16 _messages[] = {
- 0
- };
- handledMessages = _messages;
- logoutHandler = this;
-}
-
-void LogoutHandler::handleMessage(MessageIn &msg)
-{
-}
-
-void LogoutHandler::setScenario(unsigned short scenario,
- std::string *passToken)
-{
- // TODO
-}
-
-void LogoutHandler::reset()
-{
- // TODO
-}
-
-} // namespace EAthena
diff --git a/src/net/ea/logouthandler.h b/src/net/ea/logouthandler.h
deleted file mode 100644
index 0d118ab0..00000000
--- a/src/net/ea/logouthandler.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * The Mana World
- * Copyright (C) 2004 The Mana World Development Team
- *
- * This file is part of The Mana World.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#ifndef NET_EA_LOGOUTHANDLER_H
-#define NET_EA_LOGOUTHANDLER_H
-
-#include "net/logouthandler.h"
-#include "net/messagehandler.h"
-
-#include <string>
-
-namespace EAthena {
-
-class LogoutHandler : public MessageHandler, public Net::LogoutHandler
-{
- public:
- LogoutHandler();
-
- void handleMessage(MessageIn &msg);
-
- void setScenario(unsigned short scenario,
- std::string *passToken = NULL);
-
- void reset();
-};
-
-} // namespace EAthena
-
-#endif // NET_EA_LOGOUTHANDLER_H
diff --git a/src/net/ea/network.cpp b/src/net/ea/network.cpp
index c6bc712c..68bdc870 100644
--- a/src/net/ea/network.cpp
+++ b/src/net/ea/network.cpp
@@ -21,12 +21,16 @@
#include "net/ea/network.h"
+#include "net/ea/protocol.h"
+
#include "net/messagehandler.h"
#include "net/messagein.h"
-#include "log.h"
#include "utils/stringutils.h"
+#include "log.h"
+
+#include <assert.h>
#include <sstream>
/** Warning: buffers and other variables are shared,
@@ -95,7 +99,6 @@ Network *Network::mInstance = 0;
Network::Network():
mSocket(0),
- mAddress(), mPort(0),
mInBuffer(new char[BUFFER_SIZE]),
mOutBuffer(new char[BUFFER_SIZE]),
mInSize(0), mOutSize(0),
@@ -125,24 +128,26 @@ Network::~Network()
SDLNet_Quit();
}
-bool Network::connect(const std::string &address, short port)
+bool Network::connect(ServerInfo server)
{
if (mState != IDLE && mState != NET_ERROR)
{
logger->log("Tried to connect an already connected socket!");
+ assert(false);
return false;
}
- if (address.empty())
+ if (server.hostname.empty())
{
setError("Empty address given to Network::connect()!");
return false;
}
- logger->log("Network::Connecting to %s:%i", address.c_str(), port);
+ logger->log("Network::Connecting to %s:%i", server.hostname.c_str(),
+ server.port);
- mAddress = address;
- mPort = port;
+ mServer.hostname = server.hostname;
+ mServer.port = server.port;
// Reset to sane values
mOutSize = 0;
@@ -269,12 +274,16 @@ void Network::skip(int len)
bool Network::messageReady()
{
- int len = -1;
+ int len = -1, msgId;
SDL_mutexP(mMutex);
if (mInSize >= 2)
{
- len = packet_lengths[readWord(0)];
+ msgId = readWord(0);
+ if (msgId == SMSG_SERVER_VERSION_RESPONSE)
+ len = 10;
+ else
+ len = packet_lengths[msgId];
if (len == -1 && mInSize > 4)
len = readWord(2);
@@ -297,7 +306,11 @@ MessageIn Network::getNextMessage()
SDL_mutexP(mMutex);
int msgId = readWord(0);
- int len = packet_lengths[msgId];
+ int len;
+ if (msgId == SMSG_SERVER_VERSION_RESPONSE)
+ len = 10;
+ else
+ len = packet_lengths[msgId];
if (len == -1)
len = readWord(2);
@@ -316,9 +329,11 @@ bool Network::realConnect()
{
IPaddress ipAddress;
- if (SDLNet_ResolveHost(&ipAddress, mAddress.c_str(), mPort) == -1)
+ if (SDLNet_ResolveHost(&ipAddress, mServer.hostname.c_str(),
+ mServer.port) == -1)
{
- std::string errorMessage = "Unable to resolve host \"" + mAddress + "\"";
+ std::string errorMessage = "Unable to resolve host \"" +
+ mServer.hostname + "\"";
setError(errorMessage);
logger->log("SDLNet_ResolveHost: %s", errorMessage.c_str());
return false;
diff --git a/src/net/ea/network.h b/src/net/ea/network.h
index 741a8297..b61f363b 100644
--- a/src/net/ea/network.h
+++ b/src/net/ea/network.h
@@ -22,6 +22,8 @@
#ifndef EA_NETWORK_H
#define EA_NETWORK_H
+#include "net/serverinfo.h"
+
#include <SDL_net.h>
#include <SDL_thread.h>
@@ -47,10 +49,13 @@ class Network
~Network();
- bool connect(const std::string &address, short port);
+ bool connect(ServerInfo server);
void disconnect();
+ ServerInfo getServer()
+ { return mServer; }
+
void registerHandler(MessageHandler *handler);
void unregisterHandler(MessageHandler *handler);
@@ -97,8 +102,7 @@ class Network
TCPsocket mSocket;
- std::string mAddress;
- short mPort;
+ ServerInfo mServer;
char *mInBuffer, *mOutBuffer;
unsigned int mInSize, mOutSize;
diff --git a/src/net/ea/playerhandler.cpp b/src/net/ea/playerhandler.cpp
index 3e379d82..ae94ab92 100644
--- a/src/net/ea/playerhandler.cpp
+++ b/src/net/ea/playerhandler.cpp
@@ -548,7 +548,7 @@ void PlayerHandler::changeAction(Being::Action action)
void PlayerHandler::respawn()
{
- MessageOut outMsg(CMSG_PLAYER_RESPAWN);
+ MessageOut outMsg(CMSG_PLAYER_RESTART);
outMsg.writeInt8(0);
}
diff --git a/src/net/ea/protocol.h b/src/net/ea/protocol.h
index 07350841..8f3e40b5 100644
--- a/src/net/ea/protocol.h
+++ b/src/net/ea/protocol.h
@@ -47,6 +47,8 @@ static const int STORAGE_OFFSET = 1;
/*********************************
* Packets from server to client *
*********************************/
+#define SMSG_SERVER_VERSION_RESPONSE 0x7531
+
#define SMSG_SERVER_PING 0x007f /**< Contains server tick */
#define SMSG_CONNECTION_PROBLEM 0x0081
@@ -162,6 +164,8 @@ static const int STORAGE_OFFSET = 1;
/**********************************
* Packets from client to server *
**********************************/
+#define CMSG_SERVER_VERSION_REQUEST 0x7530
+
#define CMSG_CHAR_PASSWORD_CHANGE 0x0061 /**< Custom change password packet */
#define CMSG_CHAR_SERVER_CONNECT 0x0065
#define CMSG_CHAR_SELECT 0x0066
@@ -195,7 +199,7 @@ static const int STORAGE_OFFSET = 1;
#define CMSG_PLAYER_CHANGE_DIR 0x009b
#define CMSG_PLAYER_CHANGE_DEST 0x0085
#define CMSG_PLAYER_CHANGE_ACT 0x0089
-#define CMSG_PLAYER_RESPAWN 0x00b2
+#define CMSG_PLAYER_RESTART 0x00b2
#define CMSG_PLAYER_EMOTE 0x00bf
#define CMSG_PLAYER_ATTACK 0x0089
#define CMSG_WHO_REQUEST 0x00c1
diff --git a/src/net/maphandler.h b/src/net/gamehandler.h
index 6c91f4ef..062b6770 100644
--- a/src/net/maphandler.h
+++ b/src/net/gamehandler.h
@@ -28,10 +28,16 @@
namespace Net {
-class MapHandler
+class GameHandler
{
public:
- virtual void connect(LoginData *loginData) = 0;
+ virtual void connect() = 0;
+
+ virtual bool isConnected() = 0;
+
+ virtual void disconnect() = 0;
+
+ virtual void inGame() = 0;
virtual void mapLoaded(const std::string &mapName) = 0;
@@ -40,6 +46,8 @@ class MapHandler
virtual void quit() = 0;
virtual void ping(int tick) = 0;
+
+ virtual void clear() = 0;
};
} // namespace Net
diff --git a/src/net/generalhandler.h b/src/net/generalhandler.h
index 3865ca92..3b081834 100644
--- a/src/net/generalhandler.h
+++ b/src/net/generalhandler.h
@@ -19,6 +19,8 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+#include "main.h"
+
#ifndef GENERALHANDLER_H
#define GENERALHANDLER_H
@@ -40,6 +42,8 @@ class GeneralHandler
virtual void guiWindowsLoaded() = 0;
virtual void guiWindowsUnloaded() = 0;
+
+ virtual void clearHandlers() = 0;
};
} // namespace Net
diff --git a/src/net/logindata.h b/src/net/logindata.h
index db7aafff..5e72f8fd 100644
--- a/src/net/logindata.h
+++ b/src/net/logindata.h
@@ -25,28 +25,18 @@
#include <string>
#include "player.h"
+#include "net/serverinfo.h"
struct LoginData
{
std::string username;
std::string password;
std::string newPassword;
- std::string hostname;
std::string updateHost;
-#ifdef TMWSERV_SUPPORT
std::string email;
std::string newEmail;
-#endif
- short port;
-#ifdef EATHENA_SUPPORT
- int account_ID;
- int session_ID1;
- int session_ID2;
- Gender sex;
-#endif
-
- bool remember; /**< Whether to store the username and host. */
+ bool remember; /**< Whether to store the username. */
bool registerLogin; /**< Whether an account is being registered. */
void clear()
@@ -54,20 +44,9 @@ struct LoginData
username.clear();
password.clear();
newPassword.clear();
- hostname.clear();
updateHost.clear();
-#ifdef TMWSERV_SUPPORT
email.clear();
newEmail.clear();
-#endif
- port = 0;
-
-#ifdef EATHENA_SUPPORT
- account_ID = 0;
- session_ID1 = 0;
- session_ID2 = 0;
- sex = GENDER_UNSPECIFIED;
-#endif
}
};
diff --git a/src/net/loginhandler.h b/src/net/loginhandler.h
index fdd57689..26dfb53b 100644
--- a/src/net/loginhandler.h
+++ b/src/net/loginhandler.h
@@ -24,13 +24,29 @@
#include "logindata.h"
+#include "net/serverinfo.h"
+#include "net/worldinfo.h"
+
#include <iosfwd>
+#include <vector>
namespace Net {
class LoginHandler
{
public:
+ virtual void setServer(const ServerInfo &server)
+ { mServer = server; }
+
+ virtual ServerInfo getServer()
+ { return mServer; }
+
+ virtual void connect() = 0;
+
+ virtual bool isConnected() = 0;
+
+ virtual void disconnect() = 0;
+
virtual void loginAccount(LoginData *loginData) = 0;
virtual void changeEmail(const std::string &email) = 0;
@@ -39,12 +55,17 @@ class LoginHandler
const std::string &oldPassword,
const std::string &newPassword) = 0;
- virtual void chooseServer(int server) = 0;
+ virtual void chooseServer(unsigned int server) = 0;
virtual void registerAccount(LoginData *loginData) = 0;
virtual void unregisterAccount(const std::string &username,
const std::string &password) = 0;
+
+ virtual Worlds getWorlds() = 0;
+
+ protected:
+ ServerInfo mServer;
};
} // namespace Net
diff --git a/src/net/messagehandler.h b/src/net/messagehandler.h
index 28d4fea5..c89f3dcd 100644
--- a/src/net/messagehandler.h
+++ b/src/net/messagehandler.h
@@ -22,6 +22,8 @@
#ifndef NET_MESSAGEHANDLER_H
#define NET_MESSAGEHANDLER_H
+#include "net/messagein.h"
+
#include <SDL_types.h>
#include <memory>
diff --git a/src/net/messageout.cpp b/src/net/messageout.cpp
index 4333ac85..133aac96 100644
--- a/src/net/messageout.cpp
+++ b/src/net/messageout.cpp
@@ -38,6 +38,7 @@ MessageOut::MessageOut(short id):
mDataSize(0),
mPos(0)
{
+ mID = id;
#ifdef EATHENA_SUPPORT
mNetwork = Network::instance();
mData = mNetwork->mOutBuffer + mNetwork->mOutSize;
diff --git a/src/net/messageout.h b/src/net/messageout.h
index 5027ea47..f44aaa95 100644
--- a/src/net/messageout.h
+++ b/src/net/messageout.h
@@ -80,6 +80,8 @@ class MessageOut
*/
unsigned int getDataSize() const;
+ short mID;
+
private:
#ifdef TMWSERV_SUPPORT
/**
diff --git a/src/net/net.cpp b/src/net/net.cpp
index 7df336c6..6a9c072a 100644
--- a/src/net/net.cpp
+++ b/src/net/net.cpp
@@ -21,6 +21,8 @@
#include "net/net.h"
+#include "main.h"
+
#include "net/adminhandler.h"
#include "net/charhandler.h"
#include "net/chathandler.h"
@@ -28,22 +30,26 @@
#include "net/guildhandler.h"
#include "net/inventoryhandler.h"
#include "net/loginhandler.h"
-#include "net/logouthandler.h"
-#include "net/maphandler.h"
+#include "net/gamehandler.h"
#include "net/npchandler.h"
#include "net/partyhandler.h"
#include "net/playerhandler.h"
#include "net/specialhandler.h"
#include "net/tradehandler.h"
+#ifdef TMWSERV_SUPPORT
+#include "net/tmwserv/generalhandler.h"
+#else
+#include "net/ea/generalhandler.h"
+#endif
+
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::GameHandler *gameHandler;
extern Net::NpcHandler *npcHandler;
extern Net::PartyHandler *partyHandler;
extern Net::PlayerHandler *playerHandler;
@@ -65,6 +71,11 @@ Net::ChatHandler *Net::getChatHandler()
return chatHandler;
}
+Net::GameHandler *Net::getGameHandler()
+{
+ return gameHandler;
+}
+
Net::GeneralHandler *Net::getGeneralHandler()
{
return generalHandler;
@@ -86,16 +97,6 @@ Net::LoginHandler *Net::getLoginHandler()
return loginHandler;
}
-Net::LogoutHandler *Net::getLogoutHandler()
-{
- return logoutHandler;
-}
-
-Net::MapHandler *Net::getMapHandler()
-{
- return mapHandler;
-}
-
Net::NpcHandler *Net::getNpcHandler()
{
return npcHandler;
@@ -120,3 +121,21 @@ Net::TradeHandler *Net::getTradeHandler()
{
return tradeHandler;
}
+
+void Net::connectToServer(const ServerInfo &server)
+{
+ // TODO: Actually query the server about itself and choose the netcode
+ // based on that
+
+#ifdef TMWSERV_SUPPORT
+ new TmwServ::GeneralHandler;
+#else
+ new EAthena::GeneralHandler;
+#endif
+
+ Net::getGeneralHandler()->load();
+
+ Net::getLoginHandler()->setServer(server);
+
+ Net::getLoginHandler()->connect();
+}
diff --git a/src/net/net.h b/src/net/net.h
index 1d91faa7..5b0c92f4 100644
--- a/src/net/net.h
+++ b/src/net/net.h
@@ -19,6 +19,8 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+#include "net/serverinfo.h"
+
#ifndef NET_H
#define NET_H
@@ -27,12 +29,11 @@ namespace Net {
class AdminHandler;
class CharHandler;
class ChatHandler;
+class GameHandler;
class GeneralHandler;
class GuildHandler;
class InventoryHandler;
class LoginHandler;
-class LogoutHandler;
-class MapHandler;
class NpcHandler;
class PartyHandler;
class PlayerHandler;
@@ -42,18 +43,22 @@ class TradeHandler;
AdminHandler *getAdminHandler();
CharHandler *getCharHandler();
ChatHandler *getChatHandler();
+GameHandler *getGameHandler();
GeneralHandler *getGeneralHandler();
GuildHandler *getGuildHandler();
InventoryHandler *getInventoryHandler();
LoginHandler *getLoginHandler();
-LogoutHandler *getLogoutHandler();
-MapHandler *getMapHandler();
NpcHandler *getNpcHandler();
PartyHandler *getPartyHandler();
PlayerHandler *getPlayerHandler();
SpecialHandler *getSpecialHandler();
TradeHandler *getTradeHandler();
+/**
+ * Handles server detection and connection
+ */
+void connectToServer(const ServerInfo &server);
+
} // namespace Net
#endif // NET_H
diff --git a/src/net/serverinfo.h b/src/net/serverinfo.h
index c38d13c7..ac2e803d 100644
--- a/src/net/serverinfo.h
+++ b/src/net/serverinfo.h
@@ -1,6 +1,6 @@
/*
* The Mana World
- * Copyright (C) 2004 The Mana World Development Team
+ * Copyright (C) 2009 The Mana World Development Team
*
* This file is part of The Mana World.
*
@@ -19,18 +19,25 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#ifndef SERVERINFO_
-#define SERVERINFO_
+#ifndef SERVERINFO_H
+#define SERVERINFO_H
#include <string>
-struct SERVER_INFO
-{
- int address;
- short port;
- std::string name;
- short online_users;
- std::string updateHost;
-};
+typedef struct SERVER_INFO {
+ std::string hostname;
+ unsigned short port;
-#endif
+ void clear()
+ {
+ hostname.clear();
+ port = 0;
+ }
+
+ bool operator==(struct SERVER_INFO other)
+ {
+ return (hostname == other.hostname && port == other.port);
+ }
+} ServerInfo;
+
+#endif // SERVERINFO_H
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
diff --git a/src/net/logouthandler.h b/src/net/worldinfo.h
index f6c44e5c..045c64c2 100644
--- a/src/net/logouthandler.h
+++ b/src/net/worldinfo.h
@@ -19,31 +19,20 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#ifndef LOGOUTHANDLER_H
-#define LOGOUTHANDLER_H
+#ifndef WORLD_INFO_H
+#define WORLD_INFO_H
-#include "logindata.h"
+#include <string>
+#include <vector>
-#include <iosfwd>
+typedef struct {
+ int address;
+ std::string name;
+ short port;
+ short online_users;
+ std::string updateHost;
+} WorldInfo;
-/**
- * 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;
-};
-}
+typedef std::vector<WorldInfo*> Worlds;
-#endif // LOGOUTHANDLER_H
+#endif // WORLD_INFO_H