docs: add godoc comments to all exported functions and methods

This commit is contained in:
adman
2026-07-30 00:20:55 +02:00
parent 56c97a2b3f
commit 0d6b6e1ab9
50 changed files with 186 additions and 408 deletions
+1
View File
@@ -14,6 +14,7 @@ type ConfigServer struct {
registryData map[string]any
}
// ServeConfig runs the configuration phase: sends known packs, registry data, and tags, then transitions to play.
func ServeConfig(c *proto.Conn) (err error) {
cs := &ConfigServer{Conn: c}
n, err := data.LoadRegistry(c.Version)
+1
View File
@@ -17,6 +17,7 @@ var (
CantKickInStateErr = errors.New("cant kick in this state")
)
// Kick sends a disconnect/kick packet appropriate for the connection's current state.
func Kick(c *proto.Conn, reason *text.Component, status string) (err error) {
if c.Actor != proto_base.Servee {
err = NotClientErr
+8
View File
@@ -204,6 +204,7 @@ func (l *LoginServer) FinishLogin() (err error) {
type LoginServerSetting func(*LoginServer)
// WithOtherAccount returns a setting that overrides the login identity with the given account.
func WithOtherAccount(a *api2.Account) LoginServerSetting {
return func(s *LoginServer) {
s.Given = &NameAndUUID{
@@ -213,12 +214,14 @@ func WithOtherAccount(a *api2.Account) LoginServerSetting {
}
}
// WithRawStatus returns a setting that sets the raw JSON status response payload.
func WithRawStatus(status []byte) LoginServerSetting {
return func(s *LoginServer) {
s.Status = status
}
}
// WithStatus marshals a StatusResponse to JSON and passes it to WithRawStatus.
func WithStatus(response StatusResponse) LoginServerSetting {
var status []byte
status, err := json.Marshal(response)
@@ -229,6 +232,7 @@ func WithStatus(response StatusResponse) LoginServerSetting {
return WithRawStatus(status)
}
// WithCompatibleVersionsRange returns a setting that restricts the server to protocol versions in [start, end].
func WithCompatibleVersionsRange(start, end int32) LoginServerSetting {
var versions []int32
for i := start; i <= end; i++ {
@@ -237,24 +241,28 @@ func WithCompatibleVersionsRange(start, end int32) LoginServerSetting {
return WithCompatibleVersions(versions...)
}
// WithCompatibleVersions returns a setting that restricts the server to the given protocol versions.
func WithCompatibleVersions(versions ...int32) LoginServerSetting {
return func(s *LoginServer) {
s.CompatibleVersions = versions
}
}
// WithoutOnlineMode returns a setting that disables online-mode authentication.
func WithoutOnlineMode() LoginServerSetting {
return func(s *LoginServer) {
s.OnlineMode = false
}
}
// WithoutEncryption returns a setting that disables connection encryption.
func WithoutEncryption() LoginServerSetting {
return func(s *LoginServer) {
s.Encryption = false
}
}
// ServeLogin runs the full login sequence (handshake, encryption, auth, and configuration handoff) on a connection.
func ServeLogin(c *proto.Conn, settings ...LoginServerSetting) (ret *LoginServer, err error) {
ret = &LoginServer{Conn: c}
ret.OnlineMode = true
+5
View File
@@ -9,6 +9,7 @@ import (
"github.com/admin-else/strom/mc/text"
)
// Servee wraps a net.Conn in a new proto.Conn configured for the servee side.
func Servee(c net.Conn) (ret *proto.Conn) {
ret = proto.NewConn()
ret.Actor = proto_base.Servee
@@ -24,6 +25,7 @@ type ConnAcceptor func(c net.Conn) (err error)
type Factory func(c *proto.Conn) (h ConnAcceptor, err error)
// ServeClient accepts a single client connection, creates a handler via the factory, and runs it.
func ServeClient(cNet net.Conn, factory Factory) {
c := Servee(cNet)
defer c.Close()
@@ -40,6 +42,7 @@ func ServeClient(cNet net.Conn, factory Factory) {
}
}
// StartServerWithFactory listens on the given address and spawns ServeClient for every accepted connection.
func StartServerWithFactory(listenAddr string, factory Factory) (err error) {
l, err := net.Listen("tcp", listenAddr)
if err != nil {
@@ -57,6 +60,8 @@ func StartServerWithFactory(listenAddr string, factory Factory) (err error) {
var ShutDownServerErr = errors.New("server shutting down")
// StartServerWithOnConn listens on the given address and calls onConn for every accepted connection.
// The server loop stops when onConn returns ShutDownServerErr.
func StartServerWithOnConn(listenAddr string, onConn func(c *proto.Conn) (err error)) (err error) {
l, err := net.Listen("tcp", listenAddr)
if err != nil {
+1
View File
@@ -56,6 +56,7 @@ func (p *StatusServer) OnStatusPing(packet *v1_21_8.StatusToServerPacketPing) (e
return p.Send(&v1_21_8.StatusToClientPacketPing{Time: packet.Time})
}
// ServeStatus runs the server list ping sequence, responding with the given StatusResponse.
func ServeStatus(c *proto.Conn, s StatusResponse) (err error) {
status, err := json.Marshal(s)
if err != nil {