mirror of
https://github.com/DaKerboul/perun.git
synced 2026-08-09 14:45:39 +02:00
Protected calls to Perun.LogEvent in case of a nil value in the message elements
This commit is contained in:
@@ -47,6 +47,14 @@ Perun.lastFrameTime = 0;
|
|||||||
Perun.ReconnectTimeout = 30;
|
Perun.ReconnectTimeout = 30;
|
||||||
Perun.RefreshKeepAlive = 3
|
Perun.RefreshKeepAlive = 3
|
||||||
|
|
||||||
|
Perun.PTS = function(data) -- ProtectedToString
|
||||||
|
if data == nil then
|
||||||
|
return "[nil]"
|
||||||
|
else
|
||||||
|
return tostring(data)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- ################################ Helper function definitions ################################
|
-- ################################ Helper function definitions ################################
|
||||||
Perun.GetCategory = function(id)
|
Perun.GetCategory = function(id)
|
||||||
-- Helper function returns object category basing on https://pastebin.com/GUAXrd2U
|
-- Helper function returns object category basing on https://pastebin.com/GUAXrd2U
|
||||||
@@ -81,7 +89,7 @@ Perun.SideID2Name = function(id)
|
|||||||
[2] = 'BLUE',
|
[2] = 'BLUE',
|
||||||
[3] = 'NEUTRAL', -- TBD check once this is released in DCS
|
[3] = 'NEUTRAL', -- TBD check once this is released in DCS
|
||||||
}
|
}
|
||||||
if id > 0 and id <= 3 then
|
if id and id > 0 and id <= 3 then
|
||||||
return _sides[id]
|
return _sides[id]
|
||||||
else
|
else
|
||||||
return "?"
|
return "?"
|
||||||
@@ -621,7 +629,7 @@ end
|
|||||||
Perun.onSimulationStart = function()
|
Perun.onSimulationStart = function()
|
||||||
-- Simulation was started
|
-- Simulation was started
|
||||||
Perun.MissionHash=Perun.GenerateMissionHash()
|
Perun.MissionHash=Perun.GenerateMissionHash()
|
||||||
Perun.LogEvent("SimStart","Mission " .. Perun.MissionHash .. " started",nil,nil);
|
Perun.LogEvent("SimStart","Mission " .. Perun.PTS(Perun.MissionHash) .. " started",nil,nil);
|
||||||
Perun.StatData = {}
|
Perun.StatData = {}
|
||||||
Perun.StatDataLastType = {}
|
Perun.StatDataLastType = {}
|
||||||
Perun.PlayersTableCache = {}
|
Perun.PlayersTableCache = {}
|
||||||
@@ -632,7 +640,7 @@ end
|
|||||||
|
|
||||||
Perun.onSimulationStop = function()
|
Perun.onSimulationStop = function()
|
||||||
-- Simulation was stopped
|
-- Simulation was stopped
|
||||||
Perun.LogEvent("SimStop","Mission " .. Perun.MissionHash .. " finished",nil,nil);
|
Perun.LogEvent("SimStop","Mission " .. Perun.PTS(Perun.MissionHash) .. " finished",nil,nil);
|
||||||
Perun.LogAllStats()
|
Perun.LogAllStats()
|
||||||
Perun.MissionHash=Perun.GenerateMissionHash();
|
Perun.MissionHash=Perun.GenerateMissionHash();
|
||||||
Perun.StatData = {}
|
Perun.StatData = {}
|
||||||
@@ -644,14 +652,14 @@ end
|
|||||||
|
|
||||||
Perun.onPlayerDisconnect = function(id, err_code)
|
Perun.onPlayerDisconnect = function(id, err_code)
|
||||||
-- Player disconnected
|
-- Player disconnected
|
||||||
Perun.LogEvent("disconnect", "Player " .. id .. " disconnected.",nil,nil);
|
Perun.LogEvent("disconnect", "Player " .. Perun.PTS(id) .. " disconnected.",nil,nil);
|
||||||
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
Perun.onPlayerStop = function (id)
|
Perun.onPlayerStop = function (id)
|
||||||
-- Player left the simulation (happens right before a disconnect, if player exited by desire)
|
-- Player left the simulation (happens right before a disconnect, if player exited by desire)
|
||||||
Perun.LogEvent("quit", "Player " .. id .. " quit the server.",nil,nil);
|
Perun.LogEvent("quit", "Player " .. Perun.PTS(id) .. " quit the server.",nil,nil);
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -724,11 +732,11 @@ Perun.onGameEvent = function (eventName,arg1,arg2,arg3,arg4,arg5,arg6,arg7)
|
|||||||
arg2 = "Cannon"
|
arg2 = "Cannon"
|
||||||
end
|
end
|
||||||
|
|
||||||
Perun.LogEvent(eventName,Perun.SideID2Name( net.get_player_info(arg1, "side")) .. " player(s) " .. Perun.GetMulticrewCrewNames(arg1) .." killed friendly " .. Perun.GetMulticrewCrewNames(arg3) .. " using " .. arg2,nil,nil);
|
Perun.LogEvent(Perun.PTS(eventName),Perun.SideID2Name( Perun.PTS(net.get_player_info(arg1, "side"))) .. " player(s) " .. Perun.PTS(Perun.GetMulticrewCrewNames(arg1)) .." killed friendly " .. Perun.PTS(Perun.GetMulticrewCrewNames(arg3)) .. " using " .. Perun.PTS(arg2),nil,nil);
|
||||||
|
|
||||||
elseif eventName == "mission_end" then
|
elseif eventName == "mission_end" then
|
||||||
--"mission_end", winner, msg
|
--"mission_end", winner, msg
|
||||||
Perun.LogEvent(eventName,"Mission finished, winner " .. arg1 .. " message: " .. arg2,nil,nil);
|
Perun.LogEvent(Perun.PTS(eventName),"Mission finished, winner " .. Perun.PTS(arg1) .. " message: " .. Perun.PTS(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
|
||||||
@@ -791,12 +799,12 @@ Perun.onGameEvent = function (eventName,arg1,arg2,arg3,arg4,arg5,arg6,arg7)
|
|||||||
victim_vehicle = "?"
|
victim_vehicle = "?"
|
||||||
end
|
end
|
||||||
|
|
||||||
Perun.LogEvent(eventName,Perun.SideID2Name(arg3) .. _temp_killers .. " in " .. arg2 .. " killed " .. Perun.SideID2Name(arg6) .. _temp_victims .. " in " .. victim_vehicle .. " using " .. arg7 .. " [".. Perun.GetCategory(arg5).."]",arg7,Perun.GetCategory(arg5));
|
Perun.LogEvent(Perun.PTS(eventName),Perun.PTS(Perun.SideID2Name(arg3)) .. _temp_killers .. " in " .. Perun.PTS(arg2) .. " killed " .. Perun.PTS(Perun.SideID2Name(arg6)) .. Perun.PTS(_temp_victims) .. " in " .. Perun.PTS(victim_vehicle) .. " using " .. Perun.PTS(arg7) .. " [".. Perun.PTS(Perun.GetCategory(arg5)).."]",arg7,Perun.GetCategory(arg5));
|
||||||
|
|
||||||
elseif eventName == "self_kill" then
|
elseif eventName == "self_kill" then
|
||||||
--"self_kill", playerID
|
--"self_kill", playerID
|
||||||
Perun.LogStats(arg1);
|
Perun.LogStats(arg1);
|
||||||
Perun.LogEvent(eventName,net.get_player_info(arg1, "name") .. " killed himself",nil,nil);
|
Perun.LogEvent(Perun.PTS(eventName),Perun.PTS(net.get_player_info(arg1, "name")) .. " killed himself",nil,nil);
|
||||||
|
|
||||||
elseif eventName == "change_slot" then
|
elseif eventName == "change_slot" then
|
||||||
--"change_slot", playerID, slotID, prevSide
|
--"change_slot", playerID, slotID, prevSide
|
||||||
@@ -807,7 +815,7 @@ Perun.onGameEvent = function (eventName,arg1,arg2,arg3,arg4,arg5,arg6,arg7)
|
|||||||
else
|
else
|
||||||
_sub_slot =" (" .. _sub_slot .. ") "
|
_sub_slot =" (" .. _sub_slot .. ") "
|
||||||
end
|
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(Perun.PTS(eventName),Perun.PTS(Perun.SideID2Name( net.get_player_info(arg1, "side"))) .. " player " .. Perun.PTS(net.get_player_info(arg1, "name")) .. " changed slot to " .. Perun.PTS(_master_type) .. " " .. Perun.PTS(_sub_slot),nil,nil);
|
||||||
|
|
||||||
Perun.LogStats(arg1);
|
Perun.LogStats(arg1);
|
||||||
Perun.LogStatsCount(arg1,"init")
|
Perun.LogStatsCount(arg1,"init")
|
||||||
@@ -816,23 +824,23 @@ Perun.onGameEvent = function (eventName,arg1,arg2,arg3,arg4,arg5,arg6,arg7)
|
|||||||
elseif eventName == "connect" then
|
elseif eventName == "connect" then
|
||||||
--"connect", playerID, name
|
--"connect", playerID, name
|
||||||
Perun.LogLogin(arg1);
|
Perun.LogLogin(arg1);
|
||||||
Perun.LogEvent(eventName,"Player "..net.get_player_info(arg1, "name") .. " connected",nil,nil);
|
Perun.LogEvent(Perun.PTS(eventName),"Player "..Perun.PTS(net.get_player_info(arg1, "name")) .. " connected",nil,nil);
|
||||||
Perun.PlayersTableCache["p"..arg1]=net.get_player_info(arg1);
|
Perun.PlayersTableCache["p"..arg1]=net.get_player_info(arg1);
|
||||||
|
|
||||||
elseif eventName == "disconnect" then
|
elseif eventName == "disconnect" then
|
||||||
--"disconnect", playerID, name, playerSide, reason_code
|
--"disconnect", playerID, name, playerSide, reason_code
|
||||||
Perun.LogEvent(eventName,"Player " .. arg2 .. " disconnected (".. arg4 .. ")." ,arg4,nil);
|
Perun.LogEvent(Perun.PTS(eventName),"Player " .. Perun.PTS(arg2) .. " disconnected (".. Perun.PTS(arg4) .. ")." ,arg4,nil);
|
||||||
Perun.LogStats(arg1);
|
Perun.LogStats(arg1);
|
||||||
|
|
||||||
elseif eventName == "crash" then
|
elseif eventName == "crash" then
|
||||||
--"crash", playerID, unit_missionID
|
--"crash", playerID, unit_missionID
|
||||||
Perun.LogStatsCountCrew (arg1,"crash")
|
Perun.LogStatsCountCrew (arg1,"crash")
|
||||||
Perun.LogEvent(eventName, Perun.SideID2Name( net.get_player_info(arg1, "side")) .. " player(s) " .. Perun.GetMulticrewCrewNames(arg1) .. " crashed in " .. DCS.getUnitType(arg2),nil,nil);
|
Perun.LogEvent(Perun.PTS(eventName), Perun.PTS(Perun.SideID2Name( net.get_player_info(arg1, "side"))) .. " player(s) " .. Perun.PTS(Perun.GetMulticrewCrewNames(arg1)) .. " crashed in " .. Perun.PTS(DCS.getUnitType(arg2)),nil,nil);
|
||||||
|
|
||||||
elseif eventName == "eject" then
|
elseif eventName == "eject" then
|
||||||
--"eject", playerID, unit_missionID
|
--"eject", playerID, unit_missionID
|
||||||
Perun.LogStatsCountCrew (arg1,"eject") -- TBD crew or initiator only?
|
Perun.LogStatsCountCrew (arg1,"eject") -- TBD crew or initiator only?
|
||||||
Perun.LogEvent(eventName, Perun.SideID2Name( net.get_player_info(arg1, "side")) .. " player(s) " .. Perun.GetMulticrewCrewNames(arg1) .. " ejected " .. DCS.getUnitType(arg2),nil,nil);
|
Perun.LogEvent(Perun.PTS(eventName), Perun.PTS(Perun.SideID2Name( net.get_player_info(arg1, "side"))) .. " player(s) " .. Perun.PTS(Perun.GetMulticrewCrewNames(arg1)) .. " ejected " .. Perun.PTS(DCS.getUnitType(arg2)),nil,nil);
|
||||||
|
|
||||||
elseif eventName == "takeoff" then
|
elseif eventName == "takeoff" then
|
||||||
--"takeoff", playerID, unit_missionID, airdromeName
|
--"takeoff", playerID, unit_missionID, airdromeName
|
||||||
@@ -843,7 +851,7 @@ Perun.onGameEvent = function (eventName,arg1,arg2,arg3,arg4,arg5,arg6,arg7)
|
|||||||
end
|
end
|
||||||
|
|
||||||
Perun.LogStatsCountCrew (arg1,Perun.GetTakeOffLandingEvent(true,arg3))
|
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);
|
Perun.LogEvent(Perun.PTS(eventName), Perun.PTS(Perun.SideID2Name( net.get_player_info(arg1, "side"))) .. " player(s) " .. Perun.PTS(Perun.GetMulticrewCrewNames(arg1)) .. " took off in ".. Perun.PTS(DCS.getUnitType(arg2)) .. Perun.PTS(_temp_airfield),arg3,nil);
|
||||||
|
|
||||||
elseif eventName == "landing" then
|
elseif eventName == "landing" then
|
||||||
--"landing", playerID, unit_missionID, airdromeName
|
--"landing", playerID, unit_missionID, airdromeName
|
||||||
@@ -854,15 +862,15 @@ Perun.onGameEvent = function (eventName,arg1,arg2,arg3,arg4,arg5,arg6,arg7)
|
|||||||
end
|
end
|
||||||
|
|
||||||
Perun.LogStatsCountCrew (arg1,Perun.GetTakeOffLandingEvent(false,arg3))
|
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);
|
Perun.LogEvent(Perun.PTS(eventName), Perun.PTS(Perun.SideID2Name( net.get_player_info(arg1, "side"))) .. " player(s) " .. Perun.PTS(Perun.GetMulticrewCrewNames(arg1)) .. " landed in " .. Perun.PTS(DCS.getUnitType(arg2)).. Perun.PTS(_temp_airfield),arg3,nil);
|
||||||
|
|
||||||
elseif eventName == "pilot_death" then
|
elseif eventName == "pilot_death" then
|
||||||
--"pilot_death", playerID, unit_missionID
|
--"pilot_death", playerID, unit_missionID
|
||||||
Perun.LogStatsCountCrew (arg1,"pilot_death") -- TBD crew or initiator only?
|
Perun.LogStatsCountCrew (arg1,"pilot_death") -- TBD crew or initiator only?
|
||||||
Perun.LogEvent(eventName, Perun.SideID2Name( net.get_player_info(arg1, "side")) .. " player(s) " .. Perun.GetMulticrewCrewNames(arg1) .. " in " .. DCS.getUnitType(arg2) .. " died",nil,nil);
|
Perun.LogEvent(Perun.PTS(eventName), Perun.PTS(Perun.SideID2Name( net.get_player_info(arg1, "side"))) .. " player(s) " .. Perun.PTS(Perun.GetMulticrewCrewNames(arg1)) .. " in " .. Perun.PTS(DCS.getUnitType(arg2)) .. " died",nil,nil);
|
||||||
|
|
||||||
else
|
else
|
||||||
Perun.LogEvent(eventName,"Unknown event type",nil,nil);
|
Perun.LogEvent(Perun.PTS(eventName),"Unknown event type",nil,nil);
|
||||||
|
|
||||||
end
|
end
|
||||||
local _delay = (DCS.getRealTime() - _now) * 1000000
|
local _delay = (DCS.getRealTime() - _now) * 1000000
|
||||||
|
|||||||
Reference in New Issue
Block a user