mirror of
https://github.com/ParadiseSS13/Paradise.git
synced 2025-12-19 14:51:27 +00:00
* CI change * world.dm * .dme world.dm * subsystem renaming * .dme for subsystems * ai_laws.dm * armor.dm * emote.dm * logging.dm * spell.dm * air_alarm.dm * crew.dm * decal.dm * emissive_blocker.dm * footstep.dm * spawner.dm * fire.dm * carbon.dm * living.dm * mob.dm * movement.dm * thermal_drill.dm * plasmamen.dm * lavaland.dm * chaplain.dm * lightning.dm * magnet.dm * mimic.dm * wizard.dm * morph.dm * vampire.dm * click.dm * self.dm * radiation_storm.dm * airlock.dm * autolathe.dm * mulebot.dm * nuclearbomb.dm * particle_accelerator.dm * smartfridge.dm * syndicatebomb.dm * vending.dm * wires.dm * sound.dm * mining.dm * syndicate_space_base.dm * monkey.dm * guardian.dm * bomb.dm * standard.dm * nuclear.dm * pinpointer.dm * access.dm * departments.dm * job.dm * science.dm * buttons.dm * cloning.dm * igniter.dm * wishgranter.dm * atmos_control.dm * message.dm * power_monitor.dm * mecha.dm * combat.dm * mining_tools.dm * meteors.dm * spiders.dm * contraband.dm * aliens.dm * uplinks.dm * voice.dm * intercom.dm * lights.dm * robot_items.dm * mineral.dm * dice.dm * extinguisher.dm * paint.dm * signs.dm * staff.dm * smokebomb.dm * boxes.dm * random.dm * janicart.dm * statue.dm * cargo.dm * asteroid.dm * headslug.dm * fulton.dm * atmospherics.dm * pump.dm * corpse.dm * oldstation.dm * gps.dm * preferences.dm * clothing.dm * ears.dm * glasses.dm * boxing.dm * color.dm * renames ninja gear files * recipes.dm * error_handler.dm * anomaly.dm * floorcluwne.dm * undead.dm * overmind.dm * shield.dm * bottle.dm * organ.dm * piano.dm * plasma_fist.dm * language.dm * mob_defines.dm * mob_helpers.dm * damage_procs.dm * _defines.dm * empress.dm and queen.dm * brain.dm * organ file renaming * subsystems.dm * constructs.dm * bot.dm * pet.dm * nature.dm * magic.dm * colors.dm * drugs.dm * medicine.dm * toxins.dm * shuttle.dm * surgery.dm * moves a bunch of define files * traits.dm * names.dm * other_mobs.dm * flags.dm * some final define files * well turns out contractor_pinpointer.dm was taken * I forgot to remove this file * how in the hell did this get unticked * I DID INCLUDE IT, but there was a "w" there * swaps the world definitions * camera renamed to SScamera * examine -> alien_examine
127 lines
4.5 KiB
Plaintext
127 lines
4.5 KiB
Plaintext
SUBSYSTEM_DEF(http)
|
|
name = "HTTP"
|
|
flags = SS_TICKER | SS_BACKGROUND | SS_NO_INIT // Measure in ticks, but also only run if we have the spare CPU.
|
|
wait = 1
|
|
runlevels = RUNLEVELS_DEFAULT | RUNLEVEL_LOBBY // All the time
|
|
// Assuming for the worst, since only discord is hooked into this for now, but that may change
|
|
offline_implications = "The server is no longer capable of making async HTTP requests. Shuttle call recommended."
|
|
cpu_display = SS_CPUDISPLAY_LOW
|
|
/// List of all async HTTP requests in the processing chain
|
|
var/list/datum/http_request/active_async_requests = list()
|
|
/// Variable to define if logging is enabled or not. Disabled by default since we know the requests the server is making. Enable with VV if you need to debug requests
|
|
var/logging_enabled = FALSE
|
|
/// Total requests the SS has processed in a round
|
|
var/total_requests
|
|
|
|
/datum/controller/subsystem/http/PreInit()
|
|
. = ..()
|
|
rustg_create_async_http_client() // Open the door
|
|
|
|
/datum/controller/subsystem/http/get_stat_details()
|
|
return "P: [length(active_async_requests)] | T: [total_requests]"
|
|
|
|
/datum/controller/subsystem/http/fire(resumed)
|
|
for(var/r in active_async_requests)
|
|
var/datum/http_request/req = r
|
|
// Check if we are complete
|
|
if(req.is_complete())
|
|
// If so, take it out the processing list
|
|
active_async_requests -= req
|
|
var/datum/http_response/res = req.into_response()
|
|
|
|
// If the request has a callback, invoke it.Async of course to avoid choking the SS
|
|
if(req.cb)
|
|
req.cb.InvokeAsync(res)
|
|
|
|
// And log the result
|
|
if(logging_enabled)
|
|
var/list/log_data = list()
|
|
log_data += "BEGIN ASYNC RESPONSE (ID: [req.id])"
|
|
if(res.errored)
|
|
log_data += "\t ----- RESPONSE ERRROR -----"
|
|
log_data += "\t [res.error]"
|
|
else
|
|
log_data += "\tResponse status code: [res.status_code]"
|
|
log_data += "\tResponse body: [res.body]"
|
|
log_data += "\tResponse headers: [json_encode(res.headers)]"
|
|
log_data += "END ASYNC RESPONSE (ID: [req.id])"
|
|
rustg_log_write(GLOB.http_log, log_data.Join("\n[GLOB.log_end]"))
|
|
|
|
/**
|
|
* Async request creator
|
|
*
|
|
* Generates an async request, and adds it to the subsystem's processing list
|
|
* These should be used as they do not lock the entire DD process up as they execute inside their own thread pool inside RUSTG
|
|
*/
|
|
/datum/controller/subsystem/http/proc/create_async_request(method, url, body = "", list/headers, datum/callback/proc_callback)
|
|
var/datum/http_request/req = new()
|
|
req.prepare(method, url, body, headers)
|
|
if(proc_callback)
|
|
req.cb = proc_callback
|
|
|
|
// Begin it and add it to the SS active list
|
|
req.begin_async()
|
|
active_async_requests += req
|
|
total_requests++
|
|
|
|
if(logging_enabled)
|
|
// Create a log holder
|
|
var/list/log_data = list()
|
|
log_data += "BEGIN ASYNC REQUEST (ID: [req.id])"
|
|
log_data += "\t[uppertext(req.method)] [req.url]"
|
|
log_data += "\tRequest body: [req.body]"
|
|
log_data += "\tRequest headers: [req.headers]"
|
|
log_data += "END ASYNC REQUEST (ID: [req.id])"
|
|
|
|
// Write the log data
|
|
rustg_log_write(GLOB.http_log, log_data.Join("\n[GLOB.log_end]"))
|
|
|
|
/**
|
|
* Blocking request creator
|
|
*
|
|
* Generates a blocking request, executes it, logs the info then cleanly returns the response
|
|
* Exists as a proof of concept, and should never be used
|
|
*/
|
|
/datum/controller/subsystem/http/proc/make_blocking_request(method, url, body = "", list/headers)
|
|
CRASH("Attempted use of a blocking HTTP request")
|
|
/*
|
|
var/datum/http_request/req = new()
|
|
req.prepare(method, url, body, headers)
|
|
req.execute_blocking()
|
|
var/datum/http_response/res = req.into_response()
|
|
|
|
// Now generate a logfile
|
|
var/list/log_data = list()
|
|
log_data += "NEW BLOCKING REQUEST"
|
|
log_data += "\t[uppertext(req.method)] [req.url]"
|
|
log_data += "\tRequest body: [req.body]"
|
|
log_data += "\tRequest headers: [req.headers]"
|
|
if(res.errored)
|
|
log_data += "\t ----- RESPONSE ERRROR -----"
|
|
log_data += "\t [res.error]"
|
|
else
|
|
log_data += "\tResponse status code: [res.status_code]"
|
|
log_data += "\tResponse body: [res.body]"
|
|
log_data += "\tResponse headers: [json_encode(res.headers)]"
|
|
log_data += "END BLOCKING REQUEST"
|
|
|
|
// Write the log data
|
|
rustg_log_write(GLOB.http_log, log_data.Join("\n[GLOB.log_end]"))
|
|
|
|
return res
|
|
*/
|
|
|
|
/*
|
|
|
|
Example of how to use callbacks properly
|
|
|
|
/client/verb/testing()
|
|
set name = "Testing"
|
|
|
|
var/datum/callback/cb = CALLBACK(src, TYPE_PROC_REF(/client, response), usr)
|
|
SShttp.create_async_request(RUSTG_HTTP_METHOD_GET, "http://site.domain/page.html", proc_callback=cb)
|
|
|
|
/client/proc/response(mob/user, datum/http_response/response)
|
|
to_chat(user, "<span class='notice'>Code: [response.status_code] | Content: [response.body]")
|
|
*/
|