summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/char_select.cpp32
-rw-r--r--src/gui/char_select.h9
-rw-r--r--src/gui/char_server.cpp47
-rw-r--r--src/gui/char_server.h3
-rw-r--r--src/gui/connection.cpp25
-rw-r--r--src/gui/connection.h3
-rw-r--r--src/gui/login.cpp42
-rw-r--r--src/gui/login.h16
8 files changed, 114 insertions, 63 deletions
diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp
index 86e2b12f..b1f649ec 100644
--- a/src/gui/char_select.cpp
+++ b/src/gui/char_select.cpp
@@ -62,7 +62,7 @@ void CharSelectDialog::CharDeleteConfirm::action(const std::string &eventId)
}
CharSelectDialog::CharSelectDialog():
- Window("Select Character")
+ Window("Select Character"), mStatus(0)
{
selectButton = new Button("OK");
cancelButton = new Button("Cancel");
@@ -123,7 +123,8 @@ void CharSelectDialog::action(const std::string& eventId)
{
if (eventId == "ok" && n_character > 0) {
// Start game
- serverCharSelect();
+ attemptCharSelect();
+ mStatus = 1;
}
else if (eventId == "cancel") {
state = EXIT_STATE;
@@ -208,14 +209,23 @@ void CharSelectDialog::serverCharDelete()
}
}
-void CharSelectDialog::serverCharSelect()
+void CharSelectDialog::attemptCharSelect()
{
// Request character selection
MessageOut outMsg;
outMsg.writeInt16(0x0066);
outMsg.writeInt8(0);
+}
+void
+CharSelectDialog::checkCharSelect()
+{
+ // Receive reply
MessageIn msg = get_next_message();
+ if (state == ERROR_STATE)
+ {
+ return;
+ }
logger->log("CharSelect: Packet ID: %x, Length: %d, in_size: %d",
msg.getId(), msg.getLength(), in_size);
@@ -224,14 +234,14 @@ void CharSelectDialog::serverCharSelect()
{
char_ID = msg.readInt32();
map_path = "maps/" + msg.readString(16);
- map_path= map_path.substr(0, map_path.rfind(".")) + ".tmx.gz";
+ map_path = map_path.substr(0, map_path.rfind(".")) + ".tmx.gz";
map_address = msg.readInt32();
map_port = msg.readInt16();
player_info = char_info[0];
state = CONNECTING_STATE;
logger->log("CharSelect: Map: %s", map_path.c_str());
- logger->log("CharSelect: Server: %s:%d", iptostring(map_address),
+ logger->log("CharSelect: Server: %s:%i", iptostring(map_address),
map_port);
closeConnection();
}
@@ -278,6 +288,18 @@ void CharSelectDialog::logic()
if (n_character > 0) {
setPlayerInfo(char_info[0]);
}
+
+ if (mStatus == 1)
+ {
+ if (in_size > 2)
+ {
+ checkCharSelect();
+ }
+ else
+ {
+ flush();
+ }
+ }
}
CharCreateDialog::CharCreateDialog(Window *parent):
diff --git a/src/gui/char_select.h b/src/gui/char_select.h
index a85bb28c..3692c1e4 100644
--- a/src/gui/char_select.h
+++ b/src/gui/char_select.h
@@ -63,6 +63,8 @@ class CharSelectDialog : public Window, public gcn::ActionListener
gcn::Label *levelLabel;
gcn::Label *jobLevelLabel;
gcn::Label *moneyLabel;
+
+ int mStatus;
PlayerBox *playerBox;
@@ -74,7 +76,12 @@ class CharSelectDialog : public Window, public gcn::ActionListener
/**
* Communicate character selection to the server.
*/
- void serverCharSelect();
+ void attemptCharSelect();
+
+ /**
+ * Check server answer.
+ */
+ void checkCharSelect();
/**
* Listener for confirming character deletion.
diff --git a/src/gui/char_server.cpp b/src/gui/char_server.cpp
index 202c3e29..6766092c 100644
--- a/src/gui/char_server.cpp
+++ b/src/gui/char_server.cpp
@@ -42,9 +42,6 @@
extern SERVER_INFO **server_info;
-char server[30];
-
-
ServerSelectDialog::ServerSelectDialog():
Window("Select Server"), mStatus(NET_IDLE)
{
@@ -68,7 +65,7 @@ ServerSelectDialog::ServerSelectDialog():
100 - 3 * 5 - cancelButton->getHeight() -
scrollArea->getBorderSize()));
- //serverList->setEventId("ok");
+ serverList->setEventId("ok");
okButton->setEventId("ok");
cancelButton->setEventId("cancel");
@@ -97,7 +94,8 @@ ServerSelectDialog::~ServerSelectDialog()
delete serverListModel;
}
-void ServerSelectDialog::action(const std::string& eventId)
+void
+ServerSelectDialog::action(const std::string& eventId)
{
if (eventId == "ok") {
int index = serverList->getSelected();
@@ -105,14 +103,14 @@ void ServerSelectDialog::action(const std::string& eventId)
short port = server_info[index]->port;
openConnection(host, port);
mStatus = NET_CONNECTING;
- //server_char_server(serverList->getSelected());
}
else if (eventId == "cancel") {
state = LOGIN_STATE;
}
}
-void ServerSelectDialog::logic()
+void
+ServerSelectDialog::logic()
{
switch (mStatus)
{
@@ -126,25 +124,39 @@ void ServerSelectDialog::logic()
closeConnection();
break;
case NET_CONNECTED:
- selectServer(serverList->getSelected());
- //closeConnection();
+ attemptServerSelect(serverList->getSelected());
+ mStatus = NET_DATA;
+ break;
+ case NET_DATA:
+ if (in_size > 6)
+ {
+ skip(4);
+ checkServerSelect();
+ }
+ else
+ {
+ flush();
+ }
break;
}
}
-int ServerListModel::getNumberOfElements()
+int
+ServerListModel::getNumberOfElements()
{
return n_server;
}
-std::string ServerListModel::getElementAt(int i)
+std::string
+ServerListModel::getElementAt(int i)
{
std::stringstream s;
s << server_info[i]->name << " (" << server_info[i]->online_users << ")";
return s.str();
}
-void charServerInputHandler(SDL_KeyboardEvent *keyEvent)
+void
+charServerInputHandler(SDL_KeyboardEvent *keyEvent)
{
if (keyEvent->keysym.sym == SDLK_ESCAPE)
{
@@ -152,7 +164,8 @@ void charServerInputHandler(SDL_KeyboardEvent *keyEvent)
}
}
-void ServerSelectDialog::selectServer(int index)
+void
+ServerSelectDialog::attemptServerSelect(int index)
{
// Send login infos
MessageOut outMsg;
@@ -162,11 +175,11 @@ void ServerSelectDialog::selectServer(int index)
outMsg.writeInt32(session_ID2);
outMsg.writeInt16(0); // unknown
outMsg.writeInt8(sex);
+}
- // Skipping a mysterious 4 bytes
- while ((in_size < 4) || (out_size > 0)) flush();
- skip(4);
-
+void
+ServerSelectDialog::checkServerSelect()
+{
MessageIn msg = get_next_message();
if (msg.getId() == 0x006b)
diff --git a/src/gui/char_server.h b/src/gui/char_server.h
index f81c387b..f36ee76e 100644
--- a/src/gui/char_server.h
+++ b/src/gui/char_server.h
@@ -80,7 +80,8 @@ class ServerSelectDialog : public Window, public gcn::ActionListener {
gcn::ScrollArea *scrollArea;
int mStatus;
- void selectServer(int index);
+ void attemptServerSelect(int index);
+ void checkServerSelect();
};
void charServerInputHandler(SDL_KeyboardEvent *keyEvent);
diff --git a/src/gui/connection.cpp b/src/gui/connection.cpp
index 3cff4abd..c7eb3667 100644
--- a/src/gui/connection.cpp
+++ b/src/gui/connection.cpp
@@ -86,8 +86,20 @@ void ConnectionDialog::logic()
closeConnection();
break;
case NET_CONNECTED:
- mapLogin();
- state = GAME_STATE;
+ attemptMapLogin();
+ mStatus = NET_DATA;
+ break;
+ case NET_DATA:
+ if (in_size > 6)
+ {
+ skip(4);
+ checkMapLogin();
+ state = GAME_STATE;
+ }
+ else
+ {
+ flush();
+ }
break;
}
}
@@ -100,7 +112,7 @@ void ConnectionDialog::action(const std::string& eventId)
}
}
-void ConnectionDialog::mapLogin()
+void ConnectionDialog::attemptMapLogin()
{
// Send login infos
MessageOut outMsg;
@@ -110,11 +122,10 @@ void ConnectionDialog::mapLogin()
outMsg.writeInt32(session_ID1);
outMsg.writeInt32(session_ID2);
outMsg.writeInt8(sex);
+}
- // Skip a mysterious 4 bytes
- while ((in_size < 4)|| (out_size > 0)) flush();
- skip(4);
-
+void ConnectionDialog::checkMapLogin()
+{
MessageIn msg = get_next_message();
if (msg.getId() == SMSG_LOGIN_SUCCESS)
diff --git a/src/gui/connection.h b/src/gui/connection.h
index bde1e174..342b9f8d 100644
--- a/src/gui/connection.h
+++ b/src/gui/connection.h
@@ -61,7 +61,8 @@ class ConnectionDialog : public Window, public gcn::ActionListener
float mProgress;
int mStatus;
- void mapLogin();
+ void attemptMapLogin();
+ void checkMapLogin();
};
/**
diff --git a/src/gui/login.cpp b/src/gui/login.cpp
index e6df01da..a8e906e1 100644
--- a/src/gui/login.cpp
+++ b/src/gui/login.cpp
@@ -222,52 +222,47 @@ LoginDialog::action(const std::string& eventId)
} else {
config.setValue("username", "");
}
+
+ std::stringstream errorMsg;
+ bool error = false;
// Check login
if (user.length() == 0)
{
// No username
- wrongLoginNotice = new OkDialog("Error",
- "Enter your username first.",
- &wrongUsernameNoticeListener);
+ errorMsg << "Enter your username first.";
}
else if (user.length() < LEN_MIN_USERNAME)
{
// Name too short
- std::stringstream errorMsg;
errorMsg << "The username needs to be at least "
<< LEN_MIN_USERNAME
<< " characters long.";
- wrongLoginNotice = new OkDialog("Error", errorMsg.str(),
- &wrongUsernameNoticeListener);
}
else if (user.length() > LEN_MAX_USERNAME - 1 )
{
// Name too long
- std::stringstream errorMsg;
errorMsg << "The username needs to be less than "
<< LEN_MAX_USERNAME
<< " characters long.";
- wrongLoginNotice = new OkDialog("Error", errorMsg.str(),
- &wrongUsernameNoticeListener);
}
else if (passField->getText().length() < LEN_MIN_PASSWORD)
{
// Pass too short
- std::stringstream errorMsg;
errorMsg << "The password needs to be at least "
<< LEN_MIN_PASSWORD
<< " characters long.";
- wrongLoginNotice = new OkDialog("Error", errorMsg.str(),
- &wrongPasswordNoticeListener);
}
else if (passField->getText().length() > LEN_MAX_PASSWORD - 1 )
{
// Pass too long
- std::stringstream errorMsg;
errorMsg << "The password needs to be less than "
<< LEN_MAX_PASSWORD
<< " characters long.";
+ }
+
+ if (error)
+ {
wrongLoginNotice = new OkDialog("Error", errorMsg.str(),
&wrongPasswordNoticeListener);
}
@@ -280,7 +275,6 @@ LoginDialog::action(const std::string& eventId)
openConnection(host.c_str(), port);
mStatus = NET_CONNECTING;
registration = true;
- //attemptLogin(user + "_M", passField->getText());
}
}
}
@@ -300,6 +294,19 @@ LoginDialog::logic()
closeConnection();
logger->log("Connection closed");
break;
+ case NET_DATA:
+ // TODO: this is a very quick hack, we should implement something
+ // like a bool completePacket() in network functions.
+ if (in_size > 2)
+ {
+ checkLogin();
+ closeConnection();
+ }
+ else
+ {
+ flush();
+ }
+ break;
case NET_CONNECTED:
logger->log("Connected...");
std::string user = userField->getText();
@@ -309,7 +316,7 @@ LoginDialog::logic()
user += "_M";
}
attemptLogin(user, password);
- closeConnection();
+ mStatus = NET_DATA;
break;
}
}
@@ -333,12 +340,15 @@ LoginDialog::attemptLogin(const std::string& user, const std::string& pass)
outMsg.writeString(user, 24);
outMsg.writeString(pass, 24);
outMsg.writeInt8(0); // unknown
+}
+void
+LoginDialog::checkLogin()
+{
// Receive reply
MessageIn msg = get_next_message();
if (state == ERROR_STATE)
{
- closeConnection();
return;
}
diff --git a/src/gui/login.h b/src/gui/login.h
index f4966914..9fd866aa 100644
--- a/src/gui/login.h
+++ b/src/gui/login.h
@@ -73,6 +73,7 @@ class LoginDialog : public Window, public gcn::ActionListener {
bool registration;
void attemptLogin(const std::string& user, const std::string& pass);
+ void checkLogin();
};
/**
@@ -103,19 +104,4 @@ class WrongUsernameNoticeListener : public gcn::ActionListener {
*/
void loginInputHandler(SDL_KeyboardEvent *keyEvent);
-/*enum
-{
- LOGIN_OK = 0,
- LOGIN_WRONG_PASSWORD,
- LOGIN_UNREGISTERED_ID,
- LOGIN_REJECTED,
- LOGIN_BLOCKED,
- LOGIN_EXPIRED,
- LOGIN_NO_CONNECTION,
- LOGIN_USERNAME_TWICE = 9,
- LOGIN_CONNECTING,
- LOGIN_UNKNOWN_ERROR = -1
-
-};*/
-
#endif