Skip to content

Commit

Permalink
DMAPI Try 2
Browse files Browse the repository at this point in the history
  • Loading branch information
steamport committed Sep 20, 2018
1 parent 6c3fe68 commit 0855aca
Show file tree
Hide file tree
Showing 36 changed files with 1,391 additions and 90 deletions.
4 changes: 4 additions & 0 deletions baystation12.dme
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,14 @@
#include "code\__defines\process_scheduler.dm"
#include "code\__defines\qdel.dm"
#include "code\__defines\research.dm"
#include "code\__defines\rust_g.dm"
#include "code\__defines\shields.dm"
#include "code\__defines\species.dm"
#include "code\__defines\subsystem-priority.dm"
#include "code\__defines\subsystems.dm"
#include "code\__defines\targeting.dm"
#include "code\__defines\tgs.config.dm"
#include "code\__defines\tgs.dm"
#include "code\__defines\tgui.dm"
#include "code\__defines\tick.dm"
#include "code\__defines\topic.dm"
Expand Down Expand Up @@ -1384,6 +1387,7 @@
#include "code\modules\detectivework\tools\storage.dm"
#include "code\modules\detectivework\tools\swabs.dm"
#include "code\modules\detectivework\tools\uvlight.dm"
#include "code\modules\DMAPI\tgs\includes.dm"
#include "code\modules\donator\client.dm"
#include "code\modules\donator\donator_holder.dm"
#include "code\modules\donator\donator_ooc.dm"
Expand Down
12 changes: 12 additions & 0 deletions code/__defines/rust_g.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#define RUST_G (world.system_type == MS_WINDOWS ? "rust_g.dll" : "librust_g.so")

#define rustg_log_write(filename, text) world.system_type == UNIX ? file(filename) << text : call(RUST_G, "log_write")(filename, text)

#define rustg_dmi_strip_metadata(fname) call(RUST_G, "dmi_strip_metadata")(fname)

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

#define rustg_log_write(fname, text) call(RUST_G, "log_write")(fname, text)

/proc/rustg_log_close_all() return call(RUST_G, "log_close_all")()
11 changes: 11 additions & 0 deletions code/__defines/tgs.config.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//Remember, every codebase is different, you probably have better methods for these defines than the ones given here
#define TGS_EXTERNAL_CONFIGURATION
#define TGS_DEFINE_AND_SET_GLOBAL(Name, Value) GLOBAL_VAR_INIT(##Name, ##Value); GLOBAL_PROTECT(##Name)
#define TGS_READ_GLOBAL(Name) GLOB.##Name
#define TGS_WRITE_GLOBAL(Name, Value) GLOB.##Name = ##Value
#define TGS_WORLD_ANNOUNCE(message) to_chat(world, ##message)
#define TGS_INFO_LOG(message) log_world("TGS Info: [##message]")
#define TGS_ERROR_LOG(message) log_world("TGS Error: [##message]")
#define TGS_NOTIFY_ADMINS(event) log_world("TGS Admin Message: [##event]")
#define TGS_CLIENT_COUNT GLOB.clients.len
#define TGS_PROTECT_DATUM(Path)
224 changes: 224 additions & 0 deletions code/__defines/tgs.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
//tgstation-server DMAPI

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

//CONFIGURATION

//create this define if you want to do configuration outside of this file
#ifndef TGS_EXTERNAL_CONFIGURATION

//Comment this out once you've filled in the below
#error TGS API unconfigured

//Required interfaces (fill in with your codebase equivalent):

//create a global variable named `Name` and set it to `Value`
//These globals must not be modifiable from anywhere outside of the server tools
#define TGS_DEFINE_AND_SET_GLOBAL(Name, Value)

//Read the value in the global variable `Name`
#define TGS_READ_GLOBAL(Name)

//Set the value in the global variable `Name` to `Value`
#define TGS_WRITE_GLOBAL(Name, Value)

//Disallow ANYONE from reflecting a given `path`, security measure to prevent in-game priveledge escalation
#define TGS_PROTECT_DATUM(Path)

//display an announcement `message` from the server to all players
#define TGS_WORLD_ANNOUNCE(message)

//Notify current in-game administrators of a string `event`
#define TGS_NOTIFY_ADMINS(event)

//Write an info `message` to a server log
#define TGS_INFO_LOG(message)

//Write an error `message` to a server log
#define TGS_ERROR_LOG(message)

//Get the number of connected /clients
#define TGS_CLIENT_COUNT

#endif

//EVENT CODES

