summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gui/char_select.cpp14
-rw-r--r--src/gui/char_select.h7
-rw-r--r--src/gui/register.cpp20
-rw-r--r--src/gui/register.h1
-rw-r--r--src/logindata.h2
-rw-r--r--src/main.cpp28
-rw-r--r--src/main.h1
-rw-r--r--src/net/charserverhandler.cpp2
-rw-r--r--src/net/loginhandler.cpp34
-rw-r--r--src/net/protocol.h7
10 files changed, 91 insertions, 25 deletions
diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp
index 934988f4..27b5b55a 100644
--- a/src/gui/char_select.cpp
+++ b/src/gui/char_select.cpp
@@ -70,10 +70,9 @@ void CharDeleteConfirm::action(const std::string &eventId, gcn::Widget *widget)
}
CharSelectDialog::CharSelectDialog(Network *network,
- LockedArray<LocalPlayer*> *charInfo,
- unsigned char sex):
+ LockedArray<LocalPlayer*> *charInfo):
Window("Select Character"), mNetwork(network),
- mCharInfo(charInfo), mSex(sex), mCharSelected(false)
+ mCharInfo(charInfo), mCharSelected(false)
{
mSelectButton = new Button("Ok", "ok", this);
mCancelButton = new Button("Cancel", "cancel", this);
@@ -86,7 +85,7 @@ CharSelectDialog::CharSelectDialog(Network *network,
mLevelLabel = new gcn::Label("Level");
mJobLevelLabel = new gcn::Label("Job Level");
mMoneyLabel = new gcn::Label("Money");
- mPlayerBox = new PlayerBox(sex);
+ mPlayerBox = new PlayerBox(0);
int w = 195;
int h = 220;
@@ -149,7 +148,7 @@ void CharSelectDialog::action(const std::string &eventId, gcn::Widget *widget)
{
// Start new character dialog
mCharInfo->lock();
- new CharCreateDialog(this, mCharInfo->getPos(), mNetwork, mSex);
+ new CharCreateDialog(this, mCharInfo->getPos(), mNetwork);
mCharInfo->unlock();
}
}
@@ -228,8 +227,7 @@ void CharSelectDialog::logic()
updatePlayerInfo();
}
-CharCreateDialog::CharCreateDialog(Window *parent, int slot, Network *network,
- unsigned char sex):
+CharCreateDialog::CharCreateDialog(Window *parent, int slot, Network *network):
Window("Create Character", true, parent), mNetwork(network), mSlot(slot)
{
mNameField = new TextField("");
@@ -242,7 +240,7 @@ CharCreateDialog::CharCreateDialog(Window *parent, int slot, Network *network,
mHairStyleLabel = new gcn::Label("Hair Style:");
mCreateButton = new Button("Create", "create", this);
mCancelButton = new Button("Cancel", "cancel", this);
- mPlayerBox = new PlayerBox(sex);
+ mPlayerBox = new PlayerBox(0);
mPlayerBox->mShowPlayer = true;
mNameField->setEventId("create");
diff --git a/src/gui/char_select.h b/src/gui/char_select.h
index 20105516..3bf9911e 100644
--- a/src/gui/char_select.h
+++ b/src/gui/char_select.h
@@ -48,8 +48,7 @@ class CharSelectDialog : public Window, public gcn::ActionListener
* Constructor.
*/
CharSelectDialog(Network *network,
- LockedArray<LocalPlayer*> *charInfo,
- unsigned char sex);
+ LockedArray<LocalPlayer*> *charInfo);
void action(const std::string& eventId, gcn::Widget* widget);
@@ -75,7 +74,6 @@ class CharSelectDialog : public Window, public gcn::ActionListener
PlayerBox *mPlayerBox;
- unsigned char mSex;
bool mCharSelected;
/**
@@ -100,8 +98,7 @@ class CharCreateDialog : public Window, public gcn::ActionListener
/**
* Constructor.
*/
- CharCreateDialog(Window *parent, int slot, Network *network,
- unsigned char sex);
+ CharCreateDialog(Window *parent, int slot, Network *network);
void action(const std::string& eventId, gcn::Widget* widget);
diff --git a/src/gui/register.cpp b/src/gui/register.cpp
index 38136b87..82e5f716 100644
--- a/src/gui/register.cpp
+++ b/src/gui/register.cpp
@@ -50,10 +50,12 @@ RegisterDialog::RegisterDialog(LoginData *loginData):
gcn::Label *userLabel = new gcn::Label("Name:");
gcn::Label *passwordLabel = new gcn::Label("Password:");
gcn::Label *confirmLabel = new gcn::Label("Confirm:");
+ gcn::Label *emailLabel = new gcn::Label("Email:");
gcn::Label *serverLabel = new gcn::Label("Server:");
mUserField = new TextField("player");
mPasswordField = new PasswordField();
mConfirmField = new PasswordField();
+ mEmailField = new TextField();
mServerField = new TextField();
mMaleButton = new RadioButton("Male", "sex", true);
mFemaleButton = new RadioButton("Female", "sex", false);
@@ -61,7 +63,7 @@ RegisterDialog::RegisterDialog(LoginData *loginData):
mCancelButton = new Button("Cancel", "cancel", this);
int width = 200;
- int height = 150;
+ int height = 170;
setContentSize(width, height);
mUserField->setPosition(65, 5);
@@ -72,17 +74,21 @@ RegisterDialog::RegisterDialog(LoginData *loginData):
mConfirmField->setPosition(
65, mPasswordField->getY() + mPasswordField->getHeight() + 7);
mConfirmField->setWidth(130);
+ mEmailField->setPosition(
+ 65, mConfirmField->getY() + mConfirmField->getHeight() + 7);
+ mEmailField->setWidth(130);
mServerField->setPosition(
- 65, 23 + mConfirmField->getY() + mConfirmField->getHeight() + 7);
+ 65, 23 + mEmailField->getY() + mEmailField->getHeight() + 7);
mServerField->setWidth(130);
userLabel->setPosition(5, mUserField->getY() + 1);
passwordLabel->setPosition(5, mPasswordField->getY() + 1);
confirmLabel->setPosition(5, mConfirmField->getY() + 1);
+ emailLabel->setPosition(5, mEmailField->getY() + 1);
serverLabel->setPosition(5, mServerField->getY() + 1);
mFemaleButton->setPosition(width - mFemaleButton->getWidth() - 10,
- mConfirmField->getY() + mConfirmField->getHeight() + 7);
+ mEmailField->getY() + mEmailField->getHeight() + 7);
mMaleButton->setPosition(mFemaleButton->getX() - mMaleButton->getWidth() - 5,
mFemaleButton->getY());
@@ -92,11 +98,13 @@ RegisterDialog::RegisterDialog(LoginData *loginData):
add(userLabel);
add(passwordLabel);
+ add(emailLabel);
add(serverLabel);
add(confirmLabel);
add(mUserField);
add(mPasswordField);
add(mConfirmField);
+ add(mEmailField);
add(mServerField);
add(mMaleButton);
add(mFemaleButton);
@@ -176,6 +184,8 @@ RegisterDialog::action(const std::string &eventId, gcn::Widget *widget)
error = 2;
}
+ // TODO: Check if a valid email address was given
+
if (error > 0)
{
if (error == 1)
@@ -202,9 +212,9 @@ RegisterDialog::action(const std::string &eventId, gcn::Widget *widget)
mLoginData->port = (short)config.getValue("port", 0);
mLoginData->username = mUserField->getText();
mLoginData->password = mPasswordField->getText();
- mLoginData->username += mFemaleButton->isMarked() ? "_F" : "_M";
+ mLoginData->email = mEmailField->getText();
- state = ACCOUNT_STATE;
+ state = REGISTER_ACCOUNT_STATE;
}
}
}
diff --git a/src/gui/register.h b/src/gui/register.h
index 5d3f6cd5..30dacd3e 100644
--- a/src/gui/register.h
+++ b/src/gui/register.h
@@ -65,6 +65,7 @@ class RegisterDialog : public Window, public gcn::ActionListener {
gcn::TextField *mUserField;
gcn::TextField *mPasswordField;
gcn::TextField *mConfirmField;
+ gcn::TextField *mEmailField;
gcn::TextField *mServerField;
gcn::Button *mRegisterButton;
diff --git a/src/logindata.h b/src/logindata.h
index f4fcd1b1..70b80bb7 100644
--- a/src/logindata.h
+++ b/src/logindata.h
@@ -29,12 +29,12 @@ struct LoginData
std::string username;
std::string password;
std::string hostname;
+ std::string email;
short port;
int account_ID;
int session_ID1;
int session_ID2;
- char sex;
bool remember;
};
diff --git a/src/main.cpp b/src/main.cpp
index 1bec709f..ce68b7bb 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -447,6 +447,25 @@ void accountLogin(Network *network, LoginData *loginData)
config.setValue("remember", loginData->remember);
}
+void accountRegister(Network *network, LoginData *loginData)
+{
+ logger->log("Trying to connect to account server...");
+ logger->log("Username is %s", loginData->username.c_str());
+ network->connect(loginData->hostname, loginData->port);
+ network->registerHandler(&loginHandler);
+ loginHandler.setCharInfo(&charInfo);
+ loginHandler.setLoginData(loginData);
+
+ // Send login infos
+ MessageOut *msg = new MessageOut();
+ msg->writeShort(PAMSG_REGISTER);
+ msg->writeLong(0); // client version
+ msg->writeString(loginData->username);
+ msg->writeString(loginData->password);
+ msg->writeString(loginData->email);
+ network->send(msg);
+}
+
void mapLogin(Network *network, LoginData *loginData)
{
MessageOut outMsg;
@@ -463,7 +482,6 @@ void mapLogin(Network *network, LoginData *loginData)
outMsg.writeLong(player_node->mCharId);
outMsg.writeLong(loginData->session_ID1);
outMsg.writeLong(loginData->session_ID2);
- outMsg.writeByte(loginData->sex);
}
/** Main */
@@ -629,8 +647,7 @@ int main(int argc, char *argv[])
case CHAR_SELECT_STATE:
logger->log("State: CHAR_SELECT");
- currentDialog = new CharSelectDialog(network, &charInfo,
- 1 - loginData.sex);
+ currentDialog = new CharSelectDialog(network, &charInfo);
if (options.chooseDefault) {
((CharSelectDialog*)currentDialog)->action("ok",
NULL);
@@ -672,10 +689,13 @@ int main(int argc, char *argv[])
break;
case ACCOUNT_STATE:
- printf("Account: %i\n", loginData.sex);
accountLogin(network, &loginData);
break;
+ case REGISTER_ACCOUNT_STATE:
+ accountRegister(network, &loginData);
+ break;
+
default:
state = EXIT_STATE;
break;
diff --git a/src/main.h b/src/main.h
index f8bfb4d9..035b0ec7 100644
--- a/src/main.h
+++ b/src/main.h
@@ -43,6 +43,7 @@ enum {
LOGIN_STATE,
ACCOUNT_STATE,
REGISTER_STATE,
+ REGISTER_ACCOUNT_STATE,
CHAR_CONNECT_STATE,
CHAR_SERVER_STATE,
CHAR_SELECT_STATE,
diff --git a/src/net/charserverhandler.cpp b/src/net/charserverhandler.cpp
index 932a6fbc..36a17acf 100644
--- a/src/net/charserverhandler.cpp
+++ b/src/net/charserverhandler.cpp
@@ -159,8 +159,6 @@ void CharServerHandler::handleMessage(MessageIn *msg)
LocalPlayer* CharServerHandler::readPlayerData(MessageIn *msg, int &slot)
{
LocalPlayer *tempPlayer = new LocalPlayer(mLoginData->account_ID, 0, NULL);
- tempPlayer->setSex(1 - mLoginData->sex);
-
tempPlayer->mCharId = msg->readLong();
tempPlayer->mTotalWeight = 0;
tempPlayer->mMaxWeight = 0;
diff --git a/src/net/loginhandler.cpp b/src/net/loginhandler.cpp
index 5b8fbd1f..ebc8f535 100644
--- a/src/net/loginhandler.cpp
+++ b/src/net/loginhandler.cpp
@@ -36,6 +36,7 @@ LoginHandler::LoginHandler()
{
static const Uint16 _messages[] = {
APMSG_LOGIN_RESPONSE,
+ APMSG_REGISTER_RESPONSE,
0
};
handledMessages = _messages;
@@ -46,6 +47,7 @@ void LoginHandler::handleMessage(MessageIn *msg)
switch (msg->getId())
{
case APMSG_LOGIN_RESPONSE:
+ {
int errMsg = msg->readByte();
// Successful login
if (errMsg == ERRMSG_OK)
@@ -90,6 +92,38 @@ void LoginHandler::handleMessage(MessageIn *msg)
}
state = ERROR_STATE;
}
+ }
+ break;
+ case APMSG_REGISTER_RESPONSE:
+ {
+ int errMsg = msg->readByte();
+ // Successful registration
+ if (errMsg == ERRMSG_OK)
+ {
+ state = ACCOUNT_STATE;
+ }
+ // Registration failed
+ else {
+ switch (errMsg) {
+ case REGISTER_INVALID_VERSION:
+ errorMessage = "Client has an insufficient version number to login.";
+ break;
+ case ERRMSG_INVALID_ARGUMENT:
+ errorMessage = "Wrong username, password or email address";
+ break;
+ case REGISTER_EXISTS_USERNAME:
+ errorMessage = "Username already exists";
+ break;
+ case REGISTER_EXISTS_EMAIL:
+ errorMessage = "Email address already exists";
+ break;
+ default:
+ errorMessage = "Unknown error";
+ break;
+ }
+ state = ERROR_STATE;
+ }
+ }
break;
}
}
diff --git a/src/net/protocol.h b/src/net/protocol.h
index 6a13bbd9..6db3762e 100644
--- a/src/net/protocol.h
+++ b/src/net/protocol.h
@@ -200,6 +200,13 @@ enum {
LOGIN_SERVER_FULL // the server is overloaded
};
+// Account register specific return values
+enum {
+ REGISTER_INVALID_VERSION = 0x40, // the user is using an incompatible protocol
+ REGISTER_EXISTS_USERNAME, // there already is an account with this username
+ REGISTER_EXISTS_EMAIL // there already is an account with this email address
+};
+
/** Encodes coords and direction in 3 bytes data */
void set_coordinates(char *data, unsigned short x, unsigned short y, unsigned char direction);