-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: [system]\runcode 🎨 Run formatter
- Loading branch information
1 parent
5fee496
commit 12d0f0b
Showing
9 changed files
with
433 additions
and
423 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,24 @@ | ||
-- This resource is part of the default Cfx.re asset pack (cfx-server-data) | ||
-- Altering or recreating for local use only is strongly discouraged. | ||
|
||
version '1.0.0' | ||
author 'Cfx.re <root@cfx.re>' | ||
description 'Allows server owners to execute arbitrary server-side or client-side JavaScript/Lua code. *Consider only using this on development servers.' | ||
repository 'https://github.com/citizenfx/cfx-server-data' | ||
version("1.0.0") | ||
author("Cfx.re <root@cfx.re>") | ||
description("Allows server owners to execute arbitrary server-side or client-side JavaScript/Lua code. *Consider only using this on development servers.") | ||
repository("https://github.com/citizenfx/cfx-server-data") | ||
|
||
game 'common' | ||
fx_version 'bodacious' | ||
game("common") | ||
fx_version("bodacious") | ||
|
||
client_script 'runcode_cl.lua' | ||
server_script 'runcode_sv.lua' | ||
server_script 'runcode_web.lua' | ||
client_script("runcode_cl.lua") | ||
server_script("runcode_sv.lua") | ||
server_script("runcode_web.lua") | ||
|
||
shared_script 'runcode_shared.lua' | ||
shared_script 'runcode.js' | ||
shared_script("runcode_shared.lua") | ||
shared_script("runcode.js") | ||
|
||
client_script 'runcode_ui.lua' | ||
client_script("runcode_ui.lua") | ||
|
||
ui_page 'web/nui.html' | ||
files { | ||
'web/nui.html' | ||
} | ||
ui_page("web/nui.html") | ||
files({ | ||
"web/nui.html", | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
exports('runJS', (snippet) => { | ||
if (IsDuplicityVersion() && GetInvokingResource() !== GetCurrentResourceName()) { | ||
return [ 'Invalid caller.', false ]; | ||
} | ||
if (IsDuplicityVersion() && GetInvokingResource() !== GetCurrentResourceName()) { | ||
return [ 'Invalid caller.', false ]; | ||
} | ||
|
||
try { | ||
return [ new Function(snippet)(), false ]; | ||
} catch (e) { | ||
return [ false, e.toString() ]; | ||
} | ||
try { | ||
return [ new Function(snippet)(), false ]; | ||
} | ||
catch (e) { | ||
return [ false, e.toString() ]; | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
RegisterNetEvent('runcode:gotSnippet') | ||
RegisterNetEvent("runcode:gotSnippet") | ||
|
||
AddEventHandler('runcode:gotSnippet', function(id, lang, code) | ||
local res, err = RunCode(lang, code) | ||
AddEventHandler("runcode:gotSnippet", function(id, lang, code) | ||
local res, err = RunCode(lang, code) | ||
|
||
if not err then | ||
if type(res) == 'vector3' then | ||
res = json.encode({ table.unpack(res) }) | ||
elseif type(res) == 'table' then | ||
res = json.encode(res) | ||
end | ||
end | ||
if not err then | ||
if type(res) == "vector3" then | ||
res = json.encode({ table.unpack(res) }) | ||
elseif type(res) == "table" then | ||
res = json.encode(res) | ||
end | ||
end | ||
|
||
TriggerServerEvent('runcode:gotResult', id, res, err) | ||
end) | ||
TriggerServerEvent("runcode:gotResult", id, res, err) | ||
end) |
36 changes: 18 additions & 18 deletions
36
server-data/resources/[system]/runcode/runcode_shared.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,32 @@ | ||
local runners = {} | ||
|
||
function runners.lua(arg) | ||
local code, err = load('return ' .. arg, '@runcode') | ||
local code, err = load("return " .. arg, "@runcode") | ||
|
||
-- if failed, try without return | ||
if err then | ||
code, err = load(arg, '@runcode') | ||
end | ||
-- if failed, try without return | ||
if err then | ||
code, err = load(arg, "@runcode") | ||
end | ||
|
||
if err then | ||
print(err) | ||
return nil, err | ||
end | ||
if err then | ||
print(err) | ||
return nil, err | ||
end | ||
|
||
local status, result = pcall(code) | ||
print(result) | ||
local status, result = pcall(code) | ||
print(result) | ||
|
||
if status then | ||
return result | ||
end | ||
if status then | ||
return result | ||
end | ||
|
||
return nil, result | ||
return nil, result | ||
end | ||
|
||
function runners.js(arg) | ||
return table.unpack(exports[GetCurrentResourceName()]:runJS(arg)) | ||
return table.unpack(exports[GetCurrentResourceName()]:runJS(arg)) | ||
end | ||
|
||
function RunCode(lang, str) | ||
return runners[lang](str) | ||
end | ||
return runners[lang](str) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,42 @@ | ||
function GetPrivs(source) | ||
return { | ||
canServer = IsPlayerAceAllowed(source, 'command.run'), | ||
canClient = IsPlayerAceAllowed(source, 'command.crun'), | ||
canSelf = IsPlayerAceAllowed(source, 'runcode.self'), | ||
} | ||
return { | ||
canServer = IsPlayerAceAllowed(source, "command.run"), | ||
canClient = IsPlayerAceAllowed(source, "command.crun"), | ||
canSelf = IsPlayerAceAllowed(source, "runcode.self"), | ||
} | ||
end | ||
|
||
RegisterCommand('run', function(_, _, rawCommand) | ||
local _, _ = RunCode('lua', rawCommand:sub(4)) | ||
RegisterCommand("run", function(_, _, rawCommand) | ||
local _, _ = RunCode("lua", rawCommand:sub(4)) | ||
end, true) | ||
|
||
RegisterCommand('crun', function(source, _, rawCommand) | ||
if not source then | ||
return | ||
end | ||
RegisterCommand("crun", function(source, _, rawCommand) | ||
if not source then | ||
return | ||
end | ||
|
||
TriggerClientEvent('runcode:gotSnippet', source, -1, 'lua', rawCommand:sub(5)) | ||
TriggerClientEvent("runcode:gotSnippet", source, -1, "lua", rawCommand:sub(5)) | ||
end, true) | ||
|
||
RegisterCommand('runcode', function(source) | ||
if not source then | ||
return | ||
end | ||
RegisterCommand("runcode", function(source) | ||
if not source then | ||
return | ||
end | ||
|
||
local df = LoadResourceFile(GetCurrentResourceName(), 'data.json') | ||
local saveData = {} | ||
local df = LoadResourceFile(GetCurrentResourceName(), "data.json") | ||
local saveData = {} | ||
|
||
if df then | ||
saveData = json.decode(df) | ||
end | ||
if df then | ||
saveData = json.decode(df) | ||
end | ||
|
||
local p = GetPrivs(source) | ||
local p = GetPrivs(source) | ||
|
||
if not p.canServer and not p.canClient and not p.canSelf then | ||
return | ||
end | ||
if not p.canServer and not p.canClient and not p.canSelf then | ||
return | ||
end | ||
|
||
p.saveData = saveData | ||
p.saveData = saveData | ||
|
||
TriggerClientEvent('runcode:openUi', source, p) | ||
end, true) | ||
TriggerClientEvent("runcode:openUi", source, p) | ||
end, true) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.