#define TGS_EVENT_PORT_SWAP -2 //before a port change is about to happen, extra parameter is new port
#define TGS_EVENT_REBOOT_MODE_CHANGE -1 //before a reboot mode change, extras parameters are the current and new reboot mode enums

//TODO

//OTHER ENUMS

#define TGS_REBOOT_MODE_NORMAL 0
#define TGS_REBOOT_MODE_SHUTDOWN 1
#define TGS_REBOOT_MODE_RESTART 2

#define TGS_SECURITY_TRUSTED 0
#define TGS_SECURITY_SAFE 1
#define TGS_SECURITY_ULTRASAFE 2

//REQUIRED HOOKS

//Call this somewhere in /world/New() that is always run
//event_handler: optional user defined event handler. The default behaviour is to broadcast the event in english to all connected admin channels
//minimum_required_security_level: The minimum required security level to run the game in which the DMAPI is integrated
/world/proc/TgsNew(datum/tgs_event_handler/event_handler, minimum_required_security_level = TGS_SECURITY_ULTRASAFE)
return

//Call this when your initializations are complete and your game is ready to play before any player interactions happen
//This may use world.sleep_offline to make this happen so ensure no changes are made to it while this call is running
//Most importantly, before this point, note that any static files or directories may be in use by another server. Your code should account for this
//This function should not be called before ..() in /world/New()
/world/proc/TgsInitializationComplete()
return

//Put this somewhere in /world/Topic(T, Addr, Master, Keys) that is always run before T is modified
#define TGS_TOPIC var/tgs_topic_return = TgsTopic(T); if(tgs_topic_return) return tgs_topic_return

//Call this at the beginning of world/Reboot(reason)
/world/proc/TgsReboot()
return

//DATUM DEFINITIONS
//unless otherwise specified all datums defined here should be considered read-only, warranty void if written

//represents git revision information about the current world build
/datum/tgs_revision_information
var/commit //full sha of compiled commit
var/origin_commit //full sha of last known remote commit. This may be null if the TGS repository is not currently tracking a remote branch

//represents a merge of a GitHub pull request
/datum/tgs_revision_information/test_merge
var/number //pull request number
var/title //pull request title
var/body //pull request body
var/author //pull request github author
var/url //link to pull request html
var/pull_request_commit //commit of the pull request when it was merged
var/time_merged //timestamp of when the merge commit for the pull request was created
var/comment //optional comment left by the one who initiated the test merge

//represents a connected chat channel
/datum/tgs_chat_channel
var/id //internal channel representation
var/friendly_name //user friendly channel name
var/connection_name //the name of the configured chat connection
var/is_admin_channel //if the server operator has marked this channel for game admins only
var/is_private_channel //if this is a private chat channel
var/custom_tag //user defined string associated with channel

//represents a chat user
/datum/tgs_chat_user
var/id //Internal user representation, requires channel to be unique
var/friendly_name //The user's public name
var/mention //The text to use to ping this user in a message
var/datum/tgs_chat_channel/channel //The /datum/tgs_chat_channel this user was from

//user definable callback for handling events
//extra parameters may be specified depending on the event
/datum/tgs_event_handler/proc/HandleEvent(event_code, ...)
set waitfor = FALSE
return

//user definable chat command
/datum/tgs_chat_command
var/name = "" //the string to trigger this command on a chat bot. e.g. TGS3_BOT: do_this_command
var/help_text = "" //help text for this command
var/admin_only = FALSE //set to TRUE if this command should only be usable by registered chat admins

//override to implement command
//sender: The tgs_chat_user who send to command
//params: The trimmed string following the command name
//The return value will be stringified and sent to the appropriate chat
/datum/tgs_chat_command/proc/Run(datum/tgs_chat_user/sender, params)
CRASH("[type] has no implementation for Run()")

//FUNCTIONS

//Returns the respective string version of the API
/world/proc/TgsMaximumAPIVersion()
return

/world/proc/TgsMinimumAPIVersion()
return

//Gets the current version of the server tools running the server
/world/proc/TgsVersion()
return

//Returns TRUE if the world was launched under the server tools and the API matches, FALSE otherwise
//No function below this succeeds if it returns FALSE
/world/proc/TgsAvailable()
return

/world/proc/TgsInstanceName()
return

//Get the current `/datum/tgs_revision_information`
/world/proc/TgsRevision()
return

//Get the current BYOND security level
/world/proc/TgsSecurityLevel()
return

//Gets a list of active `/datum/tgs_revision_information/test_merge`s
/world/proc/TgsTestMerges()
return

