Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FML3 improvements #28

Merged
merged 10 commits into from
Dec 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions examples/mineflayer_forge/mineflayer_forge.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Usage: node mineflayer_forge.js
// Change values of host, port, username before using. Tested with 1.19.2 Minecraft offline server.

var mineflayer = require('mineflayer')
var pathfinder = require('mineflayer-pathfinder')
var autoVersionForge = require('../../src/client/autoVersionForge')

var host = "server's IP";
var port = "server's port";
var username = "bot's username";

var bot = mineflayer.createBot({
version: false,
host: host,
port: port,
username: username,
});

// leave options empty for guessing, otherwise specify the mods,
// channels and registries manually (channels and registries are only
// relevant for fml2 handshake)
const options = {
forgeMods: undefined,
channels: undefined,
}

// add handler
autoVersionForge(bot._client, options);

bot.loadPlugin(pathfinder.pathfinder)
console.info('Started mineflayer')

// set up logging
bot.on('connect', function () {
console.info('connected');
});

bot.on('spawn', function () {
console.info('I spawned')
})
9 changes: 9 additions & 0 deletions examples/mineflayer_forge/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "minecraft-protocol-forge-mineflayer-example",
"version": "0.0.0",
"private": true,
"dependencies": {
"minecraft-protocol": "^0.20.3"
},
"description": "An example of using a minecraft-protocol-forge with mineflayer"
}
41 changes: 41 additions & 0 deletions examples/mineflayer_forge_simplelogin/mineflayer_forge.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Usage: node mineflayer_forge.js
// Change values of host, port, username, sl_pwd before using. Tested with 1.19.2 Minecraft offline server with Simple Login mod.

var mineflayer = require('mineflayer');
var pathfinder = require('mineflayer-pathfinder');
var autoVersionForge = require('../../src/client/autoVersionForge');
var simplelogin = require('./simplelogin');

var host = "server's IP";
var port = "server's port";
var username = "bot's username";

var bot = mineflayer.createBot({
version: false,
host: host,
port: port,
username: username,
});

// leave options empty for guessing, otherwise specify the mods. Don't forget to write your Simple Login password (any password, if you connect for the first time)
const options = {
forgeMods: undefined,
channels: undefined,
sl_pwd: "Simple Login password for your bot"
};

// add handler
autoVersionForge(bot._client, options);
simplelogin(bot._client,options);

bot.loadPlugin(pathfinder.pathfinder);
console.info('Started mineflayer');

// set up logging
bot.on('connect', function () {
console.info('connected');
});

bot.on('spawn', function () {
console.info('I spawned')
});
9 changes: 9 additions & 0 deletions examples/mineflayer_forge_simplelogin/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "mineflayer-forge-simplelogin-example",
"version": "0.0.0",
"private": true,
"dependencies": {
"minecraft-protocol": "^0.20.3"
},
"description": "An example of using a minecraft-protocol-forge with mineflayer and Simple Login password feature (a Forge mod aimed to protect offline servers)"
}
84 changes: 84 additions & 0 deletions examples/mineflayer_forge_simplelogin/simplelogin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// https://github.com/SeraphJACK/SimpleLogin/blob/mc-1.19/src/main/java/top/seraphjack/simplelogin/network/MessageLogin.java

const Client = require("minecraft-protocol").Client;
const { SHA256 } = require('crypto-js');

const toBytes = (text) => {
const result = [];
for (let i = 0; i < text.length; i += 1) {
const hi = text.charCodeAt(i);
if (hi < 0x0080) {
// code point range: U+0000 - U+007F
// bytes: 0xxxxxxx
result.push(hi);
continue;
}
if (hi < 0x0800) {
// code point range: U+0080 - U+07FF
// bytes: 110xxxxx 10xxxxxx
result.push(0xC0 | hi >> 6,
0x80 | hi & 0x3F);
continue;
}
if (hi < 0xD800 || hi >= 0xE000 ) {
// code point range: U+0800 - U+FFFF
// bytes: 1110xxxx 10xxxxxx 10xxxxxx
result.push(0xE0 | hi >> 12,
0x80 | hi >> 6 & 0x3F,
0x80 | hi & 0x3F);
continue;
}
i += 1;
if (i < text.length) {
// surrogate pair
const lo = text.charCodeAt(i);
const code = 0x00010000 + (hi & 0x03FF) << 10 | lo & 0x03FF;
// code point range: U+10000 - U+10FFFF
// bytes: 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
result.push(0xF0 | code >> 18,
0x80 | code >> 12 & 0x3F,
0x80 | code >> 6 & 0x3F,
0x80 | code & 0x3F);
} else {
break;
}
}
return result;
};

