responsive design
This commit is contained in:
parent
63644ecc7f
commit
c617ddffc4
3 changed files with 74 additions and 12 deletions
|
@ -1,7 +1,9 @@
|
|||
2
|
||||
Minecraft Rust Async Networking Proxy CRIU
|
||||
\title
|
||||
|
||||
\toc
|
||||
|
||||
# Minecraft servers are HUNGRY
|
||||
|
||||
They hunger for your ram and your cpu. This makes it either expensive or
|
||||
|
@ -50,21 +52,65 @@ minecraft protocol instead of HTTP.
|
|||
|
||||
## The Minecraft protocol
|
||||
|
||||
Minecraft implements its own protocol consistent of packets. My first idea was to see if anybody had created a
|
||||
rust library for dealing with minecraft packets.
|
||||
Minecraft implements its own protocol consistent of packets. My first idea
|
||||
was to see if anybody had created a rust library for dealing with minecraft
|
||||
packets.
|
||||
|
||||
While some did exist, most of them where unfinished or couldn't do what I wanted. [One crate](https://www.youtube.com/watch?v=E4WlUXrJgy4)
|
||||
was useful for seeing how an implementation of parsing packets was done, but ultimately I had to write my own parser.
|
||||
While some did exist, most of them where unfinished or couldn't do what I
|
||||
wanted. [One crate](https://www.youtube.com/watch?v=E4WlUXrJgy4) was useful
|
||||
for seeing how an implementation of parsing packets was done, but ultimately
|
||||
I had to write my own parser.
|
||||
|
||||
*images of minecraft protocol*
|
||||
***images of minecraft protocol***
|
||||
|
||||
## Detecting the subdomain
|
||||
|
||||
Luckily for me, the Minecraft procotol sends the full address it is trying to connect to during the handshake. This meant that I simply
|
||||
had to parse the handshake and extract the subdomain from the address, see if it matches any configured server, and then redirect all
|
||||
traffic to the internal port that server runs on.
|
||||
Luckily for me, the Minecraft procotol sends the full address it is trying to
|
||||
connect to during the handshake. This meant that I simply had to parse the
|
||||
handshake and extract the subdomain from the address, see if it matches any
|
||||
configured server, and then redirect all traffic to the internal port that
|
||||
server runs on.
|
||||
|
||||
*code explanation*
|
||||
***code explanation***
|
||||
|
||||
***show images of hibernation and starting***
|
||||
|
||||

|
||||

|
||||
|
||||
I've talked a bunch about this hibernation, but how does it actually work?
|
||||
|
||||
# cat /proc/$(ps aux | grep server.jar) > hibernation.txt
|
||||
|
||||
Finally being able to connect to the server it was time for the next item on the list.
|
||||
|
||||
<p style="text-align: center">✨**Hibernation**✨</p>
|
||||
|
||||
Now, instead of closing the server and restarting it when a player joined I
|
||||
wanted to hibernate the server and unhibernate it when someone joined.
|
||||
|
||||
I had a feeling this would be possible as this is basically how hibernation
|
||||
works for your system; it saves the memory to disk and loads it into memory
|
||||
again upon boot.
|
||||
|
||||
After a bit of searching I found [CRIU](https://criu.org/Main_Page), a program
|
||||
capable of suspending another program to disk.
|
||||
|
||||
Not only does it save the memory, it also saves all the file descriptors the
|
||||
program was using (and fails with a million cryptic error messages if any of the
|
||||
files where changed during hibernation)
|
||||
|
||||
There was a Rust crate for CRIU, however it was poorly documented and didnt support
|
||||
all the command line arguments I needed, so I resorted to calling the binary.
|
||||
|
||||
This led to the program halting until the unhibernated server closed again, but
|
||||
it was fixed with a simple fork.
|
||||
|
||||
The only downside to this approach is that CRIU requires root access in order
|
||||
to read the memory and file descriptors of another process.
|
||||
Running your minecraft server as root is probably not the smartest idea...
|
||||
|
||||
My solution was to not care about it and hope for the best :D
|
||||
|
||||
# Why aren't my chunks loading?
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue