Skip to content

Commit

Permalink
Merge branch 'BeeStation:master' into test-fighter
Browse files Browse the repository at this point in the history
  • Loading branch information
Pockets-byte authored Jun 14, 2024
2 parents e01e2c8 + c4cd604 commit 04e1da3
Show file tree
Hide file tree
Showing 41 changed files with 494 additions and 116 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#Ignore byond config folder.
/cfg/**/*
config/starmap/starmap.json

# Ignore compiled linux libs in the root folder, e.g. librust_g.so
/*.so
Expand Down
226 changes: 192 additions & 34 deletions code/__DEFINES/rust_g.dm
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,59 @@
#define RUST_G (__rust_g || __detect_rust_g())
#endif

// Handle 515 call() -> call_ext() changes
#if DM_VERSION >= 515
#define RUSTG_CALL call_ext
#else
#define RUSTG_CALL call
#endif

/// Gets the version of rust_g
/proc/rustg_get_version() return RUSTG_CALL(RUST_G, "get_version")()


/**
* Sets up the Aho-Corasick automaton with its default options.
*
* The search patterns list and the replacements must be of the same length when replace is run, but an empty replacements list is allowed if replacements are supplied with the replace call
* Arguments:
* * key - The key for the automaton, to be used with subsequent rustg_acreplace/rustg_acreplace_with_replacements calls
* * patterns - A non-associative list of strings to search for
* * replacements - Default replacements for this automaton, used with rustg_acreplace
*/
#define rustg_setup_acreplace(key, patterns, replacements) RUSTG_CALL(RUST_G, "setup_acreplace")(key, json_encode(patterns), json_encode(replacements))

/**
* Sets up the Aho-Corasick automaton using supplied options.
*
* The search patterns list and the replacements must be of the same length when replace is run, but an empty replacements list is allowed if replacements are supplied with the replace call
* Arguments:
* * key - The key for the automaton, to be used with subsequent rustg_acreplace/rustg_acreplace_with_replacements calls
* * options - An associative list like list("anchored" = 0, "ascii_case_insensitive" = 0, "match_kind" = "Standard"). The values shown on the example are the defaults, and default values may be omitted. See the identically named methods at https://docs.rs/aho-corasick/latest/aho_corasick/struct.AhoCorasickBuilder.html to see what the options do.
* * patterns - A non-associative list of strings to search for
* * replacements - Default replacements for this automaton, used with rustg_acreplace
*/
#define rustg_setup_acreplace_with_options(key, options, patterns, replacements) RUSTG_CALL(RUST_G, "setup_acreplace")(key, json_encode(options), json_encode(patterns), json_encode(replacements))

/**
* Run the specified replacement engine with the provided haystack text to replace, returning replaced text.
*
* Arguments:
* * key - The key for the automaton
* * text - Text to run replacements on
*/
#define rustg_acreplace(key, text) RUSTG_CALL(RUST_G, "acreplace")(key, text)

/**
* Run the specified replacement engine with the provided haystack text to replace, returning replaced text.
*
* Arguments:
* * key - The key for the automaton
* * text - Text to run replacements on
* * replacements - Replacements for this call. Must be the same length as the set-up patterns
*/
#define rustg_acreplace_with_replacements(key, text, replacements) RUSTG_CALL(RUST_G, "acreplace_with_replacements")(key, text, json_encode(replacements))

/**
* This proc generates a cellular automata noise grid which can be used in procedural generation methods.
*
Expand All @@ -52,35 +105,58 @@
* * height: The height of the grid.
*/
#define rustg_cnoise_generate(percentage, smoothing_iterations, birth_limit, death_limit, width, height) \
LIBCALL(RUST_G, "cnoise_generate")(percentage, smoothing_iterations, birth_limit, death_limit, width, height)
RUSTG_CALL(RUST_G, "cnoise_generate")(percentage, smoothing_iterations, birth_limit, death_limit, width, height)

/**
* This proc generates a grid of perlin-like noise
*
* Returns a single string that goes row by row, with values of 1 representing an turned on cell, and a value of 0 representing a turned off cell.
*
* Arguments:
* * seed: seed for the function
* * accuracy: how close this is to the original perlin noise, as accuracy approaches infinity, the noise becomes more and more perlin-like
* * stamp_size: Size of a singular stamp used by the algorithm, think of this as the same stuff as frequency in perlin noise
* * world_size: size of the returned grid.
* * lower_range: lower bound of values selected for. (inclusive)
* * upper_range: upper bound of values selected for. (exclusive)
*/
#define rustg_dbp_generate(seed, accuracy, stamp_size, world_size, lower_range, upper_range) \
RUSTG_CALL(RUST_G, "dbp_generate")(seed, accuracy, stamp_size, world_size, lower_range, upper_range)

