diff --git a/data/scripts/talkactions/ban.lua b/data/scripts/talkactions/ban.lua new file mode 100644 index 0000000000..8a34f55e6d --- /dev/null +++ b/data/scripts/talkactions/ban.lua @@ -0,0 +1,50 @@ +local talk = TalkAction("/ban") + +function talk.onSay(player, words, param) + if not player:getGroup():getAccess() or player:getAccountType() < ACCOUNT_TYPE_GAMEMASTER then + return true + end + + local params = param:split(",") + if #params < 3 then + player:sendCancelMessage("Command requires 3 parameters: /ban , , ") + return true + end + + local name = params[1]:trim() + local banDuration = tonumber(params[2]:trim()) + local banReason = params[3]:trim() + + if not banDuration or banDuration <= 0 then + player:sendCancelMessage("Ban duration must be a positive number.") + return true + end + + local accountId = getAccountNumberByPlayerName(name) + if accountId == 0 then + return true + end + + local resultId = db.storeQuery("SELECT 1 FROM `account_bans` WHERE `account_id` = " .. accountId) + if resultId then + result.free(resultId) + return true + end + + local currentTime = os.time() + local expirationTime = currentTime + (banDuration * 24 * 60 * 60) + db.query(string.format("INSERT INTO `account_bans` (`account_id`, `reason`, `banned_at`, `expires_at`, `banned_by`) VALUES (%d, %s, %d, %d, %d)", accountId, db.escapeString(banReason), currentTime, expirationTime, player:getGuid())) + + local target = Player(name) + if target then + player:sendTextMessage(MESSAGE_EVENT_ADVANCE, string.format("%s has been banned for %d days.", target:getName(), banDuration)) + target:remove() + else + player:sendTextMessage(MESSAGE_EVENT_ADVANCE, string.format("%s has been banned for %d days.", name, banDuration)) + end + return true +end + +talk:separator(" ") +talk:groupType("gamemaster") +talk:register() diff --git a/data/talkactions/scripts/ban.lua b/data/talkactions/scripts/ban.lua deleted file mode 100644 index 44b9231456..0000000000 --- a/data/talkactions/scripts/ban.lua +++ /dev/null @@ -1,39 +0,0 @@ -local banDays = 7 - -function onSay(player, words, param) - if not player:getGroup():getAccess() then - return true - end - - local name = param - local reason = '' - - local separatorPos = param:find(',') - if separatorPos then - name = param:sub(0, separatorPos - 1) - reason = string.trim(param:sub(separatorPos + 1)) - end - - local accountId = getAccountNumberByPlayerName(name) - if accountId == 0 then - return false - end - - local resultId = db.storeQuery("SELECT 1 FROM `account_bans` WHERE `account_id` = " .. accountId) - if resultId then - result.free(resultId) - return false - end - - local timeNow = os.time() - db.query("INSERT INTO `account_bans` (`account_id`, `reason`, `banned_at`, `expires_at`, `banned_by`) VALUES (" .. - accountId .. ", " .. db.escapeString(reason) .. ", " .. timeNow .. ", " .. timeNow + (banDays * 86400) .. ", " .. player:getGuid() .. ")") - - local target = Player(name) - if target then - player:sendTextMessage(MESSAGE_EVENT_ADVANCE, target:getName() .. " has been banned.") - target:remove() - else - player:sendTextMessage(MESSAGE_EVENT_ADVANCE, name .. " has been banned.") - end -end diff --git a/data/talkactions/talkactions.xml b/data/talkactions/talkactions.xml index b3990d6636..fd89ea6125 100644 --- a/data/talkactions/talkactions.xml +++ b/data/talkactions/talkactions.xml @@ -2,7 +2,6 @@ -