-
-
Notifications
You must be signed in to change notification settings - Fork 85
Nethernet support for joining worlds #533
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
Draft
LucienHH
wants to merge
26
commits into
PrismarineJS:master
Choose a base branch
from
LucienHH:Nethernet
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
e2490b1
Implement Nethernet spec
LucienHH 518d6a4
Add WebSocket signalling channel
LucienHH 7c6da57
Add Nethernet ping advertisement
LucienHH 39c5c7b
Add Session handling
LucienHH d5523ab
Add nethernet transport
LucienHH 711fd51
Fix tests
LucienHH 1ed3d29
Correctly build credentials
LucienHH 1c5906f
Use active broadcast address
LucienHH d3b250e
Fix signalling handling
LucienHH 5eded5e
Downgrade to werift v0.19.9
LucienHH cf4fbc1
Lint
LucienHH a1ff57b
Remove unnecessary ping
LucienHH 52e1662
Remove debug logs
LucienHH 22b9809
Send initial discovery request
LucienHH 77e8f71
Rename `Signal` to `NethernetSignal`
LucienHH 3daa454
Compression, batching and protocol fixes
LucienHH 9b06900
Use correct buffer
LucienHH 6212f01
Update to latest pauth API
LucienHH 698fe52
Use static arguments
LucienHH 6d3ba9f
Linting
LucienHH 1b05271
Move protocol to `node-nethernet`
LucienHH 6901b20
Fix connecting via signalling
LucienHH 4a32ec1
Move nethernet properties under .nethernet.*
LucienHH 7e27ccb
Create nethernet_local.js
LucienHH 7355018
Remove node-fetch
LucienHH f132679
Rename rta to session
LucienHH File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
process.env.DEBUG = 'minecraft-protocol' | ||
|
||
const readline = require('readline') | ||
const { createClient } = require('bedrock-protocol') | ||
|
||
async function pickSession (availableSessions) { | ||
return new Promise((resolve) => { | ||
const rl = readline.createInterface({ | ||
input: process.stdin, | ||
output: process.stdout | ||
}) | ||
|
||
console.log('Available Sessions:') | ||
|
||
availableSessions.forEach((session, index) => console.log(`${index + 1}. ${session.customProperties.hostName} ${session.customProperties.worldName} (${session.customProperties.version})`)) | ||
|
||
rl.question('Please select a session by number: ', (answer) => { | ||
const sessionIndex = parseInt(answer) - 1 | ||
|
||
if (sessionIndex >= 0 && sessionIndex < availableSessions.length) { | ||
const selectedSession = availableSessions[sessionIndex] | ||
console.log(`You selected: ${selectedSession.customProperties.hostName} ${selectedSession.customProperties.worldName} (${selectedSession.customProperties.version})`) | ||
resolve(selectedSession) | ||
} else { | ||
console.log('Invalid selection. Please try again.') | ||
resolve(pickSession()) | ||
} | ||
|
||
rl.close() | ||
}) | ||
}) | ||
} | ||
|
||
const client = createClient({ | ||
transport: 'nethernet', // Use the Nethernet transport | ||
world: { | ||
pickSession | ||
} | ||
}) | ||
|
||
let ix = 0 | ||
client.on('packet', (args) => { | ||
console.log(`Packet ${ix} recieved`) | ||
ix++ | ||
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
process.env.DEBUG = 'minecraft-protocol' | ||
|
||
const { Client } = require('node-nethernet') | ||
const { createClient } = require('bedrock-protocol') | ||
|
||
const c = new Client() | ||
|
||
c.once('pong', (pong) => { | ||
c.close() | ||
|
||
const client = createClient({ | ||
transport: 'nethernet', // Use the Nethernet transport | ||
networkId: pong.senderId, | ||
useSignalling: false | ||
}) | ||
|
||
let ix = 0 | ||
client.on('packet', (args) => { | ||
console.log(`Packet ${ix} recieved`) | ||
ix++ | ||
}) | ||
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* eslint-disable */ | ||
process.env.DEBUG = 'minecraft-protocol' | ||
|
||
const bedrock = require('bedrock-protocol') | ||
|
||
const server = bedrock.createServer({ | ||
transport: 'nethernet', | ||
useSignalling: true, // disable for LAN connections only | ||
motd: { | ||
motd: 'Funtime Server', | ||
levelName: 'Wonderland' | ||
} | ||
}) | ||
|
||
server.on('connect', client => { | ||
client.on('join', () => { // The client has joined the server. | ||
const date = new Date() // Once client is in the server, send a colorful kick message | ||
client.disconnect(`Good ${date.getHours() < 12 ? '§emorning§r' : '§3afternoon§r'}\n\nMy time is ${date.toLocaleString()} !`) | ||
}) | ||
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do we know what version to connect as here if the user does not specify/can't get via ping?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the user doesn't specify it defaults to the current version and the version isn't included in the Nethernet ping response
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, what is
advertisement.version
then? We may have to figure out the version after connecting to the server then like nmp can do. It should be sent in login/network_settings packet otherwise. The current code should also be matching version by protocol version num over strings but that should be fixed outside this PRThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not entirely sure but I assume it's the version of NetherNet protocol being used as it's just a uint8. From my testing it's always been set to 3 over multiple version updates.