-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathactiontext_server.lua
More file actions
93 lines (80 loc) · 3.65 KB
/
actiontext_server.lua
File metadata and controls
93 lines (80 loc) · 3.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
RegisterNetEvent('actiontext:send')
AddEventHandler('actiontext:send', function(actionType, text)
local src = source
local playerName = GetPlayerName(src) or ('Player' .. tostring(src))
local lang = (Config.GLOBAL and Config.GLOBAL.lang) or {}
if not global_spam_tracker then global_spam_tracker = {} end
local now = (os.time() * 1000)
local spamCfg = (Config.GLOBAL and Config.GLOBAL.spam) or { cooldownMs = 1000, burstLimit = 3, burstWindowMs = 10000 }
local s = global_spam_tracker[src]
if not s then
s = { times = {} }
global_spam_tracker[src] = s
end
local newTimes = {}
for _, t in ipairs(s.times) do
if now - t <= spamCfg.burstWindowMs then table.insert(newTimes, t) end
end
s.times = newTimes
local isAdmin = false
if spamCfg and spamCfg.allowAdminBypass and spamCfg.adminAcePermission then
pcall(function()
isAdmin = IsPlayerAceAllowed(src, spamCfg.adminAcePermission)
end)
end
if not isAdmin and #s.times >= spamCfg.burstLimit then
if spamCfg.notify ~= false then
local prefix = (spamCfg and spamCfg.spamPrefix) or lang.spamPrefix or 'SPAM'
local msg = (spamCfg and spamCfg.spamMessage) or lang.spamMessage or 'You are sending actions too quickly. Please slow down.'
TriggerClientEvent('chat:addMessage', src, { color = { 255, 100, 100 }, args = { prefix, msg } })
end
return
end
if not isAdmin and #s.times > 0 then
local last = s.times[#s.times]
if now - last < spamCfg.cooldownMs then
if spamCfg.notify ~= false then
local prefix = (spamCfg and spamCfg.spamPrefix) or lang.spamPrefix or 'SPAM'
local msg = (spamCfg and spamCfg.spamMessage) or lang.spamMessage or 'Please wait before sending another action.'
TriggerClientEvent('chat:addMessage', src, { color = { 255, 100, 100 }, args = { prefix, msg } })
end
return
end
end
table.insert(s.times, now)
if Config.GLOBAL and Config.GLOBAL.serverLogging then
print(('[ActionText] /%s from %s (id=%s): %s'):format(actionType, playerName, tostring(src), text))
end
TriggerClientEvent('actiontext:display', -1, src, actionType, text)
local postChat = false
local chatColor = { 255, 183, 0 }
local formatted = ('%s %s'):format(playerName, text)
if actionType == 'me' and Config.ME and Config.ME.chat then
postChat = true
chatColor = (Config.ME.chatColor or chatColor)
formatted = (Config.ME.chatFormat or '%s %s'):format(playerName, text)
if Config.ME.useChatPrefix and Config.ME.chatPrefix then
local pf = (Config.ME.chatPrefixFormat or '^*%s^*^7 ')
formatted = (pf:format(Config.ME.chatPrefix) or '') .. formatted
else
formatted = '^7' .. formatted
end
elseif actionType == 'do' and Config.DO and Config.DO.chat then
postChat = true
chatColor = (Config.DO.chatColor or chatColor)
formatted = (Config.DO.chatFormat or '%s %s'):format(playerName, text)
if Config.DO.useChatPrefix and Config.DO.chatPrefix then
local pf = (Config.DO.chatPrefixFormat or '^*%s^*^7 ')
formatted = (pf:format(Config.DO.chatPrefix) or '') .. formatted
else
formatted = '^7' .. formatted
end
end
if postChat then
TriggerClientEvent('chat:addMessage', -1, {
color = chatColor,
multiline = true,
args = { formatted }
})
end
end)