summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorEugenio Favalli <elvenprogrammer@gmail.com>2005-10-16 13:42:33 +0000
committerEugenio Favalli <elvenprogrammer@gmail.com>2005-10-16 13:42:33 +0000
commit59167f0f02dfd2c8463b2f3d93a8ac219dcc012e (patch)
tree3dd32d4594c1a194c4cc19e1614ea01290417431 /src/gui
parentd205342bb908207f7921c444e539072e006be241 (diff)
downloadmana-59167f0f02dfd2c8463b2f3d93a8ac219dcc012e.tar.gz
mana-59167f0f02dfd2c8463b2f3d93a8ac219dcc012e.tar.bz2
mana-59167f0f02dfd2c8463b2f3d93a8ac219dcc012e.tar.xz
mana-59167f0f02dfd2c8463b2f3d93a8ac219dcc012e.zip
The connection should be non-blocking now and fixed the problem with sound not being played at startup.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/char_select.cpp6
-rw-r--r--src/gui/char_server.cpp49
-rw-r--r--src/gui/char_server.h10
-rw-r--r--src/gui/login.cpp127
-rw-r--r--src/gui/login.h29
5 files changed, 110 insertions, 111 deletions
diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp
index b7258aba..46ead1dc 100644
--- a/src/gui/char_select.cpp
+++ b/src/gui/char_select.cpp
@@ -241,12 +241,12 @@ void CharSelectDialog::serverCharSelect()
map_address = msg.readLong();
map_port = msg.readShort();
player_info = char_info[0];
- state = GAME_STATE;
+ state = CONNECTING_STATE;
logger->log("CharSelect: Map: %s", map_path.c_str());
logger->log("CharSelect: Server: %s:%d", iptostring(map_address),
map_port);
- close_session();
+ closeConnection();
}
else if (msg.getId() == 0x006c)
{
@@ -279,7 +279,7 @@ void CharSelectDialog::serverCharSelect()
errorMessage = "Unkown error with 0x0081";
break;
}
- close_session();
+ closeConnection();
state = ERROR_STATE;
}
diff --git a/src/gui/char_server.cpp b/src/gui/char_server.cpp
index a8f99d8f..22ac484b 100644
--- a/src/gui/char_server.cpp
+++ b/src/gui/char_server.cpp
@@ -46,7 +46,7 @@ char server[30];
ServerSelectDialog::ServerSelectDialog():
- Window("Select Server")
+ Window("Select Server"), mStatus(NET_IDLE)
{
serverListModel = new ServerListModel();
serverList = new ListBox(serverListModel);
@@ -82,7 +82,7 @@ ServerSelectDialog::ServerSelectDialog():
if (n_server == 0) {
// Disable Ok button
- //okButton->char_server_dialog[2].flags |= D_DISABLED;
+ okButton->setEnabled(false);
} else {
// Select first server
serverList->setSelected(1);
@@ -104,13 +104,37 @@ ServerSelectDialog::~ServerSelectDialog()
void ServerSelectDialog::action(const std::string& eventId)
{
if (eventId == "ok") {
- server_char_server(serverList->getSelected());
+ int index = serverList->getSelected();
+ const char *host = iptostring(server_info[index]->address);
+ 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()
+{
+ switch (mStatus)
+ {
+ case NET_CONNECTING:
+ mStatus = pollConnection();
+ break;
+ case NET_ERROR:
+ logger->log("ServerSelect::Unable to connect");
+ errorMessage = "Unable to connect to char server";
+ state = ERROR_STATE;
+ closeConnection();
+ break;
+ case NET_CONNECTED:
+ selectServer(serverList->getSelected());
+ //closeConnection();
+ break;
+ }
+}
int ServerListModel::getNumberOfElements()
{
@@ -132,23 +156,8 @@ void charServerInputHandler(SDL_KeyboardEvent *keyEvent)
}
}
-void server_char_server(int serverIndex)
+void ServerSelectDialog::selectServer(int index)
{
- int ret;
- state = LOGIN_STATE;
- const char *ipstring = iptostring(server_info[serverIndex]->address);
-
- // Connect to char server
- ret = open_session(ipstring, server_info[serverIndex]->port);
-
- if (ret == -1)
- {
- std::string str = std::string("Unable to connect to char server ") +
- std::string(ipstring);
- new OkDialog("Error", str);
- return;
- }
-
// Send login infos
MessageOut outMsg;
outMsg.writeShort(0x0065);
@@ -234,7 +243,7 @@ void server_char_server(int serverIndex)
}
new OkDialog("Error", errorStr);
skip(msg.getLength());
- close_session();
+ closeConnection();
}
else
{
diff --git a/src/gui/char_server.h b/src/gui/char_server.h
index 70361496..f07b2f53 100644
--- a/src/gui/char_server.h
+++ b/src/gui/char_server.h
@@ -66,6 +66,11 @@ class ServerSelectDialog : public Window, public gcn::ActionListener {
* Called when receiving actions from the widgets.
*/
void action(const std::string& eventId);
+
+ /**
+ * Updates dialog logic
+ */
+ void logic();
private:
ServerListModel *serverListModel;
@@ -73,10 +78,11 @@ class ServerSelectDialog : public Window, public gcn::ActionListener {
gcn::Button *okButton;
gcn::Button *cancelButton;
gcn::ScrollArea *scrollArea;
+ int mStatus;
+
+ void selectServer(int index);
};
void charServerInputHandler(SDL_KeyboardEvent *keyEvent);
-void server_char_server(int serverIndex);
-char *server_list(int index, int *size);
#endif
diff --git a/src/gui/login.cpp b/src/gui/login.cpp
index 6d1c896d..6846059c 100644
--- a/src/gui/login.cpp
+++ b/src/gui/login.cpp
@@ -89,7 +89,7 @@ WrongUsernameNoticeListener::action(const std::string &eventId)
}
LoginDialog::LoginDialog():
- Window("Login")
+ Window("Login"), mStatus(NET_IDLE), registration(false)
{
userLabel = new gcn::Label("Name:");
passLabel = new gcn::Label("Password:");
@@ -213,38 +213,11 @@ LoginDialog::action(const std::string& eventId)
}
else
{
- int ret = attemptLogin(user, passField->getText());
-
- if (ret == LOGIN_WRONG_PASSWORD)
- {
- wrongLoginNotice = new OkDialog("Error", "Wrong Password",
- &wrongPasswordNoticeListener);
- }
- else if (ret != LOGIN_OK)
- {
- std::string errorMsg = "Unknown error.";
-
- switch (ret)
- {
- case LOGIN_UNREGISTERED_ID:
- errorMsg = "Unregistered ID.";
- break;
- case LOGIN_EXPIRED:
- errorMsg = "This ID is expired";
- break;
- case LOGIN_REJECTED:
- errorMsg = "Rejected from server";
- break;
- case LOGIN_BLOCKED:
- errorMsg = "You have been blocked by the GM Team";
- break;
- case LOGIN_USERNAME_TWICE:
- errorMsg = "The username does already exist.";
- break;
- }
-
- wrongLoginNotice = new OkDialog("Error", errorMsg);
- }
+ const std::string host(config.getValue("host", "animesites.de"));
+ short port = (short)config.getValue("port", 0);
+ // Attempt to connect to login server
+ openConnection(host.c_str(), port);
+ mStatus = NET_CONNECTING;
}
}
else if (eventId == "cancel")
@@ -315,12 +288,47 @@ LoginDialog::action(const std::string& eventId)
else
{
// No errors detected, register the new user.
- attemptLogin(user + "_M", passField->getText());
+ const std::string host(config.getValue("host", "animesites.de"));
+ short port = (short)config.getValue("port", 0);
+ // Attempt to connect to login server
+ openConnection(host.c_str(), port);
+ mStatus = NET_CONNECTING;
+ registration = true;
+ //attemptLogin(user + "_M", passField->getText());
}
}
}
void
+LoginDialog::logic()
+{
+ switch (mStatus)
+ {
+ case NET_CONNECTING:
+ mStatus = pollConnection();
+ break;
+ case NET_ERROR:
+ logger->log("Login::Unable to connect");
+ errorMessage = "Unable to connect to login server";
+ state = ERROR_STATE;
+ closeConnection();
+ logger->log("Connection closed");
+ break;
+ case NET_CONNECTED:
+ logger->log("Connected...");
+ std::string user = userField->getText();
+ const std::string password = passField->getText();
+ if (registration)
+ {
+ user += "_M";
+ }
+ attemptLogin(user, password);
+ closeConnection();
+ break;
+ }
+}
+
+void
loginInputHandler(SDL_KeyboardEvent *keyEvent)
{
if (keyEvent->keysym.sym == SDLK_ESCAPE)
@@ -329,24 +337,9 @@ loginInputHandler(SDL_KeyboardEvent *keyEvent)
}
}
-int
-attemptLogin(const std::string& user, const std::string& pass)
+void
+LoginDialog::attemptLogin(const std::string& user, const std::string& pass)
{
- int ret;
-
- // Connect to login server
- ret = open_session(
- config.getValue("host", "animesites.de").c_str(),
- (short)config.getValue("port", 0));
-
- if (ret == -1) {
- state = LOGIN_STATE;
- wrongLoginNotice = new OkDialog("Error",
- "Unable to connect to login server");
- return LOGIN_NO_CONNECTION;
- }
-
-
// Send login infos
MessageOut outMsg;
outMsg.writeShort(0x0064);
@@ -359,8 +352,8 @@ attemptLogin(const std::string& user, const std::string& pass)
MessageIn msg = get_next_message();
if (state == ERROR_STATE)
{
- close_session();
- return LOGIN_UNKNOWN_ERROR;
+ closeConnection();
+ return;
}
// Login ok
@@ -393,47 +386,43 @@ attemptLogin(const std::string& user, const std::string& pass)
iptostring(server_info[i]->address),
server_info[i]->port);
}
+ skip(msg.getLength());
state = CHAR_SERVER_STATE;
-
- skip(msg.getLength());
- ret = LOGIN_OK;
}
else if (msg.getId() == 0x006a)
{
int loginError = msg.readByte();
logger->log("Login::error code: %i", loginError);
- ret = 0;
+
switch (loginError) {
case 0:
- ret = LOGIN_UNREGISTERED_ID;
+ errorMessage = "Unregistered ID";
break;
case 1:
- ret = LOGIN_WRONG_PASSWORD;
+ errorMessage = "Wrong password";
break;
case 2:
- ret = LOGIN_EXPIRED;
+ errorMessage = "Account expired";
break;
case 3:
- ret = LOGIN_REJECTED;
+ errorMessage = "Rejected from server";
break;
case 4:
- ret = LOGIN_BLOCKED;
+ errorMessage = "You have been blocked by the GM Team";
break;
case 9:
- ret = LOGIN_USERNAME_TWICE;
+ errorMessage = "This account is already logged in";
break;
}
skip(msg.getLength());
- state = LOGIN_STATE;
+ state = ERROR_STATE;
}
else {
skip(msg.getLength());
- state = LOGIN_STATE;
- ret = LOGIN_UNKNOWN_ERROR;
+ logger->log("Login::Unknown error");
+ errorMessage = "Unknown error";
+ state = ERROR_STATE;
}
// Todo: add other packets, also encrypted
-
- close_session();
- return ret;
}
diff --git a/src/gui/login.h b/src/gui/login.h
index 5f841d37..ae3e8a0f 100644
--- a/src/gui/login.h
+++ b/src/gui/login.h
@@ -54,6 +54,11 @@ class LoginDialog : public Window, public gcn::ActionListener {
* Called when receiving actions from the widgets.
*/
void action(const std::string& eventId);
+
+ /**
+ * Updates dialog logic.
+ */
+ void logic();
// Made them public to have the possibility to request focus
// from external functions.
@@ -69,6 +74,10 @@ class LoginDialog : public Window, public gcn::ActionListener {
gcn::Button *okButton;
gcn::Button *cancelButton;
gcn::Button *registerButton;
+ int mStatus;
+ bool registration;
+
+ void attemptLogin(const std::string& user, const std::string& pass);
};
/**
@@ -99,22 +108,7 @@ class WrongUsernameNoticeListener : public gcn::ActionListener {
*/
void loginInputHandler(SDL_KeyboardEvent *keyEvent);
-/**
- * Attempt to login to login server
- * Return an error code if any, and then stay at LOGIN state.
- * 0 means ok.
- * 1 means Wrong Password
- * 2 means unregistered ID
- * 3 means rejected from server
- * 4 means blocked by GM Team
- * 5 means expired ID
- * 6 means unable to connect to server
- * 9 means username already existing
- * -1 means unknown error
- */
-int attemptLogin(const std::string& user, const std::string& pass);
-
-enum
+/*enum
{
LOGIN_OK = 0,
LOGIN_WRONG_PASSWORD,
@@ -124,8 +118,9 @@ enum
LOGIN_EXPIRED,
LOGIN_NO_CONNECTION,
LOGIN_USERNAME_TWICE = 9,
+ LOGIN_CONNECTING,
LOGIN_UNKNOWN_ERROR = -1
-};
+};*/
#endif