#define rustg_dmi_strip_metadata(fname) LIBCALL(RUST_G, "dmi_strip_metadata")("[fname]")
#define rustg_dmi_create_png(path, width, height, data) LIBCALL(RUST_G, "dmi_create_png")(path, width, height, data)
#define rustg_dmi_resize_png(path, width, height, resizetype) LIBCALL(RUST_G, "dmi_resize_png")(path, width, height, resizetype)

#define rustg_file_read(fname) LIBCALL(RUST_G, "file_read")("[fname]")
#define rustg_file_exists(fname) LIBCALL(RUST_G, "file_exists")("[fname]")
#define rustg_file_write(text, fname) LIBCALL(RUST_G, "file_write")(text, "[fname]")
#define rustg_file_append(text, fname) LIBCALL(RUST_G, "file_append")(text, "[fname]")
#define rustg_dmi_strip_metadata(fname) RUSTG_CALL(RUST_G, "dmi_strip_metadata")("[fname]")
#define rustg_dmi_create_png(path, width, height, data) RUSTG_CALL(RUST_G, "dmi_create_png")(path, width, height, data)
#define rustg_dmi_resize_png(path, width, height, resizetype) RUSTG_CALL(RUST_G, "dmi_resize_png")(path, width, height, resizetype)

#define rustg_file_read(fname) RUSTG_CALL(RUST_G, "file_read")("[fname]")
#define rustg_file_exists(fname) RUSTG_CALL(RUST_G, "file_exists")("[fname]")
#define rustg_file_write(text, fname) RUSTG_CALL(RUST_G, "file_write")(text, "[fname]")
#define rustg_file_append(text, fname) RUSTG_CALL(RUST_G, "file_append")(text, "[fname]")
#define rustg_file_get_line_count(fname) text2num(RUSTG_CALL(RUST_G, "file_get_line_count")("[fname]"))
#define rustg_file_seek_line(fname, line) RUSTG_CALL(RUST_G, "file_seek_line")("[fname]", "[line]")

#ifdef RUSTG_OVERRIDE_BUILTINS
#define file2text(fname) rustg_file_read("[fname]")
#define text2file(text, fname) rustg_file_append(text, "[fname]")
#define file2text(fname) rustg_file_read("[fname]")
#define text2file(text, fname) rustg_file_append(text, "[fname]")
#endif

#define rustg_git_revparse(rev) LIBCALL(RUST_G, "rg_git_revparse")(rev)
#define rustg_git_commit_date(rev) LIBCALL(RUST_G, "rg_git_commit_date")(rev)
#define rustg_git_revparse(rev) RUSTG_CALL(RUST_G, "rg_git_revparse")(rev)
#define rustg_git_commit_date(rev) RUSTG_CALL(RUST_G, "rg_git_commit_date")(rev)

#define rustg_hash_string(algorithm, text) LIBCALL(RUST_G, "hash_string")(algorithm, text)
#define rustg_hash_file(algorithm, fname) LIBCALL(RUST_G, "hash_file")(algorithm, "[fname]")
#define rustg_hash_string(algorithm, text) RUSTG_CALL(RUST_G, "hash_string")(algorithm, text)
#define rustg_hash_file(algorithm, fname) RUSTG_CALL(RUST_G, "hash_file")(algorithm, "[fname]")
#define rustg_hash_generate_totp(seed) RUSTG_CALL(RUST_G, "generate_totp")(seed)
#define rustg_hash_generate_totp_tolerance(seed, tolerance) RUSTG_CALL(RUST_G, "generate_totp_tolerance")(seed, tolerance)

#define RUSTG_HASH_MD5 "md5"
#define RUSTG_HASH_SHA1 "sha1"
#define RUSTG_HASH_SHA256 "sha256"
#define RUSTG_HASH_SHA512 "sha512"
#define RUSTG_HASH_XXH64 "xxh64"
#define RUSTG_HASH_BASE64 "base64"

#ifdef RUSTG_OVERRIDE_BUILTINS
#define md5(thing) (isfile(thing) ? rustg_hash_file(RUSTG_HASH_MD5, "[thing]") : rustg_hash_string(RUSTG_HASH_MD5, thing))
#define md5(thing) (isfile(thing) ? rustg_hash_file(RUSTG_HASH_MD5, "[thing]") : rustg_hash_string(RUSTG_HASH_MD5, thing))
#endif

