summaryrefslogtreecommitdiff
path: root/src/net/ea
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <bjorn@lindeijer.nl>2009-10-06 23:40:55 +0200
committerThorbjørn Lindeijer <bjorn@lindeijer.nl>2009-10-06 23:43:40 +0200
commit64a37da4cb8d74a29f369e96e8c3669275516394 (patch)
treecaa0eb0d05ab5674b6b6ac822d151aa2585721e8 /src/net/ea
parent610dc30ceecdfe538f71826689630e0f28c278cc (diff)
downloadmana-64a37da4cb8d74a29f369e96e8c3669275516394.tar.gz
mana-64a37da4cb8d74a29f369e96e8c3669275516394.tar.bz2
mana-64a37da4cb8d74a29f369e96e8c3669275516394.tar.xz
mana-64a37da4cb8d74a29f369e96e8c3669275516394.zip
Some cleanup regarding keeping track of gender for eAthena
LoginHandler now owns the world list and the token, instead of having them as global variables with pointers to the 'sex' member of the token from the GUI.
Diffstat (limited to 'src/net/ea')
-rw-r--r--src/net/ea/charserverhandler.cpp26
-rw-r--r--src/net/ea/gamehandler.cpp16
-rw-r--r--src/net/ea/gamehandler.h1
-rw-r--r--src/net/ea/generalhandler.cpp8
-rw-r--r--src/net/ea/loginhandler.cpp35
-rw-r--r--src/net/ea/loginhandler.h9
-rw-r--r--src/net/ea/network.h2
-rw-r--r--src/net/ea/token.h5
8 files changed, 61 insertions, 41 deletions
diff --git a/src/net/ea/charserverhandler.cpp b/src/net/ea/charserverhandler.cpp
index e538eeaf..13c3cf45 100644
--- a/src/net/ea/charserverhandler.cpp
+++ b/src/net/ea/charserverhandler.cpp
@@ -21,13 +21,14 @@
#include "net/ea/charserverhandler.h"
-#include "net/ea/generalhandler.h"
+#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/net.h"
#include "game.h"
#include "log.h"
@@ -44,7 +45,7 @@
Net::CharHandler *charHandler;
namespace EAthena {
-extern Token netToken;
+
extern ServerInfo charServer;
extern ServerInfo mapServer;
@@ -177,8 +178,11 @@ void CharServerHandler::handleMessage(MessageIn &msg)
LocalPlayer *CharServerHandler::readPlayerData(MessageIn &msg, int &slot)
{
+ const Token &token =
+ static_cast<LoginHandler*>(Net::getLoginHandler())->getToken();
+
LocalPlayer *tempPlayer = new LocalPlayer(msg.readInt32(), 0, NULL);
- tempPlayer->setGender(netToken.sex);
+ tempPlayer->setGender(token.sex);
tempPlayer->setExp(msg.readInt32());
tempPlayer->setMoney(msg.readInt32());
@@ -241,8 +245,11 @@ void CharServerHandler::setCharCreateDialog(CharCreateDialog *window)
attributes.push_back(_("Dexterity:"));
attributes.push_back(_("Luck:"));
+ const Token &token =
+ static_cast<LoginHandler*>(Net::getLoginHandler())->getToken();
+
mCharCreateDialog->setAttributes(attributes, 30, 1, 9);
- mCharCreateDialog->setFixedGender(true, netToken.sex);
+ mCharCreateDialog->setFixedGender(true, token.sex);
}
void CharServerHandler::getCharacters()
@@ -279,16 +286,19 @@ void CharServerHandler::deleteCharacter(int slot, LocalPlayer* character)
void CharServerHandler::connect()
{
+ const Token &token =
+ static_cast<LoginHandler*>(Net::getLoginHandler())->getToken();
+
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);
+ outMsg.writeInt32(token.account_ID);
+ outMsg.writeInt32(token.session_ID1);
+ outMsg.writeInt32(token.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);
+ outMsg.writeInt8((token.sex == GENDER_MALE) ? 1 : 0);
// We get 4 useless bytes before the real answer comes in (what are these?)
mNetwork->skip(4);
diff --git a/src/net/ea/gamehandler.cpp b/src/net/ea/gamehandler.cpp
index f84688a3..a3c0ad3a 100644
--- a/src/net/ea/gamehandler.cpp
+++ b/src/net/ea/gamehandler.cpp
@@ -21,6 +21,7 @@
#include "net/ea/gamehandler.h"
+#include "net/ea/loginhandler.h"
#include "net/ea/network.h"
#include "net/ea/protocol.h"
@@ -41,7 +42,7 @@ Net::GameHandler *gameHandler;
extern Game *game;
namespace EAthena {
-extern Token netToken;
+
extern ServerInfo mapServer;
GameHandler::GameHandler()
@@ -91,16 +92,19 @@ void GameHandler::connect()
{
mNetwork->connect(mapServer);
+ const Token &token =
+ static_cast<LoginHandler*>(Net::getLoginHandler())->getToken();
+
// Send login infos
MessageOut outMsg(CMSG_MAP_SERVER_CONNECT);
- outMsg.writeInt32(netToken.account_ID);
+ outMsg.writeInt32(token.account_ID);
outMsg.writeInt32(player_node->getId());
- outMsg.writeInt32(netToken.session_ID1);
- outMsg.writeInt32(netToken.session_ID2);
- outMsg.writeInt8((netToken.sex == GENDER_MALE) ? 1 : 0);
+ outMsg.writeInt32(token.session_ID1);
+ outMsg.writeInt32(token.session_ID2);
+ outMsg.writeInt8((token.sex == GENDER_MALE) ? 1 : 0);
// Change the player's ID to the account ID to match what eAthena uses
- player_node->setId(netToken.account_ID);
+ player_node->setId(token.account_ID);
// We get 4 useless bytes before the real answer comes in (what are these?)
mNetwork->skip(4);
diff --git a/src/net/ea/gamehandler.h b/src/net/ea/gamehandler.h
index 6cb640c1..d8adeeaf 100644
--- a/src/net/ea/gamehandler.h
+++ b/src/net/ea/gamehandler.h
@@ -55,7 +55,6 @@ class GameHandler : public MessageHandler, public Net::GameHandler
void ping(int tick);
void clear();
-
};
} // namespace EAthena
diff --git a/src/net/ea/generalhandler.cpp b/src/net/ea/generalhandler.cpp
index c3eab725..78a10423 100644
--- a/src/net/ea/generalhandler.cpp
+++ b/src/net/ea/generalhandler.cpp
@@ -29,7 +29,6 @@
#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"
@@ -67,10 +66,8 @@ Net::GeneralHandler *generalHandler = NULL;
namespace EAthena {
-Token netToken;
ServerInfo charServer;
ServerInfo mapServer;
-Worlds worlds;
GeneralHandler::GeneralHandler():
mAdminHandler(new AdminHandler),
@@ -106,8 +103,6 @@ GeneralHandler::GeneralHandler():
stats.push_back(ItemDB::Stat("luck", N_("Luck %+d")));
ItemDB::setStatsList(stats);
-
- RegisterDialog::setGender(&netToken.sex);
}
GeneralHandler::~GeneralHandler()
@@ -179,7 +174,8 @@ void GeneralHandler::reload()
{
if (mNetwork)
mNetwork->disconnect();
- worlds.clear();
+
+ static_cast<LoginHandler*>(mLoginHandler.get())->clearWorlds();
}
void GeneralHandler::unload()
diff --git a/src/net/ea/loginhandler.cpp b/src/net/ea/loginhandler.cpp
index be547afa..5a77cce7 100644
--- a/src/net/ea/loginhandler.cpp
+++ b/src/net/ea/loginhandler.cpp
@@ -38,9 +38,8 @@
Net::LoginHandler *loginHandler;
namespace EAthena {
-extern Token netToken;
+
extern ServerInfo charServer;
-extern Worlds worlds;
LoginHandler::LoginHandler()
{
@@ -107,16 +106,16 @@ void LoginHandler::handleMessage(MessageIn &msg)
// Skip the length word
msg.skip(2);
- delete_all(worlds);
+ clearWorlds();
+
worldCount = (msg.getLength() - 47) / 32;
- netToken.session_ID1 = msg.readInt32();
- netToken.account_ID = msg.readInt32();
- netToken.session_ID2 = msg.readInt32();
+ mToken.session_ID1 = msg.readInt32();
+ mToken.account_ID = msg.readInt32();
+ mToken.session_ID2 = msg.readInt32();
msg.skip(30); // unknown
- netToken.sex = msg.readInt8() ? GENDER_MALE : GENDER_FEMALE;
+ mToken.sex = msg.readInt8() ? GENDER_MALE : GENDER_FEMALE;
- worlds.clear();
for (int i = 0; i < worldCount; i++)
{
WorldInfo *world = new WorldInfo;
@@ -133,7 +132,7 @@ void LoginHandler::handleMessage(MessageIn &msg)
ipToString(world->address),
world->port);
- worlds.push_back(world);
+ mWorlds.push_back(world);
}
state = STATE_WORLD_SELECT;
break;
@@ -236,12 +235,12 @@ void LoginHandler::changePassword(const std::string &username,
void LoginHandler::chooseServer(unsigned int server)
{
- if (server >= worlds.size())
+ if (server >= mWorlds.size())
return;
charServer.clear();
- charServer.hostname = ipToString(worlds[server]->address);
- charServer.port = worlds[server]->port;
+ charServer.hostname = ipToString(mWorlds[server]->address);
+ charServer.port = mWorlds[server]->port;
state = STATE_UPDATE;
}
@@ -249,7 +248,7 @@ void LoginHandler::chooseServer(unsigned int server)
void LoginHandler::registerAccount(LoginData *loginData)
{
std::string username = loginData->username;
- username.append((netToken.sex == GENDER_FEMALE) ? "_F" : "_M");
+ username.append((loginData->gender == GENDER_FEMALE) ? "_F" : "_M");
sendLoginRegister(username, loginData->password);
}
@@ -277,9 +276,15 @@ void LoginHandler::sendLoginRegister(const std::string &username,
outMsg.writeInt8(0x03);
}
-Worlds LoginHandler::getWorlds()
+Worlds LoginHandler::getWorlds() const
+{
+ return mWorlds;
+}
+
+void LoginHandler::clearWorlds()
{
- return worlds;
+ delete_all(mWorlds);
+ mWorlds.clear();
}
} // namespace EAthena
diff --git a/src/net/ea/loginhandler.h b/src/net/ea/loginhandler.h
index c5ce975e..0d0ef1eb 100644
--- a/src/net/ea/loginhandler.h
+++ b/src/net/ea/loginhandler.h
@@ -47,7 +47,7 @@ class LoginHandler : public MessageHandler, public Net::LoginHandler
void disconnect();
int supportedOptionalActions() const
- { return 0; }
+ { return SetGenderOnRegister; }
void loginAccount(LoginData *loginData);
@@ -66,13 +66,18 @@ class LoginHandler : public MessageHandler, public Net::LoginHandler
void unregisterAccount(const std::string &username,
const std::string &password);
- Worlds getWorlds();
+ Worlds getWorlds() const;
+ void clearWorlds();
+
+ const Token &getToken() const { return mToken; }
private:
void sendLoginRegister(const std::string &username,
const std::string &password);
std::string mUpdateHost;
+ Worlds mWorlds;
+ Token mToken;
};
} // namespace EAthena
diff --git a/src/net/ea/network.h b/src/net/ea/network.h
index b61f363b..3b8d09f9 100644
--- a/src/net/ea/network.h
+++ b/src/net/ea/network.h
@@ -53,7 +53,7 @@ class Network
void disconnect();
- ServerInfo getServer()
+ ServerInfo getServer() const
{ return mServer; }
void registerHandler(MessageHandler *handler);
diff --git a/src/net/ea/token.h b/src/net/ea/token.h
index 6c47c10e..e5e4ab0d 100644
--- a/src/net/ea/token.h
+++ b/src/net/ea/token.h
@@ -24,7 +24,8 @@
#ifndef NET_EA_TOKEN_H
#define NET_EA_TOKEN_H
-typedef struct {
+struct Token
+{
int account_ID;
int session_ID1;
int session_ID2;
@@ -37,6 +38,6 @@ typedef struct {
session_ID2 = 0;
sex = GENDER_UNSPECIFIED;
}
-} Token;
+};
#endif // NET_EA_TOKEN_H