1 ;;; erc-backend.el --- Backend network communication for ERC
3 ;; Copyright (C) 2004-2016 Free Software Foundation, Inc.
5 ;; Filename: erc-backend.el
6 ;; Author: Lawrence Mitchell <wence@gmx.li>
7 ;; Maintainer: emacs-devel@gnu.org
9 ;; Keywords: IRC chat client internet
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software: you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation, either version 3 of the License, or
16 ;; (at your option) any later version.
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
28 ;; This file defines backend network communication handlers for ERC.
32 ;; You define a new handler with `define-erc-response-handler'. This
33 ;; defines a function, a corresponding hook variable, and populates a
34 ;; global hash table `erc-server-responses' with a map from response
35 ;; to hook variable. See the function documentation for more
38 ;; Upon receiving a line from the server, `erc-parse-server-response'
41 ;; A line generally looks like:
43 ;; LINE := ':' SENDER ' ' COMMAND ' ' (COMMAND-ARGS ' ')* ':' CONTENTS
44 ;; SENDER := Not ':' | ' '
45 ;; COMMAND := Not ':' | ' '
46 ;; COMMAND-ARGS := Not ':' | ' '
48 ;; This gets parsed and stuffed into an `erc-response' struct. You
49 ;; can access the fields of the struct with:
51 ;; COMMAND --- `erc-response.command'
52 ;; COMMAND-ARGS --- `erc-response.command-args'
53 ;; CONTENTS --- `erc-response.contents'
54 ;; SENDER --- `erc-response.sender'
55 ;; LINE --- `erc-response.unparsed'
58 ;; It's probably not a good idea to destructively modify the list
59 ;; of command-args in your handlers, since other functions down the
60 ;; line may well need to access the arguments too.
62 ;; That is, unless you're /absolutely/ sure that your handler doesn't
63 ;; invoke some other function that needs to use COMMAND-ARGS, don't do
66 ;; (while (erc-response.command-args parsed)
67 ;; (let ((a (pop (erc-response.command-args parsed))))
70 ;; The parsed response is handed over to
71 ;; `erc-handle-parsed-server-response', which checks whether it should
72 ;; carry out duplicate suppression, and then runs `erc-call-hooks'.
73 ;; `erc-call-hooks' retrieves the relevant hook variable from
74 ;; `erc-server-responses' and runs it.
76 ;; Most handlers then destructure the parsed response in some way
77 ;; (depending on what the handler is, the arguments have different
78 ;; meanings), and generally display something, usually using
79 ;; `erc-display-message'.
83 ;; o Generalize the display-line code so that we can use it to
84 ;; display the stuff we send, as well as the stuff we receive.
85 ;; Then, move all display-related code into another backend-like
86 ;; file, erc-display.el, say.
88 ;; o Clean up the handlers using new display code (has to be written
93 ;; 2004/05/10 -- Handler bodies taken out of erc.el and ported to new
96 ;; 2005-08-13 -- Moved sending commands from erc.el.
100 (require 'erc-compat)
101 (eval-when-compile (require 'cl-lib))
102 ;; There's a fairly strong mutual dependency between erc.el and erc-backend.el.
103 ;; Luckily, erc.el does not need erc-backend.el for macroexpansion whereas the
105 (provide 'erc-backend)
108 ;;;; Variables and options
110 (defvar erc-server-responses (make-hash-table :test #'equal)
111 "Hashtable mapping server responses to their handler hooks.")
113 (cl-defstruct (erc-response (:conc-name erc-response.))
114 (unparsed "" :type string)
115 (sender "" :type string)
116 (command "" :type string)
117 (command-args '() :type list)
118 (contents "" :type string))
122 (defvar erc-server-current-nick nil
123 "Nickname on the current server.
124 Use `erc-current-nick' to access this.")
125 (make-variable-buffer-local 'erc-server-current-nick)
127 ;;; Server attributes
129 (defvar erc-server-process nil
130 "The process object of the corresponding server connection.")
131 (make-variable-buffer-local 'erc-server-process)
133 (defvar erc-session-server nil
134 "The server name used to connect to for this session.")
135 (make-variable-buffer-local 'erc-session-server)
137 (defvar erc-session-connector nil
138 "The function used to connect to this session (nil for the default).")
139 (make-variable-buffer-local 'erc-session-connector)
141 (defvar erc-session-port nil
142 "The port used to connect to.")
143 (make-variable-buffer-local 'erc-session-port)
145 (defvar erc-server-announced-name nil
146 "The name the server announced to use.")
147 (make-variable-buffer-local 'erc-server-announced-name)
149 (defvar erc-server-version nil
150 "The name and version of the server's ircd.")
151 (make-variable-buffer-local 'erc-server-version)
153 (defvar erc-server-parameters nil
154 "Alist listing the supported server parameters.
156 This is only set if the server sends 005 messages saying what is
157 supported on the server.
159 Entries are of the form:
162 (PARAMETER) if no value is provided.
164 Some examples of possible parameters sent by servers:
165 CHANMODES=b,k,l,imnpst - list of supported channel modes
166 CHANNELLEN=50 - maximum length of channel names
167 CHANTYPES=#&!+ - supported channel prefixes
168 CHARMAPPING=rfc1459 - character mapping used for nickname and channels
169 KICKLEN=160 - maximum allowed kick message length
170 MAXBANS=30 - maximum number of bans per channel
171 MAXCHANNELS=10 - maximum number of channels allowed to join
172 NETWORK=EFnet - the network identifier
173 NICKLEN=9 - maximum allowed length of nicknames
174 PREFIX=(ov)@+ - list of channel modes and the user prefixes if user has mode
175 RFC2812 - server supports RFC 2812 features
176 SILENCE=10 - supports the SILENCE command, maximum allowed number of entries
177 TOPICLEN=160 - maximum allowed topic length
178 WALLCHOPS - supports sending messages to all operators in a channel")
179 (make-variable-buffer-local 'erc-server-parameters)
181 ;;; Server and connection state
183 (defvar erc-server-ping-timer-alist nil
184 "Mapping of server buffers to their specific ping timer.")
186 (defvar erc-server-connected nil
187 "Non-nil if the current buffer has been used by ERC to establish
190 If you wish to determine whether an IRC connection is currently
191 active, use the `erc-server-process-alive' function instead.")
192 (make-variable-buffer-local 'erc-server-connected)
194 (defvar erc-server-reconnect-count 0
195 "Number of times we have failed to reconnect to the current server.")
196 (make-variable-buffer-local 'erc-server-reconnect-count)
198 (defvar erc-server-quitting nil
199 "Non-nil if the user requests a quit.")
200 (make-variable-buffer-local 'erc-server-quitting)
202 (defvar erc-server-reconnecting nil
203 "Non-nil if the user requests an explicit reconnect, and the
204 current IRC process is still alive.")
205 (make-variable-buffer-local 'erc-server-reconnecting)
207 (defvar erc-server-timed-out nil
208 "Non-nil if the IRC server failed to respond to a ping.")
209 (make-variable-buffer-local 'erc-server-timed-out)
211 (defvar erc-server-banned nil
212 "Non-nil if the user is denied access because of a server ban.")
213 (make-variable-buffer-local 'erc-server-banned)
215 (defvar erc-server-error-occurred nil
216 "Non-nil if the user triggers some server error.")
217 (make-variable-buffer-local 'erc-server-error-occurred)
219 (defvar erc-server-lines-sent nil
221 (make-variable-buffer-local 'erc-server-lines-sent)
223 (defvar erc-server-last-peers '(nil . nil)
224 "Last peers used, both sender and receiver.
225 Those are used for /MSG destination shortcuts.")
226 (make-variable-buffer-local 'erc-server-last-peers)
228 (defvar erc-server-last-sent-time nil
229 "Time the message was sent.
230 This is useful for flood protection.")
231 (make-variable-buffer-local 'erc-server-last-sent-time)
233 (defvar erc-server-last-ping-time nil
234 "Time the last ping was sent.
235 This is useful for flood protection.")
236 (make-variable-buffer-local 'erc-server-last-ping-time)
238 (defvar erc-server-last-received-time nil
239 "Time the last message was received from the server.
240 This is useful for detecting hung connections.")
241 (make-variable-buffer-local 'erc-server-last-received-time)
243 (defvar erc-server-lag nil
244 "Calculated server lag time in seconds.
245 This variable is only set in a server buffer.")
246 (make-variable-buffer-local 'erc-server-lag)
248 (defvar erc-server-filter-data nil
249 "The data that arrived from the server
250 but has not been processed yet.")
251 (make-variable-buffer-local 'erc-server-filter-data)
253 (defvar erc-server-duplicates (make-hash-table :test 'equal)
254 "Internal variable used to track duplicate messages.")
255 (make-variable-buffer-local 'erc-server-duplicates)
258 (defvar erc-server-processing-p nil
259 "Non-nil when we're currently processing a message.
261 When ERC receives a private message, it sets up a new buffer for
262 this query. These in turn, though, do start flyspell. This
263 involves starting an external process, in which case Emacs will
264 wait - and when it waits, it does accept other stuff from, say,
265 network exceptions. So, if someone sends you two messages
266 quickly after each other, ispell is started for the first, but
267 might take long enough for the second message to be processed
269 (make-variable-buffer-local 'erc-server-processing-p)
271 (defvar erc-server-flood-last-message 0
272 "When we sent the last message.
273 See `erc-server-flood-margin' for an explanation of the flood
274 protection algorithm.")
275 (make-variable-buffer-local 'erc-server-flood-last-message)
277 (defvar erc-server-flood-queue nil
278 "The queue of messages waiting to be sent to the server.
279 See `erc-server-flood-margin' for an explanation of the flood
280 protection algorithm.")
281 (make-variable-buffer-local 'erc-server-flood-queue)
283 (defvar erc-server-flood-timer nil
284 "The timer to resume sending.")
285 (make-variable-buffer-local 'erc-server-flood-timer)
287 ;;; IRC protocol and misc options
289 (defgroup erc-server nil
290 "Parameters for dealing with IRC servers."
293 (defcustom erc-server-auto-reconnect t
294 "Non-nil means that ERC will attempt to reestablish broken connections.
296 Reconnection will happen automatically for any unexpected disconnection."
300 (defcustom erc-server-reconnect-attempts 2
301 "The number of times that ERC will attempt to reestablish a
302 broken connection, or t to always attempt to reconnect.
304 This only has an effect if `erc-server-auto-reconnect' is non-nil."
306 :type '(choice (const :tag "Always reconnect" t)
309 (defcustom erc-server-reconnect-timeout 1
310 "The amount of time, in seconds, that ERC will wait between
311 successive reconnect attempts.
313 If a key is pressed while ERC is waiting, it will stop waiting."
317 (defcustom erc-split-line-length 440
318 "The maximum length of a single message.
319 If a message exceeds this size, it is broken into multiple ones.
321 IRC allows for lines up to 512 bytes. Two of them are CR LF.
322 And a typical message looks like this:
324 :nicky!uhuser@host212223.dialin.fnordisp.net PRIVMSG #lazybastards :Hello!
326 You can limit here the maximum length of the \"Hello!\" part.
331 (defcustom erc-coding-system-precedence '(utf-8 undecided)
332 "List of coding systems to be preferred when receiving a string from the server.
333 This will only be consulted if the coding system in
334 `erc-server-coding-system' is `undecided'."
337 :type '(repeat coding-system))
339 (defcustom erc-server-coding-system (if (and (fboundp 'coding-system-p)
340 (coding-system-p 'undecided)
341 (coding-system-p 'utf-8))
344 "The default coding system for incoming and outgoing text.
345 This is either a coding system, a cons, a function, or nil.
347 If a cons, the encoding system for outgoing text is in the car
348 and the decoding system for incoming text is in the cdr. The most
349 interesting use for this is to put `undecided' in the cdr. This
350 means that `erc-coding-system-precedence' will be consulted, and the
351 first match there will be used.
353 If a function, it is called with the argument `target' and should
354 return a coding system or a cons as described above.
356 If you need to send non-ASCII text to people not using a client that
357 does decoding on its own, you must tell ERC what encoding to use.
358 Emacs cannot guess it, since it does not know what the people on the
359 other end of the line are using."
361 :type '(choice (const :tag "None" nil)
363 (cons (coding-system :tag "encoding" :value utf-8)
364 (coding-system :tag "decoding" :value undecided))
367 (defcustom erc-encoding-coding-alist nil
368 "Alist of target regexp and coding-system pairs to use.
369 This overrides `erc-server-coding-system' depending on the
370 current target as returned by `erc-default-target'.
372 Example: If you know that the channel #linux-ru uses the coding-system
373 `cyrillic-koi8', then add (\"#linux-ru\" . cyrillic-koi8) to the
376 :type '(repeat (cons (string :tag "Target")
379 (defcustom erc-server-connect-function 'erc-open-network-stream
380 "Function used to initiate a connection.
381 It should take same arguments as `open-network-stream' does."
385 (defcustom erc-server-prevent-duplicates '("301")
386 "Either nil or a list of strings.
387 Each string is a IRC message type, like PRIVMSG or NOTICE.
388 All Message types in that list of subjected to duplicate prevention."
389 :type '(choice (const nil) (list string))
392 (defcustom erc-server-duplicate-timeout 60
393 "The time allowed in seconds between duplicate messages.
395 If two identical messages arrive within this value of one another, the second
400 (defcustom erc-server-timestamp-format "%Y-%m-%d %T"
401 "Timestamp format used with server response messages.
402 This string is processed using `format-time-string'."
409 ;; Most of this is courtesy of Jorgen Schaefer and Circe
410 ;; (http://www.nongnu.org/circe)
412 (defcustom erc-server-flood-margin 10
413 "A margin on how much excess data we send.
414 The flood protection algorithm of ERC works like the one
415 detailed in RFC 2813, section 5.8 \"Flood control of clients\".
417 * If `erc-server-flood-last-message' is less than the current
419 * While `erc-server-flood-last-message' is less than
420 `erc-server-flood-margin' seconds ahead of the current
421 time, send a message, and increase
422 `erc-server-flood-last-message' by
423 `erc-server-flood-penalty' for each message."
427 (defcustom erc-server-flood-penalty 3
428 "How much we penalize a message.
429 See `erc-server-flood-margin' for an explanation of the flood
430 protection algorithm."
436 (defcustom erc-server-send-ping-interval 30
437 "Interval of sending pings to the server, in seconds.
438 If this is set to nil, pinging the server is disabled."
440 :type '(choice (const :tag "Disabled" nil)
441 (integer :tag "Seconds")))
443 (defcustom erc-server-send-ping-timeout 120
444 "If the time between ping and response is greater than this, reconnect.
445 The time is in seconds.
447 This must be greater than or equal to the value for
448 `erc-server-send-ping-interval'.
450 If this is set to nil, never try to reconnect."
452 :type '(choice (const :tag "Disabled" nil)
453 (integer :tag "Seconds")))
455 (defvar erc-server-ping-handler nil
456 "This variable holds the periodic ping timer.")
457 (make-variable-buffer-local 'erc-server-ping-handler)
459 ;;;; Helper functions
462 (defun erc-split-line (longline)
463 "Return a list of lines which are not too long for IRC.
464 The length is specified in `erc-split-line-length'.
466 Currently this is called by `erc-send-input'."
467 (if (< (length longline)
468 erc-split-line-length)
472 (let ((fill-column erc-split-line-length))
473 (fill-region (point-min) (point-max)
475 (split-string (buffer-string) "\n"))))
477 (defun erc-forward-word ()
478 "Moves forward one word, ignoring any subword settings. If no
479 subword-mode is active, then this is (forward-word)."
480 (skip-syntax-forward "^w")
481 (> (skip-syntax-forward "w") 0))
483 (defun erc-word-at-arg-p (pos)
484 "Reports whether the char after a given POS has word syntax.
485 If POS is out of range, the value is nil."
486 (let ((c (char-after pos)))
488 (eq ?w (char-syntax c))
491 (defun erc-bounds-of-word-at-point ()
492 "Returns the bounds of a word at point, or nil if we're not at
493 a word. If no subword-mode is active, then this
494 is (bounds-of-thing-at-point 'word)."
495 (if (or (erc-word-at-arg-p (point))
496 (erc-word-at-arg-p (1- (point))))
498 (let* ((start (progn (skip-syntax-backward "w") (point)))
499 (end (progn (skip-syntax-forward "w") (point))))
503 ;; Used by CTCP functions
504 (defun erc-upcase-first-word (str)
505 "Upcase the first word in STR."
508 (goto-char (point-min))
509 (upcase-region (point) (progn (erc-forward-word) (point)))
512 (defun erc-server-setup-periodical-ping (buffer)
513 "Set up a timer to periodically ping the current server.
514 The current buffer is given by BUFFER."
515 (with-current-buffer buffer
516 (and erc-server-ping-handler (erc-cancel-timer erc-server-ping-handler))
517 (when erc-server-send-ping-interval
518 (setq erc-server-ping-handler (run-with-timer
519 4 erc-server-send-ping-interval
520 #'erc-server-send-ping
523 ;; I check the timer alist for an existing timer. If one exists,
525 (let ((timer-tuple (assq buffer erc-server-ping-timer-alist)))
527 ;; this buffer already has a timer. Cancel it and set the new one
529 (erc-cancel-timer (cdr timer-tuple))
530 (setf (cdr (assq buffer erc-server-ping-timer-alist)) erc-server-ping-handler))
532 ;; no existing timer for this buffer. Add new one
533 (add-to-list 'erc-server-ping-timer-alist
534 (cons buffer erc-server-ping-handler)))))))
536 (defun erc-server-process-alive (&optional buffer)
537 "Return non-nil when BUFFER has an `erc-server-process' open or running."
538 (with-current-buffer (or buffer (current-buffer))
539 (and erc-server-process
540 (processp erc-server-process)
541 (memq (process-status erc-server-process) '(run open)))))
543 ;;;; Connecting to a server
544 (defun erc-open-network-stream (name buffer host service)
545 "As `open-network-stream', but does non-blocking IO"
546 (make-network-process :name name :buffer buffer
547 :host host :service service :nowait t))
549 (defun erc-server-connect (server port buffer)
550 "Perform the connection and login using the specified SERVER and PORT.
551 We will store server variables in the buffer given by BUFFER."
552 (let ((msg (erc-format-message 'connect ?S server ?p port)))
554 (let ((process (funcall erc-server-connect-function
555 (format "erc-%s-%s" server port)
557 (unless (processp process)
558 (error "Connection attempt failed"))
559 (message "%s...done" msg)
560 ;; Misc server variables
561 (with-current-buffer buffer
562 (setq erc-server-process process)
563 (setq erc-server-quitting nil)
564 (setq erc-server-reconnecting nil)
565 (setq erc-server-timed-out nil)
566 (setq erc-server-banned nil)
567 (setq erc-server-error-occurred nil)
568 (let ((time (erc-current-time)))
569 (setq erc-server-last-sent-time time)
570 (setq erc-server-last-ping-time time)
571 (setq erc-server-last-received-time time))
572 (setq erc-server-lines-sent 0)
573 ;; last peers (sender and receiver)
574 (setq erc-server-last-peers '(nil . nil)))
575 ;; we do our own encoding and decoding
576 (when (fboundp 'set-process-coding-system)
577 (set-process-coding-system process 'raw-text))
579 (set-process-sentinel process 'erc-process-sentinel)
580 (set-process-filter process 'erc-server-filter-function)
581 (set-process-buffer process buffer)))
582 (erc-log "\n\n\n********************************************\n")
583 (message "%s" (erc-format-message
585 (with-current-buffer buffer (erc-current-nick))))
586 ;; wait with script loading until we receive a confirmation (first
588 (if (eq erc-server-connect-function 'open-network-stream-nowait)
589 ;; it's a bit unclear otherwise that it's attempting to establish a
591 (erc-display-message nil nil buffer "Opening connection..\n")
594 (defun erc-server-reconnect ()
595 "Reestablish the current IRC connection.
596 Make sure you are in an ERC buffer when running this."
597 (let ((buffer (erc-server-buffer)))
598 (unless (buffer-live-p buffer)
599 (if (eq major-mode 'erc-mode)
600 (setq buffer (current-buffer))
601 (error "Reconnect must be run from an ERC buffer")))
602 (with-current-buffer buffer
603 (erc-update-mode-line)
604 (erc-set-active-buffer (current-buffer))
605 (setq erc-server-last-sent-time 0)
606 (setq erc-server-lines-sent 0)
607 (let ((erc-server-connect-function (or erc-session-connector
608 'erc-open-network-stream)))
609 (erc-open erc-session-server erc-session-port erc-server-current-nick
610 erc-session-user-full-name t erc-session-password)))))
612 (defun erc-server-delayed-reconnect (event buffer)
613 (if (buffer-live-p buffer)
614 (with-current-buffer buffer
615 (erc-server-reconnect))))
617 (defun erc-server-filter-function (process string)
618 "The process filter for the ERC server."
619 (with-current-buffer (process-buffer process)
620 (setq erc-server-last-received-time (erc-current-time))
621 ;; If you think this is written in a weird way - please refer to the
622 ;; docstring of `erc-server-processing-p'
623 (if erc-server-processing-p
624 (setq erc-server-filter-data
625 (if erc-server-filter-data
626 (concat erc-server-filter-data string)
628 ;; This will be true even if another process is spawned!
629 (let ((erc-server-processing-p t))
630 (setq erc-server-filter-data (if erc-server-filter-data
631 (concat erc-server-filter-data
634 (while (and erc-server-filter-data
635 (string-match "[\n\r]+" erc-server-filter-data))
636 (let ((line (substring erc-server-filter-data
637 0 (match-beginning 0))))
638 (setq erc-server-filter-data
640 (length erc-server-filter-data))
642 (substring erc-server-filter-data
644 (erc-log-irc-protocol line nil)
645 (erc-parse-server-response process line)))))))
647 (defsubst erc-server-reconnect-p (event)
648 "Return non-nil if ERC should attempt to reconnect automatically.
649 EVENT is the message received from the closed connection process."
650 (or erc-server-reconnecting
651 (and erc-server-auto-reconnect
652 (not erc-server-banned)
653 (not erc-server-error-occurred)
654 ;; make sure we don't infinitely try to reconnect, unless the
656 (or (eq erc-server-reconnect-attempts t)
657 (and (integerp erc-server-reconnect-attempts)
658 (< erc-server-reconnect-count
659 erc-server-reconnect-attempts)))
660 (or erc-server-timed-out
661 (not (string-match "^deleted" event)))
662 ;; open-network-stream-nowait error for connection refused
663 (if (string-match "^failed with code 111" event) 'nonblocking t))))
665 (defun erc-process-sentinel-2 (event buffer)
666 "Called when `erc-process-sentinel-1' has detected an unexpected disconnect."
667 (if (not (buffer-live-p buffer))
668 (erc-update-mode-line)
669 (with-current-buffer buffer
670 (let ((reconnect-p (erc-server-reconnect-p event)) message delay)
671 (setq message (if reconnect-p 'disconnected 'disconnected-noreconnect))
672 (erc-display-message nil 'error (current-buffer) message)
673 (if (not reconnect-p)
674 ;; terminate, do not reconnect
676 (erc-display-message nil 'error (current-buffer)
677 'terminated ?e event)
678 ;; Update mode line indicators
679 (erc-update-mode-line)
680 (set-buffer-modified-p nil))
684 (setq erc-server-reconnecting nil
685 erc-server-reconnect-count (1+ erc-server-reconnect-count))
686 (setq delay erc-server-reconnect-timeout)
687 (run-at-time delay nil
688 #'erc-server-delayed-reconnect event buffer))
689 (error (unless (integerp erc-server-reconnect-attempts)
691 "Reconnecting until we succeed"
692 "kill the ERC server buffer to stop"))
693 (erc-server-delayed-reconnect event buffer))))))))
695 (defun erc-process-sentinel-1 (event buffer)
696 "Called when `erc-process-sentinel' has decided that we're disconnecting.
697 Determine whether user has quit or whether erc has been terminated.
698 Conditionally try to reconnect and take appropriate action."
699 (with-current-buffer buffer
700 (if erc-server-quitting
703 (erc-display-message nil 'error (current-buffer) 'finished)
704 ;; Update mode line indicators
705 (erc-update-mode-line)
706 ;; Kill server buffer if user wants it
707 (set-buffer-modified-p nil)
708 (when erc-kill-server-buffer-on-quit
709 (kill-buffer (current-buffer))))
710 ;; unexpected disconnect
711 (erc-process-sentinel-2 event buffer))))
713 (defun erc-process-sentinel (cproc event)
714 "Sentinel function for ERC process."
715 (let ((buf (process-buffer cproc)))
716 (when (buffer-live-p buf)
717 (with-current-buffer buf
719 "SENTINEL: proc: %S status: %S event: %S (quitting: %S)"
720 cproc (process-status cproc) event erc-server-quitting))
721 (if (string-match "^open" event)
722 ;; newly opened connection (no wait)
724 ;; assume event is 'failed
725 (erc-with-all-buffers-of-server cproc nil
726 (setq erc-server-connected nil))
727 (when erc-server-ping-handler
728 (progn (erc-cancel-timer erc-server-ping-handler)
729 (setq erc-server-ping-handler nil)))
730 (run-hook-with-args 'erc-disconnected-hook
731 (erc-current-nick) (system-name) "")
732 (dolist (buf (erc-buffer-filter (lambda () (boundp 'erc-channel-users)) cproc))
733 (with-current-buffer buf
734 (setq erc-channel-users (make-hash-table :test 'equal))))
736 (goto-char (or (marker-position erc-input-marker) (point-max)))
738 (erc-remove-text-properties-region (point) (point-max))
739 (delete-region (point) (point-max))
740 ;; Decide what to do with the buffer
741 ;; Restart if disconnected
742 (erc-process-sentinel-1 event buf))))))
744 ;;;; Sending messages
746 (defun erc-coding-system-for-target (target)
747 "Return the coding system or cons cell appropriate for TARGET.
748 This is determined via `erc-encoding-coding-alist' or
749 `erc-server-coding-system'."
750 (unless target (setq target (erc-default-target)))
752 (let ((case-fold-search t))
754 (dolist (pat erc-encoding-coding-alist)
755 (when (string-match (car pat) target)
756 (throw 'match (cdr pat)))))))
757 (and (functionp erc-server-coding-system)
758 (funcall erc-server-coding-system target))
759 erc-server-coding-system))
761 (defun erc-decode-string-from-target (str target)
762 "Decode STR as appropriate for TARGET.
763 This is indicated by `erc-encoding-coding-alist', defaulting to the value of
764 `erc-server-coding-system'."
765 (unless (stringp str)
767 (let ((coding (erc-coding-system-for-target target)))
769 (setq coding (cdr coding)))
770 (when (eq coding 'undecided)
771 (let ((codings (detect-coding-string str))
772 (precedence erc-coding-system-precedence))
773 (while (and precedence
774 (not (memq (car precedence) codings)))
777 (setq coding (car precedence)))))
778 (erc-decode-coding-string str coding)))
780 ;; proposed name, not used by anything yet
781 (defun erc-send-line (text display-fn)
782 "Send TEXT to the current server. Wrapping and flood control apply.
783 Use DISPLAY-FN to show the results."
785 (erc-server-send line)
786 (funcall display-fn))
787 (erc-split-line text)))
789 ;; From Circe, with modifications
790 (defun erc-server-send (string &optional forcep target)
791 "Send STRING to the current server.
792 If FORCEP is non-nil, no flood protection is done - the string is
793 sent directly. This might cause the messages to arrive in a wrong
796 If TARGET is specified, look up encoding information for that
797 channel in `erc-encoding-coding-alist' or
798 `erc-server-coding-system'.
800 See `erc-server-flood-margin' for an explanation of the flood
801 protection algorithm."
802 (erc-log (concat "erc-server-send: " string "(" (buffer-name) ")"))
803 (setq erc-server-last-sent-time (erc-current-time))
804 (let ((encoding (erc-coding-system-for-target target)))
805 (when (consp encoding)
806 (setq encoding (car encoding)))
807 (if (erc-server-process-alive)
808 (erc-with-server-buffer
809 (let ((str (concat string "\r\n")))
812 (setq erc-server-flood-last-message
813 (+ erc-server-flood-penalty
814 erc-server-flood-last-message))
815 (erc-log-irc-protocol str 'outbound)
818 ;; Set encoding just before sending the string
819 (when (fboundp 'set-process-coding-system)
820 (set-process-coding-system erc-server-process
822 (process-send-string erc-server-process str))
823 ;; See `erc-server-send-queue' for full
824 ;; explanation of why we need this condition-case
826 (setq erc-server-flood-queue
827 (append erc-server-flood-queue
828 (list (cons str encoding))))
829 (erc-server-send-queue (current-buffer))))
831 (message "ERC: No process running")
834 (defun erc-server-send-ping (buf)
835 "Send a ping to the IRC server buffer in BUF.
836 Additionally, detect whether the IRC process has hung."
837 (if (and (buffer-live-p buf)
838 (with-current-buffer buf
839 erc-server-last-received-time))
840 (with-current-buffer buf
841 (if (and erc-server-send-ping-timeout
843 (erc-time-diff (erc-current-time)
844 erc-server-last-received-time)
845 erc-server-send-ping-timeout))
847 ;; if the process is hung, kill it
848 (setq erc-server-timed-out t)
849 (delete-process erc-server-process))
850 (erc-server-send (format "PING %.0f" (erc-current-time)))))
851 ;; remove timer if the server buffer has been killed
852 (let ((timer (assq buf erc-server-ping-timer-alist)))
854 (erc-cancel-timer (cdr timer))
855 (setcdr timer nil)))))
858 (defun erc-server-send-queue (buffer)
859 "Send messages in `erc-server-flood-queue'.
860 See `erc-server-flood-margin' for an explanation of the flood
861 protection algorithm."
862 (with-current-buffer buffer
863 (let ((now (erc-current-time)))
864 (when erc-server-flood-timer
865 (erc-cancel-timer erc-server-flood-timer)
866 (setq erc-server-flood-timer nil))
867 (when (< erc-server-flood-last-message
869 (setq erc-server-flood-last-message now))
870 (while (and erc-server-flood-queue
871 (< erc-server-flood-last-message
872 (+ now erc-server-flood-margin)))
873 (let ((msg (caar erc-server-flood-queue))
874 (encoding (cdar erc-server-flood-queue)))
875 (setq erc-server-flood-queue (cdr erc-server-flood-queue)
876 erc-server-flood-last-message
877 (+ erc-server-flood-last-message
878 erc-server-flood-penalty))
879 (erc-log-irc-protocol msg 'outbound)
880 (erc-log (concat "erc-server-send-queue: "
881 msg "(" (buffer-name buffer) ")"))
882 (when (erc-server-process-alive)
884 ;; Set encoding just before sending the string
886 (when (fboundp 'set-process-coding-system)
887 (set-process-coding-system erc-server-process
889 (process-send-string erc-server-process msg))
890 ;; Sometimes the send can occur while the process is
891 ;; being killed, which results in a weird SIGPIPE error.
892 ;; Catch this and ignore it.
894 (when erc-server-flood-queue
895 (setq erc-server-flood-timer
896 (run-at-time (+ 0.2 erc-server-flood-penalty)
897 nil #'erc-server-send-queue buffer))))))
899 (defun erc-message (message-command line &optional force)
900 "Send LINE to the server as a privmsg or a notice.
901 MESSAGE-COMMAND should be either \"PRIVMSG\" or \"NOTICE\".
902 If the target is \",\", the last person you've got a message from will
903 be used. If the target is \".\", the last person you've sent a message
906 ((string-match "^\\s-*\\(\\S-+\\) ?\\(.*\\)" line)
907 (let ((tgt (match-string 1 line))
908 (s (match-string 2 line)))
909 (erc-log (format "cmd: MSG(%s): [%s] %s" message-command tgt s))
912 (if (car erc-server-last-peers)
913 (setq tgt (car erc-server-last-peers))
916 (if (cdr erc-server-last-peers)
917 (setq tgt (cdr erc-server-last-peers))
921 (setcdr erc-server-last-peers tgt)
922 (erc-server-send (format "%s %s :%s" message-command tgt s)
925 (erc-display-message nil 'error (current-buffer) 'no-target))))
931 (defun erc-send-ctcp-message (tgt l &optional force)
932 "Send CTCP message L to TGT.
934 If TGT is nil the message is not sent.
935 The command must contain neither a prefix nor a trailing `\\n'.
937 See also `erc-server-send'."
938 (let ((l (erc-upcase-first-word l)))
941 (erc-log (format "erc-send-CTCP-message: [%s] %s" tgt l))
942 (erc-server-send (format "PRIVMSG %s :\C-a%s\C-a" tgt l)
945 (defun erc-send-ctcp-notice (tgt l &optional force)
946 "Send CTCP notice L to TGT.
948 If TGT is nil the message is not sent.
949 The command must contain neither a prefix nor a trailing `\\n'.
951 See also `erc-server-send'."
952 (let ((l (erc-upcase-first-word l)))
955 (erc-log (format "erc-send-CTCP-notice: [%s] %s" tgt l))
956 (erc-server-send (format "NOTICE %s :\C-a%s\C-a" tgt l)
959 ;;;; Handling responses
961 (defun erc-parse-server-response (proc string)
962 "Parse and act upon a complete line from an IRC server.
963 PROC is the process (connection) from which STRING was received.
964 PROCs `process-buffer' is `current-buffer' when this function is called."
965 (unless (string= string "") ;; Ignore empty strings
967 (let ((posn (if (eq (aref string 0) ?:)
968 (string-match " " string)
970 (msg (make-erc-response :unparsed string)))
972 (setf (erc-response.sender msg)
975 (substring string 1 posn)))
977 (setf (erc-response.command msg)
978 (let* ((bposn (string-match "[^ \n]" string posn))
979 (eposn (string-match " " string bposn)))
980 (setq posn (and eposn
981 (string-match "[^ \n]" string eposn)))
982 (substring string bposn eposn)))
985 (not (eq (aref string posn) ?:)))
986 (push (let* ((bposn posn)
987 (eposn (string-match " " string bposn)))
988 (setq posn (and eposn
989 (string-match "[^ \n]" string eposn)))
990 (substring string bposn eposn))
991 (erc-response.command-args msg)))
993 (let ((str (substring string (1+ posn))))
994 (push str (erc-response.command-args msg))))
996 (setf (erc-response.contents msg)
997 (car (erc-response.command-args msg)))
999 (setf (erc-response.command-args msg)
1000 (nreverse (erc-response.command-args msg)))
1002 (erc-decode-parsed-server-response msg)
1004 (erc-handle-parsed-server-response proc msg)))))
1006 (defun erc-decode-parsed-server-response (parsed-response)
1007 "Decode a pre-parsed PARSED-RESPONSE before it can be handled.
1009 If there is a channel name in `erc-response.command-args', decode
1010 `erc-response' according to this channel name and
1011 `erc-encoding-coding-alist', or use `erc-server-coding-system'
1013 (let ((args (erc-response.command-args parsed-response))
1016 (dolist (arg args nil)
1017 (when (string-match "^[#&].*" arg)
1018 (setq decode-target arg)))
1019 (when (stringp decode-target)
1020 (setq decode-target (erc-decode-string-from-target decode-target nil)))
1021 (setf (erc-response.unparsed parsed-response)
1022 (erc-decode-string-from-target
1023 (erc-response.unparsed parsed-response)
1025 (setf (erc-response.sender parsed-response)
1026 (erc-decode-string-from-target
1027 (erc-response.sender parsed-response)
1029 (setf (erc-response.command parsed-response)
1030 (erc-decode-string-from-target
1031 (erc-response.command parsed-response)
1033 (dolist (arg (nreverse args) nil)
1034 (push (erc-decode-string-from-target arg decode-target)
1036 (setf (erc-response.command-args parsed-response) decoded-args)
1037 (setf (erc-response.contents parsed-response)
1038 (erc-decode-string-from-target
1039 (erc-response.contents parsed-response)
1042 (defun erc-handle-parsed-server-response (process parsed-response)
1043 "Handle a pre-parsed PARSED-RESPONSE from PROCESS.
1045 Hands off to helper functions via `erc-call-hooks'."
1046 (if (member (erc-response.command parsed-response)
1047 erc-server-prevent-duplicates)
1048 (let ((m (erc-response.unparsed parsed-response)))
1049 ;; duplicate suppression
1050 (if (< (or (gethash m erc-server-duplicates) 0)
1051 (- (erc-current-time) erc-server-duplicate-timeout))
1052 (erc-call-hooks process parsed-response))
1053 (puthash m (erc-current-time) erc-server-duplicates))
1054 ;; Hand off to the relevant handler.
1055 (erc-call-hooks process parsed-response)))
1057 (defun erc-get-hook (command)
1058 "Return the hook variable associated with COMMAND.
1060 See also `erc-server-responses'."
1061 (gethash (format (if (numberp command) "%03i" "%s") command)
1062 erc-server-responses))
1064 (defun erc-call-hooks (process message)
1065 "Call hooks associated with MESSAGE in PROCESS.
1067 Finds hooks by looking in the `erc-server-responses' hashtable."
1068 (let ((hook (or (erc-get-hook (erc-response.command message))
1069 'erc-default-server-functions)))
1070 (run-hook-with-args-until-success hook process message)
1071 (erc-with-server-buffer
1072 (run-hook-with-args 'erc-timer-hook (erc-current-time)))))
1074 (add-hook 'erc-default-server-functions 'erc-handle-unknown-server-response)
1076 (defun erc-handle-unknown-server-response (proc parsed)
1077 "Display unknown server response's message."
1078 (let ((line (concat (erc-response.sender parsed)
1080 (erc-response.command parsed)
1082 (mapconcat 'identity (erc-response.command-args parsed)
1084 (erc-display-message parsed 'notice proc line)))
1087 (put 'define-erc-response-handler 'edebug-form-spec
1088 '(&define :name erc-response-handler
1090 &optional sexp sexp def-body))
1092 (cl-defmacro define-erc-response-handler ((name &rest aliases)
1093 &optional extra-fn-doc extra-var-doc
1095 "Define an ERC handler hook/function pair.
1096 NAME is the response name as sent by the server (see the IRC RFC for
1100 - a hook variable `erc-server-NAME-functions' initialized to `erc-server-NAME'.
1101 - a function `erc-server-NAME' with body FN-BODY.
1103 If ALIASES is non-nil, each alias in ALIASES is `defalias'ed to
1105 Alias hook variables are created as `erc-server-ALIAS-functions' and
1106 initialized to the same default value as `erc-server-NAME-functions'.
1108 FN-BODY is the body of `erc-server-NAME' it may refer to the two
1109 function arguments PROC and PARSED.
1111 If EXTRA-FN-DOC is non-nil, it is inserted at the beginning of the
1112 defined function's docstring.
1114 If EXTRA-VAR-DOC is non-nil, it is inserted at the beginning of the
1115 defined variable's docstring.
1119 (define-erc-response-handler (311 WHOIS WI)
1120 \"Some non-generic function documentation.\"
1121 \"Some non-generic variable documentation.\"
1122 (do-stuff-with-whois proc parsed))
1127 (defvar erc-server-311-functions \\='erc-server-311
1128 \"Some non-generic variable documentation.
1130 Hook called upon receiving a 311 server response.
1131 Each function is called with two arguments, the process associated
1132 with the response and the parsed response.
1133 See also `erc-server-311'.\")
1135 (defun erc-server-311 (proc parsed)
1136 \"Some non-generic function documentation.
1138 Handler for a 311 server response.
1139 PROC is the server process which returned the response.
1140 PARSED is the actual response as an `erc-response' struct.
1141 If you want to add responses don't modify this function, but rather
1142 add things to `erc-server-311-functions' instead.\"
1143 (do-stuff-with-whois proc parsed))
1145 (puthash \"311\" \\='erc-server-311-functions erc-server-responses)
1146 (puthash \"WHOIS\" \\='erc-server-WHOIS-functions erc-server-responses)
1147 (puthash \"WI\" \\='erc-server-WI-functions erc-server-responses)
1149 (defalias \\='erc-server-WHOIS \\='erc-server-311)
1150 (defvar erc-server-WHOIS-functions \\='erc-server-311
1151 \"Some non-generic variable documentation.
1153 Hook called upon receiving a WHOIS server response.
1155 Each function is called with two arguments, the process associated
1156 with the response and the parsed response. If the function returns
1157 non-nil, stop processing the hook. Otherwise, continue.
1159 See also `erc-server-311'.\")
1161 (defalias \\='erc-server-WI \\='erc-server-311)
1162 (defvar erc-server-WI-functions \\='erc-server-311
1163 \"Some non-generic variable documentation.
1165 Hook called upon receiving a WI server response.
1166 Each function is called with two arguments, the process associated
1167 with the response and the parsed response. If the function returns
1168 non-nil, stop processing the hook. Otherwise, continue.
1170 See also `erc-server-311'.\"))
1172 \(fn (NAME &rest ALIASES) &optional EXTRA-FN-DOC EXTRA-VAR-DOC &rest FN-BODY)"
1173 (if (numberp name) (setq name (intern (format "%03i" name))))
1174 (setq aliases (mapcar (lambda (a)
1179 (let* ((hook-name (intern (format "erc-server-%s-functions" name)))
1180 (fn-name (intern (format "erc-server-%s" name)))
1181 (hook-doc (format-message "\
1182 %sHook called upon receiving a %%s server response.
1183 Each function is called with two arguments, the process associated
1184 with the response and the parsed response. If the function returns
1185 non-nil, stop processing the hook. Otherwise, continue.
1189 (concat extra-var-doc "\n\n")
1192 (fn-doc (format-message "\
1193 %sHandler for a %s server response.
1194 PROC is the server process which returned the response.
1195 PARSED is the actual response as an `erc-response' struct.
1196 If you want to add responses don't modify this function, but rather
1197 add things to `%s' instead."
1199 (concat extra-fn-doc "\n\n")
1203 (cl-loop for alias in aliases
1204 collect (intern (format "erc-server-%s" alias))))
1206 (cl-loop for alias in aliases
1207 collect (intern (format "erc-server-%s-functions" alias)))))
1209 ;; Normal hook variable. The variable may already have a
1210 ;; value at this point, so I default to nil, and (add-hook)
1212 (defvar ,hook-name nil ,(format hook-doc name))
1213 (add-to-list ',hook-name ',fn-name)
1215 (defun ,fn-name (proc parsed)
1219 ;; Make find-function and find-variable find them
1220 (put ',fn-name 'definition-name ',name)
1221 (put ',hook-name 'definition-name ',name)
1223 ;; Hashtable map of responses to hook variables
1224 ,@(cl-loop for response in (cons name aliases)
1225 for var in (cons hook-name var-alternates)
1226 collect `(puthash ,(format "%s" response) ',var
1227 erc-server-responses))
1229 ;; Functions are defaliased, hook variables are defvared so we
1230 ;; can add hooks to one alias, but not another.
1231 ,@(cl-loop for fn in fn-alternates
1232 for var in var-alternates
1234 nconc (list `(defalias ',fn ',fn-name)
1235 `(defvar ,var ',fn-name ,(format hook-doc a))
1236 `(put ',var 'definition-name ',hook-name))))))
1238 (define-erc-response-handler (ERROR)
1239 "Handle an ERROR command from the server." nil
1240 (setq erc-server-error-occurred t)
1241 (erc-display-message
1242 parsed 'error nil 'ERROR
1243 ?s (erc-response.sender parsed) ?c (erc-response.contents parsed)))
1245 (define-erc-response-handler (INVITE)
1246 "Handle invitation messages."
1248 (let ((target (car (erc-response.command-args parsed)))
1249 (chnl (erc-response.contents parsed)))
1250 (pcase-let ((`(,nick ,login ,host)
1251 (erc-parse-user (erc-response.sender parsed))))
1252 (setq erc-invitation chnl)
1253 (when (string= target (erc-current-nick))
1254 (erc-display-message
1255 parsed 'notice 'active
1256 'INVITE ?n nick ?u login ?h host ?c chnl)))))
1258 (define-erc-response-handler (JOIN)
1259 "Handle join messages."
1261 (let ((chnl (erc-response.contents parsed))
1263 (pcase-let ((`(,nick ,login ,host)
1264 (erc-parse-user (erc-response.sender parsed))))
1265 ;; strip the stupid combined JOIN facility (IRC 2.9)
1266 (if (string-match "^\\(.*\\)?\^g.*$" chnl)
1267 (setq chnl (match-string 1 chnl)))
1270 ;; If I have joined a channel
1271 ((erc-current-nick-p nick)
1272 (setq buffer (erc-open erc-session-server erc-session-port
1273 nick erc-session-user-full-name
1276 erc-server-process))
1279 (erc-add-default-channel chnl)
1280 (erc-server-send (format "MODE %s" chnl)))
1281 (erc-with-buffer (chnl proc)
1282 (erc-channel-begin-receiving-names))
1283 (erc-update-mode-line)
1284 (run-hooks 'erc-join-hook)
1286 (erc-format-message 'JOIN-you ?c chnl)))
1288 (setq buffer (erc-get-buffer chnl proc))
1291 'JOIN ?n nick ?u login ?h host ?c chnl))))))
1292 (when buffer (set-buffer buffer))
1293 (erc-update-channel-member chnl nick nick t nil nil nil nil nil host login)
1294 ;; on join, we want to stay in the new channel buffer
1296 (erc-display-message parsed nil buffer str))))))
1298 (define-erc-response-handler (KICK)
1299 "Handle kick messages received from the server." nil
1300 (let* ((ch (nth 0 (erc-response.command-args parsed)))
1301 (tgt (nth 1 (erc-response.command-args parsed)))
1302 (reason (erc-trim-string (erc-response.contents parsed)))
1303 (buffer (erc-get-buffer ch proc)))
1304 (pcase-let ((`(,nick ,login ,host)
1305 (erc-parse-user (erc-response.sender parsed))))
1306 (erc-remove-channel-member buffer tgt)
1308 ((string= tgt (erc-current-nick))
1309 (erc-display-message
1310 parsed 'notice buffer
1311 'KICK-you ?n nick ?u login ?h host ?c ch ?r reason)
1312 (run-hook-with-args 'erc-kick-hook buffer)
1315 (erc-remove-channel-users))
1316 (erc-delete-default-channel ch buffer)
1317 (erc-update-mode-line buffer))
1318 ((string= nick (erc-current-nick))
1319 (erc-display-message
1320 parsed 'notice buffer
1321 'KICK-by-you ?k tgt ?c ch ?r reason))
1322 (t (erc-display-message
1323 parsed 'notice buffer
1324 'KICK ?k tgt ?n nick ?u login ?h host ?c ch ?r reason))))))
1326 (define-erc-response-handler (MODE)
1327 "Handle server mode changes." nil
1328 (let ((tgt (car (erc-response.command-args parsed)))
1329 (mode (mapconcat 'identity (cdr (erc-response.command-args parsed))
1331 (pcase-let ((`(,nick ,login ,host)
1332 (erc-parse-user (erc-response.sender parsed))))
1333 (erc-log (format "MODE: %s -> %s: %s" nick tgt mode))
1335 (let ((buf (cond ((erc-channel-p tgt)
1336 (erc-get-buffer tgt proc))
1337 ((string= tgt (erc-current-nick)) nil)
1338 ((erc-active-buffer) (erc-active-buffer))
1339 (t (erc-get-buffer tgt)))))
1340 (with-current-buffer (or buf
1342 (erc-update-modes tgt mode nick host login))
1343 (if (or (string= login "") (string= host ""))
1344 (erc-display-message parsed 'notice buf
1347 (erc-display-message parsed 'notice buf
1348 'MODE ?n nick ?u login
1349 ?h host ?t tgt ?m mode)))
1350 (erc-banlist-update proc parsed))))
1352 (define-erc-response-handler (NICK)
1353 "Handle nick change messages." nil
1354 (let ((nn (erc-response.contents parsed))
1356 (pcase-let ((`(,nick ,login ,host)
1357 (erc-parse-user (erc-response.sender parsed))))
1358 (setq bufs (erc-buffer-list-with-nick nick proc))
1359 (erc-log (format "NICK: %s -> %s" nick nn))
1360 ;; if we had a query with this user, make sure future messages will be
1361 ;; sent to the correct nick. also add to bufs, since the user will want
1362 ;; to see the nick change in the query, and if it's a newly begun query,
1363 ;; erc-channel-users won't contain it
1366 (when (equal (erc-default-target) nick)
1367 (setq erc-default-recipients
1368 (cons nn (cdr erc-default-recipients)))
1369 (rename-buffer nn t) ; bug#12002
1370 (erc-update-mode-line)
1371 (add-to-list 'bufs (current-buffer)))))
1372 (erc-update-user-nick nick nn host nil nil login)
1374 ((string= nick (erc-current-nick))
1375 (add-to-list 'bufs (erc-server-buffer))
1376 (erc-set-current-nick nn)
1377 (erc-update-mode-line)
1378 (setq erc-nick-change-attempt-count 0)
1379 (setq erc-default-nicks (if (consp erc-nick) erc-nick (list erc-nick)))
1380 (erc-display-message
1382 'NICK-you ?n nick ?N nn)
1383 (run-hook-with-args 'erc-nick-changed-functions nn nick))
1385 (erc-handle-user-status-change 'nick (list nick login host) (list nn))
1386 (erc-display-message parsed 'notice bufs 'NICK ?n nick
1387 ?u login ?h host ?N nn))))))
1389 (define-erc-response-handler (PART)
1390 "Handle part messages." nil
1391 (let* ((chnl (car (erc-response.command-args parsed)))
1392 (reason (erc-trim-string (erc-response.contents parsed)))
1393 (buffer (erc-get-buffer chnl proc)))
1394 (pcase-let ((`(,nick ,login ,host)
1395 (erc-parse-user (erc-response.sender parsed))))
1396 (erc-remove-channel-member buffer nick)
1397 (erc-display-message parsed 'notice buffer
1398 'PART ?n nick ?u login
1399 ?h host ?c chnl ?r (or reason ""))
1400 (when (string= nick (erc-current-nick))
1401 (run-hook-with-args 'erc-part-hook buffer)
1404 (erc-remove-channel-users))
1405 (erc-delete-default-channel chnl buffer)
1406 (erc-update-mode-line buffer)
1407 (when erc-kill-buffer-on-part
1408 (kill-buffer buffer))))))
1410 (define-erc-response-handler (PING)
1411 "Handle ping messages." nil
1412 (let ((pinger (car (erc-response.command-args parsed))))
1413 (erc-log (format "PING: %s" pinger))
1414 ;; ping response to the server MUST be forced, or you can lose big
1415 (erc-server-send (format "PONG :%s" pinger) t)
1416 (when erc-verbose-server-ping
1417 (erc-display-message
1419 'PING ?s (erc-time-diff erc-server-last-ping-time (erc-current-time))))
1420 (setq erc-server-last-ping-time (erc-current-time))))
1422 (define-erc-response-handler (PONG)
1423 "Handle pong messages." nil
1424 (let ((time (string-to-number (erc-response.contents parsed))))
1426 (setq erc-server-lag (erc-time-diff time (erc-current-time)))
1427 (when erc-verbose-server-ping
1428 (erc-display-message
1429 parsed 'notice proc 'PONG
1430 ?h (car (erc-response.command-args parsed)) ?i erc-server-lag
1431 ?s (if (/= erc-server-lag 1) "s" "")))
1432 (erc-update-mode-line))))
1434 (define-erc-response-handler (PRIVMSG NOTICE)
1435 "Handle private messages, including messages in channels." nil
1436 (let ((sender-spec (erc-response.sender parsed))
1437 (cmd (erc-response.command parsed))
1438 (tgt (car (erc-response.command-args parsed)))
1439 (msg (erc-response.contents parsed)))
1440 (if (or (erc-ignored-user-p sender-spec)
1441 (erc-ignored-reply-p msg tgt proc))
1442 (when erc-minibuffer-ignored
1443 (message "Ignored %s from %s to %s" cmd sender-spec tgt))
1444 (let* ((sndr (erc-parse-user sender-spec))
1446 (login (nth 1 sndr))
1448 (msgp (string= cmd "PRIVMSG"))
1449 (noticep (string= cmd "NOTICE"))
1450 ;; S.B. downcase *both* tgt and current nick
1451 (privp (erc-current-nick-p tgt))
1454 (setf (erc-response.contents parsed) msg)
1455 (setq buffer (erc-get-buffer (if privp nick tgt) proc))
1457 (with-current-buffer buffer
1458 ;; update the chat partner info. Add to the list if private
1459 ;; message. We will accumulate private identities indefinitely
1461 (erc-update-channel-member (if privp nick tgt) nick nick
1462 privp nil nil nil nil nil host login nil nil t)
1463 (let ((cdata (erc-get-channel-user nick)))
1464 (setq fnick (funcall erc-format-nick-function
1465 (car cdata) (cdr cdata))))))
1467 ((erc-is-message-ctcp-p msg)
1469 (erc-process-ctcp-query proc parsed nick login host)
1470 (erc-process-ctcp-reply proc parsed nick login host
1471 (match-string 1 msg)))))
1473 (setcar erc-server-last-peers nick)
1474 (setq s (erc-format-privmessage
1476 ;; If buffer is a query buffer,
1477 ;; format the nick as for a channel.
1478 (and (not (and buffer
1479 (erc-query-buffer-p buffer)
1480 erc-format-query-as-channel-p))
1484 (if (and noticep privp)
1486 (run-hook-with-args 'erc-echo-notice-always-hook
1487 s parsed buffer nick)
1488 (run-hook-with-args-until-success
1489 'erc-echo-notice-hook s parsed buffer nick))
1490 (erc-display-message parsed nil buffer s)))
1491 (when (string= cmd "PRIVMSG")
1492 (erc-auto-query proc parsed))))))
1494 ;; FIXME: need clean way of specifying extra hooks in
1495 ;; define-erc-response-handler.
1496 (add-hook 'erc-server-PRIVMSG-functions 'erc-auto-query)
1498 (define-erc-response-handler (QUIT)
1499 "Another user has quit IRC." nil
1500 (let ((reason (erc-response.contents parsed))
1502 (pcase-let ((`(,nick ,login ,host)
1503 (erc-parse-user (erc-response.sender parsed))))
1504 (setq bufs (erc-buffer-list-with-nick nick proc))
1505 (erc-remove-user nick)
1506 (setq reason (erc-wash-quit-reason reason nick login host))
1507 (erc-display-message parsed 'notice bufs
1508 'QUIT ?n nick ?u login
1509 ?h host ?r reason))))
1511 (define-erc-response-handler (TOPIC)
1512 "The channel topic has changed." nil
1513 (let* ((ch (car (erc-response.command-args parsed)))
1514 (topic (erc-trim-string (erc-response.contents parsed)))
1515 (time (format-time-string erc-server-timestamp-format)))
1516 (pcase-let ((`(,nick ,login ,host)
1517 (erc-parse-user (erc-response.sender parsed))))
1518 (erc-update-channel-member ch nick nick nil nil nil nil nil nil host login)
1519 (erc-update-channel-topic ch (format "%s\C-o (%s, %s)" topic nick time))
1520 (erc-display-message parsed 'notice (erc-get-buffer ch proc)
1521 'TOPIC ?n nick ?u login ?h host
1524 (define-erc-response-handler (WALLOPS)
1525 "Display a WALLOPS message." nil
1526 (let ((message (erc-response.contents parsed)))
1527 (pcase-let ((`(,nick ,login ,host)
1528 (erc-parse-user (erc-response.sender parsed))))
1529 (erc-display-message
1531 'WALLOPS ?n nick ?m message))))
1533 (define-erc-response-handler (001)
1534 "Set `erc-server-current-nick' to reflect server settings and display the welcome message."
1536 (erc-set-current-nick (car (erc-response.command-args parsed)))
1537 (erc-update-mode-line) ; needed here?
1538 (setq erc-nick-change-attempt-count 0)
1539 (setq erc-default-nicks (if (consp erc-nick) erc-nick (list erc-nick)))
1540 (erc-display-message
1541 parsed 'notice 'active (erc-response.contents parsed)))
1543 (define-erc-response-handler (MOTD 002 003 371 372 374 375)
1544 "Display the server's message of the day." nil
1546 (erc-display-message
1547 parsed 'notice (if erc-server-connected 'active proc)
1548 (erc-response.contents parsed)))
1550 (define-erc-response-handler (376 422)
1551 "End of MOTD/MOTD is missing." nil
1552 (erc-server-MOTD proc parsed)
1553 (erc-connection-established proc parsed))
1555 (define-erc-response-handler (004)
1556 "Display the server's identification." nil
1557 (pcase-let ((`(,server-name ,server-version)
1558 (cdr (erc-response.command-args parsed))))
1559 (setq erc-server-version server-version)
1560 (setq erc-server-announced-name server-name)
1561 (erc-update-mode-line-buffer (process-buffer proc))
1562 (erc-display-message
1564 's004 ?s server-name ?v server-version
1565 ?U (nth 3 (erc-response.command-args parsed))
1566 ?C (nth 4 (erc-response.command-args parsed)))))
1568 (define-erc-response-handler (005)
1569 "Set the variable `erc-server-parameters' and display the received message.
1571 According to RFC 2812, suggests alternate servers on the network.
1572 Many servers, however, use this code to show which parameters they have set,
1573 for example, the network identifier, maximum allowed topic length, whether
1574 certain commands are accepted and more. See documentation for
1575 `erc-server-parameters' for more information on the parameters sent.
1577 A server may send more than one 005 message."
1579 (let ((line (mapconcat 'identity
1580 (setf (erc-response.command-args parsed)
1581 (cdr (erc-response.command-args parsed)))
1583 (while (erc-response.command-args parsed)
1584 (let ((section (pop (erc-response.command-args parsed))))
1585 ;; fill erc-server-parameters
1586 (when (string-match "^\\([A-Z]+\\)=\\(.*\\)$\\|^\\([A-Z]+\\)$"
1588 (add-to-list 'erc-server-parameters
1589 `(,(or (match-string 1 section)
1590 (match-string 3 section))
1592 ,(match-string 2 section))))))
1593 (erc-display-message parsed 'notice proc line)))
1595 (define-erc-response-handler (221)
1596 "Display the current user modes." nil
1597 (let* ((nick (car (erc-response.command-args parsed)))
1598 (modes (mapconcat 'identity
1599 (cdr (erc-response.command-args parsed)) " ")))
1600 (erc-set-modes nick modes)
1601 (erc-display-message parsed 'notice 'active 's221 ?n nick ?m modes)))
1603 (define-erc-response-handler (252)
1604 "Display the number of IRC operators online." nil
1605 (erc-display-message parsed 'notice 'active 's252
1606 ?i (cadr (erc-response.command-args parsed))))
1608 (define-erc-response-handler (253)
1609 "Display the number of unknown connections." nil
1610 (erc-display-message parsed 'notice 'active 's253
1611 ?i (cadr (erc-response.command-args parsed))))
1613 (define-erc-response-handler (254)
1614 "Display the number of channels formed." nil
1615 (erc-display-message parsed 'notice 'active 's254
1616 ?i (cadr (erc-response.command-args parsed))))
1618 (define-erc-response-handler (250 251 255 256 257 258 259 265 266 377 378)
1619 "Generic display of server messages as notices.
1621 See `erc-display-server-message'." nil
1622 (erc-display-server-message proc parsed))
1624 (define-erc-response-handler (275)
1625 "Display secure connection message." nil
1626 (pcase-let ((`(,nick ,user ,message)
1627 (cdr (erc-response.command-args parsed))))
1628 (erc-display-message
1629 parsed 'notice 'active 's275
1631 ?m (mapconcat 'identity (cddr (erc-response.command-args parsed))
1634 (define-erc-response-handler (290)
1635 "Handle dancer-ircd CAPAB messages." nil nil)
1637 (define-erc-response-handler (301)
1639 (erc-display-message parsed 'notice 'active 's301
1640 ?n (cadr (erc-response.command-args parsed))
1641 ?r (erc-response.contents parsed)))
1643 (define-erc-response-handler (303)
1645 (erc-display-message parsed 'notice 'active 's303
1646 ?n (cadr (erc-response.command-args parsed))))
1648 (define-erc-response-handler (305)
1649 "Return from AWAYness." nil
1650 (erc-process-away proc nil)
1651 (erc-display-message parsed 'notice 'active
1652 's305 ?m (erc-response.contents parsed)))
1654 (define-erc-response-handler (306)
1656 (erc-process-away proc t)
1657 (erc-display-message parsed 'notice 'active
1658 's306 ?m (erc-response.contents parsed)))
1660 (define-erc-response-handler (307)
1661 "Display nick-identified message." nil
1662 (pcase-let ((`(,nick ,user ,message)
1663 (cdr (erc-response.command-args parsed))))
1664 (erc-display-message
1665 parsed 'notice 'active 's307
1667 ?m (mapconcat 'identity (cddr (erc-response.command-args parsed))
1670 (define-erc-response-handler (311 314)
1671 "WHOIS/WHOWAS notices." nil
1672 (let ((fname (erc-response.contents parsed))
1673 (catalog-entry (intern (format "s%s" (erc-response.command parsed)))))
1674 (pcase-let ((`(,nick ,user ,host)
1675 (cdr (erc-response.command-args parsed))))
1676 (erc-update-user-nick nick nick host nil fname user)
1677 (erc-display-message
1678 parsed 'notice 'active catalog-entry
1679 ?n nick ?f fname ?u user ?h host))))
1681 (define-erc-response-handler (312)
1682 "Server name response in WHOIS." nil
1683 (pcase-let ((`(,nick ,server-host)
1684 (cdr (erc-response.command-args parsed))))
1685 (erc-display-message
1686 parsed 'notice 'active 's312
1687 ?n nick ?s server-host ?c (erc-response.contents parsed))))
1689 (define-erc-response-handler (313)
1690 "IRC Operator response in WHOIS." nil
1691 (erc-display-message
1692 parsed 'notice 'active 's313
1693 ?n (cadr (erc-response.command-args parsed))))
1695 (define-erc-response-handler (315 318 323 369)
1697 ;; 318 - End of WHOIS list
1698 ;; 323 - End of channel LIST
1699 ;; 369 - End of WHOWAS
1700 "End of WHO/WHOIS/LIST/WHOWAS notices." nil
1701 (ignore proc parsed))
1703 (define-erc-response-handler (317)
1705 (pcase-let ((`(,nick ,seconds-idle ,on-since ,time)
1706 (cdr (erc-response.command-args parsed))))
1707 (setq time (when on-since
1708 (format-time-string erc-server-timestamp-format
1709 (erc-string-to-emacs-time on-since))))
1710 (erc-update-user-nick nick nick nil nil nil
1711 (and time (format "on since %s" time)))
1713 (erc-display-message
1714 parsed 'notice 'active 's317-on-since
1715 ?n nick ?i (erc-sec-to-time (string-to-number seconds-idle)) ?t time)
1716 (erc-display-message
1717 parsed 'notice 'active 's317
1718 ?n nick ?i (erc-sec-to-time (string-to-number seconds-idle))))))
1720 (define-erc-response-handler (319)
1721 "Channel names in WHOIS response." nil
1722 (erc-display-message
1723 parsed 'notice 'active 's319
1724 ?n (cadr (erc-response.command-args parsed))
1725 ?c (erc-response.contents parsed)))
1727 (define-erc-response-handler (320)
1728 "Identified user in WHOIS." nil
1729 (erc-display-message
1730 parsed 'notice 'active 's320
1731 ?n (cadr (erc-response.command-args parsed))))
1733 (define-erc-response-handler (321)
1735 (setq erc-channel-list nil))
1737 (defun erc-server-321-message (proc parsed)
1738 "Display a message for the 321 event."
1739 (erc-display-message parsed 'notice proc 's321)
1741 (add-hook 'erc-server-321-functions 'erc-server-321-message t)
1743 (define-erc-response-handler (322)
1745 (let ((topic (erc-response.contents parsed)))
1746 (pcase-let ((`(,channel ,num-users)
1747 (cdr (erc-response.command-args parsed))))
1748 (add-to-list 'erc-channel-list (list channel))
1749 (erc-update-channel-topic channel topic))))
1751 (defun erc-server-322-message (proc parsed)
1752 "Display a message for the 322 event."
1753 (let ((topic (erc-response.contents parsed)))
1754 (pcase-let ((`(,channel ,num-users)
1755 (cdr (erc-response.command-args parsed))))
1756 (erc-display-message
1757 parsed 'notice proc 's322
1758 ?c channel ?u num-users ?t (or topic "")))))
1759 (add-hook 'erc-server-322-functions 'erc-server-322-message t)
1761 (define-erc-response-handler (324)
1762 "Channel or nick modes." nil
1763 (let ((channel (cadr (erc-response.command-args parsed)))
1764 (modes (mapconcat 'identity (cddr (erc-response.command-args parsed))
1766 (erc-set-modes channel modes)
1767 (erc-display-message
1768 parsed 'notice (erc-get-buffer channel proc)
1769 's324 ?c channel ?m modes)))
1771 (define-erc-response-handler (328)
1772 "Channel URL (on freenode network)." nil
1773 (let ((channel (cadr (erc-response.command-args parsed)))
1774 (url (erc-response.contents parsed)))
1775 (erc-display-message parsed 'notice (erc-get-buffer channel proc)
1776 's328 ?c channel ?u url)))
1778 (define-erc-response-handler (329)
1779 "Channel creation date." nil
1780 (let ((channel (cadr (erc-response.command-args parsed)))
1781 (time (erc-string-to-emacs-time
1782 (nth 2 (erc-response.command-args parsed)))))
1783 (erc-display-message
1784 parsed 'notice (erc-get-buffer channel proc)
1785 's329 ?c channel ?t (format-time-string erc-server-timestamp-format
1788 (define-erc-response-handler (330)
1789 "Nick is authed as (on Quakenet network)." nil
1790 ;; FIXME: I don't know what the magic numbers mean. Mummy, make
1791 ;; the magic numbers go away.
1792 ;; No seriously, I have no clue about the format of this command,
1793 ;; and don't sit on Quakenet, so can't test. Originally we had:
1794 ;; nick == (aref parsed 3)
1795 ;; authaccount == (aref parsed 4)
1796 ;; authmsg == (aref parsed 5)
1797 ;; The guesses below are, well, just that. -- Lawrence 2004/05/10
1798 (let ((nick (cadr (erc-response.command-args parsed)))
1799 (authaccount (nth 2 (erc-response.command-args parsed)))
1800 (authmsg (erc-response.contents parsed)))
1801 (erc-display-message parsed 'notice 'active 's330
1802 ?n nick ?a authmsg ?i authaccount)))
1804 (define-erc-response-handler (331)
1805 "No topic set for channel." nil
1806 (let ((channel (cadr (erc-response.command-args parsed)))
1807 (topic (erc-response.contents parsed)))
1808 (erc-display-message parsed 'notice (erc-get-buffer channel proc)
1811 (define-erc-response-handler (332)
1813 (let ((channel (cadr (erc-response.command-args parsed)))
1814 (topic (erc-response.contents parsed)))
1815 (erc-update-channel-topic channel topic)
1816 (erc-display-message parsed 'notice (erc-get-buffer channel proc)
1817 's332 ?c channel ?T topic)))
1819 (define-erc-response-handler (333)
1820 "Who set the topic, and when." nil
1821 (pcase-let ((`(,channel ,nick ,time)
1822 (cdr (erc-response.command-args parsed))))
1823 (setq time (format-time-string erc-server-timestamp-format
1824 (erc-string-to-emacs-time time)))
1825 (erc-update-channel-topic channel
1826 (format "\C-o (%s, %s)" nick time)
1828 (erc-display-message parsed 'notice (erc-get-buffer channel proc)
1829 's333 ?c channel ?n nick ?t time)))
1831 (define-erc-response-handler (341)
1832 "Let user know when an INVITE attempt has been sent successfully."
1834 (pcase-let ((`(,nick ,channel)
1835 (cdr (erc-response.command-args parsed))))
1836 (erc-display-message parsed 'notice (erc-get-buffer channel proc)
1837 's341 ?n nick ?c channel)))
1839 (define-erc-response-handler (352)
1841 (pcase-let ((`(,channel ,user ,host ,server ,nick ,away-flag)
1842 (cdr (erc-response.command-args parsed))))
1843 (let ((full-name (erc-response.contents parsed))
1845 (when (string-match "\\(^[0-9]+ \\)\\(.*\\)$" full-name)
1846 (setq hopcount (match-string 1 full-name))
1847 (setq full-name (match-string 2 full-name)))
1848 (erc-update-channel-member channel nick nick nil nil nil nil nil nil host user full-name)
1849 (erc-display-message parsed 'notice 'active 's352
1850 ?c channel ?n nick ?a away-flag
1851 ?u user ?h host ?f full-name))))
1853 (define-erc-response-handler (353)
1855 (let ((channel (nth 2 (erc-response.command-args parsed)))
1856 (users (erc-response.contents parsed)))
1857 (erc-display-message parsed 'notice (or (erc-get-buffer channel proc)
1859 's353 ?c channel ?u users)
1860 (erc-with-buffer (channel proc)
1861 (erc-channel-receive-names users))))
1863 (define-erc-response-handler (366)
1865 (erc-with-buffer ((cadr (erc-response.command-args parsed)) proc)
1866 (erc-channel-end-receiving-names)))
1868 (define-erc-response-handler (367)
1869 "Channel ban list entries." nil
1870 (pcase-let ((`(,channel ,banmask ,setter ,time)
1871 (cdr (erc-response.command-args parsed))))
1872 ;; setter and time are not standard
1874 (erc-display-message parsed 'notice 'active 's367-set-by
1879 (erc-display-message parsed 'notice 'active 's367
1883 (define-erc-response-handler (368)
1884 "End of channel ban list." nil
1885 (let ((channel (cadr (erc-response.command-args parsed))))
1886 (erc-display-message parsed 'notice 'active 's368
1889 (define-erc-response-handler (379)
1890 "Forwarding to another channel." nil
1891 ;; FIXME: Yet more magic numbers in original code, I'm guessing this
1892 ;; command takes two arguments, and doesn't have any "contents". --
1893 ;; Lawrence 2004/05/10
1894 (pcase-let ((`(,from ,to)
1895 (cdr (erc-response.command-args parsed))))
1896 (erc-display-message parsed 'notice 'active
1897 's379 ?c from ?f to)))
1899 (define-erc-response-handler (391)
1900 "Server's time string." nil
1901 (erc-display-message
1902 parsed 'notice 'active
1903 's391 ?s (cadr (erc-response.command-args parsed))
1904 ?t (nth 2 (erc-response.command-args parsed))))
1906 (define-erc-response-handler (401)
1907 "No such nick/channel." nil
1908 (let ((nick/channel (cadr (erc-response.command-args parsed))))
1909 (when erc-whowas-on-nosuchnick
1910 (erc-log (format "cmd: WHOWAS: %s" nick/channel))
1911 (erc-server-send (format "WHOWAS %s 1" nick/channel)))
1912 (erc-display-message parsed '(notice error) 'active
1913 's401 ?n nick/channel)))
1915 (define-erc-response-handler (403)
1916 "No such channel." nil
1917 (erc-display-message parsed '(notice error) 'active
1918 's403 ?c (cadr (erc-response.command-args parsed))))
1920 (define-erc-response-handler (404)
1921 "Cannot send to channel." nil
1922 (erc-display-message parsed '(notice error) 'active
1923 's404 ?c (cadr (erc-response.command-args parsed))))
1926 (define-erc-response-handler (405)
1927 "Can't join that many channels." nil
1928 (erc-display-message parsed '(notice error) 'active
1929 's405 ?c (cadr (erc-response.command-args parsed))))
1931 (define-erc-response-handler (406)
1933 (erc-display-message parsed '(notice error) 'active
1934 's406 ?n (cadr (erc-response.command-args parsed))))
1936 (define-erc-response-handler (412)
1937 "No text to send." nil
1938 (erc-display-message parsed '(notice error) 'active 's412))
1940 (define-erc-response-handler (421)
1941 "Unknown command." nil
1942 (erc-display-message parsed '(notice error) 'active 's421
1943 ?c (cadr (erc-response.command-args parsed))))
1945 (define-erc-response-handler (432)
1947 (erc-display-message parsed '(notice error) 'active 's432
1948 ?n (cadr (erc-response.command-args parsed))))
1950 (define-erc-response-handler (433)
1951 "Login-time \"nick in use\"." nil
1952 (erc-nickname-in-use (cadr (erc-response.command-args parsed))
1955 (define-erc-response-handler (437)
1956 "Nick temporarily unavailable (on IRCnet)." nil
1957 (let ((nick/channel (cadr (erc-response.command-args parsed))))
1958 (unless (erc-channel-p nick/channel)
1959 (erc-nickname-in-use nick/channel "temporarily unavailable"))))
1961 (define-erc-response-handler (442)
1962 "Not on channel." nil
1963 (erc-display-message parsed '(notice error) 'active 's442
1964 ?c (cadr (erc-response.command-args parsed))))
1966 (define-erc-response-handler (461)
1967 "Not enough parameters for command." nil
1968 (erc-display-message parsed '(notice error) 'active 's461
1969 ?c (cadr (erc-response.command-args parsed))
1970 ?m (erc-response.contents parsed)))
1972 (define-erc-response-handler (465)
1973 "You are banned from this server." nil
1974 (setq erc-server-banned t)
1975 ;; show the server's message, as a reason might be provided
1976 (erc-display-error-notice
1978 (erc-response.contents parsed)))
1980 (define-erc-response-handler (474)
1981 "Banned from channel errors." nil
1982 (erc-display-message parsed '(notice error) nil
1983 (intern (format "s%s"
1984 (erc-response.command parsed)))
1985 ?c (cadr (erc-response.command-args parsed))))
1987 (define-erc-response-handler (475)
1988 "Channel key needed." nil
1989 (erc-display-message parsed '(notice error) nil 's475
1990 ?c (cadr (erc-response.command-args parsed)))
1991 (when erc-prompt-for-channel-key
1992 (let ((channel (cadr (erc-response.command-args parsed)))
1993 (key (read-from-minibuffer
1994 (format "Channel %s is mode +k. Enter key (RET to cancel): "
1995 (cadr (erc-response.command-args parsed))))))
1996 (when (and key (> (length key) 0))
1997 (erc-cmd-JOIN channel key)))))
1999 (define-erc-response-handler (477)
2000 "Channel doesn't support modes." nil
2001 (let ((channel (cadr (erc-response.command-args parsed)))
2002 (message (erc-response.contents parsed)))
2003 (erc-display-message parsed 'notice (erc-get-buffer channel proc)
2004 (format "%s: %s" channel message))))
2006 (define-erc-response-handler (482)
2007 "You need to be a channel operator to do that." nil
2008 (let ((channel (cadr (erc-response.command-args parsed)))
2009 (message (erc-response.contents parsed)))
2010 (erc-display-message parsed '(error notice) 'active 's482
2011 ?c channel ?m message)))
2013 (define-erc-response-handler (671)
2014 "Secure connection response in WHOIS." nil
2015 (let ((nick (cadr (erc-response.command-args parsed)))
2016 (securemsg (erc-response.contents parsed)))
2017 (erc-display-message parsed 'notice 'active 's671
2018 ?n nick ?a securemsg)))
2020 (define-erc-response-handler (431 445 446 451 462 463 464 481 483 484 485
2022 ;; 431 - No nickname given
2023 ;; 445 - SUMMON has been disabled
2024 ;; 446 - USERS has been disabled
2025 ;; 451 - You have not registered
2026 ;; 462 - Unauthorized command (already registered)
2027 ;; 463 - Your host isn't among the privileged
2028 ;; 464 - Password incorrect
2029 ;; 481 - Need IRCop privileges
2030 ;; 483 - You can't kill a server!
2031 ;; 484 - Your connection is restricted!
2032 ;; 485 - You're not the original channel operator
2033 ;; 491 - No O-lines for your host
2034 ;; 501 - Unknown MODE flag
2035 ;; 502 - Cannot change mode for other users
2036 "Generic display of server error messages.
2038 See `erc-display-error-notice'." nil
2039 (erc-display-error-notice
2041 (intern (format "s%s" (erc-response.command parsed)))))
2043 ;; FIXME: These are yet to be implemented, they're just stubs for now
2044 ;; -- Lawrence 2004/05/12
2046 ;; response numbers left here for reference
2048 ;; (define-erc-response-handler (323 364 365 381 382 392 393 394 395
2049 ;; 200 201 202 203 204 205 206 208 209 211 212 213
2050 ;; 214 215 216 217 218 219 241 242 243 244 249 261
2051 ;; 262 302 342 351 402 407 409 411 413 414 415
2052 ;; 423 424 436 441 443 444 467 471 472 473 KILL)
2054 ;; (ignore proc parsed))
2056 (provide 'erc-backend)
2058 ;;; erc-backend.el ends here
2060 ;; indent-tabs-mode: nil