allow for custom kick status message
This commit is contained in:
+4
-2
@@ -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,11 +26,13 @@ func Kick(c *proto.Conn, reason *text.Component) (err error) {
|
||||
case proto_base.Handshaking:
|
||||
err = CantKickInStateErr
|
||||
case proto_base.Status:
|
||||
var b []byte
|
||||
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:
|
||||
var b []byte
|
||||
|
||||
+2
-2
@@ -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()), "")
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user