Skip to content

Commit

Permalink
avoid crash in multiplayer if allow_ownship_export is off
Browse files Browse the repository at this point in the history
This disables the CommonData exports when on a MP server where the
"Allow Player Export" option is turned off, so the rest of the exports
continue to work.

The exports on the CommonData module rely on values from LoGetSelfData()
that are only available when allow_ownship_export is on.
  • Loading branch information
jboecker committed May 22, 2017
1 parent f9cf4b1 commit 0f363ca
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
23 changes: 19 additions & 4 deletions Scripts/DCS-BIOS/lib/CommonData.lua
Expand Up @@ -9,6 +9,9 @@ local altFt
local hdgDeg
local hdgDegFrac
moduleBeingDefined.exportHooks[#moduleBeingDefined.exportHooks+1] = function()
-- skip this data if ownship export is disabled
if not LoIsOwnshipExportAllowed() then return end

local selfData = LoGetSelfData()
if selfData.LatLongAlt == nil then return end
altFt = selfData.LatLongAlt.Alt / 0.3048
Expand Down Expand Up @@ -38,15 +41,27 @@ end

defineIntegerFromGetter("LAT_DEG", function() return latDeg end, 59, "Position", "Latitude Degrees")
defineIntegerFromGetter("LAT_SEC", function() return latSec end, 59, "Position", "Latitude Seconds")
defineIntegerFromGetter("LAT_SEC_FRAC", function() return math.floor(latFractionalSec*65535) end, 65535, "Position", "Latitude Fractional Seconds (divide by 65535)")
defineIntegerFromGetter("LAT_SEC_FRAC", function()
if not LoIsOwnshipExportAllowed() then return nil end
return math.floor(latFractionalSec*65535)
end, 65535, "Position", "Latitude Fractional Seconds (divide by 65535)")

defineIntegerFromGetter("LON_DEG", function() return lonDeg end, 59, "Position", "Longitude Degrees")
defineIntegerFromGetter("LON_SEC", function() return lonSec end, 59, "Position", "Longitude Seconds")
defineIntegerFromGetter("LON_SEC_FRAC", function() return math.floor(lonFractionalSec*65535) end, 65535, "Position", "Longitude Fractional Seconds (divide by 65535)")
defineIntegerFromGetter("LON_SEC_FRAC", function()
if not LoIsOwnshipExportAllowed() then return nil end
return math.floor(lonFractionalSec*65535)
end, 65535, "Position", "Longitude Fractional Seconds (divide by 65535)")

defineIntegerFromGetter("ALT_MSL_FT", function() return math.floor(altFt) end, 65535, "Altitude", "Altitude MSL (ft)")
defineIntegerFromGetter("ALT_MSL_FT", function()
if not LoIsOwnshipExportAllowed() then return nil end
return math.floor(altFt)
end, 65535, "Altitude", "Altitude MSL (ft)")

defineIntegerFromGetter("HDG_DEG", function() return hdgDeg end, 360, "Heading", "Heading (Degrees)")
defineIntegerFromGetter("HDG_DEG_FRAC", function() return hdgDegFrac * 127 end, 127, "Heading", "Heading (Fractional Degrees, divide by 127)")
defineIntegerFromGetter("HDG_DEG_FRAC", function()
if not LoIsOwnshipExportAllowed() then return nil end
return hdgDegFrac * 127
end, 127, "Heading", "Heading (Fractional Degrees, divide by 127)")

BIOS.protocol.endModule()
3 changes: 3 additions & 0 deletions Scripts/DCS-BIOS/lib/Util.lua
Expand Up @@ -89,6 +89,9 @@ BIOS.util.MemoryAllocation = {
multiplier = nil
}
function BIOS.util.MemoryAllocation:setValue(value)
-- ignore nil values (on MP servers with player export disabled, some values are not available)
if value == nil then return end

assert(self.maxValue)
assert(value)
value = math.floor(value)
Expand Down

0 comments on commit 0f363ca

Please sign in to comment.