aboutsummaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authorLoic Guegan <manzerberdes@gmx.com>2019-05-10 08:51:16 +0200
committerLoic Guegan <manzerberdes@gmx.com>2019-05-10 08:51:16 +0200
commitb35687d51b56c2aafdb6ec5243c53d33b749a933 (patch)
tree4f7633ad62e07521d915368da9cc2acc9f6c8b86 /server
parent409897562cfb59a7181226fb3b60f216f9032e9e (diff)
Update API
Diffstat (limited to 'server')
-rw-r--r--server/api/api.lisp28
1 files changed, 5 insertions, 23 deletions
diff --git a/server/api/api.lisp b/server/api/api.lisp
index 3bd7e49..9174717 100644
--- a/server/api/api.lisp
+++ b/server/api/api.lisp
@@ -4,25 +4,7 @@
(defclass api ()
((gm
- :initform (make-instance 'game-manager))
- (games-syn
- :initform '())))
-
-
-(defmethod create-syn ((api api) game-id &optional (initial-value 0))
- (unless (eq nil (get-syn api game-id)) (error "This game ~a already have a syn !" game-id))
- (with-slots (games-syn) api
- (push (list :game-id game-id :syn initial-value) games-syn)
- initial-value))
-
-(defmethod refresh-syn ((api api) game-id)
- (with-slots (games-syn) api
- (incf (getf (first (remove-if-not #'(lambda (entry) (eql game-id (getf entry :game-id))) games-syn)) :syn))))
-
-(defmethod get-syn ((api api) game-id)
- (with-slots (games-syn) api
- (getf (first (remove-if-not #'(lambda (entry) (eql game-id (getf entry :game-id))) games-syn)) :syn)))
-
+ :initform (make-instance 'game-manager))))
;;; TODO: Handle errors (valid json etc..)
@@ -34,12 +16,11 @@
(defmethod handle-new-game ((api api) data)
(with-slots (gm) api
- (let* ((game-id (create-game gm))
- (game-syn (create-syn api game-id 1))) ; Create syn with 1 (since first packet already receive)
+ (let* ((game-id (create-game gm)))
(let ((game-dump (dump gm game-id)))
(setf (getf game-dump :game-over) :null) ; Define nil as null (for json)
(to-json
- (append (list :type "state" :syn game-syn) game-dump))))))
+ (append (list :type "state") game-dump))))))
;;; TODO: RETURN JSON !!!!
(defmethod handle-update ((api api) data)
@@ -55,7 +36,8 @@
(t (setf dir nil)))
(if dir
(refresh game :dir dir)
- (refresh game)))))
+ (refresh game))
+ (append (list :type "update") (dump gm game-id)))))