support kicker status

This commit is contained in:
adman
2026-04-17 21:51:47 +02:00
parent acc583f694
commit 7a2081f0a0
2 changed files with 13 additions and 15 deletions
+10 -1
View File
@@ -8,6 +8,8 @@ import (
"github.com/admin-else/strom/proto_base"
"github.com/admin-else/strom/proto_generated/v1_21_8"
"github.com/admin-else/strom/text"
"fmt"
)
var (
@@ -21,8 +23,15 @@ func Kick(c *proto.Conn, reason *text.Component) (err error) {
return
}
switch c.State() {
case proto_base.Handshaking, proto_base.Status:
case proto_base.Handshaking:
err = CantKickInStateErr
case proto_base.Status:
var b []byte
b, err = reason.MarshalJSON()
if err != nil {
return
}
err = c.Send(&v1_21_8.StatusToClientPacketServerInfo{Response: fmt.Sprintf("{\"description\":%s}", string(b))})
case proto_base.Login:
var b []byte
b, err = reason.MarshalJSON()
+3 -14
View File
@@ -37,11 +37,7 @@ func ServeClient(cNet net.Conn, factory Factory) {
return
}
if err != nil {
c.Log.Error("Error while handling client", "error", err, "client", c.Conn.RemoteAddr())
err = Kick(c, text.Pretty(err.Error()))
if err != nil {
c.Log.Error("Error while kicking client", "error", err, "client", c.Conn.RemoteAddr())
}
}
}
@@ -79,19 +75,12 @@ func StartServerWithOnConn(listenAddr string, onConn func(c *proto.Conn) (err er
c := Servee(cNet)
defer c.Close()
connErr := onConn(c)
if connErr != nil {
if c.State() == proto_base.Status || c.State() == proto_base.Handshaking {
return // we dont care about status packets
}
c.Log.Error("Error while handling client", "error", connErr, "client", c.Conn.RemoteAddr())
connErr = Kick(c, text.Pretty(connErr.Error()))
if connErr != nil {
c.Log.Error("Error while kicking client", "error", connErr, "client", c.Conn.RemoteAddr())
}
}
if errors.Is(connErr, ShutDownServerErr) {
running = false
}
if connErr != nil {
connErr = Kick(c, text.Pretty(connErr.Error()))
}
}()
}
err = ShutDownServerErr