Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add route to fetch server information by IP and port #69

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,18 @@ def list_json():
return send_from_directory(app.static_folder, "list.json", max_age=20)


@app.route("/server/<string:ip>/<int:port>")
def get_server(ip, port):
try:
server = serverList.get(ip, port)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's another pitfall here: this matches on the "announce requester IP" and not "IP of the server domain name" (this info is not present) or "specified IP or hostname of server".

so /server/your-land.de/30000 would never return anything

and for dualstack servers it could happen that it randomly announces over v4 and not v6, e.g. you normally do /server/2001:db8::123/30000 except you could get unlucky and it returns nothing but /server/1.2.3.4/30000 would have been right

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so /server/your-land.de/30000 would never return anything

Isn't that a serverList.get problem?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sort of. It does what it's supposed to for serverlist-internal usage, but might not do what someone expects of the API you're intending.

if server:
return server
else:
return "Server not found", 404
except ValueError as e:
return str(e), 400


@app.route("/geoip")
def geoip():
continent = geoip_lookup_continent(request.remote_addr)
Expand Down
Loading