Skip to content

Commit 013dfc4

Browse files
committed
Allow syncing player animation state
Related to ynoproject/ynoengine#81
1 parent 53388b2 commit 013dfc4

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

server/handlers.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,29 @@ func (c *RoomClient) handleSev(msg []string) error {
809809
return nil
810810
}
811811

812+
const (
813+
animStart = iota
814+
animStop
815+
)
816+
817+
func (c *RoomClient) handleAnc(msg []string) error {
818+
if len(msg) != 2 {
819+
return errors.New("segment count mismatch")
820+
}
821+
822+
cmd, err := strconv.Atoi(msg[1])
823+
if err != nil {
824+
return err
825+
}
826+
if cmd > animStop || cmd < animStart {
827+
return errors.New("invalid command")
828+
}
829+
830+
c.broadcast(buildMsg("anc", cmd))
831+
832+
return nil
833+
}
834+
812835
// SESSION
813836

814837
func (c *SessionClient) handleI() error {

server/room.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,8 @@ func (c *RoomClient) processMsg(msgStr string) (err error) {
295295
err = c.handleSv(msgFields)
296296
case "sev":
297297
err = c.handleSev(msgFields)
298+
case "anc":
299+
err = c.handleAnc(msgFields)
298300
default:
299301
err = errors.New("unknown message type")
300302
}

0 commit comments

Comments
 (0)