diff options
author | Guillaume Melquiond <guillaume.melquiond@gmail.com> | 2007-08-31 09:14:03 +0000 |
---|---|---|
committer | Guillaume Melquiond <guillaume.melquiond@gmail.com> | 2007-08-31 09:14:03 +0000 |
commit | 99e14d41865086107ec9d69ce725d98d522e448a (patch) | |
tree | ff8f1047029df1c8a694da54d90aeab1b1bc1cc4 | |
parent | 4b43c8653a267ff3ac7224805f4522a94be9fab7 (diff) | |
download | manaserv-99e14d41865086107ec9d69ce725d98d522e448a.tar.gz manaserv-99e14d41865086107ec9d69ce725d98d522e448a.tar.bz2 manaserv-99e14d41865086107ec9d69ce725d98d522e448a.tar.xz manaserv-99e14d41865086107ec9d69ce725d98d522e448a.zip |
Tidied up account server.
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | src/account-server/account.cpp | 17 | ||||
-rw-r--r-- | src/account-server/account.hpp | 7 | ||||
-rw-r--r-- | src/account-server/accountclient.cpp | 18 | ||||
-rw-r--r-- | src/account-server/accountclient.hpp | 25 | ||||
-rw-r--r-- | src/account-server/accounthandler.cpp | 96 |
6 files changed, 53 insertions, 116 deletions
@@ -6,6 +6,12 @@ Modified loading of reference files, so that it is possible to reload them. * src/game-server/command.cpp: Implemented "reload" remote command. + * src/account-server/account.hpp, src/account-server/account.cpp: + Simplified character removal. + * src/account-server/accountclient.hpp, + src/account-server/accounthandler.cpp, + src/account-server/accountclient.cpp: Removed selected character from + client data. Cleaned account handler. 2007-08-30 Guillaume Melquiond <guillaume.melquiond@gmail.com> diff --git a/src/account-server/account.cpp b/src/account-server/account.cpp index bddcf4f9..c37be3a7 100644 --- a/src/account-server/account.cpp +++ b/src/account-server/account.cpp @@ -24,9 +24,6 @@ #include "account-server/account.hpp" -#include "account-server/accountclient.hpp" -#include "utils/functors.h" - /** * Destructor. */ @@ -58,19 +55,9 @@ void Account::addCharacter(Character *character) mCharacters.push_back(character); } -/** - * Remove a character. - */ -bool Account::delCharacter(std::string const &name) +void Account::delCharacter(int i) { - Characters::iterator - end = mCharacters.end(), - it = std::find_if(mCharacters.begin(), end, - std::bind2nd(obj_name_is<Character *>(), name)); - - if (it == end) return false; - mCharacters.erase(it); - return true; + mCharacters.erase(mCharacters.begin() + i); } void Account::setID(int id) diff --git a/src/account-server/account.hpp b/src/account-server/account.hpp index dfc5210f..9b4abb68 100644 --- a/src/account-server/account.hpp +++ b/src/account-server/account.hpp @@ -147,12 +147,11 @@ class Account void addCharacter(Character *character); /** - * Remove a character. + * Removes a character from the account. * - * @param name The character's name to delete. + * @param i index of the character. */ - bool - delCharacter(std::string const &name); + void delCharacter(int i); /** diff --git a/src/account-server/accountclient.cpp b/src/account-server/accountclient.cpp index 04bd6d59..145a18f3 100644 --- a/src/account-server/accountclient.cpp +++ b/src/account-server/accountclient.cpp @@ -23,13 +23,10 @@ #include "account-server/accountclient.hpp" -#include "account-server/accounthandler.hpp" - AccountClient::AccountClient(ENetPeer *peer): NetComputer(peer), status(CLIENT_LOGIN), - mAccount(NULL), - mCharacter(NULL) + mAccount(NULL) { } @@ -38,27 +35,14 @@ AccountClient::~AccountClient() unsetAccount(); } - void AccountClient::setAccount(Account *acc) { unsetAccount(); mAccount = acc; } -void AccountClient::setCharacter(Character *ch) -{ - unsetCharacter(); - mCharacter = ch; -} - void AccountClient::unsetAccount() { - unsetCharacter(); delete mAccount; mAccount = NULL; } - -void AccountClient::unsetCharacter() -{ - mCharacter = NULL; -} diff --git a/src/account-server/accountclient.hpp b/src/account-server/accountclient.hpp index a2c17c0e..aa637f82 100644 --- a/src/account-server/accountclient.hpp +++ b/src/account-server/accountclient.hpp @@ -27,7 +27,6 @@ #include <enet/enet.h> #include "account-server/account.hpp" -#include "account-server/character.hpp" #include "net/netcomputer.hpp" class AccountHandler; @@ -40,8 +39,7 @@ enum }; /** - * A connected computer that can have an account and character associated with - * it. + * A connected computer with an associated account. */ class AccountClient : public NetComputer { @@ -73,32 +71,11 @@ class AccountClient : public NetComputer Account *getAccount() const { return mAccount; } - /** - * Set the selected character associated with connection. - */ - void - setCharacter(Character *ch); - - /** - * Deselect the character associated with connection. - */ - void - unsetCharacter(); - - /** - * Get character associated with the connection - */ - Character *getCharacter() const - { return mCharacter; } - int status; private: /** Account associated with connection */ Account *mAccount; - - /** Selected character */ - Character *mCharacter; }; #endif diff --git a/src/account-server/accounthandler.cpp b/src/account-server/accounthandler.cpp index 9e809588..dd39dce5 100644 --- a/src/account-server/accounthandler.cpp +++ b/src/account-server/accounthandler.cpp @@ -253,8 +253,8 @@ AccountHandler::handleLogoutMessage(AccountClient &computer) { // Delete it from the pendingClient list mTokenCollector.deletePendingClient(&computer); - // deletePendingClient makes sure that the client get's the message - return; + computer.status = CLIENT_LOGIN; + reply.writeByte(ERRMSG_OK); } computer.send(reply); } @@ -277,7 +277,7 @@ handleReconnectMessage(AccountClient &computer, MessageIn &msg) void AccountHandler::handleRegisterMessage(AccountClient &computer, MessageIn &msg) { - unsigned long clientVersion = msg.readLong(); + int clientVersion = msg.readLong(); std::string username = msg.readString(); std::string password = msg.readString(); std::string email = msg.readString(); @@ -388,13 +388,6 @@ AccountHandler::handleUnregisterMessage(AccountClient &computer, storage->delAccount(acc); reply.writeByte(ERRMSG_OK); - // If the account to delete is the current account we're loggedin - // on, get out of it in memory. - if (computer.getAccount() && computer.getAccount()->getName() == username) - { - computer.unsetAccount(); - computer.status = CLIENT_LOGIN; - } computer.send(reply); } @@ -403,7 +396,8 @@ handleEmailChangeMessage(AccountClient &computer, MessageIn &msg) { MessageOut reply(APMSG_EMAIL_CHANGE_RESPONSE); - if (computer.status != CLIENT_CONNECTED || !computer.getAccount()) + Account *acc = computer.getAccount(); + if (!acc) { reply.writeByte(ERRMSG_NO_LOGIN); computer.send(reply); @@ -426,7 +420,7 @@ handleEmailChangeMessage(AccountClient &computer, MessageIn &msg) } else { - computer.getAccount()->setEmail(email); + acc->setEmail(email); reply.writeByte(ERRMSG_OK); } computer.send(reply); @@ -437,7 +431,8 @@ handleEmailGetMessage(AccountClient &computer) { MessageOut reply(APMSG_EMAIL_GET_RESPONSE); - if (computer.status != CLIENT_CONNECTED || !computer.getAccount()) + Account *acc = computer.getAccount(); + if (!acc) { reply.writeByte(ERRMSG_NO_LOGIN); computer.send(reply); @@ -445,7 +440,7 @@ handleEmailGetMessage(AccountClient &computer) } reply.writeByte(ERRMSG_OK); - reply.writeString(computer.getAccount()->getEmail()); + reply.writeString(acc->getEmail()); computer.send(reply); } @@ -459,12 +454,13 @@ AccountHandler::handlePasswordChangeMessage(AccountClient &computer, MessageOut reply(APMSG_PASSWORD_CHANGE_RESPONSE); - if (computer.status != CLIENT_CONNECTED || !computer.getAccount()) + Account *acc = computer.getAccount(); + if (!acc) { reply.writeByte(ERRMSG_NO_LOGIN); } else if (newPassword.length() < MIN_PASSWORD_LENGTH || - newPassword.length() > MAX_PASSWORD_LENGTH) + newPassword.length() > MAX_PASSWORD_LENGTH) { reply.writeByte(ERRMSG_INVALID_ARGUMENT); } @@ -472,13 +468,13 @@ AccountHandler::handlePasswordChangeMessage(AccountClient &computer, { reply.writeByte(ERRMSG_INVALID_ARGUMENT); } - else if (oldPassword != computer.getAccount()->getPassword()) + else if (oldPassword != acc->getPassword()) { reply.writeByte(ERRMSG_FAILURE); } else { - computer.getAccount()->setPassword(newPassword); + acc->setPassword(newPassword); reply.writeByte(ERRMSG_OK); } @@ -496,7 +492,8 @@ AccountHandler::handleCharacterCreateMessage(AccountClient &computer, MessageOut reply(APMSG_CHAR_CREATE_RESPONSE); - if (computer.status != CLIENT_CONNECTED || !computer.getAccount()) + Account *acc = computer.getAccount(); + if (!acc) { reply.writeByte(ERRMSG_NO_LOGIN); } @@ -535,7 +532,7 @@ AccountHandler::handleCharacterCreateMessage(AccountClient &computer, } // An account shouldn't have more than MAX_OF_CHARACTERS characters. - Characters &chars = computer.getAccount()->getCharacters(); + Characters &chars = acc->getCharacters(); if (chars.size() >= MAX_OF_CHARACTERS) { reply.writeByte(CREATE_TOO_MUCH_CHARACTERS); @@ -578,7 +575,7 @@ AccountHandler::handleCharacterCreateMessage(AccountClient &computer, Character *newCharacter = new Character(name); for (int i = CHAR_ATTR_BEGIN; i < CHAR_ATTR_END; ++i) newCharacter->setAttribute(i, attributes[i - CHAR_ATTR_BEGIN]); - newCharacter->setAccount(computer.getAccount()); + newCharacter->setAccount(acc); newCharacter->setLevel(1); newCharacter->setGender(gender); newCharacter->setHairStyle(hairStyle); @@ -587,12 +584,12 @@ AccountHandler::handleCharacterCreateMessage(AccountClient &computer, Point startingPos((int) config.getValue("startX", 512), (int) config.getValue("startY", 512)); newCharacter->setPosition(startingPos); - computer.getAccount()->addCharacter(newCharacter); + acc->addCharacter(newCharacter); LOG_INFO("Character " << name << " was created for " - << computer.getAccount()->getName() << "'s account."); + << acc->getName() << "'s account."); - storage->flush(computer.getAccount()); // flush changes + storage->flush(acc); // flush changes reply.writeByte(ERRMSG_OK); computer.send(reply); @@ -611,15 +608,16 @@ handleCharacterSelectMessage(AccountClient &computer, MessageIn &msg) { MessageOut reply(APMSG_CHAR_SELECT_RESPONSE); - if (computer.status != CLIENT_CONNECTED || !computer.getAccount()) + Account *acc = computer.getAccount(); + if (!acc) { reply.writeByte(ERRMSG_NO_LOGIN); computer.send(reply); return; // not logged in } - unsigned char charNum = msg.readByte(); - Characters &chars = computer.getAccount()->getCharacters(); + unsigned charNum = msg.readByte(); + Characters &chars = acc->getCharacters(); // Character ID = 0 to Number of Characters - 1. if (charNum >= chars.size()) @@ -630,10 +628,12 @@ handleCharacterSelectMessage(AccountClient &computer, MessageIn &msg) return; } + Character *selectedChar = chars[charNum]; + std::string address; short port; - if (!serverHandler->getGameServerFromMap( - chars[charNum]->getMapId(), address, port)) + if (!serverHandler->getGameServerFromMap + (selectedChar->getMapId(), address, port)) { LOG_ERROR("Character Selection: No game server for the map."); reply.writeByte(ERRMSG_FAILURE); @@ -641,9 +641,6 @@ handleCharacterSelectMessage(AccountClient &computer, MessageIn &msg) return; } - // set character - computer.setCharacter(chars[charNum]); - Character *selectedChar = computer.getCharacter(); reply.writeByte(ERRMSG_OK); LOG_DEBUG(selectedChar->getName() << " is trying to enter the servers."); @@ -669,15 +666,16 @@ handleCharacterDeleteMessage(AccountClient &computer, MessageIn &msg) { MessageOut reply(APMSG_CHAR_DELETE_RESPONSE); - if (computer.status != CLIENT_CONNECTED || !computer.getAccount()) + Account *acc = computer.getAccount(); + if (!acc) { reply.writeByte(ERRMSG_NO_LOGIN); computer.send(reply); return; // not logged in } - unsigned char charNum = msg.readByte(); - Characters &chars = computer.getAccount()->getCharacters(); + unsigned charNum = msg.readByte(); + Characters &chars = acc->getCharacters(); // Character ID = 0 to Number of Characters - 1. if (charNum >= chars.size()) @@ -688,21 +686,12 @@ handleCharacterDeleteMessage(AccountClient &computer, MessageIn &msg) return; // not logged in } - // Delete the character. If the character to delete is the current - // character, get off of it in memory. - std::string const &deletedCharacter = chars[charNum]->getName(); - if (computer.getCharacter() && - computer.getCharacter()->getName() == deletedCharacter) - computer.unsetCharacter(); - - computer.getAccount()->delCharacter(deletedCharacter); + LOG_INFO("Character deleted:" << chars[charNum]->getName()); - storage->flush(computer.getAccount()); - - LOG_INFO(deletedCharacter << ": Character deleted..."); + acc->delCharacter(charNum); + storage->flush(acc); reply.writeByte(ERRMSG_OK); - computer.send(reply); } @@ -711,10 +700,8 @@ AccountHandler::tokenMatched(AccountClient *computer, int accountID) { MessageOut reply(APMSG_RECONNECT_RESPONSE); - // Check if the account exists + // Associate account with connection. Account *acc = storage->getAccount(accountID); - - // Associate account with connection computer->setAccount(acc); computer->status = CLIENT_CONNECTED; @@ -722,7 +709,7 @@ AccountHandler::tokenMatched(AccountClient *computer, int accountID) computer->send(reply); // Return information about available characters - Characters &chars = computer->getAccount()->getCharacters(); + Characters &chars = acc->getCharacters(); // Send characters list for (unsigned int i = 0; i < chars.size(); i++) @@ -742,10 +729,7 @@ AccountHandler::deletePendingClient(AccountClient* computer) // The computer will be deleted when the disconnect event is processed } -void -AccountHandler::deletePendingConnect(int accountID) +void AccountHandler::deletePendingConnect(int) { - // NOOP - // No memory was allocated for the PendingConnect (that was not - // allocated to a countedPtr). + // No resources to free. } |