add PlaceShips message

This commit is contained in:
2026-10-27 17:31:41 +03:00
parent 31ef12b5f2
commit 6392c2ef03
7 changed files with 843 additions and 27 deletions
+14
View File
@@ -277,6 +277,20 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
h.log.Debug("invalid ACK seq", "match", match.ID, "user", uc.UserID, "seq", seq, "err", err)
continue
}
case protocol.OpPlaceShips:
ships, err := protocol.ParsePlaceShips(args)
if err != nil {
h.log.Debug("malformed PlaceShips", "match", match.ID, "user", uc.UserID, "err", err)
continue
}
if err := protocol.ValidateShips(ships); err != nil {
h.log.Debug("invalid ship placement", "match", match.ID, "user", uc.UserID, "err", err)
continue
}
if err := h.Manager.PlaceShips(ctx, match, slotIdx, ships); err != nil {
h.log.Debug("place ships rejected", "match", match.ID, "user", uc.UserID, "err", err)
continue
}
default:
// Unknown opcodes are ignored for forward compatibility.
h.log.Debug("unknown opcode", "match", match.ID, "user", uc.UserID, "opcode", opcode)