Skip to content
Permalink
Browse files

Add ping command

  • Loading branch information
borodust committed Apr 18, 2017
1 parent d64ff70 commit 232f276db6dadd8ed53ac9ee8971d22410192455
Showing with 30 additions and 18 deletions.
  1. +22 −11 client/src/connector.lisp
  2. +3 −2 common/packages.lisp
  3. +4 −0 common/process-command.lisp
  4. +1 −1 mortar-combat.asd
  5. +0 −4 proxy/commands.lisp
@@ -28,14 +28,16 @@
(loop while enabled-p
do (log-errors
(usocket:wait-for-input connection)
(let* ((message (decode-message (connection-stream-of this)))
(message-id (getf message :reply-for)))
(with-instance-lock-held (this)
(if-let ((handler (gethash message-id message-table)))
(progn
(remhash message-id message-table)
(funcall handler message))
(log:error "Handler not found for message with id ~A" message-id)))))
(let ((message (decode-message (connection-stream-of this))))
(if-let ((reply-id (getf message :reply-for)))
(with-instance-lock-held (this)
(if-let ((handler (gethash reply-id message-table)))
(progn
(remhash reply-id message-table)
(funcall handler message))
(log:error "Handler not found for message with id ~A" reply-id)))
(encode-message (process-command (getf message :command) message)
(connection-stream-of this)))))
finally (usocket:socket-close connection)))))


@@ -67,9 +69,9 @@


(defmacro with-response (command-name (&rest properties) response &body body)
`(destructuring-bind (&key ,@properties &allow-other-keys) ,response
(check-response ,response ,command-name)
,@body))
`(destructuring-bind (&key ,@properties &allow-other-keys) ,response
(check-response ,response ,command-name)
,@body))


(defmethod dispatch ((this connector) (task function) invariant &rest keys
@@ -115,3 +117,12 @@
(defun register-game-stream (connector peer-id)
(-> (connector :command :register-game-stream :peer-id peer-id) ()
(with-response :ok () *message*)))


(defun ping-peer (connector)
(-> (connector :command :ping) ()
(with-response :ok () *message*)))


(defmethod process-command ((command (eql :ping)) message)
+ok-reply+)
@@ -2,7 +2,8 @@


(defpackage :mortar-combat.common
(:use :cl :ge.ng :ge.util)
(:export process-command
(:use :cl :ge.util)
(:export +ok-reply+
process-command
encode-message
decode-message))
@@ -1,6 +1,10 @@
(in-package :mortar-combat.common)


(define-constant +ok-reply+ (list :command :ok)
:test #'equal)


(defgeneric process-command (command message)
(:method (command message)
(list :command :error
@@ -9,7 +9,7 @@
:author "Pavel Korolev"
:mailto "dev@borodust.org"
:license "GPLv3"
:depends-on (cl-conspack)
:depends-on (cl-bodge/utils cl-conspack)
:serial t
:pathname "common/"
:components ((:file "packages")
@@ -1,10 +1,6 @@
(in-package :mortar-combat.proxy)


(define-constant +ok-reply+ (list :command :ok)
:test #'equal)


(defmacro when-peer-identified (&body body)
`(if *peer*
(progn ,@body)

0 comments on commit 232f276

Please sign in to comment.
You can’t perform that action at this time.