Standard (#44)

* standard

* remove old examples
This commit is contained in:
extremeheat 2021-03-13 13:38:31 -05:00 committed by GitHub
commit 1c582acdb5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
36 changed files with 539 additions and 731 deletions

View file

@ -1,9 +1,7 @@
process.env.DEBUG = 'minecraft-protocol raknet'
const { Client } = require('../src/client')
const fs = require('fs')
// console.log = () =>
async function test() {
async function test () {
const client = new Client({
hostname: '127.0.0.1',
port: 19132
@ -32,11 +30,8 @@ async function test() {
client.queue('client_cache_status', { enabled: false })
client.queue('request_chunk_radius', { chunk_radius: 1 })
client.queue('tick_sync', { request_time: BigInt(Date.now()), response_time: 0n })
})
// var read = 0;
// client.on('level_chunk', (packet) => {
// read++
@ -44,4 +39,4 @@ async function test() {
// })
}
test()
test()

View file

@ -1,6 +1,6 @@
const { Relay } = require('../src/relay')
function createRelay() {
function createRelay () {
console.log('Creating relay')
/**
* Example to create a non-transparent proxy (or 'Relay') connection to destination server
@ -27,7 +27,7 @@ function createRelay() {
/* Where to send upstream packets to */
destination: {
hostname: '127.0.0.1',
port: 19132,
port: 19132
// encryption: true
}
})
@ -35,4 +35,4 @@ function createRelay() {
relay.create()
}
createRelay()
createRelay()

Binary file not shown.

View file

@ -1,25 +0,0 @@
'use strict';
var pmp = require('../');
if(process.argv.length !=5) {
console.log("Usage: node client.js <host> <port> <username>");
process.exit(1);
}
var client = pmp.createClient({
host: process.argv[2],
port: parseInt(process.argv[3]),
username:process.argv[4]
});
client.on('mcpe', packet => console.log(packet));
client.on('set_spawn_position', () => {
client.writeMCPE('request_chunk_radius', {
chunkRadius:8
});
});
client.on('error',function(err){
console.log(err);
});

View file

@ -1,16 +0,0 @@
'use strict';
var mcpe = require('../');
var Parser = require('protodef').Parser;
var parser = new Parser(mcpe.createProtocol(),'mcpe_packet');
var serializer = mcpe.createSerializer();
parser.write(new Buffer('9F000000010000007E000000804800B0', 'hex'));
parser.on('error', function(err) {
console.log(err.stack);
})
parser.on('data', function(chunk) {
console.log(JSON.stringify(chunk, null, 2));
});

View file

@ -1,108 +0,0 @@
'use strict';
var pmp = require('../');
var fs = require("fs");
if(process.argv.length !=4) {
console.log("Usage: node server.js <host> <port>");
process.exit(1);
}
var server = pmp.createServer({
host: process.argv[2],
port: parseInt(process.argv[3]),
name: 'MCPE;Minecraft: PE Server;81 81;0.15.0;0;20'
});
server.on('connection', function(client) {
client.on("mcpe",packet => console.log(packet));
client.on("login_mcpe",packet => {
client.writeMCPE("player_status",{
status:0
});
client.writeMCPE('move_player', {
entityId: [0,0],
x: 1,
y: 64 + 1.62,
z: 1,
yaw: 0,
headYaw: 0,
pitch: 0,
mode: 0,
onGround: 1
});
client.writeMCPE("start_game",{
seed:-1,
dimension:0,
generator:1,
gamemode:1,
entityId:[0,0],
spawnX:1,
spawnY:1,
spawnZ:1,
x:0,
y:1+1.62,
z:0,
isLoadedInCreative:0,
dayCycleStopTime:0,
eduMode:0,
worldName:""
});
client.writeMCPE('set_spawn_position', {
x: 1,
y: 64,
z: 1
});
client.writeMCPE("set_time",{
time:0,
started:1
});
client.writeMCPE('respawn', {
x: 1,
y: 64,
z: 1
});
});
client.on("chunk_radius_update",() => {
client.writeMCPE('chunk_radius_update',{
chunk_radius:1
});
for (let x = -1; x <=1; x++) {
for (let z = -1; z <=1; z++) {
client.writeBatch([{name:"full_chunk_data",params:{
chunkX: x,
chunkZ: z,
order: 1,
chunkData:fs.readFileSync(__dirname+"/chunk")
}}]);
}
}
client.writeMCPE('player_status', {
status: 3
});
client.writeMCPE('set_time', {
time: 0,
started: 1
});
});
client.on('error', function(err) {
console.log(err.stack);
});
client.on('end',function() {
console.log("client left");
})
});

View file

@ -1,31 +0,0 @@
'use strict';
var pmp = require('../');
var fs = require("fs");
if(process.argv.length !=4) {
console.log("Usage: node server.js <host> <port>");
process.exit(1);
}
var server = pmp.createServer({
host: process.argv[2],
port: parseInt(process.argv[3]),
name: 'MCPE;Minecraft: PE Server;81 81;0.15.0;0;20'
});
server.on('connection', function(client) {
client.on("mcpe", packet => console.log(packet));
client.on("login_mcpe", data => {
console.log(client.displayName + '(' + client.XUID + ') ' + ' joined the game');
});
client.on('error', err => {
console.error(err);
});
client.on('end', () => {
console.log("client left");
})
});

View file

@ -1,25 +1,23 @@
const fs = require('fs')
process.env.DEBUG = 'minecraft-protocol raknet'
const { Server } = require('../src/server')
// const CreativeItems = require('../data/creativeitems.json')
const NBT = require('prismarine-nbt')
const fs = require('fs')
const DataProvider = require('../data/provider')
let server = new Server({
const server = new Server({
})
server.create('0.0.0.0', 19132)
function getPath(packetPath) {
function getPath (packetPath) {
return DataProvider(server.options.protocolVersion).getPath(packetPath)
}
function get(packetPath) {
function get (packetPath) {
return require(getPath('sample/' + packetPath))
}
let ran = false
// const ran = false
server.on('connect', ({ client }) => {
/** @type {Player} */
@ -29,26 +27,26 @@ server.on('connect', ({ client }) => {
// ResourcePacksInfo is sent by the server to inform the client on what resource packs the server has. It
// sends a list of the resource packs it has and basic information on them like the version and description.
client.write('resource_packs_info', {
'must_accept': false,
'has_scripts': false,
'behaviour_packs': [],
'texture_packs': []
must_accept: false,
has_scripts: false,
behaviour_packs: [],
texture_packs: []
})
client.once('resource_pack_client_response', async (packet) => {
// ResourcePackStack is sent by the server to send the order in which resource packs and behaviour packs
// should be applied (and downloaded) by the client.
client.write('resource_pack_stack', {
'must_accept': false,
'behavior_packs': [],
'resource_packs': [],
'game_version': '',
'experiments': [],
'experiments_previously_used': false
must_accept: false,
behavior_packs: [],
resource_packs: [],
game_version: '',
experiments: [],
experiments_previously_used: false
})
client.once('resource_pack_client_response', async (packet) => {
})
client.write('network_settings', {
@ -56,35 +54,35 @@ server.on('connect', ({ client }) => {
})
for (let i = 0; i < 3; i++) {
client.queue('inventory_slot', {"inventory_id":120,"slot":i,"uniqueid":0,"item":{"network_id":0}})
client.queue('inventory_slot', { inventory_id: 120, slot: i, uniqueid: 0, item: { network_id: 0 } })
}
client.queue('inventory_transaction', get('packets/inventory_transaction.json'))
client.queue('player_list', get('packets/player_list.json'))
client.queue('start_game', get('packets/start_game.json'))
client.queue('item_component', {"entries":[]})
client.queue('item_component', { entries: [] })
client.queue('set_spawn_position', get('packets/set_spawn_position.json'))
client.queue('set_time', { time: 5433771 })
client.queue('set_difficulty', { difficulty: 1 })
client.queue('set_commands_enabled', { enabled: true })
client.queue('adventure_settings', get('packets/adventure_settings.json'))
client.queue('biome_definition_list', get('packets/biome_definition_list.json'))
client.queue('available_entity_identifiers', get('packets/available_entity_identifiers.json'))
client.queue('update_attributes', get('packets/update_attributes.json'))
client.queue('creative_content', get('packets/creative_content.json'))
client.queue('inventory_content', get('packets/inventory_content.json'))
client.queue('player_hotbar', {"selected_slot":3,"window_id":0,"select_slot":true})
client.queue('player_hotbar', { selected_slot: 3, window_id: 0, select_slot: true })
client.queue('crafting_data', get('packets/crafting_data.json'))
client.queue('available_commands', get('packets/available_commands.json'))
client.queue('chunk_radius_update', {"chunk_radius":5})
client.queue('chunk_radius_update', { chunk_radius: 5 })
client.queue('set_entity_data', get('packets/set_entity_data.json'))
client.queue('game_rules_changed', get('packets/game_rules_changed.json'))
client.queue('respawn', {"x":646.9405517578125,"y":65.62001037597656,"z":77.86255645751953,"state":0,"runtime_entity_id":0})
client.queue('respawn', { x: 646.9405517578125, y: 65.62001037597656, z: 77.86255645751953, state: 0, runtime_entity_id: 0 })
for (const file of fs.readdirSync(`../data/${server.options.version}/sample/chunks`)) {
const buffer = Buffer.from(fs.readFileSync(`../data/${server.options.version}/sample/chunks/` + file, 'utf8'), 'hex')
@ -97,18 +95,17 @@ server.on('connect', ({ client }) => {
// }
setInterval(() => {
client.write('network_chunk_publisher_update', {"coordinates":{"x":646,"y":130,"z":77},"radius":64})
client.write('network_chunk_publisher_update', { coordinates: { x: 646, y: 130, z: 77 }, radius: 64 })
}, 9500)
setTimeout(() => {
client.write('play_status', { status: 'player_spawn' })
}, 8000)
// Respond to tick synchronization packets
client.on('tick_sync', ({ request_time }) => {
client.on('tick_sync', (packet) => {
client.queue('tick_sync', {
request_time,
request_time: packet.request_time,
response_time: BigInt(Date.now())
})
})
@ -116,43 +113,41 @@ server.on('connect', ({ client }) => {
})
})
async function sleep(ms) {
return new Promise(res => {
setTimeout(() => { res() }, ms)
})
}
// CHUNKS
// const { ChunkColumn, Version } = require('bedrock-provider')
const mcData = require('minecraft-data')('1.16')
var chunks = []
async function buildChunks() {
// "x": 40,
// "z": 4,
const stone = mcData.blocksByName.stone
// const mcData = require('minecraft-data')('1.16')
// const chunks = []
// async function buildChunks () {
// // "x": 40,
// // "z": 4,
for (var cx = 35; cx < 45; cx++) {
for (var cz = 0; cz < 8; cz++) {
const column = new ChunkColumn(Version.v1_2_0_bis, x, z)
for (var x = 0; x < 16; x++) {
for (var y = 0; y < 60; y++) {
for (var z = 0; z < 16; z++) {
column.setBlock(x,y,z,stone)
}
}
}
// const stone = mcData.blocksByName.stone
const ser = await column.networkEncodeNoCache()
// for (let cx = 35; cx < 45; cx++) {
// for (let cz = 0; cz < 8; cz++) {
// const column = new ChunkColumn(Version.v1_2_0_bis, x, z)
// for (let x = 0; x < 16; x++) {
// for (let y = 0; y < 60; y++) {
// for (let z = 0; z < 16; z++) {
// column.setBlock(x, y, z, stone)
// }
// }
// }
chunks.push({
x:cx, z:cz, sub_chunk_count: column.sectionsLen, cache_enabled: false,
blobs: [], payload: ser
})
}
}
// const ser = await column.networkEncodeNoCache()
// console.log('Chunks',chunks)
}
// chunks.push({
// x: cx,
// z: cz,
// sub_chunk_count: column.sectionsLen,
// cache_enabled: false,
// blobs: [],
// payload: ser
// })
// }
// }
// buildChunks()
// // console.log('Chunks',chunks)
// }
// // buildChunks()