Lua changes to match frame id updates

This commit is contained in:
VladMordock
2021-02-18 18:52:06 +01:00
parent ac029e1d30
commit 8a97ff84f8
2 changed files with 76 additions and 66 deletions

View File

@@ -7,7 +7,6 @@ PerunConfig.TCPPerunHost = "localhost" -- (string) [default: "l
PerunConfig.TCPTargetPort = 48621 -- (int) [default: 48621] TCP port to send data to PerunConfig.TCPTargetPort = 48621 -- (int) [default: 48621] TCP port to send data to
PerunConfig.Instance = 1 -- (int) [default: 1] Id number of instance (if multiple DCS instances are to run at the same PC) PerunConfig.Instance = 1 -- (int) [default: 1] Id number of instance (if multiple DCS instances are to run at the same PC)
PerunConfig.RefreshStatus = 60 -- (int) [default: 60] Base refresh rate in seconds to send status update PerunConfig.RefreshStatus = 60 -- (int) [default: 60] Base refresh rate in seconds to send status update
PerunConfig.RefreshMission = 120 -- (int) [default: 120] Refresh rate in seconds to send mission information
PerunConfig.MissionStartNoDeathWindow = 300 -- (int) [default: 300] Number of secounds after mission start when death of the pilot will not go to statistics, shall avoid death penalty during spawning DCS bugs PerunConfig.MissionStartNoDeathWindow = 300 -- (int) [default: 300] Number of secounds after mission start when death of the pilot will not go to statistics, shall avoid death penalty during spawning DCS bugs
PerunConfig.DebugMode = 2 -- (int) [0 (default),1,2] Value greater than 0 will display Perun information in DCS log file, values: 1 - minimal verbose, 2 - all log information will be logged PerunConfig.DebugMode = 2 -- (int) [0 (default),1,2] Value greater than 0 will display Perun information in DCS log file, values: 1 - minimal verbose, 2 - all log information will be logged
PerunConfig.MOTD_L1 = "[Perun] Welcome to our server !" -- (string) Message send to players connecting the server - Line 1 PerunConfig.MOTD_L1 = "[Perun] Welcome to our server !" -- (string) Message send to players connecting the server - Line 1

View File

@@ -11,7 +11,6 @@ package.cpath = package.cpath..";"..lfs.currentdir().."/LuaSocket/?.dll"
-- Load config file -- Load config file
local PerunConfig = require "perun_config" local PerunConfig = require "perun_config"
Perun.RefreshStatus = PerunConfig.RefreshStatus Perun.RefreshStatus = PerunConfig.RefreshStatus
Perun.RefreshMission = PerunConfig.RefreshMission
Perun.TCPTargetPort = PerunConfig.TCPTargetPort Perun.TCPTargetPort = PerunConfig.TCPTargetPort
Perun.TCPPerunHost = PerunConfig.TCPPerunHost Perun.TCPPerunHost = PerunConfig.TCPPerunHost
Perun.Instance = PerunConfig.Instance Perun.Instance = PerunConfig.Instance
@@ -26,7 +25,6 @@ Perun.Version = "v0.12.0"
Perun.StatusData = {} Perun.StatusData = {}
Perun.SlotsData = {} Perun.SlotsData = {}
Perun.MissionData = {} Perun.MissionData = {}
Perun.ServerData = {}
Perun.StatData = {} Perun.StatData = {}
Perun.StatDataLastType = {} Perun.StatDataLastType = {}
Perun.PlayersTableCache = {} Perun.PlayersTableCache = {}
@@ -42,6 +40,7 @@ Perun.lastReconnect = (-1) * Perun.ReconnectTimeout
Perun.SendRetries = 2 Perun.SendRetries = 2
Perun.RefreshKeepAlive = 3 Perun.RefreshKeepAlive = 3
Perun.FrameTime = 0; Perun.FrameTime = 0;
Perun.socket = require("socket") Perun.socket = require("socket")
Perun.IsServer = DCS.isServer( ) Perun.IsServer = DCS.isServer( )
@@ -246,6 +245,8 @@ Perun.ConnectToPerun = function ()
else else
-- Connected -- Connected
Perun.AddLog("Success - connected to TCP server",2) Perun.AddLog("Success - connected to TCP server",2)
Perun.lastSentMission = 0 -- TBD - reset so mission information will be send after connection is back
end end
Perun.lastReconnect = DCS.getRealTime() Perun.lastReconnect = DCS.getRealTime()
end end
@@ -281,14 +282,15 @@ Perun.SendToPerun = function(data_id, data_package)
if _err then if _err then
-- Failure, packet was not send -- Failure, packet was not send
_delay = (DCS.getRealTime() - _now) * 1000000 _delay = (DCS.getRealTime() - _now) * 1000000
Perun.AddLog("Packed not send : " .. data_id .. " , error: " .. _err .. ", tries: " .. _intTries .. ", delay: " .. _delay .. "us" .. ", lua2json: " .. _delay_lua2json .. "us",2) Perun.AddLog("Packed not send : " .. data_id .. " , error: " .. _err .. ", tries: " .. _intTries .. ", tcp delay: " .. _delay .. "us" .. ", lua2json delay: " .. _delay_lua2json .. "us",2)
if _now > Perun.lastReconnect + Perun.ReconnectTimeout then if _now > Perun.lastReconnect + Perun.ReconnectTimeout then
Perun.ConnectToPerun() Perun.ConnectToPerun()
end end
else else
-- Succes, packet was send -- Succes, packet was send
_delay = (DCS.getRealTime() - _now) * 1000000 _delay = (DCS.getRealTime() - _now) * 1000000
Perun.AddLog("Packet send : " .. data_id .. " , tries:" .. _intTries .. ", delay: " .. _delay .. "us" .. ", lua2json: " .. _delay_lua2json .. "us",2) Perun.AddLog("Packet send : " .. data_id .. " , tries:" .. _intTries .. ", tcp delay: " .. _delay .. "us" .. ", lua2json delay: " .. _delay_lua2json .. "us",2)
Perun.lastSentKeepAlive = _now -- reset keep alive counter, reduce traffic
_dropped = false _dropped = false
end end
_intTries=_intTries+1 _intTries=_intTries+1
@@ -297,7 +299,8 @@ Perun.SendToPerun = function(data_id, data_package)
if _dropped == true then if _dropped == true then
-- Add information to log file and send chat message to all that Perun connection is broken -- Add information to log file and send chat message to all that Perun connection is broken
_delay = (DCS.getRealTime() - _now) * 1000000 _delay = (DCS.getRealTime() - _now) * 1000000
Perun.AddLog("ERROR - packed dropped : " .. data_id .. ", delay: " .. _delay .. "us" .. ", lua2json: " .. _delay_lua2json .. "us",1)
Perun.AddLog("ERROR - packed dropped : " .. data_id .. ", tcp delay: " .. _delay .. "us" .. ", lua2json delay: " .. _delay_lua2json .. "us",1)
if _now > Perun.lastConnectionError + Perun.ReconnectTimeout then if _now > Perun.lastConnectionError + Perun.ReconnectTimeout then
-- Informs all players that there is Peron error; below hack for DCS net.send_chat not working -- Informs all players that there is Peron error; below hack for DCS net.send_chat not working
local _all_players = net.get_player_list() local _all_players = net.get_player_list()
@@ -549,87 +552,96 @@ Perun.LogStatsGet = function(playerID)
end end
Perun.UpdateStatus = function() Perun.UpdateStatus = function()
-- Main function for status updates -- Main function for status updates
-- Diagnostic data local _now = DCS.getRealTime()
-- Diagnostic data
-- Update version data -- Update version data
local _now = DCS.getRealTime() local _ServerData={}
Perun.ServerData['v_dcs_hook']=Perun.Version _ServerData['v_dcs_hook']=Perun.Version
-- Update clients data - count connected players -- Update clients data - count connected players
_playerlist=net.get_player_list() _playerlist=net.get_player_list()
_count = 0 _ServerData['c_players']=#_playerlist
for _ in pairs(_playerlist) do _count = _count + 1 end
Perun.ServerData['c_players']=_count
-- Send Perun.StatusData["server"] = _ServerData
local _delay = (DCS.getRealTime() - _now) * 1000000
Perun.AddLog("Updated server data; sending (" .. _delay .. "us)",2)
Perun.SendToPerun(1,Perun.ServerData)
-- Status data - update all subsections -- Mission data
-- 1 - Mission data local _MissionData={}
_now = DCS.getRealTime() _MissionData['name']=DCS.getMissionName()
local _TempData={} _MissionData['modeltime']=DCS.getModelTime()
_MissionData['realtime']=DCS.getRealTime()
_MissionData['pause']=DCS.getPause()
_MissionData['multiplayer']=DCS.isMultiplayer()
_MissionData['theatre'] = Perun.MissionData['mission']['theatre']
_TempData['name']=DCS.getMissionName() Perun.StatusData["mission"] = _MissionData
_TempData['modeltime']=DCS.getModelTime()
_TempData['realtime']=DCS.getRealTime()
_TempData['pause']=DCS.getPause()
_TempData['multiplayer']=DCS.isMultiplayer()
_TempData['theatre'] = Perun.MissionData['mission']['theatre']
Perun.StatusData["mission"] = _TempData
-- 2 - Players data -- Players data
_PlayersTable={} local _PlayersTable={}
for _k, _i in ipairs(_playerlist) do for _k, _i in ipairs(_playerlist) do
_PlayersTable[_k]=net.get_player_info(_i) _PlayersTable[_k]=net.get_player_info(_i)
_PlayersTable[_k]['pilotid'] = nil;
_PlayersTable[_k]['started'] = nil;
_PlayersTable[_k]['lang'] = nil;
_PlayersTable[_k]['ipaddr'] = nil;
end end
Perun.StatusData["players"] = _PlayersTable Perun.StatusData["clients"] = _PlayersTable
-- Send -- Send
_delay = (DCS.getRealTime() - _now) * 1000000 _delay = (DCS.getRealTime() - _now) * 1000000
Perun.AddLog("Updated status data; sending (" .. _delay .. "us)",2) Perun.AddLog("Updated status data; sending (" .. _delay .. "us)",2)
Perun.SendToPerun(2,Perun.StatusData) Perun.SendToPerun(1,Perun.StatusData)
end end
Perun.UpdateSlots = function() Perun.UpdateSlots = function()
-- Update and send slots data -- Update and send slots data
local _now = DCS.getRealTime() local _now = DCS.getRealTime()
Perun.SlotsData['coalitions']=DCS.getAvailableCoalitions() -- Check if we need to pull the data or we can use the stored one
Perun.SlotsData['slots']={} if Perun.SlotsData['coalitions'] == nil then
Perun.SlotsData['coalitions']=DCS.getAvailableCoalitions()
Perun.SlotsData['slots']={}
-- Build up slot table -- Build up slot table
for _j, _i in pairs(Perun.SlotsData['coalitions']) do for _j, _i in pairs(Perun.SlotsData['coalitions']) do
Perun.SlotsData['slots'][_j]=DCS.getAvailableSlots(_j) Perun.SlotsData['slots'][_j]=DCS.getAvailableSlots(_j)
for _sj, _si in pairs(Perun.SlotsData['slots'][_j]) do for _sj, _si in pairs(Perun.SlotsData['slots'][_j]) do
Perun.SlotsData['slots'][_j][_sj]['countryName']= nil Perun.SlotsData['slots'][_j][_sj]['countryName']= nil
Perun.SlotsData['slots'][_j][_sj]['onboard_num']= nil Perun.SlotsData['slots'][_j][_sj]['onboard_num']= nil
Perun.SlotsData['slots'][_j][_sj]['groupSize']= nil Perun.SlotsData['slots'][_j][_sj]['groupSize']= nil
Perun.SlotsData['slots'][_j][_sj]['groupName']= nil Perun.SlotsData['slots'][_j][_sj]['groupName']= nil
Perun.SlotsData['slots'][_j][_sj]['callsign']= nil Perun.SlotsData['slots'][_j][_sj]['callsign']= nil
Perun.SlotsData['slots'][_j][_sj]['task']= nil Perun.SlotsData['slots'][_j][_sj]['task']= nil
Perun.SlotsData['slots'][_j][_sj]['airdromeId']= nil Perun.SlotsData['slots'][_j][_sj]['airdromeId']= nil
Perun.SlotsData['slots'][_j][_sj]['helipadName']= nil Perun.SlotsData['slots'][_j][_sj]['helipadName']= nil
Perun.SlotsData['slots'][_j][_sj]['multicrew_place']= nil
Perun.SlotsData['slots'][_j][_sj]['role']= nil
Perun.SlotsData['slots'][_j][_sj]['helipadUnitType']= nil
Perun.SlotsData['slots'][_j][_sj]['action']= nil
end
end end
end end
local _delay = (DCS.getRealTime() - _now) * 1000000 local _delay = (DCS.getRealTime() - _now) * 1000000
Perun.AddLog("Updated slots data; sending (" .. _delay .. "us)",2) Perun.AddLog("Updated slots data; sending (" .. _delay .. "us)",2)
Perun.SendToPerun(3,Perun.SlotsData) Perun.SendToPerun(2,Perun.SlotsData)
end end
Perun.UpdateMission = function() Perun.UpdateMission = function()
-- Main function for mission information updates -- Main function for mission information updates
local _now = DCS.getRealTime() local _now = DCS.getRealTime()
-- Get mission information -- Check if we need to get mission data
Perun.MissionData=DCS.getCurrentMission() if Perun.MissionData['mission'] == nil then
-- Get mission information
Perun.MissionData=DCS.getCurrentMission()
end
local _delay = (DCS.getRealTime() - _now) * 1000000 local _delay = (DCS.getRealTime() - _now) * 1000000
Perun.AddLog("Mission data updated; saved (" .. _delay .. "us)",2) Perun.AddLog("Updated mission data; sending (" .. _delay .. "us)",2)
Perun.SendToPerun(3,Perun.MissionData)
end end
--- ################################ Event callbacks ################################ --- ################################ Event callbacks ################################
@@ -641,21 +653,26 @@ Perun.onSimulationStart = function()
Perun.StatData = {} Perun.StatData = {}
Perun.StatDataLastType = {} Perun.StatDataLastType = {}
Perun.PlayersTableCache = {} Perun.PlayersTableCache = {}
Perun.SlotsData = {}
Perun.MissionData = {}
Perun.lastSentMission = 0 -- reset so mission information will be send
end end
Perun.onSimulationStop = function() Perun.onSimulationStop = function()
-- Simulation was stopped -- Simulation was stopped
Perun.LogEvent("SimStop","Mission " .. Perun.MissionHash .. " finished",nil,nil); Perun.LogEvent("SimStop","Mission " .. Perun.MissionHash .. " finished",nil,nil);
Perun.LogAllStats()
Perun.MissionHash=Perun.GenerateMissionHash(); Perun.MissionHash=Perun.GenerateMissionHash();
Perun.StatData = {} Perun.StatData = {}
Perun.MissionData = {}
Perun.StatDataLastType = {} Perun.StatDataLastType = {}
Perun.LogAllStats()
Perun.PlayersTableCache = {} Perun.PlayersTableCache = {}
Perun.SlotsData = {}
end end
Perun.onPlayerDisconnect = function(id, err_code) Perun.onPlayerDisconnect = function(id, err_code)
-- Player disconnected -- Player disconnected
Perun.LogEvent("disconnect", "Player " .. id .. " disconnected.(?)",nil,nil); Perun.LogEvent("disconnect", "Player " .. id .. " disconnected.",nil,nil);
return return
end end
@@ -671,28 +688,22 @@ Perun.onSimulationFrame = function()
local _now = DCS.getRealTime() local _now = DCS.getRealTime()
Perun.lastFrameStart = _now Perun.lastFrameStart = _now
-- First run -- Send mission update - First run or update required (set on connection errors)
if Perun.lastSentMission == 0 and Perun.lastSentStatus == 0 then if Perun.lastSentMission == 0 then
Perun.lastSentMission = _now Perun.lastSentMission = _now
Perun.UpdateMission() Perun.UpdateMission()
Perun.UpdateSlots() Perun.UpdateSlots()
end end
-- Send mission update -- Send status update - update required
if _now > Perun.lastSentMission + Perun.RefreshMission then
Perun.lastSentMission = _now
Perun.UpdateMission()
end
-- Send status update
if _now > Perun.lastSentStatus + Perun.RefreshStatus then if _now > Perun.lastSentStatus + Perun.RefreshStatus then
Perun.lastSentStatus = _now Perun.lastSentStatus = _now
Perun.UpdateStatus() Perun.UpdateStatus()
end end
-- Send keepalive -- Send keepalive - update required
if _now > Perun.lastSentKeepAlive + Perun.RefreshKeepAlive then if _now > Perun.lastSentKeepAlive + Perun.RefreshKeepAlive then
Perun.lastSentKeepAlive = _now Perun.lastSentKeepAlive = _now