summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYohann Ferreira <bertram@cegetel.net>2005-12-05 20:19:14 +0000
committerYohann Ferreira <bertram@cegetel.net>2005-12-05 20:19:14 +0000
commit48f42f1c4330cc719a8e1658a20505073a4f6386 (patch)
tree51f27837b6a2ee4fd0e33a1755323f9141bb0ef7
parent699e67ad53507638a24d4f932c413e26f318af36 (diff)
downloadmanaserv-48f42f1c4330cc719a8e1658a20505073a4f6386.tar.gz
manaserv-48f42f1c4330cc719a8e1658a20505073a4f6386.tar.bz2
manaserv-48f42f1c4330cc719a8e1658a20505073a4f6386.tar.xz
manaserv-48f42f1c4330cc719a8e1658a20505073a4f6386.zip
Strengthened the way email addresses are checked. Added a good response when selecting a char when not logged. Committed a getEmailList function to see what's wrong.
-rw-r--r--ChangeLog9
-rw-r--r--src/accounthandler.cpp24
-rw-r--r--src/dalstorage.cpp19
-rw-r--r--src/dalstorage.h6
-rw-r--r--src/defines.h3
-rw-r--r--src/storage.h8
6 files changed, 64 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 11aed0ad..68658736 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2005-12-05 Yohann Ferreira <bertram@cegetel.net>
+
+ * src/accounthandler.cpp, src/defines.h: Strengthens the way
+ email addresses checked. Added good response for selecting
+ a char when not logged.
+ * src/storage.h, src/dalstorage.h, src/dalstorage.cpp: Added
+ the getEmailList function, doesn't seem to work, but committed
+ to see why.
+
2005-12-03 Yohann Ferreira <bertram@cegetel.net>
* src/accounthandler.cpp: Handling good conditions to register.
diff --git a/src/accounthandler.cpp b/src/accounthandler.cpp
index 993d72ac..0f7a8b5e 100644
--- a/src/accounthandler.cpp
+++ b/src/accounthandler.cpp
@@ -119,6 +119,20 @@ void AccountHandler::receiveMessage(NetComputer &computer, MessageIn &message)
// The DALstorage will first need to have some getListOf Email function.
std::cout << username << " is trying to register." << std::endl;
+ // Testing Email validity
+ bool emailValid = false;
+ if ((email.find_first_of('@') != std::string::npos)) // Searching for an @.
+ {
+ int atpos = email.find_first_of('@');
+ if (email.find_first_of('.', atpos) != std::string::npos) // Searching for a '.' after the @.
+ {
+ if (email.find_first_of(' ') == std::string::npos) // Searching if there's no spaces.
+ {
+ emailValid = true;
+ }
+ }
+ }
+
// see if the account exists
Account *accPtr = store.getAccount(username);
if ( accPtr ) // Account already exists.
@@ -139,11 +153,11 @@ void AccountHandler::receiveMessage(NetComputer &computer, MessageIn &message)
result.writeByte(REGISTER_INVALID_PASSWORD);
std::cout << email << ": Password too short." << std::endl;
}
- else if ((email.find_first_of('@') == std::string::npos) || (email.find_first_of('.') == std::string::npos))
+ else if (!emailValid)
{
result.writeShort(SMSG_REGISTER_RESPONSE);
result.writeByte(REGISTER_INVALID_EMAIL);
- std::cout << email << ": Email Invalid (misses @ or .)." << std::endl;
+ std::cout << email << ": Email Invalid (misses @, or . after the @, or maybe there is a ' '.)." << std::endl;
}
else
{
@@ -164,6 +178,7 @@ void AccountHandler::receiveMessage(NetComputer &computer, MessageIn &message)
if (computer.getAccount() == NULL) {
result.writeShort(SMSG_CHAR_CREATE_RESPONSE);
result.writeByte(CREATE_NOLOGIN);
+ std::cout << "Not logged in. Can't create a Character." << std::endl;
break;
}
@@ -174,6 +189,7 @@ void AccountHandler::receiveMessage(NetComputer &computer, MessageIn &message)
// TODO: Finish this message type (should a player customize stats
// slightly?)
+ // A player shouldn't have more than 3 characters.
tmwserv::RawStatistics stats = {10, 10, 10, 10, 10, 10};
tmwserv::BeingPtr newCharacter(new tmwserv::Being(name, sex, 1, 0, stats));
@@ -190,7 +206,9 @@ void AccountHandler::receiveMessage(NetComputer &computer, MessageIn &message)
{
if (computer.getAccount() == NULL)
{
- std::cout << "Not Logged in. Can't select Character." << std::endl;
+ result.writeShort(SMSG_CHAR_SELECT_RESPONSE);
+ result.writeByte(SELECT_NOLOGIN);
+ std::cout << "Not logged in. Can't select a Character." << std::endl;
break; // not logged in
}
diff --git a/src/dalstorage.cpp b/src/dalstorage.cpp
index 02f69239..447e3a88 100644
--- a/src/dalstorage.cpp
+++ b/src/dalstorage.cpp
@@ -154,7 +154,7 @@ DALStorage::getAccount(const std::string& userName)
{
// connect to the database (if not connected yet).
open();
-std::cout << "trying " << std::endl;
+
// look for the account in the list first.
Accounts::iterator it =
std::find_if(
@@ -340,6 +340,23 @@ DALStorage::delAccount(const std::string& userName)
}
}
+/**
+ * Return the list of all Emails addresses
+ */
+std::list<std::string>
+DALStorage::getEmailList()
+{
+ std::list <std::string> emailList;
+ Accounts::iterator it = mAccounts.begin();
+ Accounts::iterator it_end = mAccounts.end();
+ for (; it != it_end; )
+ {
+ emailList.push_front( ((it->first).get())->getEmail() );
+ std::cout << ((it->first).get())->getEmail() << std::endl;
+ ++it;
+ }
+ return emailList;
+}
/**
* Save changes to the database permanently.
diff --git a/src/dalstorage.h b/src/dalstorage.h
index 637dfa39..ec69e991 100644
--- a/src/dalstorage.h
+++ b/src/dalstorage.h
@@ -92,6 +92,12 @@ class DALStorage: public Storage
void
delAccount(const std::string& userName);
+ /**
+ * Get the list of Emails in the accounts list.
+ * @return the list of Email's Addresses.
+ */
+ std::list<std::string> getEmailList();
+
/**
* Save changes to the database permanently.
diff --git a/src/defines.h b/src/defines.h
index e49c80d1..5762b14d 100644
--- a/src/defines.h
+++ b/src/defines.h
@@ -150,7 +150,8 @@ enum {
// Character selection return values
enum {
SELECT_OK = 0,
- SELECT_INVALID
+ SELECT_INVALID,
+ SELECT_NOLOGIN
};
// Object type enumeration
diff --git a/src/storage.h b/src/storage.h
index 13b9842f..d366aa50 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -26,6 +26,7 @@
#include <map>
+#include <list>
#include "account.h"
@@ -280,6 +281,13 @@ class Storage
delAccount(const std::string& userName) = 0;
/**
+ * Get the list of Emails in the accounts list.
+ * @return the list of Email's Addresses.
+ */
+ virtual
+ std::list<std::string> getEmailList() = 0;
+
+ /**
* Saves the changes permanently.
*/
virtual void