mirror of
https://github.com/danbulant/flying-squid
synced 2026-06-11 10:31:08 +00:00
normal position is now possible because I understood it's necessary to stored the last sent position in order to compensate for the loss of precision next time a relative position packet is sent I introduced a features.json which makes it possible to describe high level differences between version and use that to handle multi version code
53 lines
1.8 KiB
JavaScript
53 lines
1.8 KiB
JavaScript
const mc = require('minecraft-protocol')
|
|
const EventEmitter = require('events').EventEmitter
|
|
const path = require('path')
|
|
const requireIndex = require('./lib/requireindex')
|
|
const supportedVersions = require('./lib/version').supportedVersions
|
|
require('emit-then').register()
|
|
if (process.env.NODE_ENV === 'dev') {
|
|
require('longjohn')
|
|
}
|
|
|
|
const supportFeature = require('./lib/supportFeature')
|
|
|
|
module.exports = {
|
|
createMCServer: createMCServer,
|
|
Behavior: require('./lib/behavior'),
|
|
Command: require('./lib/command'),
|
|
generations: require('./lib/generations'),
|
|
experience: require('./lib/experience'),
|
|
UserError: require('./lib/user_error'),
|
|
portal_detector: require('./lib/portal_detector')
|
|
}
|
|
|
|
function createMCServer (options) {
|
|
options = options || {}
|
|
const mcServer = new MCServer()
|
|
mcServer.connect(options)
|
|
return mcServer
|
|
}
|
|
|
|
class MCServer extends EventEmitter {
|
|
constructor () {
|
|
super()
|
|
this._server = null
|
|
}
|
|
|
|
connect (options) {
|
|
const version = require('minecraft-data')(options.version).version
|
|
if (supportedVersions.indexOf(version.majorVersion) === -1) {
|
|
throw new Error(`Version ${version.minecraftVersion} is not supported.`)
|
|
}
|
|
this.supportFeature = feature => supportFeature(feature, version.majorVersion)
|
|
|
|
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')
|
|
}
|
|
}
|