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")
|
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,11 +26,13 @@ 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)
|
||||||
|
if status == "" {
|
||||||
b, err = reason.MarshalJSON()
|
b, err = reason.MarshalJSON()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
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:
|
||||||
var b []byte
|
var b []byte
|
||||||
|
|||||||
+2
-2
@@ -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()), "")
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user