new server
All checks were successful
Create and publish a Docker image 🚀 / build-and-push-image (push) Successful in 1m19s

This commit is contained in:
Smile Rex
2026-01-17 16:38:45 +03:00
parent 1c60264d1d
commit 3c989c33f8
10 changed files with 156 additions and 85 deletions

View File

@@ -12,15 +12,16 @@ func (h *Hub) broadcastSnapshot() {
defer h.Mu.RUnlock()
w := models.Writer{}
w.WriteU16(uint16(len(h.Players)))
w.WriteU16(uint16(len(h.Entities)))
for _, p := range h.Players {
w.WriteU32(p.ID)
w.WriteU8(uint8(models.EntityPlayer))
w.WriteF32(p.X)
w.WriteF32(p.Y)
w.WriteF32(p.Z)
w.WriteF32(p.Yaw)
for _, e := range h.Entities {
w.WriteU32(e.GetID())
w.WriteU8(uint8(e.GetType()))
x, y, z := e.GetPosition()
w.WriteF32(x)
w.WriteF32(y)
w.WriteF32(z)
w.WriteF32(e.GetYaw())
}
msg := models.Message{
@@ -29,9 +30,9 @@ func (h *Hub) broadcastSnapshot() {
Payload: w.Bytes(),
}
for _, p := range h.Players {
if p.Conn != nil {
_ = p.Conn.WriteMessage(websocket.BinaryMessage, msg.Encode())
for _, conn := range h.Clients {
if conn != nil {
_ = conn.WriteMessage(websocket.BinaryMessage, msg.Encode())
}
}
}