Skip to content

Commit 155f0c3

Browse files
committed
More fixes
1 parent fc173f2 commit 155f0c3

File tree

4 files changed

+35
-26
lines changed

4 files changed

+35
-26
lines changed

resources/irc/meta.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
<export function="ircGetChannelUsers" type="server" http="false" />
9090
<export function="ircGetChannelTopic" type="server" http="false" />
9191
<export function="ircGetChannelFromName" type="server" http="false" />
92-
<export function="ircIsEchoChannels" type="server" http="false" />
92+
<export function="ircIsEchoChannel" type="server" http="false" />
9393

9494
<export function="ircSetUserMode" type="server" http="false" />
9595
<export function="ircGetUserMode" type="server" http="false" />

resources/irc/scripts/acl.lua

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,42 +6,39 @@
66
-- Date: 31.10.2010
77
---------------------------------------------------------------------
88

9-
acl = {}
10-
local commands = {}
9+
commands = {}
1110

1211
------------------------------------
1312
-- Acl
1413
------------------------------------
15-
function func_addIRCCommandHandler (cmd,fn,level,echochanonly)
14+
function func_addIRCCommandHandler (cmd,fn,level,echoChannelOnly)
1615
if not level then level = 0 end
17-
if not echochanonly then echochanonly = true end
18-
if not acl[string.lower(cmd)] then
19-
acl[string.lower(cmd)] = {name = string.lower(cmd),level = level,echoChannelOnly = echochannelonly}
20-
end
21-
commands[string.lower(cmd)] = fn
16+
if not echoChannelOnly then echoChannelOnly = true end
17+
if commands[string.lower(cmd)] and commands[string.lower(cmd)].fn then return false end
18+
commands[string.lower(cmd)] = {fn=fn,level=level,echoChannelOnly=echoChannelOnly,sourceResource=sourceResource}
2219
return true
2320
end
24-
registerFunction("addIRCCommandHandler","func_addIRCCommandHandler","string","function","(number)","(boolean)")
21+
registerFunction("addIRCCommandHandler","func_addIRCCommandHandler","string","function/string","(number)","(boolean)")
2522

2623
function ircGetCommands ()
2724
local cmds = {}
28-
for cmd,fn in pairs (commands) do
25+
for cmd,_ in pairs (commands) do
2926
table.insert(cmds,cmd)
3027
end
3128
return cmds
3229
end
3330

3431
function func_ircGetCommandLevel (cmd)
35-
if acl[cmd] then
36-
return tonumber(acl[cmd].level) or 0
32+
if commands[cmd] then
33+
return tonumber(commands[cmd].level)
3734
end
3835
return false
3936
end
4037
registerFunction("ircGetCommandLevel","func_ircGetCommandLevel","string")
4138

