mirror of
https://github.com/DaKerboul/perun.git
synced 2026-08-09 18:05:40 +02:00
@@ -9,13 +9,14 @@
|
|||||||
|
|
||||||
Perun.RefreshStatus = 15 -- base refresh rate in seconds to send status update (values lower than 60 may affect performance!)
|
Perun.RefreshStatus = 15 -- base refresh rate in seconds to send status update (values lower than 60 may affect performance!)
|
||||||
Perun.RefreshMission = 60 -- refresh rate in seconds to send mission information (values lower than 60 may affect performance!)
|
Perun.RefreshMission = 60 -- refresh rate in seconds to send mission information (values lower than 60 may affect performance!)
|
||||||
Perun.JsonStatusLocation = "Scripts\\Json\\" -- relatve do user's SaveGames DCS folder -> status file updated each RefreshMission
|
Perun.JsonStatusLocation = "Scripts\\Json\\" -- folder relative do user's SaveGames DCS folder -> status file updated each RefreshMission
|
||||||
Perun.UDPTargetPort = 48620 -- UDP port to send data to
|
Perun.UDPTargetPort = 48620 -- UDP port to send data to
|
||||||
Perun.MOTD_L1 = "Witamy na serwerze Gildia.org !" -- Message send to players connecting the server - Line 1
|
Perun.MOTD_L1 = "Witamy na serwerze Gildia.org !" -- Message send to players connecting the server - Line 1
|
||||||
Perun.MOTD_L2 = "Wymagamy obecnosci na 255Mhz (DCS SRS)" -- Message send to players connecting the server - Line 2
|
Perun.MOTD_L2 = "Wymagamy obecnosci na 255Mhz (DCS SRS)" -- Message send to players connecting the server - Line 2
|
||||||
|
|
||||||
-- ########### END OF SETTINGS ###########
|
-- ########### END OF SETTINGS ###########
|
||||||
|
|
||||||
|
|
||||||
-- Variable init
|
-- Variable init
|
||||||
Perun.Version = "v0.3.7"
|
Perun.Version = "v0.3.7"
|
||||||
Perun.StatusData = {}
|
Perun.StatusData = {}
|
||||||
@@ -27,14 +28,104 @@
|
|||||||
Perun.lastSentMission =0
|
Perun.lastSentMission =0
|
||||||
Perun.JsonStatusLocation = lfs.writedir() .. Perun.JsonStatusLocation
|
Perun.JsonStatusLocation = lfs.writedir() .. Perun.JsonStatusLocation
|
||||||
Perun.socket = require("socket")
|
Perun.socket = require("socket")
|
||||||
|
|
||||||
Perun.UDP = assert(Perun.socket.udp())
|
Perun.UDP = assert(Perun.socket.udp())
|
||||||
Perun.UDP:settimeout(0)
|
Perun.UDP:settimeout(0)
|
||||||
Perun.UDP:setsockname("*", 48621)
|
Perun.UDP:setsockname("*", 48621)
|
||||||
Perun.UDP:setpeername("127.0.0.1",Perun.UDPTargetPort)
|
Perun.UDP:setpeername("127.0.0.1",Perun.UDPTargetPort)
|
||||||
|
|
||||||
-- Function definition
|
-- ########### Helper function definitions ###########
|
||||||
|
function stripChars(str)
|
||||||
|
-- remove accents characters from string
|
||||||
|
-- via https://stackoverflow.com/questions/50459102/replace-accented-characters-in-string-to-standard-with-lua TBD: rewrite
|
||||||
|
tableAccents = {}
|
||||||
|
tableAccents["à"] = "a"
|
||||||
|
tableAccents["á"] = "a"
|
||||||
|
tableAccents["â"] = "a"
|
||||||
|
tableAccents["ã"] = "a"
|
||||||
|
tableAccents["ä"] = "a"
|
||||||
|
tableAccents["ç"] = "c"
|
||||||
|
tableAccents["è"] = "e"
|
||||||
|
tableAccents["é"] = "e"
|
||||||
|
tableAccents["ê"] = "e"
|
||||||
|
tableAccents["ë"] = "e"
|
||||||
|
tableAccents["ì"] = "i"
|
||||||
|
tableAccents["í"] = "i"
|
||||||
|
tableAccents["î"] = "i"
|
||||||
|
tableAccents["ï"] = "i"
|
||||||
|
tableAccents["ñ"] = "n"
|
||||||
|
tableAccents["ò"] = "o"
|
||||||
|
tableAccents["ó"] = "o"
|
||||||
|
tableAccents["ô"] = "o"
|
||||||
|
tableAccents["õ"] = "o"
|
||||||
|
tableAccents["ö"] = "o"
|
||||||
|
tableAccents["ù"] = "u"
|
||||||
|
tableAccents["ú"] = "u"
|
||||||
|
tableAccents["û"] = "u"
|
||||||
|
tableAccents["ü"] = "u"
|
||||||
|
tableAccents["ý"] = "y"
|
||||||
|
tableAccents["ÿ"] = "y"
|
||||||
|
tableAccents["À"] = "A"
|
||||||
|
tableAccents["Á"] = "A"
|
||||||
|
tableAccents["Â"] = "A"
|
||||||
|
tableAccents["Ã"] = "A"
|
||||||
|
tableAccents["Ä"] = "A"
|
||||||
|
tableAccents["Ç"] = "C"
|
||||||
|
tableAccents["È"] = "E"
|
||||||
|
tableAccents["É"] = "E"
|
||||||
|
tableAccents["Ê"] = "E"
|
||||||
|
tableAccents["Ë"] = "E"
|
||||||
|
tableAccents["Ì"] = "I"
|
||||||
|
tableAccents["Í"] = "I"
|
||||||
|
tableAccents["Î"] = "I"
|
||||||
|
tableAccents["Ï"] = "I"
|
||||||
|
tableAccents["Ñ"] = "N"
|
||||||
|
tableAccents["Ò"] = "O"
|
||||||
|
tableAccents["Ó"] = "O"
|
||||||
|
tableAccents["Ô"] = "O"
|
||||||
|
tableAccents["Õ"] = "O"
|
||||||
|
tableAccents["Ö"] = "O"
|
||||||
|
tableAccents["Ù"] = "U"
|
||||||
|
tableAccents["Ú"] = "U"
|
||||||
|
tableAccents["Û"] = "U"
|
||||||
|
tableAccents["Ü"] = "U"
|
||||||
|
tableAccents["Ý"] = "Y"
|
||||||
|
|
||||||
|
-- Polish accents
|
||||||
|
tableAccents["ę"] = "e"
|
||||||
|
tableAccents["Ę"] = "Ę"
|
||||||
|
tableAccents["ó"] = "o"
|
||||||
|
tableAccents["Ó"] = "O"
|
||||||
|
tableAccents["ą"] = "a"
|
||||||
|
tableAccents["Ą"] = "A"
|
||||||
|
tableAccents["ś"] = "s"
|
||||||
|
tableAccents["Ś"] = "S"
|
||||||
|
tableAccents["ć"] = "c"
|
||||||
|
tableAccents["Ć"] = "C"
|
||||||
|
tableAccents["ż"] = "z"
|
||||||
|
tableAccents["Ż"] = "Z"
|
||||||
|
tableAccents["ź"] = "z"
|
||||||
|
tableAccents["Ź"] = "Z"
|
||||||
|
tableAccents["ł"] = "l"
|
||||||
|
tableAccents["Ł"] = "L"
|
||||||
|
|
||||||
|
-- TBD additonal characters
|
||||||
|
|
||||||
|
normalizedString = ''
|
||||||
|
|
||||||
|
for strChar in string.gmatch(str, "([%z\1-\127\194-\244][\128-\191]*)") do
|
||||||
|
if tableAccents[strChar] ~= nil then
|
||||||
|
normalizedString = normalizedString..tableAccents[strChar]
|
||||||
|
else
|
||||||
|
normalizedString = normalizedString..strChar
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return normalizedString
|
||||||
|
end
|
||||||
|
|
||||||
Perun.GetCategory = function(id)
|
Perun.GetCategory = function(id)
|
||||||
-- Helper function via https://pastebin.com/GUAXrd2U
|
-- Returns object category basing on ID
|
||||||
|
-- Helper function via https://pastebin.com/GUAXrd2U TBD: rewrite
|
||||||
local _killed_target_category = DCS.getUnitTypeAttribute(id, "category")
|
local _killed_target_category = DCS.getUnitTypeAttribute(id, "category")
|
||||||
if _killed_target_category == nil then
|
if _killed_target_category == nil then
|
||||||
local _killed_target_cat_check_ship = DCS.getUnitTypeAttribute(id, "DeckLevel")
|
local _killed_target_cat_check_ship = DCS.getUnitTypeAttribute(id, "DeckLevel")
|
||||||
@@ -51,7 +142,7 @@
|
|||||||
end
|
end
|
||||||
|
|
||||||
Perun.SideID2Name = function(id)
|
Perun.SideID2Name = function(id)
|
||||||
-- Helper function
|
-- Helper function returns side name per side (coalition) id
|
||||||
local sides = {
|
local sides = {
|
||||||
[0] = 'SPECTATOR',
|
[0] = 'SPECTATOR',
|
||||||
[1] = 'RED',
|
[1] = 'RED',
|
||||||
@@ -60,6 +151,7 @@
|
|||||||
return sides[id]
|
return sides[id]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- ########### Main code ###########
|
||||||
Perun.AddLog = function(text)
|
Perun.AddLog = function(text)
|
||||||
-- Adds logs to DCS.log file
|
-- Adds logs to DCS.log file
|
||||||
net.log("Perun : ".. text)
|
net.log("Perun : ".. text)
|
||||||
@@ -71,7 +163,7 @@
|
|||||||
TempData["1"]=Perun.ServerData
|
TempData["1"]=Perun.ServerData
|
||||||
TempData["2"]=Perun.StatusData
|
TempData["2"]=Perun.StatusData
|
||||||
TempData["3"]=Perun.SlotsData
|
TempData["3"]=Perun.SlotsData
|
||||||
-- TempData["4"]=Perun.MissionData -- TBD?
|
-- TempData["4"]=Perun.MissionData -- TBD: hangs for some large missions
|
||||||
|
|
||||||
_temp=net.lua2json(TempData)
|
_temp=net.lua2json(TempData)
|
||||||
|
|
||||||
@@ -89,6 +181,8 @@
|
|||||||
TempData["timestamp"]=os.date('%Y-%m-%d %H:%M:%S')
|
TempData["timestamp"]=os.date('%Y-%m-%d %H:%M:%S')
|
||||||
|
|
||||||
temp=net.lua2json(TempData)
|
temp=net.lua2json(TempData)
|
||||||
|
temp=stripChars(temp)
|
||||||
|
|
||||||
Perun.UDP:send(temp)
|
Perun.UDP:send(temp)
|
||||||
Perun.AddLog("Packet send")
|
Perun.AddLog("Packet send")
|
||||||
end
|
end
|
||||||
@@ -114,7 +208,7 @@
|
|||||||
-- Send
|
-- Send
|
||||||
Perun.Send(1,Perun.ServerData)
|
Perun.Send(1,Perun.ServerData)
|
||||||
|
|
||||||
-- Update all subsections
|
-- Status data - update all subsections
|
||||||
-- 1 - Mission
|
-- 1 - Mission
|
||||||
temp={}
|
temp={}
|
||||||
temp['name']=DCS.getMissionName()
|
temp['name']=DCS.getMissionName()
|
||||||
@@ -151,8 +245,6 @@
|
|||||||
|
|
||||||
Perun.UpdateMission = function()
|
Perun.UpdateMission = function()
|
||||||
-- Main function for mission information updates
|
-- Main function for mission information updates
|
||||||
|
|
||||||
-- Update Mission data
|
|
||||||
Perun.MissionData=DCS.getCurrentMission()
|
Perun.MissionData=DCS.getCurrentMission()
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -161,7 +253,7 @@
|
|||||||
|
|
||||||
data={}
|
data={}
|
||||||
data['player']= net.get_player_info(playerID, "name")
|
data['player']= net.get_player_info(playerID, "name")
|
||||||
data['msg']=msg
|
data['msg']=stripChars(msg)
|
||||||
data['all']=all
|
data['all']=all
|
||||||
data['ucid']=net.get_player_info(playerID, 'ucid')
|
data['ucid']=net.get_player_info(playerID, 'ucid')
|
||||||
data['datetime']=os.date('%Y-%m-%d %H:%M:%S')
|
data['datetime']=os.date('%Y-%m-%d %H:%M:%S')
|
||||||
@@ -218,7 +310,7 @@
|
|||||||
Perun.Send(53,data)
|
Perun.Send(53,data)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Event callbacks
|
--- ########### Event callbacks ###########
|
||||||
|
|
||||||
Perun.onSimulationStart = function()
|
Perun.onSimulationStart = function()
|
||||||
Perun.MissionHash=DCS.getMissionName( ).."@"..os.date('%Y%m%d_%H%M%S');
|
Perun.MissionHash=DCS.getMissionName( ).."@"..os.date('%Y%m%d_%H%M%S');
|
||||||
@@ -372,6 +464,6 @@
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Finalize and set callbacks
|
-- ########### Finalize and set callbacks ###########
|
||||||
DCS.setUserCallbacks(Perun)
|
DCS.setUserCallbacks(Perun)
|
||||||
net.log("Loaded - Perun - VladMordock - " .. Perun.Version )
|
net.log("Loaded - Perun - VladMordock - " .. Perun.Version )
|
||||||
|
|||||||
Reference in New Issue
Block a user