games647 / ChangeSkin

Allows your players to change their skin by command
https://dev.bukkit.org/bukkit-plugins/changeskin/
MIT License
187 stars 33 forks source link

Cloudflare blog about caching mojang api #155

Open mirolm opened 6 years ago

mirolm commented 6 years ago

The blog post describes automating Mojang API with cloudflare tools. There are examples and API that can be used.

@games647 if you are interested have a look at it - maybe it can be usable for the plugin.

Minecraft API with Workers + CoffeeScript

The post creator states his API is free to use:

curl https://api.ashcon.app/mojang/v1/uuid/ElectroidFilms
curl https://api.ashcon.app/mojang/v1/user/ElectroidFilms
games647 commented 6 years ago

Thank you very much, I didn't know about this project. Nevertheless I think this project will hit rate limits as well although the idea behind is great. Serverless is perfect for this kind of problem.

DoNotSpamPls commented 6 years ago

@games647 I've looked into this project too, and while it's theoretically possible that it can hit ratelimits, it's practically impossible, due to the sheer amount of addresses CloudFlare owns (over 2 million, in fact).

However, currently it can't be used with ChangeSkin (for skins), due to it not reporting the signature, but that's something I've suggested and hopefully the developer will add soon.

games647 commented 6 years ago

@DoNotSpamPls

and while it's theoretically possible that it can hit ratelimits, it's practically impossible, due to the sheer amount of addresses CloudFlare owns

That's the total amount, but we don't know how those requests are distributed and if they are really equally load balanced. Maybe I'm just too pessimistic, so we should just try it out and judge after that.

However, currently it can't be used with ChangeSkin, due to it not reporting the signature, but that's something I've suggested and hopefully the developer will add soon.

That's fine. Only name -> uuid are problematic for rate-limiting. Skin downloads (based on the UUID) can be cached and are rarely hit by rate limiting only if you use player heads or Citizens skins.

BTW I looked into the code and it shouldn't be that hard to create a PR for that.

DoNotSpamPls commented 6 years ago

@games647 Well, the developer uses it for player heads on his own server's website, that's ~300 requests in the span of just a few seconds, so I feel ratelimits won't be an issue.

I suppose a seperate branch with this API added could be made - I'd be glad to test it :)

Leymooo commented 5 years ago

However, currently it can't be used with ChangeSkin (for skins), due to it not reporting the signature, but that's something I've suggested and hopefully the developer will add soon. Now there is v2, and it provide a value and the signature of skin. https://api.ashcon.app/mojang/v2/user/ElectroidFilms But it spend too much time for first request. ~3-4 seconds(only for profile request, for uuid its about ~150-200ms for first request). and ~20-50ms for repeated requests

games647 commented 5 years ago

I noticed that aswell, but with uuids too. If instant-skin-update is very stable, we could could still consider this. So that the user can join the server without a skin and ~3 seconds after it they get the skin.

Leymooo commented 5 years ago

For me uuid request does not spend to much time.

USER route for 'martin', isValid: 'true', time: '5575'
USER route for 'lethal', isValid: 'true', time: '5641'
USER route for 'legolas', isValid: 'true', time: '5946'
USER route for 'smile420', isValid: 'true', time: '5968'
USER route for 'victor', isValid: 'true', time: '6086'
USER route for 'yoker1', isValid: 'true', time: '6129'
USER route for 'godor', isValid: 'true', time: '6134'
USER route for 'dendimon', isValid: 'true', time: '3818'
USER route for 'walker', isValid: 'true', time: '3838'
UUID route for 'vetuv', isValid: 'true', time: '139'
UUID route for 'enterxx', isValid: 'false', time: '139'
UUID route for 'break_man', isValid: 'true', time: '141'
UUID route for 'velha', isValid: 'true', time: '147'
UUID route for 'brotex', isValid: 'true', time: '169'
UUID route for 'nene', isValid: 'true', time: '179'
UUID route for 'msds', isValid: 'true', time: '183'
UUID route for 'kako', isValid: 'true', time: '209'
UUID route for 'savn', isValid: 'true', time: '140'
UUID route for 'walkground', isValid: 'true', time: '156'
done

code: https://gist.github.com/Leymooo/78ee078ea0d9b3dc72d4ff1d34446a6d

games647 commented 5 years ago

Okay sorry, I thought you meant skin requests by UUID.

mirolm commented 5 years ago

Author stated that v2 API is ready for production back in May. Is it working good enough to be used by the plugin?

https://api.ashcon.app/mojang/v2/user/Notch