summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2006-08-01 21:41:58 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2006-08-01 21:41:58 +0000
commit3ee67b7374e5fa5fd5f7c44f224d4ba00529e209 (patch)
tree6c87e4b7ddccdd97e0a11144501068b99f643887
parent2c37441be01d58e1714a604645d329575ae95f82 (diff)
downloadmanaserv-3ee67b7374e5fa5fd5f7c44f224d4ba00529e209.tar.gz
manaserv-3ee67b7374e5fa5fd5f7c44f224d4ba00529e209.tar.bz2
manaserv-3ee67b7374e5fa5fd5f7c44f224d4ba00529e209.tar.xz
manaserv-3ee67b7374e5fa5fd5f7c44f224d4ba00529e209.zip
Put handling of registrations in a separate method and cleaned it up a bit.
-rw-r--r--ChangeLog2
-rw-r--r--src/accounthandler.cpp160
-rw-r--r--src/accounthandler.h5
3 files changed, 91 insertions, 76 deletions
diff --git a/ChangeLog b/ChangeLog
index 96cfa8c2..7adb499a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -9,6 +9,8 @@
all messages.
* src/client.cpp: Removed requesting character listing, as this comes
with the succesful register/login responses.
+ * src/accounthandler.cpp, src/accounthandler.h: Put handling of
+ registrations in a separate method and cleaned it up a bit.
2006-07-31 Bjørn Lindeijer <bjorn@lindeijer.nl>
diff --git a/src/accounthandler.cpp b/src/accounthandler.cpp
index 4de1c2aa..2f3f1669 100644
--- a/src/accounthandler.cpp
+++ b/src/accounthandler.cpp
@@ -97,81 +97,7 @@ void AccountHandler::processMessage(NetComputer *comp, MessageIn &message)
break;
case PAMSG_REGISTER:
- {
- unsigned long clientVersion = message.readLong();
- std::string username = message.readString();
- std::string password = message.readString();
- std::string email = message.readString();
- result.writeShort(APMSG_REGISTER_RESPONSE);
-
- if (clientVersion < config.getValue("clientVersion", 0))
- {
- LOG_INFO("Client has an unsufficient version number to login.", 1);
- result.writeByte(REGISTER_INVALID_VERSION);
- break;
- }
-
- // Checking if there are double quotes in it.
- if (stringFilter->findDoubleQuotes(username))
- {
- result.writeByte(ERRMSG_INVALID_ARGUMENT);
- LOG_INFO(username << ": has got double quotes in it.", 1);
- break;
- }
-
- // Checking conditions for having a good account.
- LOG_INFO(username << " is trying to register.", 1);
-
- // see if the account exists
- AccountPtr accPtr = store.getAccount(username);
- if ( accPtr.get() ) // Account already exists.
- {
- result.writeByte(REGISTER_EXISTS_USERNAME);
- LOG_INFO(username << ": Username already exists.", 1);
- }
- else if ((username.length() < MIN_LOGIN_LENGTH) || (username.length() > MAX_LOGIN_LENGTH)) // Username length
- {
- result.writeByte(ERRMSG_INVALID_ARGUMENT);
- LOG_INFO(username << ": Username too short or too long.", 1);
- }
- else if (!stringFilter->filterContent(username)) // Checking if the Name is slang's free.
- {
- result.writeByte(ERRMSG_INVALID_ARGUMENT);
- LOG_INFO(username << ": has got bad words in it.", 1);
- break;
- }
- else if ((password.length() < MIN_PASSWORD_LENGTH) || (password.length() > MAX_PASSWORD_LENGTH))
- {
- result.writeByte(ERRMSG_INVALID_ARGUMENT);
- LOG_INFO(email << ": Password too short or too long.", 1);
- }
- else if (!stringFilter->isEmailValid(email))
- {
- result.writeByte(ERRMSG_INVALID_ARGUMENT);
- LOG_INFO(email << ": Email Invalid, only a@b.c format is accepted.", 1);
- }
- else if (stringFilter->findDoubleQuotes(email))
- {
- result.writeByte(ERRMSG_INVALID_ARGUMENT);
- LOG_INFO(email << ": has got double quotes in it.", 1);
- break;
- }
- else if (store.getSameEmailNumber(email) > 0) // Search if Email already exists.
- {
- result.writeByte(REGISTER_EXISTS_EMAIL);
- LOG_INFO(email << ": Email already exists.", 1);
- }
- else
- {
- AccountPtr acc(new Account(username, password, email));
- store.addAccount(acc);
-
- result.writeByte(ERRMSG_OK);
-
- store.flush(); // flush changes
- LOG_INFO(username << ": Account registered.", 1);
- }
- }
+ handleRegisterMessage(computer, message);
break;
case PAMSG_UNREGISTER:
@@ -193,7 +119,8 @@ void AccountHandler::processMessage(NetComputer *comp, MessageIn &message)
AccountPtr accPtr = store.getAccount(username);
if (!accPtr.get() || accPtr->getPassword() != password) {
- LOG_INFO("Account does not exist of bad password for " << username << ".", 1);
+ LOG_INFO("Account does not exist or bad password for "
+ << username << ".", 1);
result.writeByte(ERRMSG_INVALID_ARGUMENT);
} else {
@@ -711,3 +638,84 @@ AccountHandler::handleLoginMessage(AccountClient &computer, MessageIn &msg)
computer.send(reply.getPacket());
}
+
+void
+AccountHandler::handleRegisterMessage(AccountClient &computer, MessageIn &msg)
+{
+ unsigned long clientVersion = msg.readLong();
+ std::string username = msg.readString();
+ std::string password = msg.readString();
+ std::string email = msg.readString();
+
+ LOG_INFO(username << " is trying to register.", 1);
+
+ MessageOut reply(APMSG_REGISTER_RESPONSE);
+
+ if (clientVersion < config.getValue("clientVersion", 0))
+ {
+ LOG_INFO("Client has an unsufficient version number to login.", 1);
+ reply.writeByte(REGISTER_INVALID_VERSION);
+ }
+ else if (stringFilter->findDoubleQuotes(username))
+ {
+ LOG_INFO(username << ": has got double quotes in it.", 1);
+ reply.writeByte(ERRMSG_INVALID_ARGUMENT);
+ }
+ else if (stringFilter->findDoubleQuotes(email))
+ {
+ LOG_INFO(email << ": has got double quotes in it.", 1);
+ reply.writeByte(ERRMSG_INVALID_ARGUMENT);
+ }
+ else if ((username.length() < MIN_LOGIN_LENGTH) ||
+ (username.length() > MAX_LOGIN_LENGTH))
+ {
+ LOG_INFO(username << ": Username too short or too long.", 1);
+ reply.writeByte(ERRMSG_INVALID_ARGUMENT);
+ }
+ else if ((password.length() < MIN_PASSWORD_LENGTH) ||
+ (password.length() > MAX_PASSWORD_LENGTH))
+ {
+ LOG_INFO(email << ": Password too short or too long.", 1);
+ reply.writeByte(ERRMSG_INVALID_ARGUMENT);
+ }
+ else if (!stringFilter->isEmailValid(email))
+ {
+ LOG_INFO(email << ": Email Invalid, only a@b.c format is accepted.", 1);
+ reply.writeByte(ERRMSG_INVALID_ARGUMENT);
+ }
+ // Checking if the Name is slang's free.
+ else if (!stringFilter->filterContent(username))
+ {
+ LOG_INFO(username << ": has got bad words in it.", 1);
+ reply.writeByte(ERRMSG_INVALID_ARGUMENT);
+ }
+ else
+ {
+ Storage &store = Storage::instance("tmw");
+ AccountPtr accPtr = store.getAccount(username);
+
+ // Check whether the account already exists.
+ if (accPtr.get())
+ {
+ LOG_INFO(username << ": Username already exists.", 1);
+ reply.writeByte(REGISTER_EXISTS_USERNAME);
+ }
+ // Find out whether the email is already in use.
+ else if (store.getSameEmailNumber(email) > 0)
+ {
+ LOG_INFO(email << ": Email already exists.", 1);
+ reply.writeByte(REGISTER_EXISTS_EMAIL);
+ }
+ else
+ {
+ AccountPtr acc(new Account(username, password, email));
+ store.addAccount(acc);
+ store.flush();
+ LOG_INFO(username << ": Account registered.", 1);
+
+ reply.writeByte(ERRMSG_OK);
+ }
+ }
+
+ computer.send(reply.getPacket());
+}
diff --git a/src/accounthandler.h b/src/accounthandler.h
index c4073589..9f23f207 100644
--- a/src/accounthandler.h
+++ b/src/accounthandler.h
@@ -51,8 +51,13 @@ class AccountHandler : public ConnectionHandler
void
computerDisconnected(NetComputer *comp);
+ // --- message handling ---
+
void
handleLoginMessage(AccountClient &computer, MessageIn &msg);
+
+ void
+ handleRegisterMessage(AccountClient &computer, MessageIn &msg);
};
#endif