Refactor server modules into main package and improve error handling
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"github.com/admin-else/strom/proto_base"
|
||||
)
|
||||
|
||||
// Connect connects to the given address note that it does not resolve the SRV records its just a raw net.Dial
|
||||
func Connect(addr string) (ret *proto.Conn, err error) {
|
||||
ret = &proto.Conn{}
|
||||
err = ret.SetVersion("1.21.8")
|
||||
|
||||
@@ -3,6 +3,7 @@ package modules
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
|
||||
"github.com/admin-else/strom/event"
|
||||
"github.com/admin-else/strom/proto"
|
||||
@@ -14,8 +15,8 @@ type ConfigIgnorer struct {
|
||||
*proto.Conn
|
||||
}
|
||||
|
||||
func (c *ConfigIgnorer) Default(event any) (err error) {
|
||||
fmt.Printf("%#v\n", event)
|
||||
func (c *ConfigIgnorer) Default(event event.Anything) (err error) {
|
||||
slog.Debug("Config ignorer", "packet", fmt.Sprintf("%#v", event))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -23,7 +24,7 @@ func (c *ConfigIgnorer) OnKnownPacks(packet *v1_21_8.ConfigurationToClientPacket
|
||||
return c.Send(&v1_21_8.ConfigurationToServerPacketCommonSelectKnownPacks{Packs: packet.Packs})
|
||||
}
|
||||
|
||||
func (c *ConfigIgnorer) OnFinish(_ v1_21_8.ConfigurationToClientPacketFinishConfiguration) (err error) {
|
||||
func (c *ConfigIgnorer) OnFinish(_ *v1_21_8.ConfigurationToClientPacketFinishConfiguration) (err error) {
|
||||
err = c.Send(&v1_21_8.ConfigurationToServerPacketFinishConfiguration{})
|
||||
if err != nil {
|
||||
return
|
||||
|
||||
@@ -25,7 +25,7 @@ func (s *StatusClient) Default(event any) (err error) {
|
||||
|
||||
func (s *StatusClient) OnStart(_ event.OnStart) (err error) {
|
||||
parts := strings.Split(s.RemoteAddr().String(), ":")
|
||||
versionData, err := data.LookUpProtocolVersionByName(s.Version)
|
||||
versionData, err := data.LookUpVersionByName(s.Version)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@@ -34,7 +34,7 @@ func (s *StatusClient) OnStart(_ event.OnStart) (err error) {
|
||||
return
|
||||
}
|
||||
err = s.Send(&v1_21_8.HandshakingToServerPacketSetProtocol{
|
||||
ProtocolVersion: int32(versionData.Version),
|
||||
ProtocolVersion: versionData.Version,
|
||||
ServerHost: parts[0],
|
||||
ServerPort: uint16(port),
|
||||
NextState: int32(proto_base.Status),
|
||||
|
||||
Reference in New Issue
Block a user