summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuillaume Melquiond <guillaume.melquiond@gmail.com>2007-08-31 14:06:00 +0000
committerGuillaume Melquiond <guillaume.melquiond@gmail.com>2007-08-31 14:06:00 +0000
commit0c52964be1d7158bf6533011b4e08287608a6926 (patch)
treea909c5ea79ed82345baa34152ce892a400500194
parent60f60de8aefeebd1de0bf6c940558902226d7747 (diff)
downloadmanaserv-0c52964be1d7158bf6533011b4e08287608a6926.tar.gz
manaserv-0c52964be1d7158bf6533011b4e08287608a6926.tar.xz
manaserv-0c52964be1d7158bf6533011b4e08287608a6926.zip
Implemented "ban" remote command.
-rw-r--r--ChangeLog7
-rw-r--r--src/account-server/dalstorage.cpp41
-rw-r--r--src/account-server/dalstorage.hpp8
-rw-r--r--src/account-server/serverhandler.cpp7
-rw-r--r--src/defines.h3
-rw-r--r--src/game-server/accountconnection.cpp8
-rw-r--r--src/game-server/accountconnection.hpp5
-rw-r--r--src/game-server/command.cpp19
8 files changed, 95 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 65fdf71..a1ef4b4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -18,6 +18,13 @@
on error.
* src/defines.h, src/account-server/accounthandler.cpp: Prevented
banned users from logging in.
+ * src/account-server/dalstorage.cpp, src/account-server/dalstorage.hpp:
+ Handled banned database field.
+ * src/game-server/accountconnection.hpp, src/defines.h,
+ src/game-server/accountconnection.cpp,
+ src/account-server/serverhandler.cpp: Added protocol for banning
+ players.
+ * src/game-server/command.cpp: Implemented "ban" remote command.
2007-08-30 Guillaume Melquiond <guillaume.melquiond@gmail.com>
diff --git a/src/account-server/dalstorage.cpp b/src/account-server/dalstorage.cpp
index 70b1cdf..08b149e 100644
--- a/src/account-server/dalstorage.cpp
+++ b/src/account-server/dalstorage.cpp
@@ -21,6 +21,7 @@
*/
#include <cassert>
+#include <time.h>
#include "account-server/dalstorage.hpp"
@@ -174,7 +175,16 @@ Account *DALStorage::getAccountBySQL(std::string const &query)
account->setName(accountInfo(0, 1));
account->setPassword(accountInfo(0, 2));
account->setEmail(accountInfo(0, 3));
- account->setLevel(toUint(accountInfo(0, 4)));
+
+ int level = toUint(accountInfo(0, 4));
+ // Check if the user is permanently banned, or temporarily banned.
+ if (level == AL_BANNED || time(NULL) <= toUint(accountInfo(0, 5)))
+ {
+ account->setLevel(AL_BANNED);
+ // It is, so skip character loading.
+ return account;
+ }
+ account->setLevel(level);
// load the characters associated with the account.
std::ostringstream sql;
@@ -301,7 +311,8 @@ Character *DALStorage::getCharacterBySQL(std::string const &query, Account *owne
int id = toUint(charInfo(0, 1));
character->setAccountID(id);
std::ostringstream s;
- s << "select level from tmw_accounts where id = '" << id << "';";
+ s << "select level from " << ACCOUNTS_TBL_NAME
+ << " where id = '" << id << "';";
dal::RecordSet const &levelInfo = mDb->execSql(s.str());
character->setAccountLevel(toUint(levelInfo(0, 0)), true);
}
@@ -1116,3 +1127,29 @@ void DALStorage::setQuestVar(int id, std::string const &name,
LOG_ERROR("(DALStorage::setQuestVar) SQL query failure: " << e.what());
}
}
+
+void DALStorage::banCharacter(int id, int duration)
+{
+ try
+ {
+ std::ostringstream query;
+ query << "select user_id from " << CHARACTERS_TBL_NAME
+ << " where id = '" << id << "';";
+ dal::RecordSet const &info = mDb->execSql(query.str());
+ if (info.isEmpty())
+ {
+ LOG_ERROR("Tried to ban an unknown user.");
+ return;
+ }
+
+ std::ostringstream sql;
+ sql << "update " << ACCOUNTS_TBL_NAME
+ << " set banned = '" << time(NULL) + duration * 60
+ << "' where id = '" << info(0, 0) << "';";
+ mDb->execSql(sql.str());
+ }
+ catch (dal::DbSqlQueryExecFailure const &e)
+ {
+ LOG_ERROR("(DALStorage::banAccount) SQL query failure: " << e.what());
+ }
+}
diff --git a/src/account-server/dalstorage.hpp b/src/account-server/dalstorage.hpp
index abc9d31..ec75423 100644
--- a/src/account-server/dalstorage.hpp
+++ b/src/account-server/dalstorage.hpp
@@ -119,6 +119,14 @@ class DALStorage
*/
void delAccount(Account *account);
+ /**
+ * Sets a ban on an account (hence on all its characters).
+ *
+ * @param id character identifier.
+ * @param duration duration in minutes.
+ */
+ void banCharacter(int id, int duration);
+
#if 0
/**
* Get the list of Emails in the accounts list.
diff --git a/src/account-server/serverhandler.cpp b/src/account-server/serverhandler.cpp
index 492bd16..06c9f80 100644
--- a/src/account-server/serverhandler.cpp
+++ b/src/account-server/serverhandler.cpp
@@ -218,6 +218,13 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg)
storage->setQuestVar(id, name, value);
} break;
+ case GAMSG_BAN_PLAYER:
+ {
+ int id = msg.readLong();
+ int duration = msg.readShort();
+ storage->banCharacter(id, duration);
+ } break;
+
#if 0
case GAMSG_GUILD_CREATE:
{
diff --git a/src/defines.h b/src/defines.h
index cf1db30..507265d 100644
--- a/src/defines.h
+++ b/src/defines.h
@@ -237,7 +237,8 @@ enum {
GAMSG_PLAYER_RECONNECT = 0x0532, // L id, B*32 token
GAMSG_SET_QUEST = 0x0540, // L id, S name, S value
GAMSG_GET_QUEST = 0x0541, // L id, S name
- AGMSG_GET_QUEST_RESPONSE = 0x0542, // L id S name, S value
+ AGMSG_GET_QUEST_RESPONSE = 0x0542, // L id, S name, S value
+ GAMSG_BAN_PLAYER = 0x550, // L id, W duration
#if 0
GAMSG_GUILD_CREATE = 0x0550, // S name
diff --git a/src/game-server/accountconnection.cpp b/src/game-server/accountconnection.cpp
index b351890..9a2084d 100644
--- a/src/game-server/accountconnection.cpp
+++ b/src/game-server/accountconnection.cpp
@@ -252,6 +252,14 @@ void AccountConnection::updateQuestVar(Character *ch, std::string const &name,
send(msg);
}
+void AccountConnection::banCharacter(Character *ch, int duration)
+{
+ MessageOut msg(GAMSG_BAN_PLAYER);
+ msg.writeLong(ch->getDatabaseID());
+ msg.writeShort(duration);
+ send(msg);
+}
+
#if 0
void AccountConnection::playerCreateGuild(int id, const std::string &guildName)
{
diff --git a/src/game-server/accountconnection.hpp b/src/game-server/accountconnection.hpp
index 9899db1..b591df1 100644
--- a/src/game-server/accountconnection.hpp
+++ b/src/game-server/accountconnection.hpp
@@ -61,6 +61,11 @@ class AccountConnection : public Connection
void updateQuestVar(Character *, std::string const &name,
std::string const &value);
+ /**
+ * Sends ban message.
+ */
+ void banCharacter(Character *, int);
+
#if 0
/**
* Sends create guild message
diff --git a/src/game-server/command.cpp b/src/game-server/command.cpp
index dfb218f..5775162 100644
--- a/src/game-server/command.cpp
+++ b/src/game-server/command.cpp
@@ -24,6 +24,7 @@
#include <cstddef>
#include "defines.h"
+#include "game-server/accountconnection.hpp"
#include "game-server/character.hpp"
#include "game-server/gamehandler.hpp"
#include "game-server/inventory.hpp"
@@ -245,6 +246,23 @@ static void reload(Character *from, std::string const &db)
}
}
+static void ban(Character *from, Character *ch, std::string const &duration)
+{
+ if (from->getAccountLevel() <= ch->getAccountLevel())
+ {
+ // Special case: Only ban strictly less priviledged accounts.
+ return;
+ }
+
+ int d = atoi(duration.c_str());
+ switch (duration[duration.length() - 1])
+ {
+ case 'd': d = d * 24; // nobreak
+ case 'h': d = d * 60;
+ }
+ accountHandler->banCharacter(ch, d);
+}
+
/**
* List of remote commands.
*/
@@ -258,6 +276,7 @@ static Command const commands[] =
handle("goto", AL_GM, goto_),
handle("recall", AL_GM, recall),
handle("reload", AL_ADMIN, reload),
+ handle("ban", AL_GM, ban),
};
/**