diff --git a/src/params.lisp b/src/params.lisp index 04b5fa4..6d44097 100644 --- a/src/params.lisp +++ b/src/params.lisp @@ -10,7 +10,7 @@ (in-package :naledi-ya-africa) ;;Enable debugging statements -(defparameter *debugging* T) +(defparameter *debugging* NIL) ;;XXX Change back to T? ;;Specify the logfile (defparameter *logfile* "naledi.log") diff --git a/src/params.lisp b/src/params.lisp index 04b5fa4..6d44097 100644 --- a/src/params.lisp +++ b/src/params.lisp @@ -10,7 +10,7 @@ (in-package :naledi-ya-africa) ;;Enable debugging statements -(defparameter *debugging* T) +(defparameter *debugging* NIL) ;;XXX Change back to T? ;;Specify the logfile (defparameter *logfile* "naledi.log") diff --git a/src/server.lisp b/src/server.lisp index d104be5..49354a6 100644 --- a/src/server.lisp +++ b/src/server.lisp @@ -32,6 +32,12 @@ :y (random *world-size*))))) (setf players (cons np players)))) + (defun online-players () + "Return a list of names of players who are online" + (loop for p in players + if (player-online p) + collect (player-name p))) + (defun save-players (file-name) ;;TODO )) @@ -119,8 +125,15 @@ "Set the player name associated with this thread" ;;XXX somewhat ugly... (setf (cassoc th player-threads) name)) - - ;;TODO remove threads named `terminated' + + (defun cleanup-player-threads () + "Remove threads of disconnected players" + (dotimes (i (length player-threads)) + (let ((pt (nth i player-threads))) + (when (equalp (second pt) "terminated") + (bt:join-thread (first pt)) + (setf (cdr (nth (1- i) player-threads)) + (nth (1+ i) player-threads)))))) (defun update-loop () "The main loop, updating the world in the background" @@ -137,6 +150,8 @@ (update i)))) ;;Update all items each player has ;;TODO + ;;Do cleanup work + (when (zerop (rem uptime 20)) (cleanup-player-threads)) ;;Save the world and start over (save-world) ;XXX not yet implemented (incf uptime) @@ -175,6 +190,7 @@ (args (cdr reqelts))) (logging "SERVER: received request ~S~S" cmd args) (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" @@ -188,7 +204,7 @@ (defun login (name passwd) "Log this player in" - ;;XXX name and passwd are converted to symbols by `answer'! + ;;XXX name and passwd are converted to symbols by `answer'! - not currently (logging "SERVER: ~A is trying to log in" name) (let ((p (get-player name))) (cond ((not p) "ERROR: nonexistent player") @@ -197,8 +213,6 @@ (setf (patch-occupant ;;TODO check for previous occupants (coord (.x (player-human p)) (.y (player-human p)))) (player-human p)) - ;;FIXME thread-name may only be set when creating thread? - ;; -> login player, THEN start thread (set-thread-player name) (logging "SERVER: player ~A logged in" name) name)))) @@ -211,7 +225,7 @@ (setf (patch-occupant (coord (.x (player-human p)) (.y (player-human p)))) NIL) ;;TODO set to "statue of " - (logging "SERVER: player ~A logged out" player) + (logging "SERVER: player ~A logged out" (thread-player)) (set-thread-player "terminated")))) (defun create-player (name passwd) @@ -224,8 +238,7 @@ (defun get-map (width height) "Return a 3d array (x-coord, y-coord, character/colour) of the visible map" ;;FIXME - (let* ((plr (player-human - (get-player (bt:thread-name (bt:current-thread))))) + (let* ((plr (player-human (thread-player))) (x0 (- (.x plr) (halve width))) (y0 (- (.y plr) (halve height))) (submap (make-array (list width height 2))))