Skip to content
This repository has been archived by the owner on Jul 14, 2023. It is now read-only.

Commit

Permalink
Added function supports()
Browse files Browse the repository at this point in the history
Added new function in globals to determine if a particular feature is
supported. This should allow compatibility to be maintained across
server versions.
  • Loading branch information
initramfs committed Jan 26, 2014
1 parent cd5fbc5 commit 3fe8e7d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
10 changes: 10 additions & 0 deletions COM/server/globals.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,14 @@ end

function toboolean(v)
return (type(v) == "string" and v == "true") or (type(v) == "number" and v ~= 0) or (type(v) == "boolean" and v)
end

function supports(feature)
if ServVer == -1 then
return true
end

if feature == "IP" then
return ServVer >= 12
end
end
20 changes: 10 additions & 10 deletions COM/server/processor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,31 @@ local GeneratePlayerInfo =
if p == nil then
return "null"
end

local ip = "null"

if ServVer == "0.1.2" then
if supports("IP") then
ip = p:GetIP()
end

local veh = "null"
local veh_health = -1

if p:InVehicle() then
veh = p:GetVehicle():GetName()
veh_health = p:GetVehicle():GetHealth()
end

local wep = p:GetEquippedWeapon()

if wep ~= nil then
wep = wep.id
else
wep = -1
end

local pos = p:GetPosition()

return p:GetId()..","
..p:GetName()..","
..ip..","
Expand All @@ -56,7 +56,7 @@ local GeneratePlayerData =

local ip = "null"

if ServVer == "0.1.2" then
if supports("IP") then
ip = p:GetIP()
end

Expand Down Expand Up @@ -85,7 +85,7 @@ function Processor.process(request, ReqID)
end

-- Handle incoming get request

local command = request[2]:upper()

if command == "PLAYERCOUNT" then
Expand Down

0 comments on commit 3fe8e7d

Please sign in to comment.