|
6 | 6 | -- Date: 31.10.2010
|
7 | 7 | ---------------------------------------------------------------------
|
8 | 8 |
|
| 9 | +executeSQLCreateTable("ircmutes","player TEXT, serial TEXT, reason TEXT, admin TEXT, mute TEXT, duration TEXT") |
| 10 | + |
9 | 11 | ------------------------------------
|
10 | 12 | -- Utility
|
11 | 13 | ------------------------------------
|
@@ -82,51 +84,50 @@ function getTimeStamp ()
|
82 | 84 | return "["..(time.year + 1900).."-"..(time.month+1).."-"..time.monthday.." "..time.hour..":"..time.minute..":"..time.second.."]"
|
83 | 85 | end
|
84 | 86 |
|
85 |
| -mutes = {} |
86 | 87 | _setPlayerMuted = setPlayerMuted
|
87 | 88 | function setPlayerMuted (player,muted,reason,admin,time)
|
88 | 89 | if muted then
|
89 |
| - mutes[getPlayerSerial(player)] = {reason = reason,admin = admin,time = time,tick = getTickCount()} |
| 90 | + executeSQLInsert("ircmutes","'"..tostring(getPlayerName(player)).."','"..tostring(getPlayerSerial(player)).."','"..tostring(reason).."','"..tostring(admin).."','"..tostring(getRealTime().timestamp*1000).."','"..tostring(time).."'") |
90 | 91 | else
|
91 |
| - mutes[getPlayerSerial(player)] = nil |
| 92 | + executeSQLDelete("ircmutes","serial = '"..tostring(getPlayerSerial(player)).."'") |
92 | 93 | end
|
93 | 94 | return _setPlayerMuted(player,muted)
|
94 | 95 | end
|
95 | 96 |
|
| 97 | +addEventHandler("onPlayerUnmute",root, |
| 98 | + function () |
| 99 | + executeSQLDelete("ircmutes","serial = '"..tostring(getPlayerSerial(player)).."'") |
| 100 | + end |
| 101 | +) |
| 102 | + |
96 | 103 | setTimer(function ()
|
97 |
| - for serial,info in pairs (mutes) do |
98 |
| - if info.time and (getTickCount() - info.tick) > info.time then |
99 |
| - for i,player in ipairs (getElementsByType("player")) do |
100 |
| - if getPlayerSerial(player) == serial then |
101 |
| - setPlayerMuted(player,false) |
| 104 | + local results = executeSQLSelect("ircmutes","serial,mute,duration") |
| 105 | + if type(results) == "table" then |
| 106 | + for i,result in ipairs (results) do |
| 107 | + local mutetime = tonumber(result["mute"]) |
| 108 | + local duration = tonumber(result["duration"]) |
| 109 | + if mutetime and duration and (mutetime+duration) < (getRealTime().timestamp)*1000 then |
| 110 | + for i,player in ipairs (getElementsByType("player")) do |
| 111 | + if getPlayerSerial(player) == result["serial"] then |
| 112 | + _setPlayerMuted(player,false) |
| 113 | + outputChatBox("* "..getPlayerName(player).." has been unmuted",root,255,0,0) |
| 114 | + end |
102 | 115 | end
|
103 |
| - end |
104 |
| - if mutes[serial] then |
105 |
| - mutes[serial] = nil |
| 116 | + executeSQLDelete("ircmutes","serial = '"..tostring(result["serial"]).."'") |
106 | 117 | end
|
107 | 118 | end
|
108 | 119 | end
|
109 | 120 | end,5000,0)
|
110 | 121 |
|
111 | 122 | addEventHandler("onPlayerJoin",root,
|
112 | 123 | function ()
|
113 |
| - local mute = mutes[(getPlayerSerial(source))] |
114 |
| - if mute then |
| 124 | + local result = executeSQLSelect("ircmutes","serial,reason","serial = '"..getPlayerSerial(source).."'") |
| 125 | + if result and result[1] then |
115 | 126 | _setPlayerMuted(source,true)
|
116 | 127 | end
|
117 | 128 | end
|
118 | 129 | )
|
119 | 130 |
|
120 |
| -addEventHandler("onResourceStop",resourceRoot, |
121 |
| - function () |
122 |
| - for i,player in ipairs (getElementsByType("player")) do |
123 |
| - if mutes[getPlayerSerial(player)] then |
124 |
| - setPlayerMuted(player,false) |
125 |
| - end |
126 |
| - end |
127 |
| - end |
128 |
| -) |
129 |
| - |
130 | 131 | local times = {}
|
131 | 132 | times["ms"] = 1
|
132 | 133 | times["sec"] = 1000
|
|
0 commit comments