mirror of
https://github.com/MeowLynxSea/Proksea.git
synced 2025-07-09 10:54:40 +00:00
Fix the problem of being unable to change servers in a bungeecord server
This commit is contained in:
parent
48631dbbe7
commit
de02b44266
132
app.js
132
app.js
@ -20,107 +20,49 @@ function getConfig() {
|
|||||||
const config = getConfig();
|
const config = getConfig();
|
||||||
|
|
||||||
//启动本地服务器作为default和fallback
|
//启动本地服务器作为default和fallback
|
||||||
const mc = require('minecraft-protocol')
|
let defaultServer = require('./localServer')(config)
|
||||||
|
|
||||||
console.info("Starting local server...")
|
|
||||||
config.serverList.default.port = config.localServerOptions.port
|
|
||||||
const defaultServer = mc.createServer(config.localServerOptions)
|
|
||||||
|
|
||||||
const mcData = require('minecraft-data')("1.16.3")
|
|
||||||
const loginPacket = mcData.loginPacket
|
|
||||||
|
|
||||||
defaultServer.on('playerJoin', (client) => {
|
|
||||||
isConnected = true
|
|
||||||
client.write('login', {
|
|
||||||
...loginPacket,
|
|
||||||
entityId: client.id,
|
|
||||||
isHardcore: false,
|
|
||||||
gameMode: 0,
|
|
||||||
previousGameMode: 1,
|
|
||||||
worldName: 'minecraft:overworld',
|
|
||||||
hashedSeed: [0, 0],
|
|
||||||
maxPlayers: defaultServer.maxPlayers,
|
|
||||||
viewDistance: 1,
|
|
||||||
reducedDebugInfo: false,
|
|
||||||
enableRespawnScreen: true,
|
|
||||||
isDebug: false,
|
|
||||||
isFlat: false
|
|
||||||
})
|
|
||||||
client.on('end', () => { isConnected = false })
|
|
||||||
client.on('error', () => { isConnected = false })
|
|
||||||
client.write('position', {
|
|
||||||
x: 0,
|
|
||||||
y: 0,
|
|
||||||
z: 0,
|
|
||||||
yaw: 0,
|
|
||||||
pitch: 0,
|
|
||||||
flags: 0x00
|
|
||||||
})
|
|
||||||
|
|
||||||
client.write('chat', {
|
|
||||||
message: JSON.stringify({ text: "欢迎使用Proksea\n发送 /proksea help 以获取更多帮助\n" }),
|
|
||||||
position: 0,
|
|
||||||
sender: "Proksea"
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
console.info("Local server listening on port " + config.localServerOptions.port)
|
|
||||||
|
|
||||||
//启动代理服务器
|
//启动代理服务器
|
||||||
const McProxy = require('basic-minecraft-proxy')
|
let proxy = require('./proxy')(config)
|
||||||
|
|
||||||
let proxyServerOptions = config.proxyOptions
|
//控制台指令处理
|
||||||
let serverList = config.serverList
|
const readline = require('readline');
|
||||||
let proxyOptions = {}
|
const rl = readline.createInterface({
|
||||||
let proxyPlugins = []
|
input: process.stdin,
|
||||||
|
output: process.stdout
|
||||||
//加载插件
|
|
||||||
const pluginsDir = path.resolve(__dirname, './plugins');
|
|
||||||
const files = fs.readdirSync(pluginsDir);
|
|
||||||
files.forEach(file => {
|
|
||||||
if (path.extname(file) === '.js') {
|
|
||||||
const filePath = path.join(pluginsDir, file);
|
|
||||||
console.log("Found plugin: [" + file + "]")
|
|
||||||
proxyPlugins.push(require(filePath))
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let proxy = McProxy.createProxy(proxyServerOptions, serverList, proxyOptions, proxyPlugins);
|
function handleCommand(command) {
|
||||||
|
const args = command.trim().split(' ');
|
||||||
|
const cmd = args[0].toLowerCase();
|
||||||
|
|
||||||
|
switch (cmd) {
|
||||||
|
case 'greet':
|
||||||
|
const name = args[1] || 'stranger';
|
||||||
|
console.log(`Hello, ${name}!`);
|
||||||
|
break;
|
||||||
|
case 'exit':
|
||||||
|
console.log('Goodbye!');
|
||||||
|
rl.close();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
console.log(`Unknown command: ${cmd}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
rl.setPrompt('> ');
|
||||||
|
rl.prompt();
|
||||||
|
|
||||||
proxy.on('error', (err) => {
|
rl.on('line', (input) => {
|
||||||
console.error("A error occured while running proxy: " + err)
|
handleCommand(input);
|
||||||
})
|
rl.prompt();
|
||||||
|
});
|
||||||
proxy.on('listening', () => {
|
rl.on('close', () => {
|
||||||
console.info('Proxy listening on port ' + proxyServerOptions.port)
|
console.log('Stopping server...')
|
||||||
})
|
Object.values(proxy.clients).forEach(client => {
|
||||||
|
client.write('kick_disconnect', {
|
||||||
proxy.on('login', (player) => {
|
reason: '111'
|
||||||
console.info(`[${player.username}] connected from ${player.socket.remoteAddress}`)
|
})
|
||||||
|
|
||||||
player.on('end', () => {
|
|
||||||
console.info(`[${player.username}] disconnected: ${player.socket.remoteAddress}`)
|
|
||||||
})
|
})
|
||||||
|
process.exit(0);
|
||||||
player.on('error', (err) => {
|
});
|
||||||
console.error(`[${player.username}] disconnected with error: ${player.socket.remoteAddress}`, err)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
proxy.on('moveFailed', (err, playerId, oldServerName, newServerName) => {
|
|
||||||
console.error(`Player [${proxy.clients[playerId].username}] failed to move from ${oldServerName} to ${newServerName}`, err)
|
|
||||||
})
|
|
||||||
|
|
||||||
proxy.on('playerMoving', (playerId, oldServerName, newServerName) => {
|
|
||||||
console.info(`Player [${proxy.clients[playerId].username}] is moving from ${oldServerName} to ${newServerName}`)
|
|
||||||
})
|
|
||||||
|
|
||||||
proxy.on('playerMoved', (playerId, oldServerName, newServerName) => {
|
|
||||||
console.info(`Player [${proxy.clients[playerId].username}] has moved from ${oldServerName} to ${newServerName}`)
|
|
||||||
})
|
|
||||||
|
|
||||||
proxy.on('playerFallback', (playerId, oldServerName, newServerName) => {
|
|
||||||
console.info(`Player [${proxy.clients[playerId].username}] is falling back from ${oldServerName} to ${newServerName}`)
|
|
||||||
})
|
|
49
localServer.js
Normal file
49
localServer.js
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
module.exports = function(config) {
|
||||||
|
const mc = require('minecraft-protocol')
|
||||||
|
|
||||||
|
console.info("Starting local server...")
|
||||||
|
config.serverList.default.port = config.localServerOptions.port
|
||||||
|
const defaultServer = mc.createServer(config.localServerOptions)
|
||||||
|
|
||||||
|
const mcData = require('minecraft-data')("1.16.3")
|
||||||
|
const loginPacket = mcData.loginPacket
|
||||||
|
|
||||||
|
defaultServer.on('playerJoin', (client) => {
|
||||||
|
isConnected = true
|
||||||
|
client.write('login', {
|
||||||
|
...loginPacket,
|
||||||
|
entityId: client.id,
|
||||||
|
isHardcore: false,
|
||||||
|
gameMode: 0,
|
||||||
|
previousGameMode: 1,
|
||||||
|
worldName: 'minecraft:overworld',
|
||||||
|
hashedSeed: [0, 0],
|
||||||
|
maxPlayers: defaultServer.maxPlayers,
|
||||||
|
viewDistance: 10,
|
||||||
|
reducedDebugInfo: false,
|
||||||
|
enableRespawnScreen: true,
|
||||||
|
isDebug: false,
|
||||||
|
isFlat: false
|
||||||
|
})
|
||||||
|
client.on('end', () => { isConnected = false })
|
||||||
|
client.on('error', () => { isConnected = false })
|
||||||
|
client.write('position', {
|
||||||
|
x: 0,
|
||||||
|
y: 0,
|
||||||
|
z: 0,
|
||||||
|
yaw: 0,
|
||||||
|
pitch: 0,
|
||||||
|
flags: 0x00
|
||||||
|
})
|
||||||
|
|
||||||
|
client.write('chat', {
|
||||||
|
message: JSON.stringify({ text: "欢迎使用Proksea\n发送 /proksea help 以获取更多帮助\n" }),
|
||||||
|
position: 0,
|
||||||
|
sender: "Proksea"
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
console.info("Local server listening on port " + config.localServerOptions.port)
|
||||||
|
|
||||||
|
return defaultServer
|
||||||
|
}
|
5
node_modules/.package-lock.json
generated
vendored
5
node_modules/.package-lock.json
generated
vendored
@ -697,6 +697,11 @@
|
|||||||
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
|
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/readline": {
|
||||||
|
"version": "1.3.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/readline/-/readline-1.3.0.tgz",
|
||||||
|
"integrity": "sha512-k2d6ACCkiNYz222Fs/iNze30rRJ1iIicW7JuX/7/cozvih6YCkFZH+J6mAFDVgv0dRBaAyr4jDqC95R2y4IADg=="
|
||||||
|
},
|
||||||
"node_modules/ret": {
|
"node_modules/ret": {
|
||||||
"version": "0.1.15",
|
"version": "0.1.15",
|
||||||
"resolved": "https://registry.npmjs.org/ret/-/ret-0.1.15.tgz",
|
"resolved": "https://registry.npmjs.org/ret/-/ret-0.1.15.tgz",
|
||||||
|
2
node_modules/basic-minecraft-proxy/src/Proxy/packetReplayer.js
generated
vendored
2
node_modules/basic-minecraft-proxy/src/Proxy/packetReplayer.js
generated
vendored
@ -13,7 +13,7 @@ function replayer(remoteClient, localClient, callback) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
localClient.on('login', (data, metadata) => {
|
localClient.once('login', (data, metadata) => {
|
||||||
sentRespawn = true
|
sentRespawn = true
|
||||||
remoteClient.write('respawn', {
|
remoteClient.write('respawn', {
|
||||||
dimension: data.dimension,
|
dimension: data.dimension,
|
||||||
|
6
node_modules/basic-minecraft-proxy/src/createProxy.js
generated
vendored
6
node_modules/basic-minecraft-proxy/src/createProxy.js
generated
vendored
@ -53,7 +53,11 @@ function createProxy(localServerOptions = {}, serverList = {}, proxyOptions = {}
|
|||||||
|
|
||||||
proxy.on('connection', (client) => {
|
proxy.on('connection', (client) => {
|
||||||
localServerPlugins.forEach((plugin) => plugin(client, proxy, localServerOptions, proxyOptions))
|
localServerPlugins.forEach((plugin) => plugin(client, proxy, localServerOptions, proxyOptions))
|
||||||
if (enablePlugins) proxyPlugins.forEach((plugin) => plugin(client, proxy, localServerOptions, proxyOptions))
|
if (enablePlugins) proxyPlugins.forEach((plugin) => {
|
||||||
|
if ('onConnection' in plugin) {
|
||||||
|
plugin.onConnection(client, proxy, localServerOptions, proxyOptions)
|
||||||
|
}
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
proxy.listen(port, host)
|
proxy.listen(port, host)
|
||||||
|
2
node_modules/readline/.npmignore
generated
vendored
Normal file
2
node_modules/readline/.npmignore
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
node_modules/
|
||||||
|
npm-debug.log
|
66
node_modules/readline/README.md
generated
vendored
Normal file
66
node_modules/readline/README.md
generated
vendored
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
## _readline_
|
||||||
|
> Read a file line by line.
|
||||||
|
|
||||||
|
## Install
|
||||||
|
|
||||||
|
## Important. In node 10 there is a core module named readline. Please use linebyline instead, it is the same module just renamed:
|
||||||
|
[Npm linebyline](https://www.npmjs.com/package/linebyline)
|
||||||
|
|
||||||
|
```sh
|
||||||
|
npm install linebyline
|
||||||
|
```
|
||||||
|
|
||||||
|
## Test
|
||||||
|
```sh
|
||||||
|
npm install .
|
||||||
|
npm test
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## What's this?
|
||||||
|
|
||||||
|
Simple streaming readline module for NodeJS. Reads a file and buffers new lines emitting a _line_ event for each line.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
### Simple
|
||||||
|
```js
|
||||||
|
var readline = require('linebyline'),
|
||||||
|
rl = readline('./somefile.txt');
|
||||||
|
rl.on('line', function(line, lineCount, byteCount) {
|
||||||
|
// do something with the line of text
|
||||||
|
})
|
||||||
|
.on('error', function(e) {
|
||||||
|
// something went wrong
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### ASCII file decoding
|
||||||
|
As the underlying `fs.createReadStream` doesn't care about the specific ASCII encoding of the file, an alternative way to decode the file is by telling the `readline` library to retain buffer and then decoding it using a converter (e.g. [`iconv-lite`](https://www.npmjs.com/package/iconv-lite)).
|
||||||
|
```js
|
||||||
|
var readline = require('linebyline'),
|
||||||
|
rl = readline('./file-in-win1251.txt', {
|
||||||
|
retainBuffer: true //tell readline to retain buffer
|
||||||
|
});
|
||||||
|
rl.on("line", function (data,linecount){
|
||||||
|
var line = iconv.decode(data, 'win1251');
|
||||||
|
// do something with the line of converted text
|
||||||
|
});
|
||||||
|
```
|
||||||
|
##API
|
||||||
|
## readLine(readingObject[, options])
|
||||||
|
### Params:
|
||||||
|
|
||||||
|
* `readingObject` - file path or stream object
|
||||||
|
* `options` can include:
|
||||||
|
* `maxLineLength` - override the default 4K buffer size (lines longer than this will not be read)
|
||||||
|
* `retainBuffer` - avoid converting to String prior to emitting 'line' event; will pass raw buffer with encoded data to the callback
|
||||||
|
|
||||||
|
### Return:
|
||||||
|
|
||||||
|
* **EventEmitter**
|
||||||
|
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
BSD © [Craig Brookes](http://craigbrookes.com/)
|
22
node_modules/readline/package.json
generated
vendored
Normal file
22
node_modules/readline/package.json
generated
vendored
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
{
|
||||||
|
"name": "readline",
|
||||||
|
"version": "1.3.0",
|
||||||
|
"description": "Simple streaming readline module.",
|
||||||
|
"main": "readline.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "tap --tap --stderr --timeout=120 test/*.js"
|
||||||
|
},
|
||||||
|
"dependencies":{},
|
||||||
|
"devDependencies":{
|
||||||
|
"tap":"0.4.3",
|
||||||
|
"iconv-lite":"0.4.13"
|
||||||
|
},
|
||||||
|
"repository": "git@github.com:maleck13/readline.git",
|
||||||
|
"keywords": [
|
||||||
|
"readline",
|
||||||
|
"line by line",
|
||||||
|
"file"
|
||||||
|
],
|
||||||
|
"author": "craig brookes",
|
||||||
|
"license": "BSD"
|
||||||
|
}
|
60
node_modules/readline/readline.js
generated
vendored
Normal file
60
node_modules/readline/readline.js
generated
vendored
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
var fs = require('fs'),
|
||||||
|
EventEmitter = require('events').EventEmitter,
|
||||||
|
util = require('util');
|
||||||
|
|
||||||
|
var readLine = module.exports = function(file, opts) {
|
||||||
|
if (!(this instanceof readLine)) return new readLine(file, opts);
|
||||||
|
|
||||||
|
EventEmitter.call(this);
|
||||||
|
opts = opts || {};
|
||||||
|
opts.maxLineLength = opts.maxLineLength || 4096; // 4K
|
||||||
|
opts.retainBuffer = !!opts.retainBuffer; //do not convert to String prior to invoking emit 'line' event
|
||||||
|
var self = this,
|
||||||
|
lineBuffer = new Buffer(opts.maxLineLength),
|
||||||
|
lineLength = 0,
|
||||||
|
lineCount = 0,
|
||||||
|
byteCount = 0,
|
||||||
|
emit = function(lineCount, byteCount) {
|
||||||
|
try {
|
||||||
|
var line = lineBuffer.slice(0, lineLength);
|
||||||
|
self.emit('line', opts.retainBuffer? line : line.toString(), lineCount, byteCount);
|
||||||
|
} catch (err) {
|
||||||
|
self.emit('error', err);
|
||||||
|
} finally {
|
||||||
|
lineLength = 0; // Empty buffer.
|
||||||
|
}
|
||||||
|
};
|
||||||
|
this.input = ('string' === typeof file) ? fs.createReadStream(file, opts) : file;
|
||||||
|
this.input.on('open', function(fd) {
|
||||||
|
self.emit('open', fd);
|
||||||
|
})
|
||||||
|
.on('data', function(data) {
|
||||||
|
for (var i = 0; i < data.length; i++) {
|
||||||
|
if (data[i] == 10 || data[i] == 13) { // Newline char was found.
|
||||||
|
if (data[i] == 10) {
|
||||||
|
lineCount++;
|
||||||
|
emit(lineCount, byteCount);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
lineBuffer[lineLength] = data[i]; // Buffer new line data.
|
||||||
|
lineLength++;
|
||||||
|
}
|
||||||
|
byteCount++;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.on('error', function(err) {
|
||||||
|
self.emit('error', err);
|
||||||
|
})
|
||||||
|
.on('end', function() {
|
||||||
|
// Emit last line if anything left over since EOF won't trigger it.
|
||||||
|
if (lineLength) {
|
||||||
|
lineCount++;
|
||||||
|
emit(lineCount, byteCount);
|
||||||
|
}
|
||||||
|
self.emit('end');
|
||||||
|
})
|
||||||
|
.on('close', function() {
|
||||||
|
self.emit('close');
|
||||||
|
});
|
||||||
|
};
|
||||||
|
util.inherits(readLine, EventEmitter);
|
39773
node_modules/readline/test/fixtures/afile.txt
generated
vendored
Normal file
39773
node_modules/readline/test/fixtures/afile.txt
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
14
node_modules/readline/test/fixtures/file-in-win1251.txt
generated
vendored
Normal file
14
node_modules/readline/test/fixtures/file-in-win1251.txt
generated
vendored
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
file n (folder for keeping information) ïàïêà æ
|
||||||
|
I have a file that I keep all my telephone bills in.
|
||||||
|
Ó ìåíÿ åñòü ïàïêà, â êîòîðîé ÿ õðàíþ âñå ñ÷åòà çà òåëåôîí.
|
||||||
|
file n (tool) íàïèëüíèê ì
|
||||||
|
He used a file to smooth the corner of the wood.
|
||||||
|
Îí çà÷èñòèë íàïèëüíèêîì êðàé äåðåâà.
|
||||||
|
file n (computer file) ôàéë ì
|
||||||
|
Can you send me the file as an attachment in an email?
|
||||||
|
Ìîæåøü ïîñëàòü ìíå ýòîò ôàéë êàê ïðèëîæåíèå ê ýëåêòðîííîìó ïèñüìó?
|
||||||
|
I file all my telephone bills together.
|
||||||
|
ß ïîäøèâàþ âñå ñ÷åòà çà ýëåêòðè÷åñòâî âìåñòå.
|
||||||
|
file vtr (smooth with a file) øëèôîâàòü, çà÷èùàòü íåñîâ + âèí
|
||||||
|
He filed the wood.
|
||||||
|
Îí øëèôîâàë äåðåâî.
|
7
node_modules/readline/test/fixtures/nmbr.txt
generated
vendored
Normal file
7
node_modules/readline/test/fixtures/nmbr.txt
generated
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
1
|
||||||
|
2
|
||||||
|
3
|
||||||
|
4
|
||||||
|
5
|
||||||
|
6
|
||||||
|
7
|
138
node_modules/readline/test/test_readline.js
generated
vendored
Normal file
138
node_modules/readline/test/test_readline.js
generated
vendored
Normal file
@ -0,0 +1,138 @@
|
|||||||
|
var fs = require('fs');
|
||||||
|
var readLine = require('../readline.js');
|
||||||
|
var test = require("tap").test;
|
||||||
|
|
||||||
|
test("test reading lines",function(t){
|
||||||
|
console.error("reading large file line by line asserts may take a while");
|
||||||
|
var rl = readLine('./fixtures/afile.txt');
|
||||||
|
rl.on("line", function (line,linecount){
|
||||||
|
t.ok(null !== line && undefined !== line);
|
||||||
|
});
|
||||||
|
rl.on("end",function (){
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
test("numbers", function (t){
|
||||||
|
var rl = readLine('./fixtures/nmbr.txt');
|
||||||
|
var answer = 28;
|
||||||
|
var i=0;
|
||||||
|
rl.on("line", function (line){
|
||||||
|
var num = Number(line);
|
||||||
|
console.error(num);
|
||||||
|
i+=num;
|
||||||
|
|
||||||
|
});
|
||||||
|
rl.on("end", function (){
|
||||||
|
console.error(i,answer);
|
||||||
|
t.ok(answer === i, "answered");
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
test("errors", function (t){
|
||||||
|
var rl = readLine("./Idontexist");
|
||||||
|
rl.on('error', function (e){
|
||||||
|
t.ok(e);
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
rl.on('end', function (){
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
rl.on('close', function(){
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
test("line count", function(t){
|
||||||
|
var rl = readLine('./fixtures/nmbr.txt');
|
||||||
|
var expect = 7;
|
||||||
|
var actual = 0;
|
||||||
|
rl.on("line", function (line, ln){
|
||||||
|
console.log("line",line,ln);
|
||||||
|
actual=ln;
|
||||||
|
});
|
||||||
|
rl.on("end", function (){
|
||||||
|
t.ok(actual === expect,"line count is correct");
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test("byte count after first line", function(t){
|
||||||
|
var rl = readLine('./fixtures/nmbr.txt');
|
||||||
|
var actual = 0;
|
||||||
|
var expect;
|
||||||
|
rl.on("line", function (line, ln, byteCount){
|
||||||
|
if (expect === undefined) {
|
||||||
|
expect = line.length;
|
||||||
|
console.log("byte count",byteCount);
|
||||||
|
actual=byteCount;
|
||||||
|
|
||||||
|
t.ok(actual === expect,"byte count is correct");
|
||||||
|
t.end();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test("byte count", function(t){
|
||||||
|
var rl = readLine('./fixtures/nmbr.txt');
|
||||||
|
var expect = fs.statSync('./fixtures/nmbr.txt').size;
|
||||||
|
var actual = 0;
|
||||||
|
rl.on("line", function (line, ln, byteCount){
|
||||||
|
console.log("byte count",byteCount);
|
||||||
|
actual=byteCount;
|
||||||
|
});
|
||||||
|
rl.on("end", function (){
|
||||||
|
t.ok(actual === expect,"byte count is correct");
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test("processing error passed on", function(t){
|
||||||
|
var rl = readLine('./fixtures/nmbr.txt');
|
||||||
|
var lastError;
|
||||||
|
var lineCalls = 0;
|
||||||
|
|
||||||
|
rl.on("line", function (line, ln, byteCount){
|
||||||
|
lineCalls++;
|
||||||
|
if (ln === 7) {
|
||||||
|
throw new Error('fake error');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
rl.on("error", function (err){
|
||||||
|
if (!lastError) {
|
||||||
|
lastError = err;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
rl.on("end", function (){
|
||||||
|
t.ok(lastError.message === 'fake error','error is passed on');
|
||||||
|
t.ok(lineCalls === 7, 'line count ok');
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test("test ascii file reading",function(t){
|
||||||
|
var iconv = require('iconv-lite');
|
||||||
|
var testFileValidationKeywords = {
|
||||||
|
1: 'папка',
|
||||||
|
3: 'телефон',
|
||||||
|
11: 'электричество',
|
||||||
|
14: 'дерево'
|
||||||
|
};
|
||||||
|
|
||||||
|
var rl = readLine('./fixtures/file-in-win1251.txt', {
|
||||||
|
retainBuffer: true
|
||||||
|
});
|
||||||
|
rl.on("line", function (data,linecount){
|
||||||
|
var line = iconv.decode(data, 'win1251');
|
||||||
|
t.ok(!testFileValidationKeywords[linecount] || line.indexOf(testFileValidationKeywords[linecount]) > -1);
|
||||||
|
});
|
||||||
|
rl.on("end",function (){
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
8
package-lock.json
generated
8
package-lock.json
generated
@ -12,7 +12,8 @@
|
|||||||
"basic-minecraft-proxy": "^2.0.1",
|
"basic-minecraft-proxy": "^2.0.1",
|
||||||
"loglevel": "^1.9.1",
|
"loglevel": "^1.9.1",
|
||||||
"minecraft-protocol": "^1.47.0",
|
"minecraft-protocol": "^1.47.0",
|
||||||
"prismarine-chunk": "^1.35.0"
|
"prismarine-chunk": "^1.35.0",
|
||||||
|
"readline": "^1.3.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@azure/msal-common": {
|
"node_modules/@azure/msal-common": {
|
||||||
@ -708,6 +709,11 @@
|
|||||||
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
|
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/readline": {
|
||||||
|
"version": "1.3.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/readline/-/readline-1.3.0.tgz",
|
||||||
|
"integrity": "sha512-k2d6ACCkiNYz222Fs/iNze30rRJ1iIicW7JuX/7/cozvih6YCkFZH+J6mAFDVgv0dRBaAyr4jDqC95R2y4IADg=="
|
||||||
|
},
|
||||||
"node_modules/ret": {
|
"node_modules/ret": {
|
||||||
"version": "0.1.15",
|
"version": "0.1.15",
|
||||||
"resolved": "https://registry.npmjs.org/ret/-/ret-0.1.15.tgz",
|
"resolved": "https://registry.npmjs.org/ret/-/ret-0.1.15.tgz",
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
"basic-minecraft-proxy": "^2.0.1",
|
"basic-minecraft-proxy": "^2.0.1",
|
||||||
"loglevel": "^1.9.1",
|
"loglevel": "^1.9.1",
|
||||||
"minecraft-protocol": "^1.47.0",
|
"minecraft-protocol": "^1.47.0",
|
||||||
"prismarine-chunk": "^1.35.0"
|
"prismarine-chunk": "^1.35.0",
|
||||||
|
"readline": "^1.3.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ const helpText = "\
|
|||||||
/proksea connect <server> - 连接到指定服务器\n\n\
|
/proksea connect <server> - 连接到指定服务器\n\n\
|
||||||
======================\n"
|
======================\n"
|
||||||
|
|
||||||
function handleCommands(client, proxy, localServerOptions, proxyOptions) {
|
function onConnection(client, proxy, localServerOptions, proxyOptions) {
|
||||||
client.on('chat', (data, metadata) => {
|
client.on('chat', (data, metadata) => {
|
||||||
let split = data.message.split(' ')
|
let split = data.message.split(' ')
|
||||||
if (split[0] === '/proksea') {
|
if (split[0] === '/proksea') {
|
||||||
@ -39,4 +39,6 @@ function handleCommands(client, proxy, localServerOptions, proxyOptions) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = handleCommands
|
module.exports = {
|
||||||
|
onConnection: onConnection
|
||||||
|
}
|
64
proxy.js
Normal file
64
proxy.js
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
module.exports = function(config) {
|
||||||
|
const McProxy = require('basic-minecraft-proxy')
|
||||||
|
|
||||||
|
let proxyServerOptions = config.proxyOptions
|
||||||
|
let serverList = config.serverList
|
||||||
|
let proxyOptions = {}
|
||||||
|
let proxyPlugins = []
|
||||||
|
|
||||||
|
//加载插件
|
||||||
|
const pluginsDir = path.resolve(__dirname, './plugins');
|
||||||
|
const files = fs.readdirSync(pluginsDir);
|
||||||
|
files.forEach(file => {
|
||||||
|
if (path.extname(file) === '.js') {
|
||||||
|
const filePath = path.join(pluginsDir, file);
|
||||||
|
console.log("Found plugin: [" + file + "]")
|
||||||
|
proxyPlugins.push(require(filePath))
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
let proxy = McProxy.createProxy(proxyServerOptions, serverList, proxyOptions, proxyPlugins);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
proxy.on('error', (err) => {
|
||||||
|
console.error("A error occured while running proxy: " + err)
|
||||||
|
})
|
||||||
|
|
||||||
|
proxy.on('listening', () => {
|
||||||
|
console.info('Proxy listening on port ' + proxyServerOptions.port)
|
||||||
|
})
|
||||||
|
|
||||||
|
proxy.on('login', (player) => {
|
||||||
|
console.info(`[${player.username}] connected from ${player.socket.remoteAddress}`)
|
||||||
|
|
||||||
|
player.on('end', () => {
|
||||||
|
console.info(`[${player.username}] disconnected: ${player.socket.remoteAddress}`)
|
||||||
|
})
|
||||||
|
|
||||||
|
player.on('error', (err) => {
|
||||||
|
console.error(`[${player.username}] disconnected with error: ${player.socket.remoteAddress}`, err)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
proxy.on('moveFailed', (err, playerId, oldServerName, newServerName) => {
|
||||||
|
console.error(`Player [${proxy.clients[playerId].username}] failed to move from ${oldServerName} to ${newServerName}`, err)
|
||||||
|
})
|
||||||
|
|
||||||
|
proxy.on('playerMoving', (playerId, oldServerName, newServerName) => {
|
||||||
|
console.info(`Player [${proxy.clients[playerId].username}] is moving from ${oldServerName} to ${newServerName}`)
|
||||||
|
})
|
||||||
|
|
||||||
|
proxy.on('playerMoved', (playerId, oldServerName, newServerName) => {
|
||||||
|
console.info(`Player [${proxy.clients[playerId].username}] has moved from ${oldServerName} to ${newServerName}`)
|
||||||
|
})
|
||||||
|
|
||||||
|
proxy.on('playerFallback', (playerId, oldServerName, newServerName) => {
|
||||||
|
console.info(`Player [${proxy.clients[playerId].username}] is falling back from ${oldServerName} to ${newServerName}`)
|
||||||
|
})
|
||||||
|
|
||||||
|
return proxy
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user