diff options
author | Björn Steinbrink <B.Steinbrink@gmx.de> | 2006-02-04 16:54:35 +0000 |
---|---|---|
committer | Björn Steinbrink <B.Steinbrink@gmx.de> | 2006-02-04 16:54:35 +0000 |
commit | 2d12043f225263004b91e256e4b0d14c4842236e (patch) | |
tree | 6dda6785e9d8853badaaa7b22f87d5ac159626e5 | |
parent | 9dc99e1888de6194c7ce555c33245e6bff586b3d (diff) | |
download | mana-2d12043f225263004b91e256e4b0d14c4842236e.tar.gz mana-2d12043f225263004b91e256e4b0d14c4842236e.tar.bz2 mana-2d12043f225263004b91e256e4b0d14c4842236e.tar.xz mana-2d12043f225263004b91e256e4b0d14c4842236e.zip |
Unify the various login dialogs to use LoginData.
-rw-r--r-- | ChangeLog | 11 | ||||
-rw-r--r-- | src/gui/char_select.cpp | 2 | ||||
-rw-r--r-- | src/gui/char_server.cpp | 26 | ||||
-rw-r--r-- | src/gui/char_server.h | 22 | ||||
-rw-r--r-- | src/localplayer.h | 2 | ||||
-rw-r--r-- | src/logindata.h | 4 | ||||
-rw-r--r-- | src/main.cpp | 68 | ||||
-rw-r--r-- | src/main.h | 3 | ||||
-rw-r--r-- | src/net/charserverhandler.cpp | 17 | ||||
-rw-r--r-- | src/net/charserverhandler.h | 4 | ||||
-rw-r--r-- | src/net/loginhandler.cpp | 7 | ||||
-rw-r--r-- | src/net/loginhandler.h | 7 | ||||
-rw-r--r-- | src/net/network.cpp | 16 | ||||
-rw-r--r-- | src/net/network.h | 5 |
14 files changed, 106 insertions, 88 deletions
@@ -1,4 +1,13 @@ -2006-02-03 Björn Steinbrink <B.Steinbrink@gmx.de> +2006-02-04 Björn Steinbrink <B.Steinbrink@gmx.de> + + * src/localplayer.h, src/logindata.h, src/main.cpp, src/main.h, + src/gui/char_select.cpp, src/gui/char_server.cpp, + src/gui/char_server.h, src/net/charserverhandler.cpp, + src/net/charserverhandler.h, src/net/loginhandler.cpp, + src/net/loginhandler.h, src/net/network.cpp, src/net/network.h: Unify + the gui code for the various logins to use LoginData. + +2006-02-03 Björn Steinbrink <B.Steinbrink@gmx.de> * src/logindata.h, src/main.cpp, src/gui/login.cpp, src/gui/login.h: Made the login dialog work on LoginData only, without playing with the diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp index c54481f4..621dc461 100644 --- a/src/gui/char_select.cpp +++ b/src/gui/char_select.cpp @@ -222,7 +222,7 @@ void CharSelectDialog::attemptCharDelete() // Request character deletion MessageOut outMsg(mNetwork); outMsg.writeInt16(0x0068); - outMsg.writeInt32(mCharInfo->getEntry()->mLoginId); + outMsg.writeInt32(mCharInfo->getEntry()->mCharId); outMsg.writeString("a@a.com", 40); mCharInfo->lock(); } diff --git a/src/gui/char_server.cpp b/src/gui/char_server.cpp index c66d4436..876bcd0e 100644 --- a/src/gui/char_server.cpp +++ b/src/gui/char_server.cpp @@ -29,13 +29,27 @@ #include "listbox.h" #include "scrollarea.h" +#include "../logindata.h" #include "../main.h" #include "../serverinfo.h" +#include "../net/network.h" // TODO this is just for iptostring, move that? + extern SERVER_INFO **server_info; -ServerSelectDialog::ServerSelectDialog(): - Window("Select Server") +/** + * The list model for the server list. + */ +class ServerListModel : public gcn::ListModel { + public: + virtual ~ServerListModel() {}; + + int getNumberOfElements(); + std::string getElementAt(int i); +}; + +ServerSelectDialog::ServerSelectDialog(LoginData *loginData): + Window("Select Server"), mLoginData(loginData) { serverListModel = new ServerListModel(); serverList = new ListBox(serverListModel); @@ -91,6 +105,9 @@ ServerSelectDialog::action(const std::string& eventId) { if (eventId == "ok") { okButton->setEnabled(false); + const SERVER_INFO *si = server_info[serverList->getSelected()]; + mLoginData->hostname = iptostring(si->address); + mLoginData->port = si->port; state = CHAR_CONNECT_STATE; } else if (eventId == "cancel") { @@ -98,11 +115,6 @@ ServerSelectDialog::action(const std::string& eventId) } } -SERVER_INFO* ServerSelectDialog::getServerInfo() -{ - return server_info[serverList->getSelected()]; -} - int ServerListModel::getNumberOfElements() { diff --git a/src/gui/char_server.h b/src/gui/char_server.h index ed6e4c14..b4112d75 100644 --- a/src/gui/char_server.h +++ b/src/gui/char_server.h @@ -31,18 +31,8 @@ #include "../guichanfwd.h" -class SERVER_INFO; - -/** - * The list model for the server list. - */ -class ServerListModel : public gcn::ListModel { - public: - virtual ~ServerListModel() {}; - - int getNumberOfElements(); - std::string getElementAt(int i); -}; +class LoginData; +class ServerListModel; /** * The server select dialog. @@ -56,7 +46,7 @@ class ServerSelectDialog : public Window, public gcn::ActionListener { * * @see Window::Window */ - ServerSelectDialog(); + ServerSelectDialog(LoginData *loginData); /** * Destructor. @@ -68,12 +58,8 @@ class ServerSelectDialog : public Window, public gcn::ActionListener { */ void action(const std::string& eventId); - /** - * Returns the index of the selected server - */ - SERVER_INFO* getServerInfo(); - private: + LoginData *mLoginData; ServerListModel *serverListModel; gcn::ListBox *serverList; gcn::Button *okButton; diff --git a/src/localplayer.h b/src/localplayer.h index 9bd0bf37..56814e05 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -112,7 +112,7 @@ class LocalPlayer : public Player void revive(); - Uint32 mLoginId; + Uint32 mCharId; Uint32 xp, jobXp; Uint16 lvl; diff --git a/src/logindata.h b/src/logindata.h index a5a48687..c7bee88a 100644 --- a/src/logindata.h +++ b/src/logindata.h @@ -31,6 +31,10 @@ struct LoginData std::string hostname; short port; + int account_ID; + int session_ID1; + int session_ID2; + bool remember; }; diff --git a/src/main.cpp b/src/main.cpp index 3424e90a..4e47f7e4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -52,7 +52,6 @@ #ifdef USE_OPENGL #include "openglgraphics.h" #endif -#include "serverinfo.h" #include "sound.h" #include "graphic/spriteset.h" @@ -77,16 +76,15 @@ #include "resources/resourcemanager.h" // Account infos -int account_ID, session_ID1, session_ID2; char sex, n_server, n_character; Spriteset *hairset = NULL, *playerset = NULL; Graphics *graphics; +// TODO Anyone knows a good location for this? Or a way to make it non-global? +class SERVER_INFO; SERVER_INFO **server_info; -int map_address, char_ID; -short map_port; unsigned char state; std::string errorMessage; unsigned char screen_mode; @@ -396,7 +394,7 @@ void parseOptions(int argc, char *argv[], Options &options) } CharServerHandler charServerHandler; -LoginData accountLoginData; +LoginData loginData; LoginHandler loginHandler; LockedArray<LocalPlayer*> charInfo(MAX_SLOT + 1); MapLoginHandler mapLoginHandler; @@ -406,8 +404,9 @@ void accountLogin(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.c_str(), loginData->port); + network->connect(loginData->hostname, loginData->port); network->registerHandler(&loginHandler); + loginHandler.setLoginData(loginData); // Send login infos MessageOut outMsg(network); @@ -417,6 +416,9 @@ void accountLogin(Network *network, LoginData *loginData) outMsg.writeString(loginData->password, 24); outMsg.writeInt8(0); // unknown + // Clear the password, avoids auto login when returning to login + loginData->password = ""; + // TODO This is not the best place to save the config, but at least better // than the login gui window if (loginData->remember) { @@ -426,19 +428,20 @@ void accountLogin(Network *network, LoginData *loginData) config.setValue("remember", loginData->remember); } -void charLogin(Network *network, const SERVER_INFO *si) +void charLogin(Network *network, LoginData *loginData) { logger->log("Trying to connect to char server..."); - network->connect(iptostring(si->address), si->port); + network->connect(loginData->hostname, loginData->port); network->registerHandler(&charServerHandler); charServerHandler.setCharInfo(&charInfo); + charServerHandler.setLoginData(loginData); // Send login infos MessageOut outMsg(network); outMsg.writeInt16(0x0065); - outMsg.writeInt32(account_ID); - outMsg.writeInt32(session_ID1); - outMsg.writeInt32(session_ID2); + outMsg.writeInt32(loginData->account_ID); + outMsg.writeInt32(loginData->session_ID1); + outMsg.writeInt32(loginData->session_ID2); outMsg.writeInt16(0); // unknown outMsg.writeInt8(sex); @@ -446,21 +449,22 @@ void charLogin(Network *network, const SERVER_INFO *si) network->skip(4); } -void mapLogin(Network *network) +void mapLogin(Network *network, LoginData *loginData) { - const char *host = iptostring(map_address); MessageOut outMsg(network); logger->log("Trying to connect to map server..."); - network->connect(host, map_port); + logger->log("Map: %s", map_path.c_str()); + + network->connect(loginData->hostname, loginData->port); network->registerHandler(&mapLoginHandler); // Send login infos outMsg.writeInt16(0x0072); - outMsg.writeInt32(account_ID); - outMsg.writeInt32(char_ID); - outMsg.writeInt32(session_ID1); - outMsg.writeInt32(session_ID2); + outMsg.writeInt32(loginData->account_ID); + outMsg.writeInt32(player_node->mCharId); + outMsg.writeInt32(loginData->session_ID1); + outMsg.writeInt32(loginData->session_ID2); outMsg.writeInt8(sex); // We get 4 useless bytes before the real answer comes in @@ -514,18 +518,18 @@ int main(int argc, char *argv[]) sound.playMusic(TMW_DATADIR "data/music/Magick - Real.ogg"); - accountLoginData.username = options.username; - if (accountLoginData.username.empty()) { + loginData.username = options.username; + if (loginData.username.empty()) { if (config.getValue("remember", 0)) { - accountLoginData.username = config.getValue("username", ""); + loginData.username = config.getValue("username", ""); } } if (!options.password.empty()) { - accountLoginData.password = options.password; + loginData.password = options.password; } - accountLoginData.hostname = config.getValue("host", "animesites.de"); - accountLoginData.port = (short)config.getValue("port", 0); - accountLoginData.remember = config.getValue("remember", 0); + loginData.hostname = config.getValue("host", "animesites.de"); + loginData.port = (short)config.getValue("port", 0); + loginData.remember = config.getValue("remember", 0); SDLNet_Init(); Network *network = new Network(); @@ -605,21 +609,21 @@ int main(int argc, char *argv[]) switch (state) { case LOGIN_STATE: logger->log("State: LOGIN"); - if (!accountLoginData.password.empty()) { + if (!loginData.password.empty()) { state = ACCOUNT_STATE; } else { - currentDialog = new LoginDialog(&accountLoginData); + currentDialog = new LoginDialog(&loginData); } break; case REGISTER_STATE: logger->log("State: REGISTER"); - currentDialog = new RegisterDialog(&accountLoginData); + currentDialog = new RegisterDialog(&loginData); break; case CHAR_SERVER_STATE: logger->log("State: CHAR_SERVER"); - currentDialog = new ServerSelectDialog(); + currentDialog = new ServerSelectDialog(&loginData); if (options.chooseDefault) { ((ServerSelectDialog*)currentDialog)->action("ok"); } @@ -663,16 +667,16 @@ int main(int argc, char *argv[]) case CONNECTING_STATE: logger->log("State: CONNECTING"); - mapLogin(network); + mapLogin(network, &loginData); currentDialog = new ConnectionDialog(); break; case CHAR_CONNECT_STATE: - charLogin(network, ((ServerSelectDialog*)currentDialog)->getServerInfo()); + charLogin(network, &loginData); break; case ACCOUNT_STATE: - accountLogin(network, &accountLoginData); + accountLogin(network, &loginData); break; default: @@ -67,9 +67,6 @@ enum { LEN_MIN_PASSWORD = 4 }; -extern int map_address, char_ID; -extern short map_port; -extern int account_ID, session_ID1, session_ID2; extern char sex, n_server, n_character; extern unsigned char state; extern std::string errorMessage; diff --git a/src/net/charserverhandler.cpp b/src/net/charserverhandler.cpp index e7fe3955..015c9d94 100644 --- a/src/net/charserverhandler.cpp +++ b/src/net/charserverhandler.cpp @@ -30,6 +30,7 @@ #include "../game.h" #include "../localplayer.h" #include "../log.h" +#include "../logindata.h" #include "../main.h" #include "../gui/ok_dialog.h" @@ -119,11 +120,11 @@ void CharServerHandler::handleMessage(MessageIn *msg) break; case 0x0071: - char_ID = msg->readInt32(); - map_path = msg->readString(16); - map_address = msg->readInt32(); - map_port = msg->readInt16(); player_node = mCharInfo->getEntry(); + msg->skip(4); // CharID, must be the same as player_node->charID + map_path = msg->readString(16); + mLoginData->hostname = iptostring(msg->readInt32()); + mLoginData->port = msg->readInt16(); mCharInfo->unlock(); mCharInfo->select(0); // Clear unselected players infos @@ -136,10 +137,6 @@ void CharServerHandler::handleMessage(MessageIn *msg) } while (mCharInfo->getPos()); state = CONNECTING_STATE; - - logger->log("CharSelect: Map: %s", map_path.c_str()); - logger->log("CharSelect: Server: %s:%i", iptostring(map_address), - map_port); break; case 0x0081: @@ -165,9 +162,9 @@ void CharServerHandler::handleMessage(MessageIn *msg) LocalPlayer* CharServerHandler::readPlayerData(MessageIn *msg, int &slot) { - LocalPlayer *tempPlayer = new LocalPlayer(account_ID, 0, NULL); + LocalPlayer *tempPlayer = new LocalPlayer(mLoginData->account_ID, 0, NULL); - tempPlayer->mLoginId = msg->readInt32(); + tempPlayer->mCharId = msg->readInt32(); tempPlayer->totalWeight = 0; tempPlayer->maxWeight = 0; tempPlayer->lastAttackTime = 0; diff --git a/src/net/charserverhandler.h b/src/net/charserverhandler.h index 21178377..16d2c361 100644 --- a/src/net/charserverhandler.h +++ b/src/net/charserverhandler.h @@ -29,6 +29,7 @@ #include "../lockedarray.h" class LocalPlayer; +class LoginData; class CharServerHandler : public MessageHandler { @@ -39,7 +40,10 @@ class CharServerHandler : public MessageHandler void setCharInfo(LockedArray<LocalPlayer*> *charInfo) { mCharInfo = charInfo; }; + void setLoginData(LoginData *loginData) { mLoginData = loginData; }; + protected: + LoginData *mLoginData; LockedArray<LocalPlayer*> *mCharInfo; LocalPlayer* readPlayerData(MessageIn *msg, int &slot); diff --git a/src/net/loginhandler.cpp b/src/net/loginhandler.cpp index fd525d99..aca08e6a 100644 --- a/src/net/loginhandler.cpp +++ b/src/net/loginhandler.cpp @@ -28,6 +28,7 @@ #include "protocol.h" #include "../log.h" +#include "../logindata.h" #include "../main.h" #include "../serverinfo.h" @@ -54,9 +55,9 @@ void LoginHandler::handleMessage(MessageIn *msg) n_server = (msg->getLength() - 47) / 32; server_info = (SERVER_INFO**)malloc(sizeof(SERVER_INFO*) * n_server); - session_ID1 = msg->readInt32(); - account_ID = msg->readInt32(); - session_ID2 = msg->readInt32(); + mLoginData->session_ID1 = msg->readInt32(); + mLoginData->account_ID = msg->readInt32(); + mLoginData->session_ID2 = msg->readInt32(); msg->skip(30); // unknown sex = msg->readInt8(); diff --git a/src/net/loginhandler.h b/src/net/loginhandler.h index 99ade7f1..52014559 100644 --- a/src/net/loginhandler.h +++ b/src/net/loginhandler.h @@ -26,12 +26,19 @@ #include "messagehandler.h" +struct LoginData; + class LoginHandler : public MessageHandler { public: LoginHandler(); void handleMessage(MessageIn *msg); + + void setLoginData(LoginData *loginData) { mLoginData = loginData; }; + + protected: + LoginData *mLoginData; }; #endif diff --git a/src/net/network.cpp b/src/net/network.cpp index f519a467..9e6f6621 100644 --- a/src/net/network.cpp +++ b/src/net/network.cpp @@ -91,7 +91,7 @@ int networkThread(void *data) } Network::Network(): - mAddress(0), mPort(0), + mAddress(), mPort(0), mInBuffer(new char[BUFFER_SIZE]), mOutBuffer(new char[BUFFER_SIZE]), mInSize(0), mOutSize(0), @@ -106,9 +106,6 @@ Network::~Network() { clearHandlers(); - if (mAddress) - free(mAddress); - if (mState != IDLE && mState != ERROR) disconnect(); @@ -118,7 +115,7 @@ Network::~Network() delete mOutBuffer; } -bool Network::connect(const char *address, short port) +bool Network::connect(const std::string &address, short port) { if (mState != IDLE && mState != ERROR) { @@ -126,17 +123,16 @@ bool Network::connect(const char *address, short port) return false; } - if (!address) + if (address.empty()) { logger->log("Empty address given to Network::connect()!"); mState = ERROR; return false; } - if (mAddress) - free(mAddress); + logger->log("Network::Connecting to %s:%i", address.c_str(), port); - mAddress = strdup(address); + mAddress = address; mPort = port; // Reset to sane values @@ -322,7 +318,7 @@ bool Network::realConnect() { IPaddress ipAddress; - if (SDLNet_ResolveHost(&ipAddress, mAddress, mPort) == -1) + if (SDLNet_ResolveHost(&ipAddress, mAddress.c_str(), mPort) == -1) { logger->log("Error in SDLNet_ResolveHost(): %s", SDLNet_GetError()); mState = ERROR; diff --git a/src/net/network.h b/src/net/network.h index 75bde584..06abc445 100644 --- a/src/net/network.h +++ b/src/net/network.h @@ -27,6 +27,7 @@ #include <map> #include <SDL_net.h> #include <SDL_thread.h> +#include <string> class MessageHandler; class MessageIn; @@ -42,7 +43,7 @@ class Network Network(); ~Network(); - bool connect(const char *address, short port); + bool connect(const std::string &address, short port); void disconnect(); void registerHandler(MessageHandler *handler); @@ -75,7 +76,7 @@ class Network TCPsocket mSocket; - char *mAddress; + std::string mAddress; short mPort; char *mInBuffer, *mOutBuffer; |