ID:206363
 
(See the best response by Nadrew.)
I've always wondered how to create a text file where you can add a key, which will auto-receive hoster commands when he logins in his server.

I have a game, and sometimes the people host it on their shell servers, which makes it hard to define who's the one hosting, I've seen on some games like Sunday the 19th a text file which can be edited to add the keys you want as Admins.

I can already choose GMs in runtime, but that's because I'm already coded as Owner. How can I do this? It'd be really helpful if there was a text file on the hosting files zip to give yourself Hoster Powers on Shell Server.
Hey EM! Well first, you have to make a list!
var/list/GMs = new()

After creating the list, you can input in people into it.
This is how!
mob/Login()
if(src.key in GMs) //check if they exsist in list
src.GiveGM()//gives them GM!





world/New()
GMs += file("GMs.log")



Hope this helps you! Make sure the player sepreate their keys using commas. Also, he has to create the file.
Best response
Really depends on how indepth you want the system to be, the easiest method is having a host.txt file that ONLY contains the key you want to gain hosting powers.

var/host_key = file2text("host.txt")
if(src.ckey == ckey(host_key))
// Add commands.


If you want it to contain multiple values you'd have to write something up to split the text into a list so you can read the values, I recommend my string handler library's Split() function. Simply adding a comma-separated string to the list as above would not work since you're really doing just that, adding a long string of text to the list as a single item.

var/file_text = file2text("host.txt")
var/list/hosts = str_Split(file_text,",")
if(hosts.Find(src.ckey))
// Add commands


Then the file would be in the format "key1,key2,key3" etc..

Hope this helped!
In response to Nadrew
Nadrew wrote:
Really depends on how indepth you want the system to be, the easiest method is having a host.txt file that ONLY contains the key you want to gain hosting powers.

> var/host_key = file2text("host.txt")
> if(src.ckey == ckey(host_key))
> // Add commands.
>

If you want it to contain multiple values you'd have to write something up to split the text into a list so you can read the values, I recommend my string handler library's Split() function. Simply adding a comma-separated string to the list as above would not work since you're really doing just that, adding a long string of text to the list as a single item.

> var/file_text = file2text("host.txt")
> var/list/hosts = str_Split(file_text,",")
> if(hosts.Find(src.ckey))
> // Add commands
>

Then the file would be in the format "key1,key2,key3" etc..

Hope this helped!

Thank you so much! I'll add it to my game now (:
You have to be careful about this though.
Someone could put an entry in their hosts file that reroutes that location of that text file to their own server, which means they can download the file to their own server and rehost it (modifying values to give themselves admin.)
Uh, what? It's just loading a local file, there's nothing modifying your system's hosts file can change, it's not loading anything over the network. The only person with access to the file would be the host of the world, who would be the one needing to modify it in the first place.
Ah, I would have assumed he would have uploaded it to a file server somewhere so he could dynamically add hosts.
He just wanted the hosts to be able to specify keys to get the host commands, like if they were hosting through a shell they'd still be able to get the host commands. Without having to rely on world.host or IP matching.