diff --git a/TODO b/TODO index 7b2cf8a..19a9874 100644 --- a/TODO +++ b/TODO @@ -7,9 +7,7 @@ GAME - -* introduce multithreading, update functions - + * set up an ASDF system, define packages * (I am legion...) @@ -19,8 +17,12 @@ -> SEVERE -* ... +* run-away thread creation + -> NON-SEVERE + +* ... + -> HEISENBUGS * occasionally, scrolling the map will lag, causing an "inertia" effect diff --git a/TODO b/TODO index 7b2cf8a..19a9874 100644 --- a/TODO +++ b/TODO @@ -7,9 +7,7 @@ GAME - -* introduce multithreading, update functions - + * set up an ASDF system, define packages * (I am legion...) @@ -19,8 +17,12 @@ -> SEVERE -* ... +* run-away thread creation + -> NON-SEVERE + +* ... + -> HEISENBUGS * occasionally, scrolling the map will lag, causing an "inertia" effect diff --git a/naledi.lisp b/naledi.lisp index bcb055c..dd4a87f 100644 --- a/naledi.lisp +++ b/naledi.lisp @@ -189,4 +189,4 @@ ;;TODO ) -(start-game) +;(start-game) diff --git a/TODO b/TODO index 7b2cf8a..19a9874 100644 --- a/TODO +++ b/TODO @@ -7,9 +7,7 @@ GAME - -* introduce multithreading, update functions - + * set up an ASDF system, define packages * (I am legion...) @@ -19,8 +17,12 @@ -> SEVERE -* ... +* run-away thread creation + -> NON-SEVERE + +* ... + -> HEISENBUGS * occasionally, scrolling the map will lag, causing an "inertia" effect diff --git a/naledi.lisp b/naledi.lisp index bcb055c..dd4a87f 100644 --- a/naledi.lisp +++ b/naledi.lisp @@ -189,4 +189,4 @@ ;;TODO ) -(start-game) +;(start-game) diff --git a/server.lisp b/server.lisp index 917cc2f..901d069 100644 --- a/server.lisp +++ b/server.lisp @@ -46,8 +46,14 @@ (let ((uptime 0) (world-thread NIL) (server-thread NIL) (player-threads NIL) (running NIL)) - (defun start-server () + (defun start-server (&optional (force NIL)) "Start the game server" + ;;TODO cannot restart -> ADDRESS-IN-USE ERROR + ;; -> comes from not closing connections properly? + ;;FIXME causes Naledi to hang on `q' -> Is this really the problem? + (when force + (reset-server-threads) + (reset-world-age)) (unless (or world-thread server-thread) (init-world) (setf running T) @@ -102,8 +108,11 @@ (with-socket-listener (socket "127.0.0.1" *port*) (while running (wait-for-input socket) - (let ((thread (bt:make-thread #'handle-connection - (socket-accept socket)))) + ;;FIXME infinite threads created over time + (let ((thread (bt:make-thread + #'(lambda () (handle-connection socket)) + :name (string-from-list (list "player-thread" + (length player-threads)) "-")))) (setf player-threads (cons thread player-threads)))))) (defun handle-connection (socket) @@ -111,20 +120,20 @@ (with-connected-socket (connection (socket-accept socket)) (logging "~&SERVER: received a connection.") ; cf. `get-peer-name' (do* ((sockstr (socket-stream connection)) - (request (read-line sockstr (eof-error-p NIL)) - (read-line sockstr (eof-error-p NIL)))) - ((or (not running) (null request)) (force-output sockstr)) - (format (socket-stream connection) "~S" (answer request)))))) + (request (read-line sockstr NIL) (read-line sockstr NIL))) + ((or (not running) (null request))) + (format sockstr "~S~%" (to-string (answer request))) + (finish-output sockstr))))) (defun answer (request) - (debugging "Received request ~S" request) + (logging "SERVER: received request ~S" request) (let* ((reqelts (extract-elements request)) (player-name (first reqelts)) (cmd (second reqelts)) (args (cddr reqelts))) (cond ((eq player-name 'ACK) "ACK ACK") ;debug - ((eq cmd 'get-map) (to-string (get-map player-name))) - ((eq cmd 'describe-patch) (to-string (describe-patch args))) + ((eq cmd 'get-map) (get-map player-name)) + ((eq cmd 'describe-patch) (describe-patch args)) ;;TODO ))) @@ -168,7 +177,11 @@ (unless naledi-server ;XXX do this with exceptions (return-from query-server "You are not connected to a server!")) (let ((servstr (socket-stream naledi-server))) - (format servstr request) + (logging "CLIENT: sending request ~S" request) + (format servstr "~A~%" request) + (finish-output servstr) + ;;FIXME server still doesn't receive string until disconnect... + (logging "CLIENT: waiting for server response") (wait-for-input naledi-server) (read-from-string (read-line servstr))))