summaryrefslogtreecommitdiff
path: root/src/account-server
diff options
context:
space:
mode:
Diffstat (limited to 'src/account-server')
-rw-r--r--src/account-server/accountclient.cpp6
-rw-r--r--src/account-server/accountclient.hpp12
-rw-r--r--src/account-server/accounthandler.cpp16
3 files changed, 34 insertions, 0 deletions
diff --git a/src/account-server/accountclient.cpp b/src/account-server/accountclient.cpp
index 3b9f35e8..18eab583 100644
--- a/src/account-server/accountclient.cpp
+++ b/src/account-server/accountclient.cpp
@@ -26,6 +26,7 @@ AccountClient::AccountClient(ENetPeer *peer):
status(CLIENT_LOGIN),
mAccount(NULL)
{
+ time(&lastLoginAttempt);
}
AccountClient::~AccountClient()
@@ -44,3 +45,8 @@ void AccountClient::unsetAccount()
delete mAccount;
mAccount = NULL;
}
+
+void AccountClient::updateLoginAttempt()
+{
+ time(&lastLoginAttempt);
+}
diff --git a/src/account-server/accountclient.hpp b/src/account-server/accountclient.hpp
index b0bb0c3f..600ec2db 100644
--- a/src/account-server/accountclient.hpp
+++ b/src/account-server/accountclient.hpp
@@ -69,11 +69,23 @@ class AccountClient : public NetComputer
Account *getAccount() const
{ return mAccount; }
+ /**
+ * Update lastLoginAttempt
+ */
+ void updateLoginAttempt();
+
+ /**
+ * Returns the time of the last login attempt.
+ */
+ int getLastLoginAttempt() const
+ { return lastLoginAttempt; }
+
int status;
private:
/** Account associated with connection */
Account *mAccount;
+ time_t lastLoginAttempt;
};
#endif
diff --git a/src/account-server/accounthandler.cpp b/src/account-server/accounthandler.cpp
index 0b81787b..506d80f8 100644
--- a/src/account-server/accounthandler.cpp
+++ b/src/account-server/accounthandler.cpp
@@ -169,6 +169,22 @@ static void handleLoginMessage(AccountClient &computer, MessageIn &msg)
return;
}
+ // get the IP address
+ int address = computer.getIP();
+
+ // TODO: Check IP against blacklist
+
+ time_t lastAttempt = computer.getLastLoginAttempt();
+ if ((time(NULL) - lastAttempt) < 1)
+ {
+ reply.writeByte(LOGIN_INVALID_TIME);
+ computer.send(reply);
+ return;
+ }
+
+ // updates the time last attempted to login
+ computer.updateLoginAttempt();
+
std::string username = msg.readString();
std::string password = msg.readString();