Yu-Gi-Oh! Deck Building and Card Inventory Management web interface written in Common Lisp, utilizing HTMX.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

113 lines
3.5KB

  1. ;;;; src/main.lisp
  2. ;;;;
  3. ;;;; Main App Definition And Entry Point
  4. ;;;;
  5. (in-package :cl-user)
  6. (defpackage #:cl-deck-builder2
  7. (:use #:cl
  8. #:cl-deck-builder2.db
  9. #:cl-deck-builder2.draw
  10. #:cl-deck-builder2.toolkit
  11. #:cl-deck-builder2.models
  12. ;;#:cl-deck-builder2-test
  13. )
  14. (:local-nicknames
  15. (#:v #:org.shirakumo.verbose))
  16. (:import-from :cl-deck-builder2.config
  17. :config
  18. :*app-log-file*)
  19. (:import-from :clack
  20. :clackup)
  21. (:export
  22. :start
  23. :stop
  24. :my/start
  25. :main)
  26. (:documentation "The main package for the deck builder project.
  27. This package exports the START and STOP functions, as well as the convenience function MY/START."))
  28. (in-package :cl-deck-builder2)
  29. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  30. (defvar *appfile-path*
  31. (asdf:system-relative-pathname :cl-deck-builder2 #P"app.lisp")
  32. "The application path we pass to CLACK:CLACKUP.")
  33. (defvar *clack-handler* nil
  34. "The CLACK handler currently running. NIL if there is no server running.")
  35. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  36. (defun start (&rest args &key server port debug &allow-other-keys)
  37. "Start the app. If the app is already running, raise an ERROR."
  38. (declare (ignore server port debug))
  39. (when *clack-handler*
  40. (restart-case (error "Server is already running.")
  41. (restart-server ()
  42. :report "Restart the server"
  43. (stop))))
  44. (v:info :main "CLACKUP")
  45. (setf *clack-handler* (apply #'clackup *appfile-path* args)))
  46. (defun stop ()
  47. "Stop the app, if it is running."
  48. (v:info :main "CLACK:STOP")
  49. (prog1
  50. (clack:stop *clack-handler*)
  51. (setf *clack-handler* nil)))
  52. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  53. (defun my/start (&rest args)
  54. "Convenience function for invoking RESTART-SERVER in the case that the server is already running."
  55. (handler-bind
  56. ((simple-error (lambda (c)
  57. (format t "~A~&Invoking RESTART-SERVER." c)
  58. (invoke-restart 'restart-server))))
  59. ;; TODO Multiple Addresses?
  60. ;; TODO Put it behind NGINX?
  61. ;; TODO sslh?
  62. (apply #'start args)))
  63. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  64. ;; Loader Customize
  65. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  66. (defmacro start-helper (service-name &body body)
  67. `(progn
  68. (v:info :app "~&Starting ~a ...~&" ,service-name)
  69. (if ,@body
  70. (v:info :app "~&... started.~&")
  71. (v:info :app "~&... failed?~&"))))
  72. ;; Initialize Logging
  73. ;;
  74. ;; (v:output-here *standard-output*)
  75. ;;
  76. (defun main ()
  77. (v:output-here (open *app-log-file* :direction :output
  78. :if-does-not-exist :create
  79. :if-exists :append))
  80. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  81. (v:start v:*global-controller*)
  82. (start-helper "slynk server"
  83. (apply #'slynk:create-server (config :slynk)))
  84. (v:info :app "~&Constructing database...~&")
  85. ;; (apply #'create-table *class-list*)
  86. (ensure-tables-exist)
  87. (v:info :app "~&...complete~%")
  88. (start-helper "web app"
  89. (apply #'my/start (config :server)))
  90. (start-helper "WebSocket Server Side Client"
  91. (handler-case
  92. (apply #'cl-deck-builder2.web::make-chat-client (config :websocket))
  93. (usocket:connection-refused-error () nil)
  94. (usocket:connection-reset-error () nil))))