Skip to content

Commit

Permalink
[Ready for Review] Admin lua scripting (#65635)
Browse files Browse the repository at this point in the history
Co-authored-by: Mothblocks <[email protected]>
  • Loading branch information
Y0SH1M4S73R and Mothblocks committed Jul 20, 2022
1 parent 88268b3 commit afe30af
Show file tree
Hide file tree
Showing 45 changed files with 2,228 additions and 16 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci_suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ jobs:
sudo apt update || true
sudo apt install -o APT::Immediate-Configure=false libssl1.1:i386
bash tools/ci/install_rust_g.sh
- name: Install auxlua
run: |
bash tools/ci/install_auxlua.sh
- name: Compile and run tests
run: |
bash tools/ci/install_byond.sh
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,8 @@ Temporary Items

# Autowiki
/tools/autowiki/node_modules

# Built auxtools libraries and intermediate files
aux*.dll
libaux*.so
aux*.pdb
12 changes: 12 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug External Libraries",
"type": "cppvsdbg",
"request": "launch",
"program": "${command:dreammaker.returnDreamDaemonPath}",
"cwd": "${workspaceRoot}",
"args": [
"${command:dreammaker.getFilenameDmb}",
"-trusted"
],
"preLaunchTask": "Build All"
},
{
"type": "byond",
"request": "launch",
Expand Down
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@
},
"[scss]": {
"editor.rulers": [80]
}
},
"Lua.diagnostics.enable": false
}
Binary file added auxlua.dll
Binary file not shown.
2 changes: 2 additions & 0 deletions code/__DEFINES/admin.dm
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
#define ADMIN_VERBOSEJMP(src) "[src ? src.Admin_Coordinates_Readable(TRUE, TRUE) : "nonexistent location"]"
#define ADMIN_INDIVIDUALLOG(user) "(<a href='?_src_=holder;[HrefToken(TRUE)];individuallog=[REF(user)]'>LOGS</a>)"
#define ADMIN_TAG(datum) "(<A href='?src=[REF(src)];[HrefToken(TRUE)];tag_datum=[REF(datum)]'>TAG</a>)"
#define ADMIN_LUAVIEW(state) "(<a href='?_src_=holder;[HrefToken(forceGlobal = TRUE)];lua_state=[REF(state)]'>VIEW STATE</a>)"
#define ADMIN_LUAVIEW_CHUNK(state, log_index) "(<a href='?_src_=holder;[HrefToken(forceGlobal = TRUE)];lua_state=[REF(state)];log_index=[log_index]'>VIEW CODE</a>)"

/atom/proc/Admin_Coordinates_Readable(area_name, admin_jump_ref)
var/turf/T = Safe_COORD_Location()
Expand Down
5 changes: 0 additions & 5 deletions code/__DEFINES/spaceman_dmm.dm
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,3 @@
/proc/enable_debugging(mode, port)
CRASH("auxtools not loaded")

/world/Del()
var/debug_server = world.GetConfig("env", "AUXTOOLS_DEBUG_DLL")
if (debug_server)
call(debug_server, "auxtools_shutdown")()
. = ..()
30 changes: 30 additions & 0 deletions code/__HELPERS/_auxtools_api.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#define AUXTOOLS_FULL_INIT 2
#define AUXTOOLS_PARTIAL_INIT 1

GLOBAL_LIST_EMPTY(auxtools_initialized)

#define AUXTOOLS_CHECK(LIB)\
if (GLOB.auxtools_initialized[LIB] != AUXTOOLS_FULL_INIT) {\
if (fexists(LIB)) {\
var/string = call(LIB,"auxtools_init")();\
if(findtext(string, "SUCCESS")) {\
GLOB.auxtools_initialized[LIB] = AUXTOOLS_FULL_INIT;\
} else {\
CRASH(string);\
}\
} else {\
CRASH("No file named [LIB] found!")\
}\
}\

#define AUXTOOLS_SHUTDOWN(LIB)\
if (GLOB.auxtools_initialized[LIB] == AUXTOOLS_FULL_INIT && fexists(LIB)){\
call(LIB,"auxtools_shutdown")();\
GLOB.auxtools_initialized[LIB] = AUXTOOLS_PARTIAL_INIT;\
}\

#define AUXTOOLS_FULL_SHUTDOWN(LIB)\
if (GLOB.auxtools_initialized[LIB] && fexists(LIB)){\
call(LIB,"auxtools_full_shutdown")();\
GLOB.auxtools_initialized[LIB] = FALSE;\
}\
87 changes: 87 additions & 0 deletions code/__HELPERS/_lists.dm
Original file line number Diff line number Diff line change
Expand Up @@ -808,3 +808,90 @@
return ref.resolve()
else
return element

#define REFIFY_KVPIFY_MAX_LENGTH 1000

/// Returns a copy of the list where any element that is a datum or the world is converted into a ref
/proc/refify_list(list/target_list)
if(length(target_list) > REFIFY_KVPIFY_MAX_LENGTH)
return "list\[[length(target_list)]\]"
var/list/ret = list()
for(var/i in 1 to target_list.len)
var/key = target_list[i]
var/new_key = key
if(isdatum(key))
new_key = "[key] [REF(key)]"
else if(key == world)
new_key = "world [REF(world)]"
else if(islist(key))
new_key = refify_list(key)
var/value
if(istext(key) || islist(key) || ispath(key) || isdatum(key) || key == world)
value = target_list[key]
if(isdatum(value))
value = "[value] [REF(value)]"
else if(value == world)
value = "world [REF(world)]"
else if(islist(value))
value = refify_list(value)
var/list/to_add = list(new_key)
if(value)
to_add[new_key] = value
ret += to_add
return ret

/**
* Converts a list into a list of assoc lists of the form ("key" = key, "value" = value)
* so that list keys that are themselves lists can be fully json-encoded
*/
/proc/kvpify_list(list/target_list, depth = INFINITY)
if(length(target_list) > REFIFY_KVPIFY_MAX_LENGTH)
return "list\[[length(target_list)]\]"
var/list/ret = list()
for(var/i in 1 to target_list.len)
var/key = target_list[i]
var/new_key = key
if(islist(key) && depth)
new_key = kvpify_list(key, depth-1)
var/value
if(istext(key) || islist(key) || ispath(key) || isdatum(key) || key == world)
value = target_list[key]
if(islist(value) && depth)
value = kvpify_list(value, depth-1)
if(value)
ret += list(list("key" = new_key, "value" = value))
else
ret += list(list("key" = i, "value" = new_key))
return ret

#undef REFIFY_KVPIFY_MAX_LENGTH

/// Compares 2 lists, returns TRUE if they are the same
/proc/deep_compare_list(list/list_1, list/list_2)
if(!islist(list_1) || !islist(list_2))
return FALSE

if(list_1 == list_2)
return TRUE

if(list_1.len != list_2.len)
return FALSE

for(var/i in 1 to list_1.len)
var/key_1 = list_1[i]
var/key_2 = list_2[i]
if (islist(key_1) && islist(key_2))
if(!deep_compare_list(key_1, key_2))
return FALSE
else if(key_1 != key_2)
return FALSE
if(istext(key_1) || islist(key_1) || ispath(key_1) || isdatum(key_1) || key_1 == world)
var/value_1 = list_1[key_1]
var/value_2 = list_2[key_1]
if (islist(value_1) && islist(value_2))
if(!deep_compare_list(value_1, value_2))
return FALSE
else if(value_1 != value_2)
return FALSE

return TRUE
12 changes: 12 additions & 0 deletions code/__HELPERS/auxtools.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/// Macro for getting the auxtools library file
#define AUXLUA (world.system_type == MS_WINDOWS ? "auxlua.dll" : __detect_auxtools("auxlua"))

/proc/__detect_auxtools(library)
if(IsAdminAdvancedProcCall())
return
if (fexists("./lib[library].so"))
return "./lib[library].so"
else if (fexists("[world.GetConfig("env", "HOME")]/.byond/bin/lib[library].so"))
return "[world.GetConfig("env", "HOME")]/.byond/bin/lib[library].so"
else
CRASH("Could not find lib[library].so")
64 changes: 64 additions & 0 deletions code/__HELPERS/logging/debug.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/// Logging for loading and caching assets
/proc/log_asset(text)
if(CONFIG_GET(flag/log_asset))
WRITE_LOG(GLOB.world_asset_log, "ASSET: [text]")

/// Logging for config errors
/// Rarely gets called; just here in case the config breaks.
/proc/log_config(text)
WRITE_LOG(GLOB.config_error_log, text)
SEND_TEXT(world.log, text)

/proc/log_filter_raw(text)
WRITE_LOG(GLOB.filter_log, "FILTER: [text]")

/// Logging for job slot changes
/proc/log_job_debug(text)
if (CONFIG_GET(flag/log_job_debug))
WRITE_LOG(GLOB.world_job_debug_log, "JOB: [text]")

/// Logging for mapping errors
/proc/log_mapping(text, skip_world_log)
#ifdef UNIT_TESTS
GLOB.unit_test_mapping_logs += text
#endif
WRITE_LOG(GLOB.world_map_error_log, text)
if(skip_world_log)
return
SEND_TEXT(world.log, text)

/// Logging for game performance
/proc/log_perf(list/perf_info)
. = "[perf_info.Join(",")]\n"
WRITE_LOG_NO_FORMAT(GLOB.perf_log, .)

/// Logging for hard deletes
/proc/log_qdel(text)
WRITE_LOG(GLOB.world_qdel_log, "QDEL: [text]")

/// Logging for SQL errors
/proc/log_query_debug(text)
WRITE_LOG(GLOB.query_debug_log, "SQL: [text]")

/// Logging for DB errors
/proc/log_sql(text)
WRITE_LOG(GLOB.sql_error_log, "SQL: [text]")

/// Logging for world/Topic
/proc/log_topic(text)
WRITE_LOG(GLOB.world_game_log, "TOPIC: [text]")

/* Log to the logfile only. */
/proc/log_runtime(text)
WRITE_LOG(GLOB.world_runtime_log, text)

/// Log to both DD and the logfile.
/proc/log_world(text)
#ifdef USE_CUSTOM_ERROR_HANDLER
WRITE_LOG(GLOB.world_runtime_log, text)
#endif
SEND_TEXT(world.log, text)

/// Logging for lua scripting
/proc/log_lua(text)
WRITE_LOG(GLOB.lua_log, text)
3 changes: 3 additions & 0 deletions code/_globalvars/logging.dm
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ GLOBAL_PROTECT(perf_log)
GLOBAL_VAR(demo_log)
GLOBAL_PROTECT(demo_log)

GLOBAL_VAR(lua_log)
GLOBAL_PROTECT(lua_log)

GLOBAL_LIST_EMPTY(bombers)
GLOBAL_PROTECT(bombers)
GLOBAL_LIST_EMPTY(admin_log)
Expand Down
2 changes: 2 additions & 0 deletions code/controllers/configuration/entries/lua.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/datum/config_entry/str_list/lua_path
protection = CONFIG_ENTRY_LOCKED | CONFIG_ENTRY_HIDDEN
Loading

0 comments on commit afe30af

Please sign in to comment.