mirror of
https://github.com/PrismarineJS/node-minecraft-protocol.git
synced 2024-11-15 03:14:56 -05:00
Use endian-toggle for UTF-16BE encoding (not in nodejs, see https://github.com/nodejs/node-v0.x-archive/issues/1684)
This commit is contained in:
parent
6eb95766cb
commit
4a677a25ba
2 changed files with 3 additions and 6 deletions
|
@ -29,6 +29,7 @@
|
||||||
"browser": "browser.js",
|
"browser": "browser.js",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"babel-preset-es2015": "^6.3.13",
|
"babel-preset-es2015": "^6.3.13",
|
||||||
|
"endian-toggle": "0.0.0",
|
||||||
"espower-loader": "^1.0.0",
|
"espower-loader": "^1.0.0",
|
||||||
"gulp": "^3.9.0",
|
"gulp": "^3.9.0",
|
||||||
"gulp-babel": "^6.1.1",
|
"gulp-babel": "^6.1.1",
|
||||||
|
|
|
@ -5,6 +5,7 @@ var states = require("./states");
|
||||||
var bufferEqual = require('buffer-equal');
|
var bufferEqual = require('buffer-equal');
|
||||||
var Server = require('./server');
|
var Server = require('./server');
|
||||||
var UUID = require('uuid-1345');
|
var UUID = require('uuid-1345');
|
||||||
|
var endianToggle = require('endian-toggle');
|
||||||
|
|
||||||
module.exports=createServer;
|
module.exports=createServer;
|
||||||
|
|
||||||
|
@ -139,12 +140,7 @@ function createServer(options) {
|
||||||
|
|
||||||
function sendPingResponse(responseString) {
|
function sendPingResponse(responseString) {
|
||||||
function utf16be(s) {
|
function utf16be(s) {
|
||||||
//var responseBuffer = new Buffer(responseString, 'utf16le'); // unfortunately, we need utf16be not le
|
return endianToggle(new Buffer(s, 'utf16le'), 16);
|
||||||
//var responseBuffer = new Buffer(responseString, 'ucs2'); // aliases for utf16le
|
|
||||||
// hack semi-UTF16BE encoding, by prefixing each character with a null byte
|
|
||||||
// TODO: use a real encoder, maybe https://github.com/ForbesLindesay/legacy-encoding?
|
|
||||||
// uses https://github.com/ashtuchkin/iconv-lite which has 'utf16-be'. use or separate out?
|
|
||||||
return new Buffer([''].concat(s.split('')).join('\0'), 'binary');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var responseBuffer = utf16be(responseString);
|
var responseBuffer = utf16be(responseString);
|
||||||
|
|
Loading…
Reference in a new issue