mirror of
https://github.com/DaKerboul/perun.git
synced 2026-08-09 20:35:39 +02:00
Compare commits
47 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f7f688d1a5 | ||
|
|
81ff34014a | ||
|
|
9e0c515af0 | ||
|
|
9391d8778f | ||
|
|
1cfe5a1ea9 | ||
|
|
8d1835f6f5 | ||
|
|
3be5a8765f | ||
|
|
0f01624380 | ||
|
|
3ff2fff728 | ||
|
|
f383f3c056 | ||
|
|
69f995bd6d | ||
|
|
64a550e8e8 | ||
|
|
31ed9ee875 | ||
|
|
0722a9ca26 | ||
|
|
a21bbd4459 | ||
|
|
4ff546b105 | ||
|
|
2463d4267d | ||
|
|
6b37b05dbf | ||
|
|
d34fdf00b3 | ||
|
|
37543ec167 | ||
|
|
7dda6a224d | ||
|
|
993ae2a755 | ||
|
|
c79dc039e6 | ||
|
|
a26c9d8f08 | ||
|
|
f55a117051 | ||
|
|
e05cee514c | ||
|
|
d63c0fbfdf | ||
|
|
f49734560e | ||
|
|
5d3f7148bb | ||
|
|
2629295f93 | ||
|
|
a6ad17dbe1 | ||
|
|
b7022c22c1 | ||
|
|
907d8d01d6 | ||
|
|
fc82c43072 | ||
|
|
37b6f3419e | ||
|
|
b96affd4fd | ||
|
|
8d733f83ab | ||
|
|
58cc8a7b39 | ||
|
|
e09926aa80 | ||
|
|
13969a95cc | ||
|
|
5c9fa4e284 | ||
|
|
3512f7f5cf | ||
|
|
6847a1e262 | ||
|
|
c917d0ef04 | ||
|
|
784ad9947f | ||
|
|
91c629ed81 | ||
|
|
5d415812fa |
@@ -5,45 +5,171 @@
|
|||||||
package.path = package.path..";"..lfs.currentdir().."/LuaSocket/?.lua"
|
package.path = package.path..";"..lfs.currentdir().."/LuaSocket/?.lua"
|
||||||
package.cpath = package.cpath..";"..lfs.currentdir().."/LuaSocket/?.dll"
|
package.cpath = package.cpath..";"..lfs.currentdir().."/LuaSocket/?.dll"
|
||||||
|
|
||||||
-- ########### SETTINGS ###########
|
-- ###################### SETTINGS - DO NOT MODIFY OUTSIDE THIS SECTION #############################
|
||||||
|
|
||||||
Perun.Refresh = 15 -- base refresh rate in secounds (values lower than 60 may affect performance!)
|
Perun.RefreshStatus = 15 -- (int) base refresh rate in seconds to send status update (values lower than 60 may affect performance!)
|
||||||
Perun.JsonLocation = "Scripts\\Json\\perun_export.json" -- relatve do user's SaveGames DCS folder
|
Perun.RefreshMission = 60 -- (int) refresh rate in seconds to send mission information (values lower than 60 may affect performance!)
|
||||||
Perun.UDPTargetPort = 48620 -- UDP port to send data to
|
Perun.UDPTargetPort = 48620 -- (int) UDP port to send data to
|
||||||
Perun.MOTD_L1 = "Witamy na serwerze Gildia.org !" -- Message send to players connecting the server - Line 1
|
Perun.UDPSourcePort = 48621 -- (int) UDP port to send data from
|
||||||
Perun.MOTD_L2 = "Wymagamy obecnosci na 255Mhz (DCS SRS)" -- Message send to players connecting the server - Line 2
|
Perun.Instance = 1 -- (int) Id number of instance (if multiple DCS instances are to run at the same PC)
|
||||||
|
Perun.JsonStatusLocation = "Scripts\\Json\\" -- (string) folder relative do user's SaveGames DCS folder -> status file updated each RefreshMission
|
||||||
|
Perun.MOTD_L1 = "Witamy na serwerze Gildia.org !" -- (string) Message send to players connecting the server - Line 1
|
||||||
|
Perun.MOTD_L2 = "Wymagamy obecnosci na 255Mhz (DCS SRS)" -- (string) Message send to players connecting the server - Line 2
|
||||||
|
|
||||||
|
-- ###################### END OF SETTINGS - DO NOT MODIFY OUTSIDE THIS SECTION ######################
|
||||||
|
|
||||||
-- ########### END OF SETTINGS ###########
|
|
||||||
|
|
||||||
-- Variable init
|
-- Variable init
|
||||||
Perun.Version = "v0.3.0"
|
Perun.Version = "v0.5.0"
|
||||||
Perun.StatusData = {}
|
Perun.StatusData = {}
|
||||||
Perun.SlotsData = {}
|
Perun.SlotsData = {}
|
||||||
Perun.VersionData = {}
|
Perun.MissionData = {}
|
||||||
Perun.lastSent =0
|
Perun.ServerData = {}
|
||||||
Perun.JsonLocation = lfs.writedir() .. Perun.JsonLocation
|
Perun.StatData = {}
|
||||||
|
Perun.StatDataLastType = {}
|
||||||
|
Perun.MissionHash=""
|
||||||
|
Perun.lastSentStatus =0
|
||||||
|
Perun.lastSentMission =0
|
||||||
|
Perun.JsonStatusLocation = lfs.writedir() .. Perun.JsonStatusLocation
|
||||||
Perun.socket = require("socket")
|
Perun.socket = require("socket")
|
||||||
Perun.UDP = assert(Perun.socket.udp())
|
Perun.IsServer = true --DCS.isServer( ) -- TBD looks like DCS API error, always returning True
|
||||||
Perun.UDP:settimeout(0)
|
Perun.UDPSourcePort = Perun.UDPSourcePort + Perun.Instance - 1
|
||||||
Perun.UDP:setsockname("*", 48621)
|
|
||||||
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)
|
||||||
|
-- Returns object category basing on ID
|
||||||
|
-- Helper function via https://pastebin.com/GUAXrd2U TBD: rewrite
|
||||||
|
local _killed_target_category = DCS.getUnitTypeAttribute(id, "category")
|
||||||
|
if _killed_target_category == nil then
|
||||||
|
local _killed_target_cat_check_ship = DCS.getUnitTypeAttribute(id, "DeckLevel")
|
||||||
|
local _killed_target_cat_check_plane = DCS.getUnitTypeAttribute(id, "WingSpan")
|
||||||
|
if _killed_target_cat_check_ship ~= nil and _killed_target_cat_check_plane == nil then
|
||||||
|
_killed_target_category = "Ships"
|
||||||
|
elseif _killed_target_cat_check_ship == nil and _killed_target_cat_check_plane ~= nil then
|
||||||
|
_killed_target_category = "Planes"
|
||||||
|
else
|
||||||
|
_killed_target_category = "Helicopters"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return _killed_target_category
|
||||||
|
end
|
||||||
|
|
||||||
|
Perun.SideID2Name = function(id)
|
||||||
|
-- Helper function returns side name per side (coalition) id
|
||||||
|
local sides = {
|
||||||
|
[0] = 'SPECTATOR',
|
||||||
|
[1] = 'RED',
|
||||||
|
[2] = 'BLUE',
|
||||||
|
}
|
||||||
|
return sides[id]
|
||||||
|
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)
|
||||||
end
|
end
|
||||||
|
|
||||||
Perun.UpdateJson = function()
|
Perun.UpdateJsonStatus = function()
|
||||||
-- Updates main json file
|
-- Updates status json file
|
||||||
TempData={}
|
TempData={}
|
||||||
TempData["1"]=Perun.VersionData
|
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: hangs for some large missions
|
||||||
|
|
||||||
io.open(Perun.JsonLocation,"w"):close()
|
_temp=net.lua2json(TempData)
|
||||||
perun_export = io.open(Perun.JsonLocation, "w")
|
|
||||||
perun_export:write(net.lua2json(TempData) .. "\n")
|
perun_export = io.open(Perun.JsonStatusLocation .. "perun_status_data.json", "w")
|
||||||
|
perun_export:write(_temp .. "\n")
|
||||||
perun_export:close()
|
perun_export:close()
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -52,10 +178,14 @@
|
|||||||
TempData={}
|
TempData={}
|
||||||
TempData["type"]=data_id
|
TempData["type"]=data_id
|
||||||
TempData["payload"]=data_package
|
TempData["payload"]=data_package
|
||||||
|
TempData["timestamp"]=os.date('%Y-%m-%d %H:%M:%S')
|
||||||
|
TempData["instance"]=Perun.Instance
|
||||||
|
|
||||||
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 "..data_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
Perun.UpdateStatusPart = function(part_id, data_package)
|
Perun.UpdateStatusPart = function(part_id, data_package)
|
||||||
@@ -63,20 +193,23 @@
|
|||||||
Perun.StatusData[part_id] = data_package
|
Perun.StatusData[part_id] = data_package
|
||||||
end
|
end
|
||||||
|
|
||||||
Perun.UpdateVersion = function()
|
|
||||||
-- Main function for debug/version information
|
|
||||||
|
|
||||||
-- Update Mission data
|
|
||||||
Perun.VersionData['v_dcs_hook']=Perun.Version
|
|
||||||
|
|
||||||
-- Send
|
|
||||||
Perun.Send(1,Perun.VersionData)
|
|
||||||
end
|
|
||||||
|
|
||||||
Perun.UpdateStatus = function()
|
Perun.UpdateStatus = function()
|
||||||
-- Main function for status updates
|
-- Main function for status updates
|
||||||
|
|
||||||
-- Update all subsections
|
-- Diagnostic data
|
||||||
|
-- Update version data
|
||||||
|
Perun.ServerData['v_dcs_hook']=Perun.Version
|
||||||
|
|
||||||
|
-- Update server data
|
||||||
|
_table=net.get_player_list()
|
||||||
|
_count = 0
|
||||||
|
for _ in pairs(_table) do _count = _count + 1 end
|
||||||
|
Perun.ServerData['c_players']=_count
|
||||||
|
|
||||||
|
-- Send
|
||||||
|
Perun.Send(1,Perun.ServerData)
|
||||||
|
|
||||||
|
-- Status data - update all subsections
|
||||||
-- 1 - Mission
|
-- 1 - Mission
|
||||||
temp={}
|
temp={}
|
||||||
temp['name']=DCS.getMissionName()
|
temp['name']=DCS.getMissionName()
|
||||||
@@ -84,23 +217,22 @@
|
|||||||
temp['realtime']=DCS.getRealTime()
|
temp['realtime']=DCS.getRealTime()
|
||||||
temp['pause']=DCS.getPause()
|
temp['pause']=DCS.getPause()
|
||||||
temp['multiplayer']=DCS.isMultiplayer()
|
temp['multiplayer']=DCS.isMultiplayer()
|
||||||
|
temp['theatre'] = Perun.MissionData['mission']['theatre']
|
||||||
|
temp['weather'] = Perun.MissionData['mission']['weather']
|
||||||
Perun.UpdateStatusPart("mission",temp)
|
Perun.UpdateStatusPart("mission",temp)
|
||||||
|
|
||||||
-- 2 - Players
|
-- 2 - Players
|
||||||
temp = net.get_player_list()
|
_temp = net.get_player_list()
|
||||||
for _, i in ipairs(temp) do
|
_temp2={}
|
||||||
temp[i]=net.get_player_info(i)
|
for k, i in ipairs(_temp) do
|
||||||
|
_temp2[k]=net.get_player_info(i)
|
||||||
end
|
end
|
||||||
Perun.UpdateStatusPart("players",temp)
|
Perun.UpdateStatusPart("players",_temp2)
|
||||||
|
|
||||||
-- Send
|
-- Send
|
||||||
Perun.Send(2,Perun.StatusData)
|
Perun.Send(2,Perun.StatusData)
|
||||||
end
|
|
||||||
|
|
||||||
Perun.UpdateMission = function()
|
-- Update slots data
|
||||||
-- Main function for mission information updates
|
|
||||||
|
|
||||||
-- Update Mission data
|
|
||||||
Perun.SlotsData['coalitions']=DCS.getAvailableCoalitions()
|
Perun.SlotsData['coalitions']=DCS.getAvailableCoalitions()
|
||||||
Perun.SlotsData['slots']={}
|
Perun.SlotsData['slots']={}
|
||||||
|
|
||||||
@@ -111,114 +243,393 @@
|
|||||||
Perun.Send(3,Perun.SlotsData)
|
Perun.Send(3,Perun.SlotsData)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
Perun.UpdateMission = function()
|
||||||
|
-- Main function for mission information updates
|
||||||
|
Perun.MissionData=DCS.getCurrentMission()
|
||||||
|
end
|
||||||
|
|
||||||
Perun.LogChat = function(playerID,msg,all)
|
Perun.LogChat = function(playerID,msg,all)
|
||||||
-- Log chat messages
|
-- Log chat messages
|
||||||
|
|
||||||
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['datetime']=os.date('%Y-%m-%d %H:%M:%S')
|
||||||
|
data['missionhash']=Perun.MissionHash
|
||||||
|
|
||||||
Perun.Send(50,data)
|
Perun.Send(50,data)
|
||||||
end
|
end
|
||||||
|
|
||||||
Perun.LogEvent = function(log_type,log_content)
|
Perun.LogEvent = function(log_type,log_content,log_arg_1,log_arg_2)
|
||||||
-- Log chat messages
|
-- Log chat messages
|
||||||
|
|
||||||
data={}
|
data={}
|
||||||
data['log_type']= log_type
|
data['log_type']= log_type
|
||||||
|
data['log_arg_1']= log_arg_1
|
||||||
|
data['log_arg_2']= log_arg_2
|
||||||
data['log_content']=log_content
|
data['log_content']=log_content
|
||||||
|
data['log_datetime']=os.date('%Y-%m-%d %H:%M:%S')
|
||||||
|
data['log_missionhash']=Perun.MissionHash
|
||||||
|
|
||||||
Perun.Send(51,data)
|
Perun.Send(51,data)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Event callbacks
|
Perun.LogStatsCount = function(argPlayerID,argAction,argType)
|
||||||
|
-- Creates or updates Perun statistics array
|
||||||
|
_ucid=net.get_player_info(argPlayerID, 'ucid')..argType
|
||||||
|
|
||||||
|
if Perun.StatData[_ucid] == nil then
|
||||||
|
-- Create empty element
|
||||||
|
_temp={}
|
||||||
|
_temp['ps_type'] = argType
|
||||||
|
_temp['ps_kills'] = 0
|
||||||
|
_temp['ps_pvp'] = 0
|
||||||
|
_temp['ps_deaths'] = 0
|
||||||
|
_temp['ps_ejections'] = 0
|
||||||
|
_temp['ps_crashes'] = 0
|
||||||
|
_temp['ps_teamkills'] = 0
|
||||||
|
_temp['ps_kills_planes'] = 0
|
||||||
|
_temp['ps_kills_helicopters'] = 0
|
||||||
|
_temp['ps_kills_air_defense'] = 0
|
||||||
|
_temp['ps_kills_armor'] = 0
|
||||||
|
_temp['ps_kills_unarmed'] = 0
|
||||||
|
_temp['ps_kills_infantry'] = 0
|
||||||
|
_temp['ps_kills_ships'] = 0
|
||||||
|
_temp['ps_kills_other'] = 0
|
||||||
|
_temp['ps_airfield_takeoffs'] = 0
|
||||||
|
_temp['ps_airfield_landings'] = 0
|
||||||
|
_temp['ps_ship_takeoffs'] = 0
|
||||||
|
_temp['ps_ship_landings'] = 0
|
||||||
|
_temp['ps_farp_takeoffs'] = 0
|
||||||
|
_temp['ps_farp_landings'] = 0
|
||||||
|
|
||||||
|
Perun.StatData[_ucid]=_temp
|
||||||
|
end
|
||||||
|
|
||||||
|
if argType ~= nil then
|
||||||
|
Perun.StatData[_ucid]['ps_type']=argType;
|
||||||
|
Perun.StatDataLastType[net.get_player_info(argPlayerID, 'ucid')]=_ucid
|
||||||
|
else
|
||||||
|
-- Do nothing
|
||||||
|
end
|
||||||
|
|
||||||
|
if argAction == "eject" then
|
||||||
|
Perun.StatData[_ucid]['ps_ejections']=Perun.StatData[_ucid]['ps_ejections']+1
|
||||||
|
elseif argAction == "pilot_death" then
|
||||||
|
Perun.StatData[_ucid]['ps_deaths']=Perun.StatData[_ucid]['ps_deaths']+1
|
||||||
|
elseif argAction == "friendly_fire" then
|
||||||
|
Perun.StatData[_ucid]['ps_teamkills']=Perun.StatData[_ucid]['ps_teamkills']+1
|
||||||
|
elseif argAction == "crash" then
|
||||||
|
Perun.StatData[_ucid]['ps_crashes']=Perun.StatData[_ucid]['ps_crashes']+1
|
||||||
|
elseif argAction == "landing_FARP" then
|
||||||
|
Perun.StatData[_ucid]['ps_farp_landings']=Perun.StatData[_ucid]['ps_farp_landings']+1
|
||||||
|
elseif argAction == "landing_SHIP" then
|
||||||
|
Perun.StatData[_ucid]['ps_ship_landings']=Perun.StatData[_ucid]['ps_ship_landings']+1
|
||||||
|
elseif argAction == "landing_AIRFIELD" then
|
||||||
|
Perun.StatData[_ucid]['ps_airfield_landings']=Perun.StatData[_ucid]['ps_airfield_landings']+1
|
||||||
|
elseif argAction == "tookoff_FARP" then
|
||||||
|
Perun.StatData[_ucid]['ps_farp_takeoffs']=Perun.StatData[_ucid]['ps_farp_takeoffs']+1
|
||||||
|
elseif argAction == "tookoff_SHIP" then
|
||||||
|
Perun.StatData[_ucid]['ps_ship_takeoffs']=Perun.StatData[_ucid]['ps_ship_takeoffs']+1
|
||||||
|
elseif argAction == "tookoff_AIRFIELD" then
|
||||||
|
Perun.StatData[_ucid]['ps_airfield_takeoffs']=Perun.StatData[_ucid]['ps_airfield_takeoffs']+1
|
||||||
|
elseif argAction == "kill_Planes" then
|
||||||
|
Perun.StatData[_ucid]['ps_kills_planes']=Perun.StatData[_ucid]['ps_kills_planes']+1
|
||||||
|
elseif argAction == "kill_Helicopters" then
|
||||||
|
Perun.StatData[_ucid]['ps_kills_helicopters']=Perun.StatData[_ucid]['ps_kills_helicopters']+1
|
||||||
|
elseif argAction == "kill_Ships" then
|
||||||
|
Perun.StatData[_ucid]['ps_kills_ships']=Perun.StatData[_ucid]['ps_kills_ships']+1
|
||||||
|
elseif argAction == "kill_Air_Defence" then
|
||||||
|
Perun.StatData[_ucid]['ps_kills_air_defense']=Perun.StatData[_ucid]['ps_kills_air_defense']+1
|
||||||
|
elseif argAction == "kill_Unarmed" then
|
||||||
|
Perun.StatData[_ucid]['ps_kills_unarmed']=Perun.StatData[_ucid]['ps_kills_unarmed']+1
|
||||||
|
elseif argAction == "kill_Armor" then
|
||||||
|
Perun.StatData[_ucid]['ps_kills_armor']=Perun.StatData[_ucid]['ps_kills_armor']+1
|
||||||
|
elseif argAction == "kill_Infantry" then
|
||||||
|
Perun.StatData[_ucid]['ps_kills_infantry']=Perun.StatData[_ucid]['ps_kills_infantry']+1
|
||||||
|
elseif argAction == "kill_Other" then
|
||||||
|
Perun.StatData[_ucid]['ps_kills_other']=Perun.StatData[_ucid]['ps_kills_other']+1
|
||||||
|
elseif argAction == "kill_PvP" then
|
||||||
|
Perun.StatData[_ucid]['ps_pvp']=Perun.StatData[_ucid]['ps_pvp']+1
|
||||||
|
end
|
||||||
|
|
||||||
|
Perun.LogStats(argPlayerID);
|
||||||
|
end
|
||||||
|
|
||||||
|
Perun.LogStatsGet = function(playerID)
|
||||||
|
-- Gets Perun statistics array per player
|
||||||
|
|
||||||
|
local next = next
|
||||||
|
if next(Perun.StatDataLastType) == nil then
|
||||||
|
_ucid=net.get_player_info(playerID, 'ucid')..DCS.getUnitType(playerID)
|
||||||
|
elseif Perun.StatDataLastType[net.get_player_info(playerID, 'ucid')]== nil then
|
||||||
|
_ucid=net.get_player_info(playerID, 'ucid')..DCS.getUnitType(playerID)
|
||||||
|
else
|
||||||
|
_ucid=Perun.StatDataLastType[net.get_player_info(playerID, 'ucid')]
|
||||||
|
end
|
||||||
|
|
||||||
|
local next = next
|
||||||
|
if next(Perun.StatData) == nil then
|
||||||
|
Perun.LogStatsCount(playerID,'init')
|
||||||
|
|
||||||
|
end
|
||||||
|
if Perun.StatData[_ucid]== nil then
|
||||||
|
Perun.LogStatsCount(playerID,'init')
|
||||||
|
end
|
||||||
|
return Perun.StatData[_ucid];
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Perun.LogStats = function(playerID)
|
||||||
|
-- Log player status
|
||||||
|
|
||||||
|
-- TBD : DCS stats not working at the moment WIP
|
||||||
|
p_stats_dcs={}
|
||||||
|
p_stats_dcs['PS_CAR']=net.get_stat(playerID,2)
|
||||||
|
p_stats_dcs['PS_PLANE']=net.get_stat(playerID,3)
|
||||||
|
p_stats_dcs['PS_SHIP']=net.get_stat(playerID,4)
|
||||||
|
p_stats_dcs['PS_SCORE']=net.get_stat(playerID,5)
|
||||||
|
p_stats_dcs['PS_LAND']=net.get_stat(playerID,6)
|
||||||
|
p_stats_dcs['PS_PING']=net.get_stat(playerID,0)
|
||||||
|
p_stats_dcs['PS_CRASH']=net.get_stat(playerID,1)
|
||||||
|
p_stats_dcs['PS_EJECT']=net.get_stat(playerID,7)
|
||||||
|
|
||||||
|
_temp=Perun.LogStatsGet(playerID)
|
||||||
|
data={}
|
||||||
|
data['stat_data_dcs']=p_stats_dcs
|
||||||
|
data['stat_data_perun']=_temp
|
||||||
|
data['stat_data_type']=_temp['ps_type'];
|
||||||
|
data['stat_ucid']=net.get_player_info(playerID, 'ucid')
|
||||||
|
data['stat_datetime']=os.date('%Y-%m-%d %H:%M:%S')
|
||||||
|
data['stat_missionhash']=Perun.MissionHash
|
||||||
|
|
||||||
|
Perun.Send(52,data)
|
||||||
|
end
|
||||||
|
|
||||||
|
Perun.LogLogin = function(playerID)
|
||||||
|
-- Player logged in
|
||||||
|
|
||||||
|
data={}
|
||||||
|
data['login_ucid']=net.get_player_info(playerID, 'ucid')
|
||||||
|
data['login_ipaddr']=net.get_player_info(playerID, 'ipaddr')
|
||||||
|
data['login_name']=net.get_player_info(playerID, 'name')
|
||||||
|
data['login_datetime']=os.date('%Y-%m-%d %H:%M:%S')
|
||||||
|
|
||||||
|
Perun.Send(53,data)
|
||||||
|
end
|
||||||
|
|
||||||
|
--- ########### Event callbacks ###########
|
||||||
|
|
||||||
|
Perun.onSimulationStart = function()
|
||||||
|
Perun.MissionHash=DCS.getMissionName( ).."@".. Perun.Instance .. "@"..os.date('%Y%m%d_%H%M%S');
|
||||||
|
Perun.LogEvent("SimStart","Mission " .. Perun.MissionHash .. " started",nil,nil);
|
||||||
|
Perun.StatData = {}
|
||||||
|
Perun.StatDataLastType = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
Perun.onSimulationStop = function()
|
||||||
|
Perun.LogEvent("SimStop","Mission " .. Perun.MissionHash .. " finished",nil,nil);
|
||||||
|
Perun.MissionHash="";
|
||||||
|
Perun.StatData = {}
|
||||||
|
Perun.StatDataLastType = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
Perun.onPlayerDisconnect = function(id, err_code)
|
||||||
|
Perun.LogEvent("disconnect", "Player " .. net.get_player_info(id, "name") .. " disconnected; " .. err_code,net.get_player_info(id, "name"),err_code);
|
||||||
|
end
|
||||||
|
|
||||||
Perun.onSimulationFrame = function()
|
Perun.onSimulationFrame = function()
|
||||||
local _now = DCS.getRealTime()
|
local _now = DCS.getRealTime()
|
||||||
|
|
||||||
if _now > Perun.lastSent + Perun.Refresh then
|
-- First run
|
||||||
Perun.lastSent = _now
|
if Perun.lastSentMission ==0 and Perun.lastSentStatus ==0 then
|
||||||
|
Perun.UpdateMission()
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Send mission update and update JSON
|
||||||
|
if _now > Perun.lastSentMission + Perun.RefreshMission then
|
||||||
|
Perun.lastSentMission = _now
|
||||||
|
|
||||||
Perun.UpdateMission()
|
Perun.UpdateMission()
|
||||||
|
Perun.UpdateJsonStatus()
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Send status update
|
||||||
|
if _now > Perun.lastSentStatus + Perun.RefreshStatus then
|
||||||
|
Perun.lastSentStatus = _now
|
||||||
|
|
||||||
Perun.UpdateStatus()
|
Perun.UpdateStatus()
|
||||||
Perun.UpdateVersion()
|
|
||||||
Perun.UpdateJson()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
Perun.onMissionLoadEnd = function()
|
|
||||||
Perun.UpdateMission()
|
|
||||||
Perun.UpdateJson()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
Perun.onPlayerStart = function (id)
|
Perun.onPlayerStart = function (id)
|
||||||
net.send_chat(Perun.MOTD_L1, id);
|
net.send_chat_to(Perun.MOTD_L1, id);
|
||||||
net.send_chat(Perun.MOTD_L2, id);
|
net.send_chat_to(Perun.MOTD_L2, id);
|
||||||
end
|
end
|
||||||
|
|
||||||
Perun.onPlayerTrySendChat = function (playerID, msg, all)
|
Perun.onPlayerTrySendChat = function (playerID, msg, all)
|
||||||
|
if msg~=Perun.MOTD_L1 and msg~=Perun.MOTD_L2 then
|
||||||
Perun.LogChat(playerID,msg,all)
|
Perun.LogChat(playerID,msg,all)
|
||||||
|
end
|
||||||
|
|
||||||
return msg
|
return msg
|
||||||
end
|
end
|
||||||
|
|
||||||
Perun.onGameEvent = function (eventName,arg1,arg2,arg3,arg4)
|
Perun.onGameEvent = function (eventName,arg1,arg2,arg3,arg4,arg5,arg6,arg7)
|
||||||
|
|
||||||
|
|
||||||
if eventName == "friendly_fire" then
|
if eventName == "friendly_fire" then
|
||||||
--"friendly_fire", playerID, weaponName, victimPlayerID
|
--"friendly_fire", playerID, weaponName, victimPlayerID
|
||||||
Perun.LogEvent(eventName,net.get_player_info(arg1, "name").." killed " .. net.get_player_info(arg3, "name") .. " using " .. arg2);
|
if arg2 == nil then
|
||||||
|
arg2 = "Cannon"
|
||||||
|
end
|
||||||
|
|
||||||
|
Perun.LogEvent(eventName,Perun.SideID2Name( net.get_player_info(arg1, "side")) .. " player " .. net.get_player_info(arg1, "name").." killed friendy " .. net.get_player_info(arg3, "name") .. " using " .. arg2,nil,nil);
|
||||||
|
Perun.LogStatsCount(arg1,"friendly_fire",DCS.getUnitType(arg1))
|
||||||
|
|
||||||
elseif eventName == "mission_end" then
|
elseif eventName == "mission_end" then
|
||||||
--"mission_end", winner, msg
|
--"mission_end", winner, msg
|
||||||
Perun.LogEvent(eventName,"Mission end, winner " .. arg1 .. " message: " .. arg2);
|
Perun.LogEvent(eventName,"Mission finished, winner " .. arg1 .. " message: " .. arg2,nil,nil);
|
||||||
|
|
||||||
elseif eventName == "kill" then
|
elseif eventName == "kill" then
|
||||||
--"kill", killerPlayerID, killerUnitType, killerSide, victimPlayerID, victimUnitType, victimSide, weaponName
|
--"kill", killerPlayerID, killerUnitType, killerSide, victimPlayerID, victimUnitType, victimSide, weaponName
|
||||||
Perun.LogEvent(eventName,net.get_player_info(arg1, "name").. " in " .. arg3 .. " " .. arg2 .. " killed " .. net.get_player_info(arg4, "name") .. " in " .. arg6 .. " " .. arg5 .. " using " .. arg7);
|
if net.get_player_info(arg4, "name") ~= nil then
|
||||||
|
_temp = " player ".. net.get_player_info(arg4, "name") .." ";
|
||||||
|
|
||||||
|
Perun.LogStats(arg4);
|
||||||
|
else
|
||||||
|
_temp = " AI ";
|
||||||
|
end
|
||||||
|
|
||||||
|
if net.get_player_info(arg1, "name") ~= nil then
|
||||||
|
_temp2 = " player ".. net.get_player_info(arg1, "name") .." ";
|
||||||
|
|
||||||
|
if Perun.GetCategory(arg5) == "Planes" then
|
||||||
|
Perun.LogStatsCount(arg1,"kill_Planes",arg2)
|
||||||
|
elseif Perun.GetCategory(arg5) == "Helicopters" then
|
||||||
|
Perun.LogStatsCount(arg1,"kill_Helicopters",arg2)
|
||||||
|
elseif Perun.GetCategory(arg5) == "Ships" then
|
||||||
|
Perun.LogStatsCount(arg1,"kill_Ships",arg2)
|
||||||
|
elseif Perun.GetCategory(arg5) == "Air Defence" then
|
||||||
|
Perun.LogStatsCount(arg1,"kill_Air_Defence",arg2)
|
||||||
|
elseif Perun.GetCategory(arg5) == "Unarmed" then
|
||||||
|
Perun.LogStatsCount(arg1,"kill_Unarmed",arg2)
|
||||||
|
elseif Perun.GetCategory(arg5) == "Armor" then
|
||||||
|
Perun.LogStatsCount(arg1,"kill_Armor",arg2)
|
||||||
|
elseif Perun.GetCategory(arg5) == "Infantry" then
|
||||||
|
Perun.LogStatsCount(arg1,"kill_Infantry",arg2)
|
||||||
|
else
|
||||||
|
Perun.LogStatsCount(arg1,"kill_Other",arg2)
|
||||||
|
end
|
||||||
|
|
||||||
|
if net.get_player_info(arg4, "name") ~= nil and killerSide ~= victimSide then
|
||||||
|
Perun.LogStatsCount(arg1,"kill_PvP",arg2)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
_temp2 = " AI ";
|
||||||
|
end
|
||||||
|
|
||||||
|
if arg7 == nil then
|
||||||
|
arg7 = "Cannon"
|
||||||
|
end
|
||||||
|
|
||||||
|
Perun.LogEvent(eventName,Perun.SideID2Name(arg3) .. _temp2 .. " in " .. arg2 .. " killed " .. Perun.SideID2Name(arg6) .. _temp .. " in " .. arg5 .. " using " .. arg7 .. " [".. Perun.GetCategory(arg5).."]",arg7,Perun.GetCategory(arg5));
|
||||||
|
|
||||||
elseif eventName == "self_kill" then
|
elseif eventName == "self_kill" then
|
||||||
--"self_kill", playerID
|
--"self_kill", playerID
|
||||||
Perun.LogEvent(eventName,net.get_player_info(arg1, "name") .. " killed himself");
|
Perun.LogEvent(eventName,net.get_player_info(arg1, "name") .. " killed himself",nil,nil);
|
||||||
|
Perun.LogStats(arg1);
|
||||||
|
|
||||||
elseif eventName == "change_slot" then
|
elseif eventName == "change_slot" then
|
||||||
--"change_slot", playerID, slotID, prevSide
|
--"change_slot", playerID, slotID, prevSide
|
||||||
Perun.LogEvent(eventName,net.get_player_info(arg1, "name") .. " changed slot to " .. arg2);
|
|
||||||
|
if DCS.getUnitType(arg2) ~= nil and DCS.getUnitType(arg2) ~= "" then
|
||||||
|
_temp = DCS.getUnitType(arg2);
|
||||||
|
else
|
||||||
|
_temp = "SPECTATOR";
|
||||||
|
end
|
||||||
|
|
||||||
|
Perun.LogEvent(eventName,Perun.SideID2Name( net.get_player_info(arg1, "side")) .. " player " .. net.get_player_info(arg1, "name") .. " changed slot to " .. _temp);
|
||||||
|
Perun.LogStatsCount(arg1,"init",_temp,nil,nil)
|
||||||
|
|
||||||
elseif eventName == "connect" then
|
elseif eventName == "connect" then
|
||||||
--"connect", playerID, name
|
--"connect", playerID, name
|
||||||
Perun.LogEvent(eventName,net.get_player_info(arg1, "name") .. " connected");
|
Perun.LogLogin(arg1);
|
||||||
|
Perun.LogEvent(eventName,"Player "..net.get_player_info(arg1, "name") .. " connected",nil,nil);
|
||||||
|
|
||||||
elseif eventName == "disconnect" then
|
elseif eventName == "disconnect" then
|
||||||
--"disconnect", playerID, name, playerSide, reason_code
|
--"disconnect", playerID, name, playerSide, reason_code
|
||||||
Perun.LogEvent(eventName,net.get_player_info(arg1, "name") .. " disconnected");
|
Perun.LogEvent(eventName, Perun.SideID2Name(arg3) .. " player " ..net.get_player_info(arg1, "name") .. " disconnected",nil,nil);
|
||||||
|
Perun.LogStats(arg1);
|
||||||
|
|
||||||
elseif eventName == "crash" then
|
elseif eventName == "crash" then
|
||||||
--"crash", playerID, unit_missionID
|
--"crash", playerID, unit_missionID
|
||||||
Perun.LogEvent(eventName,net.get_player_info(arg1, "name") .. " crashed");
|
Perun.LogEvent(eventName, Perun.SideID2Name( net.get_player_info(arg1, "side")) .. " player " .. net.get_player_info(arg1, "name") .. " crashed in " .. DCS.getUnitType(arg2),nil,nil);
|
||||||
|
Perun.LogStatsCount(arg1,"crash",DCS.getUnitType(arg2))
|
||||||
elseif eventName == "eject" then
|
elseif eventName == "eject" then
|
||||||
--"eject", playerID, unit_missionID
|
--"eject", playerID, unit_missionID
|
||||||
Perun.LogEvent(eventName,net.get_player_info(arg1, "name") .. " ejected");
|
Perun.LogEvent(eventName, Perun.SideID2Name( net.get_player_info(arg1, "side")) .. " player " .. net.get_player_info(arg1, "name") .. " ejected " .. DCS.getUnitType(arg2),nil,nil);
|
||||||
|
Perun.LogStatsCount(arg1,"eject",DCS.getUnitType(arg2));
|
||||||
|
|
||||||
elseif eventName == "takeoff" then
|
elseif eventName == "takeoff" then
|
||||||
--"takeoff", playerID, unit_missionID, airdromeName
|
--"takeoff", playerID, unit_missionID, airdromeName
|
||||||
Perun.LogEvent(eventName,net.get_player_info(arg1, "name") .. " took off from " .. arg3);
|
if arg3 then
|
||||||
|
_temp = " from " .. arg3;
|
||||||
|
else
|
||||||
|
_temp = "";
|
||||||
|
end
|
||||||
|
|
||||||
|
Perun.LogEvent(eventName, Perun.SideID2Name( net.get_player_info(arg1, "side")) .. " player " .. net.get_player_info(arg1, "name") .. " took off in ".. DCS.getUnitType(arg2) .. _temp,arg3,nil);
|
||||||
|
|
||||||
|
if string.find(arg3, "FARP") then
|
||||||
|
Perun.LogStatsCount(arg1,"tookoff_FARP",DCS.getUnitType(arg2))
|
||||||
|
elseif string.find(arg3, "CVN-74 John C. Stennis") or string.find(arg3, "LHA-1 Tarawa") then
|
||||||
|
Perun.LogStatsCount(arg1,"tookoff_SHIP",DCS.getUnitType(arg2))
|
||||||
|
elseif arg3 then
|
||||||
|
Perun.LogStatsCount(arg1,"tookoff_AIRFIELD",DCS.getUnitType(arg2))
|
||||||
|
else
|
||||||
|
-- do nothing
|
||||||
|
end
|
||||||
|
|
||||||
elseif eventName == "landing" then
|
elseif eventName == "landing" then
|
||||||
--"landing", playerID, unit_missionID, airdromeName
|
--"landing", playerID, unit_missionID, airdromeName
|
||||||
Perun.LogEvent(eventName,net.get_player_info(arg1, "name") .. " landed at " .. arg3);
|
if arg3 then
|
||||||
|
_temp = " at " .. arg3;
|
||||||
|
else
|
||||||
|
_temp ="";
|
||||||
|
end
|
||||||
|
|
||||||
|
Perun.LogEvent(eventName, Perun.SideID2Name( net.get_player_info(arg1, "side")) .. " player " .. net.get_player_info(arg1, "name") .. " landed in " .. DCS.getUnitType(arg2).. _temp,arg3,nil);
|
||||||
|
|
||||||
|
if string.find(arg3, "FARP") then
|
||||||
|
Perun.LogStatsCount(arg1,"landing_FARP",DCS.getUnitType(arg2))
|
||||||
|
elseif string.find(arg3, "CVN-74 John C. Stennis") or string.find(arg3, "LHA-1 Tarawa") then
|
||||||
|
Perun.LogStatsCount(arg1,"landing_SHIP",DCS.getUnitType(arg2))
|
||||||
|
elseif arg3 then
|
||||||
|
Perun.LogStatsCount(arg1,"landing_AIRFIELD",DCS.getUnitType(arg2))
|
||||||
|
else
|
||||||
|
-- do nothing
|
||||||
|
end
|
||||||
|
|
||||||
elseif eventName == "pilot_death" then
|
elseif eventName == "pilot_death" then
|
||||||
--"pilot_death", playerID, unit_missionID
|
--"pilot_death", playerID, unit_missionID
|
||||||
Perun.LogEvent(eventName,net.get_player_info(arg1, "name") .. " died");
|
Perun.LogEvent(eventName, Perun.SideID2Name( net.get_player_info(arg1, "side")) .. " player " .. net.get_player_info(arg1, "name") .. " in " .. DCS.getUnitType(arg2) .. " died",nil,nil);
|
||||||
|
Perun.LogStatsCount(arg1,"pilot_death",DCS.getUnitType(arg2))
|
||||||
else
|
else
|
||||||
Perun.LogEvent(eventName,"Unknown event type");
|
Perun.LogEvent(eventName,"Unknown event type",nil,nil);
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Finalize and set callbacks
|
-- ########### Finalize and set callbacks ###########
|
||||||
|
if Perun.IsServer then
|
||||||
|
Perun.UDP = assert(Perun.socket.udp())
|
||||||
|
Perun.UDP:settimeout(0)
|
||||||
|
Perun.UDP:setsockname("*", Perun.UDPSourcePort)
|
||||||
|
Perun.UDP:setpeername("127.0.0.1",Perun.UDPTargetPort)
|
||||||
|
|
||||||
DCS.setUserCallbacks(Perun)
|
DCS.setUserCallbacks(Perun)
|
||||||
net.log("Loaded - Perun - VladMordock - " .. Perun.Version )
|
net.log("Loaded - Perun - VladMordock - " .. Perun.Version )
|
||||||
|
end
|
||||||
|
|||||||
1
01_DCS/Json/perun_status_data.json
Normal file
1
01_DCS/Json/perun_status_data.json
Normal file
@@ -0,0 +1 @@
|
|||||||
|
|
||||||
@@ -36,7 +36,7 @@
|
|||||||
<value>False</value>
|
<value>False</value>
|
||||||
</setting>
|
</setting>
|
||||||
<setting name="MYSQL_Port" serializeAs="String">
|
<setting name="MYSQL_Port" serializeAs="String">
|
||||||
<value />
|
<value>3306</value>
|
||||||
</setting>
|
</setting>
|
||||||
</Perun_v1.Properties.Settings>
|
</Perun_v1.Properties.Settings>
|
||||||
<Perun.Properties.Settings>
|
<Perun.Properties.Settings>
|
||||||
128
02_Windows_App/Perun_v1/01_Classes/DatabaseController.cs
Normal file
128
02_Windows_App/Perun_v1/01_Classes/DatabaseController.cs
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
// This class handles MySQL communication
|
||||||
|
using MySql.Data.MySqlClient;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
internal class DatabaseController
|
||||||
|
{
|
||||||
|
public static string strMySQLConnectionString; // MySQL connection string
|
||||||
|
|
||||||
|
public static void SendToMySql(string strRawUDPFrame)
|
||||||
|
{
|
||||||
|
// Main function to send data to mysql
|
||||||
|
dynamic strUDPFrame = JsonConvert.DeserializeObject(strRawUDPFrame); // Deserialize raw data
|
||||||
|
string strUDPFrameType = strUDPFrame.type;
|
||||||
|
string strUDPFrameTimestamp = strUDPFrame.timestamp;
|
||||||
|
string strUDPFrameInstance = strUDPFrame.instance;
|
||||||
|
string strUDPFramePayload = "";
|
||||||
|
string strUDPFramePayload_Perun = "";
|
||||||
|
string strSQLQueryTxt = "";
|
||||||
|
|
||||||
|
|
||||||
|
// Some frames may come without timestamp, use database currrent timestampe then
|
||||||
|
if (strUDPFrameTimestamp != null)
|
||||||
|
{
|
||||||
|
strUDPFrameTimestamp = "'" + strUDPFrameTimestamp + "'";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
strUDPFrameTimestamp = "CURRENT_TIMESTAMP()";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Modify specific types
|
||||||
|
if (strUDPFrameType == "1")
|
||||||
|
{
|
||||||
|
strUDPFrame.payload["v_win"] = "v" + Globals.strPerunVersion; // Inject app version information
|
||||||
|
}
|
||||||
|
|
||||||
|
// Specific SQL
|
||||||
|
if (strUDPFrameType == "50")
|
||||||
|
{
|
||||||
|
// Add entry to chat log
|
||||||
|
strSQLQueryTxt = "INSERT INTO `pe_DataPlayers` (`pe_DataPlayers_ucid`) SELECT '" + strUDPFrame.payload.ucid + "' FROM DUAL WHERE NOT EXISTS (SELECT * FROM `pe_DataPlayers` where `pe_DataPlayers_ucid` = '" + strUDPFrame.payload.ucid + "' );";
|
||||||
|
strSQLQueryTxt += "UPDATE `pe_DataPlayers` SET `pe_DataPlayers_updated` = " + strUDPFrameTimestamp + ",`pe_DataPlayers_lastname`='" + strUDPFrame.payload.player + "' WHERE `pe_DataPlayers_ucid`='" + strUDPFrame.payload.ucid + "' ;";
|
||||||
|
strSQLQueryTxt += "INSERT INTO `pe_DataMissionHashes` (`pe_DataMissionHashes_hash`,`pe_DataMissionHashes_instance`) SELECT '" + strUDPFrame.payload.missionhash + "','" + strUDPFrameInstance + "' FROM DUAL WHERE NOT EXISTS (SELECT * FROM `pe_DataMissionHashes` where `pe_DataMissionHashes_hash` ='" + strUDPFrame.payload.missionhash + "' AND `pe_DataMissionHashes_instance`="+ strUDPFrameInstance + ");";
|
||||||
|
strSQLQueryTxt += "UPDATE `pe_DataMissionHashes` SET `pe_DataMissionHashes_datetime` = " + strUDPFrameTimestamp + " WHERE `pe_DataMissionHashes_hash` = '" + strUDPFrame.payload.missionhash + "' AND `pe_DataMissionHashes_instance`=" + strUDPFrameInstance + " ;";
|
||||||
|
strSQLQueryTxt += "INSERT INTO `pe_LogChat` (`pe_LogChat_id`,`pe_LogChat_datetime`, `pe_LogChat_playerid`, `pe_LogChat_msg`, `pe_LogChat_all`,`pe_LogChat_missionhash_id`) VALUES (NULL,'" + strUDPFrame.payload.datetime + "', (SELECT `pe_DataPlayers_id` from `pe_DataPlayers` WHERE `pe_DataPlayers_ucid` = '" + strUDPFrame.payload.ucid + "'), '" + strUDPFrame.payload.msg + "', '" + strUDPFrame.payload.all + "',(SELECT `pe_DataMissionHashes_id` FROM `pe_DataMissionHashes` WHERE `pe_DataMissionHashes_hash` = '" + strUDPFrame.payload.missionhash + "'));";
|
||||||
|
}
|
||||||
|
else if (strUDPFrameType == "51")
|
||||||
|
{
|
||||||
|
// Add entry to event log
|
||||||
|
strSQLQueryTxt = "INSERT INTO `pe_DataMissionHashes` (`pe_DataMissionHashes_hash`,`pe_DataMissionHashes_instance`) SELECT '" + strUDPFrame.payload.log_missionhash + "','" + strUDPFrameInstance + "' FROM DUAL WHERE NOT EXISTS (SELECT * FROM `pe_DataMissionHashes` where `pe_DataMissionHashes_hash` = '" + strUDPFrame.payload.log_missionhash + "' AND `pe_DataMissionHashes_instance`=" + strUDPFrameInstance + ");";
|
||||||
|
strSQLQueryTxt += "UPDATE `pe_DataMissionHashes` SET `pe_DataMissionHashes_datetime` = " + strUDPFrameTimestamp + " WHERE `pe_DataMissionHashes_hash` = '" + strUDPFrame.payload.log_missionhash + "' AND `pe_DataMissionHashes_instance`=" + strUDPFrameInstance + ";";
|
||||||
|
strSQLQueryTxt += "INSERT INTO `pe_LogEvent` (`pe_LogEvent_arg1`,`pe_LogEvent_arg2`,`pe_LogEvent_id`, `pe_LogEvent_datetime`, `pe_LogEvent_type`, `pe_LogEvent_content`,`pe_LogEvent_missionhash_id`) VALUES ('"+ strUDPFrame.payload.log_arg_1 + "','"+ strUDPFrame.payload.log_arg_2 + "', NULL, '" + strUDPFrame.payload.log_datetime + "', '" + strUDPFrame.payload.log_type + "', '" + strUDPFrame.payload.log_content + "', (SELECT `pe_DataMissionHashes_id` FROM `pe_DataMissionHashes` WHERE `pe_DataMissionHashes_hash` = '" + strUDPFrame.payload.log_missionhash + "'));";
|
||||||
|
}
|
||||||
|
else if (strUDPFrameType == "52")
|
||||||
|
{
|
||||||
|
// Update user stats
|
||||||
|
strUDPFramePayload = JsonConvert.SerializeObject(strUDPFrame.payload.stat_data_dcs); // Deserialize payload
|
||||||
|
strUDPFramePayload_Perun = JsonConvert.SerializeObject(strUDPFrame.payload.stat_data_perun); // Deserialize payload
|
||||||
|
|
||||||
|
strSQLQueryTxt = "INSERT INTO `pe_DataMissionHashes` (`pe_DataMissionHashes_hash`,`pe_DataMissionHashes_instance`) SELECT '" + strUDPFrame.payload.stat_missionhash + "','" + strUDPFrameInstance + "' FROM DUAL WHERE NOT EXISTS (SELECT * FROM `pe_DataMissionHashes` where `pe_DataMissionHashes_hash` = '" + strUDPFrame.payload.stat_missionhash + "' AND `pe_DataMissionHashes_instance`=" + strUDPFrameInstance + ");";
|
||||||
|
strSQLQueryTxt += "UPDATE `pe_DataMissionHashes` SET `pe_DataMissionHashes_datetime` = " + strUDPFrameTimestamp + " WHERE `pe_DataMissionHashes_hash` = '" + strUDPFrame.payload.stat_missionhash + "' AND `pe_DataMissionHashes_instance`=" + strUDPFrameInstance + " ;";
|
||||||
|
strSQLQueryTxt += "INSERT INTO `pe_DataPlayers` (`pe_DataPlayers_ucid`) SELECT '" + strUDPFrame.payload.stat_ucid + "' FROM DUAL WHERE NOT EXISTS (SELECT * FROM `pe_DataPlayers` where `pe_DataPlayers_ucid` = '" + strUDPFrame.payload.stat_ucid + "');";
|
||||||
|
strSQLQueryTxt += "UPDATE `pe_DataPlayers` SET `pe_DataPlayers_updated`=" + strUDPFrameTimestamp + " WHERE `pe_DataPlayers_ucid`='" + strUDPFrame.payload.stat_ucid + "';";
|
||||||
|
strSQLQueryTxt += "INSERT INTO `pe_LogStats` (`pe_LogStats_playerid`,`pe_LogStats_missionhash_id`,`pe_LogStats_type`) SELECT (SELECT `pe_DataPlayers_id` from `pe_DataPlayers` WHERE `pe_DataPlayers_ucid` = '" + strUDPFrame.payload.stat_ucid + "'), (SELECT `pe_DataMissionHashes_id` FROM `pe_DataMissionHashes` WHERE `pe_DataMissionHashes_hash` = '" + strUDPFrame.payload.stat_missionhash + "'),'" + strUDPFrame.payload.stat_data_type + "' FROM DUAL WHERE NOT EXISTS (SELECT * FROM `pe_LogStats` WHERE `pe_LogStats_missionhash_id`=(SELECT `pe_DataMissionHashes_id` FROM `pe_DataMissionHashes` WHERE `pe_DataMissionHashes_hash` = '" + strUDPFrame.payload.stat_missionhash + "') AND `pe_LogStats_playerid` = (SELECT `pe_DataPlayers_id` from `pe_DataPlayers` WHERE `pe_DataPlayers_ucid` = '" + strUDPFrame.payload.stat_ucid + "' AND `pe_LogStats_type`='"+ strUDPFrame.payload.stat_data_type + "') );";
|
||||||
|
strSQLQueryTxt += "UPDATE `pe_LogStats` SET `ps_kills`="+ strUDPFrame.payload.stat_data_perun.ps_kills + ",`ps_pvp`=" + strUDPFrame.payload.stat_data_perun.ps_pvp + ",`ps_deaths`=" + strUDPFrame.payload.stat_data_perun.ps_deaths + ",`ps_ejections`=" + strUDPFrame.payload.stat_data_perun.ps_ejections + ",`ps_crashes`=" + strUDPFrame.payload.stat_data_perun.ps_crashes + ",`ps_teamkills`=" + strUDPFrame.payload.stat_data_perun.ps_teamkills + ",`ps_kills_planes`=" + strUDPFrame.payload.stat_data_perun.ps_kills_planes + ",`ps_kills_helicopters`=" + strUDPFrame.payload.stat_data_perun.ps_kills_helicopters + ",`ps_kills_air_defense`=" + strUDPFrame.payload.stat_data_perun.ps_kills_air_defense + ",`ps_kills_armor`=" + strUDPFrame.payload.stat_data_perun.ps_kills_armor + ",`ps_kills_unarmed`=" + strUDPFrame.payload.stat_data_perun.ps_kills_unarmed + ",`ps_kills_infantry`=" + strUDPFrame.payload.stat_data_perun.ps_kills_infantry + ",`ps_kills_ships`=" + strUDPFrame.payload.stat_data_perun.ps_kills_ships + ",`ps_kills_other`=" + strUDPFrame.payload.stat_data_perun.ps_kills_other + ",`ps_airfield_takeoffs`=" + strUDPFrame.payload.stat_data_perun.ps_airfield_takeoffs + ",`ps_airfield_landings`=" + strUDPFrame.payload.stat_data_perun.ps_airfield_landings + ",`ps_ship_takeoffs`=" + strUDPFrame.payload.stat_data_perun.ps_ship_takeoffs + ",`ps_ship_landings`=" + strUDPFrame.payload.stat_data_perun.ps_ship_landings + ",`ps_farp_takeoffs`=" + strUDPFrame.payload.stat_data_perun.ps_farp_takeoffs + ",`ps_farp_landings`=" + strUDPFrame.payload.stat_data_perun.ps_farp_landings + ", `pe_LogStats_perun` = JSON_QUOTE('" + strUDPFramePayload_Perun + "'), `pe_LogStats_datetime`='" + strUDPFrame.payload.stat_datetime + "',`pe_LogStats_playerid` = (SELECT `pe_DataPlayers_id` from `pe_DataPlayers` WHERE `pe_DataPlayers_ucid` = '" + strUDPFrame.payload.stat_ucid + "'),`pe_LogStats_dcs`=JSON_QUOTE('" + strUDPFramePayload + "'),`pe_LogStats_missionhash_id`=(SELECT `pe_DataMissionHashes_id` FROM `pe_DataMissionHashes` WHERE `pe_DataMissionHashes_hash` = '" + strUDPFrame.payload.stat_missionhash + "') WHERE `pe_LogStats_missionhash_id`=(SELECT `pe_DataMissionHashes_id` FROM `pe_DataMissionHashes` WHERE `pe_DataMissionHashes_hash` = '" + strUDPFrame.payload.stat_missionhash + "') AND `pe_LogStats_playerid` = (SELECT `pe_DataPlayers_id` from `pe_DataPlayers` WHERE `pe_DataPlayers_ucid` = '" + strUDPFrame.payload.stat_ucid + "') AND `pe_LogStats_type`='" + strUDPFrame.payload.stat_data_type + "';";
|
||||||
|
}
|
||||||
|
else if (strUDPFrameType == "53")
|
||||||
|
{
|
||||||
|
// User logged in to DCS server
|
||||||
|
|
||||||
|
strSQLQueryTxt = "INSERT INTO `pe_DataPlayers` (`pe_DataPlayers_ucid`) SELECT '" + strUDPFrame.payload.login_ucid + "' FROM DUAL WHERE NOT EXISTS (SELECT * FROM `pe_DataPlayers` where pe_DataPlayers_ucid='" + strUDPFrame.payload.login_ucid + "');";
|
||||||
|
strSQLQueryTxt += "UPDATE `pe_DataPlayers` SET pe_DataPlayers_lastip='" + strUDPFrame.payload.login_ipaddr + "', pe_DataPlayers_lastname='" + strUDPFrame.payload.login_name + "',pe_DataPlayers_updated='" + strUDPFrame.payload.login_datetime + "' WHERE `pe_DataPlayers_ucid`= '" + strUDPFrame.payload.login_ucid + "';";
|
||||||
|
strSQLQueryTxt += "INSERT INTO `pe_LogLogins` (`pe_LogLogins_datetime`, `pe_LogLogins_playerid`, `pe_LogLogins_name`, `pe_LogLogins_ip`,`pe_LogLogins_instance`) VALUES ('" + strUDPFrame.payload.login_datetime + "', (SELECT pe_DataPlayers_id from pe_DataPlayers WHERE pe_DataPlayers_ucid = '" + strUDPFrame.payload.login_ucid + "'), '" + strUDPFrame.payload.login_name + "', '" + strUDPFrame.payload.login_ipaddr + "','"+ strUDPFrameInstance + "');";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// General definition used for 1-10 type packets
|
||||||
|
strUDPFramePayload = JsonConvert.SerializeObject(strUDPFrame.payload); // Deserialize payload
|
||||||
|
|
||||||
|
strSQLQueryTxt = "INSERT INTO `pe_DataRaw` (`pe_dataraw_type`,`pe_dataraw_instance`) SELECT '" + strUDPFrameType + "','"+ strUDPFrameInstance + "' FROM DUAL WHERE NOT EXISTS (SELECT * FROM `pe_DataRaw` WHERE `pe_dataraw_type` = '" + strUDPFrameType + "' AND `pe_dataraw_instance` = " + strUDPFrameInstance + ");";
|
||||||
|
strSQLQueryTxt += "UPDATE `pe_DataRaw` SET `pe_dataraw_payload` = JSON_QUOTE('" + strUDPFramePayload + "'), `pe_dataraw_updated`=" + strUDPFrameTimestamp + " WHERE `pe_dataraw_type`=" + strUDPFrameType + " AND `pe_dataraw_instance` = "+ strUDPFrameInstance + ";";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Connect to mysql and execute sql
|
||||||
|
MySqlConnection connMySQL = new MySqlConnection(DatabaseController.strMySQLConnectionString);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Console.WriteLine("Sending data to MySQL - Begin");
|
||||||
|
connMySQL.Open();
|
||||||
|
|
||||||
|
MySqlCommand cmdMySQL = new MySqlCommand(strSQLQueryTxt, connMySQL);
|
||||||
|
MySqlDataReader rdrMySQL = cmdMySQL.ExecuteReader();
|
||||||
|
|
||||||
|
while (rdrMySQL.Read())
|
||||||
|
{
|
||||||
|
Console.WriteLine(rdrMySQL[0] + " -- " + rdrMySQL[1]);
|
||||||
|
}
|
||||||
|
rdrMySQL.Close();
|
||||||
|
PerunHelper.LogHistoryAdd(ref Globals.arrLogHistory, "MySQL updated, package type: " + strUDPFrameType);
|
||||||
|
}
|
||||||
|
catch (ArgumentException a_ex)
|
||||||
|
{
|
||||||
|
// General exception found
|
||||||
|
Console.WriteLine(a_ex.ToString());
|
||||||
|
PerunHelper.LogHistoryAdd(ref Globals.arrLogHistory, "ERROR MySQL - package type: " + strUDPFrameType);
|
||||||
|
}
|
||||||
|
catch (MySqlException m_ex)
|
||||||
|
{
|
||||||
|
// MySQL exception found
|
||||||
|
PerunHelper.LogHistoryAdd(ref Globals.arrLogHistory, "ERROR MySQL - package type: " + strUDPFrameType);
|
||||||
|
switch (m_ex.Number)
|
||||||
|
{
|
||||||
|
case 1042: // Unable to connect to any of the specified MySQL hosts (Check Server,Port)
|
||||||
|
PerunHelper.LogHistoryAdd(ref Globals.arrLogHistory, "ERROR MySQL - unable to connect");
|
||||||
|
break;
|
||||||
|
case 0: // Access denied (Check DB name,username,password)
|
||||||
|
PerunHelper.LogHistoryAdd(ref Globals.arrLogHistory, "ERROR MySQL - access denied");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
PerunHelper.LogHistoryAdd(ref Globals.arrLogHistory, "ERROR MySQL - " + m_ex.Number);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
connMySQL.Close();
|
||||||
|
Console.WriteLine("Sending data to MySQL - Done");
|
||||||
|
}
|
||||||
|
}
|
||||||
7
02_Windows_App/Perun_v1/01_Classes/Globals.cs
Normal file
7
02_Windows_App/Perun_v1/01_Classes/Globals.cs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
// This class gathers all global variables
|
||||||
|
|
||||||
|
internal class Globals
|
||||||
|
{
|
||||||
|
public static string strPerunVersion = "DEBUG"; // Helper for pulling version definition
|
||||||
|
public static string[] arrLogHistory = new string[10]; // Log history for GUI
|
||||||
|
}
|
||||||
13
02_Windows_App/Perun_v1/01_Classes/NativeMethods.cs
Normal file
13
02_Windows_App/Perun_v1/01_Classes/NativeMethods.cs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
// This class just wraps some Win32 stuff that we're going to use for blocking of multiple instances
|
||||||
|
using System;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
internal class NativeMethods
|
||||||
|
{
|
||||||
|
public const int HWND_BROADCAST = 0xffff;
|
||||||
|
public static readonly int WM_SHOWME = RegisterWindowMessage("WM_SHOWME");
|
||||||
|
[DllImport("user32")]
|
||||||
|
public static extern bool PostMessage(IntPtr hwnd, int msg, IntPtr wparam, IntPtr lparam);
|
||||||
|
[DllImport("user32")]
|
||||||
|
public static extern int RegisterWindowMessage(string message);
|
||||||
|
}
|
||||||
26
02_Windows_App/Perun_v1/01_Classes/PerunHelper.cs
Normal file
26
02_Windows_App/Perun_v1/01_Classes/PerunHelper.cs
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
// This class gathers all helper functions
|
||||||
|
using System;
|
||||||
|
|
||||||
|
internal class PerunHelper
|
||||||
|
{
|
||||||
|
public static void LogHistoryAdd(ref string[] arrLogHistory, string strEntryToAdd)
|
||||||
|
{
|
||||||
|
// Add entry to log history and rotate
|
||||||
|
for (int i = 0; i < arrLogHistory.Length - 1; i++)
|
||||||
|
{
|
||||||
|
arrLogHistory[i] = arrLogHistory[i + 1]; // Shift one down
|
||||||
|
}
|
||||||
|
|
||||||
|
arrLogHistory[arrLogHistory.Length - 1] = DateTime.Now.ToString("HH:mm:ss") + " > " + strEntryToAdd; // Add entry at the last position
|
||||||
|
}
|
||||||
|
public static string GetAppVersion(string strBeginning)
|
||||||
|
{
|
||||||
|
// Gets build version
|
||||||
|
if (System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed)
|
||||||
|
{
|
||||||
|
System.Deployment.Application.ApplicationDeployment cd = System.Deployment.Application.ApplicationDeployment.CurrentDeployment;
|
||||||
|
Globals.strPerunVersion = cd.CurrentVersion.ToString();
|
||||||
|
}
|
||||||
|
return strBeginning+"v" + Globals.strPerunVersion;
|
||||||
|
}
|
||||||
|
}
|
||||||
47
02_Windows_App/Perun_v1/01_Classes/Program.cs
Normal file
47
02_Windows_App/Perun_v1/01_Classes/Program.cs
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
using System;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace Perun_v1
|
||||||
|
{
|
||||||
|
static class Program
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Main entry point to app
|
||||||
|
/// </summary>
|
||||||
|
|
||||||
|
// Mutex to block multiple instances
|
||||||
|
static Mutex mutex = new Mutex(true, "{5a710507-92e9-4664-9b91-918b8b82f107}");
|
||||||
|
|
||||||
|
[STAThread]
|
||||||
|
|
||||||
|
static void Main()
|
||||||
|
{
|
||||||
|
// Check if no other instances running
|
||||||
|
if (mutex.WaitOne(TimeSpan.Zero, true))
|
||||||
|
{
|
||||||
|
// Only instance
|
||||||
|
Application.EnableVisualStyles();
|
||||||
|
Application.SetCompatibleTextRenderingDefault(false);
|
||||||
|
Application.ApplicationExit += new EventHandler(Application_ApplicationExit);
|
||||||
|
|
||||||
|
void Application_ApplicationExit(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Properties.Settings.Default.Save(); // We will save settings on exit
|
||||||
|
}
|
||||||
|
Application.Run(new form_Main()); // Run main form
|
||||||
|
mutex.ReleaseMutex(); // Release mutex
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Multiple instance - send our Win32 message to make the currently running instance jump to front
|
||||||
|
NativeMethods.PostMessage(
|
||||||
|
(IntPtr)NativeMethods.HWND_BROADCAST,
|
||||||
|
NativeMethods.WM_SHOWME,
|
||||||
|
IntPtr.Zero,
|
||||||
|
IntPtr.Zero);
|
||||||
|
MessageBox.Show("Only one Perun instance is allowed.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
91
02_Windows_App/Perun_v1/01_Classes/UDPController.cs
Normal file
91
02_Windows_App/Perun_v1/01_Classes/UDPController.cs
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
// This class handles UDP communication
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using System;
|
||||||
|
using System.Net;
|
||||||
|
using System.Net.Sockets;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
internal class UDPController
|
||||||
|
{
|
||||||
|
// Main class for UDP listener
|
||||||
|
public static int intListenPort; // Port to listen at
|
||||||
|
public static bool boolDone; // Helper to exit main loop without killing thread
|
||||||
|
public static UdpClient udpListener; // Listener object
|
||||||
|
public static string[] arrLogHistory; // Log history for GUI
|
||||||
|
public static string[] arrSendBuffer; // Mysql send buffer
|
||||||
|
public static Thread thrUDPListener; // Seperate thread for UDP
|
||||||
|
|
||||||
|
public static void Create(int intListenPort, ref string[] arrLogHistory, ref string[] arrSendBuffer)
|
||||||
|
{
|
||||||
|
// Create class
|
||||||
|
UDPController.intListenPort = intListenPort;
|
||||||
|
UDPController.arrLogHistory = arrLogHistory;
|
||||||
|
UDPController.arrSendBuffer = arrSendBuffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void StopListen()
|
||||||
|
{
|
||||||
|
// FInish listening
|
||||||
|
UDPController.boolDone = true;
|
||||||
|
UDPController.udpListener.Close();
|
||||||
|
UDPController.udpListener = null;
|
||||||
|
|
||||||
|
for (int i = 0; i < arrSendBuffer.Length - 1; i++)
|
||||||
|
{
|
||||||
|
arrSendBuffer[i] = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void StartListen()
|
||||||
|
{
|
||||||
|
Console.WriteLine("UDP Listen start");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Start listening to UDP
|
||||||
|
|
||||||
|
udpListener = new UdpClient(intListenPort);
|
||||||
|
IPEndPoint ipendpointGroupEP = new IPEndPoint(IPAddress.Loopback, intListenPort);
|
||||||
|
string strReceivedData;
|
||||||
|
byte[] arrReceiveByteArray;
|
||||||
|
|
||||||
|
// Start the main loop
|
||||||
|
UDPController.boolDone = false;
|
||||||
|
while (!UDPController.boolDone)
|
||||||
|
{
|
||||||
|
// Start listening
|
||||||
|
Console.WriteLine("UDP: Waiting for packet");
|
||||||
|
arrReceiveByteArray = udpListener.Receive(ref ipendpointGroupEP);
|
||||||
|
strReceivedData = Encoding.ASCII.GetString(arrReceiveByteArray, 0, arrReceiveByteArray.Length);
|
||||||
|
Console.WriteLine("Sender: {0} Payload: {1}", ipendpointGroupEP.ToString(), strReceivedData);
|
||||||
|
|
||||||
|
// Add to log history and rotate
|
||||||
|
dynamic dynamicRawUDPFrame = JsonConvert.DeserializeObject(strReceivedData); // Deserialize received frame
|
||||||
|
string strRawUDPFrameType = dynamicRawUDPFrame.type;
|
||||||
|
PerunHelper.LogHistoryAdd(ref arrLogHistory, "UDP packet received, type: " + strRawUDPFrameType);
|
||||||
|
|
||||||
|
// Add to mySQL send buffer (find first empty slot)
|
||||||
|
for (int i = 0; i < arrSendBuffer.Length - 1; i++)
|
||||||
|
{
|
||||||
|
if (arrSendBuffer[i] == null)
|
||||||
|
{
|
||||||
|
arrSendBuffer[i] = strReceivedData;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
udpListener.Close(); // Close port
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
// General exception found
|
||||||
|
if (e.HResult != -2147467259) {
|
||||||
|
Console.WriteLine(e.ToString());
|
||||||
|
PerunHelper.LogHistoryAdd(ref arrLogHistory, "ERROR UDP - port may be in use");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Console.WriteLine("UDP listen stop");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -58,6 +58,8 @@
|
|||||||
this.openFileDialog_SRS = new System.Windows.Forms.OpenFileDialog();
|
this.openFileDialog_SRS = new System.Windows.Forms.OpenFileDialog();
|
||||||
this.openFileDialog_LotATC = new System.Windows.Forms.OpenFileDialog();
|
this.openFileDialog_LotATC = new System.Windows.Forms.OpenFileDialog();
|
||||||
this.tim_10000ms = new System.Windows.Forms.Timer(this.components);
|
this.tim_10000ms = new System.Windows.Forms.Timer(this.components);
|
||||||
|
this.tim_200ms = new System.Windows.Forms.Timer(this.components);
|
||||||
|
this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);
|
||||||
this.con_GroupBox_1.SuspendLayout();
|
this.con_GroupBox_1.SuspendLayout();
|
||||||
this.con_GroupBox_2.SuspendLayout();
|
this.con_GroupBox_2.SuspendLayout();
|
||||||
this.con_GroupBox_3.SuspendLayout();
|
this.con_GroupBox_3.SuspendLayout();
|
||||||
@@ -68,16 +70,7 @@
|
|||||||
this.con_List_Received.Enabled = false;
|
this.con_List_Received.Enabled = false;
|
||||||
this.con_List_Received.FormattingEnabled = true;
|
this.con_List_Received.FormattingEnabled = true;
|
||||||
this.con_List_Received.Items.AddRange(new object[] {
|
this.con_List_Received.Items.AddRange(new object[] {
|
||||||
"Loading",
|
"Welcome to Perun for DCS World!"});
|
||||||
"Loading",
|
|
||||||
"Loading",
|
|
||||||
"Loading",
|
|
||||||
"Loading",
|
|
||||||
"Loading",
|
|
||||||
"Loading",
|
|
||||||
"Loading",
|
|
||||||
"Loading",
|
|
||||||
"Loading"});
|
|
||||||
this.con_List_Received.Location = new System.Drawing.Point(6, 19);
|
this.con_List_Received.Location = new System.Drawing.Point(6, 19);
|
||||||
this.con_List_Received.Name = "con_List_Received";
|
this.con_List_Received.Name = "con_List_Received";
|
||||||
this.con_List_Received.Size = new System.Drawing.Size(307, 134);
|
this.con_List_Received.Size = new System.Drawing.Size(307, 134);
|
||||||
@@ -149,6 +142,7 @@
|
|||||||
//
|
//
|
||||||
// con_txt_mysql_port
|
// con_txt_mysql_port
|
||||||
//
|
//
|
||||||
|
this.con_txt_mysql_port.Enabled = false;
|
||||||
this.con_txt_mysql_port.Location = new System.Drawing.Point(106, 45);
|
this.con_txt_mysql_port.Location = new System.Drawing.Point(106, 45);
|
||||||
this.con_txt_mysql_port.Name = "con_txt_mysql_port";
|
this.con_txt_mysql_port.Name = "con_txt_mysql_port";
|
||||||
this.con_txt_mysql_port.Size = new System.Drawing.Size(207, 20);
|
this.con_txt_mysql_port.Size = new System.Drawing.Size(207, 20);
|
||||||
@@ -321,6 +315,15 @@
|
|||||||
this.tim_10000ms.Interval = 30000;
|
this.tim_10000ms.Interval = 30000;
|
||||||
this.tim_10000ms.Tick += new System.EventHandler(this.tim_10000ms_Tick);
|
this.tim_10000ms.Tick += new System.EventHandler(this.tim_10000ms_Tick);
|
||||||
//
|
//
|
||||||
|
// tim_200ms
|
||||||
|
//
|
||||||
|
this.tim_200ms.Tick += new System.EventHandler(this.tim_200ms_Tick);
|
||||||
|
//
|
||||||
|
// notifyIcon1
|
||||||
|
//
|
||||||
|
this.notifyIcon1.Text = "notifyIcon1";
|
||||||
|
this.notifyIcon1.Visible = true;
|
||||||
|
//
|
||||||
// form_Main
|
// form_Main
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||||
@@ -383,6 +386,8 @@
|
|||||||
private System.Windows.Forms.Timer tim_10000ms;
|
private System.Windows.Forms.Timer tim_10000ms;
|
||||||
private System.Windows.Forms.Label label6;
|
private System.Windows.Forms.Label label6;
|
||||||
private System.Windows.Forms.TextBox con_txt_mysql_port;
|
private System.Windows.Forms.TextBox con_txt_mysql_port;
|
||||||
|
private System.Windows.Forms.Timer tim_200ms;
|
||||||
|
private System.Windows.Forms.NotifyIcon notifyIcon1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
376
02_Windows_App/Perun_v1/02_Forms/form_Main.cs
Normal file
376
02_Windows_App/Perun_v1/02_Forms/form_Main.cs
Normal file
@@ -0,0 +1,376 @@
|
|||||||
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace Perun_v1
|
||||||
|
{
|
||||||
|
public partial class form_Main : Form
|
||||||
|
{
|
||||||
|
// Variable definitions
|
||||||
|
public string[] arrSendBuffer = new string[100]; // Mysql send buffer
|
||||||
|
public bool boolLetMeOut = false; // Helper to handle system tray
|
||||||
|
|
||||||
|
// ################################ Main ################################
|
||||||
|
private void form_Main_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
// Form loaded - fill controls with default values
|
||||||
|
|
||||||
|
Globals.arrLogHistory[0] = DateTime.Now.ToString("HH:mm:ss") + " > " + "Perun started";
|
||||||
|
form_Main_LoadSettings(); // Load settings
|
||||||
|
this.Text = PerunHelper.GetAppVersion(this.Text + " - "); // Display build version in title bar
|
||||||
|
}
|
||||||
|
|
||||||
|
public form_Main()
|
||||||
|
{
|
||||||
|
// Form init
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ################################ Helpers ################################
|
||||||
|
private void form_Main_LoadSettings()
|
||||||
|
{
|
||||||
|
// Loads settings
|
||||||
|
con_txt_mysql_database.Text = Properties.Settings.Default.MYSQL_DB;
|
||||||
|
con_txt_mysql_username.Text = Properties.Settings.Default.MYSQL_User;
|
||||||
|
con_txt_mysql_password.Text = Properties.Settings.Default.MYSQL_Password;
|
||||||
|
con_txt_mysql_server.Text = Properties.Settings.Default.MYSQL_Server;
|
||||||
|
con_txt_mysql_port.Text = Properties.Settings.Default.MYSQL_Port;
|
||||||
|
con_txt_3rd_lotatc.Text = Properties.Settings.Default.OTHER_LOTATC_FILE;
|
||||||
|
con_txt_3rd_srs.Text = Properties.Settings.Default.OTHER_SRS_FILE;
|
||||||
|
con_check_3rd_lotatc.Checked = Properties.Settings.Default.OTHER_LOTATC_USE;
|
||||||
|
con_check_3rd_srs.Checked = Properties.Settings.Default.OTHER_SRS_USE;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void form_Main_SaveSettings()
|
||||||
|
{
|
||||||
|
// Saves settings
|
||||||
|
Properties.Settings.Default.MYSQL_Server = con_txt_mysql_database.Text;
|
||||||
|
Properties.Settings.Default.MYSQL_DB = con_txt_mysql_database.Text;
|
||||||
|
Properties.Settings.Default.MYSQL_User = con_txt_mysql_username.Text;
|
||||||
|
Properties.Settings.Default.MYSQL_Password = con_txt_mysql_password.Text;
|
||||||
|
Properties.Settings.Default.MYSQL_Port = con_txt_mysql_port.Text;
|
||||||
|
Properties.Settings.Default.MYSQL_Server = con_txt_mysql_server.Text;
|
||||||
|
Properties.Settings.Default.MYSQL_Port = con_txt_mysql_port.Text;
|
||||||
|
Properties.Settings.Default.OTHER_LOTATC_FILE = con_txt_3rd_lotatc.Text;
|
||||||
|
Properties.Settings.Default.OTHER_SRS_FILE = con_txt_3rd_srs.Text;
|
||||||
|
Properties.Settings.Default.OTHER_LOTATC_USE = con_check_3rd_lotatc.Checked;
|
||||||
|
Properties.Settings.Default.OTHER_SRS_USE = con_check_3rd_srs.Checked;
|
||||||
|
|
||||||
|
Properties.Settings.Default.Save();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void form_Main_DisableControls()
|
||||||
|
{
|
||||||
|
// Disables controls
|
||||||
|
con_Button_Listen_ON.Enabled = false;
|
||||||
|
con_Button_Listen_OFF.Enabled = true;
|
||||||
|
con_txt_mysql_database.Enabled = false;
|
||||||
|
con_txt_mysql_username.Enabled = false;
|
||||||
|
con_txt_mysql_password.Enabled = false;
|
||||||
|
con_txt_mysql_server.Enabled = false;
|
||||||
|
con_txt_mysql_port.Enabled = false;
|
||||||
|
con_txt_3rd_lotatc.Enabled = false;
|
||||||
|
con_txt_3rd_srs.Enabled = false;
|
||||||
|
con_check_3rd_lotatc.Enabled = false;
|
||||||
|
con_check_3rd_srs.Enabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void form_Main_EnableControls()
|
||||||
|
{
|
||||||
|
// Enables controls
|
||||||
|
con_Button_Listen_ON.Enabled = true;
|
||||||
|
con_Button_Listen_OFF.Enabled = false;
|
||||||
|
|
||||||
|
con_txt_mysql_database.Enabled = true;
|
||||||
|
con_txt_mysql_username.Enabled = true;
|
||||||
|
con_txt_mysql_password.Enabled = true;
|
||||||
|
//con_txt_mysql_port.Enabled = true; // TBD - protect against writting text in the port field
|
||||||
|
con_txt_mysql_server.Enabled = true;
|
||||||
|
con_txt_3rd_lotatc.Enabled = true;
|
||||||
|
con_txt_3rd_srs.Enabled = true;
|
||||||
|
con_check_3rd_lotatc.Enabled = true;
|
||||||
|
con_check_3rd_srs.Enabled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ################################ User input ################################
|
||||||
|
private void con_Button_Listen_ON_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
// Start listening
|
||||||
|
UDPController.Create(48620, ref Globals.arrLogHistory, ref arrSendBuffer);
|
||||||
|
UDPController.thrUDPListener = new Thread(UDPController.StartListen);
|
||||||
|
UDPController.thrUDPListener.Start();
|
||||||
|
UDPController.thrUDPListener.Name = "UDPThread";
|
||||||
|
|
||||||
|
form_Main_DisableControls(); // Disable controlls
|
||||||
|
form_Main_SaveSettings(); // Save settings
|
||||||
|
|
||||||
|
// Prepare connection string
|
||||||
|
DatabaseController.strMySQLConnectionString = "server=" + con_txt_mysql_server.Text + ";user=" + con_txt_mysql_username.Text + ";database=" + con_txt_mysql_database.Text + ";port=" + con_txt_mysql_port.Text + ";password=" + con_txt_mysql_password.Text;
|
||||||
|
|
||||||
|
// Start timmers
|
||||||
|
tim_200ms.Enabled = true;
|
||||||
|
tim_1000ms.Enabled = true;
|
||||||
|
tim_10000ms.Enabled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void con_Button_Listen_OFF_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
// Stop listening
|
||||||
|
try
|
||||||
|
{
|
||||||
|
UDPController.StopListen();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine(ex.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
form_Main_EnableControls(); // Enable controls
|
||||||
|
|
||||||
|
// Stop timmers
|
||||||
|
tim_1000ms.Enabled = false;
|
||||||
|
tim_10000ms.Enabled = false;
|
||||||
|
tim_200ms.Enabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void con_lab_github_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
|
||||||
|
{
|
||||||
|
// Open default browser with link to Perun repo
|
||||||
|
ProcessStartInfo sInfo = new ProcessStartInfo("https://github.com/szporwolik/perun");
|
||||||
|
Process.Start(sInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void con_txt_3rd_srs_Click(object sender, MouseEventArgs e)
|
||||||
|
{
|
||||||
|
// Chose SRS Json file
|
||||||
|
if (openFileDialog_SRS.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
con_txt_3rd_srs.Text = openFileDialog_SRS.FileName;
|
||||||
|
con_check_3rd_srs.Checked = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
con_txt_3rd_srs.Text = "";
|
||||||
|
con_check_3rd_srs.Checked = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void con_txt_3rd_lotatc_Click(object sender, MouseEventArgs e)
|
||||||
|
{
|
||||||
|
// Chose LotATC Json file
|
||||||
|
if (openFileDialog_LotATC.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
con_txt_3rd_lotatc.Text = openFileDialog_LotATC.FileName;
|
||||||
|
con_check_3rd_lotatc.Checked = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
con_txt_3rd_lotatc.Text = "";
|
||||||
|
con_check_3rd_lotatc.Checked = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ################################ Form state ################################
|
||||||
|
private void con_Button_Quit_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
// Close app
|
||||||
|
DialogResult dialogResult = MessageBox.Show("Are you sure to exit Perun?", "Question", MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Question);
|
||||||
|
if (dialogResult == DialogResult.Yes)
|
||||||
|
{
|
||||||
|
form_Main_SaveSettings();
|
||||||
|
|
||||||
|
boolLetMeOut = true; // Save settings on exit
|
||||||
|
this.Close(); // Allow to exit application
|
||||||
|
}
|
||||||
|
else if (dialogResult == DialogResult.No)
|
||||||
|
{
|
||||||
|
//do nothing
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void WndProc(ref Message m)
|
||||||
|
{
|
||||||
|
// Try to run of 2nd instance
|
||||||
|
if (m.Msg == NativeMethods.WM_SHOWME)
|
||||||
|
{
|
||||||
|
form_Main_BringFromTray();
|
||||||
|
}
|
||||||
|
base.WndProc(ref m);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void form_Main_SendToTray()
|
||||||
|
{
|
||||||
|
// Sends app to system tray
|
||||||
|
trayIconMain.Visible = true;
|
||||||
|
this.WindowState = FormWindowState.Minimized;
|
||||||
|
this.ShowInTaskbar = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void form_Main_BringFromTray()
|
||||||
|
{
|
||||||
|
// Sends app from system tray
|
||||||
|
trayIconMain.Visible = false;
|
||||||
|
this.WindowState = FormWindowState.Normal;
|
||||||
|
this.ShowInTaskbar = true;
|
||||||
|
|
||||||
|
if (WindowState == FormWindowState.Minimized)
|
||||||
|
{
|
||||||
|
WindowState = FormWindowState.Normal;
|
||||||
|
}
|
||||||
|
// get our current "TopMost" value (ours will always be false though)
|
||||||
|
bool top = TopMost;
|
||||||
|
// make our form jump to the top of everything
|
||||||
|
TopMost = true;
|
||||||
|
// set it back to whatever it was
|
||||||
|
TopMost = top;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void form_Main_FormClosing(object sender, FormClosingEventArgs e)
|
||||||
|
{
|
||||||
|
// Minimize to try on clicking "X"
|
||||||
|
if (e.CloseReason == CloseReason.UserClosing && !boolLetMeOut)
|
||||||
|
{
|
||||||
|
e.Cancel = true;
|
||||||
|
form_Main_SendToTray(); // Send app to system tray
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void trayIconMain_MouseDoubleClick(object sender, MouseEventArgs e)
|
||||||
|
{
|
||||||
|
// Maximize from tray
|
||||||
|
form_Main_BringFromTray(); // Bring app from system tray
|
||||||
|
}
|
||||||
|
|
||||||
|
// ################################ Timers ################################
|
||||||
|
private void timer1_Tick(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
// Main timer to sync GUI with background tasks and flush buffers
|
||||||
|
// Refresh Log Window
|
||||||
|
con_List_Received.Items.Clear();
|
||||||
|
foreach (string i in Globals.arrLogHistory)
|
||||||
|
{
|
||||||
|
if (i != null)
|
||||||
|
{
|
||||||
|
con_List_Received.Items.Add(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void tim_200ms_Tick(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
// Send buffer to MySQL
|
||||||
|
for (int i = 0; i < arrSendBuffer.Length - 1; i++)
|
||||||
|
{
|
||||||
|
if (arrSendBuffer[i] != null)
|
||||||
|
{
|
||||||
|
DatabaseController.SendToMySql(arrSendBuffer[i]);
|
||||||
|
arrSendBuffer[i] = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void tim_10000ms_Tick(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
// Main timer to send JSON files to MySQL
|
||||||
|
string strSRSJson = "";
|
||||||
|
string strLotATCJson = "";
|
||||||
|
|
||||||
|
bool boolSRSdefault = true;
|
||||||
|
bool boolLotATCdefault = true;
|
||||||
|
|
||||||
|
// Handle SRS
|
||||||
|
if (con_check_3rd_srs.Checked)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
strSRSJson = System.IO.File.ReadAllText(con_txt_3rd_srs.Text);
|
||||||
|
dynamic raw_lotatc = JsonConvert.DeserializeObject(strSRSJson);
|
||||||
|
|
||||||
|
for (int i = 0; i < raw_lotatc.Count; i++)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (raw_lotatc[i].RadioInfo != null)
|
||||||
|
{
|
||||||
|
|
||||||
|
int temp = raw_lotatc[i].RadioInfo.radios.Count - 1;
|
||||||
|
for (int j = temp; j >= 0; j--)
|
||||||
|
{
|
||||||
|
raw_lotatc[i].RadioInfo.radios[j].enc.Parent.Remove();
|
||||||
|
raw_lotatc[i].RadioInfo.radios[j].encKey.Parent.Remove();
|
||||||
|
raw_lotatc[i].RadioInfo.radios[j].encMode.Parent.Remove();
|
||||||
|
raw_lotatc[i].RadioInfo.radios[j].freqMax.Parent.Remove();
|
||||||
|
raw_lotatc[i].RadioInfo.radios[j].freqMin.Parent.Remove();
|
||||||
|
raw_lotatc[i].RadioInfo.radios[j].modulation.Parent.Remove();
|
||||||
|
raw_lotatc[i].RadioInfo.radios[j].freqMode.Parent.Remove();
|
||||||
|
raw_lotatc[i].RadioInfo.radios[j].volMode.Parent.Remove();
|
||||||
|
raw_lotatc[i].RadioInfo.radios[j].expansion.Parent.Remove();
|
||||||
|
raw_lotatc[i].RadioInfo.radios[j].channel.Parent.Remove();
|
||||||
|
raw_lotatc[i].RadioInfo.radios[j].simul.Parent.Remove();
|
||||||
|
|
||||||
|
if (raw_lotatc[i].RadioInfo.radios[j].name == "No Radio")
|
||||||
|
{
|
||||||
|
raw_lotatc[i].RadioInfo.radios[j].Remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
raw_lotatc[i].ClientChannelId.Parent.Remove();
|
||||||
|
raw_lotatc[i].RadioInfo.simultaneousTransmission.Parent.Remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (raw_lotatc.Count > 0)
|
||||||
|
{
|
||||||
|
strSRSJson = JsonConvert.SerializeObject(raw_lotatc);
|
||||||
|
strSRSJson = "{'type':'100','instance':'1','payload':'" + strSRSJson + "'}";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
strSRSJson = "{'type':'100','instance':'1','payload':{'ignore':'false'}}"; // No SRS clients connected
|
||||||
|
}
|
||||||
|
boolSRSdefault = false;
|
||||||
|
PerunHelper.LogHistoryAdd(ref Globals.arrLogHistory, "SRS data loaded");
|
||||||
|
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
PerunHelper.LogHistoryAdd(ref Globals.arrLogHistory, "SRS data ERROR");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
if (boolSRSdefault)
|
||||||
|
{
|
||||||
|
strSRSJson = "{'type':'100','instance':'1','payload':{'ignore':'true'}}";
|
||||||
|
}
|
||||||
|
DatabaseController.SendToMySql(strSRSJson);
|
||||||
|
|
||||||
|
// Handle LotATC
|
||||||
|
if (con_check_3rd_lotatc.Checked)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
strLotATCJson = System.IO.File.ReadAllText(con_txt_3rd_lotatc.Text);
|
||||||
|
dynamic raw_srs = JsonConvert.DeserializeObject(strLotATCJson);
|
||||||
|
|
||||||
|
strLotATCJson = "{'type':'101','instance':'1','payload':'" + strLotATCJson + "'}";
|
||||||
|
boolLotATCdefault = false;
|
||||||
|
PerunHelper.LogHistoryAdd(ref Globals.arrLogHistory, "LotATC data loaded");
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
PerunHelper.LogHistoryAdd(ref Globals.arrLogHistory, "LotATC data ERROR");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (boolLotATCdefault)
|
||||||
|
{
|
||||||
|
strLotATCJson = "{'type':'101','instance':'1','payload':{'ignore':'true'}}"; // No LotATC controller connected
|
||||||
|
}
|
||||||
|
DatabaseController.SendToMySql(strLotATCJson);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -416,6 +416,12 @@
|
|||||||
<metadata name="tim_10000ms.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
<metadata name="tim_10000ms.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
<value>563, 19</value>
|
<value>563, 19</value>
|
||||||
</metadata>
|
</metadata>
|
||||||
|
<metadata name="tim_200ms.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
<value>687, 19</value>
|
||||||
|
</metadata>
|
||||||
|
<metadata name="notifyIcon1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
<value>797, 19</value>
|
||||||
|
</metadata>
|
||||||
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
<value>
|
<value>
|
||||||
AAABAAEAQD8AAAEAIAAgQQAAFgAAACgAAABAAAAAfgAAAAEAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
AAABAAEAQD8AAAEAIAAgQQAAFgAAACgAAABAAAAAfgAAAAEAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
||||||
|
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
@@ -12,21 +12,30 @@
|
|||||||
<FileAlignment>512</FileAlignment>
|
<FileAlignment>512</FileAlignment>
|
||||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||||
<Deterministic>true</Deterministic>
|
<Deterministic>true</Deterministic>
|
||||||
<IsWebBootstrapper>false</IsWebBootstrapper>
|
<IsWebBootstrapper>true</IsWebBootstrapper>
|
||||||
<PublishUrl>C:\Users\simpo\Desktop\Perun\</PublishUrl>
|
<PublishUrl>ftp://s18.mydevil.net/perun/</PublishUrl>
|
||||||
<Install>true</Install>
|
<Install>true</Install>
|
||||||
<InstallFrom>Disk</InstallFrom>
|
<InstallFrom>Web</InstallFrom>
|
||||||
<UpdateEnabled>false</UpdateEnabled>
|
<UpdateEnabled>true</UpdateEnabled>
|
||||||
<UpdateMode>Foreground</UpdateMode>
|
<UpdateMode>Foreground</UpdateMode>
|
||||||
<UpdateInterval>7</UpdateInterval>
|
<UpdateInterval>7</UpdateInterval>
|
||||||
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
|
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
|
||||||
<UpdatePeriodically>false</UpdatePeriodically>
|
<UpdatePeriodically>false</UpdatePeriodically>
|
||||||
<UpdateRequired>false</UpdateRequired>
|
<UpdateRequired>false</UpdateRequired>
|
||||||
<MapFileExtensions>true</MapFileExtensions>
|
<MapFileExtensions>true</MapFileExtensions>
|
||||||
<AutorunEnabled>true</AutorunEnabled>
|
<InstallUrl>http://share.porwolik.com/ftp/perun/</InstallUrl>
|
||||||
<ApplicationRevision>1</ApplicationRevision>
|
<SupportUrl>https://github.com/szporwolik/perun</SupportUrl>
|
||||||
<ApplicationVersion>0.3.0.%2a</ApplicationVersion>
|
<ErrorReportUrl>https://github.com/szporwolik/perun</ErrorReportUrl>
|
||||||
|
<TargetCulture>en</TargetCulture>
|
||||||
|
<ProductName>Perun for DCS World</ProductName>
|
||||||
|
<PublisherName>szporwolik</PublisherName>
|
||||||
|
<SuiteName>Perun</SuiteName>
|
||||||
|
<CreateWebPageOnPublish>true</CreateWebPageOnPublish>
|
||||||
|
<WebPage>Perun.htm</WebPage>
|
||||||
|
<ApplicationRevision>0</ApplicationRevision>
|
||||||
|
<ApplicationVersion>0.5.0.%2a</ApplicationVersion>
|
||||||
<UseApplicationTrust>false</UseApplicationTrust>
|
<UseApplicationTrust>false</UseApplicationTrust>
|
||||||
|
<CreateDesktopShortcut>true</CreateDesktopShortcut>
|
||||||
<PublishWizardCompleted>true</PublishWizardCompleted>
|
<PublishWizardCompleted>true</PublishWizardCompleted>
|
||||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
@@ -52,7 +61,7 @@
|
|||||||
</DocumentationFile>
|
</DocumentationFile>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<ApplicationIcon>perun_logo.ico</ApplicationIcon>
|
<ApplicationIcon>03_Resources\perun_logo.ico</ApplicationIcon>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<ManifestCertificateThumbprint>2ACE4C8C2C325A04CA5986B1CD76744B4B03755D</ManifestCertificateThumbprint>
|
<ManifestCertificateThumbprint>2ACE4C8C2C325A04CA5986B1CD76744B4B03755D</ManifestCertificateThumbprint>
|
||||||
@@ -73,6 +82,7 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetZone>LocalIntranet</TargetZone>
|
<TargetZone>LocalIntranet</TargetZone>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
<PropertyGroup />
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<ApplicationManifest>Properties\app.manifest</ApplicationManifest>
|
<ApplicationManifest>Properties\app.manifest</ApplicationManifest>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
@@ -106,15 +116,20 @@
|
|||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="form_Main.cs">
|
<Compile Include="01_Classes\UDPController.cs" />
|
||||||
|
<Compile Include="01_Classes\Globals.cs" />
|
||||||
|
<Compile Include="01_Classes\DatabaseController.cs" />
|
||||||
|
<Compile Include="01_Classes\PerunHelper.cs" />
|
||||||
|
<Compile Include="01_Classes\NativeMethods.cs" />
|
||||||
|
<Compile Include="02_Forms\form_Main.cs">
|
||||||
<SubType>Form</SubType>
|
<SubType>Form</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="form_Main.Designer.cs">
|
<Compile Include="02_Forms\form_Main.Designer.cs">
|
||||||
<DependentUpon>form_Main.cs</DependentUpon>
|
<DependentUpon>form_Main.cs</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="Program.cs" />
|
<Compile Include="01_Classes\Program.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<EmbeddedResource Include="form_Main.resx">
|
<EmbeddedResource Include="02_Forms\form_Main.resx">
|
||||||
<DependentUpon>form_Main.cs</DependentUpon>
|
<DependentUpon>form_Main.cs</DependentUpon>
|
||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
<EmbeddedResource Include="Properties\Resources.resx">
|
<EmbeddedResource Include="Properties\Resources.resx">
|
||||||
@@ -127,8 +142,8 @@
|
|||||||
<DependentUpon>Resources.resx</DependentUpon>
|
<DependentUpon>Resources.resx</DependentUpon>
|
||||||
<DesignTime>True</DesignTime>
|
<DesignTime>True</DesignTime>
|
||||||
</Compile>
|
</Compile>
|
||||||
<None Include="packages.config" />
|
<None Include="00_Config\packages.config" />
|
||||||
<None Include="Perun_v1_TemporaryKey.pfx" />
|
<None Include="00_Config\Perun_v1_TemporaryKey.pfx" />
|
||||||
<None Include="Properties\app.manifest" />
|
<None Include="Properties\app.manifest" />
|
||||||
<None Include="Properties\Settings.settings">
|
<None Include="Properties\Settings.settings">
|
||||||
<Generator>SettingsSingleFileGenerator</Generator>
|
<Generator>SettingsSingleFileGenerator</Generator>
|
||||||
@@ -141,7 +156,7 @@
|
|||||||
</Compile>
|
</Compile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="App.config" />
|
<None Include="00_Config\App.config" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<BootstrapperPackage Include=".NETFramework,Version=v4.6.1">
|
<BootstrapperPackage Include=".NETFramework,Version=v4.6.1">
|
||||||
@@ -156,10 +171,8 @@
|
|||||||
</BootstrapperPackage>
|
</BootstrapperPackage>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Include="perun_logo.ico" />
|
<Content Include="03_Resources\perun_logo.ico" />
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<Folder Include="Resources\" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup />
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
</Project>
|
</Project>
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Windows.Forms;
|
|
||||||
|
|
||||||
namespace Perun_v1
|
|
||||||
{
|
|
||||||
|
|
||||||
static class Program
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Główny punkt wejścia dla aplikacji.
|
|
||||||
/// </summary>
|
|
||||||
[STAThread]
|
|
||||||
|
|
||||||
|
|
||||||
static void Main()
|
|
||||||
{
|
|
||||||
Application.EnableVisualStyles();
|
|
||||||
Application.SetCompatibleTextRenderingDefault(false);
|
|
||||||
|
|
||||||
Application.ApplicationExit += new EventHandler(Application_ApplicationExit);
|
|
||||||
|
|
||||||
void Application_ApplicationExit(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
Properties.Settings.Default.Save();
|
|
||||||
}
|
|
||||||
|
|
||||||
Application.Run(new form_Main());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -33,7 +33,7 @@ using System.Runtime.InteropServices;
|
|||||||
// Możesz określić wszystkie wartości lub użyć domyślnych numerów kompilacji i poprawki
|
// Możesz określić wszystkie wartości lub użyć domyślnych numerów kompilacji i poprawki
|
||||||
// przy użyciu symbolu „*”, tak jak pokazano poniżej:
|
// przy użyciu symbolu „*”, tak jak pokazano poniżej:
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("0.3.0.0")]
|
[assembly: AssemblyVersion("0.5.0.0")]
|
||||||
[assembly: AssemblyFileVersion("0.3.0.0")]
|
[assembly: AssemblyFileVersion("0.5.0.0")]
|
||||||
[assembly: NeutralResourcesLanguage("en")]
|
[assembly: NeutralResourcesLanguage("en")]
|
||||||
|
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ namespace Perun_v1.Properties {
|
|||||||
|
|
||||||
[global::System.Configuration.UserScopedSettingAttribute()]
|
[global::System.Configuration.UserScopedSettingAttribute()]
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||||
[global::System.Configuration.DefaultSettingValueAttribute("")]
|
[global::System.Configuration.DefaultSettingValueAttribute("3306")]
|
||||||
public string MYSQL_Port {
|
public string MYSQL_Port {
|
||||||
get {
|
get {
|
||||||
return ((string)(this["MYSQL_Port"]));
|
return ((string)(this["MYSQL_Port"]));
|
||||||
|
|||||||
@@ -27,7 +27,7 @@
|
|||||||
<Value Profile="(Default)">False</Value>
|
<Value Profile="(Default)">False</Value>
|
||||||
</Setting>
|
</Setting>
|
||||||
<Setting Name="MYSQL_Port" Type="System.String" Scope="User">
|
<Setting Name="MYSQL_Port" Type="System.String" Scope="User">
|
||||||
<Value Profile="(Default)" />
|
<Value Profile="(Default)">3306</Value>
|
||||||
</Setting>
|
</Setting>
|
||||||
</Settings>
|
</Settings>
|
||||||
</SettingsFile>
|
</SettingsFile>
|
||||||
@@ -1,460 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Net;
|
|
||||||
using System.Net.Sockets;
|
|
||||||
using System.Reflection;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Windows.Forms;
|
|
||||||
|
|
||||||
using MySql.Data.MySqlClient;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
using Newtonsoft.Json.Linq;
|
|
||||||
|
|
||||||
namespace Perun_v1
|
|
||||||
{
|
|
||||||
public partial class form_Main : Form
|
|
||||||
{
|
|
||||||
|
|
||||||
// Variable definitions
|
|
||||||
public Thread thread_UDPListener; // Seperate thread for UDP
|
|
||||||
public class_UDPListener UDPListener; // Helper class for UDP comunication
|
|
||||||
public string[] LogHistory=new string[10]; // Log history for GUI
|
|
||||||
public string[] SendBuffer=new string[10]; // Mysql send buffer
|
|
||||||
public bool LetMeOut=false; // Helper to handle system tray
|
|
||||||
public string MySql_connStr; // MySQL connection string
|
|
||||||
|
|
||||||
public static void LogHistoryAdd(ref string[] LogHistory, string Comment)
|
|
||||||
{
|
|
||||||
// Add to log history and rotate
|
|
||||||
for (int i = 0; i < LogHistory.Length - 1; i++)
|
|
||||||
{
|
|
||||||
LogHistory[i] = LogHistory[i + 1];
|
|
||||||
}
|
|
||||||
LogHistory[9] = DateTime.Now.ToString("HH:mm:ss") + " > " + Comment;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SendToMySql(string raw_udp_frame)
|
|
||||||
{
|
|
||||||
// Main function to send data to mysql
|
|
||||||
dynamic udp_frame = JsonConvert.DeserializeObject(raw_udp_frame);
|
|
||||||
|
|
||||||
// Cut raw data to type and paylod for proper mysql insert
|
|
||||||
string type = udp_frame.type;
|
|
||||||
string payload = "";
|
|
||||||
string sql = "";
|
|
||||||
|
|
||||||
// Modify specific
|
|
||||||
if (type == "1") // Inject app version information
|
|
||||||
{
|
|
||||||
Assembly assembly = Assembly.GetExecutingAssembly();
|
|
||||||
FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(assembly.Location);
|
|
||||||
string version = fileVersionInfo.ProductVersion;
|
|
||||||
udp_frame.payload["v_win"] = "v"+version;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Specific SQL
|
|
||||||
if(type == "50")
|
|
||||||
{
|
|
||||||
sql = "INSERT INTO `pe_LogChat` (`pe_LogChat_id`, `pe_LogChat_playerid`, `pe_LogChat_msg`, `pe_LogChat_all`) VALUES (NULL, '"+udp_frame.payload.player+ "', '" + udp_frame.payload.msg + "', '" + udp_frame.payload.all + "');";
|
|
||||||
}
|
|
||||||
else if(type == "51")
|
|
||||||
{
|
|
||||||
sql = "INSERT INTO `pe_LogEvent` (`pe_LogEvent_id`, `pe_LogEvent_datetime`, `pe_LogEvent_type`, `pe_LogEvent_content`) VALUES (NULL, CURRENT_TIMESTAMP, '" + udp_frame.payload.log_type + "', '" + udp_frame.payload.log_content + "');";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
payload = JsonConvert.SerializeObject(udp_frame.payload);
|
|
||||||
sql = "INSERT INTO pe_DataRaw(pe_dataraw_type,pe_dataraw_payload) VALUES (" + type + ",JSON_QUOTE('" + payload + "')) ON DUPLICATE KEY UPDATE pe_dataraw_payload = JSON_QUOTE('" + payload + "')";
|
|
||||||
}
|
|
||||||
|
|
||||||
// Connect to mysql
|
|
||||||
MySqlConnection conn = new MySqlConnection(MySql_connStr);
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Console.WriteLine("Sending data to MySQL - Begin");
|
|
||||||
conn.Open();
|
|
||||||
|
|
||||||
MySqlCommand cmd = new MySqlCommand(sql, conn);
|
|
||||||
MySqlDataReader rdr = cmd.ExecuteReader();
|
|
||||||
|
|
||||||
while (rdr.Read())
|
|
||||||
{
|
|
||||||
Console.WriteLine(rdr[0] + " -- " + rdr[1]);
|
|
||||||
}
|
|
||||||
rdr.Close();
|
|
||||||
LogHistoryAdd(ref LogHistory, "MySQL updated, package type: "+ type);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Console.WriteLine(ex.ToString());
|
|
||||||
LogHistoryAdd(ref LogHistory, "ERROR: MySQL");
|
|
||||||
}
|
|
||||||
|
|
||||||
conn.Close();
|
|
||||||
Console.WriteLine("Sending data to MySQL - Done");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class class_UDPListener
|
|
||||||
{
|
|
||||||
// Main class for UDP listener
|
|
||||||
int listenPort; // Port to listen at
|
|
||||||
public bool done; // Helper to exit main loop without killing thread
|
|
||||||
public UdpClient listener; // Listener object
|
|
||||||
public string[] LogHistory; // Log history for GUI
|
|
||||||
public string[] SendBuffer; // Mysql send buffer
|
|
||||||
|
|
||||||
public class_UDPListener(int port, ref string[] LogHistory, ref string[] SendBuffer)
|
|
||||||
{
|
|
||||||
// Create clas - NOTE that there is reference passing
|
|
||||||
this.listenPort = port;
|
|
||||||
this.LogHistory = LogHistory;
|
|
||||||
this.SendBuffer = SendBuffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void StartListen()
|
|
||||||
{
|
|
||||||
// Start listening to UDP
|
|
||||||
this.done = false;
|
|
||||||
listener = new UdpClient(listenPort);
|
|
||||||
IPEndPoint groupEP = new IPEndPoint(IPAddress.Loopback, listenPort);
|
|
||||||
string received_data;
|
|
||||||
byte[] receive_byte_array;
|
|
||||||
|
|
||||||
Console.WriteLine("UDP Listen start");
|
|
||||||
try
|
|
||||||
{
|
|
||||||
while (!done)
|
|
||||||
{
|
|
||||||
Console.WriteLine("UDP: Waiting for packet");
|
|
||||||
receive_byte_array = listener.Receive(ref groupEP);
|
|
||||||
received_data = Encoding.ASCII.GetString(receive_byte_array, 0, receive_byte_array.Length);
|
|
||||||
|
|
||||||
Console.WriteLine("Sender: {0} Payload: {1}", groupEP.ToString(), received_data);
|
|
||||||
|
|
||||||
// Add to log history and rotate
|
|
||||||
dynamic udp_frame = JsonConvert.DeserializeObject(received_data);
|
|
||||||
string type = udp_frame.type;
|
|
||||||
LogHistoryAdd(ref LogHistory, "UDP packet received, type: "+ type);
|
|
||||||
|
|
||||||
// Add to mySQL send buffer and rotate
|
|
||||||
for (int i = 0; i < SendBuffer.Length - 1; i++)
|
|
||||||
{
|
|
||||||
SendBuffer[i] = SendBuffer[i + 1];
|
|
||||||
}
|
|
||||||
SendBuffer[9] = received_data;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Console.WriteLine(e.ToString());
|
|
||||||
}
|
|
||||||
Console.WriteLine("UDP listen stop");
|
|
||||||
listener.Close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public form_Main()
|
|
||||||
{
|
|
||||||
// Form init
|
|
||||||
InitializeComponent();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void form_Main_Load(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
// Form loaded - fill controls with default values
|
|
||||||
LogHistory[0] = DateTime.Now.ToString("HH:mm:ss") + " > " + "Perun loaded...";
|
|
||||||
|
|
||||||
// Load settings
|
|
||||||
con_txt_mysql_database.Text = Properties.Settings.Default.MYSQL_DB;
|
|
||||||
con_txt_mysql_username.Text = Properties.Settings.Default.MYSQL_User;
|
|
||||||
con_txt_mysql_password.Text = Properties.Settings.Default.MYSQL_Password;
|
|
||||||
con_txt_mysql_server.Text = Properties.Settings.Default.MYSQL_Server;
|
|
||||||
con_txt_mysql_port.Text = Properties.Settings.Default.MYSQL_Port;
|
|
||||||
con_txt_3rd_lotatc.Text = Properties.Settings.Default.OTHER_LOTATC_FILE;
|
|
||||||
con_txt_3rd_srs.Text = Properties.Settings.Default.OTHER_SRS_FILE;
|
|
||||||
con_check_3rd_lotatc.Checked = Properties.Settings.Default.OTHER_LOTATC_USE;
|
|
||||||
con_check_3rd_srs.Checked = Properties.Settings.Default.OTHER_SRS_USE;
|
|
||||||
|
|
||||||
// Version to title header
|
|
||||||
Assembly assembly = Assembly.GetExecutingAssembly();
|
|
||||||
FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(assembly.Location);
|
|
||||||
this.Text = this.Text + " - v" + fileVersionInfo.ProductVersion;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void con_Button_Listen_ON_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
// Start listening
|
|
||||||
UDPListener = new class_UDPListener(48620,ref LogHistory, ref SendBuffer);
|
|
||||||
thread_UDPListener = new Thread(UDPListener.StartListen);
|
|
||||||
thread_UDPListener.Start();
|
|
||||||
|
|
||||||
// Update form controls
|
|
||||||
con_Button_Listen_ON.Enabled = false;
|
|
||||||
con_Button_Listen_OFF.Enabled = true;
|
|
||||||
con_txt_mysql_database.Enabled = false;
|
|
||||||
con_txt_mysql_username.Enabled = false;
|
|
||||||
con_txt_mysql_password.Enabled = false;
|
|
||||||
con_txt_mysql_server.Enabled = false;
|
|
||||||
con_txt_mysql_port.Enabled = false;
|
|
||||||
con_txt_3rd_lotatc.Enabled = false;
|
|
||||||
con_txt_3rd_srs.Enabled = false;
|
|
||||||
con_check_3rd_lotatc.Enabled = false;
|
|
||||||
con_check_3rd_srs.Enabled = false;
|
|
||||||
|
|
||||||
// Save settings
|
|
||||||
Properties.Settings.Default.MYSQL_Server = con_txt_mysql_database.Text;
|
|
||||||
Properties.Settings.Default.MYSQL_DB = con_txt_mysql_database.Text;
|
|
||||||
Properties.Settings.Default.MYSQL_User = con_txt_mysql_username.Text;
|
|
||||||
Properties.Settings.Default.MYSQL_Password = con_txt_mysql_password.Text;
|
|
||||||
Properties.Settings.Default.MYSQL_Port = con_txt_mysql_port.Text;
|
|
||||||
Properties.Settings.Default.MYSQL_Server = con_txt_mysql_server.Text;
|
|
||||||
Properties.Settings.Default.MYSQL_Port = con_txt_mysql_port.Text;
|
|
||||||
Properties.Settings.Default.OTHER_LOTATC_FILE = con_txt_3rd_lotatc.Text;
|
|
||||||
Properties.Settings.Default.OTHER_SRS_FILE = con_txt_3rd_srs.Text;
|
|
||||||
Properties.Settings.Default.OTHER_LOTATC_USE = con_check_3rd_lotatc.Checked;
|
|
||||||
Properties.Settings.Default.OTHER_SRS_USE = con_check_3rd_srs.Checked;
|
|
||||||
|
|
||||||
// Prepare connection string
|
|
||||||
MySql_connStr = "server="+con_txt_mysql_server.Text+";user="+con_txt_mysql_username.Text+";database="+con_txt_mysql_database.Text+";port="+ con_txt_mysql_port.Text + ";password="+con_txt_mysql_password.Text;
|
|
||||||
|
|
||||||
// Start timmers
|
|
||||||
tim_1000ms.Enabled = true;
|
|
||||||
tim_10000ms.Enabled = true;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void con_Button_Listen_OFF_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
// Stop listening
|
|
||||||
UDPListener.listener.Close();
|
|
||||||
|
|
||||||
// Update form controls
|
|
||||||
con_Button_Listen_ON.Enabled = true;
|
|
||||||
con_Button_Listen_OFF.Enabled = false;
|
|
||||||
|
|
||||||
con_txt_mysql_database.Enabled = true;
|
|
||||||
con_txt_mysql_username.Enabled = true;
|
|
||||||
con_txt_mysql_password.Enabled = true;
|
|
||||||
con_txt_mysql_port.Enabled = true;
|
|
||||||
con_txt_mysql_server.Enabled = true;
|
|
||||||
con_txt_3rd_lotatc.Enabled = true;
|
|
||||||
con_txt_3rd_srs.Enabled = true;
|
|
||||||
con_check_3rd_lotatc.Enabled = true;
|
|
||||||
con_check_3rd_srs.Enabled = true;
|
|
||||||
|
|
||||||
// Stop timmers
|
|
||||||
tim_1000ms.Enabled = false;
|
|
||||||
tim_10000ms.Enabled = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void timer1_Tick(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
// Main timer to sync GUI with background tasks and flush buffers
|
|
||||||
// Refresh Log Window
|
|
||||||
con_List_Received.Items.Clear();
|
|
||||||
foreach (string i in LogHistory)
|
|
||||||
{
|
|
||||||
if (i != null)
|
|
||||||
{
|
|
||||||
con_List_Received.Items.Add(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Send buffer to MySQL
|
|
||||||
for (int i = 0; i < SendBuffer.Length - 1; i++)
|
|
||||||
{
|
|
||||||
if (SendBuffer[i] != null)
|
|
||||||
{
|
|
||||||
SendToMySql(SendBuffer[i]);
|
|
||||||
SendBuffer[i] = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void con_lab_github_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
|
|
||||||
{
|
|
||||||
// Open default browser with link to Perun repo
|
|
||||||
ProcessStartInfo sInfo = new ProcessStartInfo("https://github.com/szporwolik/perun");
|
|
||||||
Process.Start(sInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void con_Button_Quit_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
// Close app
|
|
||||||
|
|
||||||
DialogResult dialogResult = MessageBox.Show("Are you sure to exit Perun?", "Question", MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Question);
|
|
||||||
if (dialogResult == DialogResult.Yes)
|
|
||||||
{
|
|
||||||
// Save settings on exit
|
|
||||||
Properties.Settings.Default.MYSQL_Server = con_txt_mysql_database.Text;
|
|
||||||
Properties.Settings.Default.MYSQL_DB = con_txt_mysql_database.Text;
|
|
||||||
Properties.Settings.Default.MYSQL_User = con_txt_mysql_username.Text;
|
|
||||||
Properties.Settings.Default.MYSQL_Password = con_txt_mysql_password.Text;
|
|
||||||
Properties.Settings.Default.MYSQL_Port = con_txt_mysql_port.Text;
|
|
||||||
Properties.Settings.Default.MYSQL_Server = con_txt_mysql_server.Text;
|
|
||||||
Properties.Settings.Default.MYSQL_Port = con_txt_mysql_port.Text;
|
|
||||||
Properties.Settings.Default.OTHER_LOTATC_FILE = con_txt_3rd_lotatc.Text;
|
|
||||||
Properties.Settings.Default.OTHER_SRS_FILE = con_txt_3rd_srs.Text;
|
|
||||||
Properties.Settings.Default.OTHER_LOTATC_USE = con_check_3rd_lotatc.Checked;
|
|
||||||
Properties.Settings.Default.OTHER_SRS_USE = con_check_3rd_srs.Checked;
|
|
||||||
|
|
||||||
Properties.Settings.Default.Save();
|
|
||||||
|
|
||||||
LetMeOut = true;
|
|
||||||
this.Close();
|
|
||||||
}
|
|
||||||
else if (dialogResult == DialogResult.No)
|
|
||||||
{
|
|
||||||
//do nothing
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void form_Main_FormClosing(object sender, FormClosingEventArgs e)
|
|
||||||
{
|
|
||||||
// Minimize to try
|
|
||||||
if (e.CloseReason == CloseReason.UserClosing && !LetMeOut)
|
|
||||||
{
|
|
||||||
e.Cancel = true;
|
|
||||||
trayIconMain.Visible = true;
|
|
||||||
this.WindowState = FormWindowState.Minimized;
|
|
||||||
this.ShowInTaskbar = false;
|
|
||||||
//this.Hide();
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void trayIconMain_MouseDoubleClick(object sender, MouseEventArgs e)
|
|
||||||
{
|
|
||||||
// Maximize from try
|
|
||||||
trayIconMain.Visible = false;
|
|
||||||
this.WindowState = FormWindowState.Normal;
|
|
||||||
this.ShowInTaskbar = true;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void con_txt_3rd_srs_Click(object sender, MouseEventArgs e)
|
|
||||||
{
|
|
||||||
// Chose SRS Json file
|
|
||||||
if (openFileDialog_SRS.ShowDialog() == DialogResult.OK)
|
|
||||||
{
|
|
||||||
con_txt_3rd_srs.Text = openFileDialog_SRS.FileName;
|
|
||||||
con_check_3rd_srs.Checked = true;
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
con_txt_3rd_srs.Text = "";
|
|
||||||
con_check_3rd_srs.Checked = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void con_txt_3rd_lotatc_Click(object sender, MouseEventArgs e)
|
|
||||||
{
|
|
||||||
// Chose LotATC Json file
|
|
||||||
if (openFileDialog_LotATC.ShowDialog() == DialogResult.OK)
|
|
||||||
{
|
|
||||||
con_txt_3rd_lotatc.Text = openFileDialog_LotATC.FileName;
|
|
||||||
con_check_3rd_lotatc.Checked = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
con_txt_3rd_lotatc.Text = "";
|
|
||||||
con_check_3rd_lotatc.Checked = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void tim_10000ms_Tick(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
// Main timer to send JSON files to MySQL
|
|
||||||
string strSRSJson ="";
|
|
||||||
string strLotATCJson="";
|
|
||||||
|
|
||||||
bool SRSdefault = true;
|
|
||||||
bool LotATCdefault = true;
|
|
||||||
|
|
||||||
// Handle SRS
|
|
||||||
if (con_check_3rd_srs.Checked)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
strSRSJson = System.IO.File.ReadAllText(con_txt_3rd_srs.Text);
|
|
||||||
dynamic raw_lotatc = JsonConvert.DeserializeObject(strSRSJson);
|
|
||||||
|
|
||||||
for (int i = 0; i < raw_lotatc.Count; i++)
|
|
||||||
{
|
|
||||||
|
|
||||||
int temp = raw_lotatc[i].RadioInfo.radios.Count - 1;
|
|
||||||
for (int j = temp; j >= 0; j--)
|
|
||||||
{
|
|
||||||
raw_lotatc[i].RadioInfo.radios[j].enc.Parent.Remove();
|
|
||||||
raw_lotatc[i].RadioInfo.radios[j].encKey.Parent.Remove();
|
|
||||||
raw_lotatc[i].RadioInfo.radios[j].encMode.Parent.Remove();
|
|
||||||
raw_lotatc[i].RadioInfo.radios[j].freqMax.Parent.Remove();
|
|
||||||
raw_lotatc[i].RadioInfo.radios[j].freqMin.Parent.Remove();
|
|
||||||
raw_lotatc[i].RadioInfo.radios[j].modulation.Parent.Remove();
|
|
||||||
raw_lotatc[i].RadioInfo.radios[j].freqMode.Parent.Remove();
|
|
||||||
raw_lotatc[i].RadioInfo.radios[j].volMode.Parent.Remove();
|
|
||||||
raw_lotatc[i].RadioInfo.radios[j].expansion.Parent.Remove();
|
|
||||||
raw_lotatc[i].RadioInfo.radios[j].channel.Parent.Remove();
|
|
||||||
raw_lotatc[i].RadioInfo.radios[j].simul.Parent.Remove();
|
|
||||||
|
|
||||||
if (raw_lotatc[i].RadioInfo.radios[j].name == "No Radio")
|
|
||||||
{
|
|
||||||
raw_lotatc[i].RadioInfo.radios[j].Remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
raw_lotatc[i].ClientChannelId.Parent.Remove();
|
|
||||||
raw_lotatc[i].RadioInfo.simultaneousTransmission.Parent.Remove();
|
|
||||||
}
|
|
||||||
|
|
||||||
strSRSJson = JsonConvert.SerializeObject(raw_lotatc);
|
|
||||||
strSRSJson = "{'type':'100','payload':'" + strSRSJson + "'}";
|
|
||||||
SRSdefault = false;
|
|
||||||
LogHistoryAdd(ref LogHistory, "SRS data loaded");
|
|
||||||
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
LogHistoryAdd(ref LogHistory, "SRS data ERROR");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
if(SRSdefault)
|
|
||||||
{
|
|
||||||
strSRSJson = "{'type':'100','payload':{'ignore':'true'}}";
|
|
||||||
}
|
|
||||||
SendToMySql(strSRSJson);
|
|
||||||
|
|
||||||
// Handle LotATC
|
|
||||||
if (con_check_3rd_lotatc.Checked)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
strLotATCJson = System.IO.File.ReadAllText(con_txt_3rd_lotatc.Text);
|
|
||||||
dynamic raw_srs = JsonConvert.DeserializeObject(strLotATCJson);
|
|
||||||
|
|
||||||
strLotATCJson = "{'type':'101','payload':'" + strLotATCJson + "'}";
|
|
||||||
LotATCdefault = false;
|
|
||||||
LogHistoryAdd(ref LogHistory, "LotATC data loaded");
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
LogHistoryAdd(ref LogHistory, "LotATC data ERROR");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (LotATCdefault)
|
|
||||||
{
|
|
||||||
strLotATCJson = "{'type':'101','payload':{'ignore':'true'}}";
|
|
||||||
}
|
|
||||||
SendToMySql(strLotATCJson);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
169
03_MySQL/m1081_perun.sql
Normal file
169
03_MySQL/m1081_perun.sql
Normal file
@@ -0,0 +1,169 @@
|
|||||||
|
|
||||||
|
|
||||||
|
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
|
||||||
|
SET AUTOCOMMIT = 0;
|
||||||
|
START TRANSACTION;
|
||||||
|
SET time_zone = "+00:00";
|
||||||
|
|
||||||
|
|
||||||
|
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
|
||||||
|
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
|
||||||
|
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
|
||||||
|
/*!40101 SET NAMES utf8mb4 */;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Baza danych: `m1081_perun`
|
||||||
|
--
|
||||||
|
CREATE DATABASE IF NOT EXISTS `m1081_perun` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
|
||||||
|
USE `m1081_perun`;
|
||||||
|
|
||||||
|
-- --------------------------------------------------------
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Struktura tabeli dla tabeli `pe_DataMissionHashes`
|
||||||
|
--
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS `pe_DataMissionHashes`;
|
||||||
|
CREATE TABLE IF NOT EXISTS `pe_DataMissionHashes` (
|
||||||
|
`pe_DataMissionHashes_id` bigint(20) NOT NULL AUTO_INCREMENT,
|
||||||
|
`pe_DataMissionHashes_instance` smallint(5) UNSIGNED NOT NULL,
|
||||||
|
`pe_DataMissionHashes_hash` varchar(150) NOT NULL,
|
||||||
|
`pe_DataMissionHashes_datetime` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
PRIMARY KEY (`pe_DataMissionHashes_id`),
|
||||||
|
UNIQUE KEY `UNIQUE_hash` (`pe_DataMissionHashes_hash`),
|
||||||
|
KEY `pe_DataMissionHashes_instance` (`pe_DataMissionHashes_instance`)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||||
|
|
||||||
|
-- --------------------------------------------------------
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Struktura tabeli dla tabeli `pe_DataPlayers`
|
||||||
|
--
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS `pe_DataPlayers`;
|
||||||
|
CREATE TABLE IF NOT EXISTS `pe_DataPlayers` (
|
||||||
|
`pe_DataPlayers_id` bigint(20) NOT NULL AUTO_INCREMENT,
|
||||||
|
`pe_DataPlayers_ucid` varchar(150) NOT NULL,
|
||||||
|
`pe_DataPlayers_lastip` varchar(100) NOT NULL,
|
||||||
|
`pe_DataPlayers_lastname` varchar(150) NOT NULL,
|
||||||
|
`pe_DataPlayers_updated` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
PRIMARY KEY (`pe_DataPlayers_id`),
|
||||||
|
UNIQUE KEY `UNIQUE_UCID` (`pe_DataPlayers_ucid`)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||||
|
|
||||||
|
-- --------------------------------------------------------
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Struktura tabeli dla tabeli `pe_DataRaw`
|
||||||
|
--
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS `pe_DataRaw`;
|
||||||
|
CREATE TABLE IF NOT EXISTS `pe_DataRaw` (
|
||||||
|
`pe_dataraw_type` tinyint(4) NOT NULL,
|
||||||
|
`pe_dataraw_instance` smallint(5) UNSIGNED NOT NULL,
|
||||||
|
`pe_dataraw_payload` text NOT NULL,
|
||||||
|
`pe_dataraw_updated` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
PRIMARY KEY (`pe_dataraw_type`,`pe_dataraw_instance`)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||||
|
|
||||||
|
-- --------------------------------------------------------
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Struktura tabeli dla tabeli `pe_LogChat`
|
||||||
|
--
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS `pe_LogChat`;
|
||||||
|
CREATE TABLE IF NOT EXISTS `pe_LogChat` (
|
||||||
|
`pe_LogChat_id` bigint(20) NOT NULL AUTO_INCREMENT,
|
||||||
|
`pe_LogChat_datetime` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
`pe_LogChat_missionhash_id` bigint(20) DEFAULT NULL,
|
||||||
|
`pe_LogChat_playerid` varchar(100) NOT NULL,
|
||||||
|
`pe_LogChat_msg` text NOT NULL,
|
||||||
|
`pe_LogChat_all` varchar(10) NOT NULL,
|
||||||
|
PRIMARY KEY (`pe_LogChat_id`),
|
||||||
|
KEY `pe_LogChat_missionhash_id` (`pe_LogChat_missionhash_id`),
|
||||||
|
KEY `pe_LogChat_playerid` (`pe_LogChat_playerid`)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||||
|
|
||||||
|
-- --------------------------------------------------------
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Struktura tabeli dla tabeli `pe_LogEvent`
|
||||||
|
--
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS `pe_LogEvent`;
|
||||||
|
CREATE TABLE IF NOT EXISTS `pe_LogEvent` (
|
||||||
|
`pe_LogEvent_id` bigint(20) NOT NULL AUTO_INCREMENT,
|
||||||
|
`pe_LogEvent_missionhash_id` bigint(20) DEFAULT NULL,
|
||||||
|
`pe_LogEvent_datetime` datetime DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
`pe_LogEvent_type` varchar(100) NOT NULL,
|
||||||
|
`pe_LogEvent_content` text NOT NULL,
|
||||||
|
`pe_LogEvent_arg1` varchar(150) DEFAULT NULL,
|
||||||
|
`pe_LogEvent_arg2` varchar(150) DEFAULT NULL,
|
||||||
|
PRIMARY KEY (`pe_LogEvent_id`),
|
||||||
|
KEY `pe_LogEvent_missionhash_id` (`pe_LogEvent_missionhash_id`)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||||
|
|
||||||
|
-- --------------------------------------------------------
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Struktura tabeli dla tabeli `pe_LogLogins`
|
||||||
|
--
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS `pe_LogLogins`;
|
||||||
|
CREATE TABLE IF NOT EXISTS `pe_LogLogins` (
|
||||||
|
`pe_LogLogins_id` bigint(20) NOT NULL AUTO_INCREMENT,
|
||||||
|
`pe_LogLogins_datetime` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
`pe_LogLogins_instance` smallint(5) UNSIGNED NOT NULL,
|
||||||
|
`pe_LogLogins_playerid` bigint(20) DEFAULT NULL,
|
||||||
|
`pe_LogLogins_name` varchar(150) NOT NULL,
|
||||||
|
`pe_LogLogins_ip` varchar(100) NOT NULL,
|
||||||
|
PRIMARY KEY (`pe_LogLogins_id`),
|
||||||
|
KEY `pe_LogLogins_playerid` (`pe_LogLogins_playerid`)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||||
|
|
||||||
|
-- --------------------------------------------------------
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Struktura tabeli dla tabeli `pe_LogStats`
|
||||||
|
--
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS `pe_LogStats`;
|
||||||
|
CREATE TABLE IF NOT EXISTS `pe_LogStats` (
|
||||||
|
`pe_LogStats_id` bigint(20) NOT NULL AUTO_INCREMENT,
|
||||||
|
`pe_LogStats_missionhash_id` bigint(20) DEFAULT NULL,
|
||||||
|
`pe_LogStats_datetime` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
`pe_LogStats_playerid` bigint(20) DEFAULT NULL,
|
||||||
|
`pe_LogStats_type` varchar(50) DEFAULT NULL,
|
||||||
|
`pe_LogStats_debug` text,
|
||||||
|
`pe_LogStats_dcs` text,
|
||||||
|
`pe_LogStats_perun` text,
|
||||||
|
`ps_kills` int(11) UNSIGNED NOT NULL DEFAULT '0',
|
||||||
|
`ps_pvp` int(11) UNSIGNED NOT NULL DEFAULT '0',
|
||||||
|
`ps_deaths` int(11) UNSIGNED NOT NULL DEFAULT '0',
|
||||||
|
`ps_ejections` int(11) UNSIGNED NOT NULL DEFAULT '0',
|
||||||
|
`ps_crashes` int(11) UNSIGNED NOT NULL DEFAULT '0',
|
||||||
|
`ps_teamkills` int(11) UNSIGNED NOT NULL DEFAULT '0',
|
||||||
|
`ps_kills_planes` int(11) UNSIGNED NOT NULL DEFAULT '0',
|
||||||
|
`ps_kills_helicopters` int(11) UNSIGNED NOT NULL DEFAULT '0',
|
||||||
|
`ps_kills_air_defense` int(11) UNSIGNED NOT NULL DEFAULT '0',
|
||||||
|
`ps_kills_armor` int(11) UNSIGNED NOT NULL DEFAULT '0',
|
||||||
|
`ps_kills_unarmed` int(11) UNSIGNED NOT NULL DEFAULT '0',
|
||||||
|
`ps_kills_infantry` int(11) UNSIGNED NOT NULL DEFAULT '0',
|
||||||
|
`ps_kills_ships` int(11) UNSIGNED NOT NULL DEFAULT '0',
|
||||||
|
`ps_kills_other` int(11) UNSIGNED NOT NULL DEFAULT '0',
|
||||||
|
`ps_airfield_takeoffs` int(11) UNSIGNED NOT NULL DEFAULT '0',
|
||||||
|
`ps_airfield_landings` int(11) UNSIGNED NOT NULL DEFAULT '0',
|
||||||
|
`ps_ship_takeoffs` int(11) UNSIGNED NOT NULL DEFAULT '0',
|
||||||
|
`ps_ship_landings` int(11) UNSIGNED NOT NULL DEFAULT '0',
|
||||||
|
`ps_farp_takeoffs` int(11) UNSIGNED NOT NULL DEFAULT '0',
|
||||||
|
`ps_farp_landings` int(11) UNSIGNED NOT NULL DEFAULT '0',
|
||||||
|
PRIMARY KEY (`pe_LogStats_id`),
|
||||||
|
UNIQUE KEY `UNIQUE_STATS_PER_MISSION_AND_UCID_AND_TYPE` (`pe_LogStats_playerid`,`pe_LogStats_missionhash_id`,`pe_LogStats_type`) USING BTREE,
|
||||||
|
KEY `pe_LogStats_type` (`pe_LogStats_type`)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||||
|
COMMIT;
|
||||||
|
|
||||||
|
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
|
||||||
|
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
|
||||||
|
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
||||||
60
README.md
60
README.md
@@ -1,11 +1,18 @@
|
|||||||
|

|
||||||
|

|
||||||
|

|
||||||
|
|
||||||
|
|
||||||
# Perun for DCS World
|
# Perun for DCS World
|
||||||
|
|
||||||
This toolset extracts data from DCS World server and export it to local json file and UDP port. **Optional** windows app puts JSON data to MySQL database.
|
This toolset extracts data from DCS World server and sends information to the local Json file and UDP port for further processing.
|
||||||
Additionaly windows app can be used to merge LotATC and DCS SRS data in one database making Perun for DCS World ultimate integration tool for server admins.
|
|
||||||
|
|
||||||
## Getting Started
|
Provided windows app puts received UDP packets to MySQL database. Additionaly Perun windows application can be used to merge LotATC and DCS SRS data in one database making Perun for DCS World wannabe ultimate integration tool for the server admins.
|
||||||
|
|
||||||
You can use this toolkit with or without Windows app. Simple DCS export scripts will create JSON file which can be used for further processing, by default this file is created in Scripts\Json folder located in your Saved Games DCS folder tree.
|
However, this software is intended to be used by experienced users - the output is Json data and MySQL; you will need to process/display it yourself.
|
||||||
|
|
||||||
|

|
||||||
|

|
||||||
|
|
||||||
### Prerequisites
|
### Prerequisites
|
||||||
|
|
||||||
@@ -13,38 +20,43 @@ Core:
|
|||||||
* For JSON Export:
|
* For JSON Export:
|
||||||
* DCS World stable or DCS World beta
|
* DCS World stable or DCS World beta
|
||||||
* **(Optional)** For MySQL Export:
|
* **(Optional)** For MySQL Export:
|
||||||
* MySQL server with read/write access
|
* MySQL server with read/write access (tested with v5.7.21)
|
||||||
|
* .NET Framework 4.6.1
|
||||||
|
|
||||||
3rd party support:
|
3rd party applications support:
|
||||||
* for [DCS SRS](https://github.com/ciribob/DCS-SimpleRadioStandalone/releases) integration location of the clients-list.json file and SRS configuration with JSON data export enabled - see [SRS documentation](https://github.com/ciribob/DCS-SimpleRadioStandalone/wiki)
|
* for [DCS SRS](https://github.com/ciribob/DCS-SimpleRadioStandalone/releases) integration location of the clients-list.json file will be required (by default: SRS Server folder), "Auto Export List" option has to be enabled - see [SRS documentation](https://github.com/ciribob/DCS-SimpleRadioStandalone/wiki)
|
||||||
* for [LotATC](https://www.lotatc.com/) integration location of the stats.json file and LotATC configuration with JSON data export enabled - see [LotATC documentation](https://www.lotatc.com/documentation/server_configuration.html)
|
* for [LotATC](https://www.lotatc.com/) you will need location of stats.json file and proper LotATC configuration with JSON data export enabled - see [LotATC documentation](https://www.lotatc.com/documentation/server_configuration.html)
|
||||||
|
|
||||||
### Installing
|
### Installing
|
||||||
|
|
||||||
* Download latest [release](https://github.com/szporwolik/perun/releases) **optionaly** together with Win32 binary file for MySQL export
|
* Download latest [release](https://github.com/szporwolik/perun/releases), **optionaly** together with windows binary file for MySQL export - [DOWNLOAD](http://share.porwolik.com/ftp/perun/Perun.htm)
|
||||||
* Copy contents of DCS folder to you \Scripts folder (inside DCS folder in your Saved Games)
|
* Copy contents of [01_DCS](https://github.com/szporwolik/perun/tree/master/01_DCS) to your \Scripts folder (located inside DCS folder in your Saved Games)
|
||||||
* create MySQL server 03_MySQL folder contains creation SQL file
|
* **optionaly** Create MySQL server using SQL script located in [03_MySQL](https://github.com/szporwolik/perun/tree/master/03_MySQL)
|
||||||
* **optionaly** Run the Win32 application
|
* **optionaly** Run the Win32 application
|
||||||
* set MySQL connection data
|
* set MySQL connection data
|
||||||
* point LotATC json file location
|
* point LotATC json file location
|
||||||
* point DCS SRS json file location
|
* point DCS SRS json file location
|
||||||
* click connect and leave the app running
|
* click connect and leave the app running in the background
|
||||||
* Start DCS World and host multiplayer session
|
* Start DCS World and host multiplayer session
|
||||||
* by default the JSON is written into Scripts\Json folder located in your Saved Games DCS folder tree
|
* by default the JSON is written into Scripts\Json folder located in your Saved Games DCS folder tree
|
||||||
* by default the UDP port 48620 is in use as target
|
* by default the UDP port 48620 is in use as target port
|
||||||
|
* Data shall be filling your MySQL database
|
||||||
|
|
||||||
## Data packets
|
## Data packets
|
||||||
* ID: 1, contains version information
|
* ```ID: 1```, contains version/diagnostic information
|
||||||
* ID: 2, contains status data in the following sections
|
* ```ID: 2```, contains status data in the following sections
|
||||||
* mission
|
* mission - minimal information about mission
|
||||||
* players
|
* players - connected players
|
||||||
* ID: 3, available slots list and coalitions
|
* ```ID: 3```, available slots list and coalitions
|
||||||
* coalitions
|
* coalitions - available coalitions
|
||||||
* slots
|
* slots - available slots
|
||||||
* ID: 50, chat event
|
* ```ID: 4```, stores mission data **WIP: not yet implemented**
|
||||||
* ID: 51, game event
|
* ```ID: 50```, chat event
|
||||||
* ID: 100, DCS SRS's client-list.json
|
* ```ID: 51```, game event
|
||||||
* ID: 101, LotATC's stats.json
|
* ```ID: 52```, player stats **WIP: not yet implemented**
|
||||||
|
* ```ID: 53```, player login to DCS server
|
||||||
|
* ```ID: 100```, DCS SRS's client-list.json
|
||||||
|
* ```ID: 101```, LotATC's stats.json
|
||||||
|
|
||||||
## Built With
|
## Built With
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user