summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2009-04-12 14:53:32 +0200
committerBjørn Lindeijer <bjorn@lindeijer.nl>2009-04-12 14:58:48 +0200
commit92a8e0403595cd0f4b8b2084c45ec79edca7e7c1 (patch)
treed1d4b2b6638935f666c6512b467a6ffc3017fb60
parent14a6e6a4bc5d39ddf8f31efc07a5e2493a6f6d0a (diff)
downloadmana-92a8e0403595cd0f4b8b2084c45ec79edca7e7c1.tar.gz
mana-92a8e0403595cd0f4b8b2084c45ec79edca7e7c1.tar.bz2
mana-92a8e0403595cd0f4b8b2084c45ec79edca7e7c1.tar.xz
mana-92a8e0403595cd0f4b8b2084c45ec79edca7e7c1.zip
Append _F or _M to username in eAthena network layer
Abstracts it away and out of main.cpp and register.cpp.
-rw-r--r--src/gui/charcreatedialog.cpp8
-rw-r--r--src/gui/charcreatedialog.h6
-rw-r--r--src/gui/register.cpp3
-rw-r--r--src/logindata.h6
-rw-r--r--src/main.cpp22
-rw-r--r--src/net/ea/charserverhandler.cpp10
-rw-r--r--src/net/ea/loginhandler.cpp49
-rw-r--r--src/net/ea/loginhandler.h13
-rw-r--r--src/net/ea/maphandler.cpp2
-rw-r--r--src/net/loginhandler.h14
-rw-r--r--src/net/tmwserv/loginhandler.cpp7
-rw-r--r--src/net/tmwserv/loginhandler.h10
12 files changed, 76 insertions, 74 deletions
diff --git a/src/gui/charcreatedialog.cpp b/src/gui/charcreatedialog.cpp
index b9dc54a8..024d18b3 100644
--- a/src/gui/charcreatedialog.cpp
+++ b/src/gui/charcreatedialog.cpp
@@ -203,7 +203,7 @@ void CharCreateDialog::action(const gcn::ActionEvent &event)
}
}
-std::string CharCreateDialog::getName()
+std::string CharCreateDialog::getName() const
{
std::string name = mNameField->getText();
trim(name);
@@ -248,7 +248,7 @@ void CharCreateDialog::unlock()
mCreateButton->setEnabled(true);
}
-int CharCreateDialog::getDistributedPoints()
+int CharCreateDialog::getDistributedPoints() const
{
int points = 0;
@@ -310,9 +310,9 @@ void CharCreateDialog::setAttributes(std::vector<std::string> labels,
h - 5 - mCancelButton->getHeight());
}
-void CharCreateDialog::setFixedGender(bool fixed, bool gender)
+void CharCreateDialog::setFixedGender(bool fixed, Gender gender)
{
- if (gender)
+ if (gender == GENDER_FEMALE)
{
mFemale->setSelected(true);
mMale->setSelected(false);
diff --git a/src/gui/charcreatedialog.h b/src/gui/charcreatedialog.h
index 8897b5f7..5dbc6050 100644
--- a/src/gui/charcreatedialog.h
+++ b/src/gui/charcreatedialog.h
@@ -65,17 +65,17 @@ class CharCreateDialog : public Window, public gcn::ActionListener
void setAttributes(std::vector<std::string> labels, int available,
int min, int max);
- void setFixedGender(bool fixed, bool gender = false);
+ void setFixedGender(bool fixed, Gender gender = GENDER_FEMALE);
private:
- int getDistributedPoints();
+ int getDistributedPoints() const;
void updateSliders();
/**
* Returns the name of the character to create.
*/
- std::string getName();
+ std::string getName() const;
/**
* Communicate character creation to the server.
diff --git a/src/gui/register.cpp b/src/gui/register.cpp
index 8442c3ea..04da656b 100644
--- a/src/gui/register.cpp
+++ b/src/gui/register.cpp
@@ -232,7 +232,8 @@ void RegisterDialog::action(const gcn::ActionEvent &event)
#ifdef EATHENA_SUPPORT
mLoginData->hostname = mServerField->getText();
mLoginData->port = getUShort(mPortField->getText());
- mLoginData->username += mFemaleButton->isSelected() ? "_F" : "_M";
+ mLoginData->sex =
+ mFemaleButton->isSelected() ? GENDER_FEMALE : GENDER_MALE;
#else
mLoginData->email = mEmailField->getText();
#endif
diff --git a/src/logindata.h b/src/logindata.h
index 8ecba235..4cf989cb 100644
--- a/src/logindata.h
+++ b/src/logindata.h
@@ -24,7 +24,7 @@
#include <string>
-#include <string>
+#include "being.h"
struct LoginData
{
@@ -43,7 +43,7 @@ struct LoginData
int account_ID;
int session_ID1;
int session_ID2;
- char sex;
+ Gender sex;
#endif
bool remember; /**< Whether to store the username and host. */
@@ -66,7 +66,7 @@ struct LoginData
account_ID = 0;
session_ID1 = 0;
session_ID2 = 0;
- sex = 0;
+ sex = GENDER_UNSPECIFIED;
#endif
}
};
diff --git a/src/main.cpp b/src/main.cpp
index 5bd82e33..d10403b5 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -736,20 +736,15 @@ static void accountLogin(Network *network, LoginData *loginData)
#endif
// Send login infos
- Net::getLoginHandler()->loginAccount(loginData);
+ if (loginData->registerLogin) {
+ Net::getLoginHandler()->registerAccount(loginData);
+ } else {
+ Net::getLoginHandler()->loginAccount(loginData);
+ }
// Clear the password, avoids auto login when returning to login
loginData->password = "";
-#ifdef EATHENA_SUPPORT
- // Remove _M or _F from username after a login for registration purpose
- if (loginData->registerLogin)
- {
- loginData->username =
- loginData->username.substr(0, loginData->username.length() - 2);
- }
-#endif
-
// TODO This is not the best place to save the config, but at least better
// than the login gui window
if (loginData->remember)
@@ -802,9 +797,7 @@ static void accountRegister(LoginData *loginData)
logger->log("Username is %s", loginData->username.c_str());
Net::getCharHandler()->setCharInfo(&charInfo);
-
- Net::getLoginHandler()->registerAccount(loginData->username,
- loginData->password, loginData->email);
+ Net::getLoginHandler()->registerAccount(loginData);
}
static void switchCharacter(std::string *passToken)
@@ -1465,8 +1458,7 @@ int main(int argc, char *argv[])
case STATE_CHAR_SELECT:
logger->log("State: CHAR_SELECT");
currentDialog = new CharSelectDialog(&charInfo,
- (loginData.sex == 0) ?
- GENDER_FEMALE : GENDER_MALE);
+ loginData.sex);
positionDialog(currentDialog, screenWidth, screenHeight);
if (((CharSelectDialog*) currentDialog)->
diff --git a/src/net/ea/charserverhandler.cpp b/src/net/ea/charserverhandler.cpp
index 2973fc4c..3402b5fc 100644
--- a/src/net/ea/charserverhandler.cpp
+++ b/src/net/ea/charserverhandler.cpp
@@ -170,8 +170,7 @@ void CharServerHandler::handleMessage(MessageIn &msg)
LocalPlayer *CharServerHandler::readPlayerData(MessageIn &msg, int &slot)
{
LocalPlayer *tempPlayer = new LocalPlayer(mLoginData->account_ID, 0, NULL);
- tempPlayer->setGender(
- (mLoginData->sex == 0) ? GENDER_FEMALE : GENDER_MALE);
+ tempPlayer->setGender(mLoginData->sex);
tempPlayer->mCharId = msg.readInt32();
tempPlayer->setXp(msg.readInt32());
@@ -218,7 +217,8 @@ void CharServerHandler::setCharCreateDialog(CharCreateDialog *window)
{
mCharCreateDialog = window;
- if (!mCharCreateDialog) return;
+ if (!mCharCreateDialog)
+ return;
std::vector<std::string> attributes;
attributes.push_back(_("Strength:"));
@@ -229,7 +229,7 @@ void CharServerHandler::setCharCreateDialog(CharCreateDialog *window)
attributes.push_back(_("Luck:"));
mCharCreateDialog->setAttributes(attributes, 30, 1, 9);
- mCharCreateDialog->setFixedGender(true);
+ mCharCreateDialog->setFixedGender(true, mLoginData->sex);
}
void CharServerHandler::connect(LoginData *loginData)
@@ -243,7 +243,7 @@ void CharServerHandler::connect(LoginData *loginData)
// [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);
+ 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);
diff --git a/src/net/ea/loginhandler.cpp b/src/net/ea/loginhandler.cpp
index 1031ee05..9c34c4cd 100644
--- a/src/net/ea/loginhandler.cpp
+++ b/src/net/ea/loginhandler.cpp
@@ -81,7 +81,7 @@ void LoginHandler::handleMessage(MessageIn &msg)
mLoginData->account_ID = msg.readInt32();
mLoginData->session_ID2 = msg.readInt32();
msg.skip(30); // unknown
- mLoginData->sex = msg.readInt8();
+ mLoginData->sex = msg.readInt8() ? GENDER_MALE : GENDER_FEMALE;
for (int i = 0; i < n_server; i++)
{
@@ -146,18 +146,7 @@ void LoginHandler::handleMessage(MessageIn &msg)
void LoginHandler::loginAccount(LoginData *loginData)
{
mLoginData = loginData;
- MessageOut outMsg(0x0064);
- outMsg.writeInt32(0); // client version
- outMsg.writeString(loginData->username, 24);
- outMsg.writeString(loginData->password, 24);
-
- /*
- * eAthena calls the last byte "client version 2", but it isn't used at
- * at all. We're retasking it, with bit 0 to indicate whether the client
- * can handle the 0x63 "update host" packet. Clients prior to 0.0.25 send
- * 0 here.
- */
- outMsg.writeInt8(0x01);
+ sendLoginRegister(loginData->username, loginData->password);
}
void LoginHandler::changeEmail(const std::string &email)
@@ -166,8 +155,8 @@ void LoginHandler::changeEmail(const std::string &email)
}
void LoginHandler::changePassword(const std::string &username,
- const std::string &oldPassword,
- const std::string &newPassword)
+ const std::string &oldPassword,
+ const std::string &newPassword)
{
// TODO
}
@@ -177,17 +166,37 @@ void LoginHandler::chooseServer(int server)
// TODO
}
-void LoginHandler::registerAccount(const std::string &username,
- const std::string &password,
- const std::string &email = "")
+void LoginHandler::registerAccount(LoginData *loginData)
{
- // TODO
+ mLoginData = loginData;
+
+ std::string username = loginData->username;
+ username.append((loginData->sex == GENDER_FEMALE) ? "_F" : "_M");
+
+ sendLoginRegister(username, loginData->password);
}
void LoginHandler::unregisterAccount(const std::string &username,
- const std::string &password)
+ const std::string &password)
{
// TODO
}
+void LoginHandler::sendLoginRegister(const std::string &username,
+ const std::string &password)
+{
+ MessageOut outMsg(0x0064);
+ outMsg.writeInt32(0); // client version
+ outMsg.writeString(username, 24);
+ outMsg.writeString(password, 24);
+
+ /*
+ * eAthena calls the last byte "client version 2", but it isn't used at
+ * at all. We're retasking it, with bit 0 to indicate whether the client
+ * can handle the 0x63 "update host" packet. Clients prior to 0.0.25 send
+ * 0 here.
+ */
+ outMsg.writeInt8(0x01);
+}
+
} // namespace EAthena
diff --git a/src/net/ea/loginhandler.h b/src/net/ea/loginhandler.h
index cdc59e4a..93f21754 100644
--- a/src/net/ea/loginhandler.h
+++ b/src/net/ea/loginhandler.h
@@ -43,19 +43,20 @@ class LoginHandler : public MessageHandler, public Net::LoginHandler
void changeEmail(const std::string &email);
void changePassword(const std::string &username,
- const std::string &oldPassword,
- const std::string &newPassword);
+ const std::string &oldPassword,
+ const std::string &newPassword);
void chooseServer(int server);
- void registerAccount(const std::string &username,
- const std::string &password,
- const std::string &email);
+ void registerAccount(LoginData *loginData);
void unregisterAccount(const std::string &username,
- const std::string &password);
+ const std::string &password);
private:
+ void sendLoginRegister(const std::string &username,
+ const std::string &password);
+
LoginData *mLoginData;
std::string mUpdateHost;
};
diff --git a/src/net/ea/maphandler.cpp b/src/net/ea/maphandler.cpp
index de60059f..6b061798 100644
--- a/src/net/ea/maphandler.cpp
+++ b/src/net/ea/maphandler.cpp
@@ -87,7 +87,7 @@ void MapHandler::connect(LoginData *loginData)
outMsg.writeInt32(player_node->mCharId);
outMsg.writeInt32(loginData->session_ID1);
outMsg.writeInt32(loginData->session_ID2);
- outMsg.writeInt8(loginData->sex);
+ 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);
diff --git a/src/net/loginhandler.h b/src/net/loginhandler.h
index fcdee0da..fdd57689 100644
--- a/src/net/loginhandler.h
+++ b/src/net/loginhandler.h
@@ -27,6 +27,7 @@
#include <iosfwd>
namespace Net {
+
class LoginHandler
{
public:
@@ -35,18 +36,17 @@ class LoginHandler
virtual void changeEmail(const std::string &email) = 0;
virtual void changePassword(const std::string &username,
- const std::string &oldPassword,
- const std::string &newPassword) = 0;
+ const std::string &oldPassword,
+ const std::string &newPassword) = 0;
virtual void chooseServer(int server) = 0;
- virtual void registerAccount(const std::string &username,
- const std::string &password,
- const std::string &email) = 0;
+ virtual void registerAccount(LoginData *loginData) = 0;
virtual void unregisterAccount(const std::string &username,
- const std::string &password) = 0;
+ const std::string &password) = 0;
};
-}
+
+} // namespace Net
#endif // LOGINHANDLER_H
diff --git a/src/net/tmwserv/loginhandler.cpp b/src/net/tmwserv/loginhandler.cpp
index ef23546a..c8db624c 100644
--- a/src/net/tmwserv/loginhandler.cpp
+++ b/src/net/tmwserv/loginhandler.cpp
@@ -258,12 +258,13 @@ void LoginHandler::chooseServer(int server)
// TODO
}
-void LoginHandler::registerAccount(const std::string &username,
- const std::string &password, const std::string &email)
+void LoginHandler::registerAccount(LoginData *loginData)
{
Net::AccountServer::registerAccount(accountServerConnection,
0, // client version
- username, password, email);
+ loginData->username,
+ loginData->password,
+ loginData->email);
}
void LoginHandler::unregisterAccount(const std::string &username,
diff --git a/src/net/tmwserv/loginhandler.h b/src/net/tmwserv/loginhandler.h
index 93d55396..f3bc0c6d 100644
--- a/src/net/tmwserv/loginhandler.h
+++ b/src/net/tmwserv/loginhandler.h
@@ -41,17 +41,15 @@ class LoginHandler : public MessageHandler, public Net::LoginHandler
void changeEmail(const std::string &email);
void changePassword(const std::string &username,
- const std::string &oldPassword,
- const std::string &newPassword);
+ const std::string &oldPassword,
+ const std::string &newPassword);
void chooseServer(int server);
- void registerAccount(const std::string &username,
- const std::string &password,
- const std::string &email);
+ void registerAccount(LoginData *loginData);
void unregisterAccount(const std::string &username,
- const std::string &password);
+ const std::string &password);
private:
void handleLoginResponse(MessageIn &msg);