//Forces a hard reboot of BYOND by ending the process
//unlike del(world) clients will try to reconnect
//If the service has not requested a shutdown, the next server will take over
/world/proc/TgsEndProcess()
return

//Gets a list of connected tgs_chat_channel
/world/proc/TgsChatChannelInfo()
return

//Sends a message to connected game chats
//message: The message to send
//channels: optional channels to limit the broadcast to
/world/proc/TgsChatBroadcast(message, list/channels)
return

//Send a message to non-admin connected chats
//message: The message to send
//admin_only: If TRUE, message will instead be sent to only admin connected chats
/world/proc/TgsTargetedChatBroadcast(message, admin_only)
return

//Send a private message to a specific user
//message: The message to send
//user: The /datum/tgs_chat_user to send to
/world/proc/TgsChatPrivateMessage(message, datum/tgs_chat_user/user)
return

/*
The MIT License
Copyright (c) 2017 Jordan Brown
Permission is hereby granted, free of charge,
to any person obtaining a copy of this software and
associated documentation files (the "Software"), to
deal in the Software without restriction, including
without limitation the rights to use, copy, modify,
merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom
the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice
shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
8 changes: 4 additions & 4 deletions code/_helpers/global_access.dm
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@
if("restricted_camera_networks")
return global.restricted_camera_networks;
if("revdata")
return global.revdata;
return GLOB.revdata;
if("revs")
return global.revs;
if("robot_custom_icons")
Expand Down Expand Up @@ -1069,7 +1069,7 @@
return global.z_levels;
if("zone_blocked")
return global.zone_blocked;

/proc/writeglobal(which, newval)
switch(which)
if("ALL_ANTIGENS")
Expand Down Expand Up @@ -1879,7 +1879,7 @@
if("restricted_camera_networks")
global.restricted_camera_networks=newval;
if("revdata")
global.revdata=newval;
GLOB.revdata=newval;
if("revs")
global.revs=newval;
if("robot_custom_icons")
Expand Down Expand Up @@ -2138,7 +2138,7 @@
global.z_levels=newval;
if("zone_blocked")
global.zone_blocked=newval;

/var/list/_all_globals=list(
"ALL_ANTIGENS",
"ANTAG_FREQS",
Expand Down
9 changes: 7 additions & 2 deletions code/_helpers/logging.dm
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
//wrapper macros for easier grepping
#define WRITE_FILE(filename, text) rustg_log_write(filename, text)
#define DIRECT_OUTPUT(A, B) A << B
#define SEND_IMAGE(target, image) DIRECT_OUTPUT(target, image)
#define SEND_SOUND(target, sound) DIRECT_OUTPUT(target, sound)
#define SEND_TEXT(target, text) DIRECT_OUTPUT(target, text)
#define WRITE_FILE(file, text) DIRECT_OUTPUT(file, text)
#define WRITE_LOG(log, text) rustg_log_write(log, text)


// On Linux/Unix systems the line endings are LF, on windows it's CRLF, admins that don't use notepad++
Expand Down Expand Up @@ -33,7 +38,7 @@
to_world_log("## TESTING: [msg][log_end]")

/proc/game_log(category, text)
rustg_log_write(diary, "\[[time_stamp()]] [game_id] [category]: [text][log_end]")
WRITE_LOG(diary, "\[[time_stamp()]] [game_id] [category]: [text][log_end]")

/proc/log_admin(text)
GLOB.admin_log.Add(text)
Expand Down
2 changes: 1 addition & 1 deletion code/_helpers/type2type.dm
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
if (4.0) return EAST
if (8.0) return WEST
else
rustg_log_write(world.log, "UNKNOWN DIRECTION: [direction]")
WRITE_LOG(world.log, "UNKNOWN DIRECTION: [direction]")

// Turns a direction into text
/proc/dir2text(direction)
Expand Down
4 changes: 0 additions & 4 deletions code/_macros.dm
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,6 @@
#define show_image(target, image) target << image
#define send_rsc(target, rsc_content, rsc_name) target << browse_rsc(rsc_content, rsc_name)

// file writes on Unix are much much faster than rust_g, but rust_g is 10x faster than using the vanilla Windows system
#define rustg_log_write(filename, text) world.system_type == UNIX ? \
file(filename) << text : call("tools/rust_g.dll", "log_write")(filename, text)

#define MAP_IMAGE_PATH "nano/images/[GLOB.using_map.path]/"

#define map_image_file_name(z_level) "[GLOB.using_map.path]-[z_level].png"
Expand Down
Loading

0 comments on commit 0855aca

Please sign in to comment.