From 9fa9cb8fa13049fa4ba28d31159b4e1a0c6c0432 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Sun, 12 Jun 2005 12:32:14 +0000 Subject: Some cleanups mostly in account class formatting. --- docs/packets.txt | 2 +- src/account.cpp | 39 ++++++++++++++++++++---------------- src/account.h | 51 ++++++++++++++++++++++------------------------- src/accounthandler.cpp | 6 +++--- src/accounthandler.h | 2 +- src/connectionhandler.cpp | 7 +++++++ src/connectionhandler.h | 18 +++++++++++++++++ 7 files changed, 76 insertions(+), 49 deletions(-) diff --git a/docs/packets.txt b/docs/packets.txt index 7d3b1d8a..bc6ebb1a 100644 --- a/docs/packets.txt +++ b/docs/packets.txt @@ -39,7 +39,7 @@ NOTE: In this representation square brackets mean their content can be repeated C - char (1 byte) S - short (2 bytes) L - long (4 bytes) - + - "fieldName" is the name of the field (choose a meaningful name). - "value" is a list of every possible for the field. diff --git a/src/account.cpp b/src/account.cpp index a4d704ff..a72068b8 100644 --- a/src/account.cpp +++ b/src/account.cpp @@ -23,21 +23,21 @@ #include "account.h" -Account::Account(const std::string &aName, const std::string aPassword, - const std::string &aEmail, Being aPlayer[ACC_MAX_CHARS]) - : name(aName), - password(aPassword), - email(aEmail) +Account::Account() { } -Account::~Account() +Account::Account(const std::string &name, const std::string &password, + const std::string &email, const std::vector &beings): + name(name), + password(password), + email(email), + beings(beings) { } -void Account::setName(const std::string& n) +Account::~Account() { - name = n; } const std::string& Account::getName() @@ -45,23 +45,28 @@ const std::string& Account::getName() return name; } -void Account::setPassword(const std::string& p) +const std::string& Account::getPassword() { - //A hash of p needs to be made then hash stored in password - password = p; + return password; } -const std::string& Account::getPassword() +const std::string& Account::getEmail() { - return password; + return email; } -void Account::setEmail(const std::string& e) +void Account::setName(const std::string &n) { - email = e; + name = n; } -const std::string& Account::getEmail() +void Account::setPassword(const std::string &p) { - return email; + // A hash of p needs to be made then hash stored in password + password = p; +} + +void Account::setEmail(const std::string &e) +{ + email = e; } diff --git a/src/account.h b/src/account.h index 564da11a..cedc1bcc 100644 --- a/src/account.h +++ b/src/account.h @@ -24,39 +24,36 @@ #ifndef ACCOUNT_H #define ACCOUNT_H -#include +#include +#include #include "object.h" #define ACC_MAX_CHARS 4 -//Account definition +/** + * A player account. + */ class Account { - //Account name (username) - std::string name; - //Account password (MD5 hash) - std::string password; - //Account email adress - std::string email; - - //Player data - Being player[ACC_MAX_CHARS]; - - - public: - Account() { }; - Account(const std::string &aName, const std::string aPassword, - const std::string &email, Being aPlayer[ACC_MAX_CHARS]); - ~Account(); - - void setName(const std::string&); - const std::string& getName(); - - void setPassword(const std::string&); - const std::string& getPassword(); - - void setEmail(const std::string&); - const std::string& getEmail(); + public: + Account(); + Account(const std::string &name, const std::string &password, + const std::string &email, const std::vector &beings); + ~Account(); + + void setName(const std::string &name); + void setPassword(const std::string &password); + void setEmail(const std::string &email); + + const std::string& getEmail(); + const std::string& getPassword(); + const std::string& getName(); + + private: + std::string name; /**< Username */ + std::string password; /**< Password (md5 hash) */ + std::string email; /**< Email address */ + std::vector beings; /**< Player data */ }; #endif diff --git a/src/accounthandler.cpp b/src/accounthandler.cpp index 7c3a92b1..40fca0f8 100644 --- a/src/accounthandler.cpp +++ b/src/accounthandler.cpp @@ -32,7 +32,7 @@ void AccountHandler::receiveMessage(NetComputer &computer, MessageIn &message) { int result = 0; - + // determine message type /* switch(message.type) @@ -58,7 +58,7 @@ void AccountHandler::receiveMessage(NetComputer &computer, MessageIn &message) * Return Value: SUCCESS if the player was successfully assigned the * requested char, ERROR on early termination of the * routine. - */ + */ int AccountHandler::loginMessage(NetComputer &computer, MessageIn &message) { // Get the handle (account) the player is requesting @@ -86,7 +86,7 @@ int AccountHandler::loginMessage(NetComputer &computer, MessageIn &message) * Return Value: SUCCESS if the player was successfully assigned the * requested handle, ERROR on early termination of the * routine. - */ + */ int AccountHandler::assignAccount(NetComputer &computer, AccountData *account) { // RETURN TMW_ACCOUNTERROR_ASSIGNFAILED if: the account was accessed before diff --git a/src/accounthandler.h b/src/accounthandler.h index 56ef30cf..c2f7f182 100644 --- a/src/accounthandler.h +++ b/src/accounthandler.h @@ -29,7 +29,7 @@ #include "netcomputer.h" #include "messagein.h" #include "defines.h" - + /** * Manages the data stored in user accounts and provides a reliable interface * for working with an account. The account handler class can be used as a link diff --git a/src/connectionhandler.cpp b/src/connectionhandler.cpp index 6099280f..5f09e9c7 100644 --- a/src/connectionhandler.cpp +++ b/src/connectionhandler.cpp @@ -31,6 +31,11 @@ #define MAX_CLIENTS 1024 +ClientData::ClientData(): + inp(0) +{ +} + ConnectionHandler::ConnectionHandler() { } @@ -106,6 +111,8 @@ void ConnectionHandler::startListen(ListenThreadData *ltd) } else { + // Copy the incoming data to the in buffer of this + // client buffer[result] = 0; logger->log("Received %s", buffer); #ifdef SCRIPT_SUPPORT diff --git a/src/connectionhandler.h b/src/connectionhandler.h index ab01dc2c..cf93e6af 100644 --- a/src/connectionhandler.h +++ b/src/connectionhandler.h @@ -30,9 +30,27 @@ #include #include +#define IN_BUFFER_SIZE 8192 + + // Forward declaration class ListenThreadData; +/** + * Data related to a connected client. This includes the buffer for incoming + * messages and the related socket. + */ +class ClientData +{ + public: + ClientData(); + + TCPsocket sock; /**< The socket used for communication */ + + int inp; /**< The amount of data in the in buffer */ + char in[IN_BUFFER_SIZE]; /**< The in buffer for incoming messages */ +}; + /** * This class represents the connection handler interface. The connection * handler will respond to connect/reconnect/disconnect events and handle -- cgit v1.2.3-70-g09d2