Trigary / Iodine

A Minecraft mod - server plugin pair that adds custom GUIs and overlays. No more inventory and chat menus!
GNU General Public License v3.0
24 stars 0 forks source link

Client-side caching of image GUI elements #9

Closed Trigary closed 4 years ago

Trigary commented 5 years ago

Images should be cached client-side. I don't want to force the clients into making any web requests, therefore the server (the plugin) must provide the images. To allow caching, the images can't be included in the serialized form of the image GUI elements, therefore an alternative way of requesting them must be added. (A request packet that clients can send, to which the server responds with the image. This raises security questions, eg. what if the client requests an image it shouldn't be allowed to see? A possible and easy-to-implement answer is to not cache such secret images, but alternatives, eg. checking whether the player has a reason to request that image at that time exist.)

Keeping track of which clients have which images server-side would still not allow the images to be serialized with the rest of the GUI: currently, the GUI only needs to be serialized once when it is updated, and that byte array can be sent to all players. This means that the image would have to be sent separately, at that point giving the clients a way to request them seems better.

Trigary commented 5 years ago

The caching should probably be based on String keys, which follow some simple regex, eg. a-zA-Z0-9_-:

If the image is cached, a CRC32 should be included in the image GUI element's serialized form. This way it's easy to implement images which change eg. daily.

Trigary commented 4 years ago

When the server receives the packet to which it should reply with the cached image itself, how does the server actually find the cached image? Should these cached images be supplied to the GUI element or to some central manager instead? What about images that aren't cached. Should the images be kept in-memory? They should have a maximum size, what should that be?

Trigary commented 4 years ago

The client requesting these images when it should already be displaying the GUI doesn't seem like a nice idea. A potentially optional option of pre-sending it should exist. This could be done by Iodine automatically on player join and also by plugins through the API.

Trigary commented 4 years ago

Instead of the mod handling the image caching, can't we just rely on the resource pack system? The mod would only have to transmit the resource identifier. This system would also allow the use of built-in textures, which I want to add nevertheless.

Non-cached images would still have to be included in the packets.