This commit is contained in:
adman
2026-01-25 12:55:27 +01:00
parent 0034a2c6d4
commit 85529b965b
7 changed files with 34 additions and 8 deletions
+2 -1
View File
@@ -4,6 +4,7 @@ package event
import ( import (
"errors" "errors"
"fmt" "fmt"
"log/slog"
"reflect" "reflect"
"strings" "strings"
) )
@@ -61,7 +62,7 @@ func (l *Loop) FindHandlers() {
} }
eventType := method.Type.In(1) eventType := method.Type.In(1)
l.HandlerFunctions[eventType] = append(l.HandlerFunctions[eventType], v.Method(i)) l.HandlerFunctions[eventType] = append(l.HandlerFunctions[eventType], v.Method(i))
//fmt.Println("Registered Handler:", t.String(), ".", method.Name, "(", eventType.String(), ")") slog.Debug("Registered Handler", "at", t.String()+"."+method.Name, "for", eventType.String())
} }
} }
} }
+1 -1
View File
@@ -1,6 +1,6 @@
module github.com/admin-else/strom module github.com/admin-else/strom
go 1.24 go 1.25
require ( require (
github.com/go-viper/mapstructure/v2 v2.4.0 github.com/go-viper/mapstructure/v2 v2.4.0
+2
View File
@@ -2,5 +2,7 @@ github.com/go-viper/mapstructure/v2 v2.4.0 h1:EBsztssimR/CONLSZZ04E8qAkxNYq4Qp9L
github.com/go-viper/mapstructure/v2 v2.4.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM= github.com/go-viper/mapstructure/v2 v2.4.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4=
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
+8
View File
@@ -0,0 +1,8 @@
go 1.25
use (
.devres/examples/ishacking
.
.devres/examples/ishackingapis
.devres/examples/testmod
)
+3
View File
@@ -63,6 +63,9 @@ func StartServerWithOnConn(listenAddr string, onConn func(c *proto.Conn) (err er
defer c.Close() defer c.Close()
connErr := onConn(c) connErr := onConn(c)
if connErr != nil { if connErr != nil {
if c.State() == proto_base.Status || c.State() == proto_base.Handshaking {
return // we dont care about status packets
}
slog.Error("Error while handling client", "error", connErr, "client", c.Conn.RemoteAddr()) slog.Error("Error while handling client", "error", connErr, "client", c.Conn.RemoteAddr())
connErr = server_modules.Kick(c, text.Pretty(connErr.Error())) connErr = server_modules.Kick(c, text.Pretty(connErr.Error()))
if connErr != nil { if connErr != nil {
+5 -6
View File
@@ -32,8 +32,6 @@ func (u UnexpectedNextStateError) Error() string {
return fmt.Sprintf("unexpected next state: %v", u.NextState) return fmt.Sprintf("unexpected next state: %v", u.NextState)
} }
var IncompatibleProtocolVersionError = fmt.Errorf("incompatible protocol version")
type LoginServer struct { type LoginServer struct {
*proto.Conn *proto.Conn
//OnlineMode bool FIXME: implement this //OnlineMode bool FIXME: implement this
@@ -51,16 +49,17 @@ func (l *LoginServer) OnHandshake(packet *v1_21_8.HandshakingToServerPacketSetPr
l.ServerHost = packet.ServerHost l.ServerHost = packet.ServerHost
l.ServerPort = packet.ServerPort l.ServerPort = packet.ServerPort
if packet.NextState != int32(proto_base.Login) && !(l.Status != nil && packet.NextState == int32(proto_base.Status)) {
err = UnexpectedNextStateError{proto_base.State(packet.NextState)}
}
if len(l.CompatibleVersions) != 0 { if len(l.CompatibleVersions) != 0 {
if !slices.Contains(l.CompatibleVersions, packet.ProtocolVersion) { if !slices.Contains(l.CompatibleVersions, packet.ProtocolVersion) {
err = IncompatibleProtocolVersionError err = fmt.Errorf("incompatible protocol version please use one of %v you can look up the real coresponding version at https://minecraft.wiki/w/Minecraft_Wiki:Projects/wiki.vg_merge/Protocol_version_numbers", l.CompatibleVersions)
return return
} }
} }
if packet.NextState != int32(proto_base.Login) && !(l.Status != nil && packet.NextState == int32(proto_base.Status)) {
err = UnexpectedNextStateError{proto_base.State(packet.NextState)}
}
return return
} }
+13
View File
@@ -4,6 +4,8 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"strings" "strings"
"github.com/admin-else/strom/nbt"
) )
// Component represents a Minecraft text component. // Component represents a Minecraft text component.
@@ -538,3 +540,14 @@ func (c *Component) writePretty(sb *strings.Builder) {
extra.writePretty(sb) extra.writePretty(sb)
} }
} }
func (c *Component) AsNBT() nbt.Anon {
return nbt.Anon{Value: c.ToNBT()}
}
func (c *Component) AsOldNBT() nbt.Tag {
return nbt.Tag{
Name: "",
Value: c.ToNBT(),
}
}