mirror of
https://github.com/PolarisSS13/Polaris.git
synced 2026-08-28 15:47:38 +01:00
Upgrades communicators to NanoUI, adds a new EPv2 fake networking system, adds new semi-telecomms machine, lets communicators call ghosts, call other communicators, and have as many ghosts or communicators linked as the user desires. Adds preference option to remain invisible on communicator device searches.
This commit is contained in:
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
Exonet Protocol Version 2
|
||||
|
||||
This is designed to be a fairly simple fake-networking system, allowing you to send and receive messages
|
||||
between the exonet_protocol datums, and for atoms to react to those messages, based on the contents of the message.
|
||||
Hopefully, this can evolve to be a more robust fake-networking system and allow for some devious network hacking in the future.
|
||||
|
||||
Version 1 never existed.
|
||||
|
||||
*Setting up*
|
||||
|
||||
To set up the exonet link, define a variable on your desired atom it is like this;
|
||||
var/datum/exonet_protocol/exonet = null
|
||||
Afterwards, before you want to do networking, call exonet = New(src), then exonet.make_address(string), and give it a string to hash into the new IP.
|
||||
The reason it needs a string is so you can have the addresses be persistant, assuming no-one already took it first.
|
||||
|
||||
When you're no longer wanting to use the address and want to free it up, like when you want to Destroy() it, you need to call remove_address()
|
||||
|
||||
*Sending messages*
|
||||
|
||||
To send a message to another datum, you need to know it's EPv2 (fake IP) address. Once you know that, call send_message(), place your
|
||||
intended address in the first argument, then the message in the second. For example, send_message(exonet.address, "ping") will make you
|
||||
ping yourself.
|
||||
|
||||
*Receiving messages*
|
||||
You don't need to do anything special to receive the messages, other than give your target exonet datum an address as well. Once something hits
|
||||
your datum with send_message(), receive_message() is called, and the default action is to call receive_exonet_message() on the datum's holder.
|
||||
You'll want to override receive_exonet_message() on your atom, and define what will occur when the message is received.
|
||||
The receiving atom will receive the origin atom (the atom that sent the message), the origin address, and finally the message itself.
|
||||
It's suggested to start with an if or switch statement for the message, to determine what to do.
|
||||
*/
|
||||
|
||||
var/global/list/all_exonet_connections = list()
|
||||
|
||||
/datum/exonet_protocol
|
||||
var/address = "" //Resembles IPv6, but with only five 'groups', e.g. XXXX:XXXX:XXXX:XXXX:XXXX
|
||||
var/atom/movable/holder = null
|
||||
|
||||
/datum/exonet_protocol/New(var/atom/holder)
|
||||
src.holder = holder
|
||||
..()
|
||||
|
||||
|
||||
// Proc: make_address()
|
||||
// Parameters: 1 (string - used to make into a hash that will be part of the new address)
|
||||
// Description: Allocates a new address based on the string supplied. It results in consistant addresses for each round assuming it is not already taken..
|
||||
/datum/exonet_protocol/proc/make_address(var/string)
|
||||
if(string)
|
||||
var/new_address = null
|
||||
while(new_address == find_address(new_address)) //Collision test.
|
||||
var/hash = md5(string)
|
||||
var/raw_address = copytext(hash,1,25)
|
||||
var/addr_0 = "fc00" //Used for unique local address in real-life IPv6.
|
||||
var/addr_1 = hexadecimal_to_EPv2(raw_address)
|
||||
|
||||
new_address = "[addr_0]:[addr_1]"
|
||||
string = "[string]0" //If we did get a collision, this should make the next attempt not have one.
|
||||
sleep(1)
|
||||
address = new_address
|
||||
all_exonet_connections |= src
|
||||
|
||||
|
||||
// Proc: make_arbitrary_address()
|
||||
// Parameters: 1 (new_address - the desired address)
|
||||
// Description: Allocates that specific address, if it is available.
|
||||
/datum/exonet_protocol/proc/make_arbitrary_address(var/new_address)
|
||||
if(new_address)
|
||||
if(new_address == find_address(new_address) ) //Collision test.
|
||||
return 0
|
||||
address = new_address
|
||||
all_exonet_connections |= src
|
||||
return 1
|
||||
|
||||
// Proc: hexadecimal_to_EPv2()
|
||||
// Parameters: 1 (hex - a string of hexadecimals to convert)
|
||||
// Description: Helper proc to add colons to a string in the right places.
|
||||
/proc/hexadecimal_to_EPv2(var/hex)
|
||||
if(!hex)
|
||||
return null
|
||||
var/addr_1 = copytext(hex,1,5)
|
||||
var/addr_2 = copytext(hex,5,9)
|
||||
var/addr_3 = copytext(hex,9,13)
|
||||
var/addr_4 = copytext(hex,13,17)
|
||||
var/new_address = "[addr_1]:[addr_2]:[addr_3]:[addr_4]"
|
||||
return new_address
|
||||
|
||||
|
||||
// Proc: remove_address()
|
||||
// Parameters: None
|
||||
// Description: Deallocates the address, freeing it for use.
|
||||
/datum/exonet_protocol/proc/remove_address()
|
||||
address = ""
|
||||
all_exonet_connections.Remove(src)
|
||||
|
||||
|
||||
// Proc: find_address()
|
||||
// Parameters: 1 (target_address - the desired address to find)
|
||||
// Description: Searches the global list all_exonet_connections for a specific address, and returns it if found, otherwise returns null.
|
||||
/datum/exonet_protocol/proc/find_address(var/target_address)
|
||||
for(var/datum/exonet_protocol/exonet in all_exonet_connections)
|
||||
if(exonet.address == target_address)
|
||||
return exonet.address
|
||||
return null
|
||||
|
||||
// Proc: send_message()
|
||||
// Parameters: 2 (target_address - the desired address to send the message to, message - the message to send)
|
||||
// Description: Sends the message to target_address, by calling receive_message() on the desired datum.
|
||||
/datum/exonet_protocol/proc/send_message(var/target_address, var/message)
|
||||
if(!address)
|
||||
return 0
|
||||
for(var/datum/exonet_protocol/exonet in all_exonet_connections)
|
||||
if(exonet.address == target_address)
|
||||
exonet.receive_message(holder, address, message)
|
||||
break
|
||||
|
||||
// Proc: receive_message()
|
||||
// Parameters: 3 (origin_atom - the origin datum's holder, origin_address - the address the message originated from, message - the message that was sent)
|
||||
// Description: Called when send_message() successfully reaches the intended datum. By default, calls receive_exonet_message() on the holder atom.
|
||||
/datum/exonet_protocol/proc/receive_message(var/atom/origin_atom, var/origin_address, var/message)
|
||||
holder.receive_exonet_message(origin_atom, origin_address, message)
|
||||
return
|
||||
|
||||
// Proc: receive_exonet_message()
|
||||
// Parameters: 3 (origin_atom - the origin datum's holder, origin_address - the address the message originated from, message - the message that was sent)
|
||||
// Description: Override this to make your atom do something when a message is received.
|
||||
/atom/proc/receive_exonet_message(var/atom/origin_atom, var/origin_address, var/message)
|
||||
return
|
||||
@@ -8,7 +8,7 @@
|
||||
if(creator)
|
||||
parent = creator
|
||||
|
||||
var/global/datum/locations/milky_way/locations = new()
|
||||
var/global/datum/locations/milky_way/all_locations = new()
|
||||
|
||||
//Galaxy
|
||||
|
||||
@@ -26,6 +26,24 @@ var/global/datum/locations/milky_way/locations = new()
|
||||
new /datum/locations/uueoa_esa(src),
|
||||
new /datum/locations/vir(src)
|
||||
)
|
||||
|
||||
/proc/choose_location_datum(client/user)
|
||||
var/datum/locations/choice = all_locations
|
||||
while(length(choice.contents) > 0) //For some reason it wouldn't let me do contents.len even when I defined it as a list.
|
||||
var/specific = alert(user, "The location currently selected is [choice.name]. More specific options exist, would you like to pick a more specific location?",
|
||||
"Choose location", "Yes", "No")
|
||||
if(specific == "Yes" && length(choice.contents) > 0)
|
||||
choice = input(user, "Please choose a location.","Locations") as null|anything in choice.contents
|
||||
else
|
||||
break
|
||||
user << choice.name
|
||||
user << choice.desc
|
||||
return choice
|
||||
|
||||
// var/datum/locations/choice = input(user, "Please choose a location.","Locations") as null|anything in all_locations
|
||||
// if(choice && choice.contents.len > 0)
|
||||
|
||||
|
||||
/*
|
||||
/datum/locations/proc/show_contents()
|
||||
// world << "[src]\n[desc]"
|
||||
|
||||
@@ -52,6 +52,17 @@
|
||||
desc = "The Northern Star is an asteroid colony owned and operated by Nanotrasen, among many other asteroid installations. \
|
||||
Originally conceived as 'just another pitstop' for weary asteroid miners, it has grown to become a significant installation in the Kara subsystem."
|
||||
|
||||
/datum/locations/northern_star/New(var/creator)
|
||||
contents.Add(
|
||||
new /datum/locations/northern_star_interior(src)
|
||||
)
|
||||
..(creator)
|
||||
|
||||
/datum/locations/northern_star_interior
|
||||
name = "Northern Star Inner Level"
|
||||
desc = "The Northern Star contains multiple layers, this one being the inner level, also known as the residentual area. It contains most of the \
|
||||
homes for the Northern Star, as well as acting as the heart of commerece, with many shops and markets near the center."
|
||||
|
||||
/datum/locations/rota
|
||||
name = "Rota"
|
||||
desc = "A Neptune-like ice giant, with a beautiful ring system circling it. It is 165 kelvin (-157°C)."
|
||||
Reference in New Issue
Block a user