summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPhilipp Sehmisch <crush@themanaworld.org>2009-01-17 12:54:20 +0100
committerPhilipp Sehmisch <crush@themanaworld.org>2009-01-17 12:54:20 +0100
commit2f28f585b12880d3cddab9d634fedff2f5954485 (patch)
tree370433972f687616fad54dfbe0ab11bda7db1aff /src
parentba6a9e534cfab2ecab6e120af4ab6ae11aee26c4 (diff)
parentd1b73b1195f8e8b2ad64ff692e7ddb17ed0bbad1 (diff)
downloadmanaserv-2f28f585b12880d3cddab9d634fedff2f5954485.tar.gz
manaserv-2f28f585b12880d3cddab9d634fedff2f5954485.tar.bz2
manaserv-2f28f585b12880d3cddab9d634fedff2f5954485.tar.xz
manaserv-2f28f585b12880d3cddab9d634fedff2f5954485.zip
Merge branch 'master' of git@gitorious.org:tmwserv/mainline
Diffstat (limited to 'src')
-rw-r--r--src/account-server/accountclient.cpp6
-rw-r--r--src/account-server/accountclient.hpp12
-rw-r--r--src/account-server/accounthandler.cpp16
-rw-r--r--src/defines.h1
-rw-r--r--src/game-server/commandhandler.cpp19
-rw-r--r--src/game-server/state.cpp12
-rw-r--r--src/game-server/state.hpp5
-rw-r--r--src/net/netcomputer.cpp5
-rw-r--r--src/net/netcomputer.hpp5
9 files changed, 81 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();
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 */