garrettjoecox / scriptserver

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

.send() not working #27

Closed sigmasoldi3r closed 5 years ago

sigmasoldi3r commented 6 years ago

The server.send('string') method is ignored by the server.

The snippet tested:

console.log('Hello world!');
server.send(`say Command tested by ${player.name}`);

Which produces:

[13:23:18] [Server thread/INFO] [minecraft/DedicatedServer]: <player> !test
Hello world!

But nothing in-game.

RCON is also enabled, the console yields at the startup:

[13:20:42] [Server thread/INFO] [minecraft/DedicatedServer]: Done (21,957s)! For help, type "help" or "?"
[13:20:42] [Server thread/INFO] [minecraft/DedicatedServer]: Starting remote control listener
[13:20:42] [RCON Listener #1/INFO] [minecraft/MinecraftServer]: RCON running on 0.0.0.0:25575

SpongeForge is present and installed, maybe this relates to https://github.com/garrettjoecox/scriptserver/issues/16 (Not sure)

Also I had to workaround those issues: https://github.com/garrettjoecox/scriptserver-event/issues/6 and https://github.com/garrettjoecox/scriptserver-command/issues/3 using this snippet:

server.on('console', line => {
  const match = line.match(REGEX);
  if (match) {
    const [ input, timestamp, thread, title, ply, command, rawParams ] = match;
    const params = rawParams.split(' ');
    const cmdFile = path.join('scripts', 'commands', `${command}.js`);
    try {
      const player = PLAYERS[ply] || new Player(ply);
      const script = fs.readFileSync(cmdFile).toString();
      try {
        vm.runInNewContext(script, vm.createContext({
          player, input, timestamp, thread, title, command, params, server, console
        }));
      } catch (err) {
        console.error(err);
        const msg = [
          '',
          { text: 'ERROR: ', color: 'red' },
          { text: 'Command failed, reason: '},
          { text: `"${err.message}"`, color: 'red' }
        ];
        server.send(`tellraw ${ply} ${JSON.stringify(msg)}`);
      }
    } catch (err) {
      console.error(err);
      const msg = [
        '',
        { 'text': 'ERROR: ', 'color': 'red' },
        { 'text': `"${command}"`, 'italic': true },
        { 'text': ' is not a known command.' }
      ];
      server.send(`tellraw ${ply} ${JSON.stringify(msg)}`);
    }
  }
});

Which even on error do not report to the server, I don't know if this currently relates to the same problem.

Node v10.7.0 NPM 6.4.1 scriptserver latest scriptserver-command latest

Edit:

Tested server.spawn.stdin.write but does not work either.

fjeddy commented 5 years ago

All of your issues seem related to the same thing.

You don't provide and connect to RCON.

sigmasoldi3r commented 5 years ago

All of your issues seem related to the same thing.

You don't provide and connect to RCON.

What do you mean?

fjeddy commented 5 years ago

What I mean is that your configuration does not give any indication that you're actually connecting to RCON. It's not enough to just have it running server side, scriptserver also needs to connect to it.

More specifically, you're missing a connection from localhost line in console

[14:49:22 INFO]: Done (13.379s)! For help, type "help"
[14:49:22 INFO]: Starting remote control listener
[14:49:22 INFO]: RCON running on 0.0.0.0:25575
[14:49:22 INFO]: Rcon connection from: /127.0.0.1

If scriptserver fails to connect to rcon, then most of it will fail to work as a result. And based on your other issues and the examples you give, then it seems like you don't ever connect RCON with scriptserver at all.

Take your code in the second, identical issue you created.

const app = new Server({
  core: {
    jar: config.jar,
    args: [
      ...config.args
    ]
  }
});

Where are the RCON connection details? How would Scriptserver know where RCON is located, what port it's running on and what your RCON password is, unless you specifically provide it as the readme explains?

sigmasoldi3r commented 5 years ago

I'll check it out later, I don't even remember where I had the project located 😅

garrettjoecox commented 5 years ago

Closing this as it is working correctly.

KDSbami commented 3 years ago

Hey, I am having the same issue. I gave all rcon params even tried connecting to default.

[16:48:03] [Server thread/INFO]: Thread RCON Listener started [16:48:03] [Server thread/INFO]: RCON running on 0.0.0.0:25575

rcon.password=0000

rcon: { host: 'localhost', port: '25575', password: '0000', buffer: 100, },

garrettjoecox commented 3 years ago

@KDSbami I’ve learned that the problem is usually with the RegExp scriptserver is waiting for.

You can override the default one to match what your version of Minecraft outputs, the default one is here https://github.com/garrettjoecox/scriptserver/blob/ae1e000d6ba6680b66c41b7cb81250af4504aa2f/index.js#L25

garrettjoecox commented 3 years ago

Try replacing that with a regexp that matches yours (yours is Server Info rather than Rcon Listener)

I’ve been meaning to update the docs to reflect this but havent had the time