1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Hey Guest, is it this your first time on the forums?

    Visit the Beginner's Box

    Introduce yourself, read some of the ins and outs of the community, access to useful links and information.

    Dismiss Notice

Community App KAG gshost-api-wrapper - A Free Python Wrapper for Managing KAG Servers Remotely

Discussion in 'Community Dev Corner' started by Geti, Jan 31, 2017.

Mods: Downburst, Mazey
  1. Geti

    Geti Please avoid PMing me (poke a mod instead) THD Team Administrator Global Moderator

    Repo: https://github.com/1bardesign/gshost-api-wrapper

    This is something I had to develop as part of making the official modded server; it makes automation of remote admin of a server very easy - particularly taking the server down, changing files, and putting it up again (like we have to for the mod rotations). Everything is done over HTTPS with authentication.

    For anyone with GSHost servers, it should work for your servers as well, though it's a bit rough around the edges. If it gets some use I'm sure Joe and I can spend a bit of time giving it some more love.

    Possible uses:
    • Swapping out gamemode configs, mapcycles, seclevs, maps etc based on some central file(s) for anyone with multiple servers
    • Web-based whitelisting (click a link to get access on a server) or blacklisting
    • Updating stuff based on community web poll (eg tdm settings voter)
    • Collaborative map drawing website?
    Possible Extensions:
    • TCPR Bridge - secure remote TCPR injection without the worry of handling persistent connections. One way only though. Still useful for server messages and setting variables.
    • TCPR Backlog - would allow "normal TCPR apps" (bidirectional) without as much hassle, for people who don't like dealing with streams.
    • Download Files - would allow inline modifications of files by downloading, modifying, and uploading all from script
    • Delete Files - would allow remote cleanup of known junk
    • Create/Delete Directories - everybody likes directories
    • List directory - useful for knowing what files to download / checking if a file exists
    • Mirror Directory Tree - with the above implemented, could be done purely from python, though it'd take a lot of separate requests
    • Replace Directory from archive - single-request uploading of a zip or tar to replace an existing directory.
    But isn't this possible just with ssh and a bunch of glue?
    Sure, but if you use gshost, there's already some glue there for you to use.
    Let us know if you use it, how you use it, and any issues you have with it! And be sure to star the project if you've got a github account ;)
    Last edited: Jan 31, 2017
    Osmal, master4523 and joshua12131415 like this.
  2. Cruxiat

    Cruxiat Ballista Bolt Thrower Tester
    1. Gather Oceania
    2. KAG World Cup 2018

  3. joshua12131415

    joshua12131415 Bison Rider Tester

    This would be awesome if I knew how to use it.
    I know how to get the node url and server number but that's it.
    How do you actually use .py files? This would be a lot easier if it were a .exe );
    Last edited: Jan 31, 2017
  4. Geti

    Geti Please avoid PMing me (poke a mod instead) THD Team Administrator Global Moderator

    Note: this doesn't work with just any KAG server, it requires you to be hosted with GSHost, since it uses @jrgp's API there - so hopefully some of the folks getting tagged are hosted there haha.

    I'll fix that link right now, but googling "python requests" will get you 99% of the way there. e: fixed!

    No it wouldn't, because then I'd have to bundle the entirety of python, I'd need three versions of it (one for each OS), and you wouldn't be able to read the source.

    I'm actually going to assume you don't know what python is, based on your response.

    Python is a scripting language which is pretty well supported and comes with "batteries included", as well as having a pretty active ecosystem. I chose it because it runs everywhere I need it to (Windows and Linux) and I had working example code for joe's API already in python.

    Here's how to get started with this module, from "nothing, I don't even have python installed"

    • Google Python. Install it.
    • Install requests (i really strongly recommend using pip for this, but you could conceivably download all the deps yourself and put them all in the right places...)
    • Log into GSHost and figure out what node your server is on, and what its ID is
    • Put the example code into a file called example.py, and make sure to fill in your server info and auth.
    • Then, run the script by double clicking it. Your server should be restarted with a brand new autoconfig, which will give your server a silly name and description, and set the mode to TDM.
    • Now that you've got it working, come up with whatever other cool use you want and implement that in python!

    If you're on windows, getting pip working is a bit annoying - you have to remember to put your python directory AND python/Scripts on your PATH. I have no idea why the installer doesn't have an option for that. Then, open up a command prompt and pip install requests should "just work"

    If you have more trouble getting it to work, let me know!
    joshua12131415 likes this.
  5. Geti

    Geti Please avoid PMing me (poke a mod instead) THD Team Administrator Global Moderator

  6. Geti

    Geti Please avoid PMing me (poke a mod instead) THD Team Administrator Global Moderator

    Just updated this - the API can now do TCPR calls (requires that the server is set up for TCPR). There's no way to get output from TCPR yet (let joe know if you'd love this feature!) but this can be really handy for piping in messages from an external service. At this stage you can do anything you'd be able to achieve with TCPR normally other than pulling info out of the server - with the convenience of not needing to set up a connection and handle auth yourself.

    Things are also handled over https, which means that this is "safe" to use to perform TCPR actions from remote machines (no passwords in plaintext over the internet).

    For the modded server, we're using it for letting players know the server will be going down and having a new mod soon. Other uses I can imagine it'd be good for is piping events from a website in, triggering a reload after using the API to update some config or map file. I'm sure there's more good uses for it too!

    Same github repo, let me know if you get any good use out of this and feel free to make feature requests; we'll see what we can do about it!
Mods: Downburst, Mazey