Skip to content

Commit

Permalink
Adds Cross-Server Communication Network Option (PAID* CODE) (tgstatio…
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbah authored Oct 1, 2020
1 parent 1bff36f commit 7b1bed7
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 15 deletions.
3 changes: 3 additions & 0 deletions code/controllers/configuration/entries/comms.dm
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@
return key_value != "byond:\\address:port" && ..()

/datum/config_entry/string/cross_comms_name

/datum/config_entry/string/cross_comms_network
protection = CONFIG_ENTRY_LOCKED
6 changes: 6 additions & 0 deletions code/datums/world_topic.dm
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@
require_comms_key = TRUE

/datum/world_topic/comms_console/Run(list/input)
// Reject comms messages from other servers that are not on our configured network,
// if this has been configured. (See CROSS_COMMS_NETWORK in comms.txt)
var/configured_network = CONFIG_GET(string/cross_comms_network)
if (configured_network && configured_network != input["network"])
return

minor_announce(input["message"], "Incoming message from [input["message_sender"]]")
for(var/obj/machinery/computer/communications/CM in GLOB.machines)
CM.overrideCooldown()
Expand Down
13 changes: 7 additions & 6 deletions code/game/machinery/computer/communications.dm
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,14 @@
if(!input || !(usr in view(1,src)) || !checkCCcooldown())
return
playsound(src, 'sound/machines/terminal_prompt_confirm.ogg', 50, FALSE)
if(dest == "all")
send2otherserver("[station_name()]", input,"Comms_Console")
else
send2otherserver("[station_name()]", input,"Comms_Console", list(dest))
var/payload = list()
var/network_name = CONFIG_GET(string/cross_comms_network)
if (network_name)
payload["network"] = network_name
send2otherserver("[station_name()]", input,"Comms_Console", dest == "all" ? null : list(dest), additional_data = payload)
minor_announce(input, title = "Outgoing message to allied station")
usr.log_talk(input, LOG_SAY, tag="message to the other server")
message_admins("[ADMIN_LOOKUPFLW(usr)] has sent a message to the other server.")
message_admins("[ADMIN_LOOKUPFLW(usr)] has sent a message to the other server\[s].")
deadchat_broadcast(" has sent an outgoing message to the other station(s).</span>", "<span class='bold'>[usr.real_name]", usr, message_type=DEADCHAT_ANNOUNCEMENT)
CM.lastTimeUsed = world.time

Expand Down Expand Up @@ -484,7 +485,7 @@
for(var/server in cross_servers)
if(server == our_id)
continue
dat += "<BR>\[ <A HREF='?src=[REF(src)];operation=crossserver=all;cross_dest=[server]'>Send a message to station in [server] sector.</A> \]"
dat += "<BR>\[ <A HREF='?src=[REF(src)];operation=crossserver;cross_dest=[server]'>Send a message to station in [server] sector.</A> \]"
if(cross_servers.len > 2)
dat += "<BR>\[ <A HREF='?src=[REF(src)];operation=crossserver;cross_dest=all'>Send a message to all allied stations</A> \]"
if(SSmapping.config.allow_custom_shuttles)
Expand Down
24 changes: 16 additions & 8 deletions code/modules/admin/verbs/adminhelp.dm
Original file line number Diff line number Diff line change
Expand Up @@ -589,26 +589,34 @@ GLOBAL_DATUM_INIT(ahelp_tickets, /datum/admin_help_tickets, new)
send2adminchat(source,final)
send2otherserver(source,final)

/// Sends a message to other servers.
/proc/send2otherserver(source,msg,type = "Ahelp",target_servers)
/**
* Sends a message to a set of cross-communications-enabled servers using world topic calls
*
* Arguments:
* * source - Who sent this message
* * msg - The message body
* * type - The type of message, becomes the topic command under the hood
* * target_servers - A collection of servers to send the message to, defined in config
* * additional_data - An (optional) associated list of extra parameters and data to send with this world topic call
*/
/proc/send2otherserver(source, msg, type = "Ahelp", target_servers, list/additional_data = list())
if(!CONFIG_GET(string/comms_key))
debug_world_log("Server cross-comms message not sent for lack of configured key")
return

var/our_id = CONFIG_GET(string/cross_comms_name)
var/list/message = list()
message["message_sender"] = source
message["message"] = msg
message["source"] = "([our_id])"
message += type
additional_data["message_sender"] = source
additional_data["message"] = msg
additional_data["source"] = "([our_id])"
additional_data += type

var/list/servers = CONFIG_GET(keyed_list/cross_server)
for(var/I in servers)
if(I == our_id) //No sending to ourselves
continue
if(target_servers && !(I in target_servers))
continue
world.send_cross_comms(I, message)
world.send_cross_comms(I, additional_data)

/// Sends a message to a given cross comms server by name (by name for security).
/world/proc/send_cross_comms(server_name, list/message, auth = TRUE)
Expand Down
7 changes: 6 additions & 1 deletion config/comms.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,9 @@
#CROSS_SERVER ServerName byond:\\address:port

## Name that the server calls itself in communications
#CROSS_COMMS_NAME
#CROSS_COMMS_NAME

## Network-name used for cross-server broadcasts made from communication consoles.
## Servers that do not match this network-name will have their messages discarded.
## Leaving this commented will allow all messages through, regardless of network.
#CROSS_COMMS_NETWORK default_network

0 comments on commit 7b1bed7

Please sign in to comment.