#define RUSTG_HTTP_METHOD_GET "get"
Expand All @@ -89,35 +165,117 @@
#define RUSTG_HTTP_METHOD_PATCH "patch"
#define RUSTG_HTTP_METHOD_HEAD "head"
#define RUSTG_HTTP_METHOD_POST "post"
#define rustg_http_request_blocking(method, url, body, headers) LIBCALL(RUST_G, "http_request_blocking")(method, url, body, headers)
#define rustg_http_request_async(method, url, body, headers) LIBCALL(RUST_G, "http_request_async")(method, url, body, headers)
#define rustg_http_check_request(req_id) LIBCALL(RUST_G, "http_check_request")(req_id)
#define rustg_http_request_blocking(method, url, body, headers, options) RUSTG_CALL(RUST_G, "http_request_blocking")(method, url, body, headers, options)
#define rustg_http_request_async(method, url, body, headers, options) RUSTG_CALL(RUST_G, "http_request_async")(method, url, body, headers, options)
#define rustg_http_check_request(req_id) RUSTG_CALL(RUST_G, "http_check_request")(req_id)

#define RUSTG_JOB_NO_RESULTS_YET "NO RESULTS YET"
#define RUSTG_JOB_NO_SUCH_JOB "NO SUCH JOB"
#define RUSTG_JOB_ERROR "JOB PANICKED"

#define rustg_json_is_valid(text) (LIBCALL(RUST_G, "json_is_valid")(text) == "true")
#define rustg_json_is_valid(text) (RUSTG_CALL(RUST_G, "json_is_valid")(text) == "true")

#define rustg_log_write(fname, text, format) RUSTG_CALL(RUST_G, "log_write")("[fname]", text, format)
/proc/rustg_log_close_all() return RUSTG_CALL(RUST_G, "log_close_all")()

#define rustg_noise_get_at_coordinates(seed, x, y) RUSTG_CALL(RUST_G, "noise_get_at_coordinates")(seed, x, y)

/**
* Register a list of nodes into a rust library. This list of nodes must have been serialized in a json.
* Node {// Index of this node in the list of nodes
* unique_id: usize,
* // Position of the node in byond
* x: usize,
* y: usize,
* z: usize,
* // Indexes of nodes connected to this one
* connected_nodes_id: Vec<usize>}
* It is important that the node with the unique_id 0 is the first in the json, unique_id 1 right after that, etc.
* It is also important that all unique ids follow. {0, 1, 2, 4} is not a correct list and the registering will fail
* Nodes should not link across z levels.
* A node cannot link twice to the same node and shouldn't link itself either
*/
#define rustg_register_nodes_astar(json) RUSTG_CALL(RUST_G, "register_nodes_astar")(json)

/**
* Add a new node to the static list of nodes. Same rule as registering_nodes applies.
* This node unique_id must be equal to the current length of the static list of nodes
*/
#define rustg_add_node_astar(json) RUSTG_CALL(RUST_G, "add_node_astar")(json)

/*
* Remove every link to the node with unique_id. Replace that node by null
*/
#define rustg_remove_node_astart(unique_id) RUSTG_CALL(RUST_G, "remove_node_astar")(unique_id)

/**
* Compute the shortest path between start_node and goal_node using A*. Heuristic used is simple geometric distance
*/
#define rustg_generate_path_astar(start_node_id, goal_node_id) RUSTG_CALL(RUST_G, "generate_path_astar")(start_node_id, goal_node_id)

#define RUSTG_REDIS_ERROR_CHANNEL "RUSTG_REDIS_ERROR_CHANNEL"

#define rustg_log_write(fname, text, format) LIBCALL(RUST_G, "log_write")("[fname]", text, format)
/proc/rustg_log_close_all() return LIBCALL(RUST_G, "log_close_all")()
#define rustg_redis_connect(addr) RUSTG_CALL(RUST_G, "redis_connect")(addr)
/proc/rustg_redis_disconnect() return RUSTG_CALL(RUST_G, "redis_disconnect")()
#define rustg_redis_subscribe(channel) RUSTG_CALL(RUST_G, "redis_subscribe")(channel)
/proc/rustg_redis_get_messages() return RUSTG_CALL(RUST_G, "redis_get_messages")()
#define rustg_redis_publish(channel, message) RUSTG_CALL(RUST_G, "redis_publish")(channel, message)

