Add admin interface

This commit is contained in:
Loic Guegan 2019-05-12 14:01:05 +02:00
parent 8cba94e081
commit 8e31de0793
4 changed files with 34 additions and 3 deletions

View file

@ -33,6 +33,7 @@
((equal dir "down") (setf (getf p-request :direction) :down))
((equal dir "left") (setf (getf p-request :direction) :left))
((equal dir "right") (setf (getf p-request :direction) :right))))))
((equal type "admin"))
((not (equal type "new-game"))
(error 'bad-request :msg "Unknown request type")))
p-request)))
@ -59,6 +60,16 @@
(to-json
(append (list :type "state") (dump gm game-id)))))))
;;; TODO: debug this function
(defmethod handle-admin ((api api) data)
(with-slots (gm) api
(let* ((game-id (getf data :game-id))
(cmd (getf data :cmd))
(arg (getf data :arg))
(game (get-game gm game-id)))
(cond
((equal cmd "move") (admin game :move arg)))))
"Command executed!")
(defmethod handle-request ((api api) request)
;; Catch request error and send it to the client
@ -68,6 +79,7 @@
(cond
((equal type "new-game") (handle-new-game api data))
((equal type "update") (handle-update api data))
((equal type "admin") (handle-admin api data))
(t (format t "Unknow type"))))
(error (condition) ; Send reason to the client
(let ((reason (make-array 0