Restrict to Debug Only and Server Admin
This commit is contained in:
@@ -6,6 +6,24 @@ local SERVER_MODULE = "PROJECTRVTools"
|
|||||||
local SERVER_COMMAND_REASSIGN = "ReassignVehicleToCurrentRoom"
|
local SERVER_COMMAND_REASSIGN = "ReassignVehicleToCurrentRoom"
|
||||||
local CLIENT_COMMAND_RESULT = "ReassignVehicleResult"
|
local CLIENT_COMMAND_RESULT = "ReassignVehicleResult"
|
||||||
|
|
||||||
|
local function isDebugModeEnabled()
|
||||||
|
if type(isDebugEnabled) == "function" then
|
||||||
|
return isDebugEnabled() == true
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
local function isAdminPlayer(player)
|
||||||
|
if not isClient() then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
if not player or not player.getAccessLevel then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
local accessLevel = tostring(player:getAccessLevel() or ""):lower()
|
||||||
|
return accessLevel == "admin"
|
||||||
|
end
|
||||||
|
|
||||||
-- Get the room type based on the player's coordinates
|
-- Get the room type based on the player's coordinates
|
||||||
local function getRoomTypeAtPosition(x, y, z)
|
local function getRoomTypeAtPosition(x, y, z)
|
||||||
local RV = require("RVVehicleTypes")
|
local RV = require("RVVehicleTypes")
|
||||||
@@ -98,6 +116,13 @@ local function reassignVehicleToCurrentRoom(player)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function requestReassignVehicleToCurrentRoom(player)
|
local function requestReassignVehicleToCurrentRoom(player)
|
||||||
|
if not isDebugModeEnabled() then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if not isAdminPlayer(player) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
if isClient() then
|
if isClient() then
|
||||||
sendClientCommand(SERVER_MODULE, SERVER_COMMAND_REASSIGN, {})
|
sendClientCommand(SERVER_MODULE, SERVER_COMMAND_REASSIGN, {})
|
||||||
return
|
return
|
||||||
@@ -141,6 +166,13 @@ end
|
|||||||
|
|
||||||
-- Main function that adds the context menu option
|
-- Main function that adds the context menu option
|
||||||
local function addReassignOption(player, context)
|
local function addReassignOption(player, context)
|
||||||
|
if not isDebugModeEnabled() then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if not isAdminPlayer(player) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local inRoom, roomType, room = isPlayerInValidRoom(player)
|
local inRoom, roomType, room = isPlayerInValidRoom(player)
|
||||||
|
|
||||||
if not inRoom then
|
if not inRoom then
|
||||||
|
|||||||
@@ -6,6 +6,24 @@ local BLOCK_RADIUS = 6 -- radius processed each tick
|
|||||||
local TOTAL_RADIUS = 60 -- final total radius
|
local TOTAL_RADIUS = 60 -- final total radius
|
||||||
local BLOCK_STEP = (BLOCK_RADIUS * 2) + 1 -- 13 when BLOCK_RADIUS=6
|
local BLOCK_STEP = (BLOCK_RADIUS * 2) + 1 -- 13 when BLOCK_RADIUS=6
|
||||||
|
|
||||||
|
local function isDebugModeEnabled()
|
||||||
|
if type(isDebugEnabled) == "function" then
|
||||||
|
return isDebugEnabled() == true
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
local function isAdminPlayer(player)
|
||||||
|
if not isClient() then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
if not player or not player.getAccessLevel then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
local accessLevel = tostring(player:getAccessLevel() or ""):lower()
|
||||||
|
return accessLevel == "admin"
|
||||||
|
end
|
||||||
|
|
||||||
local function makeBlocksList(totalRadius, step)
|
local function makeBlocksList(totalRadius, step)
|
||||||
local blocks = {}
|
local blocks = {}
|
||||||
local start = -totalRadius
|
local start = -totalRadius
|
||||||
@@ -79,6 +97,7 @@ end
|
|||||||
|
|
||||||
local function startProgressiveRemoval(player)
|
local function startProgressiveRemoval(player)
|
||||||
if not player then return end
|
if not player then return end
|
||||||
|
if not isAdminPlayer(player) then return end
|
||||||
local px = math.floor(player:getX())
|
local px = math.floor(player:getX())
|
||||||
local py = math.floor(player:getY())
|
local py = math.floor(player:getY())
|
||||||
local pz = math.floor(player:getZ() or 0)
|
local pz = math.floor(player:getZ() or 0)
|
||||||
@@ -128,6 +147,8 @@ local function onFillWorldObjectContextMenu(playerOrNum, context, worldObjects,
|
|||||||
local player
|
local player
|
||||||
if type(playerOrNum) == "number" then player = getSpecificPlayer(playerOrNum) else player = playerOrNum end
|
if type(playerOrNum) == "number" then player = getSpecificPlayer(playerOrNum) else player = playerOrNum end
|
||||||
if not player then return end
|
if not player then return end
|
||||||
|
if not isDebugModeEnabled() then return end
|
||||||
|
if not isAdminPlayer(player) then return end
|
||||||
|
|
||||||
context:addOption("Progressively remove 'street' tiles (radius "..tostring(TOTAL_RADIUS)..")", worldObjects, function()
|
context:addOption("Progressively remove 'street' tiles (radius "..tostring(TOTAL_RADIUS)..")", worldObjects, function()
|
||||||
startProgressiveRemoval(player)
|
startProgressiveRemoval(player)
|
||||||
|
|||||||
@@ -4,6 +4,14 @@ local SERVER_MODULE = "PROJECTRVTools"
|
|||||||
local SERVER_COMMAND_REASSIGN = "ReassignVehicleToCurrentRoom"
|
local SERVER_COMMAND_REASSIGN = "ReassignVehicleToCurrentRoom"
|
||||||
local CLIENT_COMMAND_RESULT = "ReassignVehicleResult"
|
local CLIENT_COMMAND_RESULT = "ReassignVehicleResult"
|
||||||
|
|
||||||
|
local function isAdminPlayer(player)
|
||||||
|
if not player or not player.getAccessLevel then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
local accessLevel = tostring(player:getAccessLevel() or ""):lower()
|
||||||
|
return accessLevel == "admin"
|
||||||
|
end
|
||||||
|
|
||||||
local function getRoomTypeAtPosition(x, y, z)
|
local function getRoomTypeAtPosition(x, y, z)
|
||||||
local RV = require("RVVehicleTypes")
|
local RV = require("RVVehicleTypes")
|
||||||
local vehicleTypes = RV.VehicleTypes
|
local vehicleTypes = RV.VehicleTypes
|
||||||
@@ -112,6 +120,16 @@ local function onClientCommand(module, command, player, args)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if command == SERVER_COMMAND_REASSIGN then
|
if command == SERVER_COMMAND_REASSIGN then
|
||||||
|
if not isAdminPlayer(player) then
|
||||||
|
if player then
|
||||||
|
sendServerCommand(player, SERVER_MODULE, CLIENT_COMMAND_RESULT, {
|
||||||
|
ok = false,
|
||||||
|
message = "Only admins can use this action."
|
||||||
|
})
|
||||||
|
end
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local ok, message = reassignVehicleToCurrentRoom(player)
|
local ok, message = reassignVehicleToCurrentRoom(player)
|
||||||
if player then
|
if player then
|
||||||
sendServerCommand(player, SERVER_MODULE, CLIENT_COMMAND_RESULT, {
|
sendServerCommand(player, SERVER_MODULE, CLIENT_COMMAND_RESULT, {
|
||||||
|
|||||||
Reference in New Issue
Block a user