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

Make it easy for a server to encode a packet once and send it to multiple clients #713

Closed
rom1504 opened this issue May 11, 2020 · 3 comments · Fixed by #851
Closed

Make it easy for a server to encode a packet once and send it to multiple clients #713

rom1504 opened this issue May 11, 2020 · 3 comments · Fixed by #851

Comments

@rom1504
Copy link
Member

rom1504 commented May 11, 2020

Basically use client.writeRaw + a convenient way to encode packets only once.

use case : https://github.com/PrismarineJS/flying-squid/blob/master/src/lib/plugins/world.js#L62

(@Karang idea)

would make server implementations faster

@Saiv46
Copy link

Saiv46 commented May 12, 2020

{} !== {}

Maybe there should be a way to make a cache for that things (WeakMap + Hash)

@rom1504
Copy link
Member Author

rom1504 commented May 12, 2020

Invalidating caches is hard. It's better to do this explicitly

@Karang
Copy link
Contributor

Karang commented May 12, 2020

Why doing complicated things where it just boils down to exposing 3 things:

  • A method to serialize a packet and return a buffer
  • the list of connected clients
  • a way to send a raw packet
    Maybe a convenience method can be added to the server:
server.writeToClients = (clients, data) {
  const buf = server.serializer.createBuffer(data)
  clients.forEach(client => client.writeRaw(buf))
}

The problem with cache is that the buffers will tend to be very short lived. Take for instance a position update packet: it needs to be rebuilt very often and only sent at a point in time, to all players around. But once it is sent, there is no point in keeping it in memory.

The only exception I could think of would be the map_chunk packets, that are fairly large, not modified very often and need to be sent to every new player coming in the area. But I think if we want to do some chunk packet caching, it makes more sense to handle that one in prismarine-chunks

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