Giter VIP home page Giter VIP logo

minecraft-player-locations's Introduction

Minecraft-Player-Locations

A way to display current player locations in Minecraft on a rendered Overviewer map.

This uses a simple node web socket server running in a docker container to connect to Minecraft's RCON interface and get player location data sent to a browser.

Usage

Minecraft RCON

You must have RCON enabled on your Minecraft server. To do so make sure these lines exist and have values in your server.properties file:

enable-rcon=true
rcon.port=25575
rcon.password=supersecretpassword

The docker container must be able to access the RCON port. I do not at all recommend exposing RCON publicly. It will be best if the docker container is on the same machine or at least on the same network.

JavaScript Client

The client.js file is what will connect the web browser to the Node socket server and render the player locations. If the socket server will be located on a host other than what is serving the Overviewer map, or not served on port 8888, line 2 of the client.js file must be modified to fit your needs.

socketUrl: 'ws://yourdomain.com:8888'

To use it on an HTTPS site, you need to use wss as protocol. Keep this in mind when changing the socketUrl.

Overviewer

This assumes you have a rendered Overviewer map being served that you want to add player locations to. In order to add this functionality additional web assets need to be included in the render. These assets are the client.js and index.html files in this project. Place these files in a folder on the machine which renders the map.

The JavaScript file is entirely required,and the HTML file is really just taking what Overviewer has and adding an additional script to load.

<script type="text/javascript" src="client.js"></script>

I do not see anything in the Overviwer documentation which just adds JavaScript imports. If you have modified your index.html file already, just add the aforementioned script tag.

The Overviewer configuration file should include the following line:

customwebassets = "/path/to/assets"

When Overviewer renders the map, it will copy the asset files into the defined web directory.

Docker Socket Server

This assumes you have a machine with Docker installed and running that can communicate with the Minecraft server and has a port exposed. The docker container runs the socket server which sends location data to the web browser as well as talks to your Minecraft server via the RCON interface. An example docker run command looks like this:

docker run \
  --detach \
  --publish 8888:8888 \
  --name minecraft-player-locations \
  --env "NODE_ENV=production" \
  --env "RCON_HOST=MyMineCraftHost" \
  --env "RCON_PORT=25575" \
  --env "RCON_PASSWORD=supersecretpassword" \
  archmageinc/minecraft-player-locations

Configuration

--publish 8888:8888 - This is what maps the container port to the host port. If you need a different port bound to the local machine, change the right hand port number

--env "RCON_HOST=MyMineCraftHost" - This is the hostname of the Minecraft server

--env "RCON_PORT=25575" - This is the port RCON is listening to as defined in Minecraft's server.properties file

--env "RCON_PASSWORD=supersecretpassword" - This is the password to connect to RCON as defined in Minecraft's server.properties file

HTTPS Configuration

Additional configuration required for maps running over https.

---env "WEBSOCKET_KEY=/path/to/keyfile" - This is the keyfile of your https server (e.g. /etc/letsencrypt/live/MyDomain.example.com/privkey.pem)

---env "WEBSOCKET_CERT=/path/to/certfile" - This is the certfile of your https server (e.g. /etc/letsencrypt/live/MyDomain.example.com/fullchain.pem)

To mount these files into the container use --mount as found in the Docker documentation.

minecraft-player-locations's People

Contributors

dependabot[bot] avatar kaemmelot avatar thedruidskeeper avatar v1nc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

minecraft-player-locations's Issues

Not displaying player locations / multiworld setup

Following your instructions, I'm unable to get player locations to show up on the map. The JavaScript console shows that a websocket connection was opened, but no player locations show up.

If it makes a difference, I'm using a multi-world plugin (Multiverse) with this setup.

EDIT: Docker Logs indicate the following:

Attempting to establish an RCON connection
There was an error creating an RCON connection:  { Error: connect ECONNREFUSED 127.0.0.1:25575
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1191:14)
  errno: 'ECONNREFUSED',
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 25575 }

I have confirmed that the port is open and listening through netstat.

Temporary fix for 1.12.2 (working)

First off let me say: Thank you so much. Using RCON is extremely clever and it works pretty well. Installed without Docker, however, but it went smoothly. Was about to attempt this myself, but saw your post here and wanted to try it out first.

I do, however, have this running on an 1.12.2 server (RLCraft). There is no data command in 1.12.2, since it was introduced in 1.13, so I tried to find a way that still worked without additional mods.. and I did. But holy moly is it ugly. The only way to get position of a player without mods, is by calling this command:

/tp <player> ~ ~ ~

Which will return:

Teleported <player> to x, y, z

Because of that, I could simply change the parsePlayerCoords function to use that data instead. So far I have not noticed it having an impact on the player's actual position. I tried running, swimming, sleeping, sailing, and flying. The /tp command doesn't seem to do anything, when the player is teleported to ~ ~ ~. So here is my edit, and you can do with it what you want (alternatively keep this issue open or branch out).

getPlayerCoords = (playerName) => {
  return rcon.send(`tp ${playerName} ~ ~ ~`).then(parsePlayerCoords).then(data => {return {name: playerName, x: data.x, y: data.y, z: data.z}});
};

parsePlayerCoords = (playerResult) => {
  let regex = "to (.*), (.*), (.*)";
  let data = playerResult.match(regex);
  
  return {
    x: Number(data[1]),
    y: Number(data[2]),
    z: Number(data[3])
  };
};

Excellent

Not an issue.
I just want to say thank you! This works perfectly. I have a minecraft server and the overviewer running each in a separate docker container. I had to copy the client.js and index.html to the overviewer html directory and connect the minecraft server and your player docker with one docker network.

Thank you, we are using minecraft to overcome this hard coronavirus time. Stay healthy!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.