diff --git a/naledi.lisp b/naledi.lisp index 872e192..942ef18 100644 --- a/naledi.lisp +++ b/naledi.lisp @@ -18,7 +18,7 @@ :input-echoing nil :cursor-visibility nil :input-reading :unbuffered) (splash-screen scr) - (choose-local-or-remote scr) + (start-or-connect-to-server scr) (user-interface scr))) (defun splash-screen (scr) @@ -40,7 +40,7 @@ ((nil) nil) (otherwise (return-from croatoan:event-case))))) -(defun choose-local-or-remote (scr) +(defun start-or-connect-to-server (scr) "Choose whether to start a local game or connect to a remote server" (croatoan:clear scr) (croatoan:refresh scr) @@ -66,51 +66,27 @@ (croatoan:draw-menu mw)) (#\newline (cond ((equalp (croatoan:current-item mw) "Start a local game") + ;;TODO choose world size (start-server) - (sleep 0.5) ;;give the server time to start + (setf *host* (first *defaulthost*) + *port* (second *defaulthost*)) + ;;TODO check whether server is up! + (sleep 1) ;;give the server time to start (connect-server)) ((equalp (croatoan:current-item mw) "Connect to a remote server") - (connect-server (enter-server-address scr)))) - (return-from croatoan:event-case))))) + (setf *host* (query-user scr "Server IP/URL:" T)) + (setf *port* (read-from-string + (query-user scr "Server port:" T))) + (if (user-confirm-p scr + (format nil "Connect to ~A:~S?" *host* *port*) + T) + (connect-server) + (start-or-connect-to-server scr))) + (return-from croatoan:event-case)))))) ;;TODO (choose-world-size) -(defun enter-server-address (scr) - "Enter the IP and port of the server to connect to" - ;;TODO rewrite this with individual, successive forms? - (croatoan:clear scr) - (croatoan:refresh scr) - (let* ((x0 (- (halve (croatoan:.width scr)) 25)) - (y0 (- (halve (croatoan:.height scr)) 5)) - (ip-field (make-instance 'croatoan:field :width 20 - :position '(4 8))) - (port-field (make-instance 'croatoan:field :width 20 - :position '(5 10))) - (form (make-instance 'croatoan:form - :fields (list ip-field port-field))) - (inputwin (make-instance 'croatoan:window :position (list y0 x0) - :width 50 :height 10))) - (setf (croatoan:.visible inputwin) t) - (croatoan:add-string inputwin - "Enter the servers IP address and port." :y 2 :x 4) - (croatoan:add-string inputwin "IP:" :y 4 :x 4) - (croatoan:add-string inputwin "Port:" :y 5 :x 4) - (croatoan:add-string inputwin - "(Jump with Tab, confirm with control-A)" :y 7 :x 4) - (setf (croatoan:.buffer ip-field) - (reverse (to-list "127.0.0.1"))) - (setf (croatoan:.buffer port-field) - (reverse (to-list (to-string *port*)))) - (croatoan:box inputwin) - (croatoan:edit inputwin form) - (croatoan:move inputwin 5 8) - (croatoan:refresh inputwin) - ;;FIXME The keymap doesn't work and throws an error - (setf (croatoan:.event-handlers scr) - (croatoan:get-keymap :form-default-keymap)))) - - (defun user-interface (scr) "Create the screen on the ncurses interface and hand over to window functions" (let* ((width (croatoan:.width scr)) (height (1- (croatoan:.height scr))) @@ -247,6 +223,64 @@ :message-text "Press b to go back."))) ;;:event-handlers '((#\b #'exit-event-loop))))) +(defun query-user (scr msg &optional (cls NIL) (val-width 30)) + "Display a popup asking the user to enter a value, then return that value" + ;;XXX I found `field/form' to complicated to use (:form-default-keymap + ;; doesn't seem to work), so I hacked up my own alternative + (when cls (croatoan:clear scr)) + (croatoan:refresh scr) + (let* ((x0 (- (halve (croatoan:.width scr)) (+ 5 (halve val-width)))) + (y0 (- (halve (croatoan:.height scr)) 3)) + (inputwin (make-instance 'croatoan:window :position (list y0 x0) + :width (+ 10 val-width) :height 6))) + (setf (croatoan:.visible inputwin) t) + (croatoan:box inputwin) + (croatoan:add-string inputwin msg :y 2 :x 4) + (croatoan:add-string inputwin ">>> " :y 3 :x 4) + (croatoan:move inputwin 3 8) + (croatoan:refresh inputwin) + (croatoan:event-case (scr event) + ((nil) nil) + (:backspace + (when (< 8 (croatoan:.cursor-position-x inputwin)) + (croatoan:move inputwin 0 -1 :relative t) + (croatoan:add-char inputwin #\space) + (croatoan:move inputwin 0 -1 :relative t) + (croatoan:refresh inputwin))) + (#\newline + (return-from croatoan:event-case + (trim-whitespace + (croatoan:extract-string inputwin + :y 3 :x 8 :n val-width)))) + (otherwise + (when (and (characterp event) + (> (+ 8 val-width) + (croatoan:.cursor-position-x inputwin))) + (croatoan:add-char inputwin event + :color-pair '(:blue :black)) + (croatoan:refresh inputwin)))))) + +(defun user-confirm-p (scr msg &optional (cls NIL)) + "Ask the user to confirm (Yes/No) a message." + (when cls (croatoan:clear scr)) + (croatoan:refresh scr) + (let ((dw (make-instance 'croatoan:dialog-window + :center t :border t :width (max 20 (+ 4 (length msg))) + :max-item-length (max 4 (halve (length msg))) + :input-blocking t :layout '(1 2) + :message-height 1 :message-text msg + :items '(" Yes" " No")))) + (croatoan:draw-menu dw) + (croatoan:event-case (scr event) + ((nil) nil) + ((:left :right) + (croatoan:update-menu dw event) + (croatoan:draw-menu dw)) + (#\newline + (return-from croatoan:event-case + (equalp (croatoan:current-item dw) " Yes")))))) + + (defun process-command (event) ;;TODO ) diff --git a/naledi.lisp b/naledi.lisp index 872e192..942ef18 100644 --- a/naledi.lisp +++ b/naledi.lisp @@ -18,7 +18,7 @@ :input-echoing nil :cursor-visibility nil :input-reading :unbuffered) (splash-screen scr) - (choose-local-or-remote scr) + (start-or-connect-to-server scr) (user-interface scr))) (defun splash-screen (scr) @@ -40,7 +40,7 @@ ((nil) nil) (otherwise (return-from croatoan:event-case))))) -(defun choose-local-or-remote (scr) +(defun start-or-connect-to-server (scr) "Choose whether to start a local game or connect to a remote server" (croatoan:clear scr) (croatoan:refresh scr) @@ -66,51 +66,27 @@ (croatoan:draw-menu mw)) (#\newline (cond ((equalp (croatoan:current-item mw) "Start a local game") + ;;TODO choose world size (start-server) - (sleep 0.5) ;;give the server time to start + (setf *host* (first *defaulthost*) + *port* (second *defaulthost*)) + ;;TODO check whether server is up! + (sleep 1) ;;give the server time to start (connect-server)) ((equalp (croatoan:current-item mw) "Connect to a remote server") - (connect-server (enter-server-address scr)))) - (return-from croatoan:event-case))))) + (setf *host* (query-user scr "Server IP/URL:" T)) + (setf *port* (read-from-string + (query-user scr "Server port:" T))) + (if (user-confirm-p scr + (format nil "Connect to ~A:~S?" *host* *port*) + T) + (connect-server) + (start-or-connect-to-server scr))) + (return-from croatoan:event-case)))))) ;;TODO (choose-world-size) -(defun enter-server-address (scr) - "Enter the IP and port of the server to connect to" - ;;TODO rewrite this with individual, successive forms? - (croatoan:clear scr) - (croatoan:refresh scr) - (let* ((x0 (- (halve (croatoan:.width scr)) 25)) - (y0 (- (halve (croatoan:.height scr)) 5)) - (ip-field (make-instance 'croatoan:field :width 20 - :position '(4 8))) - (port-field (make-instance 'croatoan:field :width 20 - :position '(5 10))) - (form (make-instance 'croatoan:form - :fields (list ip-field port-field))) - (inputwin (make-instance 'croatoan:window :position (list y0 x0) - :width 50 :height 10))) - (setf (croatoan:.visible inputwin) t) - (croatoan:add-string inputwin - "Enter the servers IP address and port." :y 2 :x 4) - (croatoan:add-string inputwin "IP:" :y 4 :x 4) - (croatoan:add-string inputwin "Port:" :y 5 :x 4) - (croatoan:add-string inputwin - "(Jump with Tab, confirm with control-A)" :y 7 :x 4) - (setf (croatoan:.buffer ip-field) - (reverse (to-list "127.0.0.1"))) - (setf (croatoan:.buffer port-field) - (reverse (to-list (to-string *port*)))) - (croatoan:box inputwin) - (croatoan:edit inputwin form) - (croatoan:move inputwin 5 8) - (croatoan:refresh inputwin) - ;;FIXME The keymap doesn't work and throws an error - (setf (croatoan:.event-handlers scr) - (croatoan:get-keymap :form-default-keymap)))) - - (defun user-interface (scr) "Create the screen on the ncurses interface and hand over to window functions" (let* ((width (croatoan:.width scr)) (height (1- (croatoan:.height scr))) @@ -247,6 +223,64 @@ :message-text "Press b to go back."))) ;;:event-handlers '((#\b #'exit-event-loop))))) +(defun query-user (scr msg &optional (cls NIL) (val-width 30)) + "Display a popup asking the user to enter a value, then return that value" + ;;XXX I found `field/form' to complicated to use (:form-default-keymap + ;; doesn't seem to work), so I hacked up my own alternative + (when cls (croatoan:clear scr)) + (croatoan:refresh scr) + (let* ((x0 (- (halve (croatoan:.width scr)) (+ 5 (halve val-width)))) + (y0 (- (halve (croatoan:.height scr)) 3)) + (inputwin (make-instance 'croatoan:window :position (list y0 x0) + :width (+ 10 val-width) :height 6))) + (setf (croatoan:.visible inputwin) t) + (croatoan:box inputwin) + (croatoan:add-string inputwin msg :y 2 :x 4) + (croatoan:add-string inputwin ">>> " :y 3 :x 4) + (croatoan:move inputwin 3 8) + (croatoan:refresh inputwin) + (croatoan:event-case (scr event) + ((nil) nil) + (:backspace + (when (< 8 (croatoan:.cursor-position-x inputwin)) + (croatoan:move inputwin 0 -1 :relative t) + (croatoan:add-char inputwin #\space) + (croatoan:move inputwin 0 -1 :relative t) + (croatoan:refresh inputwin))) + (#\newline + (return-from croatoan:event-case + (trim-whitespace + (croatoan:extract-string inputwin + :y 3 :x 8 :n val-width)))) + (otherwise + (when (and (characterp event) + (> (+ 8 val-width) + (croatoan:.cursor-position-x inputwin))) + (croatoan:add-char inputwin event + :color-pair '(:blue :black)) + (croatoan:refresh inputwin)))))) + +(defun user-confirm-p (scr msg &optional (cls NIL)) + "Ask the user to confirm (Yes/No) a message." + (when cls (croatoan:clear scr)) + (croatoan:refresh scr) + (let ((dw (make-instance 'croatoan:dialog-window + :center t :border t :width (max 20 (+ 4 (length msg))) + :max-item-length (max 4 (halve (length msg))) + :input-blocking t :layout '(1 2) + :message-height 1 :message-text msg + :items '(" Yes" " No")))) + (croatoan:draw-menu dw) + (croatoan:event-case (scr event) + ((nil) nil) + ((:left :right) + (croatoan:update-menu dw event) + (croatoan:draw-menu dw)) + (#\newline + (return-from croatoan:event-case + (equalp (croatoan:current-item dw) " Yes")))))) + + (defun process-command (event) ;;TODO ) diff --git a/package.lisp b/package.lisp index e66ce0b..5f3c2b7 100644 --- a/package.lisp +++ b/package.lisp @@ -25,7 +25,10 @@ ;; XXX security risk? connect-server query-server - disconnect)) + disconnect + ;; global variables + *host* + *port*)) ;;convenience function (defun start () (nya:start-game)) diff --git a/naledi.lisp b/naledi.lisp index 872e192..942ef18 100644 --- a/naledi.lisp +++ b/naledi.lisp @@ -18,7 +18,7 @@ :input-echoing nil :cursor-visibility nil :input-reading :unbuffered) (splash-screen scr) - (choose-local-or-remote scr) + (start-or-connect-to-server scr) (user-interface scr))) (defun splash-screen (scr) @@ -40,7 +40,7 @@ ((nil) nil) (otherwise (return-from croatoan:event-case))))) -(defun choose-local-or-remote (scr) +(defun start-or-connect-to-server (scr) "Choose whether to start a local game or connect to a remote server" (croatoan:clear scr) (croatoan:refresh scr) @@ -66,51 +66,27 @@ (croatoan:draw-menu mw)) (#\newline (cond ((equalp (croatoan:current-item mw) "Start a local game") + ;;TODO choose world size (start-server) - (sleep 0.5) ;;give the server time to start + (setf *host* (first *defaulthost*) + *port* (second *defaulthost*)) + ;;TODO check whether server is up! + (sleep 1) ;;give the server time to start (connect-server)) ((equalp (croatoan:current-item mw) "Connect to a remote server") - (connect-server (enter-server-address scr)))) - (return-from croatoan:event-case))))) + (setf *host* (query-user scr "Server IP/URL:" T)) + (setf *port* (read-from-string + (query-user scr "Server port:" T))) + (if (user-confirm-p scr + (format nil "Connect to ~A:~S?" *host* *port*) + T) + (connect-server) + (start-or-connect-to-server scr))) + (return-from croatoan:event-case)))))) ;;TODO (choose-world-size) -(defun enter-server-address (scr) - "Enter the IP and port of the server to connect to" - ;;TODO rewrite this with individual, successive forms? - (croatoan:clear scr) - (croatoan:refresh scr) - (let* ((x0 (- (halve (croatoan:.width scr)) 25)) - (y0 (- (halve (croatoan:.height scr)) 5)) - (ip-field (make-instance 'croatoan:field :width 20 - :position '(4 8))) - (port-field (make-instance 'croatoan:field :width 20 - :position '(5 10))) - (form (make-instance 'croatoan:form - :fields (list ip-field port-field))) - (inputwin (make-instance 'croatoan:window :position (list y0 x0) - :width 50 :height 10))) - (setf (croatoan:.visible inputwin) t) - (croatoan:add-string inputwin - "Enter the servers IP address and port." :y 2 :x 4) - (croatoan:add-string inputwin "IP:" :y 4 :x 4) - (croatoan:add-string inputwin "Port:" :y 5 :x 4) - (croatoan:add-string inputwin - "(Jump with Tab, confirm with control-A)" :y 7 :x 4) - (setf (croatoan:.buffer ip-field) - (reverse (to-list "127.0.0.1"))) - (setf (croatoan:.buffer port-field) - (reverse (to-list (to-string *port*)))) - (croatoan:box inputwin) - (croatoan:edit inputwin form) - (croatoan:move inputwin 5 8) - (croatoan:refresh inputwin) - ;;FIXME The keymap doesn't work and throws an error - (setf (croatoan:.event-handlers scr) - (croatoan:get-keymap :form-default-keymap)))) - - (defun user-interface (scr) "Create the screen on the ncurses interface and hand over to window functions" (let* ((width (croatoan:.width scr)) (height (1- (croatoan:.height scr))) @@ -247,6 +223,64 @@ :message-text "Press b to go back."))) ;;:event-handlers '((#\b #'exit-event-loop))))) +(defun query-user (scr msg &optional (cls NIL) (val-width 30)) + "Display a popup asking the user to enter a value, then return that value" + ;;XXX I found `field/form' to complicated to use (:form-default-keymap + ;; doesn't seem to work), so I hacked up my own alternative + (when cls (croatoan:clear scr)) + (croatoan:refresh scr) + (let* ((x0 (- (halve (croatoan:.width scr)) (+ 5 (halve val-width)))) + (y0 (- (halve (croatoan:.height scr)) 3)) + (inputwin (make-instance 'croatoan:window :position (list y0 x0) + :width (+ 10 val-width) :height 6))) + (setf (croatoan:.visible inputwin) t) + (croatoan:box inputwin) + (croatoan:add-string inputwin msg :y 2 :x 4) + (croatoan:add-string inputwin ">>> " :y 3 :x 4) + (croatoan:move inputwin 3 8) + (croatoan:refresh inputwin) + (croatoan:event-case (scr event) + ((nil) nil) + (:backspace + (when (< 8 (croatoan:.cursor-position-x inputwin)) + (croatoan:move inputwin 0 -1 :relative t) + (croatoan:add-char inputwin #\space) + (croatoan:move inputwin 0 -1 :relative t) + (croatoan:refresh inputwin))) + (#\newline + (return-from croatoan:event-case + (trim-whitespace + (croatoan:extract-string inputwin + :y 3 :x 8 :n val-width)))) + (otherwise + (when (and (characterp event) + (> (+ 8 val-width) + (croatoan:.cursor-position-x inputwin))) + (croatoan:add-char inputwin event + :color-pair '(:blue :black)) + (croatoan:refresh inputwin)))))) + +(defun user-confirm-p (scr msg &optional (cls NIL)) + "Ask the user to confirm (Yes/No) a message." + (when cls (croatoan:clear scr)) + (croatoan:refresh scr) + (let ((dw (make-instance 'croatoan:dialog-window + :center t :border t :width (max 20 (+ 4 (length msg))) + :max-item-length (max 4 (halve (length msg))) + :input-blocking t :layout '(1 2) + :message-height 1 :message-text msg + :items '(" Yes" " No")))) + (croatoan:draw-menu dw) + (croatoan:event-case (scr event) + ((nil) nil) + ((:left :right) + (croatoan:update-menu dw event) + (croatoan:draw-menu dw)) + (#\newline + (return-from croatoan:event-case + (equalp (croatoan:current-item dw) " Yes")))))) + + (defun process-command (event) ;;TODO ) diff --git a/package.lisp b/package.lisp index e66ce0b..5f3c2b7 100644 --- a/package.lisp +++ b/package.lisp @@ -25,7 +25,10 @@ ;; XXX security risk? connect-server query-server - disconnect)) + disconnect + ;; global variables + *host* + *port*)) ;;convenience function (defun start () (nya:start-game)) diff --git a/src/client.lisp b/src/client.lisp index 01052cd..276150b 100644 --- a/src/client.lisp +++ b/src/client.lisp @@ -11,7 +11,7 @@ (in-package :naledi-ya-africa) (let ((naledi-server NIL)) - (defun connect-server (&optional (ip "127.0.0.1") (port *port*)) + (defun connect-server (&optional (ip *host*) (port *port*)) "Connect to the specified server" ;;FIXME I need to catch some exceptions here... (setf naledi-server (usocket:socket-connect ip port)) diff --git a/naledi.lisp b/naledi.lisp index 872e192..942ef18 100644 --- a/naledi.lisp +++ b/naledi.lisp @@ -18,7 +18,7 @@ :input-echoing nil :cursor-visibility nil :input-reading :unbuffered) (splash-screen scr) - (choose-local-or-remote scr) + (start-or-connect-to-server scr) (user-interface scr))) (defun splash-screen (scr) @@ -40,7 +40,7 @@ ((nil) nil) (otherwise (return-from croatoan:event-case))))) -(defun choose-local-or-remote (scr) +(defun start-or-connect-to-server (scr) "Choose whether to start a local game or connect to a remote server" (croatoan:clear scr) (croatoan:refresh scr) @@ -66,51 +66,27 @@ (croatoan:draw-menu mw)) (#\newline (cond ((equalp (croatoan:current-item mw) "Start a local game") + ;;TODO choose world size (start-server) - (sleep 0.5) ;;give the server time to start + (setf *host* (first *defaulthost*) + *port* (second *defaulthost*)) + ;;TODO check whether server is up! + (sleep 1) ;;give the server time to start (connect-server)) ((equalp (croatoan:current-item mw) "Connect to a remote server") - (connect-server (enter-server-address scr)))) - (return-from croatoan:event-case))))) + (setf *host* (query-user scr "Server IP/URL:" T)) + (setf *port* (read-from-string + (query-user scr "Server port:" T))) + (if (user-confirm-p scr + (format nil "Connect to ~A:~S?" *host* *port*) + T) + (connect-server) + (start-or-connect-to-server scr))) + (return-from croatoan:event-case)))))) ;;TODO (choose-world-size) -(defun enter-server-address (scr) - "Enter the IP and port of the server to connect to" - ;;TODO rewrite this with individual, successive forms? - (croatoan:clear scr) - (croatoan:refresh scr) - (let* ((x0 (- (halve (croatoan:.width scr)) 25)) - (y0 (- (halve (croatoan:.height scr)) 5)) - (ip-field (make-instance 'croatoan:field :width 20 - :position '(4 8))) - (port-field (make-instance 'croatoan:field :width 20 - :position '(5 10))) - (form (make-instance 'croatoan:form - :fields (list ip-field port-field))) - (inputwin (make-instance 'croatoan:window :position (list y0 x0) - :width 50 :height 10))) - (setf (croatoan:.visible inputwin) t) - (croatoan:add-string inputwin - "Enter the servers IP address and port." :y 2 :x 4) - (croatoan:add-string inputwin "IP:" :y 4 :x 4) - (croatoan:add-string inputwin "Port:" :y 5 :x 4) - (croatoan:add-string inputwin - "(Jump with Tab, confirm with control-A)" :y 7 :x 4) - (setf (croatoan:.buffer ip-field) - (reverse (to-list "127.0.0.1"))) - (setf (croatoan:.buffer port-field) - (reverse (to-list (to-string *port*)))) - (croatoan:box inputwin) - (croatoan:edit inputwin form) - (croatoan:move inputwin 5 8) - (croatoan:refresh inputwin) - ;;FIXME The keymap doesn't work and throws an error - (setf (croatoan:.event-handlers scr) - (croatoan:get-keymap :form-default-keymap)))) - - (defun user-interface (scr) "Create the screen on the ncurses interface and hand over to window functions" (let* ((width (croatoan:.width scr)) (height (1- (croatoan:.height scr))) @@ -247,6 +223,64 @@ :message-text "Press b to go back."))) ;;:event-handlers '((#\b #'exit-event-loop))))) +(defun query-user (scr msg &optional (cls NIL) (val-width 30)) + "Display a popup asking the user to enter a value, then return that value" + ;;XXX I found `field/form' to complicated to use (:form-default-keymap + ;; doesn't seem to work), so I hacked up my own alternative + (when cls (croatoan:clear scr)) + (croatoan:refresh scr) + (let* ((x0 (- (halve (croatoan:.width scr)) (+ 5 (halve val-width)))) + (y0 (- (halve (croatoan:.height scr)) 3)) + (inputwin (make-instance 'croatoan:window :position (list y0 x0) + :width (+ 10 val-width) :height 6))) + (setf (croatoan:.visible inputwin) t) + (croatoan:box inputwin) + (croatoan:add-string inputwin msg :y 2 :x 4) + (croatoan:add-string inputwin ">>> " :y 3 :x 4) + (croatoan:move inputwin 3 8) + (croatoan:refresh inputwin) + (croatoan:event-case (scr event) + ((nil) nil) + (:backspace + (when (< 8 (croatoan:.cursor-position-x inputwin)) + (croatoan:move inputwin 0 -1 :relative t) + (croatoan:add-char inputwin #\space) + (croatoan:move inputwin 0 -1 :relative t) + (croatoan:refresh inputwin))) + (#\newline + (return-from croatoan:event-case + (trim-whitespace + (croatoan:extract-string inputwin + :y 3 :x 8 :n val-width)))) + (otherwise + (when (and (characterp event) + (> (+ 8 val-width) + (croatoan:.cursor-position-x inputwin))) + (croatoan:add-char inputwin event + :color-pair '(:blue :black)) + (croatoan:refresh inputwin)))))) + +(defun user-confirm-p (scr msg &optional (cls NIL)) + "Ask the user to confirm (Yes/No) a message." + (when cls (croatoan:clear scr)) + (croatoan:refresh scr) + (let ((dw (make-instance 'croatoan:dialog-window + :center t :border t :width (max 20 (+ 4 (length msg))) + :max-item-length (max 4 (halve (length msg))) + :input-blocking t :layout '(1 2) + :message-height 1 :message-text msg + :items '(" Yes" " No")))) + (croatoan:draw-menu dw) + (croatoan:event-case (scr event) + ((nil) nil) + ((:left :right) + (croatoan:update-menu dw event) + (croatoan:draw-menu dw)) + (#\newline + (return-from croatoan:event-case + (equalp (croatoan:current-item dw) " Yes")))))) + + (defun process-command (event) ;;TODO ) diff --git a/package.lisp b/package.lisp index e66ce0b..5f3c2b7 100644 --- a/package.lisp +++ b/package.lisp @@ -25,7 +25,10 @@ ;; XXX security risk? connect-server query-server - disconnect)) + disconnect + ;; global variables + *host* + *port*)) ;;convenience function (defun start () (nya:start-game)) diff --git a/src/client.lisp b/src/client.lisp index 01052cd..276150b 100644 --- a/src/client.lisp +++ b/src/client.lisp @@ -11,7 +11,7 @@ (in-package :naledi-ya-africa) (let ((naledi-server NIL)) - (defun connect-server (&optional (ip "127.0.0.1") (port *port*)) + (defun connect-server (&optional (ip *host*) (port *port*)) "Connect to the specified server" ;;FIXME I need to catch some exceptions here... (setf naledi-server (usocket:socket-connect ip port)) diff --git a/src/params.lisp b/src/params.lisp index 1a1f8bb..3dfdf97 100644 --- a/src/params.lisp +++ b/src/params.lisp @@ -21,7 +21,13 @@ ;;Milliseconds between world updates and screen refreshes (defparameter *framerate* 1000) -;;Network port to run the server on +;;Localhost defaults +(defparameter *defaulthost* '("127.0.0.1" 21895)) + +;;Host server address to connect to +(defparameter *host* "127.0.0.1") + +;;Network port to use (defparameter *port* 21895) ;;Compass directions needed for spatial functions