From 775404c84c3250225d43f10c4a5363e997618cb2 Mon Sep 17 00:00:00 2001 From: Rogier Polak Date: Fri, 23 Feb 2007 19:18:28 +0000 Subject: Added unregistering, logout_then_exit, switch_character and switch_accountserver. --- src/net/accountserver/account.cpp | 7 +- src/net/accountserver/account.h | 5 +- src/net/accountserver/accountserver.cpp | 10 +- src/net/accountserver/accountserver.h | 3 + src/net/chatserver/chatserver.cpp | 7 ++ src/net/chatserver/chatserver.h | 2 + src/net/connection.cpp | 3 +- src/net/gameserver/gameserver.cpp | 9 ++ src/net/gameserver/gameserver.h | 2 + src/net/loginhandler.cpp | 30 +++++ src/net/logouthandler.cpp | 216 ++++++++++++++++++++++++++++++++ src/net/logouthandler.h | 63 ++++++++++ src/net/protocol.h | 10 +- 13 files changed, 361 insertions(+), 6 deletions(-) create mode 100644 src/net/logouthandler.cpp create mode 100644 src/net/logouthandler.h (limited to 'src/net') diff --git a/src/net/accountserver/account.cpp b/src/net/accountserver/account.cpp index daf94a65..16f81f44 100644 --- a/src/net/accountserver/account.cpp +++ b/src/net/accountserver/account.cpp @@ -68,9 +68,14 @@ void Net::AccountServer::Account::selectCharacter(char slot) Net::AccountServer::connection->send(msg); } -void Net::AccountServer::Account::unregister() +void Net::AccountServer::Account::unregister(const std::string &username, + const std::string &password) { MessageOut msg(PAMSG_UNREGISTER); + + msg.writeString(username); + msg.writeString(password); + Net::AccountServer::connection->send(msg); } diff --git a/src/net/accountserver/account.h b/src/net/accountserver/account.h index aaf3afe0..d3c84a15 100644 --- a/src/net/accountserver/account.h +++ b/src/net/accountserver/account.h @@ -41,13 +41,14 @@ namespace Net void selectCharacter(char slot); - void unregister(); + void unregister(const std::string &username, + const std::string &password); void changeEmail(const std::string &email); void getEmail(); - void changePassword(const std::string &oldPassowrd, + void changePassword(const std::string &oldPassword, const std::string &newPassword); } } diff --git a/src/net/accountserver/accountserver.cpp b/src/net/accountserver/accountserver.cpp index 8fde6d5e..92d803e6 100644 --- a/src/net/accountserver/accountserver.cpp +++ b/src/net/accountserver/accountserver.cpp @@ -63,6 +63,14 @@ void Net::AccountServer::logout() { MessageOut msg(PAMSG_LOGOUT); Net::AccountServer::connection->send(msg); +} - Net::AccountServer::connection = 0; +void Net::AccountServer::reconnectAccount(Net::Connection *connection, + const std::string &passToken) +{ + Net::AccountServer::connection = connection; + + MessageOut msg(PAMSG_RECONNECT); + msg.writeString(passToken, 32); + Net::AccountServer::connection->send(msg); } diff --git a/src/net/accountserver/accountserver.h b/src/net/accountserver/accountserver.h index c05b5317..8bfe991c 100644 --- a/src/net/accountserver/accountserver.h +++ b/src/net/accountserver/accountserver.h @@ -40,6 +40,9 @@ namespace Net const std::string &email); void logout(); + + void reconnectAccount(Net::Connection *connection, + const std::string &passToken); } } diff --git a/src/net/chatserver/chatserver.cpp b/src/net/chatserver/chatserver.cpp index e6a3331d..32979ea5 100644 --- a/src/net/chatserver/chatserver.cpp +++ b/src/net/chatserver/chatserver.cpp @@ -43,6 +43,13 @@ void Net::ChatServer::connect(Net::Connection *connection, connection->send(msg); } +void Net::ChatServer::logout() +{ + MessageOut msg(PCMSG_DISCONNECT); + + connection->send(msg); +} + void Net::ChatServer::chat(short channel, const std::string &text) { MessageOut msg(PCMSG_CHAT); diff --git a/src/net/chatserver/chatserver.h b/src/net/chatserver/chatserver.h index 93fe17c4..cf86baf3 100644 --- a/src/net/chatserver/chatserver.h +++ b/src/net/chatserver/chatserver.h @@ -34,6 +34,8 @@ namespace Net { void connect(Net::Connection *connection, const std::string &token); + void logout(); + void chat(short channel, const std::string &text); void announce(const std::string &text); diff --git a/src/net/connection.cpp b/src/net/connection.cpp index 4ce05d4a..ce060ae7 100644 --- a/src/net/connection.cpp +++ b/src/net/connection.cpp @@ -84,7 +84,8 @@ void Net::Connection::disconnect() bool Net::Connection::isConnected() { - return mConnection && mConnection->state == ENET_PEER_STATE_CONNECTED; + return bool (mConnection) ? + (mConnection->state == ENET_PEER_STATE_CONNECTED) : false; } void Net::Connection::send(const MessageOut &msg) diff --git a/src/net/gameserver/gameserver.cpp b/src/net/gameserver/gameserver.cpp index 04e5bb08..8f8ad8ac 100644 --- a/src/net/gameserver/gameserver.cpp +++ b/src/net/gameserver/gameserver.cpp @@ -40,3 +40,12 @@ void Net::GameServer::connect(Net::Connection *connection, Net::GameServer::connection->send(msg); } + +void Net::GameServer::logout(bool reconnectAccount) +{ + MessageOut msg(PGMSG_DISCONNECT); + + msg.writeByte((unsigned char) reconnectAccount); + + Net::GameServer::connection->send(msg); +} diff --git a/src/net/gameserver/gameserver.h b/src/net/gameserver/gameserver.h index ee49d7e3..5bf196b6 100644 --- a/src/net/gameserver/gameserver.h +++ b/src/net/gameserver/gameserver.h @@ -33,6 +33,8 @@ namespace Net namespace GameServer { void connect(Net::Connection *connection, const std::string &token); + + void logout(bool reconnectAccount); } } diff --git a/src/net/loginhandler.cpp b/src/net/loginhandler.cpp index 73be4b2f..c68a620a 100644 --- a/src/net/loginhandler.cpp +++ b/src/net/loginhandler.cpp @@ -33,6 +33,7 @@ LoginHandler::LoginHandler() static const Uint16 _messages[] = { APMSG_LOGIN_RESPONSE, APMSG_REGISTER_RESPONSE, + APMSG_RECONNECT_RESPONSE, 0 }; handledMessages = _messages; @@ -106,5 +107,34 @@ void LoginHandler::handleMessage(MessageIn &msg) } } break; + case APMSG_RECONNECT_RESPONSE: + { + int errMsg = msg.readByte(); + // Successful login + if (errMsg == ERRMSG_OK) + { + state = STATE_CHAR_SELECT; + } + // Login failed + else + { + switch (errMsg) { + case ERRMSG_INVALID_ARGUMENT: + errorMessage = "Wrong magic_token"; + break; + case ERRMSG_FAILURE: + errorMessage = "Already logged in"; + break; + case LOGIN_SERVER_FULL: + errorMessage = "Server is full"; + break; + default: + errorMessage = "Unknown error"; + break; + } + state = STATE_ERROR; + } + } + break; } } diff --git a/src/net/logouthandler.cpp b/src/net/logouthandler.cpp new file mode 100644 index 00000000..b52a38c5 --- /dev/null +++ b/src/net/logouthandler.cpp @@ -0,0 +1,216 @@ +/* + * The Mana World + * Copyright 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include "logouthandler.h" + +#include "messagein.h" +#include "protocol.h" + +#include "../main.h" + +LogoutHandler::LogoutHandler(): +mPassToken(NULL), mScenario(LOGOUT_EXIT), +mLoggedOutAccount(false), mLoggedOutGame(false), mLoggedOutChat(false) +{ + static const Uint16 _messages[] = { + APMSG_LOGOUT_RESPONSE, + APMSG_UNREGISTER_RESPONSE, + GPMSG_DISCONNECT_RESPONSE, + CPMSG_DISCONNECT_RESPONSE, + 0 + }; + handledMessages = _messages; +} + +void LogoutHandler::handleMessage(MessageIn &msg) +{ + switch (msg.getId()) + { + case APMSG_LOGOUT_RESPONSE: + { + int errMsg = msg.readByte(); + + // Successful logout + if (errMsg == ERRMSG_OK) + { + mLoggedOutAccount = true; + + switch (mScenario) + { + case LOGOUT_SWITCH_ACCOUNTSERVER: + if (mLoggedOutGame && mLoggedOutChat) + state = STATE_SWITCH_ACCOUNTSERVER; + break; + + case LOGOUT_EXIT: + default: + if (mLoggedOutGame && mLoggedOutChat) + state = STATE_FORCE_QUIT; + break; + } + } + // Logout failed + else + { + switch (errMsg) { + case ERRMSG_NO_LOGIN: + errorMessage = "Accountserver: Not logged in"; + break; + default: + errorMessage = "Accountserver: Unknown error"; + break; + } + state = STATE_ERROR; + } + } + break; + case APMSG_UNREGISTER_RESPONSE: + { + int errMsg = msg.readByte(); + // Successful unregistration + if (errMsg == ERRMSG_OK) + { + state = STATE_UNREGISTER; + } + // Unregistration failed + else + { + switch (errMsg) { + case ERRMSG_INVALID_ARGUMENT: + errorMessage = + "Accountserver: Wrong username or password"; + break; + default: + errorMessage = "Accountserver: Unknown error"; + break; + } + state = STATE_ERROR; + } + } + break; + case GPMSG_DISCONNECT_RESPONSE: + { + int errMsg = msg.readByte(); + // Successful logout + if (errMsg == ERRMSG_OK) + { + mLoggedOutGame = true; + + switch (mScenario) + { + case LOGOUT_SWITCH_CHARACTER: + if (mPassToken) + { + *mPassToken = msg.readString(32); + mPassToken = NULL; + } + if (mLoggedOutChat) state = STATE_RECONNECT_ACCOUNT; + break; + + case LOGOUT_SWITCH_ACCOUNTSERVER: + if (mLoggedOutAccount && mLoggedOutChat) + state = STATE_SWITCH_ACCOUNTSERVER; + break; + + case LOGOUT_EXIT: + default: + if (mLoggedOutAccount && mLoggedOutChat) + state = STATE_FORCE_QUIT; + break; + } + } + // Logout failed + else + { + switch (errMsg) { + case ERRMSG_NO_LOGIN: + errorMessage = "Gameserver: Not logged in"; + break; + default: + errorMessage = "Gameserver: Unknown error"; + break; + } + state = STATE_ERROR; + } + } + break; + case CPMSG_DISCONNECT_RESPONSE: + { + int errMsg = msg.readByte(); + // Successful logout + if (errMsg == ERRMSG_OK) + { + mLoggedOutChat = true; + + switch (mScenario) + { + case LOGOUT_SWITCH_CHARACTER: + if (mLoggedOutGame) state = STATE_RECONNECT_ACCOUNT; + break; + + case LOGOUT_SWITCH_ACCOUNTSERVER: + if (mLoggedOutAccount && mLoggedOutGame) + state = STATE_SWITCH_ACCOUNTSERVER; + break; + + case LOGOUT_EXIT: + default: + if (mLoggedOutAccount && mLoggedOutGame) + { + state = STATE_FORCE_QUIT; + } + break; + } + } + else + { + switch (errMsg) { + case ERRMSG_NO_LOGIN: + errorMessage = "Chatserver: Not logged in"; + break; + default: + errorMessage = "Chatserver: Unknown error"; + break; + } + state = STATE_ERROR; + } + } + break; + } +} + +void +LogoutHandler::setScenario(unsigned short scenario, std::string* passToken) +{ + mScenario = scenario; + mPassToken = passToken; +} + +void +LogoutHandler::reset() +{ + mPassToken = NULL; + mScenario = LOGOUT_EXIT; + mLoggedOutAccount = false; + mLoggedOutGame = false; + mLoggedOutChat = false; +} diff --git a/src/net/logouthandler.h b/src/net/logouthandler.h new file mode 100644 index 00000000..bf4e1221 --- /dev/null +++ b/src/net/logouthandler.h @@ -0,0 +1,63 @@ +/* + * The Mana World + * Copyright 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#ifndef _TMW_NET_LOGOUTHANDLER_H +#define _TMW_NET_LOGOUTHANDLER_H + +#include + +#include "messagehandler.h" + +/** + * The different scenarios for which LogoutHandler can be used + */ +enum { + LOGOUT_EXIT, + LOGOUT_SWITCH_ACCOUNTSERVER, + LOGOUT_SWITCH_CHARACTER +}; + +class LogoutHandler : public MessageHandler +{ + public: + LogoutHandler(); + + void handleMessage(MessageIn &msg); + + void setScenario(unsigned short scenario, + std::string* passToken = NULL); + + void reset(); + + void setAccountLoggedOut(){ mLoggedOutAccount = true; } + void setGameLoggedOut(){ mLoggedOutGame = true; } + void setChatLoggedOut(){ mLoggedOutChat = true; } + + private: + std::string* mPassToken; + unsigned short mScenario; + bool mLoggedOutAccount; + bool mLoggedOutGame; + bool mLoggedOutChat; +}; + +#endif diff --git a/src/net/protocol.h b/src/net/protocol.h index 096ba29c..78a42e42 100644 --- a/src/net/protocol.h +++ b/src/net/protocol.h @@ -119,7 +119,7 @@ enum { // Login/Register PAMSG_REGISTER = 0x0000, // L version, S username, S password, S email APMSG_REGISTER_RESPONSE = 0x0002, // B error - PAMSG_UNREGISTER = 0x0003, // - + PAMSG_UNREGISTER = 0x0003, // S username, S password APMSG_UNREGISTER_RESPONSE = 0x0004, // B error PAMSG_LOGIN = 0x0010, // L version, S username, S password APMSG_LOGIN_RESPONSE = 0x0012, // B error @@ -144,6 +144,14 @@ enum { PCMSG_CONNECT = 0x0053, // B*32 token CPMSG_CONNECT_RESPONSE = 0x0054, // B error + PGMSG_DISCONNECT = 0x0060, // B reconnect account + GPMSG_DISCONNECT_RESPONSE = 0x0061, // B error, B*32 token + PCMSG_DISCONNECT = 0x0063, // - + CPMSG_DISCONNECT_RESPONSE = 0x0064, // B error + + PAMSG_RECONNECT = 0x0065, // B*32 token + APMSG_RECONNECT_RESPONSE = 0x0066, // B error + // Game GPMSG_PLAYER_MAP_CHANGE = 0x0100, // S filename, W x, W y GPMSG_PLAYER_SERVER_CHANGE = 0x0101, // B*32 token, S game address, W game port -- cgit v1.2.3-70-g09d2