mc root source folder cleanup

This commit is contained in:
adman
2026-06-27 13:54:54 +02:00
parent b2784574bd
commit 666f250b3e
480 changed files with 325 additions and 325 deletions
+51
View File
@@ -0,0 +1,51 @@
package server
import (
"errors"
"fmt"
"github.com/admin-else/strom/mc/nbt"
"github.com/admin-else/strom/mc/proto"
"github.com/admin-else/strom/mc/proto_base"
"github.com/admin-else/strom/mc/proto_generated/v1_21_8"
"github.com/admin-else/strom/mc/text"
)
var (
NotClientErr = errors.New("not a servee")
CantKickInStateErr = errors.New("cant kick in this state")
)
func Kick(c *proto.Conn, reason *text.Component, status string) (err error) {
if c.Actor != proto_base.Servee {
err = NotClientErr
return
}
switch c.State() {
case proto_base.Handshaking:
err = CantKickInStateErr
case proto_base.Status:
if status == "" {
var b []byte
b, err = reason.MarshalJSON()
if err != nil {
return
}
status = fmt.Sprintf("{\"description\":%s}", string(b))
}
err = c.Send(&v1_21_8.StatusToClientPacketServerInfo{Response: status})
case proto_base.Login:
var b []byte
b, err = reason.MarshalJSON()
if err != nil {
return
}
err = c.Send(&v1_21_8.LoginToClientPacketDisconnect{Reason: string(b)})
case proto_base.Configuration:
err = c.Send(&v1_21_8.ConfigurationToClientPacketDisconnect{Reason: nbt.Anon{Value: reason.ToNBT()}})
case proto_base.Play:
err = c.Send(&v1_21_8.PlayToClientPacketKickDisconnect{Reason: nbt.Anon{Value: reason.ToNBT()}})
}
return
}