Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ban talk #4833

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions data/scripts/talkactions/ban.lua
Original file line number Diff line number Diff line change
@@ -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 <player name>, <duration in days>, <reason>")
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()
39 changes: 0 additions & 39 deletions data/talkactions/scripts/ban.lua

This file was deleted.

1 change: 0 additions & 1 deletion data/talkactions/talkactions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<talkactions>
<!-- commands -->
<talkaction words="/attr" separator=" " script="attributes.lua" />
<talkaction words="/ban" separator=" " script="ban.lua" />
<talkaction words="/ipban" separator=" " script="ip_ban.lua" />
<talkaction words="/unban" separator=" " script="unban.lua" />
<talkaction words="/up" script="up.lua" />
Expand Down
Loading