summaryrefslogtreecommitdiff
path: root/lisp/erc/erc-backend.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/erc/erc-backend.el')
-rw-r--r--lisp/erc/erc-backend.el175
1 files changed, 110 insertions, 65 deletions
diff --git a/lisp/erc/erc-backend.el b/lisp/erc/erc-backend.el
index eff0157c2ff..0fead116d8f 100644
--- a/lisp/erc/erc-backend.el
+++ b/lisp/erc/erc-backend.el
@@ -461,27 +461,6 @@ Currently this is called by `erc-send-input'."
(upcase-word 1)
(buffer-string)))
-(defun erc-server-send-ping (buf)
- "Send a ping to the IRC server buffer in BUF.
-Additionally, detect whether the IRC process has hung."
- (if (buffer-live-p buf)
- (with-current-buffer buf
- (if (and erc-server-send-ping-timeout
- (>
- (erc-time-diff (erc-current-time)
- erc-server-last-received-time)
- erc-server-send-ping-timeout))
- (progn
- ;; if the process is hung, kill it
- (setq erc-server-timed-out t)
- (delete-process erc-server-process))
- (erc-server-send (format "PING %.0f" (erc-current-time)))))
- ;; remove timer if the server buffer has been killed
- (let ((timer (assq buf erc-server-ping-timer-alist)))
- (when timer
- (erc-cancel-timer (cdr timer))
- (setcdr timer nil)))))
-
(defun erc-server-setup-periodical-ping (buffer)
"Set up a timer to periodically ping the current server.
The current buffer is given by BUFFER."
@@ -536,7 +515,7 @@ We will store server variables in the buffer given by BUFFER."
(set-process-filter process 'erc-server-filter-function)
(set-process-buffer process buffer)))
(erc-log "\n\n\n********************************************\n")
- (message (erc-format-message
+ (message "%s" (erc-format-message
'login ?n
(with-current-buffer buffer (erc-current-nick))))
;; wait with script loading until we receive a confirmation (first
@@ -550,11 +529,12 @@ We will store server variables in the buffer given by BUFFER."
(defun erc-server-reconnect ()
"Reestablish the current IRC connection.
Make sure you are in an ERC buffer when running this."
- (let ((server (erc-server-buffer)))
- (unless (and server
- (buffer-live-p server))
- (error "Couldn't switch to server buffer"))
- (with-current-buffer server
+ (let ((buffer (erc-server-buffer)))
+ (unless (buffer-live-p buffer)
+ (if (eq major-mode 'erc-mode)
+ (setq buffer (current-buffer))
+ (error "Reconnect must be run from an ERC buffer")))
+ (with-current-buffer buffer
(erc-update-mode-line)
(erc-set-active-buffer (current-buffer))
(setq erc-server-last-sent-time 0)
@@ -609,39 +589,61 @@ EVENT is the message received from the closed connection process."
;; open-network-stream-nowait error for connection refused
(not (string-match "^failed with code 111" event)))))
-(defun erc-process-sentinel-1 (event)
+(defun erc-process-sentinel-2 (event buffer)
+ "Called when `erc-process-sentinel-1' has detected an unexpected disconnect."
+ (if (not (buffer-live-p buffer))
+ (erc-update-mode-line)
+ (with-current-buffer buffer
+ (let ((reconnect-p (erc-server-reconnect-p event)))
+ (erc-display-message nil 'error (current-buffer)
+ (if reconnect-p 'disconnected
+ 'disconnected-noreconnect))
+ (if (not reconnect-p)
+ ;; terminate, do not reconnect
+ (progn
+ (erc-display-message nil 'error (current-buffer)
+ 'terminated ?e event)
+ ;; Update mode line indicators
+ (erc-update-mode-line)
+ (set-buffer-modified-p nil))
+ ;; reconnect
+ (condition-case err
+ (progn
+ (setq erc-server-reconnecting nil)
+ (erc-server-reconnect)
+ (setq erc-server-reconnect-count 0))
+ (error (when (buffer-live-p buffer)
+ (set-buffer buffer)
+ (if (integerp erc-server-reconnect-attempts)
+ (setq erc-server-reconnect-count
+ (1+ erc-server-reconnect-count))
+ (message "%s ... %s"
+ "Reconnecting until we succeed"
+ "kill the ERC server buffer to stop"))
+ (if (numberp erc-server-reconnect-timeout)
+ (run-at-time erc-server-reconnect-timeout nil
+ #'erc-process-sentinel-2
+ event buffer)
+ (error (concat "`erc-server-reconnect-timeout`"
+ " must be a number")))))))))))
+
+(defun erc-process-sentinel-1 (event buffer)
"Called when `erc-process-sentinel' has decided that we're disconnecting.
Determine whether user has quit or whether erc has been terminated.
Conditionally try to reconnect and take appropriate action."
- (if erc-server-quitting
- ;; normal quit
- (progn
- (erc-display-message nil 'error (current-buffer) 'finished)
- (when erc-kill-server-buffer-on-quit
+ (with-current-buffer buffer
+ (if erc-server-quitting
+ ;; normal quit
+ (progn
+ (erc-display-message nil 'error (current-buffer) 'finished)
+ ;; Update mode line indicators
+ (erc-update-mode-line)
+ ;; Kill server buffer if user wants it
(set-buffer-modified-p nil)
- (kill-buffer (current-buffer))))
- ;; unexpected disconnect
- (let ((again t))
- (while again
- (setq again nil)
- (erc-display-message nil 'error (current-buffer)
- (if (erc-server-reconnect-p event)
- 'disconnected
- 'disconnected-noreconnect))
- (if (erc-server-reconnect-p event)
- (condition-case err
- (progn
- (setq erc-server-reconnecting nil)
- (erc-server-reconnect)
- (setq erc-server-reconnect-count 0))
- (error (when (integerp erc-server-reconnect-attempts)
- (setq erc-server-reconnect-count
- (1+ erc-server-reconnect-count))
- (sit-for erc-server-reconnect-timeout)
- (setq again t))))
- ;; terminate, do not reconnect
- (erc-display-message nil 'error (current-buffer)
- 'terminated ?e event))))))
+ (when erc-kill-server-buffer-on-quit
+ (kill-buffer (current-buffer))))
+ ;; unexpected disconnect
+ (erc-process-sentinel-2 event buffer))))
(defun erc-process-sentinel (cproc event)
"Sentinel function for ERC process."
@@ -668,12 +670,7 @@ Conditionally try to reconnect and take appropriate action."
(delete-region (point) (point-max))
;; Decide what to do with the buffer
;; Restart if disconnected
- (erc-process-sentinel-1 event)
- ;; Make sure we don't write to the buffer if it has been
- ;; killed
- (when (buffer-live-p buf)
- (erc-update-mode-line)
- (set-buffer-modified-p nil))))))
+ (erc-process-sentinel-1 event buf)))))
;;;; Sending messages
@@ -757,6 +754,27 @@ protection algorithm."
(message "ERC: No process running")
nil)))
+(defun erc-server-send-ping (buf)
+ "Send a ping to the IRC server buffer in BUF.
+Additionally, detect whether the IRC process has hung."
+ (if (buffer-live-p buf)
+ (with-current-buffer buf
+ (if (and erc-server-send-ping-timeout
+ (>
+ (erc-time-diff (erc-current-time)
+ erc-server-last-received-time)
+ erc-server-send-ping-timeout))
+ (progn
+ ;; if the process is hung, kill it
+ (setq erc-server-timed-out t)
+ (delete-process erc-server-process))
+ (erc-server-send (format "PING %.0f" (erc-current-time)))))
+ ;; remove timer if the server buffer has been killed
+ (let ((timer (assq buf erc-server-ping-timer-alist)))
+ (when timer
+ (erc-cancel-timer (cdr timer))
+ (setcdr timer nil)))))
+
;; From Circe
(defun erc-server-send-queue (buffer)
"Send messages in `erc-server-flood-queue'.
@@ -1054,8 +1072,11 @@ Would expand to:
\"Some non-generic variable documentation.
Hook called upon receiving a WHOIS server response.
+
Each function is called with two arguments, the process associated
- with the response and the parsed response.
+ with the response and the parsed response. If the function returns
+ non-nil, stop processing the hook. Otherwise, continue.
+
See also `erc-server-311'.\")
(defalias 'erc-server-WI 'erc-server-311)
@@ -1064,7 +1085,9 @@ Would expand to:
Hook called upon receiving a WI server response.
Each function is called with two arguments, the process associated
- with the response and the parsed response.
+ with the response and the parsed response. If the function returns
+ non-nil, stop processing the hook. Otherwise, continue.
+
See also `erc-server-311'.\"))
\(fn (NAME &rest ALIASES) &optional EXTRA-FN-DOC EXTRA-VAR-DOC &rest FN-BODY)"
@@ -1078,7 +1101,9 @@ Would expand to:
(fn-name (intern (format "erc-server-%s" name)))
(hook-doc (format "%sHook called upon receiving a %%s server response.
Each function is called with two arguments, the process associated
-with the response and the parsed response.
+with the response and the parsed response. If the function returns
+non-nil, stop processing the hook. Otherwise, continue.
+
See also `%s'."
(if extra-var-doc
(concat extra-var-doc "\n\n")
@@ -1513,6 +1538,16 @@ A server may send more than one 005 message."
See `erc-display-server-message'." nil
(erc-display-server-message proc parsed))
+(define-erc-response-handler (275)
+ "Display secure connection message." nil
+ (multiple-value-bind (nick user message)
+ (cdr (erc-response.command-args parsed))
+ (erc-display-message
+ parsed 'notice 'active 's275
+ ?n nick
+ ?m (mapconcat 'identity (cddr (erc-response.command-args parsed))
+ " "))))
+
(define-erc-response-handler (290)
"Handle dancer-ircd CAPAB messages." nil nil)
@@ -1539,6 +1574,16 @@ See `erc-display-server-message'." nil
(erc-display-message parsed 'notice 'active
's306 ?m (erc-response.contents parsed)))
+(define-erc-response-handler (307)
+ "Display nick-identified message." nil
+ (multiple-value-bind (nick user message)
+ (cdr (erc-response.command-args parsed))
+ (erc-display-message
+ parsed 'notice 'active 's307
+ ?n nick
+ ?m (mapconcat 'identity (cddr (erc-response.command-args parsed))
+ " "))))
+
(define-erc-response-handler (311 314)
"WHOIS/WHOWAS notices." nil
(let ((fname (erc-response.contents parsed))