player and dimension loader with ecs system
This commit is contained in:
@ -2,17 +2,14 @@ package clientinfo
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/Tnze/go-mc/server/ecs"
|
||||
|
||||
"github.com/Tnze/go-mc/data/packetid"
|
||||
pk "github.com/Tnze/go-mc/net/packet"
|
||||
"github.com/Tnze/go-mc/server"
|
||||
)
|
||||
|
||||
type ClientInformation struct {
|
||||
Players map[uuid.UUID]*Info
|
||||
}
|
||||
type ClientInformation struct{}
|
||||
|
||||
type Info struct {
|
||||
Locale string
|
||||
@ -26,10 +23,25 @@ type Info struct {
|
||||
}
|
||||
|
||||
func (c *ClientInformation) Init(g *server.Game) {
|
||||
c.Players = make(map[uuid.UUID]*Info)
|
||||
infos := ecs.GetComponent[Info](g.World)
|
||||
type updateData struct {
|
||||
eid ecs.Index
|
||||
info Info
|
||||
}
|
||||
updateChan := make(chan updateData)
|
||||
g.Add(ecs.FuncSystem(func() {
|
||||
for {
|
||||
select {
|
||||
case info := <-updateChan:
|
||||
infos.SetValue(info.eid, info.info)
|
||||
default:
|
||||
return
|
||||
}
|
||||
}
|
||||
}), "ClientInfoSystem", nil)
|
||||
g.AddHandler(&server.PacketHandler{
|
||||
ID: packetid.ServerboundClientInformation,
|
||||
F: func(player *server.Player, p server.Packet758) error {
|
||||
F: func(client *server.Client, player *server.Player, p server.Packet758) error {
|
||||
var (
|
||||
Locale pk.String
|
||||
ViewDistance pk.Byte
|
||||
@ -53,21 +65,25 @@ func (c *ClientInformation) Init(g *server.Game) {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
c.Players[player.UUID] = &Info{
|
||||
Locale: string(Locale),
|
||||
ViewDistance: int(ViewDistance),
|
||||
ChatMode: byte(ChatMode),
|
||||
ChatColors: bool(ChatColors),
|
||||
DisplayedSkinParts: byte(DisplayedSkinParts),
|
||||
MainHand: byte(MainHand),
|
||||
EnableTextFiltering: bool(EnableTextFiltering),
|
||||
AllowServerListings: bool(AllowServerListings),
|
||||
|
||||
updateChan <- updateData{
|
||||
eid: client.Index,
|
||||
info: Info{
|
||||
Locale: string(Locale),
|
||||
ViewDistance: int(ViewDistance),
|
||||
ChatMode: byte(ChatMode),
|
||||
ChatColors: bool(ChatColors),
|
||||
DisplayedSkinParts: byte(DisplayedSkinParts),
|
||||
MainHand: byte(MainHand),
|
||||
EnableTextFiltering: bool(EnableTextFiltering),
|
||||
AllowServerListings: bool(AllowServerListings),
|
||||
},
|
||||
}
|
||||
return nil
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func (c *ClientInformation) Run(ctx context.Context) {}
|
||||
func (c *ClientInformation) AddPlayer(p *server.Player) {}
|
||||
func (c *ClientInformation) RemovePlayer(p *server.Player) {}
|
||||
func (c *ClientInformation) Run(ctx context.Context) {}
|
||||
func (c *ClientInformation) ClientJoin(p *server.Client) {}
|
||||
func (c *ClientInformation) ClientLeft(p *server.Client) {}
|
||||
|
Reference in New Issue
Block a user