Sandertv / go-raknet

Go library implementing a basic version of the RakNet protocol.
MIT License
100 stars 38 forks source link

RakNet Security layer is not supported #28

Closed RaphiMC closed 4 months ago

RaphiMC commented 8 months ago

Trying to connect to a server which uses the RakNet security flag (In OpenConnectionReply1) causes a timeout. While I am not 100% sure that the timeout is not caused by some other error in go-raknet other RakNet libraries failed because of the servers usage of the security flag (See https://github.com/CloudburstMC/Network/issues/37). Connecting to the server with Bedrock Edition (or https://github.com/extremeheat/fb-raknet) works fine since both use the original RakNet.

Reproduceable example code:

package main

import (
    "github.com/sandertv/go-raknet"
    "time"
)

func main() {
    conn, err := raknet.DialTimeout("play.timecrack.net:19132", time.Duration(5)*time.Second)
    if err != nil {
        panic(err.Error())
    }
    defer func(conn *raknet.Conn) {
        err := conn.Close()
        if err != nil {
            panic(err.Error())
        }
    }(conn)

    println("Connected")
}
dktapps commented 5 months ago

FWIW, the vanilla RakNet client decodes OpenConnectionReply1 differently depending on whether it was compiled with security support or not. If the server enables security but the client doesn't support it, the client won't read the key bytes from the packet, and will interpret those bytes as the MTU size. Basically the server needs to be psychic and know whether the client supports encryption in order to structure the packet properly. RakNet Quality Code ™

Sandertv commented 4 months ago

Fixed in 1beb5ce.