#define rustg_noise_get_at_coordinates(seed, x, y) LIBCALL(RUST_G, "noise_get_at_coordinates")(seed, x, y)
#define rustg_sql_connect_pool(options) RUSTG_CALL(RUST_G, "sql_connect_pool")(options)
#define rustg_sql_query_async(handle, query, params) RUSTG_CALL(RUST_G, "sql_query_async")(handle, query, params)
#define rustg_sql_query_blocking(handle, query, params) RUSTG_CALL(RUST_G, "sql_query_blocking")(handle, query, params)
#define rustg_sql_connected(handle) RUSTG_CALL(RUST_G, "sql_connected")(handle)
#define rustg_sql_disconnect_pool(handle) RUSTG_CALL(RUST_G, "sql_disconnect_pool")(handle)
#define rustg_sql_check_query(job_id) RUSTG_CALL(RUST_G, "sql_check_query")("[job_id]")

#define rustg_sql_connect_pool(options) LIBCALL(RUST_G, "sql_connect_pool")(options)
#define rustg_sql_query_async(handle, query, params) LIBCALL(RUST_G, "sql_query_async")(handle, query, params)
#define rustg_sql_query_blocking(handle, query, params) LIBCALL(RUST_G, "sql_query_blocking")(handle, query, params)
#define rustg_sql_connected(handle) LIBCALL(RUST_G, "sql_connected")(handle)
#define rustg_sql_disconnect_pool(handle) LIBCALL(RUST_G, "sql_disconnect_pool")(handle)
#define rustg_sql_check_query(job_id) LIBCALL(RUST_G, "sql_check_query")("[job_id]")
#define rustg_time_microseconds(id) text2num(RUSTG_CALL(RUST_G, "time_microseconds")(id))
#define rustg_time_milliseconds(id) text2num(RUSTG_CALL(RUST_G, "time_milliseconds")(id))
#define rustg_time_reset(id) RUSTG_CALL(RUST_G, "time_reset")(id)

#define rustg_unzip_download_async(url, unzip_directory) LIBCALL(RUST_G, "unzip_download_async")(url, unzip_directory)
#define rustg_unzip_check(job_id) LIBCALL(RUST_G, "unzip_check")("[job_id]")
/proc/rustg_unix_timestamp()
return text2num(RUSTG_CALL(RUST_G, "unix_timestamp")())

#define rustg_url_encode(text) LIBCALL(RUST_G, "url_encode")(text)
#define rustg_url_decode(text) LIBCALL(RUST_G, "url_decode")(text)
#define rustg_raw_read_toml_file(path) json_decode(RUSTG_CALL(RUST_G, "toml_file_to_json")(path) || "null")

/proc/rustg_read_toml_file(path)
var/list/output = rustg_raw_read_toml_file(path)
if (output["success"])
return json_decode(output["content"])
else
CRASH(output["content"])

#define rustg_raw_toml_encode(value) json_decode(RUSTG_CALL(RUST_G, "toml_encode")(json_encode(value)))

/proc/rustg_toml_encode(value)
var/list/output = rustg_raw_toml_encode(value)
if (output["success"])
return output["content"]
else
CRASH(output["content"])

#define rustg_unzip_download_async(url, unzip_directory) RUSTG_CALL(RUST_G, "unzip_download_async")(url, unzip_directory)
#define rustg_unzip_check(job_id) RUSTG_CALL(RUST_G, "unzip_check")("[job_id]")

#define rustg_url_encode(text) RUSTG_CALL(RUST_G, "url_encode")("[text]")
#define rustg_url_decode(text) RUSTG_CALL(RUST_G, "url_decode")(text)

#ifdef RUSTG_OVERRIDE_BUILTINS
#define url_encode(text) rustg_url_encode(text)
#define url_decode(text) rustg_url_decode(text)
#define url_encode(text) rustg_url_encode(text)
#define url_decode(text) rustg_url_decode(text)
#endif

/**
* This proc generates a noise grid using worley noise algorithm
*
* Returns a single string that goes row by row, with values of 1 representing an alive cell, and a value of 0 representing a dead cell.
*
* Arguments:
* * region_size: The size of regions
* * threshold: the value that determines wether a cell is dead or alive
* * node_per_region_chance: chance of a node existiing in a region
* * size: size of the returned grid
* * node_min: minimum amount of nodes in a region (after the node_per_region_chance is applied)
* * node_max: maximum amount of nodes in a region
*/
#define rustg_worley_generate(region_size, threshold, node_per_region_chance, size, node_min, node_max) \
RUSTG_CALL(RUST_G, "worley_generate")(region_size, threshold, node_per_region_chance, size, node_min, node_max)
26 changes: 24 additions & 2 deletions code/__DEFINES/tgs.dm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// tgstation-server DMAPI

#define TGS_DMAPI_VERSION "7.0.2"
#define TGS_DMAPI_VERSION "7.1.2"

// All functions and datums outside this document are subject to change with any version and should not be relied on.

Expand Down Expand Up @@ -50,6 +50,13 @@

#endif

#ifndef TGS_FILE2TEXT_NATIVE
#ifdef file2text
#error Your codebase is re-defining the BYOND proc file2text. The DMAPI requires the native version to read the result of world.Export(). You can fix this by adding "#define TGS_FILE2TEXT_NATIVE file2text" before your override of file2text to allow the DMAPI to use the native version. This will only be used for world.Export(), not regular file accesses
#endif
#define TGS_FILE2TEXT_NATIVE file2text
#endif

// EVENT CODES

/// Before a reboot mode change, extras parameters are the current and new reboot mode enums.
Expand Down Expand Up @@ -305,6 +312,7 @@
var/datum/tgs_chat_embed/structure/embed

/datum/tgs_message_content/New(text)
..()
if(!istext(text))
TGS_ERROR_LOG("[/datum/tgs_message_content] created with no text!")
text = null
Expand Down Expand Up @@ -347,6 +355,7 @@
var/proxy_url

/datum/tgs_chat_embed/media/New(url)
..()
if(!istext(url))
CRASH("[/datum/tgs_chat_embed/media] created with no url!")

Expand All @@ -360,6 +369,7 @@
var/proxy_icon_url

/datum/tgs_chat_embed/footer/New(text)
..()
if(!istext(text))
CRASH("[/datum/tgs_chat_embed/footer] created with no text!")

Expand All @@ -376,6 +386,7 @@
var/proxy_icon_url

/datum/tgs_chat_embed/provider/author/New(name)
..()
if(!istext(name))
CRASH("[/datum/tgs_chat_embed/provider/author] created with no name!")

Expand All @@ -388,6 +399,7 @@
var/is_inline

/datum/tgs_chat_embed/field/New(name, value)
..()
if(!istext(name))
CRASH("[/datum/tgs_chat_embed/field] created with no name!")

Expand Down Expand Up @@ -490,10 +502,20 @@
/world/proc/TgsChatChannelInfo()
return

/**
* Trigger an event in TGS. Requires TGS version >= 6.3.0. Returns [TRUE] if the event was triggered successfully, [FALSE] otherwise. This function may sleep!
*
* event_name - The name of the event to trigger
* parameters - Optional list of string parameters to pass as arguments to the event script. The first parameter passed to a script will always be the running game's directory followed by these parameters.
* wait_for_completion - If set, this function will not return until the event has run to completion.
*/
/world/proc/TgsTriggerEvent(event_name, list/parameters, wait_for_completion = FALSE)
return

/*
The MIT License
Copyright (c) 2017-2023 Jordan Brown
Copyright (c) 2017-2024 Jordan Brown
Permission is hereby granted, free of charge,
to any person obtaining a copy of this software and
Expand Down
8 changes: 0 additions & 8 deletions code/__byond_version_compat.dm
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,6 @@
/savefile/byond_version = MIN_COMPILER_VERSION
#endif

// Temporary 515 block until it is completely compatible.
// AnturK says there are issues with savefiles that would make it dangerous to test merge,
// and so this check is in place to stop serious damage.
// That being said, if you really are ready, you can give YES_I_WANT_515 to TGS.
#if !defined(YES_I_WANT_515) && DM_VERSION >= 515
#error We do not yet completely support BYOND 515.
#endif

// 515 split call for external libraries into call_ext
#if DM_VERSION < 515
#define LIBCALL call
Expand Down
6 changes: 3 additions & 3 deletions code/_compile_options.dm
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@
//End NSV

//Update this whenever the byond version is stable so people stop updating to hilariously broken versions
#define MAX_COMPILER_VERSION 514
#define MAX_COMPILER_BUILD 1589
#define MAX_COMPILER_VERSION 515
#define MAX_COMPILER_BUILD 1700
#if DM_VERSION > MAX_COMPILER_VERSION || DM_BUILD > MAX_COMPILER_BUILD
#warn WARNING: Your BYOND version is over the recommended version (514.1589)! Stability is not guaranteed.
#warn WARNING: Your BYOND version is over the recommended version (515.1700)! Stability is not guaranteed.
#endif
//Log the full sendmaps profile on 514.1556+, any earlier and we get bugs or it not existing
#if DM_VERSION >= 514 && DM_BUILD >= 1556
Expand Down
Loading

0 comments on commit 04e1da3

Please sign in to comment.