Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

19. Creating a Graphical, Web-Based Vers... > Building the Web Server Interface

Building the Web Server Interface

Now that we’ve completed the graphical side of Dice of Doom version 3, we’re ready to write the side that interfaces with the web server.

Writing Our Web Request Handler

The central function for our web server handling is called dod-request-handler. It is the function that we can pass to the serve command in our web server library, and it is responsible for handling all the web requests coming from the web browser. Here is the code for dod-request-handler:

(defparameter *cur-game-tree* nil)
  (defparameter *from-tile* nil)

  (defun dod-request-handler (path header params)
   (if (equal path "game.html")
       (progn (princ "<!doctype html>")
              (tag center ()
                    (princ "Welcome to DICE OF DOOM!")
                    (tag br ())
                   (let ((chosen (assoc 'chosen params)))
                     (when (or (not *cur-game-tree*) (not chosen))
                        (setf chosen nil)
                       (web-initialize))
                      (cond ((lazy-null (caddr *cur-game-tree*))
                              (web-announce-winner (cadr *cur-game-tree*)))
                            ((zerop (car *cur-game-tree*))
                              (web-handle-human
                                  (when chosen
                                        (read-from-string (cdr chosen)))))
                           (t (web-handle-computer))))
                    (tag br ())
                   (draw-dod-page *cur-game-tree* *from-tile*)))
      (princ "Sorry... I don't know that page.")))

  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint