garrettjoecox / scriptserver

A Minecraft server wrapper, allows for simple plugins in vanilla
GNU General Public License v3.0
68 stars 10 forks source link

RCON fails to connect through the wrapper #33

Closed Kehino closed 3 years ago

Kehino commented 3 years ago

Hi,

I activated the RCON Listener for the server, it starts correctly when I launch the server through the wrapper or even with the java ... command. However, as mentionned in the closed errors, the line connection from localhost never appears, neither at startup nor when I trigger my server.sends.

I managed to test the simple-rcon tool with their example code below, which returns the following; I'd say it means that the server is properly setup:

Connected! Authenticated! Disconnected!

(The disconnection sometimes fails with ECONNRESET)

var Rcon = require('simple-rcon');
var client = new Rcon({
  host: '127.0.0.1',
  port: '25575',
  password: '0000'
}).exec('changelevel cp_badlands', function() {
  client.exec('say \'hey look the map changed!\'');
}).exec('status', function(res) {
  console.log('Server status', res.body);
}).exec('sm_kick somebody', function() {
  client.close();
}).connect();

client.on('authenticated', function() {
  console.log('Authenticated!');
}).on('connected', function() {
  console.log('Connected!');
}).on('disconnected', function() {
  console.log('Disconnected!');
});

And in that case, the Minecraft server returns:

[00:58:10] [RCON Listener #1/INFO]: Thread RCON Client /127.0.0.1 started [00:58:10] [RCON Client /127.0.0.1 #2/INFO]: Thread RCON Client /127.0.0.1 shutting down

The server.js file is below, I think I followed the README s; the feedbacks "Command was fired!" appear in the server log:

const ScriptServer = require('scriptserver');

const server = new ScriptServer({
  core: {
    jar: 'minecraft_server.1.16.4.jar',
    args: ['-Xmx2G'],
    rcon: {
      port: '25575',
      password: '0000'
    }
  },
  command: {
    prefix: '~'
  }
});

server.use(require('scriptserver-event'));
server.use(require('scriptserver-command'));

// Registers the event 'chat' to the following function
server.on('chat', event => {

  // Player who sent the chat message
  console.log(event.player);

  // The chat message itself
  console.log(event.message);

  // Timestamp of when the chat was sent
  console.log(event.timestamp);
});

// Registers the command ~spawn to the following function
server.command('spawn', event => {

  // Person who sent command
  var commandSender = event.player;

  // Command used (in this case, spawn)
  var command = event.command;

  // Array of arguments passed after command (in this case useless)
  var arguments = event.args;

  // Timestamp of when the command was sent
  var timestamp = event.timestamp;

  var spawnLocation = { x: 0, y: 70, z: 0 };

  console.log("Command was fired!");

  server.send(`tp ${commandSender} ${spawnLocation.x} ${spawnLocation.y} ${spawnLocation.z}`);
});

server.command('hello', event => {

  // Person who sent command
  var commandSender = event.player;

  // Command used (in this case, spawn)
  var command = event.command;

  // Array of arguments passed after command (in this case useless)
  //var arguments = event.args;

  // Timestamp of when the command was sent
  var timestamp = event.timestamp;

  console.log("Command was fired!");

  server.send(`say Hello!`);
});

server.start();
garrettjoecox commented 3 years ago

Thanks for the report @Kehino, if I was to guess this is because the regex no longer matches for this version of minecraft. You are able to override this by updating your config with the following:

const server = new ScriptServer({
  core: {
    jar: 'minecraft_server.1.16.4.jar',
    args: ['-Xmx2G'],
    rcon: {
      port: '25575',
      password: '0000'
    },
    flavorSpecific: {
      default: {
        rconRunning: /^\[[\d:]{8}\] \[RCON Listener #1\/INFO\]: RCON running/i,
      },
    },
  },
  command: {
    prefix: '~'
  }
});

If you don't understand regex, I'd be happy to get you a working one if you would post your server startup logs.

Sorry for the delayed response!

Kehino commented 3 years ago

Thanks @garrettjoecox !

I managed to update my regex. The log extract and the regex are below for reference:

[22:45:50] [Server thread/INFO]: Starting minecraft server version 1.16.4 [22:45:50] [Server thread/INFO]: Loading properties [22:45:50] [Server thread/INFO]: Default game type: SURVIVAL [22:45:50] [Server thread/INFO]: Generating keypair [22:45:50] [Server thread/INFO]: Starting Minecraft server on 127.0.0.1:25565 [22:45:50] [Server thread/INFO]: Using epoll channel type [22:45:51] [Server thread/INFO]: Preparing level "world" [22:45:51] [Server thread/INFO]: Preparing start region for dimension minecraft:overworld [22:45:53] [Server thread/INFO]: Preparing spawn area: 0% ... [22:45:57] [Worker-Main-6/INFO]: Preparing spawn area: 99% [22:45:57] [Server thread/INFO]: Time elapsed: 6510 ms

[22:45:57] [Server thread/INFO]: Starting remote control listener [22:45:57] [Server thread/INFO]: Thread RCON Listener started [22:45:57] [Server thread/INFO]: RCON running on 127.0.0.1:25575 [22:45:57] [RCON Listener #1/INFO]: Thread RCON Client /127.0.0.1 started

const server = new ScriptServer({
  core: {
    jar: 'minecraft_server.1.16.4.jar',
    args: ['-Xmx2G'],
    rcon: {
      port: '25575',
      password: '0000'
    },
    flavorSpecific: {
      default: {
        rconRunning: /^\[[\d:]{8}\] \[Server thread\/INFO\]: RCON running/i,
      },
    },
  },
  command: {
    prefix: '~'
  }
});

Merry Christmas and happy New Year!