--- /dev/null
+(import matchable
+ srfi-13
+ sam-macros)
+
+(define login-beh
+ (let ((accounts '()))
+ (make-beh
+ (login)
+ ((console) =>
+ (send-message console 'print "Welcome to the world!\n"
+ "\n"
+ "Enter your username or \"NEW\" to create a new account:")
+ (send-message console 'read
+ (make-actor-with-beh
+ (self)
+ (("NEW") =>
+ (send-message login console 'new-user)
+ 'done)
+ ((user) =>
+ (send-message login console 'user user)
+ 'done)))
+ 'sleep)
+ ((console 'user user) =>
+ (send-message console 'print "password: ")
+ (send-message console 'read
+ (make-actor-with-beh
+ (self)
+ ((pass) =>
+ (send-message login console 'user user 'pass pass)
+ 'done)))
+ 'sleep)
+ ((console 'user user 'pass pass) =>
+ (send-message console 'print "Logged in user " user " with password " pass)
+ 'sleep)
+ ((console 'new-user) =>
+ (send-message console 'print "What should I call your character?")
+ (send-message console 'read
+ (make-actor-with-beh
+ (self)
+ ((user) =>
+ (if (assoc user accounts)
+ (begin
+ (send-message console 'print
+ "A character with that name already exists.")
+ (send-message login console 'new-user))
+ (send-message login console 'new-user user))
+ 'done)))
+ 'sleep)
+ ((console 'new-user user) =>
+ (send-message console 'print "Please enter a good password/phrase:")
+ (send-message console 'read
+ (make-actor-with-beh
+ (self)
+ ((pass) =>
+ (send-message login console 'new-user user 'pass-confirm pass)
+ 'done)))
+ 'sleep)
+ ((console 'new-user user 'pass-confirm pass) =>
+ (send-message console 'print "Please confirm your password:")
+ (send-message console 'read
+ (make-actor-with-beh
+ (self)
+ ((pass-conf) =>
+ (if (equal? pass pass-conf)
+ (send-message login console 'new-user user 'pass pass)
+ (begin
+ (send-message console 'print "Passwords do not match. Try again.")
+ (send-message login console 'new-user user)))
+ 'done)))
+ 'sleep)
+ ((console 'new-user user 'pass pass) =>
+ (let ((player (make-actor (make-player-beh user))))
+ (set! accounts (cons (list user pass player)))
+ (send-message console 'print "New account created! Welcome!"))
+ 'sleep))))
+
+
+(define-beh main-beh (self)
+ ((system) =>
+ (send-message (make-actor login-beh) system)
+ 'done))
+