jhead / phantom

Use your own Minecraft server with your Xbox or PS4 and play with friends!
MIT License
609 stars 75 forks source link

API #87

Open jhead opened 4 years ago

jhead commented 4 years ago

Branch: feature/api

Here's an umbrella issue tracking work on providing an (optional) HTTP-based API for phantom. The goal is to provide an API that's sufficient for powering a UI or web app.

Goals

Features

Let me know if you have ideas for features!

A fair warning: a lot of the code and APIs could change from commit to commit, so if you build anything against this right now, expect it to break.

jhead commented 4 years ago

An example

POST /api/servers/myServer

 {
  "name": "Test Server",
  "prefs": {
    "bindAddress": "0.0.0.0",
    "bindPort": 0,
    "remoteServer": "lax.mcbr.cubed.host:19132",
    "idleTimeout": 0,
    "ipv6": false
  }
}

^ would create a new server and store it in phantom.json automatically. That file also contains settings, etc., and you could edit it manually.

POST /api/servers/myServer/start would start a proxy for that server, just like running phantom from the CLI normally.

POST api/servers/myServer/stop would stop the proxy for that server.

Not all the endpoints are implemented yet but they should be soon.

WhatWheatleySaid commented 4 years ago

@jhead awesome! I'll look into that, since I never worked with that kind of API. Do i just send a POST request to "/api/..." (instead an URL) with a JSON as parameters? Does this work on window aswell (since the file system is different than an UNIX like Systems)?

EDIT: NVM

but: when I send a post request to "http://localhost:7377/api/servers/MyServer" with your example json, I get 12:45PM WRN Received invalid server object error="schema: converter not found for proxy.ProxyPrefs" in the commandline of phantom (ignore the wierd commandline formatting for the timestamp, seems to be a problem with my system) EDIT2: NVM again, I'm apparently just to dumb to use the requests-library of python.

WhatWheatleySaid commented 4 years ago

@jhead Is there something in the API to remove a server from the JSON without having to fiddle with the JSON directly and overwriting it?

jhead commented 4 years ago

Is there something in the API to remove a server from the JSON without having to fiddle with the JSON directly and overwriting it?

You can use an HTTP DELETE request, for example: DELETE http://localhost:7377/api/servers/MyServer would stop and delete the MyServer server.

Does this work on window aswell (since the file system is different than an UNIX like Systems)?

It should, but let me know if you run into any issues 🙂

WhatWheatleySaid commented 4 years ago

@jhead it indeed deletes the server, but it does not alter the JSON file and thus, when restarting the application, the server is back in the list

jhead commented 4 years ago

@WhatWheatleySaid thanks, fixed in 12e0418

WhatWheatleySaid commented 4 years ago

@jhead another Bug I encountered is, that only the most recent started server seems to show up in minecraft in your newest version (when using the JSON REST API)

BRadHoc commented 4 years ago

I don't know how closely related this could be connection-wise, but with the way this is connecting people over LAN would it be possible to make something like BungeeCord for bedrock (connecting multiple servers through portals)

jhead commented 4 years ago

I don't know how closely related this could be connection-wise, but with the way this is connecting people over LAN would it be possible to make something like BungeeCord for bedrock (connecting multiple servers through portals)

Hey @BRadHoc! Cool idea. I’m not sure if I want to build it into phantom though, since you could just setup phantom with one of the existing Bedrock proxies like DragonProxy, etc. Don’t reinvent the wheel, right?

Heath123 commented 4 years ago

existing Bedrock proxies like DragonProxy

DragonProxy is an abandoned project for joining Java Edition servers that was replaced by Geyser, you're probably thinking of things like WaterDog