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

Adding custom latency delay #1005

Open
bendgk opened this issue Jun 7, 2022 · 3 comments
Open

Adding custom latency delay #1005

bendgk opened this issue Jun 7, 2022 · 3 comments

Comments

@bendgk
Copy link

bendgk commented Jun 7, 2022

I'm experimenting with latency and how it affects Minecraft clients and servers.

What would be the easiest way to introduce "fake" latency between a node-minecraft-protocol client and a java server?

Essentially I'm thinking of something like being able to delay all packet writes by a custom spoofedLatency field.

Any way to currently do this? Where should I look if I wanted to implement such a feature?

@IceTank
Copy link
Contributor

IceTank commented Jun 7, 2022

You can make this by using a proxy to connect to a server. Then relay the packets after a certain delay. Or you can overwrite the write function off a client or server and replace it with a dummy function that takes the arguments and writes them after a while. Delaying packets can cause instability tho.

@bendgk
Copy link
Author

bendgk commented Jun 7, 2022

So I forked the repo, and used setTimeout to delay the write and writeRaw functions found in client.js however that didn't seem to work, the node player never seems to be able to join the server. I then tried to do the same in
deserializer.on('data', () =>{}) however that lead to deserialization problems.

If you have time, could you care to elaborate why this is happening and what a possible remedy may be?

I may just end up writing a proxy, seems like the most hassle free solution...

you can view my changes to client.js here

@IceTank
Copy link
Contributor

IceTank commented Jun 8, 2022

You can use the proxy example and change this line to use something like setTimeout to delay the write

if (!endedTargetClient) { targetClient.write(meta.name, data) }

Or you can do something like this

const client = createClient(...)
const originalWrite = client.write
client.write = (...args) => {
  setTimeout(() => {
    originalWrite(...args)
  }, 500)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants