ACBob / VoxelThingYeah

Voxel Game Engine
1 stars 1 forks source link

Network Protocol #2

Open ACBob opened 3 years ago

ACBob commented 3 years ago

I need to define a proper protocol for the network, Looking at Minecraft it seems to have a shitton of packet types without much care in the world for saving them (Cuberite as reference on 1.8) so I can do the same, right? Right?

This doesn't clear up how MC does player input, I'm still thinking looking should be 100% client-side (and set to the server, although this might have issues if the client lies) and use a source-like ConCommand system where inputs are commands executed on the server.

ACBob commented 3 years ago

Important Question:\ Encryption, Yay or Nay?

After that, How do we do it!?\ Perhaps a password hash sent to the server ala Minetest?

ACBob commented 3 years ago

as of commit ac9437e this is being worked on

ACBob commented 3 years ago

An Idea I'd had:\ It's loosely based on Minecraft Classic.

Client -> Server

Packet ID Info Notes
Player ID Protocol Version, Username
Set Block Position, BlockType
Chat Message Message
Pong Contains no data
Leave Contains no data
Chunk Request X,Y,Z
Command Executed Command, Command Args Used for Movement ConCommands (#11)

Server -> Client

Packed ID Info Notes
Server Info Protocol Version, Server Name, Server Description
Keep Alive Contains no data
Chunk Data X, Y, Z, nBlocks, Blocks (1D Array)
Set Block X, Y, Z, Block Type Sent to ALL clients, even the client that might've instigated it
Player Spawn X,Y,Z, Pitch, Yaw
Chat Message Username, Message
Disconnect isKick, Kick Mesasge
Convar Update ConVarName, Value Used for CVars marked notify (i.e sv_cheats)

Example

Joining the server for the first time, Downloading the chunk at spawn and then leaving:

Client DIR Server
Player ID -> Test name, protocol version, etc.
Set local variables, Test protocol, etc. <- Server Info
Set local coordinates, orientation <- Player Spawn
Chunk Request -> Load the chunk data and spit it back
Handle chunk data, generating mesh & stuff <- Chunk Data
... ... ...
Send Pong <- Keep Alive
Pong -> Don't kick player
... ... ...
Leave -> Handle leaving, kick player*

*We kick the player to stop fraudulent leaving, where the client doesn't actually disconnect - The server decides when you're done.

ACBob commented 3 years ago

Further investigation into how MC does it shows that the server reads your render distance, and then decides itself to send you chunks. This is actually really smart, so let's do that too.

The client can ignore any chunks outside its' set render distance in the case of a malicious server, and the server can curb to a maximum render distance by not sending anymore.

This also means a client can't just go "HEY I'M GOING TO LOOP FROM -infinity TO +infinity IN ALL DIRECTIONS, GIMME CHUNKS" and then ignore it, which would be a funny but unfortunate attack.

ACBob commented 3 years ago

What we have atm seems to work alright, but is too minecraft based. Doesn't even implement #11!

Good for a prototype, needs changed and fixed.

ACBob commented 3 years ago

While technically we have something working, there's always room for improvement.