diff --git a/TODO b/TODO index cee714b..d907c04 100644 --- a/TODO +++ b/TODO @@ -18,6 +18,8 @@ * split `naledi-ya-africa` package into `naledi-server` and `naledi-client`? +* remove `debugging` calls, introduce logging levels + * (I am legion...) @@ -27,6 +29,9 @@ * Game map is not rendered +* world thread type error: "The value -1 is not of type unsigned-byte when binding + sb-impl::n" + -> NON-SEVERE * Lakes are created diff --git a/TODO b/TODO index cee714b..d907c04 100644 --- a/TODO +++ b/TODO @@ -18,6 +18,8 @@ * split `naledi-ya-africa` package into `naledi-server` and `naledi-client`? +* remove `debugging` calls, introduce logging levels + * (I am legion...) @@ -27,6 +29,9 @@ * Game map is not rendered +* world thread type error: "The value -1 is not of type unsigned-byte when binding + sb-impl::n" + -> NON-SEVERE * Lakes are created diff --git a/naledi.lisp b/naledi.lisp index 4de1da4..2cd3483 100644 --- a/naledi.lisp +++ b/naledi.lisp @@ -24,6 +24,7 @@ (defun splash-screen (scr) "Display the splash screen with the `Naledi ya Africa' logo" (let* ((width (croatoan:.width scr)) (height (croatoan:.height scr)) + ;;FIXME fails when not in the naledi directory (logo (load-text-file "LOGO")) (y (halve (- height (length logo)))) (xoff (halve (- width 80)))) @@ -65,10 +66,9 @@ (croatoan:update-menu mw event) (croatoan:draw-menu mw)) (#\newline - (cond ((equalp (croatoan:.current-item mw) "Start a local game") + (cond ((= (croatoan:.current-item-number mw) 0) (start-local-game scr)) - ((equalp (croatoan:.current-item mw) - "Connect to a remote server") + ((= (croatoan:.current-item-number mw) 1) (connect-remote-game scr))) (return-from croatoan:event-case))))) @@ -93,6 +93,7 @@ (query-user scr "Server port:" :default (second *defaulthost*) :cls T))) (if (user-confirm-p scr (format nil "Connect to ~A:~S?" *host* *port*) T) + ;;TODO ask for username/password! (connect-server) (start-or-connect-to-server scr))) diff --git a/TODO b/TODO index cee714b..d907c04 100644 --- a/TODO +++ b/TODO @@ -18,6 +18,8 @@ * split `naledi-ya-africa` package into `naledi-server` and `naledi-client`? +* remove `debugging` calls, introduce logging levels + * (I am legion...) @@ -27,6 +29,9 @@ * Game map is not rendered +* world thread type error: "The value -1 is not of type unsigned-byte when binding + sb-impl::n" + -> NON-SEVERE * Lakes are created diff --git a/naledi.lisp b/naledi.lisp index 4de1da4..2cd3483 100644 --- a/naledi.lisp +++ b/naledi.lisp @@ -24,6 +24,7 @@ (defun splash-screen (scr) "Display the splash screen with the `Naledi ya Africa' logo" (let* ((width (croatoan:.width scr)) (height (croatoan:.height scr)) + ;;FIXME fails when not in the naledi directory (logo (load-text-file "LOGO")) (y (halve (- height (length logo)))) (xoff (halve (- width 80)))) @@ -65,10 +66,9 @@ (croatoan:update-menu mw event) (croatoan:draw-menu mw)) (#\newline - (cond ((equalp (croatoan:.current-item mw) "Start a local game") + (cond ((= (croatoan:.current-item-number mw) 0) (start-local-game scr)) - ((equalp (croatoan:.current-item mw) - "Connect to a remote server") + ((= (croatoan:.current-item-number mw) 1) (connect-remote-game scr))) (return-from croatoan:event-case))))) @@ -93,6 +93,7 @@ (query-user scr "Server port:" :default (second *defaulthost*) :cls T))) (if (user-confirm-p scr (format nil "Connect to ~A:~S?" *host* *port*) T) + ;;TODO ask for username/password! (connect-server) (start-or-connect-to-server scr))) diff --git a/package.lisp b/package.lisp index 545c0b9..5e0dcc4 100644 --- a/package.lisp +++ b/package.lisp @@ -19,6 +19,7 @@ start-server runningp age-of-the-world + online-players terminate init-world ;; client functions - use with caution! @@ -35,3 +36,7 @@ ;;convenience function (defun start () (nya:start-game)) + +;;XXX utility function during development, remove later +(defun dt (&optional (n 0)) + (bt:destroy-thread (nth n (bt:all-threads)))) diff --git a/TODO b/TODO index cee714b..d907c04 100644 --- a/TODO +++ b/TODO @@ -18,6 +18,8 @@ * split `naledi-ya-africa` package into `naledi-server` and `naledi-client`? +* remove `debugging` calls, introduce logging levels + * (I am legion...) @@ -27,6 +29,9 @@ * Game map is not rendered +* world thread type error: "The value -1 is not of type unsigned-byte when binding + sb-impl::n" + -> NON-SEVERE * Lakes are created diff --git a/naledi.lisp b/naledi.lisp index 4de1da4..2cd3483 100644 --- a/naledi.lisp +++ b/naledi.lisp @@ -24,6 +24,7 @@ (defun splash-screen (scr) "Display the splash screen with the `Naledi ya Africa' logo" (let* ((width (croatoan:.width scr)) (height (croatoan:.height scr)) + ;;FIXME fails when not in the naledi directory (logo (load-text-file "LOGO")) (y (halve (- height (length logo)))) (xoff (halve (- width 80)))) @@ -65,10 +66,9 @@ (croatoan:update-menu mw event) (croatoan:draw-menu mw)) (#\newline - (cond ((equalp (croatoan:.current-item mw) "Start a local game") + (cond ((= (croatoan:.current-item-number mw) 0) (start-local-game scr)) - ((equalp (croatoan:.current-item mw) - "Connect to a remote server") + ((= (croatoan:.current-item-number mw) 1) (connect-remote-game scr))) (return-from croatoan:event-case))))) @@ -93,6 +93,7 @@ (query-user scr "Server port:" :default (second *defaulthost*) :cls T))) (if (user-confirm-p scr (format nil "Connect to ~A:~S?" *host* *port*) T) + ;;TODO ask for username/password! (connect-server) (start-or-connect-to-server scr))) diff --git a/package.lisp b/package.lisp index 545c0b9..5e0dcc4 100644 --- a/package.lisp +++ b/package.lisp @@ -19,6 +19,7 @@ start-server runningp age-of-the-world + online-players terminate init-world ;; client functions - use with caution! @@ -35,3 +36,7 @@ ;;convenience function (defun start () (nya:start-game)) + +;;XXX utility function during development, remove later +(defun dt (&optional (n 0)) + (bt:destroy-thread (nth n (bt:all-threads)))) diff --git a/src/client.lisp b/src/client.lisp index 0cbbeaa..fd84476 100644 --- a/src/client.lisp +++ b/src/client.lisp @@ -29,13 +29,17 @@ (logging "CLIENT: sending request ~S" request) (format servstr "~A~%" req) (finish-output servstr) - (logging "CLIENT: waiting for server response") (usocket:wait-for-input naledi-server) - (let ((reply (read-line servstr))) + (let ((reply (read-line servstr nil))) + ;;XXX do I need to be able to read multiple lines? + ;; (do* ((raw-reply (multiple-value-list (read-line servstr nil)) + ;; (multiple-value-list (read-line servstr nil))) + ;; (reply-line (first raw-reply) (first raw-reply)) + ;; (eof (second raw-reply) (second raw-reply)) + ;; (reply reply-line (sconc reply reply-line))) + ;; ((or eof (null reply-line)) ;;FIXME (logging "CLIENT: received reply ~A" reply) (read-from-string reply)))) - ;; (logging "CLIENT: ready to receive response") - ;; (read-from-string (read-line servstr)))) (defun disconnect () "Disconnect from the server" diff --git a/TODO b/TODO index cee714b..d907c04 100644 --- a/TODO +++ b/TODO @@ -18,6 +18,8 @@ * split `naledi-ya-africa` package into `naledi-server` and `naledi-client`? +* remove `debugging` calls, introduce logging levels + * (I am legion...) @@ -27,6 +29,9 @@ * Game map is not rendered +* world thread type error: "The value -1 is not of type unsigned-byte when binding + sb-impl::n" + -> NON-SEVERE * Lakes are created diff --git a/naledi.lisp b/naledi.lisp index 4de1da4..2cd3483 100644 --- a/naledi.lisp +++ b/naledi.lisp @@ -24,6 +24,7 @@ (defun splash-screen (scr) "Display the splash screen with the `Naledi ya Africa' logo" (let* ((width (croatoan:.width scr)) (height (croatoan:.height scr)) + ;;FIXME fails when not in the naledi directory (logo (load-text-file "LOGO")) (y (halve (- height (length logo)))) (xoff (halve (- width 80)))) @@ -65,10 +66,9 @@ (croatoan:update-menu mw event) (croatoan:draw-menu mw)) (#\newline - (cond ((equalp (croatoan:.current-item mw) "Start a local game") + (cond ((= (croatoan:.current-item-number mw) 0) (start-local-game scr)) - ((equalp (croatoan:.current-item mw) - "Connect to a remote server") + ((= (croatoan:.current-item-number mw) 1) (connect-remote-game scr))) (return-from croatoan:event-case))))) @@ -93,6 +93,7 @@ (query-user scr "Server port:" :default (second *defaulthost*) :cls T))) (if (user-confirm-p scr (format nil "Connect to ~A:~S?" *host* *port*) T) + ;;TODO ask for username/password! (connect-server) (start-or-connect-to-server scr))) diff --git a/package.lisp b/package.lisp index 545c0b9..5e0dcc4 100644 --- a/package.lisp +++ b/package.lisp @@ -19,6 +19,7 @@ start-server runningp age-of-the-world + online-players terminate init-world ;; client functions - use with caution! @@ -35,3 +36,7 @@ ;;convenience function (defun start () (nya:start-game)) + +;;XXX utility function during development, remove later +(defun dt (&optional (n 0)) + (bt:destroy-thread (nth n (bt:all-threads)))) diff --git a/src/client.lisp b/src/client.lisp index 0cbbeaa..fd84476 100644 --- a/src/client.lisp +++ b/src/client.lisp @@ -29,13 +29,17 @@ (logging "CLIENT: sending request ~S" request) (format servstr "~A~%" req) (finish-output servstr) - (logging "CLIENT: waiting for server response") (usocket:wait-for-input naledi-server) - (let ((reply (read-line servstr))) + (let ((reply (read-line servstr nil))) + ;;XXX do I need to be able to read multiple lines? + ;; (do* ((raw-reply (multiple-value-list (read-line servstr nil)) + ;; (multiple-value-list (read-line servstr nil))) + ;; (reply-line (first raw-reply) (first raw-reply)) + ;; (eof (second raw-reply) (second raw-reply)) + ;; (reply reply-line (sconc reply reply-line))) + ;; ((or eof (null reply-line)) ;;FIXME (logging "CLIENT: received reply ~A" reply) (read-from-string reply)))) - ;; (logging "CLIENT: ready to receive response") - ;; (read-from-string (read-line servstr)))) (defun disconnect () "Disconnect from the server" diff --git a/src/player.lisp b/src/player.lisp index 30c9a88..712738b 100644 --- a/src/player.lisp +++ b/src/player.lisp @@ -27,8 +27,12 @@ (inventory :accessor .inventory :initarg :inventory :initform '((NIL 0) (NIL 0) (NIL 0) (NIL 0) (NIL 0) (NIL 0) (NIL 0) (NIL 0) (NIL 0) (NIL 0)))) + ;;XXX change habitats to (available-biomes)? -> requires load order change (:default-initargs :habitat T)) +(defmethod update ((h human)) + ;;TODO + ) ;; INVENTORY HANDLING FUNCTIONS diff --git a/TODO b/TODO index cee714b..d907c04 100644 --- a/TODO +++ b/TODO @@ -18,6 +18,8 @@ * split `naledi-ya-africa` package into `naledi-server` and `naledi-client`? +* remove `debugging` calls, introduce logging levels + * (I am legion...) @@ -27,6 +29,9 @@ * Game map is not rendered +* world thread type error: "The value -1 is not of type unsigned-byte when binding + sb-impl::n" + -> NON-SEVERE * Lakes are created diff --git a/naledi.lisp b/naledi.lisp index 4de1da4..2cd3483 100644 --- a/naledi.lisp +++ b/naledi.lisp @@ -24,6 +24,7 @@ (defun splash-screen (scr) "Display the splash screen with the `Naledi ya Africa' logo" (let* ((width (croatoan:.width scr)) (height (croatoan:.height scr)) + ;;FIXME fails when not in the naledi directory (logo (load-text-file "LOGO")) (y (halve (- height (length logo)))) (xoff (halve (- width 80)))) @@ -65,10 +66,9 @@ (croatoan:update-menu mw event) (croatoan:draw-menu mw)) (#\newline - (cond ((equalp (croatoan:.current-item mw) "Start a local game") + (cond ((= (croatoan:.current-item-number mw) 0) (start-local-game scr)) - ((equalp (croatoan:.current-item mw) - "Connect to a remote server") + ((= (croatoan:.current-item-number mw) 1) (connect-remote-game scr))) (return-from croatoan:event-case))))) @@ -93,6 +93,7 @@ (query-user scr "Server port:" :default (second *defaulthost*) :cls T))) (if (user-confirm-p scr (format nil "Connect to ~A:~S?" *host* *port*) T) + ;;TODO ask for username/password! (connect-server) (start-or-connect-to-server scr))) diff --git a/package.lisp b/package.lisp index 545c0b9..5e0dcc4 100644 --- a/package.lisp +++ b/package.lisp @@ -19,6 +19,7 @@ start-server runningp age-of-the-world + online-players terminate init-world ;; client functions - use with caution! @@ -35,3 +36,7 @@ ;;convenience function (defun start () (nya:start-game)) + +;;XXX utility function during development, remove later +(defun dt (&optional (n 0)) + (bt:destroy-thread (nth n (bt:all-threads)))) diff --git a/src/client.lisp b/src/client.lisp index 0cbbeaa..fd84476 100644 --- a/src/client.lisp +++ b/src/client.lisp @@ -29,13 +29,17 @@ (logging "CLIENT: sending request ~S" request) (format servstr "~A~%" req) (finish-output servstr) - (logging "CLIENT: waiting for server response") (usocket:wait-for-input naledi-server) - (let ((reply (read-line servstr))) + (let ((reply (read-line servstr nil))) + ;;XXX do I need to be able to read multiple lines? + ;; (do* ((raw-reply (multiple-value-list (read-line servstr nil)) + ;; (multiple-value-list (read-line servstr nil))) + ;; (reply-line (first raw-reply) (first raw-reply)) + ;; (eof (second raw-reply) (second raw-reply)) + ;; (reply reply-line (sconc reply reply-line))) + ;; ((or eof (null reply-line)) ;;FIXME (logging "CLIENT: received reply ~A" reply) (read-from-string reply)))) - ;; (logging "CLIENT: ready to receive response") - ;; (read-from-string (read-line servstr)))) (defun disconnect () "Disconnect from the server" diff --git a/src/player.lisp b/src/player.lisp index 30c9a88..712738b 100644 --- a/src/player.lisp +++ b/src/player.lisp @@ -27,8 +27,12 @@ (inventory :accessor .inventory :initarg :inventory :initform '((NIL 0) (NIL 0) (NIL 0) (NIL 0) (NIL 0) (NIL 0) (NIL 0) (NIL 0) (NIL 0) (NIL 0)))) + ;;XXX change habitats to (available-biomes)? -> requires load order change (:default-initargs :habitat T)) +(defmethod update ((h human)) + ;;TODO + ) ;; INVENTORY HANDLING FUNCTIONS diff --git a/src/server.lisp b/src/server.lisp index 49354a6..ae45bad 100644 --- a/src/server.lisp +++ b/src/server.lisp @@ -7,10 +7,6 @@ ;;;; (c) 2018 Daniel Vedder, MIT license ;;;; -;;XXX utility function during development, remove later -(defun dt (&optional (n 0)) - (bt:destroy-thread (nth n (bt:all-threads)))) - (in-package :naledi-ya-africa) ;; TODO save and load functions @@ -164,6 +160,7 @@ (while running (usocket:wait-for-input socket) (when (eq (usocket:socket-state socket) ':read) + ;;XXX give player threads unique names again? (let ((thread (bt:make-thread #'(lambda () (handle-connection socket)) @@ -188,20 +185,20 @@ (let* ((reqelts (split-string request #\space)) (cmd (car reqelts)) (args (cdr reqelts))) - (logging "SERVER: received request ~S~S" cmd args) + (logging "SERVER: received request ~S" reqelts) (if (member cmd (keys *API*) :test #'equalp) ;;XXX Surely there must be a way to simplify the next few lines?! (if (and (equalp (thread-player) "anon") (not (or (equalp cmd "login") (equalp cmd "signup")))) "ERROR: not logged in" - (progn - (logging "SERVER: calling function ~S with args ~S" - (cassoc cmd *API* :test #'equalp) args) - (apply (cassoc cmd *API* :test #'equalp) args))) - (logging "ERROR: unknown command")))) + (apply (cassoc cmd *API* :test #'equalp) args)) + "ERROR: unknown command"))) ;;; COMMUNICATION FUNCTIONS +;;NOTE: all following functions receive string arguments and must convert +;; them as needed + (defun login (name passwd) "Log this player in" ;;XXX name and passwd are converted to symbols by `answer'! - not currently @@ -235,17 +232,18 @@ (add-player name passwd) (login name passwd)))) -(defun get-map (width height) +(defun get-map (swidth sheight) "Return a 3d array (x-coord, y-coord, character/colour) of the visible map" - ;;FIXME - (let* ((plr (player-human (thread-player))) + (let* ((plr (player-human (get-player (thread-player)))) + (width (read-from-string swidth)) + (height (read-from-string sheight)) (x0 (- (.x plr) (halve width))) (y0 (- (.y plr) (halve height))) (submap (make-array (list width height 2)))) (dotimes (h height) (dotimes (w width) (let ((p (coord (+ w x0 1) (+ h y0 1))) - (next-char #\space) (next-col :black)) + (next-char #\space) (next-col ':black)) (if (and p (patch-occupant p)) (setf next-char (.char (patch-occupant p)) next-col (.color (patch-occupant p))) @@ -253,6 +251,8 @@ next-col (biome-col (patch-biome p))))) (setf (aref submap w h 0) next-char (aref submap w h 1) next-col)))) + ;;FIXME arrays are pretty-printed with linebreaks, this causes a + ;; client-side error (only expecting one line) submap)) (defun describe-patch (coords)