2.0.23 • Published 3 years ago

cloud-core-server v2.0.23

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

npm.io


Cloud Core is a highly configurable Minecraft Java wrapper, it uses child_process, express, websocket and many other modules to expose your Minecraft Java server to the web.

  • HTTP Api for sending commands, requesting the last 100 lines of console and getting the server usage statistics (cpu & ram).
  • Websocket support to receive console lines, send commands and start / stop the server.
  • A fully automated backup system that backs up your whole server on a bi-weekly / bi-monthly basis.
  • Highly customizable with events, and functions to interact with the server from plain javascript.
  • Highly secured, only letting users with a certain password connect.
  • Logs every command sent into the Minecraft latest log with an optional user field to log a command by a user.

Install

Firstly make sure you have the following dependencies:

  • Java 8 or above.
  • NodeJS 12 or above.
  • Access to SSH on your host.

Install via NPM...

npm install cloud-core-server

To start a server, you need to create a javascript file in the root of your server.

Include Cloud Core into this script by entering this line:

const CloudCore = require("cloud-core-server");

Then make a new instance of CloudCore:

const server = new CloudCore(options);

You need to configure most of the options, download the example-start.js file to see an example of what you might find, all options and default values are listed here:

core:

core.backups:

remote:

Running

Start your server by installing pm2 and running this command:

pm2 start (your start javascript file) -n (server name)

Your server will now be started. You can use pm2 log (server name) to view the server log or if there are any errors.

Be careful when you are stopping your server. If you stop your server via pm2 stop (server name) your server can be shut down incorrectly. Please first stop your server through the web, then stop it via pm2.

You can also start multiple servers using pm2.

Accessing

HTTP GET request to any URL to get the last 100 lines of the console.

HTTP POST request to any URL to send a command.

Open websocket to any URL.

Start & stop.

Make sure you follow authentication rules.

Also have a look at proxying your webserver to ensure security.

Getting CPU & RAM Usage.

$context = [
  "http" => [
      "method" => "GET",
      "header" => "Authorization: <auth code here>"
  ]
];

$console = file_get_contents("http://localhost:35565/", false, stream_context_create($context))
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,"http://localhost:35565/");
curl_setopt($ch, CURLOPT_POST, 1);
$authHeaders = array(
  "Authorization: <auth code here>",
  "Content-type: application/json"
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $authHeaders);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(array("command" => "command here", "user" => "optional user here")));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$server_output = curl_exec($ch);

curl_close ($ch);
webSocket = new WebSocket('ws://localhost:35565', 'auth code here');
webSocket.onmessage = (message) => {
    let line = message.data;
    console.log(line)
};

webSocket.send(JSON.stringify({"action": "command", "command": "command here", "user": "optional user here"}))

Important Note: You must have a ping/pong event every ~10 seconds to keep the websocket connection alive. To do this put ping for the action field. The server will return a pong in raw text. I advise you to have an if statement to make sure you filter it out.

In the websocket, specify the action field as either: start, stop, restart or kill.

In HTTP, specify the command field as either start, stop or restart.

Note: You can still pass the user field.

All requests include a Authorization header with the auth code you set in the start.js file.

Pass the authentication code in the protocall for websockets. See Above

It is highly recommended that you proxy your webserver as this does not support https at the moment. Here are some articles on how you can do that.

Setting up NGINX as your proxy server with NodeJS apps

How to Setup Apache As Frontend Proxy for Node.js

Make a GET request to /usage to return a json array of the server's current CPU load and ram.

$context = [
  "http" => [
      "method" => "GET",
      "header" => "Authorization: <auth code here>"
  ]
];

$usage = file_get_contents("http://localhost:35565/usage", false, stream_context_create($context))
$usage = json_decode($usage, true);

API

Events

Methods

Register an event by doing:

server.on("event name", (params) => {
  // do stuff
})

Help

To get help feel free to message me on discord Chezzer#6969.

2.0.23

3 years ago

2.0.22

3 years ago

2.0.19

3 years ago

2.0.18

3 years ago

2.0.20

3 years ago

2.0.21

3 years ago

2.0.15

3 years ago

2.0.16

3 years ago

2.0.13

3 years ago

2.0.14

3 years ago

2.0.17

3 years ago

2.0.11

3 years ago

2.0.12

3 years ago

2.0.10

3 years ago

2.0.7

3 years ago

2.0.9

3 years ago

2.0.8

3 years ago

2.0.3

3 years ago

2.0.2

3 years ago

2.0.5

3 years ago

2.0.4

3 years ago

2.0.6

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.1.1

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.0

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago