allow for custom kick status message

This commit is contained in:
adman
2026-04-29 18:31:36 +02:00
parent 4878c6cc7b
commit 3d34ad59e9
2 changed files with 9 additions and 7 deletions
+7 -5
View File
@@ -17,7 +17,7 @@ var (
CantKickInStateErr = errors.New("cant kick in this state") CantKickInStateErr = errors.New("cant kick in this state")
) )
func Kick(c *proto.Conn, reason *text.Component) (err error) { func Kick(c *proto.Conn, reason *text.Component, status string) (err error) {
if c.Actor != proto_base.Servee { if c.Actor != proto_base.Servee {
err = NotClientErr err = NotClientErr
return return
@@ -26,10 +26,12 @@ func Kick(c *proto.Conn, reason *text.Component) (err error) {
case proto_base.Handshaking: case proto_base.Handshaking:
err = CantKickInStateErr err = CantKickInStateErr
case proto_base.Status: case proto_base.Status:
var b []byte var b = []byte(status)
b, err = reason.MarshalJSON() if status == "" {
if err != nil { b, err = reason.MarshalJSON()
return if err != nil {
return
}
} }
err = c.Send(&v1_21_8.StatusToClientPacketServerInfo{Response: fmt.Sprintf("{\"description\":%s}", string(b))}) err = c.Send(&v1_21_8.StatusToClientPacketServerInfo{Response: fmt.Sprintf("{\"description\":%s}", string(b))})
case proto_base.Login: case proto_base.Login:
+2 -2
View File
@@ -37,7 +37,7 @@ func ServeClient(cNet net.Conn, factory Factory) {
return return
} }
if err != nil { if err != nil {
err = Kick(c, text.Pretty(err.Error())) err = Kick(c, text.Pretty(err.Error()), "")
} }
} }
@@ -79,7 +79,7 @@ func StartServerWithOnConn(listenAddr string, onConn func(c *proto.Conn) (err er
running = false running = false
} }
if connErr != nil { if connErr != nil {
connErr = Kick(c, text.Pretty(connErr.Error())) connErr = Kick(c, text.Pretty(connErr.Error()), "")
} }
}() }()
} }