diff options
author | Philipp Sehmisch <mana@crushnet.org> | 2011-03-18 20:14:57 +0100 |
---|---|---|
committer | Philipp Sehmisch <mana@crushnet.org> | 2011-03-18 20:15:49 +0100 |
commit | c4f3d184abeda63abcfdaa386b4846e94bfed1f9 (patch) | |
tree | 0882b3a10184236d88d0ea8b4ed69cd1c39e2ba9 | |
parent | 9344a79233882ac278b3812b91b6edf874ef5d16 (diff) | |
download | manaserv-c4f3d184abeda63abcfdaa386b4846e94bfed1f9.tar.gz manaserv-c4f3d184abeda63abcfdaa386b4846e94bfed1f9.tar.bz2 manaserv-c4f3d184abeda63abcfdaa386b4846e94bfed1f9.tar.xz manaserv-c4f3d184abeda63abcfdaa386b4846e94bfed1f9.zip |
Improved @ban command
When banning a character, the game master now sets a time unit (m, h, d, w
or y for minutes, hours, days, weeks or years) after the duration.
Ban durations longer than 2^16 minutes are now possible.
The banned character is now kicked automatically and the banning character
receives a feedback chat message.
Reviewed-by: Thorbjorn
-rw-r--r-- | src/account-server/serverhandler.cpp | 2 | ||||
-rw-r--r-- | src/account-server/storage.cpp | 5 | ||||
-rw-r--r-- | src/game-server/accountconnection.cpp | 2 | ||||
-rw-r--r-- | src/game-server/commandhandler.cpp | 50 |
4 files changed, 43 insertions, 16 deletions
diff --git a/src/account-server/serverhandler.cpp b/src/account-server/serverhandler.cpp index dd6a82e9..5b88348c 100644 --- a/src/account-server/serverhandler.cpp +++ b/src/account-server/serverhandler.cpp @@ -383,7 +383,7 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg) case GAMSG_BAN_PLAYER: { int id = msg.readInt32(); - int duration = msg.readInt16(); + int duration = msg.readInt32(); storage->banCharacter(id, duration); } break; diff --git a/src/account-server/storage.cpp b/src/account-server/storage.cpp index 333f3aaf..fdcb1cd9 100644 --- a/src/account-server/storage.cpp +++ b/src/account-server/storage.cpp @@ -1649,6 +1649,7 @@ void Storage::banCharacter(int id, int duration) { try { + // check the account of the character std::ostringstream query; query << "select user_id from " << CHARACTERS_TBL_NAME << " where id = '" << id << "';"; @@ -1659,10 +1660,12 @@ void Storage::banCharacter(int id, int duration) return; } + uint64_t bantime = (uint64_t)time(0) + (uint64_t)duration * 60u; + // ban the character std::ostringstream sql; sql << "update " << ACCOUNTS_TBL_NAME << " set level = '" << AL_BANNED << "', banned = '" - << time(0) + duration * 60 + << bantime << "' where id = '" << info(0, 0) << "';"; mDb->execSql(sql.str()); } diff --git a/src/game-server/accountconnection.cpp b/src/game-server/accountconnection.cpp index 5276bce3..c404e421 100644 --- a/src/game-server/accountconnection.cpp +++ b/src/game-server/accountconnection.cpp @@ -294,7 +294,7 @@ void AccountConnection::banCharacter(Character *ch, int duration) { MessageOut msg(GAMSG_BAN_PLAYER); msg.writeInt32(ch->getDatabaseID()); - msg.writeInt16(duration); + msg.writeInt32(duration); send(msg); } diff --git a/src/game-server/commandhandler.cpp b/src/game-server/commandhandler.cpp index d68ffb0e..d7bd8f44 100644 --- a/src/game-server/commandhandler.cpp +++ b/src/game-server/commandhandler.cpp @@ -92,7 +92,7 @@ static CmdRef const cmdRef[] = "Teleports you to the location of another character", &handleGoto}, {"recall", "<character>", "Teleports another character to your location", &handleRecall}, - {"ban", "<character> <length of time>", + {"ban", "<character> <length of time>(m|h|d|w|y)", "Bans the character and all characters on the same account from the game", &handleBan}, {"item", "<character> <item id> <amount>", "Creates a number of items in the inventory of a character", &handleItem}, @@ -776,6 +776,7 @@ static void handleBan(Character *player, std::string &args) { Character *other; int length; + int lengthMutiplier = 0; // get arguments std::string character = getArgument(args); @@ -797,27 +798,50 @@ static void handleBan(Character *player, std::string &args) return; } - // check the length is really an integer - if (!utils::isNumeric(valuestr)) + // get the unit + char unit = valuestr.at(valuestr.length()-1); + switch (unit) { - say("Invalid argument", player); - return; + case 'm': + lengthMutiplier = 1; + break; + case 'h': + lengthMutiplier = 60; + break; + case 'd': + lengthMutiplier = 60 * 24; + break; + case 'w': + lengthMutiplier = 60 * 24 * 7; + break; + case 'y': + lengthMutiplier = 60 * 24 * 365; + break; } - - // change the length to an integer - length = utils::stringToInt(valuestr); - - if (length < 0) + length = utils::stringToInt(valuestr.substr(0, valuestr.length()-1)); + length = length * lengthMutiplier; + if (length <= 0) { - say("Invalid length", player); + std::string errmsg; + errmsg += "Invalid length. Please enter a positive number "; + errmsg += "followed by the letter m, h, d, w or y for minutes "; + errmsg += ", hours, days, weeks or years."; + say(errmsg , player); return; } // ban the player accountHandler->banCharacter(other, length); - + // disconnect the player + MessageOut kickmsg(GPMSG_CONNECT_RESPONSE); + kickmsg.writeInt8(ERRMSG_ADMINISTRATIVE_LOGOFF); + other->getClient()->disconnect(kickmsg); + + // feedback for command user + std::string msg = "You've banned " + other->getName() + " for " + utils::toString(length) + " minutes"; + say(msg.c_str(), player); // log transaction - std::string msg = "User banned " + other->getName(); + msg = "User banned " + other->getName() + " for " + utils::toString(length) + " minutes"; accountHandler->sendTransaction(player->getDatabaseID(), TRANS_CMD_BAN, msg); } |