From 04633eb64d3756a898ab8cf4f47ec16fb7951aef Mon Sep 17 00:00:00 2001 From: hbeni Date: Wed, 20 Mar 2024 23:55:22 +0100 Subject: [PATCH] Server/Bots: Added version string to log output Also the test/fgcom-fakepilot bot was ammended: - now also has a version number - now utilizes fgcom.log() and .dbg() for output (giving timestamps) --- server/fgcom-radio-playback.bot.lua | 3 +- server/fgcom-radio-recorder.bot.lua | 3 +- server/statuspage/fgcom-status.bot.lua | 3 +- server/test/fgcom-fakepilot.bot.lua | 80 ++++++++++++++------------ 4 files changed, 49 insertions(+), 40 deletions(-) diff --git a/server/fgcom-radio-playback.bot.lua b/server/fgcom-radio-playback.bot.lua index 6e2dbe5..8e26769 100644 --- a/server/fgcom-radio-playback.bot.lua +++ b/server/fgcom-radio-playback.bot.lua @@ -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") diff --git a/server/fgcom-radio-recorder.bot.lua b/server/fgcom-radio-recorder.bot.lua index 941854c..4128a83 100644 --- a/server/fgcom-radio-recorder.bot.lua +++ b/server/fgcom-radio-recorder.bot.lua @@ -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") diff --git a/server/statuspage/fgcom-status.bot.lua b/server/statuspage/fgcom-status.bot.lua index 538f25d..d970858 100644 --- a/server/statuspage/fgcom-status.bot.lua +++ b/server/statuspage/fgcom-status.bot.lua @@ -99,7 +99,8 @@ if arg[1] then 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.log("connect and bind: OK") diff --git a/server/test/fgcom-fakepilot.bot.lua b/server/test/fgcom-fakepilot.bot.lua index 8d02374..2c4d815 100644 --- a/server/test/fgcom-fakepilot.bot.lua +++ b/server/test/fgcom-fakepilot.bot.lua @@ -33,6 +33,7 @@ Installation of this plugin is described in the projects readme: https://github. ]] dofile("fgcom-sharedFunctions.inc.lua") -- include shared functions +fgcom.botversion = "1.0.1" -- init random generator using /dev/random, if poosible (=linux) fgcom.rng.initialize() @@ -67,7 +68,7 @@ local sample = "recordings/fgcom.rec.testsample.fgcs" if arg[1] then if arg[1]=="-h" or arg[1]=="--help" then - print(botname) + print(botname..", "..fgcom.getVersion()) print("usage: "..arg[0].." [opt=val ...]") print(" Options:") print(" --id= id to join with (default=random)") @@ -81,6 +82,8 @@ if arg[1] then print(" --sleep= Time interval between checks (default="..sleep..")") print(" --chancet= Chance for transmission (default="..chance_transmit..")") print(" --chancee= Chance that transmit is echotest (default="..chance_echotest..")") + print(" --debug print debug messages (default=no)") + print(" --version print version and exit") os.exit(0) end @@ -97,6 +100,8 @@ if arg[1] then if k=="sleep" then sleep=tonumber(v) end if k=="chancet" then chance_transmit=tonumber(v) end if k=="chancee" then chance_echotest=tonumber(v) end + if opt == "--debug" then fgcom.debugMode = true end + if opt == "--version" then print(botname..", "..fgcom.getVersion()) os.exit(0) end end end @@ -130,7 +135,7 @@ readFGCSSampleFile = function(file) local endOfSamples = false while not endOfSamples do local nextSample = fgcom.io.readFGCSSample(sampleFH) - --print("sample: len="..nextSample.len.."; eof='"..tostring(nextSample.eof).."'; data='"..nextSample.data.."'") + --fgcom.dbg("sample: len="..nextSample.len.."; eof='"..tostring(nextSample.eof).."'; data='"..nextSample.data.."'") if nextSample.len > 0 and not nextSample.eof then vb:pushright(nextSample) -- write the sample structure to the buffer end @@ -149,36 +154,37 @@ end ----------------------------- --[[ BOT RUNTIME ]] ----------------------------- +fgcom.log(botname..": "..fgcom.getVersion()) -- read the file into the queue. lastHeader, _ = readFGCSSampleFile(sample) -if not lastHeader then print("ERROR: '"..sample.."' not readable or no FGCS file") os.exit(1) end +if not lastHeader then fgcom.log("ERROR: '"..sample.."' not readable or no FGCS file") os.exit(1) end -- AFTER THIS CODE we can be confident it was a valid FGCS file! -- lastHeader is initialized with the header data -- voiceBuffer is initialized with the read samples -print(sample..": successfully loaded.") +fgcom.log(sample..": successfully loaded.") -- Connect to server, so we get the API -print(botname..": connecting as '"..fgcom.callsign.."' to "..host.." on port "..port.." (cert: "..cert.."; key: "..key..")") +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) -print("connect and bind: OK") +fgcom.dbg("connect and bind: OK") -- function to get all channel users -- this updates the global playback_target table updateAllChannelUsersforSend = function(cl) - --print("udpate channelusers") + --fgcom.dbg("udpate channelusers") local ch = cl:getChannel(fgcom.channel) local users = ch:getUsers() playback_targets = {} - --print("ok: "..ch:getName()) + --fgcom.dbg("ok: "..ch:getName()) for k,v in pairs(users) do - --print(" k",k,"v=",v) + --fgcom.dbg(" k",k,"v=",v) table.insert(playback_targets, v) end end @@ -192,26 +198,26 @@ end local playbackTimer = mumble.timer() local freq = testfrequencies[1] playbackTimer_func = function(t) - --print("playback timer: tick; ptt=",ptt) + --fgcom.dbg("playback timer: tick; ptt=",ptt) -- So, a new timer tick started. if ptt then -- PTT is active: setup voice buffer and radio (if not done already) if voiceBuffer:size() <= 0 then - print("fgcom.callsign.. Starting new transmission...") + fgcom.log(fgcom.callsign.." Starting new transmission...") -- fill temporary buffer lastHeader, voiceBuffer = readFGCSSampleFile(sample) - if not lastHeader then print("ERROR: '"..sample.."' not readable or no FGCS file") os.exit(1) else print(sample..": successfully refreshed ("..voiceBuffer:size().." samples)") end + if not lastHeader then fgcom.log("ERROR: '"..sample.."' not readable or no FGCS file") os.exit(1) else fgcom.dbg(sample..": successfully refreshed ("..voiceBuffer:size().." samples)") end -- choose a random frequency freq = testfrequencies[math.random(1,#testfrequencies)] local ce = tonumber(math.random(0, 100)/100) if ce < chance_echotest then freq = "910.00" - print(" (Echotest transmission @"..freq..")") + fgcom.log(" (Echotest transmission @"..freq..")") else - print(" (Normal transmission @"..freq..")") + fgcom.log(" (Normal transmission @"..freq..")") end -- Broadcast radio @@ -221,31 +227,31 @@ playbackTimer_func = function(t) ..",CHN="..freq ..",PWR=10" ..",PTT=1" - print(fgcom.callsign.." Bot sets radio: "..msg) + fgcom.dbg(fgcom.callsign.." Bot sets radio: "..msg) client:sendPluginData("FGCOM:UPD_COM:0:0", msg, playback_targets) end end -- Play the samples, then stop transmission. if voiceBuffer:size() > 0 then - --print("voiceBuffer is still filled, samples: "..voiceBuffer:size()) + --fgcom.dbg("voiceBuffer is still filled, samples: "..voiceBuffer:size()) -- get the next sample from the buffer and play it local nextSample = voiceBuffer:popleft() local endofStream = false if voiceBuffer:size() == 0 then endofStream = true end - print("transmit next sample @"..freq) - --print(" tgt="..playback_target:getSession()) - print(" eos="..tostring(endofStream)) - print(" cdc="..lastHeader.voicecodec) - print(" dta="..#nextSample.data) - --print(" dta="..nextSample.data) + fgcom.dbg("transmit next sample @"..freq) + --fgcom.dbg(" tgt="..playback_target:getSession()) + fgcom.dbg(" eos="..tostring(endofStream)) + fgcom.dbg(" cdc="..lastHeader.voicecodec) + fgcom.dbg(" dta="..#nextSample.data) + --fgcom.dbg(" dta="..nextSample.data) client:transmit(lastHeader.voicecodec, nextSample.data, not endofStream) -- Transmit the single frame as an audio packet (the bot "speaks") - print(" transmit ok") + fgcom.dbg(" transmit ok") if endofStream then -- no samples left? Just loop around to trigger all the checks - print(fgcom.callsign.." no samples left, playback complete") + fgcom.dbg(fgcom.callsign.." no samples left, playback complete") ptt = false; @@ -256,19 +262,19 @@ playbackTimer_func = function(t) ..",CHN="..freq ..",PWR=10" ..",PTT=0" - print(" Bot sets radio: "..msg) + fgcom.dbg(" Bot sets radio: "..msg) client:sendPluginData("FGCOM:UPD_COM:0:0", msg, playback_targets) end t:stop() -- Stop the timer - print(fgcom.callsign.." Transmission complete.") + fgcom.log(fgcom.callsign.." Transmission complete.") end end else -- PTT is false. -- (This should never be reached, because the only place ptt is reset to false is, if the voicebuffer is empty. Somehow the timer was not stopped...) - print("ERROR: PTT=0 invalid state reached.") + fgcom.log("ERROR: PTT=0 invalid state reached.") t:stop() voiceBuffer = Queue.new() --os.exit(1) @@ -286,12 +292,12 @@ local alt = math.random(15, 8000) local latmv = math.random(-100, 100)/100000 local lonmv = math.random(-100, 100)/100000 client:hook("OnServerSync", function(client, event) - print("Sync done; server greeted with: ", event.welcome_text) + fgcom.log("Sync done; server greeted with: ", event.welcome_text) -- try to join fgcom-mumble channel local ch = client:getChannel(fgcom.channel) event.user:move(ch) - print(fgcom.callsign.." joined channel "..fgcom.channel) + fgcom.log(fgcom.callsign.." joined channel "..fgcom.channel) updateAllChannelUsersforSend(client) local msg = "CALLSIGN="..fgcom.callsign @@ -299,7 +305,7 @@ client:hook("OnServerSync", function(client, event) -- update location locUpd:start(function(t) - --print("locUpd: tick") + --fgcom.dbg("locUpd: tick") -- update current users of channel updateAllChannelUsersforSend(client) if #playback_targets > 0 then @@ -311,7 +317,7 @@ client:hook("OnServerSync", function(client, event) local msg = "LON="..lat ..",LAT="..lon ..",ALT="..alt - --print("Bot sets location: "..msg) + --fgcom.dbg("Bot sets location: "..msg) client:sendPluginData("FGCOM:UPD_LOC:0", msg, playback_targets) end @@ -319,16 +325,16 @@ client:hook("OnServerSync", function(client, event) -- let the pilot check every n seconds if he wants to do a transmission checkTimer:start(function(t) - --print("checkTimer: tick") + --fgcom.dbg("checkTimer: tick") local ct = math.random(0, 100)/100 if chance_transmit < ct then -- triggerTransmit, if not already transmitting if not ptt then - --print("activating PTT") + --fgcom.dbg("activating PTT") ptt = true playbackTimer:start(playbackTimer_func, 0.0, lastHeader.samplespeed) else - -- print("(not activating PTT, its still active)") + -- fgcom.dbg("(not activating PTT, its still active)") end end end, 0.00, sleep) @@ -342,11 +348,11 @@ client:hook("OnPluginData", function(client, event) --["receivers"] = { -- A table of who is receiving this data -- [1] = mumble.user, --}, - --print("OnPluginData(): DATA INCOMING FROM="..tostring(event.id)..", "..tostring(event.sender)) + --fgcom.dbg("OnPluginData(): DATA INCOMING FROM="..tostring(event.id)..", "..tostring(event.sender)) -- Answer data requests if event.id:len() > 0 and event.id:find("FGCOM:ICANHAZDATAPLZ") then - print("OnPluginData(): client asks for data: "..tostring(event.sender)) + fgcom.dbg("OnPluginData(): client asks for data: "..tostring(event.sender)) local msg = "CALLSIGN="..fgcom.callsign client:sendPluginData("FGCOM:UPD_USR:0", msg, {event.sender}) @@ -370,4 +376,4 @@ end) mumble.loop() -print(botname.." with callsign "..fgcom.callsign.." completed.") +fgcom.log(botname.." with callsign "..fgcom.callsign.." completed.")