Skip to content

Commit 4268580

Browse files
committed
*insert something useful here*
1 parent c979281 commit 4268580

File tree

9 files changed

+181
-48
lines changed

9 files changed

+181
-48
lines changed

resources/irc/acl.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,10 @@
4040
<command name="!modules" level="3" echoChannelOnly="true" />
4141
<command name="!changemap" level="3" echoChannelOnly="true" />
4242
<command name="!map" level="0" echoChannelOnly="true" />
43+
<command name="!shutdown" level="5" echoChannelOnly="true" />
44+
<command name="!password" level="4" echoChannelOnly="true" />
45+
<command name="!gravity" level="3" echoChannelOnly="true" />
46+
<command name="!weather" level="3" echoChannelOnly="true" />
47+
<command name="!server" level="0" echoChannelOnly="false" />
48+
<command name="!zone" level="0" echoChannelOnly="false" />
4349
</acl>

resources/irc/logs.html

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,14 @@
66
<*
77
local file = fileOpen(":irc/irc.log",true)
88

9-
for i,line in pairs (split(tostring(fileRead(file,fileGetSize(file))),10)) do
10-
httpWrite(tostring(line)..'<br>')
9+
if file then
10+
11+
for i,line in pairs (split(tostring(fileRead(file,fileGetSize(file))),10)) do
12+
httpWrite(tostring(line)..'<br>')
13+
end
14+
15+
else
16+
httpWrite("File could not be opened!");
1117
end
1218

1319
fileClose(file)

resources/irc/meta.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<setting
55
name="*irc-client"
66
value="false"
7-
friendlyname="Ungame irc client"
7+
friendlyname="Ingame irc client"
88
examples="true,false"
99
desc="Activate ingame irc client?"
1010
/>

resources/irc/scripts/echo.lua

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,18 @@
99
------------------------------------
1010
-- Echo
1111
------------------------------------
12+
local messages = {}
13+
1214
addEventHandler("onResourceStart",root,
1315
function (resource)
1416
if getResourceInfo(resource,"type") ~= "map" then
1517
outputIRC("07* Resource '"..getResourceName(resource).."' started!")
1618
end
19+
if resource == getThisResource() then
20+
for i,player in ipairs (getElementsByType("player")) do
21+
messages[player] = 0
22+
end
23+
end
1724
end
1825
)
1926