4239
function func_ircIsCommandEchoChannelOnly (cmd)
43-
if acl[cmd] then
44-
return acl[cmd].echoChannelOnly
40+
if commands[cmd] then
41+
return commands[cmd].echoChannelOnly
4542
end
4643
return false
4744
end
@@ -52,13 +49,12 @@ addEventHandler("onIRCMessage",root,
5249
function (channel,message)
5350
local cmd = string.lower(gettok(message,1,32))
5451
local args = split(message,32)
55-
if commands[cmd] and acl[cmd] and acl[cmd].level and (tonumber(acl[cmd].level) or 0) <= (tonumber(ircGetUserLevel(source,channel)) or 0) then
56-
if ircIsCommandEchoChannelOnly(cmd) then
57-
if ircIsEchoChannel(channel) then
58-
commands[cmd](ircGetChannelServer(channel),channel,source,unpack(args))
59-
end
52+
if commands[cmd] and commands[cmd].level <= (tonumber(ircGetUserLevel(source,channel)) or 0) then
53+
if commands[cmd].echoChannelOnly and not ircIsEchoChannel(channel) then return end
54+
if type(commands[cmd].fn) == "function" then
55+
commands[cmd].fn(ircGetChannelServer(channel),channel,source,unpack(args))
6056
else
61-
commands[cmd](ircGetChannelServer(channel),channel,source,unpack(args))
57+
call(commands[cmd].sourceResource,commands[cmd].fn,ircGetChannelServer(channel),channel,source,unpack(args))
6258
end
6359
end
6460
end

resources/irc/scripts/irccommands.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,8 @@ addEventHandler("onIRCResourceStart",root,
188188
if player then
189189
setElementVelocity((getPedOccupiedVehicle(player) or player),0,0,hp*0.01)
190190
setElementHealth((getPedOccupiedVehicle(player) or player),(getElementHealth((getPedOccupiedVehicle(player) or player)) - hp))
191-
outputChatBox(getPlayerName(player).." was slaped by "..ircGetUserNick(user).." ("..reason..")("..hp.."HP)",root,255,0,0)
192-
ircSay(channel,"12* "..getPlayerName(player).." was slaped by "..ircGetUserNick(user).." ("..reason..")("..hp.."HP)")
191+
outputChatBox(getPlayerName(player).." was slapped by "..ircGetUserNick(user).." ("..reason..")("..hp.."HP)",root,255,0,0)
192+
ircSay(channel,"12* "..getPlayerName(player).." was slapped by "..ircGetUserNick(user).." ("..reason..")("..hp.."HP)")
193193
else
194194
ircNotice(user,"'"..name.."' no such player")
195195
end

resources/irc/scripts/loading.lua

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,12 @@ addEventHandler("onResourceStart",resourceRoot,
8585
while(xmlFindChild(aclFile,"command",i)) do
8686
local child = xmlFindChild(aclFile,"command",i)
8787
local attrs = xmlNodeGetAttributes(child)
88-
acl[attrs.name] = attrs
88+
if commands[string.lower(attrs.name)] then
89+
commands[string.lower(attrs.name)].level = tonumber(attrs.level)
90+
commands[string.lower(attrs.name)].echoChannelOnly = attrs.echoChannelOnly
91+
else
92+
commands[string.lower(attrs.name)] = {level = tonumber(attrs.level),echoChannelOnly = attrs.echoChannelOnly}
93+
end
8994
i = i + 1
9095
end
9196
xmlUnloadFile(aclFile)
@@ -206,9 +211,17 @@ function registerFunction (name,ft,...)
206211
local arguments = {...}
207212
for i,arg in ipairs (arguments) do
208213
if string.sub(arg,1,1) == "(" and string.sub(arg,-1) == ")" then
209-
arguments[i] = "if args["..i.."] and type(args["..i.."]) ~= '"..string.sub(arg,2,-2).."' then return not outputDebugString('bad argument at "..name.." "..arg.." expected, got '..type(args["..i.."])) end"
214+
arguments[i] = "if args["..i.."] and type(args["..i.."]) ~= '"..string.sub(arg,2,-2).."' then return not outputDebugString('bad argument #"..i.." at "..name.." "..arg.." expected, got '..type(args["..i.."])) end"
215+
elseif string.find(arg,"/") then
216+
local args = split(arg,"/")
217+
local str = ""
218+
for k,arg in ipairs (args) do
219+
str = str.."type(args["..i.."]) ~= '"..arg.."' and "
220+
end
221+
str = string.sub(str,1,-5)
222+
arguments[i] = "if "..str.." then return not outputDebugString('bad argument #"..i.." at "..name.." "..arg.." expected, got '..type(args["..i.."])) end"
210223
else
211-
arguments[i] = "if type(args["..i.."]) ~= '"..arg.."' then return not outputDebugString('bad argument at "..name.." "..arg.." expected, got '..type(args["..i.."])) end"
224+
arguments[i] = "if type(args["..i.."]) ~= '"..arg.."' then return not outputDebugString('bad argument #"..i.." at "..name.." "..arg.." expected, got '..type(args["..i.."])) end"
212225
end
213226
end
214227
loadstring("function "..name.." (...) local args = {...} "..table.concat(arguments," ").." return "..ft.."(...) end")()

0 commit comments

Comments
 (0)