Skip to content

Commit

Permalink
Server/Bots sharedFunctions lib hooks support
Browse files Browse the repository at this point in the history
The lua shared functions lib now supports calling a hook
for when plugin data was parsed.
A bot now can hook custom code into parsePluginData()
by supplying fgcom.hooks.parsePluginData_afterParseIID = function(sid, iid)
  • Loading branch information
hbeni committed Mar 6, 2024
1 parent 428ce25 commit 80f70e6
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion server/sharedFunctions.inc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ end
-- FGCom functions
fgcom = {
botversion = "unknown",
libversion = "1.7.0",
libversion = "1.8.0",
gitver = "", -- will be set from makefile when bundling
channel = "fgcom-mumble",
callsign = "FGCOM-someUnknownBot",
Expand Down Expand Up @@ -369,6 +369,8 @@ fgcom = {
fgcom.dbg("parsing field failed! "..#field.." tokens seen")
end
end

if fgcom.hooks.parsePluginData_afterParseIID ~= nil then fgcom.hooks.parsePluginData_afterParseIID(sid, iid) end

elseif packtype == "PING" then
-- update the contained identites lastUpdate timestamps
Expand All @@ -378,6 +380,8 @@ fgcom = {
if fgcom_clients[sid][iid] then
fgcom_clients[sid][iid].lastUpdate = os.time()
end

if fgcom.hooks.parsePluginData_afterParseIID ~= nil then fgcom.hooks.parsePluginData_afterParseIID(sid, iid) end
end

elseif packtype == "ICANHAZDATAPLZ" then
Expand Down Expand Up @@ -476,6 +480,13 @@ fgcom = {
end
return fgcom.auth.isAuthenticated(user)
end,
},

-- Various hooks, bots can implement to have event based adjustment options.
-- If they are not defined, they will not be called.
hooks = {
-- parsePluginData_afterParseIID(sid, iid)
-- called when parsePluginData() received data for a given iid
}
}

Expand Down

0 comments on commit 80f70e6

Please sign in to comment.