@@ -13,7 +13,45 @@ local adTimer
13
13
---- --------------------------------
14
14
addEventHandler (" onResourceStart" ,resourceRoot ,
15
15
function ()
16
- -- Parse rights file.
16
+ -- Parse functions file.
17
+ local functionsFile = fileOpen (" scripts/functions.txt" ,true )
18
+ if functionsFile then
19
+ for i ,line in ipairs (split (fileRead (functionsFile ,fileGetSize (functionsFile )),44 )) do
20
+ if gettok (line ,1 ,21 ) ~= " --" then
21
+ local functionName = gettok (line ,2 ,32 )
22
+ _G [(functionName )] = function (...)
23
+ local args = {... }
24
+ for i ,arg in ipairs (args ) do
25
+ local expectedArgType = gettok (line ,(2 + i ),32 )
26
+ if expectedArgType and type (arg ) ~= expectedArgType and not (expectedArgType or string.find (expectedArgType ," )" )) then
27
+ outputServerLog (" IRC: Bad argument #" .. i .. " @ '" .. gettok (line ,2 ,32 ).. " ' " .. expectedArgType .. " expected, got " .. type (arg ))
28
+ return
29
+ end
30
+ end
31
+ if _G [(" func_" .. functionName )] then
32
+ return _G [(" func_" .. functionName )](... )
33
+ else
34
+ outputServerLog (" Function '" .. functionName .. " ' does not exist" )
35
+ return false
36
+ end
37
+ end
38
+ end
39
+ end
40
+ fileClose (functionsFile )
41
+ else
42
+ outputServerLog (" IRC: could not start resource, the functions file can't be loaded!" )
43
+ outputServerLog (" IRC: restart the resource to retry" )
44
+ return
45
+ end
46
+
47
+ -- Is the sockets module loaded?
48
+ if not sockOpen then
49
+ outputServerLog (" IRC: could not start resource, the sockets module isn't loaded!" )
50
+ outputServerLog (" IRC: restart the resource to retry" )
51
+ return
52
+ end
53
+
54
+ -- Parse rights file.
17
55
local rightsFile = fileOpen (" scripts/rights.txt" ,true )
18
56
if rightsFile then
19
57
local missingRights = {}
@@ -29,6 +67,7 @@ addEventHandler("onResourceStart",resourceRoot,
29
67
outputServerLog (" - " .. missingRight )
30
68
end
31
69
outputServerLog (" Please give the irc resource these rights or it will not work properly!" )
70
+ return
32
71
end
33
72
else
34
73
outputServerLog (" IRC: could not start resource, the rights file can't be loaded!" )
@@ -60,37 +99,6 @@ addEventHandler("onResourceStart",resourceRoot,
60
99
end
61
100
end
62
101
63
- -- Parse functions file.
64
- local functionsFile = fileOpen (" scripts/functions.txt" ,true )
65
- if functionsFile then
66
- for i ,line in ipairs (split (fileRead (functionsFile ,fileGetSize (functionsFile )),44 )) do
67
- if gettok (line ,1 ,21 ) ~= " --" then
68
- local functionName = gettok (line ,2 ,32 )
69
- _G [(functionName )] = function (...)
70
- local args = {... }
71
- for i ,arg in ipairs (args ) do
72
- local expectedArgType = gettok (line ,(2 + i ),32 )
73
- if expectedArgType and type (arg ) ~= expectedArgType and not (expectedArgType or string.find (expectedArgType ," )" )) then
74
- outputServerLog (" IRC: Bad argument #" .. i .. " @ '" .. gettok (line ,2 ,32 ).. " ' " .. expectedArgType .. " expected, got " .. type (arg ))
75
- return
76
- end
77
- end
78
- if _G [(" func_" .. functionName )] then
79
- return _G [(" func_" .. functionName )](... )
80
- else
81
- outputServerLog (" Function '" .. functionName .. " ' does not exist" )
82
- return false
83
- end
84
- end
85
- end
86
- end
87
- fileClose (functionsFile )
88
- else
89
- outputServerLog (" IRC: could not start resource, the functions file can't be loaded!" )
90
- outputServerLog (" IRC: restart the resource to retry" )
91
- return
92
- end
93
-
94
102
-- parse acl file
95
103
local aclFile = xmlLoadFile (" acl.xml" )
96
104
if aclFile then
@@ -108,21 +116,6 @@ addEventHandler("onResourceStart",resourceRoot,
108
116
outputServerLog (" IRC: restart the resource to retry" )
109
117
return
110
118
end
111
-
112
- -- Is the sockets module loaded?
113
- if not sockOpen then
114
- outputServerLog (" IRC: could not start resource, the sockets module isn't loaded!" )
115
- outputServerLog (" IRC: restart the resource to retry" )
116
- return
117
- end
118
-
119
- -- start irc addons
120
- for i ,resource in ipairs (getResources ()) do
121
- local info = getResourceInfo (resource ," addon" )
122
- if info and info == " irc" then
123
- startResource (resource )
124
- end
125
- end
126
119
127
120
triggerEvent (" onIRCResourceStart" ,root )
128
121
internalConnect ()
@@ -131,7 +124,7 @@ addEventHandler("onResourceStart",resourceRoot,
131
124
132
125
addEventHandler (" onResourceStop" ,resourceRoot ,
133
126
function ()
134
- for i ,server in ipairs (ircGetServers ()) do
127
+ for i ,server in ipairs (ircGetServers () or {} ) do
135
128
ircDisconnect (server ," resource stopped" )
136
129
end
137
130
servers = {}
0 commit comments