How to use the minecraft-protocol.createServer function in minecraft-protocol

To help you get started, we’ve selected a few minecraft-protocol examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github PrismarineJS / node-minecraft-protocol / examples / server / server.js View on Github external
const mc = require('minecraft-protocol')

const options = {
  motd: 'Vox Industries',
  'max-players': 127,
  port: 25565,
  'online-mode': false
}

const server = mc.createServer(options)

server.on('login', function (client) {
  broadcast(client.username + ' joined the game.')
  const addr = client.socket.remoteAddress + ':' + client.socket.remotePort
  console.log(client.username + ' connected', '(' + addr + ')')

  client.on('end', function () {
    broadcast(client.username + ' left the game.', client)
    console.log(client.username + ' disconnected', '(' + addr + ')')
  })

  // send init data so client will start rendering world
  client.write('login', {
    entityId: client.id,
    levelType: 'default',
    gameMode: 1,
github DragonetMC / SelectorServer / server.js View on Github external
// item settings
const item_server = 3;
const item_category = 4;
const item_functional = 2;
// messages
const message_loading = '\u00a7aLoading... ';
const menu_title = "\u00a70Choose a server";
const message_error_exit = "You didn't select a server to join! ";
const message_bye = "Bye! ";

/* == END OF SETTINGS AREA == */

const type = require("type-detect");

const mc = require('minecraft-protocol');
const server = mc.createServer({
  'online-mode': false,   // optional
  encryption: true,      // optional
  host: listen_host,       // optional
  port: listen_port,           // optional
});

console.log("Server is now started! ");

server.on('login', function(client) {
  modifyClient(client);
  client.write('login', {
    entityId: 0,
    levelType: 'default',
    gameMode: 3,
    dimension: 0,
    difficulty: 2,
github themoonisacheese / 2bored2wait / main.js View on Github external
}
		stop();
		// setTimeout(startQueuing, 100); // reconnect after 100 ms
	});

	client.on('error', (err) => {
		if (proxyClient) {
            proxyClient.end(`Connection error by 2b2t server.\n Error message: ${err}\nReconnecting...`);
            proxyClient = null
		}
		console.log('err', err);
		stop();
		// setTimeout(startQueuing, 100); // reconnect after 100 ms
	});

	server = mc.createServer({ // create a server for us to connect to
		'online-mode': false,
		encryption: true,
		host: '0.0.0.0',
		port: config.ports.minecraft,
		version: config.MCversion,
		'max-players': maxPlayers = 1
	});

	server.on('login', (newProxyClient) => { // handle login
		newProxyClient.write('login', {
			entityId: newProxyClient.id,
			levelType: 'default',
			gameMode: 0,
			dimension: 0,
			difficulty: 2,
			maxPlayers: server.maxPlayers,
github PrismarineJS / node-minecraft-protocol / examples / server_channel / server_channel.js View on Github external
const mc = require('minecraft-protocol')

const server = mc.createServer({
  'online-mode': false, // optional
  encryption: false, // optional
  host: '0.0.0.0', // optional
  port: 25565, // optional
  version: '1.10'
})

server.on('login', function (client) {
  client.registerChannel('MC|Brand', ['string', []])
  client.on('MC|Brand', console.log)
  client.write('login', {
    entityId: client.id,
    levelType: 'default',
    gameMode: 0,
    dimension: 0,
    difficulty: 2,
github PrismarineJS / prismarine-server / src / app.js View on Github external
var mc = require('minecraft-protocol');
var states = mc.protocol.states;

var options = {
    motd: 'Bushido Studios',
    'max-players': 127,
    port: 25565,
    'online-mode': true,
};

var server = mc.createServer(options);

server.on('login', function(client) {
    broadcast(client.username+' joined the game.');
    var addr = client.socket.remoteAddress + ':' + client.socket.remotePort;
    console.log(client.username+' connected', '('+addr+')');

    client.on('end', function() {
        broadcast(client.username+' left the game.', client);
        console.log(client.username+' disconnected', '('+addr+')');
    });

    // send init data so client will start rendering world
    client.write('login', {
        entityId: client.id,
        levelType: 'default',
        gameMode: 1,
github PrismarineJS / node-minecraft-protocol / examples / server_helloworld / server_helloworld.js View on Github external
const mc = require('minecraft-protocol')

const options = {
  'online-mode': true
}

const server = mc.createServer(options)

server.on('login', function (client) {
  const addr = client.socket.remoteAddress
  console.log('Incoming connection', '(' + addr + ')')

  client.on('end', function () {
    console.log('Connection closed', '(' + addr + ')')
  })

  client.on('error', function (error) {
    console.log('Error:', error)
  })

  // send init data so client will start rendering world
  client.write('login', {
    entityId: client.id,
github PrismarineJS / node-minecraft-protocol / examples / server_custom_channel / server_custom_channel.js View on Github external
const mc = require('minecraft-protocol')

const server = mc.createServer({
  'online-mode': false, // optional
  encryption: false, // optional
  host: '0.0.0.0', // optional
  port: 25565, // optional
  version: '1.10'
})

server.on('login', function (client) {
  client.write('login', {
    entityId: client.id,
    levelType: 'default',
    gameMode: 0,
    dimension: 0,
    difficulty: 2,
    maxPlayers: server.maxPlayers,
    reducedDebugInfo: false
github PrismarineJS / flying-squid / src / index.js View on Github external
connect (options) {
    const plugins = requireIndex(path.join(__dirname, 'lib', 'plugins'))
    this._server = mc.createServer(options)
    Object.keys(plugins)
      .filter(pluginName => plugins[pluginName].server !== undefined)
      .forEach(pluginName => plugins[pluginName].server(this, options))
    if (options.logging === true) this.createLog()
    this._server.on('error', error => this.emit('error', error))
    this._server.on('listening', () => this.emit('listening', this._server.socketServer.address().port))
    this.emit('asap')
  }
}
github Electroid / infrastructure / docker / other / request / server.js View on Github external
const request = require('sync-request');
const merge = require('merge');
const sleep = require('system-sleep');
const mc = require('minecraft-protocol');

const id = server_id();
var cache = server_doc(id);

const origin_port = 25565;
const port = 25555;
const server = mc.createServer({
  host: '0.0.0.0',
  port: port,
  'online-mode': false
});

server.on('login', function(client) {
  let start = new Date();
  let username = client.username
  let response = server_request(username);
  client.end(response.message);
  let end = new Date();
  let success = response.success;
  console.log('- ' + username + ' was ' + (success ? 'accepted' : (success == null ? 'deferred' : 'rejected')) + ' after ' + ((end - start) / 1000) + ' seconds');
  if(success) {
    server_transfer();
  }
github PrismarineJS / node-minecraft-protocol / examples / server_world / mc.js View on Github external
const mc = require('minecraft-protocol')
const Chunk = require('prismarine-chunk')('1.12.1')
const Vec3 = require('vec3')
var server = mc.createServer({
  'online-mode': true,
  encryption: true,
  host: '0.0.0.0',
  port: 25565,
  version: '1.12.1'
})
var chunk = new Chunk()

for (var x = 0; x < 16; x++) {
  for (var z = 0; z < 16; z++) {
    chunk.setBlockType(new Vec3(x, 100, z), 2)
    for (var y = 0; y < 256; y++) {
      chunk.setSkyLight(new Vec3(x, y, z), 15)
    }
  }
}