diff options
-rw-r--r-- | accountserver.cbp | 2 | ||||
-rw-r--r-- | gameserver.cbp | 1 | ||||
-rw-r--r-- | src/account-server/accountclient.cpp | 6 | ||||
-rw-r--r-- | src/account-server/accountclient.hpp | 12 | ||||
-rw-r--r-- | src/account-server/accounthandler.cpp | 16 | ||||
-rw-r--r-- | src/defines.h | 1 | ||||
-rw-r--r-- | src/game-server/commandhandler.cpp | 19 | ||||
-rw-r--r-- | src/game-server/state.cpp | 12 | ||||
-rw-r--r-- | src/game-server/state.hpp | 5 | ||||
-rw-r--r-- | src/net/netcomputer.cpp | 5 | ||||
-rw-r--r-- | src/net/netcomputer.hpp | 5 |
11 files changed, 81 insertions, 3 deletions
diff --git a/accountserver.cbp b/accountserver.cbp index 45bf9197..6b6f5487 100644 --- a/accountserver.cbp +++ b/accountserver.cbp @@ -113,8 +113,6 @@ <Unit filename="src/point.h" /> <Unit filename="src/utils/base64.cpp" /> <Unit filename="src/utils/base64.h" /> - <Unit filename="src/utils/cipher.cpp" /> - <Unit filename="src/utils/cipher.h" /> <Unit filename="src/utils/encryption.cpp" /> <Unit filename="src/utils/encryption.h" /> <Unit filename="src/utils/functors.h" /> diff --git a/gameserver.cbp b/gameserver.cbp index f3c7aaf2..64bfb8a1 100644 --- a/gameserver.cbp +++ b/gameserver.cbp @@ -134,7 +134,6 @@ <Unit filename="src/scripting/script.hpp" /> <Unit filename="src/utils/base64.cpp" /> <Unit filename="src/utils/base64.h" /> - <Unit filename="src/utils/cipher.h" /> <Unit filename="src/utils/logger.cpp" /> <Unit filename="src/utils/logger.h" /> <Unit filename="src/utils/mathutils.cpp" /> 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(); diff --git a/src/defines.h b/src/defines.h index ea3aab57..b722e0d1 100644 --- a/src/defines.h +++ b/src/defines.h @@ -320,6 +320,7 @@ enum { // Login specific return values enum { LOGIN_INVALID_VERSION = 0x40, // the user is using an incompatible protocol + LOGIN_INVALID_TIME = 0x50, // the user tried logging in too fast LOGIN_BANNED // the user is currently banned }; diff --git a/src/game-server/commandhandler.cpp b/src/game-server/commandhandler.cpp index 3822e2ef..5268d131 100644 --- a/src/game-server/commandhandler.cpp +++ b/src/game-server/commandhandler.cpp @@ -124,6 +124,7 @@ static void handleHelp(Character *player, std::string &args) say("Administrator Commands", player); say("@reload", player); say("@setgroup <character> <AL level>", player); + say("@announce <message>", player); } } else @@ -688,6 +689,19 @@ static void handleReport(Character *player, std::string &args) // TODO: Send the report to a developer or something } +static void handleAnnounce(Character *player, std::string &args) +{ + std::string msg = getArgument(args); + + if (msg == "") + { + say("Invalid number of arguments given.", player); + return; + } + + GameState::sayToAll(msg); +} + void CommandHandler::handleCommand(Character *player, const std::string &command) { @@ -763,6 +777,11 @@ void CommandHandler::handleCommand(Character *player, if (handlePermissions(player, AL_PLAYER)) handleReport(player, args); } + else if (type == "announce") + { + if (handlePermissions(player, AL_ADMIN)) + handleAnnounce(player, args); + } else { say("command not found", player); diff --git a/src/game-server/state.cpp b/src/game-server/state.cpp index a42c689f..8202f7ca 100644 --- a/src/game-server/state.cpp +++ b/src/game-server/state.cpp @@ -715,3 +715,15 @@ void GameState::sayTo(Object *destination, Object *source, std::string const &te gameHandler->sendTo(static_cast< Character * >(destination), msg); } + +void GameState::sayToAll(const std::string &text) +{ + MessageOut msg(GPMSG_SAY); + + // message will show as from server + msg.writeShort(0); + msg.writeString(text); + + // sends to everyone connected to the game server + gameHandler->sendToEveryone(msg); +} diff --git a/src/game-server/state.hpp b/src/game-server/state.hpp index 7cd69d76..f5595bc8 100644 --- a/src/game-server/state.hpp +++ b/src/game-server/state.hpp @@ -99,6 +99,11 @@ namespace GameState */ void sayAround(Object *, std::string const &text); + /** + * Says something to every player on the server. + */ + void sayToAll(const std::string &text); + } #endif diff --git a/src/net/netcomputer.cpp b/src/net/netcomputer.cpp index ff2bbb71..2ce30c02 100644 --- a/src/net/netcomputer.cpp +++ b/src/net/netcomputer.cpp @@ -103,3 +103,8 @@ operator <<(std::ostream &os, const NetComputer &comp) return os; } + +int NetComputer::getIP() +{ + return mPeer->address.host; +} diff --git a/src/net/netcomputer.hpp b/src/net/netcomputer.hpp index b85456a6..2c4d706a 100644 --- a/src/net/netcomputer.hpp +++ b/src/net/netcomputer.hpp @@ -81,6 +81,11 @@ class NetComputer send(const MessageOut &msg, bool reliable = true, unsigned int channel = 0); + /** + * Returns IP address of computer in 32bit int form + */ + int getIP(); + private: ENetPeer *mPeer; /**< Client peer */ |