summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2005-06-12 12:32:14 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2005-06-12 12:32:14 +0000
commit9fa9cb8fa13049fa4ba28d31159b4e1a0c6c0432 (patch)
tree5a766717b6af2be67b1475ae2b520e1918599dc1
parent7a8b2b11e989e474dceb30330852174d877b1601 (diff)
downloadmanaserv-9fa9cb8fa13049fa4ba28d31159b4e1a0c6c0432.tar.gz
manaserv-9fa9cb8fa13049fa4ba28d31159b4e1a0c6c0432.tar.xz
manaserv-9fa9cb8fa13049fa4ba28d31159b4e1a0c6c0432.zip
Some cleanups mostly in account class formatting.
-rw-r--r--docs/packets.txt2
-rw-r--r--src/account.cpp39
-rw-r--r--src/account.h51
-rw-r--r--src/accounthandler.cpp6
-rw-r--r--src/accounthandler.h2
-rw-r--r--src/connectionhandler.cpp7
-rw-r--r--src/connectionhandler.h18
7 files changed, 76 insertions, 49 deletions
diff --git a/docs/packets.txt b/docs/packets.txt
index 7d3b1d8..bc6ebb1 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 a4d704f..a72068b 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<Being*> &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 564da11..cedc1bc 100644
--- a/src/account.h
+++ b/src/account.h
@@ -24,39 +24,36 @@
#ifndef ACCOUNT_H
#define ACCOUNT_H
-#include <iostream>
+#include <string>
+#include <vector>
#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<Being*> &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<Being*> beings; /**< Player data */
};
#endif
diff --git a/src/accounthandler.cpp b/src/accounthandler.cpp
index 7c3a92b..40fca0f 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 56ef30c..c2f7f18 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 6099280..5f09e9c 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 ab01dc2..cf93e6a 100644
--- a/src/connectionhandler.h
+++ b/src/connectionhandler.h
@@ -30,10 +30,28 @@
#include <map>
#include <SDL_net.h>
+#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
* incoming messages, passing them on to registered message handlers.