-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhooks.lua
103 lines (72 loc) · 2.91 KB
/
hooks.lua
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
94
95
96
97
98
99
100
101
102
103
-- ==
--[[
Load hooks for the plugin
--]]
function hooks()
cPluginManager:AddHook(cPluginManager.HOOK_EXECUTE_COMMAND, OnExecuteCommand)
cPluginManager:AddHook(cPluginManager.HOOK_PLAYER_DESTROYED, OnPlayerDestroyed);
cPluginManager:AddHook(cPluginManager.HOOK_CHAT, OnChat);
end
--------------------------------------------------------------------------------
function OnChat(aPlayer, aMessage)
return msgCheck(aPlayer);
end
--------------------------------------------------------------------------------
function msgCheck(aPlayer)
if not aPlayer then
return false;
end
-- console_log(os.time(), 1);
-- console_log("Client locale is ".. aPlayer:GetClientHandle():GetLocale());
msgTooManySpam = "Too many spam from you (flood).";
msgTooManyFlood = "Too many flood from you. You will be kicked next time";
-- Get player world
local world = aPlayer:GetWorld();
local plName = aPlayer:GetName();
local plUID = aPlayer:GetUniqueID();
-- is it player into send message
if not gPlayers[plUID] then
gPlayers[plUID] = cPlayers:new(plName);
gPlayers[plUID]:setLastMsgTime(os.time());
return false;
end
-- Check delay
if (os.time() - gPlayers[plUID]:getLastMsgTime()) < gMsgDelay then
-- Increase warnings count
gPlayers[plUID]:increaseWarnings();
-- console_log("Warnings count: ".. gPlayers[plUID]:getWarningsCount(), 1);
-- Check warnings limit
if gPlayers[plUID]:getWarningsCount() > gWarningsBeforeKick then
-- Delete player object
gPlayers[plUID] = nil;
-- Kick player
aPlayer:GetClientHandle():Kick(msgTooManySpam);
-- Do not show message
return true;
end
-- Update last message time
gPlayers[plUID]:setLastMsgTime(os.time());
-- Show player warning message
aPlayer:SendMessageWarning(msgTooManyFlood);
-- Do not show player messge
return true;
end
return false;
end
--------------------------------------------------------------------------------
function OnExecuteCommand(aPlayer, aCommand)
return msgCheck(aPlayer);
end
--------------------------------------------------------------------------------
function OnPlayerDestroyed(aPlayer)
return false;
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- =============================================================================