X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;ds=inline;f=mudsync%2Fgame-master.scm;h=34476b0077a892aaa553813e73df8d30f6676d3c;hb=af6f936a671c835bc6d9aadc59fd8ff5969fe1ad;hp=bb8756a5e2ca96563d0d594760d1051e0691b5bc;hpb=d13325f5f6eba20c808636948432dcdff4e138f6;p=mudsync.git
diff --git a/mudsync/game-master.scm b/mudsync/game-master.scm
index bb8756a..34476b0 100644
--- a/mudsync/game-master.scm
+++ b/mudsync/game-master.scm
@@ -17,8 +17,6 @@
;;; along with Mudsync. If not, see .
(define-module (mudsync game-master)
- #:use-module (mudsync room)
- #:use-module (mudsync player)
#:use-module (mudsync networking)
#:use-module (8sync systems actors)
#:use-module (8sync agenda)
@@ -35,10 +33,6 @@
(special-dir #:init-thunk make-hash-table
#:getter gm-special-dir)
- ;; Room directory. Room symbols to locations.
- (room-dir #:init-thunk make-hash-table
- #:getter gm-room-dir)
-
;; A mapping of client ids to in-game actors
;; and a reverse ;p
(client-dir #:init-thunk make-hash-table
@@ -47,11 +41,11 @@
#:getter gm-reverse-client-dir)
;; Network manager
- (network-manager #:accessor gm-network-manager
+ (network-manager #:getter gm-network-manager
#:init-value #f)
;; How we get a new connection acclimated to the system
- (new-conn-handler #:accessor gm-new-conn-handler
+ (new-conn-handler #:getter gm-new-conn-handler
#:init-keyword #:new-conn-handler)
(message-handler
@@ -59,7 +53,7 @@
(make-action-dispatch
(init-world (wrap-apply gm-init-world))
(client-input (wrap-apply gm-handle-client-input))
- (lookup-room (wrap-apply gm-lookup-room))
+ (lookup-special (wrap-apply gm-lookup-special))
(new-client (wrap-apply gm-new-client))
(write-home (wrap-apply gm-write-home)))))
@@ -71,7 +65,7 @@
;; TODO
;; Init basic rooms / structure
- (gm-init-rooms gm (message-ref message 'room-spec))
+ (gm-init-game-spec gm (message-ref message 'game-spec))
;; Restore database-based actors
;; TODO
@@ -79,49 +73,49 @@
;; Set up the network
(gm-setup-network gm))
-(define (gm-init-rooms gm rooms-spec)
- "Initialize the prebuilt rooms"
- ;; @@: Would it be nicer to just allow passing in
- ;; #:exits to the room spec itself?
- (define (exit-from-spec exit-spec)
- "Take room exits syntax from the spec, turn it into exits"
- (match exit-spec
- ((name to-symbol desc)
- (make
- #:name name
- #:to-symbol to-symbol
- #:desc desc))))
-
- (define rooms
+(define (gm-init-game-spec gm game-spec)
+ "Initialize the prebuilt special objects"
+ (define set-locs '())
+ (define specials
(map
(match-lambda
- ((room-symbol room-class
- room-args ...
- (room-exits ...))
- ;; initialize the room
- (let ((room
- (apply create-actor* gm room-class "room"
+ ((symbol class loc args ...)
+ ;; initialize the special object
+ (let ((special-obj
+ (apply create-actor* gm class
+ ;; set cookie to be the object's symbol
+ (symbol->string symbol)
#:gm (actor-id gm)
- #:exits (map exit-from-spec room-exits)
- room-args)))
- ;; register the room
- (hash-set! (gm-room-dir gm) room-symbol room)
+ args)))
+ ;; register the object
+ (hash-set! (gm-special-dir gm) symbol special-obj)
+ ;; Give ourselves an instruction to set the location
+ (set! set-locs (cons (cons special-obj loc) set-locs))
;; pass it back to the map
- room)))
- rooms-spec))
+ special-obj)))
+ game-spec))
- ;; now wire up all the exits
+ ;; Set all initial locations
+ (for-each
+ (match-lambda
+ ((special-obj . loc)
+ (if loc
+ (<-wait gm special-obj 'set-loc!
+ #:loc (hash-ref (gm-special-dir gm) loc)))))
+ set-locs)
+
+ ;; now init all the objects
(for-each
- (lambda (room)
- (format #t "Wiring up ~s...\n" (address->string room))
- (<-wait gm room 'wire-exits!))
- rooms))
+ (lambda (special-obj)
+ (format #t "Initializing ~s...\n" (address->string special-obj))
+ (<-wait gm special-obj 'init))
+ specials))
(define (gm-setup-network gm)
;; Create a default network manager if none available
- (set! (gm-network-manager gm)
- (create-actor* gm "netman"
+ (slot-set! gm 'network-manager
+ (create-actor* gm "netman"
#:send-input-to (actor-id gm)))
;; TODO: Add host and port options
@@ -141,15 +135,18 @@
"Handle input from a client."
(define client-id (message-ref message 'client))
(define input (message-ref message 'data))
- (format #t "From ~s: ~s\n" client-id input)
- (<- actor (gm-network-manager actor) 'send-to-client
- #:client client-id
- #:data "Thanks, we got it!\n"))
+ ;; Look up player
+ (define player (hash-ref (gm-client-dir actor) client-id))
+
+ ;; debugging
+ (format #t "DEBUG: From ~s: ~s\n" client-id input)
+
+ (<- actor player 'handle-input
+ #:input input))
-(define-mhandler (gm-lookup-room actor message symbol)
- (define room-id
- (slot-ref (gm-room-dir actor) symbol))
- (<-reply actor message room-id))
+(define-mhandler (gm-lookup-special actor message symbol)
+ (<-reply actor message
+ #:room-id (hash-ref (slot-ref actor 'special-dir) symbol)))
(define-mhandler (gm-write-home actor message text)
(define client-id (hash-ref (gm-reverse-client-dir actor)
@@ -182,23 +179,25 @@
(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)
- (define guest-name (string-append "Guest-"
+ (set! count (+ count 1))
+ (let* ((guest-name (string-append "Guest-"
(number->string count)))
- (define room-id
- (hash-ref (gm-room-dir gm) default-room))
- ;; create and register the player
- (define player
- (create-actor* gm "player"
- #:username guest-name
- #:gm (actor-id gm)
- #:client client-id))
-
- ;; Register the player in our database of players -> connections
- (gm-register-client! gm client-id player)
- ;; Dump the player into the default room
- (<-wait gm player 'set-loc! #:id room-id)
- ;; Initialize the player
- (<- gm player 'init))))
+ (room-id
+ (hash-ref (gm-special-dir gm) default-room))
+ ;; create and register the player
+ (player
+ (create-actor* gm (@@ (mudsync player) ) "player"
+ #: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
+ (<-wait gm player 'set-loc! #:loc room-id)
+ ;; Initialize the player
+ (<- gm player 'init)))))