-
Notifications
You must be signed in to change notification settings - Fork 0
Installation
- A working Dragonfly server (
main.gousinggithub.com/df-mc/dragonfly/server). - A running Portal proxy, with
network.communication.secretset — see Portal's Configuration wiki page.
go get github.com/MEMOxiiii/PortalDFEnable connects to the proxy, registers /transfer, /server and /servers, and wires up stale-session cleanup, all in a single call:
package main
import (
"github.com/MEMOxiiii/PortalDF"
"github.com/df-mc/dragonfly/server"
)
func main() {
// ... set up dragonfly server config ...
srv := conf.New()
srv.CloseOnProgramEnd()
srv.Listen()
portaldf.Enable(srv, portaldf.Config{
ProxyAddress: "127.0.0.1",
SocketPort: 19131,
Secret: "your-secret",
ServerName: "Hub1",
ServerAddress: "127.0.0.1:19132",
})
for p := range srv.Accept() {
// handle players...
}
}Enable returns the *Portal client, so you can still call any of its methods (TransferPlayer, SetLatencyHandler, SetDraining, etc. — see API Usage) on the result if you need more than the built-in commands. Use EnableWithLogger instead of Enable to log through your own *slog.Logger.
Every Config field is documented in Configuration — the four above are the minimum you need; if this server should run over NetherNet instead of RakNet, read Transport Setup before changing ServerAddress's format.
If you'd rather manage the connection and command registration yourself (for example, to skip the built-in commands), wire them up individually instead of calling Enable:
package main
import (
"log/slog"
"github.com/MEMOxiiii/PortalDF"
portalcmd "github.com/MEMOxiiii/PortalDF/command"
"github.com/df-mc/dragonfly/server"
)
func main() {
// ... set up dragonfly server config ...
srv := conf.New()
srv.CloseOnProgramEnd()
portal := portaldf.New(portaldf.Config{
ProxyAddress: "127.0.0.1",
SocketPort: 19131,
Secret: "your-secret",
ServerName: "Hub1",
ServerAddress: "127.0.0.1:19132",
}, slog.Default())
go portal.Connect()
// Register /transfer, /server, /servers commands.
portalcmd.Register(portal, srv)
srv.Listen()
for p := range srv.Accept() {
// handle players...
}
}See Commands for what portalcmd.Register gives you, and API Usage for everything callable on the *Portal client either path returns.