antiblock
Elveron
  • Chatbox

    Did you check out our Discord? https://discord.gg/FFdvMjk9xA
    You don't have permission to chat.
    Load More
Karbust

Cloudflare R2 as a Patcher CDN

2 posts in this topic

Boas pessoal

 

Desculpem o tutorial estar em inglês mas, não me apeteceu perder tempo a reescrever tudo em português.

 

 

 

So, now that Cloudflare R2 is in general availability, it's time to talk about it and how it can improve your metin2 servers, more specifically, the patcher.

 

Tradicional CDNs and block storage are expensive and charge a lot for egress bandwidth, but Clouldflare, as always, doesn't charge for bandwidth, at all. Here is the pricing: https://developers.cloudflare.com/r2/platform/pricing/

 

Storage: 10GB/month (free), then $0.015/GB-month
Class A Operations: 1 million requests/month, then $4.50/million requests
Class B Operations: 10 million requests/month, then $0.36/million requests

 

On Class A, the more important operations for the patcher are: PutObject, and, if you use cloudflare's dashboard, ListBuckets and ListObjects (or the equivalent AWS S3 commands on the script at the bottom).
On Class B, the more important operations for the patcher are: GetObject, and, again, if you use cloudflare's dashboard, UsageSummary (or the equivalent AWS S3 commands on the script at the bottom).

 

I made a small PowerShell script to download a lot of files from the storage:

For ($i = 0; $i -lt 1000; $i++) {
    $ProgressPreference = 'SilentlyContinue'
    $combinedVariable = "C:\Users\Karbust\Desktop\test\metin2_$i.exe"
    $Response = Invoke-Webrequest -Uri https://<my custom domain>/metin2.exe -OutFile $combinedVariable
}

This was the usage metrics:

ouL2AGY.png

They barely change, the 20 class B requests are basically all from UsageSummary (refreshing the page), and the Class A are ListBuckets and ListObjects.

Why is that? Because by using a custom domain it will cache the requests. This is good to prevent GetObject flooding requests. Cloudflare, on free accounts (until Enterprise), can cache up to 512MB per file.

Instead of relying on the default cache rules, you can change them, to something like this:

7ekgRbH.png

When you make an update, you need to purge the cache, either purge it all or just the files you want.

 

Tutorial

Go to your cloudflare dashboard and access the R2 tab:

V9t2yPN.png

There you will be asked to enable it. You will need to have a payment setup in the account.

Then, after that's done, create a bucket, you can call it whatever you want:

8H0b1kN.png

Then go you Settings and scroll down to the Domain Access section and add one:

The domain must be in the same cloudflare account as the bucket.

KU4iZZc.png

LVhGpZX.png

Now you can use that domain to access the files in the bucket. If you change the cache settings, you must do it on the domain you added.

When you upload a file (or a folder), it will be something like this:

QmtSW4N.png

To access that file, you do https://<domain>/metin2.exe, like this: https://r2-tests.karbust.com/metin2.exe

If you have folders, just do https://<domain>/folder_name/file_name.

 

If you use my patcher:

 

You just need to edit this variables:

export const patchlistUrl = 'https://<domain>/files.json'
export const patchlistFolder = 'https://<domain>/files/'
export const patchSliderUrl = 'https://<domain>/slider.json'
export const patchSliderImages = 'https://<domain>/slider/'

 

Since you can't upload more than 100 files at the same time with the dashboard, I made a script in typescript to help with that:

https://github.com/Karbust/Cloudflare_R2_Upload

The instructions are in the repository, but I will say this, add the files inside the uploads folder, then run the script. If try to upload a file which already exists and the MD5 hash matches, it will not be uploaded and will return a http error code 412.

 

The end

 

I decided to make this tutorial since many servers use either one or multiple VPS to have more bandwidth, and downloads can become slow if many players are downloading at the same time, and because Cloudflare doesn't charge for used bandwidth, and has a generous free tier can is more than enough for almost all server owners.

 

Enjoy

Share this post


Link to post
Share on other sites
antiblock
https://arwen2.global/
Guest Lagosta do Snooke

good veri nici therapeutic tutorarial

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now