Working on MUD login system.
authorTim Vaughan <plugd@thelambdalab.xyz>
Mon, 3 May 2021 19:28:12 +0000 (21:28 +0200)
committerTim Vaughan <plugd@thelambdalab.xyz>
Mon, 3 May 2021 19:28:12 +0000 (21:28 +0200)
world.scm [new file with mode: 0644]

diff --git a/world.scm b/world.scm
new file mode 100644 (file)
index 0000000..9dab1b1
--- /dev/null
+++ b/world.scm
@@ -0,0 +1,82 @@
+(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))
+