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")
)
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 {
err = NotClientErr
return
@@ -26,10 +26,12 @@ func Kick(c *proto.Conn, reason *text.Component) (err error) {
case proto_base.Handshaking:
err = CantKickInStateErr
case proto_base.Status:
var b []byte
b, err = reason.MarshalJSON()
if err != nil {
return
var b = []byte(status)
if status == "" {
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:
+2 -2
View File
@@ -37,7 +37,7 @@ func ServeClient(cNet net.Conn, factory Factory) {
return
}
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
}
if connErr != nil {
connErr = Kick(c, text.Pretty(connErr.Error()))
connErr = Kick(c, text.Pretty(connErr.Error()), "")
}
}()
}