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

Getting player count from server for java+bedrock connection monitoring #11

Closed
doctorray117 opened this issue Sep 11, 2021 · 7 comments
Closed
Assignees

Comments

@doctorray117
Copy link
Owner

As a minecraft player, I want to use this procedure with bedrock edition. Right now, bedrock communicates on a UDP port which makes the current netstat+grep+wc method of determining connected player count inadequate for bedrock users.

https://github.com/itzg/mc-monitor is a project that offers server querying for both bedrock and java edition servers, which will return server status as well as an online player count. While available as a standalone container, fargate is not set up in a way that we can fire off individual containers for the purpose of querying server status. Nor can we do Docker inside of Docker within this setup.

Potential options are:

  1. include the mc-monitor code as a go get function within this container build, call it against the local server host, and parse the quantity of online players. Advantages is that it works out of the box for java and bedrock, disadvantage is that it will likely increase the container size to over 1gb.
  2. Write a new curl and/or socat request to query the server and just pull the online player count.
  3. Grep the logfile for connect/disconnect messages to determine player count.

Switching to this will allow the easy addition of bedrock servers.

@safetymonkey
Copy link

safetymonkey commented Sep 13, 2021

There are other monitoring tools that may be a bit easier to use than the itzg/mc-monitor. For example, mcstatus is a Python library that can be installed and executed pretty easily.

  $ mcstatus example.org status
  version: v1.8.8 (protocol 47)
  description: "A Minecraft Server"
  players: 1/20 ['Dinnerbone (61699b2e-d327-4a01-9f1e-0ea8c3f06bc6)']

Another approach would be using the mcsrvstat.us API, which you could hit with cURL:
$ curl -sb -H "Accept: application/json" "https://api.mcsrvstat.us/bedrock/2/example.org"
It returns a JSON object which I'm bad at parsing via grep, but it's easy enough to do it in a one-liner with Python.

$ curl -sb -H "Accept: application/json" "https://api.mcsrvstat.us/2/mc.snapcraft.net" | python -c 'import json,sys;obj=json.load(sys.stdin);print(obj["players"]["online"])'
339

NOTE: The API URL I used above was for a Java edition server because I was in a hurry. The Bedrock API format is https://api.mcsrvstat.us/bedrock/2/example.org. If you wanted to be extra clever, you could just check both API endpoints.

@doctorray117
Copy link
Owner Author

Those are much simpler solutions. I'll get to work incorporating the detection shortly, and I have Minecraft on a tablet here I can test with. Thanks for the legwork!

@safetymonkey
Copy link

Sure thing. I'm having difficulty getting mcstatus to work properly with Bedrock servers for some reason, so if it were me I'd do the mcsrvstat.us API approach. Here's a valid test example for Bedrock:

$ curl -sb -H "Accept: application/json" "https://api.mcsrvstat.us/bedrock/2/play.fallentech.io" | python -c 'import json,sys;obj=json.load(sys.stdin);print(obj["players"]["online"])'
99

@safetymonkey
Copy link

Also: Thanks for your work! This is such a cool concept. I'm hoping to borrow the approach to work on an on-demand Valheim server this weekend.

@doctorray117
Copy link
Owner Author

Sure thing.

Also, found this as a possible solution that can query both types of servers. Playing with it now.

@safetymonkey
Copy link

safetymonkey commented Sep 13, 2021 via email

@doctorray117 doctorray117 self-assigned this Sep 15, 2021
@doctorray117
Copy link
Owner Author

Bedrock supported now; player count extracted from raknet ping/pong through ncat. Detection of edition automatic in watchdog.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants