(defun rcirc-sentinel (process sentinel)
"Called when PROCESS receives SENTINEL."
- (let ((sentinel (replace-regexp-in-string "\n" "" sentinel)))
+ (let ((sentinel (string-replace "\n" "" sentinel)))
(rcirc-debug process (format "SENTINEL: %S %S\n" process sentinel))
(with-rcirc-process-buffer process
- (dolist (buffer (cons nil (mapcar 'cdr rcirc-buffer-alist)))
- (with-current-buffer (or buffer (current-buffer))
- (rcirc-print process "rcirc.el" "ERROR" rcirc-target
- (format "%s: %s (%S)"
- (process-name process)
- sentinel
- (process-status process))
- (not rcirc-target))
- (rcirc-disconnect-buffer)))
- (when (and (string= sentinel "deleted")
- (< 0 rcirc-reconnect-delay))
- (let ((now (current-time)))
- (when (or (null rcirc-last-connect-time)
- (time-less-p rcirc-reconnect-delay
- (time-subtract now rcirc-last-connect-time)))
- (setq rcirc-last-connect-time now)
- (rcirc-cmd-reconnect nil))))
+ (if (string= sentinel "open")
+ (let* ((server (nth 0 rcirc-connection-info))
+ (user-name (nth 3 rcirc-connection-info))
+ (full-name (nth 4 rcirc-connection-info))
+ (password (nth 6 rcirc-connection-info))
+ (server-alias (nth 8 rcirc-connection-info))
+ (use-sasl (eq (rcirc-get-server-method server) 'sasl)))
+
+ ;; prepare SASL authentication
+ (when use-sasl
+ (rcirc-send-string process "CAP REQ sasl")
+ (setq-local rcirc-finished-sasl nil))
+
+ ;; identify
+ (dolist (cap rcirc-implemented-capabilities)
+ (rcirc-send-string process "CAP" "REQ" : cap)
+ (push cap rcirc-requested-capabilities))
+ (unless (zerop (length password))
+ (rcirc-send-string process "PASS" password))
+ (rcirc-send-string process "NICK" rcirc-nick)
+ (rcirc-send-string process "USER" user-name "0" "*" : full-name)
+
+ ;; Setup sasl, and initiate authentication.
+ (when (and rcirc-auto-authenticate-flag
+ use-sasl)
+ (rcirc-send-string process "AUTHENTICATE" "PLAIN"))
+
+ ;; setup ping timer if necessary
+ (unless rcirc-keepalive-timer
+ (setq rcirc-keepalive-timer
+ (run-at-time 0 (/ rcirc-timeout-seconds 2) #'rcirc-keepalive)))
+
+ (message "Connecting to %s...done" (or server-alias server))
+ (setq mode-line-process nil))
+ (dolist (buffer (cons nil (mapcar 'cdr rcirc-buffer-alist)))
+ (with-current-buffer (or buffer (current-buffer))
+ (rcirc-print process "rcirc.el" "ERROR" rcirc-target
+ (format "%s: %s (%S)"
+ (process-name process)
+ sentinel
+ (process-status process))
+ (not rcirc-target))
+ (rcirc-disconnect-buffer)))
+ (when (and (string= sentinel "deleted")
+ (< 0 rcirc-reconnect-delay)
+ (not rcirc-connecting))
+ (let ((now (current-time)))
+ (when (or (null rcirc-last-connect-time)
+ (time-less-p rcirc-reconnect-delay
+ (time-subtract now rcirc-last-connect-time)))
+ (setq rcirc-last-connect-time now)
+ (rcirc-cmd-reconnect nil)))))
(run-hook-with-args 'rcirc-sentinel-functions process sentinel))))
(defun rcirc-disconnect-buffer (&optional buffer)