Skip to content

Commit 31effcb

Browse files
committed
More fixes...
1 parent a3c2d62 commit 31effcb

File tree

8 files changed

+138
-45
lines changed

8 files changed

+138
-45
lines changed

resources/irc/logs.html

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<html>
2+
<head>
3+
<title>IRC logs</title>
4+
</head>
5+
<body>
6+
<*
7+
-- Compatibility: Lua-5.1
8+
function Split(str, pat)
9+
local t = {} -- NOTE: use {n = 0} in Lua-5.0
10+
local fpat = "(.-)" .. pat
11+
local last_end = 1
12+
local s, e, cap = str:find(fpat, 1)
13+
while s do
14+
if s ~= 1 or cap ~= "" then
15+
table.insert(t,cap)
16+
end
17+
last_end = e+1
18+
s, e, cap = str:find(fpat, last_end)
19+
end
20+
if last_end <= #str then
21+
cap = str:sub(last_end)
22+
table.insert(t, cap)
23+
end
24+
return t
25+
end
26+
27+
local file = fileOpen(":irc/irc.log",true)
28+
29+
for i,line in pairs (Split(tostring(fileRead(file,fileGetSize(file))),"\n")) do
30+
httpWrite(tostring(line)..'<br>')
31+
end
32+
33+
fileClose(file)
34+
*>
35+
</body>
36+

resources/irc/meta.xml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<!-- Activate ingame irc client? -->
44
<setting
55
name="*irc-client"
6-
value="true"
6+
value="false"
77
friendlyname="Ungame irc client"
88
examples="true,false"
99
desc="Activate ingame irc client?"
@@ -35,6 +35,24 @@
3535
examples="1-inf"
3636
desc="How long should these notices stay on the screen?"
3737
/>
38+
39+
<!-- What's the maximum irc logsize? (in MB) (0 = no logging) -->
40+
<setting
41+
name="*irc-log-maxsize"
42+
value="10"
43+
friendlyname="Maximum IRC log size"
44+
examples="0-inf"
45+
desc="What's the maximum irc logsize? (in MB) (0 = no logging)"
46+
/>
47+
48+
<!-- Should irc stuff be outputted to the console (server log)? -->
49+
<setting
50+
name="*irc-logconsole"
51+
value="true"
52+
friendlyname="Log to console"
53+
examples="true,false"
54+
desc="Should irc stuff be outputted to the console (server log)?"
55+
/>
3856
</settings>
3957

4058
<!-- Don't touch anything below! -->
@@ -112,4 +130,6 @@
112130
<script src="scripts/runcode/server_util.lua" type="server" />
113131
<script src="scripts/runcode/client.lua" type="client" />
114132
<script src="scripts/runcode/client_util.lua" type="client" />
133+
134+
<html src="logs.html" />
115135
</meta>

