X-Git-Url: https://jxself.org/git/?p=mudsync.git;a=blobdiff_plain;f=mudsync%2Fgame-master.scm;h=05de6697c7db54c4c6221d0afc225caff1f2df78;hp=aab0b7a856820a1a6a18071b361d421b73518cc6;hb=dc6370a830b0f027db2e75e22b65a1a978e13f18;hpb=7248fd4470039dab59a8e3a95829952e91c0fd19 diff --git a/mudsync/game-master.scm b/mudsync/game-master.scm index aab0b7a..05de669 100644 --- a/mudsync/game-master.scm +++ b/mudsync/game-master.scm @@ -55,7 +55,8 @@ (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 .. @@ -155,6 +156,18 @@ #: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 @@ -162,14 +175,15 @@ (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)))) @@ -179,7 +193,6 @@ (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)) @@ -190,10 +203,9 @@ with an anonymous persona" ;; create and register the player (player (create-actor* gm (@@ (mudsync player) ) "player" - #:username guest-name + #: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