1
+ ---- -----------------------------------------------------------------
2
+ -- Project: irc
3
+ -- Author: MCvarial
4
+
5
+ -- Version: 1.0.0
6
+ -- Date: 31.10.2010
7
+ ---- -----------------------------------------------------------------
8
+
9
+ executeSQLCreateTable (" ircmutes" ," player TEXT, serial TEXT, reason TEXT, admin TEXT, mute TEXT, duration TEXT" )
10
+ local mutes = {}
11
+
12
+ -- admin panel interaction
13
+ addEvent (" aPlayer" ,true )
14
+ addEventHandler (" aPlayer" ,root ,
15
+ function (player ,action ,reason ,time )
16
+ if isPlayerMuted (player ) then
17
+ executeSQLInsert (" ircmutes" ," '" .. tostring (getPlayerName (player )).. " ','" .. tostring (getPlayerSerial (player )).. " ','" .. tostring (reason ).. " ','" .. tostring (getPlayerName (source )).. " ','" .. tostring (getRealTime ().timestamp * 1000 ).. " ','" .. ((time or 0 )* 1000 ).. " '" )
18
+ else
19
+ executeSQLDelete (" ircmutes" ," serial = '" .. tostring (getPlayerSerial (player )).. " '" )
20
+ end
21
+ end
22
+ )
23
+
24
+ _setPlayerMuted = setPlayerMuted
25
+ function setPlayerMuted (player ,muted ,reason ,admin )
26
+ if muted then
27
+ local time = getTimeFromString (reason ) or 0
28
+ executeSQLInsert (" ircmutes" ," '" .. tostring (getPlayerName (player )).. " ','" .. tostring (getPlayerSerial (player )).. " ','" .. tostring (reason ).. " ','" .. tostring (admin ).. " ','" .. tostring (getRealTime ().timestamp * 1000 ).. " ','" .. time .. " '" )
29
+ if time > 50 then
30
+ mutes [player ] = setTimer (setPlayerMuted ,time ,1 ,player ,false )
31
+ end
32
+ else
33
+ executeSQLDelete (" ircmutes" ," serial = '" .. tostring (getPlayerSerial (player )).. " '" )
34
+ if mutes [player ] then
35
+ mutes [player ] = nil
36
+ end
37
+ end
38
+ return _setPlayerMuted (player ,muted )
39
+ end
40
+
41
+ addEventHandler (" onPlayerUnmute" ,root ,
42
+ function ()
43
+ executeSQLDelete (" ircmutes" ," serial = '" .. tostring (getPlayerSerial (source )).. " '" )
44
+ if mutes [source ] then
45
+ mutes [source ] = nil
46
+ end
47
+ end
48
+ )
49
+
50
+ addEventHandler (" onPlayerJoin" ,root ,
51
+ function ()
52
+ local result = executeSQLSelect (" ircmutes" ," serial,reason,mute,duration" ," serial = '" .. getPlayerSerial (source ).. " '" )
53
+ if result and result [1 ] then
54
+ local time = (tonumber (result [1 ][" mute" ])+ tonumber (result [1 ][" duration" ]))- (getRealTime ().timestamp * 1000 )
55
+ if time < 50 then
56
+ executeSQLDelete (" ircmutes" ," serial = '" .. tostring (getPlayerSerial (source )).. " '" )
57
+ else
58
+ _setPlayerMuted (source ,true )
59
+ mutes [source ] = setTimer (setPlayerMuted ,time ,1 ,source ,false )
60
+ end
61
+ end
62
+ end
63
+ )
64
+
65
+ addEventHandler (" onPlayerQuit" ,root ,
66
+ function ()
67
+ if mutes [source ] then
68
+ killTimer (mutes [source ])
69
+ mutes [source ] = nil
70
+ local result = executeSQLSelect (" ircmutes" ," serial,reason,mute,duration" ," serial = '" .. getPlayerSerial (source ).. " '" )
71
+ if result and result [1 ] then
72
+ if result [1 ].duration == 0 then
73
+ executeSQLDelete (" ircmutes" ," serial = '" .. tostring (getPlayerSerial (source )).. " '" )
74
+ end
75
+ end
76
+ end
77
+ end
78
+ )
79
+
80
+ addEventHandler (" onResourceStart" ,resourceRoot ,
81
+ function ()
82
+ local results = executeSQLSelect (" ircmutes" ," serial,mute,duration" )
83
+ if type (results ) == " table" then
84
+ for i ,result in ipairs (results ) do
85
+ local mutetime = tonumber (result [" mute" ])
86
+ local duration = tonumber (result [" duration" ])
87
+ if mutetime and duration and (mutetime + duration ) < (getRealTime ().timestamp )* 1000 then
88
+ for i ,player in ipairs (getElementsByType (" player" )) do
89
+ if getPlayerSerial (player ) == result [" serial" ] then
90
+ _setPlayerMuted (player ,false )
91
+ outputChatBox (" * " .. getPlayerName (player ).. " has been unmuted" ,root ,255 ,0 ,0 )
92
+ end
93
+ end
94
+ executeSQLDelete (" ircmutes" ," serial = '" .. tostring (result [" serial" ]).. " '" )
95
+ end
96
+ end
97
+ end
98
+ end
99
+ )
100
+
101
+ local times = {}
102
+ times [" ms" ] = 1
103
+ times [" sec" ] = 1000
104
+ times [" secs" ] = 1000
105
+ times [" second" ] = 1000
106
+ times [" seconds" ] = 1000
107
+ times [" min" ] = 60000
108
+ times [" mins" ] = 60000
109
+ times [" minute" ] = 60000
110
+ times [" minutes" ] = 60000
111
+ times [" hour" ] = 3600000
112
+ times [" hours" ] = 3600000
113
+ times [" day" ] = 86400000
114
+ times [" days" ] = 86400000
115
+ times [" week" ] = 604800000
116
+ times [" weeks" ] = 604800000
117
+ times [" month" ] = 2592000000
118
+ times [" months" ] = 2592000000
119
+ function getTimeFromString (string )
120
+ if type (string ) ~= " string" then return false end
121
+ local time = 0
122
+ for i ,v in pairs (times ) do
123
+ local start ,stop = string.find (string ,i )
124
+ if start then
125
+ local number = string.sub (string ,start - 2 ,start - 1 )
126
+ if number and tonumber (number ) then
127
+ number = tonumber (number )
128
+ time = time + number * v
129
+ end
130
+ end
131
+ end
132
+ return time
133
+ end
0 commit comments