This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Dave-ee Jones's profile picture

Host - Local DNS Hosting API

Started by Dave-ee Jones, 27 September 2017 - 02:27 AM
Dave-ee Jones #1
Posted 27 September 2017 - 04:27 AM
HOST

Dave-ee's DNS API



So, here's my super-simple and easy-to-use DNS API. Usage is very simple. All you need is a name of your choice, and a computer ID. BOOM! Done.

There's some more documentation in the API and the demo themselves, so if you get stuck just have a look at those! But there's some functions below..

Functions:
Spoiler

--# Creating an entry
host.new(NAME, ID)
--# Change ID of an entry
host.setID(NAME, NEW_ID)
--# Change NAME of an entry
host.setName(ID, NEW_NAME)
--# Get NAME of an entry
local returned_NAME = host.getName(ID)
--# Get ID of an entry
local returned_ID = host.getID(NAME)
--# Delete an entry
host.delete(NAME)

Errors:
Spoiler

Error:
"host: ID needs to be a number"
Solution:
Make sure that the ID is a number!
Error:
"host: NAME needs to be a string"
Solution:
Make sure that the NAME is a string!
Error:
"host: Record for *NAME* doesn't exist"
Solution:
Make sure the entry exists
Error:
"host: Record for *ID* doesn't exist"
Solution:
Make sure the entry exists

So, as you can see it's very simple and easy to use. It's also extremely lightweight (under 100 lines of code with commenting), and so easy to incorporate into your OS' if you want to (which you are entirely free to do)!

What's the difference between RAM and FS editions?
Glad you asked! RAM Edition means that once the computer has rebooted you have to create all the DNS entries again. Could be useful, could be annoying, which is why I've created 2 different versions of this program.
FS Edition means that all entries are stored in a directory (default: ".hosts") and are referred to that way.


API Pastebin (RAM Edition):

pastebin get bhZ5Pi6Q host


API Pastebin (FS Edition):

pastebin get ruu0wpdw host


Demo Pastebin:

pastebin get fAriampD demo




FEEL FREE TO COMMENT BELOW YOUR FEEDBACK AND SUGGESTIONS!
Edited on 27 September 2017 - 04:14 AM
Dave-ee Jones #2
Posted 27 September 2017 - 04:44 AM
Quick fixes:
  • If you use 'dofile("host")' instead of 'os.loadAPI("host")' it now keeps the record entries globally so you can set them in one program and still use them for another. Might make it so it refers to a directory for entries so it works after restarts etc.
Major change:
  • 2 Editions (explained in OP)
Edited on 27 September 2017 - 04:13 AM