Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bots and statuspage fixes #178

Merged
merged 10 commits into from
Apr 1, 2024
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ bundle-server:
mv fgcom-mumble-server-$(SERVER_VER)/statuspage/Readme.statuspage.md fgcom-mumble-server-$(SERVER_VER)
cp server/Readme.server-de_DE.md fgcom-mumble-server-$(SERVER_VER)/
cp server/fgcom-botmanager.sh server/*.bot.lua fgcom-mumble-server-$(SERVER_VER)
sed '/^\s\+gitver/s/""/"$(GITVER) $(GITDATE)"/' server/sharedFunctions.inc.lua > fgcom-mumble-server-$(SERVER_VER)/sharedFunctions.inc.lua
sed '/^\s\+gitver/s/""/"$(GITVER) $(GITDATE)"/' server/fgcom-sharedFunctions.inc.lua > fgcom-mumble-server-$(SERVER_VER)/fgcom-sharedFunctions.inc.lua
zip -r fgcom-mumble-server-$(SERVER_VER).zip fgcom-mumble-server-$(SERVER_VER)
rm -rf fgcom-mumble-server-$(SERVER_VER)

Expand Down
2 changes: 1 addition & 1 deletion server/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION: 1.1.4
VERSION: 1.2.0
5 changes: 3 additions & 2 deletions server/fgcom-radio-playback.bot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ The bot is depending on lua-mumble from bkacjios (https://github.com/bkacjios/l
Installation of this plugin is described in the projects readme: https://github.com/bkacjios/lua-mumble/blob/master/README.md

]]
dofile("sharedFunctions.inc.lua") -- include shared functions
dofile("fgcom-sharedFunctions.inc.lua") -- include shared functions
fgcom.botversion = "1.8.1"

-- init random generator using /dev/random, if poosible (=linux)
Expand Down Expand Up @@ -253,7 +253,8 @@ end


-- Connect to server, so we get the API
fgcom.log(botname..": connecting as '"..fgcom.callsign.."' to "..host.." on port "..port.." (cert: "..cert.."; key: "..key.."), joining: '"..fgcom.channel.."'")
fgcom.log(botname..": "..fgcom.getVersion())
fgcom.log("connecting as '"..fgcom.callsign.."' to "..host.." on port "..port.." (cert: "..cert.."; key: "..key.."), joining: '"..fgcom.channel.."'")
local client = assert(mumble.connect(host, port, cert, key))
client:auth(fgcom.callsign)
fgcom.dbg("connect and bind: OK")
Expand Down
10 changes: 7 additions & 3 deletions server/fgcom-radio-recorder.bot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ Installation of this plugin is described in the projects readme: https://github.

]]

dofile("sharedFunctions.inc.lua") -- include shared functions
fgcom.botversion = "1.8.1"
dofile("fgcom-sharedFunctions.inc.lua") -- include shared functions
fgcom.botversion = "1.8.2"
local botname = "FGCOM-Recorder"
fgcom.callsign = "FGCOM-REC"
local voiceBuffer = Queue:new()
Expand Down Expand Up @@ -125,7 +125,8 @@ end


-- Connect to server, so we get the API
fgcom.log(botname..": connecting as '"..fgcom.callsign.."' to "..host.." on port "..port.." (cert: "..cert.."; key: "..key.."), joining: '"..fgcom.channel.."'")
fgcom.log(botname..": "..fgcom.getVersion())
fgcom.log("connecting as '"..fgcom.callsign.."' to "..host.." on port "..port.." (cert: "..cert.."; key: "..key.."), joining: '"..fgcom.channel.."'")
local client = assert(mumble.connect(host, port, cert, key))
client:auth(botname)
fgcom.log("connect and bind: OK")
Expand Down Expand Up @@ -285,6 +286,9 @@ client:hook("OnPluginData", function(client, event)

-- clean up stale entries
fgcom.data.cleanupPluginData()

-- check for missing data and ask for it if neccesary
local missing_data = fgcom.data.checkMissingPluginData(client);

end)

Expand Down
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 @@ -308,15 +308,19 @@ fgcom = {
end

-- check if we already know this clients identity with given iid; if not, add template
if not fgcom_clients[sid][iid] then
if fgcom_clients[sid][iid] then
if fgcom.hooks.parsePluginData_updateKnownClient ~= nil then fgcom.hooks.parsePluginData_updateKnownClient(sid, iid) end
else
fgcom_clients[sid][iid] = {
callsign="",
lat="",
lon="",
alt="",
radios={},
lastUpdate=0
lastUpdate=0,
missingDataSince=0 -- 0: need to check; >0: missing-timestamp; -1: verified ok
}
if fgcom.hooks.parsePluginData_newClient ~= nil then fgcom.hooks.parsePluginData_newClient(sid, iid) end
end

-- record that we had an data update
Expand Down Expand Up @@ -369,6 +373,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,11 +384,16 @@ 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
-- ignore for now
end

fgcom.dbg("Packet fully processed.")
if fgcom.hooks.parsePluginData_processedPacket ~= nil then fgcom.hooks.parsePluginData_processedPacket(sender, packtype, dataID_t) end
end

fgcom.dbg("Parsing done. New remote state:")
Expand All @@ -398,6 +409,9 @@ fgcom = {
fgcom.dbg("sid="..uid.."; idty="..iid.." radio #"..radio_id.." pwr='"..radio.power.."'")
fgcom.dbg("sid="..uid.."; idty="..iid.." radio #"..radio_id.." opr='"..radio.operable.."'")
end
elseif k == "lastUpdate" then
local last_updated_since = os.time() - v
fgcom.dbg("sid="..uid.."; idty="..iid.."\t"..k..":\t"..tostring(v).." ("..last_updated_since.."s ago)")
else
fgcom.dbg("sid="..uid.."; idty="..iid.."\t"..k..":\t"..tostring(v))
end
Expand All @@ -416,10 +430,74 @@ fgcom = {
local stale_since = os.time() - idty.lastUpdate
if stale_since > fgcom.data.cleanupTimeout then
fgcom.dbg("cleanup remote data: sid="..uid.."; idty="..iid.." stale_since="..stale_since)
fgcom_clients[uid][iid] = nil;
local process = true
if fgcom.hooks.cleanupPluginData_entry ~= nil then process=fgcom.hooks.cleanupPluginData_entry(uid, iid) end

if process then fgcom_clients[uid][iid] = nil end
end
end
end
end,

-- Check if data is missing for an extended period of time, and ask for more.
-- You can "just check" without asking if supplying nil as client param.
-- @param mumble.client instance. If nil, no sending for the ask package is performed.
-- @param int (optional) timeout in secs, after which to ask for data.
-- @return array with missing data: ({ {sid=n, iid=n, missing_data={list, of, missing, data, field, names}}, {...} })
checkMissingPluginData = function(client, askForMissingDataAfter)
askForMissingDataAfter = askForMissingDataAfter or 30
local missing_data_return = {}

local allUsers = {} -- sid=>mumbleUser table
if client then
for i, mc in ipairs(client:getUsers()) do allUsers[mc:getSession()] = mc end
end

for sid,remote_client in pairs(fgcom_clients) do
for iid,idty in pairs(remote_client) do
fgcom.dbg("checking for missing fgcom.clients data: sid="..sid.."; idty="..iid.."...")
if idty.missingDataSince == -1 then
-- no further checks needed (-1)
fgcom.dbg(" all data already complete")
else
-- see if data is missing
local missing_data = {}
if idty.callsign == "" then table.insert(missing_data, "callsign") end
if idty.lat == "" then table.insert(missing_data, "lat") end
if idty.lon == "" then table.insert(missing_data, "lon") end
if idty.alt == "" then table.insert(missing_data, "alt") end

if #missing_data == 0 then
-- all needed data there, mark identity as finally checked
fgcom.dbg(" all data is now complete, no further checks needed")
idty.missingDataSince = -1
else
-- we really still miss data. See if we already need to ask.
if idty.missingDataSince == 0 then
-- first check, store timestamp for later checks
fgcom.dbg(" missing data ("..table.concat(missing_data, ", ").."), marking for further checks")
idty.missingDataSince = os.time()
else
-- consecutive checks, see if timeout exceeded
local missing_since = os.time() - idty.missingDataSince
fgcom.dbg(" missing data ("..table.concat(missing_data, ", ").."), since "..missing_since.."s")
if client and askForMissingDataAfter > 0 and missing_since > askForMissingDataAfter then
fgcom.dbg(" data missing for too long; asking sid="..sid.." for data")
client:sendPluginData("FGCOM:ICANHAZDATAPLZ", "orly!", {allUsers[sid]})
for iid,idty in pairs(remote_client) do
idty.missingDataSince = 0 -- mark for checking again
end
end
end

-- add data to return structure
table.insert(missing_data_return, {sid=sid, iid=iid, missing=missing_data})
end

end
end
end
return missing_data_return
end
},

Expand Down Expand Up @@ -476,6 +554,27 @@ 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

-- fgcom.hooks.parsePluginData_newClient(sid, iid)
-- called when parsePluginData() detected that the client was not seen before.
-- is called before any datas is parsed/added.

-- fgcom.hooks.parsePluginData_updateKnownClient(sid, iid)
-- called when parsePluginData() detected that the client was known.
-- is called before any datas is parsed/updated.

-- fgcom.hooks.parsePluginData_processedPacket(mumble_user, packtype, dataID_t)
-- called after processing the packet, passing raw data

-- fgcom.hooks.cleanupPluginData_entry(sid, iid)
-- called when cleaning up an entry. return false to prevent the entry to be cleaned out.
}
}

Expand Down
Loading
Loading