summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/account.cpp1
-rw-r--r--src/account.h1
-rw-r--r--src/accounthandler.cpp42
-rw-r--r--src/dalstorage.cpp15
-rw-r--r--src/defines.h57
5 files changed, 96 insertions, 20 deletions
diff --git a/src/account.cpp b/src/account.cpp
index c44af2d9..bf20ac34 100644
--- a/src/account.cpp
+++ b/src/account.cpp
@@ -26,7 +26,6 @@
#include "account.h"
-
namespace tmwserv
{
diff --git a/src/account.h b/src/account.h
index 7e1322cc..f45ec7c4 100644
--- a/src/account.h
+++ b/src/account.h
@@ -185,7 +185,6 @@ class Account
Beings&
getCharacters(void);
-
/**
* Get a character by name.
*
diff --git a/src/accounthandler.cpp b/src/accounthandler.cpp
index 63b2d3d6..602f5845 100644
--- a/src/accounthandler.cpp
+++ b/src/accounthandler.cpp
@@ -121,11 +121,11 @@ void AccountHandler::receiveMessage(NetComputer &computer, MessageIn &message)
// looking the email address already exists.
std::list<std::string> emailList = store.getEmailList();
std::string upcasedEmail, upcasedIt;
+ upcasedEmail = email;
+ std::transform(upcasedEmail.begin(), upcasedEmail.end(), upcasedEmail.begin(), (int(*)(int))std::toupper);
for (std::list<std::string>::const_iterator it = emailList.begin(); it != emailList.end(); it++)
{
// Upcasing both mails for a good comparison
- upcasedEmail = email;
- std::transform(upcasedEmail.begin(), upcasedEmail.end(), upcasedEmail.begin(), (int(*)(int))std::toupper);
upcasedIt = *it;
std::transform(upcasedIt.begin(), upcasedIt.end(), upcasedIt.begin(), (int(*)(int))std::toupper);
if ( upcasedEmail == upcasedIt )
@@ -161,13 +161,13 @@ void AccountHandler::receiveMessage(NetComputer &computer, MessageIn &message)
result.writeByte(REGISTER_EXISTS_USERNAME);
std::cout << username << ": Username already exists." << std::endl;
}
- else if ((username.length() < 4) || (username.length() > 16)) // Username length
+ else if ((username.length() < MIN_LOGIN_LENGTH) || (username.length() > MAX_LOGIN_LENGTH)) // Username length
{
result.writeShort(SMSG_REGISTER_RESPONSE);
result.writeByte(REGISTER_INVALID_USERNAME);
std::cout << username << ": Username too short or too long." << std::endl;
}
- else if (password.length() < 4)
+ else if (password.length() < MIN_PASSWORD_LENGTH)
{
result.writeShort(SMSG_REGISTER_RESPONSE);
result.writeByte(REGISTER_INVALID_PASSWORD);
@@ -187,8 +187,8 @@ void AccountHandler::receiveMessage(NetComputer &computer, MessageIn &message)
result.writeShort(SMSG_REGISTER_RESPONSE);
result.writeByte(REGISTER_OK);
- std::cout << username << ": Account registered." << std::endl;
store.flush(); // flush changes
+ std::cout << username << ": Account registered." << std::endl;
}
}
break;
@@ -202,23 +202,29 @@ void AccountHandler::receiveMessage(NetComputer &computer, MessageIn &message)
break;
}
+ // A player shouldn't have more than 3 characters.
+ tmwserv::Beings &chars = computer.getAccount()->getCharacters();
+ if (chars.size() >= MAX_OF_CHARACTERS)
+ {
+ result.writeShort(SMSG_CHAR_CREATE_RESPONSE);
+ result.writeByte(CREATE_TOO_MUCH_CHARACTERS);
+ std::cout << "Already has 3 characters. Can't create another Character." << std::endl;
+ break;
+ }
+
std::string name = message.readString();
//char hairStyle = message.readByte();
//char hairColor = message.readByte();
Genders sex = (Genders)message.readByte();
- // TODO: Finish this message type (should a player customize stats
- // slightly?)
- // A player shouldn't have more than 3 characters.
-
+ // TODO: Customization of player's stats...
tmwserv::RawStatistics stats = {10, 10, 10, 10, 10, 10};
tmwserv::BeingPtr newCharacter(new tmwserv::Being(name, sex, 1, 0, stats));
computer.getAccount()->addCharacter(newCharacter);
+ store.flush(); // flush changes
result.writeShort(SMSG_CHAR_CREATE_RESPONSE);
result.writeByte(CREATE_OK);
-
- store.flush(); // flush changes
}
break;
@@ -235,11 +241,18 @@ void AccountHandler::receiveMessage(NetComputer &computer, MessageIn &message)
unsigned char charNum = message.readByte();
tmwserv::Beings &chars = computer.getAccount()->getCharacters();
-
result.writeShort(SMSG_CHAR_SELECT_RESPONSE);
+ if ( chars.size() == 0 )
+ {
+ result.writeByte(SELECT_NOT_YET_CHARACTERS);
+ std::cout << "Character Selection : Yet no characters created." << std::endl;
+ break;
+ }
+ // Character ID = 0 to Number of Characters - 1.
if (charNum >= chars.size()) {
// invalid char selection
result.writeByte(SELECT_INVALID);
+ std::cout << "Character Selection : Selection out of ID range." << std::endl;
break;
}
@@ -251,6 +264,11 @@ void AccountHandler::receiveMessage(NetComputer &computer, MessageIn &message)
state.addBeing(computer.getCharacter(), computer.getCharacter()->getMap());
result.writeByte(SELECT_OK);
+ std::cout << "Selected Character " << int(charNum)
+ << " : " <<
+ computer.getCharacter()->getName() << std::endl;
+
+ //TODO: Add the character in the database and flush.
}
break;
diff --git a/src/dalstorage.cpp b/src/dalstorage.cpp
index c62b0dc4..187a9a26 100644
--- a/src/dalstorage.cpp
+++ b/src/dalstorage.cpp
@@ -73,15 +73,26 @@ DALStorage::open(void)
using namespace dal;
+ static bool dbFileShown = false;
+ std::string dbFile(getName());
try {
// open a connection to the database.
#if defined (MYSQL_SUPPORT) || defined (POSTGRESQL_SUPPORT)
mDb->connect(getName(), getUser(), getPassword());
+ if (!dbFileShown)
+ {
+ LOG_INFO("Using " << dbFile << " as Database Name.")
+ dbFileShown = true;
+ }
#elif defined (SQLITE_SUPPORT)
// create the database file name.
- std::string dbFile(getName());
dbFile += ".db";
mDb->connect(dbFile, "", "");
+ if (!dbFileShown)
+ {
+ LOG_INFO("SQLite uses ./" << dbFile << " as DB.")
+ dbFileShown = true;
+ }
#endif
// ensure that the required tables are created.
@@ -340,7 +351,7 @@ DALStorage::delAccount(const std::string& userName)
}
/**
- * Return the list of all Emails addresses
+ * Return the list of all Emails addresses.
*/
std::list<std::string>
DALStorage::getEmailList()
diff --git a/src/defines.h b/src/defines.h
index 5762b14d..716ec65e 100644
--- a/src/defines.h
+++ b/src/defines.h
@@ -54,6 +54,26 @@ typedef enum {
GENDER_UNKNOWN
} Genders;
+enum {
+ // Registering related
+ MIN_LOGIN_LENGTH = 4,
+ MAX_LOGIN_LENGTH = 16,
+ MIN_PASSWORD_LENGTH = 4,
+
+ // Character related
+ MAX_OF_CHARACTERS = 3,
+/** Tells the max difference between the
+ * less big stat and the biggest one.
+ * So that players haven't disproportionned
+ * Raw statistics.
+ */
+ MAX_DIFF_BETWEEN_STATS = 5,
+/**
+ * Points to give to a brand new character
+ */
+ POINTS_TO_DISTRIBUTES_AT_LVL1 = 60
+};
+
/**
* Enumerated type for communicated messages
*/
@@ -62,15 +82,19 @@ enum {
CMSG_REGISTER = 0x0000,
CMSG_ENCRYPTED_REGISTER = 0x0001,
SMSG_REGISTER_RESPONSE = 0x0002,
+ CMSG_UNREGISTER = 0x0003,
+ SMSG_UNREGISTER_RESPONSE = 0x0004,
CMSG_LOGIN = 0x0010,
CMSG_ENCRYPTED_LOGIN = 0x0011,
SMSG_LOGIN_ERROR = 0x0012,
SMSG_LOGIN_CONFIRM = 0x0013,
CMSG_CHAR_CREATE = 0x0020,
SMSG_CHAR_CREATE_RESPONSE = 0x0021,
- CMSG_CHAR_LIST = 0x0022, // this is required after char creation
- CMSG_CHAR_SELECT = 0x0023,
- SMSG_CHAR_SELECT_RESPONSE = 0x0034,
+ CMSG_CHAR_DELETE = 0x0022,
+ SMSG_CHAR_DELETE_RESPONSE = 0x0023,
+ CMSG_CHAR_LIST = 0x0024, // this is required after char creation
+ CMSG_CHAR_SELECT = 0x0030,
+ SMSG_CHAR_SELECT_RESPONSE = 0x0031,
// Objects
SMSG_NEW_OBJECT = 0x0100,
@@ -126,6 +150,13 @@ enum {
LOGIN_UNKNOWN
};
+// Logout return values
+enum {
+ LOGOUT_OK = 0,
+ LOGOUT_UNSUCCESSFULL,
+ LOGOUT_UNKNOWN
+};
+
// Account register return values
enum {
REGISTER_OK = 0,
@@ -136,6 +167,14 @@ enum {
REGISTER_EXISTS_EMAIL
};
+// Account deletion return values
+enum {
+ UNREGISTER_OK = 0,
+ UNREGISTER_INVALID_USERNAME,
+ UNREGISTER_INVALID_PASSWORD,
+ UNREGISTER_INVALID_UNSUFFICIENT_RIGHTS
+};
+
// Character creation return values
enum {
CREATE_OK = 0,
@@ -143,14 +182,24 @@ enum {
CREATE_INVALID_HAIR,
CREATE_INVALID_SEX,
CREATE_EXISTS_USERNAME,
- CREATE_EXISTS_EMAIL,
+ CREATE_TOO_MUCH_CHARACTERS,
CREATE_NOLOGIN
};
+// Character deletion return values
+enum {
+ DELETE_OK = 0,
+ DELETE_INVALID_NAME,
+ DELETE_NO_MORE_CHARACTERS,
+ DELETE_NOLOGIN
+};
+
// Character selection return values
+// (When selecting a new one, you deselect the previous.)
enum {
SELECT_OK = 0,
SELECT_INVALID,
+ SELECT_NOT_YET_CHARACTERS,
SELECT_NOLOGIN
};