function byte2Hex(bytes) {
const hexChars = [];
for (let i = 0; i < bytes.length; ++i) {
let hex = (bytes[i] & 0xff).toString(16);
if (hex.length === 1) {
hex = '0' + hex;
}
hexChars.push(hex);
}
return hexChars.join('');
}

function hash256(pwd) {
const hash = SHA256(pwd).toString();
const hash_bytes = toBytes(hash);
const hash_hex = byte2Hex(hash_bytes);
return hash_hex;
};

/**
* Simple Login message to the server.
*/
module.exports = function (client, options) {
client.on("custom_payload", function (packet) {
if (packet.channel === "simplelogin:main") {
const sl_pwd = options.sl_pwd;
const hashedPassword = hash256(sl_pwd).toString();
const len = Buffer.alloc(4);
const buffer = Buffer.concat([len, Buffer.from(hashedPassword, 'utf-8')]);
client.write('custom_payload', {
channel: 'simplelogin:main',
data: buffer,
});
};
});
};
11 changes: 8 additions & 3 deletions src/client/autoVersionForge.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module.exports = function (client, options) {
var forgeMods = response.forgeData.mods;
console.log('Using forgeMods:', forgeMods);

// Install the FML|HS plugin with the given mods
// Install the FML2 plugin with the given mods
forgeHandshake2(client, { forgeMods });
});

Expand All @@ -39,6 +39,11 @@ module.exports = function (client, options) {
return // not ours
}

forgeHandshake3(client)
})
// Use the list of Forge mods from the server ping, so client will match server
var forgeMods = response.forgeData.mods;
console.log('Using forgeMods:', forgeMods);

// Install the FML3 plugin with the given mods
forgeHandshake3(client, { forgeMods });
});
}
110 changes: 92 additions & 18 deletions src/client/data/fml3.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,13 @@
{
"type": "varint",
"mappings": {
"0": "ModList",
"1": "ModListReply",
"2": "ServerRegistry",
"3": "ConfigurationData",
"1": "ModList",
"2": "ModListReply",
"3": "ServerRegistry",
"4": "ConfigurationData",
"5": "ModData",
"6": "ChannelMismatchData",
"98": "Quark",
"99": "Acknowledgement"
}
}
Expand Down Expand Up @@ -197,17 +198,30 @@
]
}
]
},
{
"name": "dataPackRegistries",
"type": [
"array",
{
"countType": "varint",
"type": [
"container",
[
{
"name": "name",
"type": "string"
}
]
]
}
]
}
]
],
"ModListReply": [
"container",
[
{
"name": "modCount",
"type": "varint"

},
{
"name": "modNames",
"type": [
Expand All @@ -218,11 +232,6 @@
}
]
},
{
"name": "channelCount",
"type": "varint"

},
{
"name": "channels",
"type": [
Expand Down Expand Up @@ -298,14 +307,79 @@
}
]
],
"Acknowledgement": "void",
"ModData" : "void",
"ChannelMismatchData" : "void"
"ModData": [
"container",
[
{
"name": "mods",
"type": [
"array",
{
"countType": "varint",
"type": [
"container",
[
{
"name": "key",
"type": "string"
},
{
"name": "value",
"type": [
"container",
[
{
"name": "first",
"type": "string"
},
{
"name": "second",
"type": "string"
}
]
]
}
]
]
}
]
}
]
],
"ChannelMismatchData": [
"container",
[
{
"name": "mismatchedChannelData",
"type": [
"array",
{
"countType": "varint",
"type": [
"container",
[
{
"name": "first",
"type": "string"
},
{
"name": "second",
"type": "string"
}
]
]
}
]
}
]
],
"Quark": "void",
"Acknowledgement": "void"
}
}
]
}
]
]
}
}
}
Loading