(client-input (wrap-apply gm-handle-client-input))
(lookup-special (wrap-apply gm-lookup-special))
(new-client (wrap-apply gm-new-client))
- (write-home (wrap-apply gm-write-home)))))
+ (write-home (wrap-apply gm-write-home))
+ (client-closed (wrap-apply gm-client-closed)))))
;;; .. begin world init stuff ..
#:client client-id
#:data text))
+(define-mhandler (gm-client-closed gm message client)
+ ;; Do we have this client registered to an actor? Get the id if so.
+ (define actor-id (hash-ref (gm-client-dir gm) client))
+
+ ;; Have the actor appropriately disappear / be removed from its
+ ;; room, if we have one.
+ ;; (In some games, if the user never connected)
+ (when actor-id
+ (<-wait gm actor-id 'disconnect-self-destruct)
+ ;; Unregister from the client directories.
+ (gm-unregister-client! gm client)))
+
;;; GM utilities
(hash-set! (gm-client-dir gm) client-id player)
(hash-set! (gm-reverse-client-dir gm) player client-id))
-(define (gm-unregister-client! gm client-id)
+(define* (gm-unregister-client! gm client-id #:optional destroy-player)
"Remove a connection/player combo and ask them to self destruct"
(match (hash-remove! (gm-client-dir gm) client-id) ; Remove from our client dir
((_ . player-id)
;; Remove from reverse table too
(hash-remove! (gm-reverse-client-dir gm) client-id)
;; Destroy player
- (<- gm player-id 'destroy-self))
+ (if destroy-player
+ (<- gm player-id 'self-destruct)))
(#f (throw 'no-client-to-unregister
"Can't unregister a client that doesn't exist?"
client-id))))
(define (make-default-room-conn-handler default-room)
"Make a handler for a GM that dumps people in a default room
with an anonymous persona"
- (display "right before breakage?\n")
(let ((count 0))
(lambda (gm client-id)
(set! count (+ count 1))
#:name guest-name
#:gm (actor-id gm)
#:client client-id)))
- (display "Are we broke yet?\n")
;; Register the player in our database of players -> connections
(gm-register-client! gm client-id player)
;; Dump the player into the default room