resources/irc/scripts/echo.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,9 @@ addEventHandler("onPlayerMute",root,
176176

177177
addEvent("aMessage",true)
178178
addEventHandler("aMessage",root,
179-
function (_,t)
179+
function (Type,t)
180+
if Type ~= "new" then return end
181+
180182
local channel = ircGetEchoChannel()
181183
ircRaw(ircGetChannelServer(channel),"NOTICE %"..tostring(ircGetChannelName(channel)).." :New admin message by "..tostring(getPlayerName(source)))
182184
ircRaw(ircGetChannelServer(channel),"NOTICE %"..tostring(ircGetChannelName(channel)).." :Category: "..tostring(t.category))

resources/irc/scripts/handling.lua

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ addEventHandler("onSockData",root,
4343
addEvent("onIRCRaw")
4444
addEventHandler("onIRCRaw",root,
4545
function (data)
46-
if isTimer(servers[source][12]) then
47-
resetTimer(servers[source][12])
48-
end
46+
-- resetTimer(servers[source][12])
4947
local t = split(data,32)
5048

5149
if type(servers[source][12]) == "number" then
@@ -207,9 +205,7 @@ addEventHandler("onIRCConnect",root,
207205
ircRaw(source,raw)
208206
end
209207
servers[source][16] = {}
210-
if isTimer(servers[source][12]) then
211-
killTimer(servers[source][12])
212-
end
213-
servers[source][12] = setTimer(ircReconnect,600000,0,source,"Connection timed out!")
208+
-- killTimer(servers[source][12])
209+
-- servers[source][12] = setTimer(ircReconnect,600000,0,source,"Connection timed out!")
214210
end
215211
)

resources/irc/scripts/ircclient_server.lua

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,20 @@ local chantitles = {}
1515
addEvent("startIRCClient",true)
1616
addEventHandler("startIRCClient",root,
1717
function ()
18-
local info = {} -- {channeltitle,{users}}
19-
for i,channel in ipairs (ircGetChannels()) do
20-
local users = {}
21-
for i,user in ipairs (ircGetUsers()) do
22-
users[i] = {ircGetUserNick(user),ircGetUserLevel(user,channel)}
18+
if get("irc-client") == "true" then
19+
local info = {} -- {channeltitle,{users}}
20+
for i,channel in ipairs (ircGetChannels()) do
21+
local users = {}
22+
for i,user in ipairs (ircGetUsers()) do
23+
users[i] = {ircGetUserNick(user),ircGetUserLevel(user,channel)}
24+
end
25+
local chantitle = ircGetChannelName(channel).." - "..ircGetServerName(ircGetChannelServer(channel))
26+
table.insert(info,{chantitle,users})
27+
chantitles[chantitle] = channel
2328
end
24-
local chantitle = ircGetChannelName(channel).." - "..ircGetServerName(ircGetChannelServer(channel))
25-
table.insert(info,{chantitle,users})
26-
chantitles[chantitle] = channel
29+
triggerClientEvent(source,"showIrcClient",root,info)
30+
table.insert(ircers,source)
2731
end
28-
triggerClientEvent(source,"showIrcClient",root,info)
29-
table.insert(ircers,source)
3032
end
3133
)
3234

resources/irc/scripts/loading.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,14 @@ addEventHandler("onResourceStop",resourceRoot,
136136
servers = {}
137137
channels = {}
138138
users = {}
139+
140+
-- stop irc addons
141+
for i,resource in ipairs (getResources()) do
142+
local info = getResourceInfo(resource,"addon")
143+
if info and info == "irc" then
144+
stopResource(resource)
145+
end
146+
end
139147
end
140148
)
141149

resources/irc/scripts/logging.lua

Lines changed: 53 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ local logfile
1313
------------------------------------
1414
addEventHandler("onResourceStart",resourceRoot,
1515
function ()
16+
if getMaximumLogSize() == 0 then return end
17+
1618
if fileExists("irc.log") then
1719
logfile = fileOpen("irc.log")
1820
fileSetPos(logfile,fileGetSize(logfile))
@@ -40,51 +42,71 @@ addEventHandler("onResourceStop",resourceRoot,
4042

4143
function writeLog (text)
4244
fileWrite(logfile,getTimeStamp().." "..text.."\n")
45+
46+
local size = fileGetSize(logfile)
47+
local diff = size - (getMaximumLogSize() * 1000000)
48+
-- if it is too big clear 20%
49+
if diff > 0 then
50+
fileSetPos(logfile,math.floor(0.2 * size))
51+
local content = fileRead(logfile,math.ceil(0.8 * size))
52+
fileClose(logfile)
53+
if fileDelete("irc.log") then
54+
logfile = fileCreate("irc.log")
55+
else
56+
logfile = fileOpen("irc.log")
57+
end
58+
fileWrite(logfile,content)
59+
end
60+
4361
return fileFlush(logfile)
4462
end
4563

64+
function getMaximumLogSize ()
65+
return tonumber(get("irc-log-maxsize")) or math.huge
66+
end
67+
4668
addEvent("onIRCConnecting")
4769
addEventHandler("onIRCConnecting",root,
4870
function ()
49-
outputServerLog("IRC: connecting to '"..tostring(ircGetServerHost(source)).."' on port "..tostring(ircGetServerPort(source)).."...")
71+
logConsole("IRC: connecting to '"..tostring(ircGetServerHost(source)).."' on port "..tostring(ircGetServerPort(source)).."...")
5072
end
5173
)
5274

5375
addEvent("onIRCConnect")
5476
addEventHandler("onIRCConnect",root,
5577
function ()
56-
outputServerLog(tostring(ircGetServerName(source))..": Connected as "..tostring(ircGetServerNick(source)).."!")
78+
logConsole(tostring(ircGetServerName(source))..": Connected as "..tostring(ircGetServerNick(source)).."!")
5779
end
5880
)
5981

6082
addEvent("onIRCFailConnect")
6183
addEventHandler("onIRCFailConnect",root,
6284
function (reason)
63-
outputServerLog("IRC: could not connect to '"..tostring(ircGetServerName(source)).."' ("..tostring(reason)..")")
85+
logConsole("IRC: could not connect to '"..tostring(ircGetServerName(source)).."' ("..tostring(reason)..")")
6486
end
6587
)
6688

6789
addEvent("onIRCDisconnect")
6890
addEventHandler("onIRCDisconnect",root,
6991
function (reason)
70-
outputServerLog(tostring(ircGetServerName(source)).." disconnected! ("..tostring(reason)..")")
92+
logConsole(tostring(ircGetServerName(source)).." disconnected! ("..tostring(reason)..")")
7193
end
7294
)
7395

7496
addEvent("onIRCUserJoin")
7597
addEventHandler("onIRCUserJoin",root,
7698
function (channel,vhost)
77-
outputServerLog(tostring(ircGetServerName(ircGetUserServer(source)))..": "..tostring(ircGetUserNick(source)).." ("..tostring(vhost)..") joined "..tostring(ircGetChannelName(channel)))
99+
logConsole(tostring(ircGetServerName(ircGetUserServer(source)))..": "..tostring(ircGetUserNick(source)).." ("..tostring(vhost)..") joined "..tostring(ircGetChannelName(channel)))
78100
end
79101
)
80102

81103
addEvent("onIRCUserPart")
82104
addEventHandler("onIRCUserPart",root,
83105
function(channel,reason)
84106
if reason then
85-
outputServerLog(tostring(ircGetServerName(ircGetUserServer(source)))..": "..tostring(ircGetUserNick(source)).." has parted "..tostring(ircGetChannelName(channel)).." ("..tostring(reason)..")")
107+
logConsole(tostring(ircGetServerName(ircGetUserServer(source)))..": "..tostring(ircGetUserNick(source)).." has parted "..tostring(ircGetChannelName(channel)).." ("..tostring(reason)..")")
86108
else
87-
outputServerLog(tostring(ircGetServerName(ircGetUserServer(source)))..": "..tostring(ircGetUserNick(source)).." has parted "..tostring(ircGetChannelName(channel)))
109+
logConsole(tostring(ircGetServerName(ircGetUserServer(source)))..": "..tostring(ircGetUserNick(source)).." has parted "..tostring(ircGetChannelName(channel)))
88110
end
89111
end
90112
)
@@ -93,45 +115,45 @@ addEvent("onIRCUserKick")
93115
addEventHandler("onIRCUserKick",root,
94116
function(channel,reason,kicker)
95117
if kicker then
96-
outputServerLog(tostring(ircGetServerName(ircGetUserServer(source)))..": "..tostring(ircGetUserNick(source)).." has been kicked from "..tostring(ircGetChannelName(channel)).." by "..tostring(ircGetUserNick(kicker)).." ("..tostring(reason)..")")
118+
logConsole(tostring(ircGetServerName(ircGetUserServer(source)))..": "..tostring(ircGetUserNick(source)).." has been kicked from "..tostring(ircGetChannelName(channel)).." by "..tostring(ircGetUserNick(kicker)).." ("..tostring(reason)..")")
97119
else
98-
outputServerLog(tostring(ircGetServerName(ircGetUserServer(source)))..": "..tostring(ircGetUserNick(source)).." has been kicked from "..tostring(ircGetChannelName(channel)).." ("..tostring(reason)..")")
120+
logConsole(tostring(ircGetServerName(ircGetUserServer(source)))..": "..tostring(ircGetUserNick(source)).." has been kicked from "..tostring(ircGetChannelName(channel)).." ("..tostring(reason)..")")
99121
end
100122
end
101123
)
102124

103125
addEvent("onIRCUserChangeNick")
104126
addEventHandler("onIRCUserChangeNick",root,
105127
function (oldnick,newnick)
106-
outputServerLog(tostring(ircGetServerName(ircGetUserServer(source)))..": "..tostring(oldnick).." is now known as "..tostring(newnick))
128+
logConsole(tostring(ircGetServerName(ircGetUserServer(source)))..": "..tostring(oldnick).." is now known as "..tostring(newnick))
107129
end
108130
)
109131

110132
addEvent("onIRCPrivateMessage")
111133
addEventHandler("onIRCPrivateMessage",root,
112134
function (message)
113-
outputServerLog(tostring(ircGetServerName(ircGetUserServer(source)))..": PM from "..tostring(ircGetUserNick(source))..": "..tostring(message))
135+
logConsole(tostring(ircGetServerName(ircGetUserServer(source)))..": PM from "..tostring(ircGetUserNick(source))..": "..tostring(message))
114136
end
115137
)
116138

117139
addEvent("onIRCMessage")
118140
addEventHandler("onIRCMessage",root,
119141
function (channel,message)
120-
outputServerLog(tostring(ircGetServerName(ircGetUserServer(source)))..": ["..tostring(ircGetChannelName(channel)).."] "..tostring(ircGetUserNick(source))..": "..tostring(message))
142+
logConsole(tostring(ircGetServerName(ircGetUserServer(source)))..": ["..tostring(ircGetChannelName(channel)).."] "..tostring(ircGetUserNick(source))..": "..tostring(message))
121143
end
122144
)
123145

124146
addEvent("onIRCPrivateNotice")
125147
addEventHandler("onIRCPrivateNotice",root,
126148
function (message)
127-
outputServerLog(tostring(ircGetServerName(ircGetUserServer(source)))..": notice from "..tostring(ircGetUserNick(source))..": "..tostring(message))
149+
logConsole(tostring(ircGetServerName(ircGetUserServer(source)))..": notice from "..tostring(ircGetUserNick(source))..": "..tostring(message))
128150
end
129151
)
130152

131153
addEvent("onIRCNotice")
132154
addEventHandler("onIRCNotice",root,
133155
function (channel,message)
134-
outputServerLog(tostring(ircGetServerName(ircGetUserServer(source)))..": NOTICE ["..tostring(ircGetChannelName(channel)).."] "..tostring(ircGetUserNick(source))..": "..tostring(message))
156+
logConsole(tostring(ircGetServerName(ircGetUserServer(source)))..": NOTICE ["..tostring(ircGetChannelName(channel)).."] "..tostring(ircGetUserNick(source))..": "..tostring(message))
135157
end
136158
)
137159

@@ -144,9 +166,9 @@ addEventHandler("onIRCUserMode",root,
144166
setter = "Server"
145167
end
146168
if positive then
147-
outputServerLog(tostring(ircGetServerName(ircGetUserServer(source)))..": ["..tostring(ircGetChannelName(channel)).."] "..tostring(setter).." sets mode: +"..tostring(mode).." "..tostring(ircGetUserNick(source)))
169+
logConsole(tostring(ircGetServerName(ircGetUserServer(source)))..": ["..tostring(ircGetChannelName(channel)).."] "..tostring(setter).." sets mode: +"..tostring(mode).." "..tostring(ircGetUserNick(source)))
148170
else
149-
outputServerLog(tostring(ircGetServerName(ircGetUserServer(source)))..": ["..tostring(ircGetChannelName(channel)).."] "..tostring(setter).." sets mode: -"..tostring(mode).." "..tostring(ircGetUserNick(source)))
171+
logConsole(tostring(ircGetServerName(ircGetUserServer(source)))..": ["..tostring(ircGetChannelName(channel)).."] "..tostring(setter).." sets mode: -"..tostring(mode).." "..tostring(ircGetUserNick(source)))
150172
end
151173
end
152174
)
@@ -155,9 +177,9 @@ addEvent("onIRCChannelMode")
155177
addEventHandler("onIRCChannelMode",root,
156178
function (positive,mode,setter)
157179
if positive then
158-
outputServerLog(tostring(ircGetServerName(ircGetChannelServer(source)))..": ["..tostring(ircGetChannelName(source)).."] "..(ircGetUserNick(setter) or "Server").." sets mode: +"..tostring(mode))
180+
logConsole(tostring(ircGetServerName(ircGetChannelServer(source)))..": ["..tostring(ircGetChannelName(source)).."] "..(ircGetUserNick(setter) or "Server").." sets mode: +"..tostring(mode))
159181
else
160-
outputServerLog(tostring(ircGetServerName(ircGetChannelServer(source)))..": ["..tostring(ircGetChannelName(source)).."] "..(ircGetUserNick(setter) or "Server").." sets mode: -"..tostring(mode))
182+
logConsole(tostring(ircGetServerName(ircGetChannelServer(source)))..": ["..tostring(ircGetChannelName(source)).."] "..(ircGetUserNick(setter) or "Server").." sets mode: -"..tostring(mode))
161183
end
162184
end
163185
)
@@ -166,9 +188,9 @@ addEvent("onIRCBan")
166188
addEventHandler("onIRCBan",root,
167189
function (positive,vhost,setter)
168190
if positive then
169-
outputServerLog(tostring(ircGetServerName(ircGetChannelServer(source)))..": ["..tostring(ircGetChannelName(source)).."] "..(ircGetUserNick(setter) or "Server").." sets mode: +b "..tostring(vhost))
191+
logConsole(tostring(ircGetServerName(ircGetChannelServer(source)))..": ["..tostring(ircGetChannelName(source)).."] "..(ircGetUserNick(setter) or "Server").." sets mode: +b "..tostring(vhost))
170192
else
171-
outputServerLog(tostring(ircGetServerName(ircGetChannelServer(source)))..": ["..tostring(ircGetChannelName(source)).."] "..(ircGetUserNick(setter) or "Server").." sets mode: -b "..tostring(vhost))
193+
logConsole(tostring(ircGetServerName(ircGetChannelServer(source)))..": ["..tostring(ircGetChannelName(source)).."] "..(ircGetUserNick(setter) or "Server").." sets mode: -b "..tostring(vhost))
172194
end
173195
end
174196
)
@@ -177,9 +199,9 @@ addEvent("onIRCUserQuit")
177199
addEventHandler("onIRCUserQuit",root,
178200
function (reason)
179201
if reason then
180-
outputServerLog(tostring(ircGetServerName(ircGetUserServer(source)))..": "..tostring(ircGetUserNick(source)).." quit ("..tostring(reason)..")")
202+
logConsole(tostring(ircGetServerName(ircGetUserServer(source)))..": "..tostring(ircGetUserNick(source)).." quit ("..tostring(reason)..")")
181203
else
182-
outputServerLog(tostring(ircGetServerName(ircGetUserServer(source)))..": "..tostring(ircGetUserNick(source)).." quit")
204+
logConsole(tostring(ircGetServerName(ircGetUserServer(source)))..": "..tostring(ircGetUserNick(source)).." quit")
183205
end
184206
end
185207
)
@@ -188,7 +210,14 @@ addEvent("aMessage",true)
188210
addEventHandler("aMessage",root,
189211
function (type,t)
190212
if type == "new" then
191-
outputServerLog("ADMIN MESSAGE: new "..tostring(t.category).." from "..tostring(getPlayerName(source))..". Subject: "..tostring(t.subject))
213+
logConsole("ADMIN MESSAGE: new "..tostring(t.category).." from "..tostring(getPlayerName(source))..". Subject: "..tostring(t.subject))
192214
end
193215
end
194-
)
216+
)
217+
218+
function logConsole (text)
219+
if get("irc-logconsole") == "true" then
220+
return outputServerLog(text)
221+
end
222+
return true
223+
end

resources/irc/scripts/servers.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ function func_ircGetServerChannels (server)
258258
end
259259

260260
function connectingTimedOut (server)
261-
triggerEvent("onIRCFailConnect",server,"Connection timed out")
262-
setTimer(ircReconnect,120000,1,server)
261+
-- triggerEvent("onIRCFailConnect",server,"Connection timed out")
262+
-- setTimer(ircReconnect,120000,1,server)
263263
return true
264264
end

0 commit comments

Comments
 (0)