diff options
| author | John Wiegley <johnw@newartisans.com> | 2002-04-25 20:21:55 +0000 |
|---|---|---|
| committer | John Wiegley <johnw@newartisans.com> | 2002-04-25 20:21:55 +0000 |
| commit | 57b8e0947024d5be6c6e8725a598002f8b4a7364 (patch) | |
| tree | 0afb9085ad168fa3d73ee07d95caa5176186bd7d | |
| parent | d1dac420bf5279262c01a0a020fcee21d13669c7 (diff) | |
fixes to the ICS client
| -rw-r--r-- | chess-clock.el | 2 | ||||
| -rw-r--r-- | chess-engine.el | 3 | ||||
| -rw-r--r-- | chess-ics.el | 112 |
3 files changed, 69 insertions, 48 deletions
diff --git a/chess-clock.el b/chess-clock.el index 1494d93..74a791c 100644 --- a/chess-clock.el +++ b/chess-clock.el @@ -61,7 +61,7 @@ ((eq event 'set-data) (if (and (eq (car args) 'active) - (null (chess-game-data game 'active))) + (not (chess-game-data game 'active))) (chess-clock-handler game 'destroy))) ((memq event '(destroy resign drawn)) diff --git a/chess-engine.el b/chess-engine.el index 090332e..aac40a6 100644 --- a/chess-engine.el +++ b/chess-engine.el @@ -395,8 +395,7 @@ (goto-char chess-engine-last-pos) (goto-char (point-min))) (unwind-protect - (while (and (not (eobp)) - (/= (line-end-position) (point-max))) + (while (not (eobp)) (let ((triggers chess-engine-regexp-alist) last-trigger result) (while triggers diff --git a/chess-ics.el b/chess-ics.el index 508c4fa..58517a4 100644 --- a/chess-ics.el +++ b/chess-ics.el @@ -30,12 +30,67 @@ The format of each entry is: (repeat string)))) :group 'chess-ics) +(defvar chess-ics-server) (defvar chess-ics-handle) +(defvar chess-ics-password) (defvar chess-ics-prompt) +(make-variable-buffer-local 'chess-ics-server) (make-variable-buffer-local 'chess-ics-handle) +(make-variable-buffer-local 'chess-ics-password) (make-variable-buffer-local 'chess-ics-prompt) +(defvar chess-ics-regexp-alist + (list (cons "\\(ogin\\|name\\):" + (function + (lambda () + (chess-engine-send nil (concat chess-ics-handle "\n")) + 'once))) + (cons "[Pp]assword:" + (function + (lambda () + (let ((pass (or chess-ics-password + (read-passwd "Password: ")))) + (if (file-readable-p pass) + (setq pass (with-temp-buffer + (insert-file-contents pass) + (buffer-string)))) + (chess-engine-send nil (concat pass "\n"))) + 'once))) + (cons "%" + (function + (lambda () + (chess-engine-send nil "set style 12\n") + (chess-engine-send nil "set bell 0\n") + 'once))) + (cons "Logging you in as \"\\([^\"]+\\)\"" + (function + (lambda () + (setq chess-ics-handle (match-string 1)) + 'once))) + (cons "Press return to enter the server as" + (function + (lambda () + (chess-engine-send nil "\n") + 'once))) + (cons "The game has been aborted on move [^.]+\\." + (function + (lambda () + (let ((chess-engine-pending-offer 'abort)) + (funcall chess-engine-response-handler 'accept))))) + (cons "<12> \\(.+\\)" + 'chess-ics-handle-move) + (cons "Illegal move (\\([^)]+\\))\\." + (function + (lambda () + (funcall chess-engine-response-handler 'illegal + (match-string 1))))) + (cons "Challenge: \\(\\S-+\\) \\S-+ \\S-+ \\S-+ .+" + (function + (lambda () + (funcall chess-engine-response-handler 'match + (match-string 1))))))) + ;; ICS12 format (with artificial line breaks): ;; ;; <12> rnbqkbnr pppppppp -------- -------- \ @@ -156,6 +211,10 @@ who is black." (list position move white black white-time black-time))) +;; <12> -k------ p-p----- -p------ ----n-R- ---N--p- ---P---- PPP-r--- -K---r-- W -1 0 0 0 0 1 160 GuestLKMM MiloBot 1 15 0 12 17 774 898 26 R/f8-f1 (0:00) Rf1# 0 1 0 + +;; error in process filter: Assertion failed: (equal (car info) (chess-engine-position nil)) + (defun chess-ics-handle-move () (let ((chess-engine-handling-event t) (begin (match-beginning 0)) @@ -171,12 +230,12 @@ who is black." (cadr info) t))) (chess-game-set-data game 'white-remaining (nth 4 info)) (chess-game-set-data game 'black-remaining (nth 5 info)) - (chess-game-move game ply)) - (assert (equal (car info) (chess-engine-position nil)))) + (chess-game-move game ply))) (let ((chess-game-inhibit-events t) plies) (chess-game-set-data game 'my-color (string= (nth 2 info) chess-ics-handle)) (chess-game-set-data game 'active t) + (chess-game-set-tag game "Site" (car chess-ics-server)) (chess-game-set-start-position game (car info))) (chess-game-run-hooks game 'orient)) (goto-char begin) @@ -185,36 +244,6 @@ who is black." (forward-line -1) t)) -(defvar chess-ics-regexp-alist - (list (cons "[A-Za-z0-9_]+%" - (function - (lambda () - (chess-engine-send nil "set style 12\n") - (chess-engine-send nil "set bell 0\n") - 'once))) - (cons "Logging you in as \"\\([^\"]+\\)\"" - (function - (lambda () - (setq chess-ics-handle (match-string 1)) - 'once))) - (cons "The game has been aborted on move [^.]+\\." - (function - (lambda () - (let ((chess-engine-pending-offer 'abort)) - (funcall chess-engine-response-handler 'accept))))) - (cons "<12> \\(.+\\)" - 'chess-ics-handle-move) - (cons "Illegal move (\\([^)]+\\))\\." - (function - (lambda () - (funcall chess-engine-response-handler 'illegal - (match-string 1))))) - (cons "Challenge: \\(\\S-+\\) \\S-+ \\S-+ \\S-+ .+" - (function - (lambda () - (funcall chess-engine-response-handler 'match - (match-string 1))))))) - (chess-message-catalog 'english '((ics-server-prompt . "Connect to chess server: ") (ics-connecting . "Connecting to Internet Chess Server '%s'...") @@ -248,21 +277,14 @@ who is black." (add-hook 'comint-output-filter-functions 'chess-engine-filter t t) - (setq comint-prompt-regexp "^[^%\n]*% *" + (setq chess-ics-server server + comint-prompt-regexp "^[^%\n]*% *" comint-scroll-show-maximum-output t) - (let ((proc (get-buffer-process (current-buffer)))) - (if (null (nth 2 server)) - (comint-send-string proc "guest\n") - (setq chess-ics-handle (nth 2 server)) - (comint-send-string proc (concat chess-ics-handle "\n")) - (let ((pass (or (nth 3 server) - (read-passwd "Password: ")))) - (if (file-readable-p pass) - (setq pass (with-temp-buffer - (insert-file-contents file) - (buffer-string)))) - (comint-send-string proc (concat pass "\n"))))))) + (if (null (nth 2 server)) + (setq chess-ics-handle "guest") + (setq chess-ics-handle (nth 2 server) + chess-ics-password (nth 3 server))))) t) ((eq event 'match) |
