diff --git a/01_DCS/Hooks/Perun.lua b/01_DCS/Hooks/Perun.lua index 1b27995..d9cbc10 100644 --- a/01_DCS/Hooks/Perun.lua +++ b/01_DCS/Hooks/Perun.lua @@ -9,9 +9,9 @@ package.cpath = package.cpath..";"..lfs.currentdir().."/LuaSocket/?.dll" Perun.RefreshStatus = 15 -- (int) [default: 60] Base refresh rate in seconds to send status update Perun.RefreshMission = 60 -- (int) [default: 120] Refresh rate in seconds to send mission information -Perun.TCPTargetPort = 48622 -- (int) [default: 48621] TCP port to send data to +Perun.TCPTargetPort = 48620 -- (int) [default: 48621] TCP port to send data to Perun.TCPPerunHost = "localhost" -- (string) [default: "localhost"] IP adress of the Perun instance or "localhost" -Perun.Instance = 2 -- (int) [default: 1] Id number of instance (if multiple DCS instances are to run at the same PC) +Perun.Instance = 1 -- (int) [default: 1] Id number of instance (if multiple DCS instances are to run at the same PC) Perun.JsonStatusLocation = "Scripts\\Json\\" -- (string) [default: "Scripts\\Json\\"] Folder relative do user's SaveGames DCS folder -> status file updated each RefreshMission Perun.MissionStartNoDeathWindow = 300 -- (int) [default: 300] Number of secounds after mission start when death of the pilot will not go to statistics, shall avoid death penalty during spawning DCS bugs Perun.DebugMode = 2 -- (int) [0 (default),1,2] Value greater than 0 will display Perun information in DCS log file, values: 1 - minimal verbose, 2 - all log information will be logged @@ -22,24 +22,27 @@ Perun.MOTD_L2 = "Wymagamy obecnosci DCS SRS oraz TeamSpeak - szczegoly na forum" -- ###################### END OF SETTINGS - DO NOT MODIFY OUTSIDE THIS SECTION ###################### -- Variable init -Perun.Version = "v0.9.1" +Perun.Version = "v0.9.2" Perun.StatusData = {} Perun.SlotsData = {} Perun.MissionData = {} Perun.ServerData = {} Perun.StatData = {} Perun.StatDataLastType = {} +Perun.PlayersTableCache = {} Perun.MissionHash="" +Perun.ReconnectTimeout = 30 Perun.lastSentStatus = 0 Perun.lastSentMission = 0 Perun.lastSentKeepAlive = 0 Perun.lastConnectionError = 0 -Perun.lastReconnect = 0 -Perun.SendRetries = 3 +Perun.lastTimer = 0 +Perun.lastReconnect = (-1) * Perun.ReconnectTimeout +Perun.SendRetries = 2 Perun.RefreshKeepAlive = 3 Perun.JsonStatusLocation = lfs.writedir() .. Perun.JsonStatusLocation Perun.socket = require("socket") -Perun.IsServer = true --DCS.isServer( ) -- TBD looks like DCS API error, always returning True +Perun.IsServer = DCS.isServer( ) Perun.ConnectionError = "[Perun] ERROR: Connection broken - contact server admin!" -- ################################ Helper function definitions ################################ @@ -134,7 +137,7 @@ function stripChars(str) end Perun.GetCategory = function(id) - -- Helper function returns object category basing on I via https://pastebin.com/GUAXrd2U TBD: rewrite + -- Helper function returns object category basing on https://pastebin.com/GUAXrd2U local _killed_target_category = DCS.getUnitTypeAttribute(id, "category") -- Below, simple hack to get the propper category when DCS API is not returning correct value @@ -179,11 +182,15 @@ end Perun.GetMulticrewAllParameters = function (PlayerId) -- Gets all multicrew parameters local _result = "" - local _player_slot=net.get_player_info(PlayerId, 'slot') local _master_type= "?" local _master_slot = nil local _sub_slot = nil + local _player_slot = net.get_player_info(PlayerId, 'slot') + if not _player_slot then + _player_slot=Perun.PlayersTableCache["p"..PlayerId].slot + end + if _player_slot and _player_slot ~= '' and not (string.find(_player_slot, 'red') or string.find(_player_slot, 'blue')) then -- Player took model _master_slot = _player_slot @@ -214,6 +221,9 @@ Perun.GetMulticrewAllParameters = function (PlayerId) end _master_slot = -1 _sub_slot = 0 + else + _master_slot = -1 + _sub_slot = -1 end return _master_type,_master_slot,_sub_slot end @@ -278,6 +288,29 @@ Perun.GetMulticrewCrewNames = function (owner_playerID) return _result_text end +Perun.GetTakeOffLandingEvent = function (takeoff,location) + -- Get correct event type for statistics basing on objecy which served as runway/farp + local _operation = "" + if takeoff == true then + _operation="tookoff_" + else + _operation="landing_" + end + + local _temp_type = "" + if string.find(location, "FARP",1,true) then + _temp_type = "FARP" + elseif string.find(location, "CVN-74 John C. Stennis",1,true) or string.find(location, "LHA-1 Tarawa",1,true) or string.find(location, "SHIP",1,true) then + _temp_type = "SHIP" + elseif location ~= "" then + _temp_type = "AIRFIELD" + else + _temp_type = "OTHER" + end + + return _operation .. _temp_type +end + -- ################################ TCP Connection ################################ Perun.ConnectToPerun = function () @@ -293,8 +326,9 @@ Perun.ConnectToPerun = function () else -- Connected Perun.AddLog("Success - connected to TCP server",2) - Perun.lastReconnect = _now end + local _now = DCS.getRealTime() + Perun.lastReconnect = _now end Perun.SendToPerun = function(data_id, data_package) @@ -315,12 +349,15 @@ Perun.SendToPerun = function(data_id, data_package) local _dropped = true -- Try to send a few times (defind in settings section) + local _now = DCS.getRealTime() while _intStatus == nil and _intTries < Perun.SendRetries do _intStatus, _err = Perun.TCP:send(_TCPFrame) if _err then -- Failure, packet was not send Perun.AddLog("Packed not send : " .. data_id .. " , error: " .. _err .. ", tries: " .. _intTries,2) - Perun.ConnectToPerun() + if _now > Perun.lastReconnect + Perun.ReconnectTimeout then + Perun.ConnectToPerun() + end else -- Succes, packet was send Perun.AddLog("Packet send : " .. data_id .. " , tries:" .. _intTries,2) @@ -332,8 +369,7 @@ Perun.SendToPerun = function(data_id, data_package) if _dropped == true then -- Add information to log file and send chat message to all that Perun connection is broken Perun.AddLog("ERROR - packed dropped : " .. data_id,1) - local _now = DCS.getRealTime() - if _now > Perun.lastConnectionError + 60 then + if _now > Perun.lastConnectionError + Perun.ReconnectTimeout then -- Informs all players that there is Peron error; below hack for DCS net.send_chat not working local _all_players = net.get_player_list() for PlayerIDIndex, _playerID in ipairs(_all_players) do @@ -390,8 +426,8 @@ Perun.LogStats = function(playerID) _TempData['stat_data_type']= _PlayerStatsTable['ps_type']; _TempData['stat_data_masterslot'] = _PlayerStatsTable['ps_masterslot']; _TempData['stat_data_subslot'] = _PlayerStatsTable['ps_subslot']; - _TempData['stat_ucid']=net.get_player_info(playerID, 'ucid') - _TempData['stat_name']=net.get_player_info(playerID, 'name') + _TempData['stat_ucid']=_PlayerStatsTable['ps_ucid']; + _TempData['stat_name']=_PlayerStatsTable['ps_name']; _TempData['stat_datetime']=os.date('%Y-%m-%d %H:%M:%S') _TempData['stat_missionhash']=Perun.MissionHash @@ -399,6 +435,16 @@ Perun.LogStats = function(playerID) Perun.SendToPerun(52,_TempData) end +Perun.LogAllStats = function() + -- Log all players data + local _all_players = net.get_player_list() + for PlayerIDIndex, _playerID in ipairs(_all_players) do + if _playerID ~= 1 then + Perun.LogStats(_playerID) + end + end +end + Perun.LogLogin = function(playerID) -- Player logged in local _TempData={} @@ -413,13 +459,18 @@ end --- ################################ Calculate stats ################################ -Perun.LogStatsCount = function(argPlayerID,argAction) +Perun.LogStatsCount = function(argPlayerID,argAction,argTimer) -- Creates or updates Perun statistics array local _player_hash=net.get_player_info(argPlayerID, 'ucid')..Perun.GetMulticrewParameter(argPlayerID,"subtype") + -- By default we will be sending stats + argTimer = argTimer or false + if Perun.StatData[_player_hash] == nil then -- Create empty element local _TempData={} + _TempData['ps_ucid'] = net.get_player_info(argPlayerID, 'ucid') + _TempData['ps_name'] = net.get_player_info(argPlayerID, 'name') _TempData['ps_type'] = Perun.GetMulticrewParameter(argPlayerID,"subtype") _TempData['ps_masterslot'] = Perun.GetMulticrewParameter(argPlayerID,"masterslot") _TempData['ps_subslot'] = Perun.GetMulticrewParameter(argPlayerID,"subslot") @@ -428,6 +479,7 @@ Perun.LogStatsCount = function(argPlayerID,argAction) _TempData['ps_ejections'] = 0 _TempData['ps_crashes'] = 0 _TempData['ps_teamkills'] = 0 + _TempData['ps_time'] = 0 _TempData['ps_kills_planes'] = 0 _TempData['ps_kills_helicopters'] = 0 _TempData['ps_kills_air_defense'] = 0 @@ -449,15 +501,12 @@ Perun.LogStatsCount = function(argPlayerID,argAction) Perun.StatData[_player_hash]=_TempData end - -- TBD BELLOW SEEMS TO BE OBSOLETE, CHECK AND DELETE - if argType ~= nil then - Perun.StatData[_player_hash]['ps_type']=Perun.GetMulticrewParameter(argPlayerID,"subtype"); + if Perun.GetMulticrewParameter(argPlayerID,"subtype") ~= nil then Perun.StatDataLastType[net.get_player_info(argPlayerID, 'ucid')]=_player_hash else -- Do nothing end - -- TBD ABOVE SEEMS TO BE OBSOLETE, CHECK AND DELETE - + if argAction == "eject" then Perun.StatData[_player_hash]['ps_ejections']=Perun.StatData[_player_hash]['ps_ejections']+1 elseif argAction == "pilot_death" then @@ -505,6 +554,8 @@ Perun.LogStatsCount = function(argPlayerID,argAction) Perun.StatData[_player_hash]['ps_other_landings']=Perun.StatData[_player_hash]['ps_other_landings']+1 elseif argAction == "tookoff_OTHER" then Perun.StatData[_player_hash]['ps_other_takeoffs']=Perun.StatData[_player_hash]['ps_other_takeoffs']+1 + elseif argAction == "timer" then + Perun.StatData[_player_hash]['ps_time']=Perun.StatData[_player_hash]['ps_time']+1 end -- Always update slots @@ -512,7 +563,11 @@ Perun.LogStatsCount = function(argPlayerID,argAction) Perun.StatData[_player_hash]['ps_subslot'] = Perun.GetMulticrewParameter(argPlayerID,"subslot") Perun.AddLog("Stats data prepared",2) - Perun.LogStats(argPlayerID); + + -- If this is timer request do not send data to database + if argTimer ~= true then + Perun.LogStats(argPlayerID); + end end Perun.LogStatsCountCrew = function (MasterPilotID,ActionType) @@ -525,22 +580,27 @@ end -- ################################ Data preparation ################################ Perun.LogStatsGet = function(playerID) - -- Gets Perun statistics array per player TBD rewrite - local next = next -- Make next function local - this improves performance TBD + -- Gets Perun statistics array per player + local next = next -- Make next function local - this improves performance local _player_hash = nil - - if next(Perun.StatDataLastType) == nil then - -- Array is empty - _player_hash=net.get_player_info(playerID, 'ucid')..Perun.GetMulticrewParameter(playerID,"subtype") - elseif Perun.StatDataLastType[net.get_player_info(playerID, 'ucid')]== nil then - -- Last type entry is empty - _player_hash=net.get_player_info(playerID, 'ucid')..Perun.GetMulticrewParameter(playerID,"subtype") - else - -- Return last type entry - _player_hash=Perun.StatDataLastType[net.get_player_info(playerID, 'ucid')] + + local _ucid = net.get_player_info(playerID, 'ucid') + if not _ucid then + _ucid=Perun.PlayersTableCache["p"..playerID].ucid end - local next = next -- Make next function local - this improves performance TBD + if next(Perun.StatDataLastType) == nil then + -- Array is empty + _player_hash=_ucid..Perun.GetMulticrewParameter(playerID,"subtype") + elseif Perun.StatDataLastType[net.get_player_info(playerID, 'ucid')]== nil then + -- Last type entry is empty + _player_hash=_ucid..Perun.GetMulticrewParameter(playerID,"subtype") + else + -- Return last type entry + _player_hash=Perun.StatDataLastType[_ucid] + end + + local next = next -- Make next function local - this improves performance if next(Perun.StatData) == nil then -- Array is empty Perun.LogStatsCount(playerID,'init') -- Init statistics @@ -554,21 +614,6 @@ Perun.LogStatsGet = function(playerID) return Perun.StatData[_player_hash]; end -Perun.UpdateJsonStatus = function() - -- Updates status json file - local _TempData={} - _TempData["1"]=Perun.ServerData - _TempData["2"]=Perun.StatusData - _TempData["3"]=Perun.SlotsData - -- _TempData["4"]=Perun.MissionData -- TBD: hangs for some large missions - - -- Export data to JSON file - local _perun_export = io.open(Perun.JsonStatusLocation .. "perun_status_data.json", "w") - _perun_export:write(net.lua2json(_TempData) .. "\n") - _perun_export:close() - Perun.AddLog("Updated JSON",2) -end - Perun.UpdateStatus = function() -- Main function for status updates @@ -650,6 +695,7 @@ Perun.onSimulationStart = function() Perun.LogEvent("SimStart","Mission " .. Perun.MissionHash .. " started",nil,nil); Perun.StatData = {} Perun.StatDataLastType = {} + Perun.PlayersTableCache = {} end Perun.onSimulationStop = function() @@ -658,14 +704,21 @@ Perun.onSimulationStop = function() Perun.MissionHash=Perun.GenerateMissionHash(); Perun.StatData = {} Perun.StatDataLastType = {} + Perun.LogAllStats() + Perun.PlayersTableCache = {} end Perun.onPlayerDisconnect = function(id, err_code) - -- Player disconnected - TBD DCS Bug, this is not triggered at this point of time - if err_code == nil then - err_code = "-1" - end - Perun.LogEvent("disconnect", "Player " .. net.get_player_info(id, "name") .. " disconnected; " .. err_code,net.get_player_info(id, "name"),err_code); + -- Player disconnected + Perun.LogEvent("disconnect", "Player " .. id .. " disconnected.(?)",nil,nil); + + return +end + +Perun.onPlayerStop = function (id) + -- Player left the simulation (happens right before a disconnect, if player exited by desire) + Perun.LogEvent("quit", "Player " .. id .. " quit the server.",nil,nil); + return end Perun.onSimulationFrame = function() @@ -682,7 +735,6 @@ Perun.onSimulationFrame = function() Perun.lastSentMission = _now Perun.UpdateMission() - Perun.UpdateJsonStatus() end -- Send status update @@ -697,6 +749,19 @@ Perun.onSimulationFrame = function() Perun.lastSentKeepAlive = _now Perun.SendToPerun(0,nil) end + + -- Calucalate time on slot per each of players + if _now > Perun.lastTimer + 60 then + Perun.lastTimer = _now; + local _all_players = net.get_player_list() + for PlayerIDIndex, _playerID in ipairs(_all_players) do + if _playerID ~= 1 then + Perun.LogStatsCount(_playerID,"timer",true) + end + end + end + + end Perun.onPlayerStart = function (id) @@ -792,26 +857,29 @@ Perun.onGameEvent = function (eventName,arg1,arg2,arg3,arg4,arg5,arg6,arg7) elseif eventName == "change_slot" then --"change_slot", playerID, slotID, prevSide - - Perun.LogStatsCount(arg1,"init") + _master_type,_master_slot,_sub_slot = Perun.GetMulticrewAllParameters(arg1) if _sub_slot == nil then _sub_slot ="" else _sub_slot =" (" .. _sub_slot .. ") " end - Perun.LogEvent(eventName,Perun.SideID2Name( net.get_player_info(arg1, "side")) .. " player " .. net.get_player_info(arg1, "name") .. " changed slot to " .. _master_type .. " " .. _sub_slot,nil,nil); - + Perun.LogEvent(eventName,Perun.SideID2Name( net.get_player_info(arg1, "side")) .. " player " .. net.get_player_info(arg1, "name") .. " changed slot to " .. _master_type .. " " .. _sub_slot,nil,nil); + + Perun.LogStats(arg1); + Perun.LogStatsCount(arg1,"init") + Perun.PlayersTableCache["p"..arg1]=net.get_player_info(arg1); elseif eventName == "connect" then --"connect", playerID, name Perun.LogLogin(arg1); Perun.LogEvent(eventName,"Player "..net.get_player_info(arg1, "name") .. " connected",nil,nil); + Perun.PlayersTableCache["p"..arg1]=net.get_player_info(arg1); elseif eventName == "disconnect" then --"disconnect", playerID, name, playerSide, reason_code + Perun.LogEvent(eventName,"Player " .. arg2 .. " disconnected (".. arg4 .. ")." ,arg4,nil); Perun.LogStats(arg1); - Perun.LogEvent(eventName, Perun.SideID2Name(arg3) .. " player " ..net.get_player_info(arg1, "name") .. " disconnected",nil,nil); elseif eventName == "crash" then --"crash", playerID, unit_missionID @@ -831,19 +899,7 @@ Perun.onGameEvent = function (eventName,arg1,arg2,arg3,arg4,arg5,arg6,arg7) _temp_airfield = ""; end - -- TBD below shall be moved to function and arrays of strings - see landings - _temp_type = "" - if string.find(arg3, "FARP",1,true) then - _temp_type="tookoff_FARP" - elseif string.find(arg3, "CVN-74 John C. Stennis",1,true) or string.find(arg3, "LHA-1 Tarawa",1,true) or string.find(arg3, "SHIP",1,true) then - _temp_type="tookoff_SHIP" - elseif arg3 ~= "" then - _temp_type="tookoff_AIRFIELD" - else - _temp_type="tookoff_OTHER" - end - - Perun.LogStatsCountCrew (arg1,_temp_type) + Perun.LogStatsCountCrew (arg1,Perun.GetTakeOffLandingEvent(true,arg3)) Perun.LogEvent(eventName, Perun.SideID2Name( net.get_player_info(arg1, "side")) .. " player(s) " .. Perun.GetMulticrewCrewNames(arg1) .. " took off in ".. DCS.getUnitType(arg2) .. _temp_airfield,arg3,nil); elseif eventName == "landing" then @@ -854,19 +910,7 @@ Perun.onGameEvent = function (eventName,arg1,arg2,arg3,arg4,arg5,arg6,arg7) _temp_airfield =""; end - -- TBD below shall be moved to function and arrays of strings - see takeoffs - _temp_type = "" - if string.find(arg3, "FARP",1,true) then - _temp_type = "landing_FARP" - elseif string.find(arg3, "CVN-74 John C. Stennis",1,true) or string.find(arg3, "LHA-1 Tarawa",1,true) or string.find(arg3, "SHIP",1,true) then - _temp_type = "landing_SHIP" - elseif arg3 ~= "" then - _temp_type = "landing_AIRFIELD" - else - _temp_type = "landing_OTHER" - end - - Perun.LogStatsCountCrew (arg1,_temp_type) + Perun.LogStatsCountCrew (arg1,Perun.GetTakeOffLandingEvent(false,arg3)) Perun.LogEvent(eventName, Perun.SideID2Name( net.get_player_info(arg1, "side")) .. " player(s) " .. Perun.GetMulticrewCrewNames(arg1) .. " landed in " .. DCS.getUnitType(arg2).. _temp_airfield,arg3,nil); elseif eventName == "pilot_death" then diff --git a/01_DCS/Json/perun_status_data.json b/01_DCS/Json/perun_status_data.json deleted file mode 100644 index 60b0742..0000000 --- a/01_DCS/Json/perun_status_data.json +++ /dev/null @@ -1 +0,0 @@ -[] diff --git a/02_Windows_App/Perun_v1/01_Classes/DatabaseController.cs b/02_Windows_App/Perun_v1/01_Classes/DatabaseController.cs index 6887e80..38af228 100644 --- a/02_Windows_App/Perun_v1/01_Classes/DatabaseController.cs +++ b/02_Windows_App/Perun_v1/01_Classes/DatabaseController.cs @@ -69,7 +69,7 @@ public class DatabaseController SQLQueryTxt += "UPDATE `pe_DataPlayers` SET `pe_DataPlayers_updated`=" + TCPFrameTimestamp + " WHERE `pe_DataPlayers_ucid`='" + TCPFrame.payload.stat_ucid + "';"; SQLQueryTxt += "INSERT INTO `pe_DataTypes` (`pe_DataTypes_name`) SELECT '" + TCPFrame.payload.stat_data_type + "' FROM DUAL WHERE NOT EXISTS (SELECT * FROM `pe_DataTypes` where `pe_DataTypes_name` = '" + TCPFrame.payload.stat_data_type + "');"; SQLQueryTxt += "INSERT INTO `pe_LogStats` (`pe_LogStats_playerid`,`pe_LogStats_missionhash_id`,`pe_LogStats_typeid`) SELECT (SELECT `pe_DataPlayers_id` from `pe_DataPlayers` WHERE `pe_DataPlayers_ucid` = '" + TCPFrame.payload.stat_ucid + "'), (SELECT `pe_DataMissionHashes_id` FROM `pe_DataMissionHashes` WHERE `pe_DataMissionHashes_hash` = '" + TCPFrame.payload.stat_missionhash + "'), (SELECT pe_DataTypes_id FROM `pe_DataTypes` where `pe_DataTypes_name` = '" + TCPFrame.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` = '" + TCPFrame.payload.stat_missionhash + "') AND `pe_LogStats_playerid` = (SELECT `pe_DataPlayers_id` from `pe_DataPlayers` WHERE `pe_DataPlayers_ucid` = '" + TCPFrame.payload.stat_ucid + "') AND `pe_LogStats_typeid`= (SELECT pe_DataTypes_id FROM `pe_DataTypes` where `pe_DataTypes_name` = '" + TCPFrame.payload.stat_data_type + "'));"; - SQLQueryTxt += "UPDATE `pe_LogStats` SET `pe_LogStats_seat`=" + TCPFrame.payload.stat_data_subslot + ",`pe_LogStats_masterslot`=" + TCPFrame.payload.stat_data_masterslot + ",`ps_kills_fortification`=" + TCPFrame.payload.stat_data_perun.ps_kills_fortification + ",`ps_other_landings`=" + TCPFrame.payload.stat_data_perun.ps_other_landings + ",`ps_other_takeoffs`=" + TCPFrame.payload.stat_data_perun.ps_other_takeoffs + ",`ps_pvp`=" + TCPFrame.payload.stat_data_perun.ps_pvp + ",`ps_deaths`=" + TCPFrame.payload.stat_data_perun.ps_deaths + ",`ps_ejections`=" + TCPFrame.payload.stat_data_perun.ps_ejections + ",`ps_crashes`=" + TCPFrame.payload.stat_data_perun.ps_crashes + ",`ps_teamkills`=" + TCPFrame.payload.stat_data_perun.ps_teamkills + ",`ps_kills_planes`=" + TCPFrame.payload.stat_data_perun.ps_kills_planes + ",`ps_kills_helicopters`=" + TCPFrame.payload.stat_data_perun.ps_kills_helicopters + ",`ps_kills_air_defense`=" + TCPFrame.payload.stat_data_perun.ps_kills_air_defense + ",`ps_kills_armor`=" + TCPFrame.payload.stat_data_perun.ps_kills_armor + ",`ps_kills_unarmed`=" + TCPFrame.payload.stat_data_perun.ps_kills_unarmed + ",`ps_kills_infantry`=" + TCPFrame.payload.stat_data_perun.ps_kills_infantry + ",`ps_kills_ships`=" + TCPFrame.payload.stat_data_perun.ps_kills_ships + ",`ps_kills_other`=" + TCPFrame.payload.stat_data_perun.ps_kills_other + ",`ps_airfield_takeoffs`=" + TCPFrame.payload.stat_data_perun.ps_airfield_takeoffs + ",`ps_airfield_landings`=" + TCPFrame.payload.stat_data_perun.ps_airfield_landings + ",`ps_ship_takeoffs`=" + TCPFrame.payload.stat_data_perun.ps_ship_takeoffs + ",`ps_ship_landings`=" + TCPFrame.payload.stat_data_perun.ps_ship_landings + ",`ps_farp_takeoffs`=" + TCPFrame.payload.stat_data_perun.ps_farp_takeoffs + ",`ps_farp_landings`=" + TCPFrame.payload.stat_data_perun.ps_farp_landings + ", `pe_LogStats_datetime`='" + TCPFrame.payload.stat_datetime + "',`pe_LogStats_playerid` = (SELECT `pe_DataPlayers_id` from `pe_DataPlayers` WHERE `pe_DataPlayers_ucid` = '" + TCPFrame.payload.stat_ucid + "'),`pe_LogStats_missionhash_id`=(SELECT `pe_DataMissionHashes_id` FROM `pe_DataMissionHashes` WHERE `pe_DataMissionHashes_hash` = '" + TCPFrame.payload.stat_missionhash + "') WHERE `pe_LogStats_missionhash_id`=(SELECT `pe_DataMissionHashes_id` FROM `pe_DataMissionHashes` WHERE `pe_DataMissionHashes_hash` = '" + TCPFrame.payload.stat_missionhash + "') AND `pe_LogStats_playerid` = (SELECT `pe_DataPlayers_id` from `pe_DataPlayers` WHERE `pe_DataPlayers_ucid` = '" + TCPFrame.payload.stat_ucid + "') AND `pe_LogStats_typeid`=(SELECT pe_DataTypes_id FROM `pe_DataTypes` where `pe_DataTypes_name` = '" + TCPFrame.payload.stat_data_type + "');"; + SQLQueryTxt += "UPDATE `pe_LogStats` SET `ps_time`=" + TCPFrame.payload.stat_data_perun.ps_time + ",`pe_LogStats_seat`=" + TCPFrame.payload.stat_data_subslot + ",`pe_LogStats_masterslot`=" + TCPFrame.payload.stat_data_masterslot + ",`ps_kills_fortification`=" + TCPFrame.payload.stat_data_perun.ps_kills_fortification + ",`ps_other_landings`=" + TCPFrame.payload.stat_data_perun.ps_other_landings + ",`ps_other_takeoffs`=" + TCPFrame.payload.stat_data_perun.ps_other_takeoffs + ",`ps_pvp`=" + TCPFrame.payload.stat_data_perun.ps_pvp + ",`ps_deaths`=" + TCPFrame.payload.stat_data_perun.ps_deaths + ",`ps_ejections`=" + TCPFrame.payload.stat_data_perun.ps_ejections + ",`ps_crashes`=" + TCPFrame.payload.stat_data_perun.ps_crashes + ",`ps_teamkills`=" + TCPFrame.payload.stat_data_perun.ps_teamkills + ",`ps_kills_planes`=" + TCPFrame.payload.stat_data_perun.ps_kills_planes + ",`ps_kills_helicopters`=" + TCPFrame.payload.stat_data_perun.ps_kills_helicopters + ",`ps_kills_air_defense`=" + TCPFrame.payload.stat_data_perun.ps_kills_air_defense + ",`ps_kills_armor`=" + TCPFrame.payload.stat_data_perun.ps_kills_armor + ",`ps_kills_unarmed`=" + TCPFrame.payload.stat_data_perun.ps_kills_unarmed + ",`ps_kills_infantry`=" + TCPFrame.payload.stat_data_perun.ps_kills_infantry + ",`ps_kills_ships`=" + TCPFrame.payload.stat_data_perun.ps_kills_ships + ",`ps_kills_other`=" + TCPFrame.payload.stat_data_perun.ps_kills_other + ",`ps_airfield_takeoffs`=" + TCPFrame.payload.stat_data_perun.ps_airfield_takeoffs + ",`ps_airfield_landings`=" + TCPFrame.payload.stat_data_perun.ps_airfield_landings + ",`ps_ship_takeoffs`=" + TCPFrame.payload.stat_data_perun.ps_ship_takeoffs + ",`ps_ship_landings`=" + TCPFrame.payload.stat_data_perun.ps_ship_landings + ",`ps_farp_takeoffs`=" + TCPFrame.payload.stat_data_perun.ps_farp_takeoffs + ",`ps_farp_landings`=" + TCPFrame.payload.stat_data_perun.ps_farp_landings + ", `pe_LogStats_datetime`='" + TCPFrame.payload.stat_datetime + "',`pe_LogStats_playerid` = (SELECT `pe_DataPlayers_id` from `pe_DataPlayers` WHERE `pe_DataPlayers_ucid` = '" + TCPFrame.payload.stat_ucid + "'),`pe_LogStats_missionhash_id`=(SELECT `pe_DataMissionHashes_id` FROM `pe_DataMissionHashes` WHERE `pe_DataMissionHashes_hash` = '" + TCPFrame.payload.stat_missionhash + "') WHERE `pe_LogStats_missionhash_id`=(SELECT `pe_DataMissionHashes_id` FROM `pe_DataMissionHashes` WHERE `pe_DataMissionHashes_hash` = '" + TCPFrame.payload.stat_missionhash + "') AND `pe_LogStats_playerid` = (SELECT `pe_DataPlayers_id` from `pe_DataPlayers` WHERE `pe_DataPlayers_ucid` = '" + TCPFrame.payload.stat_ucid + "') AND `pe_LogStats_typeid`=(SELECT pe_DataTypes_id FROM `pe_DataTypes` where `pe_DataTypes_name` = '" + TCPFrame.payload.stat_data_type + "');"; } else if (TCPFrameType == "53") { diff --git a/02_Windows_App/Perun_v1/01_Classes/PerunHelper.cs b/02_Windows_App/Perun_v1/01_Classes/PerunHelper.cs index 5f4c5b6..1f96346 100644 --- a/02_Windows_App/Perun_v1/01_Classes/PerunHelper.cs +++ b/02_Windows_App/Perun_v1/01_Classes/PerunHelper.cs @@ -48,7 +48,7 @@ internal class PerunHelper Globals.AppUpdateGUI = true; } // Add the entry to log file - LogController.WriteLog(DateTime.Now.ToString("yyyy-dd-MM ") + " " + DateTime.Now.ToString("HH:mm:ss") + " | Instance: "+ Globals.AppInstanceID + " | " + LogMarker + " | "+ LogDirection + " | "+ strType + " | " + strEntryToAdd); + LogController.WriteLog(DateTime.Now.ToString("yyyy-MM-dd ") + " " + DateTime.Now.ToString("HH:mm:ss") + " | Instance: "+ Globals.AppInstanceID + " | " + LogMarker + " | "+ LogDirection + " | "+ strType + " | " + strEntryToAdd); } public static string GetAppVersion(string strBeginning) diff --git a/02_Windows_App/Perun_v1/02_Forms/form_Main.Designer.cs b/02_Windows_App/Perun_v1/02_Forms/form_Main.Designer.cs index b6aea20..5880617 100644 --- a/02_Windows_App/Perun_v1/02_Forms/form_Main.Designer.cs +++ b/02_Windows_App/Perun_v1/02_Forms/form_Main.Designer.cs @@ -157,11 +157,11 @@ // label6 // this.label6.AutoSize = true; - this.label6.Location = new System.Drawing.Point(41, 48); + this.label6.Location = new System.Drawing.Point(19, 48); this.label6.Name = "label6"; - this.label6.Size = new System.Drawing.Size(59, 13); + this.label6.Size = new System.Drawing.Size(81, 13); this.label6.TabIndex = 9; - this.label6.Text = "Server port"; + this.label6.Text = "MySQL DB port"; // // con_txt_mysql_port // @@ -198,20 +198,20 @@ // label2 // this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(47, 74); + this.label2.Location = new System.Drawing.Point(18, 74); this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(53, 13); + this.label2.Size = new System.Drawing.Size(82, 13); this.label2.TabIndex = 4; - this.label2.Text = "Database"; + this.label2.Text = "Database name"; // // label1 // this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(22, 22); + this.label1.Location = new System.Drawing.Point(3, 22); this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(78, 13); + this.label1.Size = new System.Drawing.Size(100, 13); this.label1.TabIndex = 3; - this.label1.Text = "Server address"; + this.label1.Text = "MySQL DB address"; // // con_txt_mysql_database // @@ -359,11 +359,11 @@ // label8 // this.label8.AutoSize = true; - this.label8.Location = new System.Drawing.Point(41, 45); + this.label8.Location = new System.Drawing.Point(7, 45); this.label8.Name = "label8"; - this.label8.Size = new System.Drawing.Size(62, 13); + this.label8.Size = new System.Drawing.Size(93, 13); this.label8.TabIndex = 12; - this.label8.Text = "Instance ID"; + this.label8.Text = "Perun Instance ID"; // // con_txt_dcs_instance // @@ -375,11 +375,11 @@ // label7 // this.label7.AutoSize = true; - this.label7.Location = new System.Drawing.Point(41, 19); + this.label7.Location = new System.Drawing.Point(44, 19); this.label7.Name = "label7"; - this.label7.Size = new System.Drawing.Size(59, 13); + this.label7.Size = new System.Drawing.Size(56, 13); this.label7.TabIndex = 10; - this.label7.Text = "Server port"; + this.label7.Text = "Perun port"; // // con_txt_dcs_server_port // diff --git a/02_Windows_App/Perun_v1/02_Forms/form_Main.cs b/02_Windows_App/Perun_v1/02_Forms/form_Main.cs index e6c4882..d7504ca 100644 --- a/02_Windows_App/Perun_v1/02_Forms/form_Main.cs +++ b/02_Windows_App/Perun_v1/02_Forms/form_Main.cs @@ -557,7 +557,10 @@ namespace Perun_v1 { ExtSRSJson = "{'type':'100','instance':'" + Int32.Parse(con_txt_dcs_instance.Text) + "','payload':{'ignore':'true'}}"; } - DatabaseConnection.SendToMySql(ExtSRSJson); + if (ExtSRSStatus) + { + DatabaseConnection.SendToMySql(ExtSRSJson); + } } // Handle LotATC @@ -588,7 +591,10 @@ namespace Perun_v1 { ExtLotATCJson = "{'type':'101','instance':'" + Int32.Parse(con_txt_dcs_instance.Text) + "','payload':{'ignore':'true'}}"; // No LotATC controller connected } - DatabaseConnection.SendToMySql(ExtLotATCJson); + if (ExtLotATCStatus) + { + DatabaseConnection.SendToMySql(ExtLotATCJson); + } } // Let's do not risk int overload diff --git a/02_Windows_App/Perun_v1/Perun_v1.csproj b/02_Windows_App/Perun_v1/Perun_v1.csproj index 5b5f00e..3a1f758 100644 --- a/02_Windows_App/Perun_v1/Perun_v1.csproj +++ b/02_Windows_App/Perun_v1/Perun_v1.csproj @@ -31,8 +31,8 @@ szporwolik Perun Perun.htm - 1 - 0.9.1.%2a + 0 + 0.9.2.%2a false true true diff --git a/02_Windows_App/Perun_v1/Properties/AssemblyInfo.cs b/02_Windows_App/Perun_v1/Properties/AssemblyInfo.cs index 0c0b053..0506b92 100644 --- a/02_Windows_App/Perun_v1/Properties/AssemblyInfo.cs +++ b/02_Windows_App/Perun_v1/Properties/AssemblyInfo.cs @@ -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 // przy użyciu symbolu „*”, tak jak pokazano poniżej: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.9.1.0")] -[assembly: AssemblyFileVersion("0.9.1.0")] +[assembly: AssemblyVersion("0.9.2.0")] +[assembly: AssemblyFileVersion("0.9.2.0")] [assembly: NeutralResourcesLanguage("en")] diff --git a/03_MySQL/m1081_perun.sql b/03_MySQL/m1081_perun.sql index bf6db08..b068485 100644 --- a/03_MySQL/m1081_perun.sql +++ b/03_MySQL/m1081_perun.sql @@ -17,7 +17,7 @@ CREATE TABLE IF NOT EXISTS `pe_Config` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8; INSERT INTO `pe_Config` (`pe_Config_id`, `pe_Config_payload`) VALUES -(1, 'v0.9.1'); +(1, 'v0.9.2'); DROP TABLE IF EXISTS `pe_DataMissionHashes`; CREATE TABLE IF NOT EXISTS `pe_DataMissionHashes` ( @@ -28,7 +28,7 @@ CREATE TABLE IF NOT EXISTS `pe_DataMissionHashes` ( PRIMARY KEY (`pe_DataMissionHashes_id`), UNIQUE KEY `UNIQUE_hash` (`pe_DataMissionHashes_hash`), KEY `pe_DataMissionHashes_instance` (`pe_DataMissionHashes_instance`) -) ENGINE=InnoDB AUTO_INCREMENT=7276 DEFAULT CHARSET=utf8; +ENGINE=InnoDB DEFAULT CHARSET=utf8; DROP TABLE IF EXISTS `pe_DataPlayers`; CREATE TABLE IF NOT EXISTS `pe_DataPlayers` ( @@ -39,7 +39,8 @@ CREATE TABLE IF NOT EXISTS `pe_DataPlayers` ( `pe_DataPlayers_updated` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`pe_DataPlayers_id`), UNIQUE KEY `UNIQUE_UCID` (`pe_DataPlayers_ucid`) -) ENGINE=InnoDB AUTO_INCREMENT=228 DEFAULT CHARSET=utf8; +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + DROP TABLE IF EXISTS `pe_DataRaw`; CREATE TABLE IF NOT EXISTS `pe_DataRaw` ( @@ -59,7 +60,7 @@ CREATE TABLE IF NOT EXISTS `pe_DataTypes` ( `pe_DataTypes_update` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`pe_DataTypes_id`), UNIQUE KEY `UNIQUE_TYPE_NAME` (`pe_DataTypes_name`) -) ENGINE=InnoDB AUTO_INCREMENT=62 DEFAULT CHARSET=utf8; +) ENGINE=InnoDB DEFAULT CHARSET=utf8; DROP TABLE IF EXISTS `pe_LogChat`; CREATE TABLE IF NOT EXISTS `pe_LogChat` ( @@ -74,7 +75,7 @@ CREATE TABLE IF NOT EXISTS `pe_LogChat` ( KEY `pe_LogChat_playerid` (`pe_LogChat_playerid`), KEY `pe_LogChat_datetime` (`pe_LogChat_datetime`), KEY `pe_LogChat_all` (`pe_LogChat_all`) -) ENGINE=InnoDB AUTO_INCREMENT=24169 DEFAULT CHARSET=utf8; +) ENGINE=InnoDB DEFAULT CHARSET=utf8; DROP TABLE IF EXISTS `pe_LogEvent`; CREATE TABLE IF NOT EXISTS `pe_LogEvent` ( @@ -90,7 +91,7 @@ CREATE TABLE IF NOT EXISTS `pe_LogEvent` ( KEY `pe_LogEvent_missionhash_id` (`pe_LogEvent_missionhash_id`), KEY `pe_LogEvent_datetime` (`pe_LogEvent_datetime`), KEY `pe_LogEvent_type_2` (`pe_LogEvent_type`) -) ENGINE=InnoDB AUTO_INCREMENT=102357 DEFAULT CHARSET=utf8; +) ENGINE=InnoDB DEFAULT CHARSET=utf8; DROP TABLE IF EXISTS `pe_LogLogins`; CREATE TABLE IF NOT EXISTS `pe_LogLogins` ( @@ -104,7 +105,7 @@ CREATE TABLE IF NOT EXISTS `pe_LogLogins` ( KEY `pe_LogLogins_playerid` (`pe_LogLogins_playerid`), KEY `pe_LogLogins_datetime` (`pe_LogLogins_datetime`), KEY `pe_LogLogins_instance` (`pe_LogLogins_instance`) -) ENGINE=InnoDB AUTO_INCREMENT=11705 DEFAULT CHARSET=utf8; +) ENGINE=InnoDB DEFAULT CHARSET=utf8; DROP TABLE IF EXISTS `pe_LogStats`; CREATE TABLE IF NOT EXISTS `pe_LogStats` ( @@ -115,7 +116,7 @@ CREATE TABLE IF NOT EXISTS `pe_LogStats` ( `pe_LogStats_typeid` int(11) DEFAULT NULL, `pe_LogStats_masterslot` int(11) DEFAULT NULL, `pe_LogStats_seat` int(10) UNSIGNED DEFAULT NULL, - `ps_kills` int(11) UNSIGNED NOT NULL DEFAULT '0', + `ps_kills_X` 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', @@ -138,6 +139,7 @@ CREATE TABLE IF NOT EXISTS `pe_LogStats` ( `ps_farp_landings` int(11) UNSIGNED NOT NULL DEFAULT '0', `ps_other_landings` int(10) UNSIGNED NOT NULL DEFAULT '0', `ps_other_takeoffs` int(10) UNSIGNED NOT NULL DEFAULT '0', + `ps_time` int(10) UNSIGNED NOT NULL DEFAULT '0', `pe_LogStats_mstatus` enum('?','RTB','MIA','KIA') DEFAULT NULL, PRIMARY KEY (`pe_LogStats_id`), UNIQUE KEY `UNIQUE_STATS_PER_MISSION_AND_UCID_AND_TYPE` (`pe_LogStats_playerid`,`pe_LogStats_missionhash_id`,`pe_LogStats_typeid`) USING BTREE, @@ -147,7 +149,8 @@ CREATE TABLE IF NOT EXISTS `pe_LogStats` ( KEY `pe_LogStats_masterslot` (`pe_LogStats_masterslot`), KEY `pe_LogStats_mstatus` (`pe_LogStats_mstatus`), KEY `pe_LogStats_seat` (`pe_LogStats_seat`) -) ENGINE=InnoDB AUTO_INCREMENT=10507 DEFAULT CHARSET=utf8; +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + DROP TRIGGER IF EXISTS `pe_LogStats_UPDATE`; DELIMITER $$ CREATE TRIGGER `pe_LogStats_UPDATE` BEFORE UPDATE ON `pe_LogStats` FOR EACH ROW BEGIN