@@ -27,12 +34,14 @@ addEventHandler("onResourceStop",root,
2734

2835
addEventHandler("onPlayerJoin",root,
2936
function ()
37+
messages[source] = 0
3038
outputIRC("03*** "..getPlayerName(source).." joined the game.")
3139
end
3240
)
3341

3442
addEventHandler("onPlayerQuit",root,
3543
function (quit,reason,element)
44+
messages[source] = nil
3645
if reason then
3746
outputIRC("02*** "..getPlayerName(source).." was "..quit.." from the game by "..getPlayerName(element).." ("..reason..")")
3847
else
@@ -43,24 +52,30 @@ addEventHandler("onPlayerQuit",root,
4352

4453
addEventHandler("onPlayerChangeNick",root,
4554
function (oldNick,newNick)
46-
outputIRC("13* "..oldNick.." is now known as "..newNick)
55+
setTimer(function (player,oldNick)
56+
local newNick = getPlayerName(player)
57+
if newNick ~= oldNick then
58+
outputIRC("13* "..oldNick.." is now known as "..newNick)
59+
end
60+
end,100,1,source,oldNick)
4761
end
4862
)
4963

50-
addEvent("onPlayerMute",root,
64+
addEventHandler("onPlayerMute",root,
5165
function ()
5266
outputIRC("12* "..getPlayerName(source).." has been muted")
5367
end
5468
)
5569

56-
addEvent("onPlayerUnmute",root,
70+
addEventHandler("onPlayerUnmute",root,
5771
function ()
5872
outputIRC("12* "..getPlayerName(source).." has been unmuted")
5973
end
6074
)
6175

6276
addEventHandler("onPlayerChat",root,
6377
function (message,type)
78+
messages[source] = messages[source] + 1
6479
if type == 0 then
6580
outputIRC("07"..getPlayerName(source)..": "..message)
6681
elseif type == 1 then
@@ -71,6 +86,25 @@ addEventHandler("onPlayerChat",root,
7186
end
7287
)
7388

89+
-- anti-spam
90+
setTimer(function ()
91+
for player,number in pairs (messages) do
92+
if number >= 2 then
93+
muteSerial(getPlayerSerial(player),"Antispam triggered",180000)
94+
setPlayerMuted(player,true)
95+
outputChatBox("* "..getPlayerName(player).." was muted by irc (Antispam triggered)",root,0,0,255)
96+
ircSay(channel,"12* "..getPlayerName(player).." was muted by irc (Antispam triggered)")
97+
end
98+
messages[player] = 0
99+
end
100+
end,3000,0)
101+
102+
addEventHandler("onSettingChange",root,
103+
function (setting,oldValue,newValue)
104+
outputIRC("6Setting '"..tostring(setting).."' changed: "..tostring(oldValue).." -> "..tostring(newValue))
105+
end
106+
)
107+
74108
local bodyparts = {nil,nil,"Torso","Ass","Left Arm","Right Arm","Left Leg","Right Leg","Head"}
75109
local weapons = {}
76110
weapons[19] = "Rockets"

resources/irc/scripts/functions.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ boolean ircNotice userdata string,
99
boolean outputIRC string,
1010
boolean ircConnect string string (number) (string) (boolean),
1111
boolean ircIdentify userdata string,
12-
boolean ircReconnect userdata,
12+
boolean ircReconnect userdata (string),
1313
boolean ircDisconnect userdata string,
1414
boolean ircChangeNick userdata string,
1515
table ircGetServers,

resources/irc/scripts/handling.lua

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,9 @@ addEventHandler("onSockData",root,
4343
addEvent("onIRCRaw")
4444
addEventHandler("onIRCRaw",root,
4545
function (data)
46-
-- resetTimer(servers[source][12])
47-
local t = split(data,32)
46+
servers[source][11] = getTickCount()
4847

49-
if type(servers[source][12]) == "number" then
50-
servers[source][12] = getTickCount()
51-
end
48+
local t = split(data,32)
5249
if t[1] == "PING" then
5350
if t[2] then
5451
ircRaw(source,"PONG "..string.sub(t[2],2))
@@ -62,9 +59,10 @@ addEventHandler("onIRCRaw",root,
6259
end
6360
if t[2] == "001" then
6461
servers[source][2] = t[7]
62+
servers[source][15] = true
6563
end
6664
if t[2] == "002" then
67-
servers[source][3] = t[7]
65+
servers[source][3] = string.sub(t[7],1,-2)
6866
end
6967
if t[2] == "JOIN" then
7068
local nick = getNickFromRaw(data)
@@ -73,6 +71,7 @@ addEventHandler("onIRCRaw",root,
7371
local vhost = gettok(gettok(data,1,32),2,33)
7472
if nick == ircGetServerNick(source) then
7573
if not channel then
74+
table.insert(servers[source][14],getMessageFromRaw(data))
7675
channel = createElement("irc-channel")
7776
channels[channel] = {getMessageFromRaw(data),"+nst","Unknown",{},false,true,false}
7877
setElementParent(channel,source)
@@ -205,7 +204,16 @@ addEventHandler("onIRCConnect",root,
205204
ircRaw(source,raw)
206205
end
207206
servers[source][16] = {}
208-
-- killTimer(servers[source][12])
209-
-- servers[source][12] = setTimer(ircReconnect,600000,0,source,"Connection timed out!")
210207
end
211-
)
208+
)
209+
210+
setTimer(function ()
211+
for i,server in ipairs (ircGetServers()) do
212+
if (getTickCount() - servers[server][11]) > 180000 then
213+
servers[server][11] = getTickCount()
214+
ircReconnect(server,"Connection timed out")
215+
elseif (getTickCount() - servers[server][11]) > 120000 then
216+
ircRaw(server,"PING")
217+
end
218+
end
219+
end,30000,0)

resources/irc/scripts/ircclient_client.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ addEventHandler("showIrcClient",root,
4747
local memo = guiCreateMemo(0.005,0.01,0.74,0.9,"",true,tab)
4848
local gridlist = guiCreateGridList(0.75,0.01,0.245,0.99,true,tab)
4949
local column = guiGridListAddColumn(gridlist,"Users",0.8)
50+
guiGridListSetSortingEnabled(gridlist,true)
5051
for i,user in ipairs (inf[2]) do
5152
local row = guiGridListAddRow(gridlist)
5253
guiGridListSetItemText(gridlist,row,column,getIconFromLevel(user[2])..user[1],false,false)
@@ -57,7 +58,6 @@ addEventHandler("showIrcClient",root,
5758
gridlists[chantitle] = gridlist
5859
memolines[memo] = {}
5960
end
60-
guiGridListSetSortingEnabled(gridlist,true)
6161
guiBringToFront(exitbutton)
6262
guiSetInputEnabled(true)
6363
showCursor(true)

resources/irc/scripts/irccommands.lua

Lines changed: 93 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function addIRCCommands ()
1111

1212
function say (server,channel,user,command,...)
1313
local message = table.concat({...}," ")
14-
if not message then ircNotice(user,"syntax is !s <message>") return end
14+
if message == "" then ircNotice(user,"syntax is !s <message>") return end
1515
outputChatBox("* "..ircGetUserNick(user).." on irc: "..message,root,255,168,0)
1616
outputIRC("07* "..ircGetUserNick(user).." on irc: "..message)
1717
end
@@ -23,7 +23,7 @@ addIRCCommandHandler("!pm",
2323
function (server,channel,user,command,name,...)
2424
local message = table.concat({...}," ")
2525
if not name then ircNotice(user,"syntax is !pm <name> <message>") return end
26-
if not message then ircNotice(user,"syntax is !pm <name> <message>") return end
26+
if message == "" then ircNotice(user,"syntax is !pm <name> <message>") return end
2727
local player = getPlayerFromPartialName(name)
2828
if player then
2929
outputChatBox("* PM from "..ircGetUserNick(user).." on irc: "..message,player,255,168,0)
@@ -130,8 +130,8 @@ addIRCCommandHandler("!unmute",
130130
addIRCCommandHandler("!freeze",
131131
function (server,channel,user,command,name,...)
132132
if not name then ircNotice(user,"syntax is !freeze <name> [reason]") return end
133-
local reason = table.concat({...}," ") or ""
134-
local reason = table.concat({...}," ") or ""
133+
local reason = table.concat({...}," ")
134+
local reason = table.concat({...}," ")
135135
local t = split(reason,40)
136136
local time
137137
if #t > 1 then
@@ -172,8 +172,8 @@ addIRCCommandHandler("!unfreeze",
172172

173173
addIRCCommandHandler("!slap",
174174
function (server,channel,user,command,name,hp,...)
175-
if not name then ircNotice(user,"syntax is !slap <name> <hp> [reason]") return end
176-
if not hp then ircNotice(user,"syntax is !slap <name> <hp> [reason]") return end
175+
if not name then ircNotice(user,"syntax is !slap <name> <hp> (<reason>)") return end
176+
if not hp then ircNotice(user,"syntax is !slap <name> <hp> (<reason>)") return end
177177
local reason = table.concat({...}," ") or ""
178178
local player = getPlayerFromPartialName(name)
179179
if player then
@@ -324,7 +324,7 @@ addIRCCommandHandler("!players",
324324
addIRCCommandHandler("!run",
325325
function (server,channel,user,command,...)
326326
local str = table.concat({...}," ")
327-
if not str then ircNotice(user,"syntax is !run <string>") return end
327+
if str == "" then ircNotice(user,"syntax is !run <string>") return end
328328
runString(str,root,ircGetUserNick(user))
329329
end
330330
)
@@ -333,15 +333,23 @@ addIRCCommandHandler("!crun",
333333
function (server,channel,user,command,...)
334334
local t = {...}
335335
local str = table.concat(t," ")
336-
if not str then ircNotice(user,"syntax is !crun <string>") return end
337-
if #getElementsByType("player") == 0 then
338-
ircNotice(user,"No player ingame!")
339-
end
340-
for i,player in ipairs (getElementsByType("player")) do
341-
if i == 1 then
342-
triggerClientEvent(player,"doCrun",root,str,false)
343-
else
344-
triggerClientEvent(player,"doCrun",root,str,false)
336+
if str == "" then ircNotice(user,"syntax is !crun (<name>) <string>") return end
337+
local player = getPlayerFromPartialName(tostring(t[1]))
338+
if player then
339+
table.remove(t,1)
340+
str = table.concat(t," ")
341+
triggerClientEvent(player,"doCrun",root,str,true)
342+
else
343+
if #getElementsByType("player") == 0 then
344+
ircNotice(user,"No player ingame!")
345+
return
346+
end
347+
for i,player in ipairs (getElementsByType("player")) do
348+
if i == 1 then
349+
triggerClientEvent(player,"doCrun",root,str,true)
350+
else
351+
triggerClientEvent(player,"doCrun",root,str,false)
352+
end
345353
end
346354
end
347355
end
@@ -552,4 +560,73 @@ addIRCCommandHandler("!modules",
552560
end
553561
)
554562

563+
addIRCCommandHandler("!shutdown",
564+
function (server,channel,user,command,...)
565+
local reason = table.concat({...}," ")
566+
if not reason then reason = "Shutdown from irc" end
567+
shutdown(reason)
568+
end
569+
)
570+
571+
addIRCCommandHandler("!password",
572+
function (server,channel,user,command,...)
573+
local newpass = table.concat({...}," ")
574+
if newpass ~= "" then
575+
if setServerPassword(newpass) then
576+
ircNotice(user,"New server pass: "..tostring(getServerPassword()))
577+
end
578+
else
579+
ircNotice(user,"Current server pass: "..tostring(getServerPassword()).." use !password <newpass> to change it")
580+
end
581+
end
582+
)
583+
584+
addIRCCommandHandler("!gravity",
585+
function (server,channel,user,command,...)
586+
local newgravity = table.concat({...}," ")
587+
if tonumber(newgravity) then
588+
if setGravity(tonumber(newgravity)) then
589+
ircNotice(user,"New gravity: "..tostring(getGravity()))
590+
end
591+
else
592+
ircNotice(user,"Current gravity: "..tostring(getWeather()).." use !gravity <new gravity> to change it")
593+
end
594+
end
595+
)
596+
597+
addIRCCommandHandler("!weather",
598+
function (server,channel,user,command,...)
599+
local newweather = table.concat({...}," ")
600+
if newweather then
601+
if setWeather(tonumber(newweather)) then
602+
ircNotice(user,"New weather: "..tostring(getWeather()))
603+
end
604+
else
605+
ircNotice(user,"Current weather: "..tostring(getWeather()).." use !weather <new weather> to change it")
606+
end
607+
end
608+
)
609+
610+
addIRCCommandHandler("!server",
611+
function (server,channel,user,command,...)
612+
ircSay(channel,"Server: "..tostring(getServerName()).." Port: "..tostring(getServerPort()))
613+
end
614+
)
615+
616+
addIRCCommandHandler("!zone",
617+
function (server,channel,user,command,name)
618+
if not name then ircNotice(user,"syntax is !zone <name>") return end
619+
local player = getPlayerFromPartialName(name)
620+
if player then
621+
local x,y,z = getElementPosition(player)
622+
if not x then return end
623+
local zone = getZoneName(x,y,z,false)
624+
local city = getZoneName(x,y,z,true)
625+
ircSay(channel,tostring(getPlayerName(player)).."'s zone: "..tostring(zone).." ("..tostring(city)..")")
626+
else
627+
ircSay(channel,"'"..name.."' no such player")
628+
end
629+
end
630+
)
631+
555632
end

0 commit comments

Comments
 (0)