Merge from emacs--rel--22
[emacs.git] / lisp / erc / erc-backend.el
blob1bb3e4aada20c492618319d5622e580f64f34f44
1 ;;; erc-backend.el --- Backend network communication for ERC
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
5 ;; Filename: erc-backend.el
6 ;; Author: Lawrence Mitchell <wence@gmx.li>
7 ;; Created: 2004-05-7
8 ;; Keywords: IRC chat client internet
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 3, or (at your option)
15 ;; any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, USA.
27 ;;; Commentary:
29 ;; This file defines backend network communication handlers for ERC.
31 ;; How things work:
33 ;; You define a new handler with `define-erc-response-handler'. This
34 ;; defines a function, a corresponding hook variable, and populates a
35 ;; global hash table `erc-server-responses' with a map from response
36 ;; to hook variable. See the function documentation for more
37 ;; information.
39 ;; Upon receiving a line from the server, `erc-parse-server-response'
40 ;; is called on it.
42 ;; A line generally looks like:
44 ;; LINE := ':' SENDER ' ' COMMAND ' ' (COMMAND-ARGS ' ')* ':' CONTENTS
45 ;; SENDER := Not ':' | ' '
46 ;; COMMAND := Not ':' | ' '
47 ;; COMMAND-ARGS := Not ':' | ' '
49 ;; This gets parsed and stuffed into an `erc-response' struct. You
50 ;; can access the fields of the struct with:
52 ;; COMMAND --- `erc-response.command'
53 ;; COMMAND-ARGS --- `erc-response.command-args'
54 ;; CONTENTS --- `erc-response.contents'
55 ;; SENDER --- `erc-response.sender'
56 ;; LINE --- `erc-response.unparsed'
58 ;; WARNING, WARNING!!
59 ;; It's probably not a good idea to destructively modify the list
60 ;; of command-args in your handlers, since other functions down the
61 ;; line may well need to access the arguments too.
63 ;; That is, unless you're /absolutely/ sure that your handler doesn't
64 ;; invoke some other function that needs to use COMMAND-ARGS, don't do
65 ;; something like
67 ;; (while (erc-response.command-args parsed)
68 ;; (let ((a (pop (erc-response.command-args parsed))))
69 ;; ...))
71 ;; The parsed response is handed over to
72 ;; `erc-handle-parsed-server-response', which checks whether it should
73 ;; carry out duplicate suppression, and then runs `erc-call-hooks'.
74 ;; `erc-call-hooks' retrieves the relevant hook variable from
75 ;; `erc-server-responses' and runs it.
77 ;; Most handlers then destructure the parsed response in some way
78 ;; (depending on what the handler is, the arguments have different
79 ;; meanings), and generally display something, usually using
80 ;; `erc-display-message'.
82 ;;; TODO:
84 ;; o Generalise the display-line code so that we can use it to
85 ;; display the stuff we send, as well as the stuff we receive.
86 ;; Then, move all display-related code into another backend-like
87 ;; file, erc-display.el, say.
89 ;; o Clean up the handlers using new display code (has to be written
90 ;; first).
92 ;;; History:
94 ;; 2004/05/10 -- Handler bodies taken out of erc.el and ported to new
95 ;; interface.
97 ;; 2005-08-13 -- Moved sending commands from erc.el.
99 ;;; Code:
101 (require 'erc-compat)
102 (eval-when-compile (require 'cl))
103 (autoload 'erc-with-buffer "erc" nil nil 'macro)
104 (autoload 'erc-log "erc" nil nil 'macro)
106 ;;;; Variables and options
108 (defvar erc-server-responses (make-hash-table :test #'equal)
109 "Hashtable mapping server responses to their handler hooks.")
111 (defstruct (erc-response (:conc-name erc-response.))
112 (unparsed "" :type string)
113 (sender "" :type string)
114 (command "" :type string)
115 (command-args '() :type list)
116 (contents "" :type string))
118 ;;; User data
120 (defvar erc-server-current-nick nil
121 "Nickname on the current server.
122 Use `erc-current-nick' to access this.")
123 (make-variable-buffer-local 'erc-server-current-nick)
125 ;;; Server attributes
127 (defvar erc-server-process nil
128 "The process object of the corresponding server connection.")
129 (make-variable-buffer-local 'erc-server-process)
131 (defvar erc-session-server nil
132 "The server name used to connect to for this session.")
133 (make-variable-buffer-local 'erc-session-server)
135 (defvar erc-session-port nil
136 "The port used to connect to.")
137 (make-variable-buffer-local 'erc-session-port)
139 (defvar erc-server-announced-name nil
140 "The name the server announced to use.")
141 (make-variable-buffer-local 'erc-server-announced-name)
143 (defvar erc-server-version nil
144 "The name and version of the server's ircd.")
145 (make-variable-buffer-local 'erc-server-version)
147 (defvar erc-server-parameters nil
148 "Alist listing the supported server parameters.
150 This is only set if the server sends 005 messages saying what is
151 supported on the server.
153 Entries are of the form:
154 (PARAMETER . VALUE)
156 (PARAMETER) if no value is provided.
158 Some examples of possible parameters sent by servers:
159 CHANMODES=b,k,l,imnpst - list of supported channel modes
160 CHANNELLEN=50 - maximum length of channel names
161 CHANTYPES=#&!+ - supported channel prefixes
162 CHARMAPPING=rfc1459 - character mapping used for nickname and channels
163 KICKLEN=160 - maximum allowed kick message length
164 MAXBANS=30 - maximum number of bans per channel
165 MAXCHANNELS=10 - maximum number of channels allowed to join
166 NETWORK=EFnet - the network identifier
167 NICKLEN=9 - maximum allowed length of nicknames
168 PREFIX=(ov)@+ - list of channel modes and the user prefixes if user has mode
169 RFC2812 - server supports RFC 2812 features
170 SILENCE=10 - supports the SILENCE command, maximum allowed number of entries
171 TOPICLEN=160 - maximum allowed topic length
172 WALLCHOPS - supports sending messages to all operators in a channel")
173 (make-variable-buffer-local 'erc-server-parameters)
175 ;;; Server and connection state
177 (defvar erc-server-ping-timer-alist nil
178 "Mapping of server buffers to their specific ping timer.")
180 (defvar erc-server-connected nil
181 "Non-nil if the current buffer has been used by ERC to establish
182 an IRC connection.
184 If you wish to determine whether an IRC connection is currently
185 active, use the `erc-server-process-alive' function instead.")
186 (make-variable-buffer-local 'erc-server-connected)
188 (defvar erc-server-reconnect-count 0
189 "Number of times we have failed to reconnect to the current server.")
190 (make-variable-buffer-local 'erc-server-reconnect-count)
192 (defvar erc-server-quitting nil
193 "Non-nil if the user requests a quit.")
194 (make-variable-buffer-local 'erc-server-quitting)
196 (defvar erc-server-reconnecting nil
197 "Non-nil if the user requests an explicit reconnect, and the
198 current IRC process is still alive.")
199 (make-variable-buffer-local 'erc-server-reconnecting)
201 (defvar erc-server-timed-out nil
202 "Non-nil if the IRC server failed to respond to a ping.")
203 (make-variable-buffer-local 'erc-server-timed-out)
205 (defvar erc-server-banned nil
206 "Non-nil if the user is denied access because of a server ban.")
207 (make-variable-buffer-local 'erc-server-banned)
209 (defvar erc-server-error-occurred nil
210 "Non-nil if the user triggers some server error.")
211 (make-variable-buffer-local 'erc-server-error-occurred)
213 (defvar erc-server-lines-sent nil
214 "Line counter.")
215 (make-variable-buffer-local 'erc-server-lines-sent)
217 (defvar erc-server-last-peers '(nil . nil)
218 "Last peers used, both sender and receiver.
219 Those are used for /MSG destination shortcuts.")
220 (make-variable-buffer-local 'erc-server-last-peers)
222 (defvar erc-server-last-sent-time nil
223 "Time the message was sent.
224 This is useful for flood protection.")
225 (make-variable-buffer-local 'erc-server-last-sent-time)
227 (defvar erc-server-last-ping-time nil
228 "Time the last ping was sent.
229 This is useful for flood protection.")
230 (make-variable-buffer-local 'erc-server-last-ping-time)
232 (defvar erc-server-last-received-time nil
233 "Time the last message was received from the server.
234 This is useful for detecting hung connections.")
235 (make-variable-buffer-local 'erc-server-last-received-time)
237 (defvar erc-server-lag nil
238 "Calculated server lag time in seconds.
239 This variable is only set in a server buffer.")
240 (make-variable-buffer-local 'erc-server-lag)
242 (defvar erc-server-filter-data nil
243 "The data that arrived from the server
244 but has not been processed yet.")
245 (make-variable-buffer-local 'erc-server-filter-data)
247 (defvar erc-server-duplicates (make-hash-table :test 'equal)
248 "Internal variable used to track duplicate messages.")
249 (make-variable-buffer-local 'erc-server-duplicates)
251 ;; From Circe
252 (defvar erc-server-processing-p nil
253 "Non-nil when we're currently processing a message.
255 When ERC receives a private message, it sets up a new buffer for
256 this query. These in turn, though, do start flyspell. This
257 involves starting an external process, in which case Emacs will
258 wait - and when it waits, it does accept other stuff from, say,
259 network exceptions. So, if someone sends you two messages
260 quickly after each other, ispell is started for the first, but
261 might take long enough for the second message to be processed
262 first.")
263 (make-variable-buffer-local 'erc-server-processing-p)
265 (defvar erc-server-flood-last-message 0
266 "When we sent the last message.
267 See `erc-server-flood-margin' for an explanation of the flood
268 protection algorithm.")
269 (make-variable-buffer-local 'erc-server-flood-last-message)
271 (defvar erc-server-flood-queue nil
272 "The queue of messages waiting to be sent to the server.
273 See `erc-server-flood-margin' for an explanation of the flood
274 protection algorithm.")
275 (make-variable-buffer-local 'erc-server-flood-queue)
277 (defvar erc-server-flood-timer nil
278 "The timer to resume sending.")
279 (make-variable-buffer-local 'erc-server-flood-timer)
281 ;;; IRC protocol and misc options
283 (defgroup erc-server nil
284 "Parameters for dealing with IRC servers."
285 :group 'erc)
287 (defcustom erc-server-auto-reconnect t
288 "Non-nil means that ERC will attempt to reestablish broken connections.
290 Reconnection will happen automatically for any unexpected disconnection."
291 :group 'erc-server
292 :type 'boolean)
294 (defcustom erc-server-reconnect-attempts 2
295 "The number of times that ERC will attempt to reestablish a
296 broken connection, or t to always attempt to reconnect.
298 This only has an effect if `erc-server-auto-reconnect' is non-nil."
299 :group 'erc-server
300 :type '(choice (const :tag "Always reconnect" t)
301 integer))
303 (defcustom erc-server-reconnect-timeout 1
304 "The amount of time, in seconds, that ERC will wait between
305 successive reconnect attempts.
307 If a key is pressed while ERC is waiting, it will stop waiting."
308 :group 'erc-server
309 :type 'number)
311 (defcustom erc-split-line-length 440
312 "*The maximum length of a single message.
313 If a message exceeds this size, it is broken into multiple ones.
315 IRC allows for lines up to 512 bytes. Two of them are CR LF.
316 And a typical message looks like this:
318 :nicky!uhuser@host212223.dialin.fnordisp.net PRIVMSG #lazybastards :Hello!
320 You can limit here the maximum length of the \"Hello!\" part.
321 Good luck."
322 :type 'integer
323 :group 'erc-server)
325 (defcustom erc-server-coding-system (if (and (fboundp 'coding-system-p)
326 (coding-system-p 'undecided)
327 (coding-system-p 'utf-8))
328 '(utf-8 . undecided)
329 nil)
330 "The default coding system for incoming and outgoing text.
331 This is either a coding system, a cons, a function, or nil.
333 If a cons, the encoding system for outgoing text is in the car
334 and the decoding system for incoming text is in the cdr. The most
335 interesting use for this is to put `undecided' in the cdr.
337 If a function, it is called with the argument `target' and should
338 return a coding system or a cons as described above.
340 If you need to send non-ASCII text to people not using a client that
341 does decoding on its own, you must tell ERC what encoding to use.
342 Emacs cannot guess it, since it does not know what the people on the
343 other end of the line are using."
344 :group 'erc-server
345 :type '(choice (const :tag "None" nil)
346 coding-system
347 (cons (coding-system :tag "encoding" :value utf-8)
348 (coding-system :tag "decoding" :value undecided))
349 function))
351 (defcustom erc-encoding-coding-alist nil
352 "Alist of target regexp and coding-system pairs to use.
353 This overrides `erc-server-coding-system' depending on the
354 current target as returned by `erc-default-target'.
356 Example: If you know that the channel #linux-ru uses the coding-system
357 `cyrillic-koi8', then add '(\"#linux-ru\" . cyrillic-koi8) to the
358 alist."
359 :group 'erc-server
360 :type '(repeat (cons (string :tag "Target")
361 coding-system)))
363 (defcustom erc-server-connect-function 'open-network-stream
364 "Function used to initiate a connection.
365 It should take same arguments as `open-network-stream' does."
366 :group 'erc-server
367 :type 'function)
369 (defcustom erc-server-prevent-duplicates '("301")
370 "*Either nil or a list of strings.
371 Each string is a IRC message type, like PRIVMSG or NOTICE.
372 All Message types in that list of subjected to duplicate prevention."
373 :type '(choice (const nil) (list string))
374 :group 'erc-server)
376 (defcustom erc-server-duplicate-timeout 60
377 "*The time allowed in seconds between duplicate messages.
379 If two identical messages arrive within this value of one another, the second
380 isn't displayed."
381 :type 'integer
382 :group 'erc-server)
384 ;;; Flood-related
386 ;; Most of this is courtesy of Jorgen Schaefer and Circe
387 ;; (http://www.nongnu.org/circe)
389 (defcustom erc-server-flood-margin 10
390 "*A margin on how much excess data we send.
391 The flood protection algorithm of ERC works like the one
392 detailed in RFC 2813, section 5.8 \"Flood control of clients\".
394 * If `erc-server-flood-last-message' is less than the current
395 time, set it equal.
396 * While `erc-server-flood-last-message' is less than
397 `erc-server-flood-margin' seconds ahead of the current
398 time, send a message, and increase
399 `erc-server-flood-last-message' by
400 `erc-server-flood-penalty' for each message."
401 :type 'integer
402 :group 'erc-server)
404 (defcustom erc-server-flood-penalty 3
405 "How much we penalize a message.
406 See `erc-server-flood-margin' for an explanation of the flood
407 protection algorithm."
408 :type 'integer
409 :group 'erc-server)
411 ;; Ping handling
413 (defcustom erc-server-send-ping-interval 30
414 "*Interval of sending pings to the server, in seconds.
415 If this is set to nil, pinging the server is disabled."
416 :group 'erc-server
417 :type '(choice (const :tag "Disabled" nil)
418 (integer :tag "Seconds")))
420 (defcustom erc-server-send-ping-timeout 120
421 "*If the time between ping and response is greater than this, reconnect.
422 The time is in seconds.
424 This must be greater than or equal to the value for
425 `erc-server-send-ping-interval'.
427 If this is set to nil, never try to reconnect."
428 :group 'erc-server
429 :type '(choice (const :tag "Disabled" nil)
430 (integer :tag "Seconds")))
432 (defvar erc-server-ping-handler nil
433 "This variable holds the periodic ping timer.")
434 (make-variable-buffer-local 'erc-server-ping-handler)
436 ;;;; Helper functions
438 ;; From Circe
439 (defun erc-split-line (longline)
440 "Return a list of lines which are not too long for IRC.
441 The length is specified in `erc-split-line-length'.
443 Currently this is called by `erc-send-input'."
444 (if (< (length longline)
445 erc-split-line-length)
446 (list longline)
447 (with-temp-buffer
448 (insert longline)
449 (let ((fill-column erc-split-line-length))
450 (fill-region (point-min) (point-max)
451 nil t))
452 (split-string (buffer-string) "\n"))))
454 ;; Used by CTCP functions
455 (defun erc-upcase-first-word (str)
456 "Upcase the first word in STR."
457 (with-temp-buffer
458 (insert str)
459 (goto-char (point-min))
460 (upcase-word 1)
461 (buffer-string)))
463 (defun erc-server-setup-periodical-ping (buffer)
464 "Set up a timer to periodically ping the current server.
465 The current buffer is given by BUFFER."
466 (with-current-buffer buffer
467 (and erc-server-ping-handler (erc-cancel-timer erc-server-ping-handler))
468 (when erc-server-send-ping-interval
469 (setq erc-server-ping-handler (run-with-timer
470 4 erc-server-send-ping-interval
471 #'erc-server-send-ping
472 buffer))
473 (setq erc-server-ping-timer-alist (cons (cons buffer
474 erc-server-ping-handler)
475 erc-server-ping-timer-alist)))))
477 (defun erc-server-process-alive ()
478 "Return non-nil when `erc-server-process' is open or running."
479 (and erc-server-process
480 (processp erc-server-process)
481 (memq (process-status erc-server-process) '(run open))))
483 ;;;; Connecting to a server
485 (defun erc-server-connect (server port buffer)
486 "Perform the connection and login using the specified SERVER and PORT.
487 We will store server variables in the buffer given by BUFFER."
488 (let ((msg (erc-format-message 'connect ?S server ?p port)))
489 (message "%s" msg)
490 (let ((process (funcall erc-server-connect-function
491 (format "erc-%s-%s" server port)
492 nil server port)))
493 (unless (processp process)
494 (error "Connection attempt failed"))
495 (message "%s...done" msg)
496 ;; Misc server variables
497 (with-current-buffer buffer
498 (setq erc-server-process process)
499 (setq erc-server-quitting nil)
500 (setq erc-server-reconnecting nil)
501 (setq erc-server-timed-out nil)
502 (setq erc-server-banned nil)
503 (setq erc-server-error-occurred nil)
504 (let ((time (erc-current-time)))
505 (setq erc-server-last-sent-time time)
506 (setq erc-server-last-ping-time time)
507 (setq erc-server-last-received-time time))
508 (setq erc-server-lines-sent 0)
509 ;; last peers (sender and receiver)
510 (setq erc-server-last-peers '(nil . nil)))
511 ;; we do our own encoding and decoding
512 (when (fboundp 'set-process-coding-system)
513 (set-process-coding-system process 'raw-text))
514 ;; process handlers
515 (set-process-sentinel process 'erc-process-sentinel)
516 (set-process-filter process 'erc-server-filter-function)
517 (set-process-buffer process buffer)))
518 (erc-log "\n\n\n********************************************\n")
519 (message "%s" (erc-format-message
520 'login ?n
521 (with-current-buffer buffer (erc-current-nick))))
522 ;; wait with script loading until we receive a confirmation (first
523 ;; MOTD line)
524 (if (eq erc-server-connect-function 'open-network-stream-nowait)
525 ;; it's a bit unclear otherwise that it's attempting to establish a
526 ;; connection
527 (erc-display-message nil nil buffer "Opening connection..\n")
528 (erc-login)))
530 (defun erc-server-reconnect ()
531 "Reestablish the current IRC connection.
532 Make sure you are in an ERC buffer when running this."
533 (let ((buffer (erc-server-buffer)))
534 (unless (buffer-live-p buffer)
535 (if (eq major-mode 'erc-mode)
536 (setq buffer (current-buffer))
537 (error "Reconnect must be run from an ERC buffer")))
538 (with-current-buffer buffer
539 (erc-update-mode-line)
540 (erc-set-active-buffer (current-buffer))
541 (setq erc-server-last-sent-time 0)
542 (setq erc-server-lines-sent 0)
543 (erc-open erc-session-server erc-session-port erc-server-current-nick
544 erc-session-user-full-name t erc-session-password))))
546 (defun erc-server-filter-function (process string)
547 "The process filter for the ERC server."
548 (with-current-buffer (process-buffer process)
549 (setq erc-server-last-received-time (erc-current-time))
550 ;; If you think this is written in a weird way - please refer to the
551 ;; docstring of `erc-server-processing-p'
552 (if erc-server-processing-p
553 (setq erc-server-filter-data
554 (if erc-server-filter-data
555 (concat erc-server-filter-data string)
556 string))
557 ;; This will be true even if another process is spawned!
558 (let ((erc-server-processing-p t))
559 (setq erc-server-filter-data (if erc-server-filter-data
560 (concat erc-server-filter-data
561 string)
562 string))
563 (while (and erc-server-filter-data
564 (string-match "[\n\r]+" erc-server-filter-data))
565 (let ((line (substring erc-server-filter-data
566 0 (match-beginning 0))))
567 (setq erc-server-filter-data
568 (if (= (match-end 0)
569 (length erc-server-filter-data))
571 (substring erc-server-filter-data
572 (match-end 0))))
573 (erc-parse-server-response process line)))))))
575 (defsubst erc-server-reconnect-p (event)
576 "Return non-nil if ERC should attempt to reconnect automatically.
577 EVENT is the message received from the closed connection process."
578 (or erc-server-reconnecting
579 (and erc-server-auto-reconnect
580 (not erc-server-banned)
581 (not erc-server-error-occurred)
582 ;; make sure we don't infinitely try to reconnect, unless the
583 ;; user wants that
584 (or (eq erc-server-reconnect-attempts t)
585 (and (integerp erc-server-reconnect-attempts)
586 (< erc-server-reconnect-count
587 erc-server-reconnect-attempts)))
588 (or erc-server-timed-out
589 (not (string-match "^deleted" event)))
590 ;; open-network-stream-nowait error for connection refused
591 (not (string-match "^failed with code 111" event)))))
593 (defun erc-process-sentinel-2 (event buffer)
594 "Called when `erc-process-sentinel-1' has detected an unexpected disconnect."
595 (if (not (buffer-live-p buffer))
596 (erc-update-mode-line)
597 (with-current-buffer buffer
598 (let ((reconnect-p (erc-server-reconnect-p event)))
599 (erc-display-message nil 'error (current-buffer)
600 (if reconnect-p 'disconnected
601 'disconnected-noreconnect))
602 (if (not reconnect-p)
603 ;; terminate, do not reconnect
604 (progn
605 (erc-display-message nil 'error (current-buffer)
606 'terminated ?e event)
607 ;; Update mode line indicators
608 (erc-update-mode-line)
609 (set-buffer-modified-p nil))
610 ;; reconnect
611 (condition-case err
612 (progn
613 (setq erc-server-reconnecting nil)
614 (erc-server-reconnect)
615 (setq erc-server-reconnect-count 0))
616 (error (when (buffer-live-p buffer)
617 (set-buffer buffer)
618 (if (integerp erc-server-reconnect-attempts)
619 (setq erc-server-reconnect-count
620 (1+ erc-server-reconnect-count))
621 (message "%s ... %s"
622 "Reconnecting until we succeed"
623 "kill the ERC server buffer to stop"))
624 (if (numberp erc-server-reconnect-timeout)
625 (run-at-time erc-server-reconnect-timeout nil
626 #'erc-process-sentinel-2
627 event buffer)
628 (error (concat "`erc-server-reconnect-timeout`"
629 " must be a number")))))))))))
631 (defun erc-process-sentinel-1 (event buffer)
632 "Called when `erc-process-sentinel' has decided that we're disconnecting.
633 Determine whether user has quit or whether erc has been terminated.
634 Conditionally try to reconnect and take appropriate action."
635 (with-current-buffer buffer
636 (if erc-server-quitting
637 ;; normal quit
638 (progn
639 (erc-display-message nil 'error (current-buffer) 'finished)
640 ;; Update mode line indicators
641 (erc-update-mode-line)
642 ;; Kill server buffer if user wants it
643 (set-buffer-modified-p nil)
644 (when erc-kill-server-buffer-on-quit
645 (kill-buffer (current-buffer))))
646 ;; unexpected disconnect
647 (erc-process-sentinel-2 event buffer))))
649 (defun erc-process-sentinel (cproc event)
650 "Sentinel function for ERC process."
651 (with-current-buffer (process-buffer cproc)
652 (erc-log (format
653 "SENTINEL: proc: %S status: %S event: %S (quitting: %S)"
654 cproc (process-status cproc) event erc-server-quitting))
655 (if (string-match "^open" event)
656 ;; newly opened connection (no wait)
657 (erc-login)
658 ;; assume event is 'failed
659 (let ((buf (process-buffer cproc)))
660 (erc-with-all-buffers-of-server cproc nil
661 (setq erc-server-connected nil))
662 (when erc-server-ping-handler
663 (progn (erc-cancel-timer erc-server-ping-handler)
664 (setq erc-server-ping-handler nil)))
665 (run-hook-with-args 'erc-disconnected-hook
666 (erc-current-nick) (system-name) "")
667 ;; Remove the prompt
668 (goto-char (or (marker-position erc-input-marker) (point-max)))
669 (forward-line 0)
670 (erc-remove-text-properties-region (point) (point-max))
671 (delete-region (point) (point-max))
672 ;; Decide what to do with the buffer
673 ;; Restart if disconnected
674 (erc-process-sentinel-1 event buf)))))
676 ;;;; Sending messages
678 (defun erc-coding-system-for-target (target)
679 "Return the coding system or cons cell appropriate for TARGET.
680 This is determined via `erc-encoding-coding-alist' or
681 `erc-server-coding-system'."
682 (unless target (setq target (erc-default-target)))
683 (or (when target
684 (let ((case-fold-search t))
685 (catch 'match
686 (dolist (pat erc-encoding-coding-alist)
687 (when (string-match (car pat) target)
688 (throw 'match (cdr pat)))))))
689 (and (functionp erc-server-coding-system)
690 (funcall erc-server-coding-system target))
691 erc-server-coding-system))
693 (defun erc-decode-string-from-target (str target)
694 "Decode STR as appropriate for TARGET.
695 This is indicated by `erc-encoding-coding-alist', defaulting to the value of
696 `erc-server-coding-system'."
697 (unless (stringp str)
698 (setq str ""))
699 (let ((coding (erc-coding-system-for-target target)))
700 (when (consp coding)
701 (setq coding (cdr coding)))
702 (erc-decode-coding-string str coding)))
704 ;; proposed name, not used by anything yet
705 (defun erc-send-line (text display-fn)
706 "Send TEXT to the current server. Wrapping and flood control apply.
707 Use DISPLAY-FN to show the results."
708 (mapc (lambda (line)
709 (erc-server-send line)
710 (funcall display-fn))
711 (erc-split-line text)))
713 ;; From Circe, with modifications
714 (defun erc-server-send (string &optional forcep target)
715 "Send STRING to the current server.
716 If FORCEP is non-nil, no flood protection is done - the string is
717 sent directly. This might cause the messages to arrive in a wrong
718 order.
720 If TARGET is specified, look up encoding information for that
721 channel in `erc-encoding-coding-alist' or
722 `erc-server-coding-system'.
724 See `erc-server-flood-margin' for an explanation of the flood
725 protection algorithm."
726 (erc-log (concat "erc-server-send: " string "(" (buffer-name) ")"))
727 (setq erc-server-last-sent-time (erc-current-time))
728 (let ((encoding (erc-coding-system-for-target target)))
729 (when (consp encoding)
730 (setq encoding (car encoding)))
731 (if (erc-server-process-alive)
732 (erc-with-server-buffer
733 (let ((str (concat string "\r\n")))
734 (if forcep
735 (progn
736 (setq erc-server-flood-last-message
737 (+ erc-server-flood-penalty
738 erc-server-flood-last-message))
739 (erc-log-irc-protocol str 'outbound)
740 (condition-case err
741 (progn
742 ;; Set encoding just before sending the string
743 (when (fboundp 'set-process-coding-system)
744 (set-process-coding-system erc-server-process
745 'raw-text encoding))
746 (process-send-string erc-server-process str))
747 ;; See `erc-server-send-queue' for full
748 ;; explanation of why we need this condition-case
749 (error nil)))
750 (setq erc-server-flood-queue
751 (append erc-server-flood-queue
752 (list (cons str encoding))))
753 (erc-server-send-queue (current-buffer))))
755 (message "ERC: No process running")
756 nil)))
758 (defun erc-server-send-ping (buf)
759 "Send a ping to the IRC server buffer in BUF.
760 Additionally, detect whether the IRC process has hung."
761 (if (buffer-live-p buf)
762 (with-current-buffer buf
763 (if (and erc-server-send-ping-timeout
765 (erc-time-diff (erc-current-time)
766 erc-server-last-received-time)
767 erc-server-send-ping-timeout))
768 (progn
769 ;; if the process is hung, kill it
770 (setq erc-server-timed-out t)
771 (delete-process erc-server-process))
772 (erc-server-send (format "PING %.0f" (erc-current-time)))))
773 ;; remove timer if the server buffer has been killed
774 (let ((timer (assq buf erc-server-ping-timer-alist)))
775 (when timer
776 (erc-cancel-timer (cdr timer))
777 (setcdr timer nil)))))
779 ;; From Circe
780 (defun erc-server-send-queue (buffer)
781 "Send messages in `erc-server-flood-queue'.
782 See `erc-server-flood-margin' for an explanation of the flood
783 protection algorithm."
784 (with-current-buffer buffer
785 (let ((now (erc-current-time)))
786 (when erc-server-flood-timer
787 (erc-cancel-timer erc-server-flood-timer)
788 (setq erc-server-flood-timer nil))
789 (when (< erc-server-flood-last-message
790 now)
791 (setq erc-server-flood-last-message now))
792 (while (and erc-server-flood-queue
793 (< erc-server-flood-last-message
794 (+ now erc-server-flood-margin)))
795 (let ((msg (caar erc-server-flood-queue))
796 (encoding (cdar erc-server-flood-queue)))
797 (setq erc-server-flood-queue (cdr erc-server-flood-queue)
798 erc-server-flood-last-message
799 (+ erc-server-flood-last-message
800 erc-server-flood-penalty))
801 (erc-log-irc-protocol msg 'outbound)
802 (erc-log (concat "erc-server-send-queue: "
803 msg "(" (buffer-name buffer) ")"))
804 (when (erc-server-process-alive)
805 (condition-case err
806 ;; Set encoding just before sending the string
807 (progn
808 (when (fboundp 'set-process-coding-system)
809 (set-process-coding-system erc-server-process
810 'raw-text encoding))
811 (process-send-string erc-server-process msg))
812 ;; Sometimes the send can occur while the process is
813 ;; being killed, which results in a weird SIGPIPE error.
814 ;; Catch this and ignore it.
815 (error nil)))))
816 (when erc-server-flood-queue
817 (setq erc-server-flood-timer
818 (run-at-time (+ 0.2 erc-server-flood-penalty)
819 nil #'erc-server-send-queue buffer))))))
821 (defun erc-message (message-command line &optional force)
822 "Send LINE to the server as a privmsg or a notice.
823 MESSAGE-COMMAND should be either \"PRIVMSG\" or \"NOTICE\".
824 If the target is \",\", the last person you've got a message from will
825 be used. If the target is \".\", the last person you've sent a message
826 to will be used."
827 (cond
828 ((string-match "^\\s-*\\(\\S-+\\) ?\\(.*\\)" line)
829 (let ((tgt (match-string 1 line))
830 (s (match-string 2 line)))
831 (erc-log (format "cmd: MSG(%s): [%s] %s" message-command tgt s))
832 (cond
833 ((string= tgt ",")
834 (if (car erc-server-last-peers)
835 (setq tgt (car erc-server-last-peers))
836 (setq tgt nil)))
837 ((string= tgt ".")
838 (if (cdr erc-server-last-peers)
839 (setq tgt (cdr erc-server-last-peers))
840 (setq tgt nil))))
841 (cond
842 (tgt
843 (setcdr erc-server-last-peers tgt)
844 (erc-server-send (format "%s %s :%s" message-command tgt s)
845 force))
847 (erc-display-message nil 'error (current-buffer) 'no-target))))
849 (t nil)))
851 ;;; CTCP
853 (defun erc-send-ctcp-message (tgt l &optional force)
854 "Send CTCP message L to TGT.
856 If TGT is nil the message is not sent.
857 The command must contain neither a prefix nor a trailing `\\n'.
859 See also `erc-server-send'."
860 (let ((l (erc-upcase-first-word l)))
861 (cond
862 (tgt
863 (erc-log (format "erc-send-CTCP-message: [%s] %s" tgt l))
864 (erc-server-send (format "PRIVMSG %s :\C-a%s\C-a" tgt l)
865 force)))))
867 (defun erc-send-ctcp-notice (tgt l &optional force)
868 "Send CTCP notice L to TGT.
870 If TGT is nil the message is not sent.
871 The command must contain neither a prefix nor a trailing `\\n'.
873 See also `erc-server-send'."
874 (let ((l (erc-upcase-first-word l)))
875 (cond
876 (tgt
877 (erc-log (format "erc-send-CTCP-notice: [%s] %s" tgt l))
878 (erc-server-send (format "NOTICE %s :\C-a%s\C-a" tgt l)
879 force)))))
881 ;;;; Handling responses
883 (defun erc-parse-server-response (proc string)
884 "Parse and act upon a complete line from an IRC server.
885 PROC is the process (connection) from which STRING was received.
886 PROCs `process-buffer' is `current-buffer' when this function is called."
887 (unless (string= string "") ;; Ignore empty strings
888 (save-match-data
889 (let ((posn (if (eq (aref string 0) ?:)
890 (string-match " " string)
892 (msg (make-erc-response :unparsed string)))
894 (setf (erc-response.sender msg)
895 (if (eq posn 0)
896 erc-session-server
897 (substring string 1 posn)))
899 (setf (erc-response.command msg)
900 (let* ((bposn (string-match "[^ \n]" string posn))
901 (eposn (string-match " " string bposn)))
902 (setq posn (and eposn
903 (string-match "[^ \n]" string eposn)))
904 (substring string bposn eposn)))
906 (while (and posn
907 (not (eq (aref string posn) ?:)))
908 (push (let* ((bposn posn)
909 (eposn (string-match " " string bposn)))
910 (setq posn (and eposn
911 (string-match "[^ \n]" string eposn)))
912 (substring string bposn eposn))
913 (erc-response.command-args msg)))
914 (when posn
915 (let ((str (substring string (1+ posn))))
916 (push str (erc-response.command-args msg))))
918 (setf (erc-response.contents msg)
919 (first (erc-response.command-args msg)))
921 (setf (erc-response.command-args msg)
922 (nreverse (erc-response.command-args msg)))
924 (erc-decode-parsed-server-response msg)
926 (erc-handle-parsed-server-response proc msg)))))
928 (defun erc-decode-parsed-server-response (parsed-response)
929 "Decode a pre-parsed PARSED-RESPONSE before it can be handled.
931 If there is a channel name in `erc-response.command-args', decode
932 `erc-response' according to this channel name and
933 `erc-encoding-coding-alist', or use `erc-server-coding-system'
934 for decoding."
935 (let ((args (erc-response.command-args parsed-response))
936 (decode-target nil)
937 (decoded-args ()))
938 (dolist (arg args nil)
939 (when (string-match "^[#&].*" arg)
940 (setq decode-target arg)))
941 (when (stringp decode-target)
942 (setq decode-target (erc-decode-string-from-target decode-target nil)))
943 (setf (erc-response.unparsed parsed-response)
944 (erc-decode-string-from-target
945 (erc-response.unparsed parsed-response)
946 decode-target))
947 (setf (erc-response.sender parsed-response)
948 (erc-decode-string-from-target
949 (erc-response.sender parsed-response)
950 decode-target))
951 (setf (erc-response.command parsed-response)
952 (erc-decode-string-from-target
953 (erc-response.command parsed-response)
954 decode-target))
955 (dolist (arg (nreverse args) nil)
956 (push (erc-decode-string-from-target arg decode-target)
957 decoded-args))
958 (setf (erc-response.command-args parsed-response) decoded-args)
959 (setf (erc-response.contents parsed-response)
960 (erc-decode-string-from-target
961 (erc-response.contents parsed-response)
962 decode-target))))
964 (defun erc-handle-parsed-server-response (process parsed-response)
965 "Handle a pre-parsed PARSED-RESPONSE from PROCESS.
967 Hands off to helper functions via `erc-call-hooks'."
968 (if (member (erc-response.command parsed-response)
969 erc-server-prevent-duplicates)
970 (let ((m (erc-response.unparsed parsed-response)))
971 ;; duplicate supression
972 (if (< (or (gethash m erc-server-duplicates) 0)
973 (- (erc-current-time) erc-server-duplicate-timeout))
974 (erc-call-hooks process parsed-response))
975 (puthash m (erc-current-time) erc-server-duplicates))
976 ;; Hand off to the relevant handler.
977 (erc-call-hooks process parsed-response)))
979 (defun erc-get-hook (command)
980 "Return the hook variable associated with COMMAND.
982 See also `erc-server-responses'."
983 (gethash (format (if (numberp command) "%03i" "%s") command)
984 erc-server-responses))
986 (defun erc-call-hooks (process message)
987 "Call hooks associated with MESSAGE in PROCESS.
989 Finds hooks by looking in the `erc-server-responses' hashtable."
990 (let ((hook (or (erc-get-hook (erc-response.command message))
991 'erc-default-server-functions)))
992 (run-hook-with-args-until-success hook process message)
993 (erc-with-server-buffer
994 (run-hook-with-args 'erc-timer-hook (erc-current-time)))))
996 (add-hook 'erc-default-server-functions 'erc-handle-unknown-server-response)
998 (defun erc-handle-unknown-server-response (proc parsed)
999 "Display unknown server response's message."
1000 (let ((line (concat (erc-response.sender parsed)
1002 (erc-response.command parsed)
1004 (mapconcat 'identity (erc-response.command-args parsed)
1005 " "))))
1006 (erc-display-message parsed 'notice proc line)))
1009 (put 'define-erc-response-handler 'edebug-form-spec
1010 '(&define :name erc-response-handler
1011 (name &rest name)
1012 &optional sexp sexp def-body))
1014 (defmacro* define-erc-response-handler ((name &rest aliases)
1015 &optional extra-fn-doc extra-var-doc
1016 &rest fn-body)
1017 "Define an ERC handler hook/function pair.
1018 NAME is the response name as sent by the server (see the IRC RFC for
1019 meanings).
1021 This creates:
1022 - a hook variable `erc-server-NAME-functions' initialized to `erc-server-NAME'.
1023 - a function `erc-server-NAME' with body FN-BODY.
1025 If ALIASES is non-nil, each alias in ALIASES is `defalias'ed to
1026 `erc-server-NAME'.
1027 Alias hook variables are created as `erc-server-ALIAS-functions' and
1028 initialized to the same default value as `erc-server-NAME-functions'.
1030 FN-BODY is the body of `erc-server-NAME' it may refer to the two
1031 function arguments PROC and PARSED.
1033 If EXTRA-FN-DOC is non-nil, it is inserted at the beginning of the
1034 defined function's docstring.
1036 If EXTRA-VAR-DOC is non-nil, it is inserted at the beginning of the
1037 defined variable's docstring.
1039 As an example:
1041 (define-erc-response-handler (311 WHOIS WI)
1042 \"Some non-generic function documentation.\"
1043 \"Some non-generic variable documentation.\"
1044 (do-stuff-with-whois proc parsed))
1046 Would expand to:
1048 (prog2
1049 (defvar erc-server-311-functions 'erc-server-311
1050 \"Some non-generic variable documentation.
1052 Hook called upon receiving a 311 server response.
1053 Each function is called with two arguments, the process associated
1054 with the response and the parsed response.
1055 See also `erc-server-311'.\")
1057 (defun erc-server-311 (proc parsed)
1058 \"Some non-generic function documentation.
1060 Handler for a 311 server response.
1061 PROC is the server process which returned the response.
1062 PARSED is the actual response as an `erc-response' struct.
1063 If you want to add responses don't modify this function, but rather
1064 add things to `erc-server-311-functions' instead.\"
1065 (do-stuff-with-whois proc parsed))
1067 (puthash \"311\" 'erc-server-311-functions erc-server-responses)
1068 (puthash \"WHOIS\" 'erc-server-WHOIS-functions erc-server-responses)
1069 (puthash \"WI\" 'erc-server-WI-functions erc-server-responses)
1071 (defalias 'erc-server-WHOIS 'erc-server-311)
1072 (defvar erc-server-WHOIS-functions 'erc-server-311
1073 \"Some non-generic variable documentation.
1075 Hook called upon receiving a WHOIS server response.
1077 Each function is called with two arguments, the process associated
1078 with the response and the parsed response. If the function returns
1079 non-nil, stop processing the hook. Otherwise, continue.
1081 See also `erc-server-311'.\")
1083 (defalias 'erc-server-WI 'erc-server-311)
1084 (defvar erc-server-WI-functions 'erc-server-311
1085 \"Some non-generic variable documentation.
1087 Hook called upon receiving a WI server response.
1088 Each function is called with two arguments, the process associated
1089 with the response and the parsed response. If the function returns
1090 non-nil, stop processing the hook. Otherwise, continue.
1092 See also `erc-server-311'.\"))
1094 \(fn (NAME &rest ALIASES) &optional EXTRA-FN-DOC EXTRA-VAR-DOC &rest FN-BODY)"
1095 (if (numberp name) (setq name (intern (format "%03i" name))))
1096 (setq aliases (mapcar (lambda (a)
1097 (if (numberp a)
1098 (format "%03i" a)
1100 aliases))
1101 (let* ((hook-name (intern (format "erc-server-%s-functions" name)))
1102 (fn-name (intern (format "erc-server-%s" name)))
1103 (hook-doc (format "%sHook called upon receiving a %%s server response.
1104 Each function is called with two arguments, the process associated
1105 with the response and the parsed response. If the function returns
1106 non-nil, stop processing the hook. Otherwise, continue.
1108 See also `%s'."
1109 (if extra-var-doc
1110 (concat extra-var-doc "\n\n")
1112 fn-name))
1113 (fn-doc (format "%sHandler for a %s server response.
1114 PROC is the server process which returned the response.
1115 PARSED is the actual response as an `erc-response' struct.
1116 If you want to add responses don't modify this function, but rather
1117 add things to `%s' instead."
1118 (if extra-fn-doc
1119 (concat extra-fn-doc "\n\n")
1121 name hook-name))
1122 (fn-alternates
1123 (loop for alias in aliases
1124 collect (intern (format "erc-server-%s" alias))))
1125 (var-alternates
1126 (loop for alias in aliases
1127 collect (intern (format "erc-server-%s-functions" alias)))))
1128 `(prog2
1129 ;; Normal hook variable.
1130 (defvar ,hook-name ',fn-name ,(format hook-doc name))
1131 ;; Handler function
1132 (defun ,fn-name (proc parsed)
1133 ,fn-doc
1134 ,@fn-body)
1136 ;; Make find-function and find-variable find them
1137 (put ',fn-name 'definition-name ',name)
1138 (put ',hook-name 'definition-name ',name)
1140 ;; Hashtable map of responses to hook variables
1141 ,@(loop for response in (cons name aliases)
1142 for var in (cons hook-name var-alternates)
1143 collect `(puthash ,(format "%s" response) ',var
1144 erc-server-responses))
1145 ;; Alternates.
1146 ;; Functions are defaliased, hook variables are defvared so we
1147 ;; can add hooks to one alias, but not another.
1148 ,@(loop for fn in fn-alternates
1149 for var in var-alternates
1150 for a in aliases
1151 nconc (list `(defalias ',fn ',fn-name)
1152 `(defvar ,var ',fn-name ,(format hook-doc a))
1153 `(put ',var 'definition-name ',hook-name))))))
1155 (define-erc-response-handler (ERROR)
1156 "Handle an ERROR command from the server." nil
1157 (setq erc-server-error-occurred t)
1158 (erc-display-message
1159 parsed 'error nil 'ERROR
1160 ?s (erc-response.sender parsed) ?c (erc-response.contents parsed)))
1162 (define-erc-response-handler (INVITE)
1163 "Handle invitation messages."
1165 (let ((target (first (erc-response.command-args parsed)))
1166 (chnl (erc-response.contents parsed)))
1167 (multiple-value-bind (nick login host)
1168 (erc-parse-user (erc-response.sender parsed))
1169 (setq erc-invitation chnl)
1170 (when (string= target (erc-current-nick))
1171 (erc-display-message
1172 parsed 'notice 'active
1173 'INVITE ?n nick ?u login ?h host ?c chnl)))))
1176 (define-erc-response-handler (JOIN)
1177 "Handle join messages."
1179 (let ((chnl (erc-response.contents parsed))
1180 (buffer nil))
1181 (multiple-value-bind (nick login host)
1182 (erc-parse-user (erc-response.sender parsed))
1183 ;; strip the stupid combined JOIN facility (IRC 2.9)
1184 (if (string-match "^\\(.*\\)?\^g.*$" chnl)
1185 (setq chnl (match-string 1 chnl)))
1186 (save-excursion
1187 (let* ((str (cond
1188 ;; If I have joined a channel
1189 ((erc-current-nick-p nick)
1190 (setq buffer (erc-open erc-session-server erc-session-port
1191 nick erc-session-user-full-name
1192 nil nil
1193 erc-default-recipients chnl
1194 erc-server-process))
1195 (when buffer
1196 (set-buffer buffer)
1197 (erc-add-default-channel chnl)
1198 (erc-server-send (format "MODE %s" chnl)))
1199 (erc-with-buffer (chnl proc)
1200 (erc-channel-begin-receiving-names))
1201 (erc-update-mode-line)
1202 (run-hooks 'erc-join-hook)
1203 (erc-make-notice
1204 (erc-format-message 'JOIN-you ?c chnl)))
1206 (setq buffer (erc-get-buffer chnl proc))
1207 (erc-make-notice
1208 (erc-format-message
1209 'JOIN ?n nick ?u login ?h host ?c chnl))))))
1210 (when buffer (set-buffer buffer))
1211 (erc-update-channel-member chnl nick nick t nil nil host login)
1212 ;; on join, we want to stay in the new channel buffer
1213 ;;(set-buffer ob)
1214 (erc-display-message parsed nil buffer str))))))
1216 (define-erc-response-handler (KICK)
1217 "Handle kick messages received from the server." nil
1218 (let* ((ch (first (erc-response.command-args parsed)))
1219 (tgt (second (erc-response.command-args parsed)))
1220 (reason (erc-trim-string (erc-response.contents parsed)))
1221 (buffer (erc-get-buffer ch proc)))
1222 (multiple-value-bind (nick login host)
1223 (erc-parse-user (erc-response.sender parsed))
1224 (erc-remove-channel-member buffer tgt)
1225 (cond
1226 ((string= tgt (erc-current-nick))
1227 (erc-display-message
1228 parsed 'notice buffer
1229 'KICK-you ?n nick ?u login ?h host ?c ch ?r reason)
1230 (run-hook-with-args 'erc-kick-hook buffer)
1231 (erc-with-buffer
1232 (buffer)
1233 (erc-remove-channel-users))
1234 (erc-delete-default-channel ch buffer)
1235 (erc-update-mode-line buffer))
1236 ((string= nick (erc-current-nick))
1237 (erc-display-message
1238 parsed 'notice buffer
1239 'KICK-by-you ?k tgt ?c ch ?r reason))
1240 (t (erc-display-message
1241 parsed 'notice buffer
1242 'KICK ?k tgt ?n nick ?u login ?h host ?c ch ?r reason))))))
1244 (define-erc-response-handler (MODE)
1245 "Handle server mode changes." nil
1246 (let ((tgt (first (erc-response.command-args parsed)))
1247 (mode (mapconcat 'identity (cdr (erc-response.command-args parsed))
1248 " ")))
1249 (multiple-value-bind (nick login host)
1250 (erc-parse-user (erc-response.sender parsed))
1251 (erc-log (format "MODE: %s -> %s: %s" nick tgt mode))
1252 ;; dirty hack
1253 (let ((buf (cond ((erc-channel-p tgt)
1254 (erc-get-buffer tgt proc))
1255 ((string= tgt (erc-current-nick)) nil)
1256 ((erc-active-buffer) (erc-active-buffer))
1257 (t (erc-get-buffer tgt)))))
1258 (with-current-buffer (or buf
1259 (current-buffer))
1260 (erc-update-modes tgt mode nick host login))
1261 (if (or (string= login "") (string= host ""))
1262 (erc-display-message parsed 'notice buf
1263 'MODE-nick ?n nick
1264 ?t tgt ?m mode)
1265 (erc-display-message parsed 'notice buf
1266 'MODE ?n nick ?u login
1267 ?h host ?t tgt ?m mode)))
1268 (erc-banlist-update proc parsed))))
1270 (define-erc-response-handler (NICK)
1271 "Handle nick change messages." nil
1272 (let ((nn (erc-response.contents parsed))
1273 bufs)
1274 (multiple-value-bind (nick login host)
1275 (erc-parse-user (erc-response.sender parsed))
1276 (setq bufs (erc-buffer-list-with-nick nick proc))
1277 (erc-log (format "NICK: %s -> %s" nick nn))
1278 ;; if we had a query with this user, make sure future messages will be
1279 ;; sent to the correct nick. also add to bufs, since the user will want
1280 ;; to see the nick change in the query, and if it's a newly begun query,
1281 ;; erc-channel-users won't contain it
1282 (erc-buffer-filter
1283 (lambda ()
1284 (when (equal (erc-default-target) nick)
1285 (setq erc-default-recipients
1286 (cons nn (cdr erc-default-recipients)))
1287 (rename-buffer nn)
1288 (erc-update-mode-line)
1289 (add-to-list 'bufs (current-buffer)))))
1290 (erc-update-user-nick nick nn host nil nil login)
1291 (cond
1292 ((string= nick (erc-current-nick))
1293 (add-to-list 'bufs (erc-server-buffer))
1294 (erc-set-current-nick nn)
1295 (erc-update-mode-line)
1296 (setq erc-nick-change-attempt-count 0)
1297 (setq erc-default-nicks (if (consp erc-nick) erc-nick (list erc-nick)))
1298 (erc-display-message
1299 parsed 'notice bufs
1300 'NICK-you ?n nick ?N nn)
1301 (run-hook-with-args 'erc-nick-changed-functions nn nick))
1303 (erc-handle-user-status-change 'nick (list nick login host) (list nn))
1304 (erc-display-message parsed 'notice bufs 'NICK ?n nick
1305 ?u login ?h host ?N nn))))))
1307 (define-erc-response-handler (PART)
1308 "Handle part messages." nil
1309 (let* ((chnl (first (erc-response.command-args parsed)))
1310 (reason (erc-trim-string (erc-response.contents parsed)))
1311 (buffer (erc-get-buffer chnl proc)))
1312 (multiple-value-bind (nick login host)
1313 (erc-parse-user (erc-response.sender parsed))
1314 (erc-remove-channel-member buffer nick)
1315 (erc-display-message parsed 'notice buffer
1316 'PART ?n nick ?u login
1317 ?h host ?c chnl ?r (or reason ""))
1318 (when (string= nick (erc-current-nick))
1319 (run-hook-with-args 'erc-part-hook buffer)
1320 (erc-with-buffer
1321 (buffer)
1322 (erc-remove-channel-users))
1323 (erc-delete-default-channel chnl buffer)
1324 (erc-update-mode-line buffer)
1325 (when erc-kill-buffer-on-part
1326 (kill-buffer buffer))))))
1328 (define-erc-response-handler (PING)
1329 "Handle ping messages." nil
1330 (let ((pinger (first (erc-response.command-args parsed))))
1331 (erc-log (format "PING: %s" pinger))
1332 ;; ping response to the server MUST be forced, or you can lose big
1333 (erc-server-send (format "PONG :%s" pinger) t)
1334 (when erc-verbose-server-ping
1335 (erc-display-message
1336 parsed 'error proc
1337 'PING ?s (erc-time-diff erc-server-last-ping-time (erc-current-time))))
1338 (setq erc-server-last-ping-time (erc-current-time))))
1340 (define-erc-response-handler (PONG)
1341 "Handle pong messages." nil
1342 (let ((time (string-to-number (erc-response.contents parsed))))
1343 (when (> time 0)
1344 (setq erc-server-lag (erc-time-diff time (erc-current-time)))
1345 (when erc-verbose-server-ping
1346 (erc-display-message
1347 parsed 'notice proc 'PONG
1348 ?h (first (erc-response.command-args parsed)) ?i erc-server-lag
1349 ?s (if (/= erc-server-lag 1) "s" "")))
1350 (erc-update-mode-line))))
1352 (define-erc-response-handler (PRIVMSG NOTICE)
1353 "Handle private messages, including messages in channels." nil
1354 (let ((sender-spec (erc-response.sender parsed))
1355 (cmd (erc-response.command parsed))
1356 (tgt (car (erc-response.command-args parsed)))
1357 (msg (erc-response.contents parsed)))
1358 (if (or (erc-ignored-user-p sender-spec)
1359 (erc-ignored-reply-p msg tgt proc))
1360 (when erc-minibuffer-ignored
1361 (message "Ignored %s from %s to %s" cmd sender-spec tgt))
1362 (let* ((sndr (erc-parse-user sender-spec))
1363 (nick (nth 0 sndr))
1364 (login (nth 1 sndr))
1365 (host (nth 2 sndr))
1366 (msgp (string= cmd "PRIVMSG"))
1367 (noticep (string= cmd "NOTICE"))
1368 ;; S.B. downcase *both* tgt and current nick
1369 (privp (erc-current-nick-p tgt))
1370 s buffer
1371 fnick)
1372 (setf (erc-response.contents parsed) msg)
1373 (setq buffer (erc-get-buffer (if privp nick tgt) proc))
1374 (when buffer
1375 (with-current-buffer buffer
1376 ;; update the chat partner info. Add to the list if private
1377 ;; message. We will accumulate private identities indefinitely
1378 ;; at this point.
1379 (erc-update-channel-member (if privp nick tgt) nick nick
1380 privp nil nil host login nil nil t)
1381 (let ((cdata (erc-get-channel-user nick)))
1382 (setq fnick (funcall erc-format-nick-function
1383 (car cdata) (cdr cdata))))))
1384 (cond
1385 ((erc-is-message-ctcp-p msg)
1386 (setq s (if msgp
1387 (erc-process-ctcp-query proc parsed nick login host)
1388 (erc-process-ctcp-reply proc parsed nick login host
1389 (match-string 1 msg)))))
1391 (setcar erc-server-last-peers nick)
1392 (setq s (erc-format-privmessage
1393 (or fnick nick) msg
1394 ;; If buffer is a query buffer,
1395 ;; format the nick as for a channel.
1396 (and (not (and buffer
1397 (erc-query-buffer-p buffer)
1398 erc-format-query-as-channel-p))
1399 privp)
1400 msgp))))
1401 (when s
1402 (if (and noticep privp)
1403 (progn
1404 (run-hook-with-args 'erc-echo-notice-always-hook
1405 s parsed buffer nick)
1406 (run-hook-with-args-until-success
1407 'erc-echo-notice-hook s parsed buffer nick))
1408 (erc-display-message parsed nil buffer s)))
1409 (when (string= cmd "PRIVMSG")
1410 (erc-auto-query proc parsed))))))
1412 ;; FIXME: need clean way of specifiying extra hooks in
1413 ;; define-erc-response-handler.
1414 (add-hook 'erc-server-PRIVMSG-functions 'erc-auto-query)
1416 (define-erc-response-handler (QUIT)
1417 "Another user has quit IRC." nil
1418 (let ((reason (erc-response.contents parsed))
1419 bufs)
1420 (multiple-value-bind (nick login host)
1421 (erc-parse-user (erc-response.sender parsed))
1422 (setq bufs (erc-buffer-list-with-nick nick proc))
1423 (erc-remove-user nick)
1424 (setq reason (erc-wash-quit-reason reason nick login host))
1425 (erc-display-message parsed 'notice bufs
1426 'QUIT ?n nick ?u login
1427 ?h host ?r reason))))
1429 (define-erc-response-handler (TOPIC)
1430 "The channel topic has changed." nil
1431 (let* ((ch (first (erc-response.command-args parsed)))
1432 (topic (erc-trim-string (erc-response.contents parsed)))
1433 (time (format-time-string "%T %m/%d/%y" (current-time))))
1434 (multiple-value-bind (nick login host)
1435 (erc-parse-user (erc-response.sender parsed))
1436 (erc-update-channel-member ch nick nick nil nil nil host login)
1437 (erc-update-channel-topic ch (format "%s\C-o (%s, %s)" topic nick time))
1438 (erc-display-message parsed 'notice (erc-get-buffer ch proc)
1439 'TOPIC ?n nick ?u login ?h host
1440 ?c ch ?T topic))))
1442 (define-erc-response-handler (WALLOPS)
1443 "Display a WALLOPS message." nil
1444 (let ((message (erc-response.contents parsed)))
1445 (multiple-value-bind (nick login host)
1446 (erc-parse-user (erc-response.sender parsed))
1447 (erc-display-message
1448 parsed 'notice nil
1449 'WALLOPS ?n nick ?m message))))
1451 (define-erc-response-handler (001)
1452 "Set `erc-server-current-nick' to reflect server settings and display the welcome message."
1454 (erc-set-current-nick (first (erc-response.command-args parsed)))
1455 (erc-update-mode-line) ; needed here?
1456 (setq erc-nick-change-attempt-count 0)
1457 (setq erc-default-nicks (if (consp erc-nick) erc-nick (list erc-nick)))
1458 (erc-display-message
1459 parsed 'notice 'active (erc-response.contents parsed)))
1461 (define-erc-response-handler (MOTD 002 003 371 372 374 375)
1462 "Display the server's message of the day." nil
1463 (erc-handle-login)
1464 (erc-display-message
1465 parsed 'notice (if erc-server-connected 'active proc)
1466 (erc-response.contents parsed)))
1468 (define-erc-response-handler (376 422)
1469 "End of MOTD/MOTD is missing." nil
1470 (erc-server-MOTD proc parsed)
1471 (erc-connection-established proc parsed))
1473 (define-erc-response-handler (004)
1474 "Display the server's identification." nil
1475 (multiple-value-bind (server-name server-version)
1476 (cdr (erc-response.command-args parsed))
1477 (setq erc-server-version server-version)
1478 (setq erc-server-announced-name server-name)
1479 (erc-update-mode-line-buffer (process-buffer proc))
1480 (erc-display-message
1481 parsed 'notice proc
1482 's004 ?s server-name ?v server-version
1483 ?U (fourth (erc-response.command-args parsed))
1484 ?C (fifth (erc-response.command-args parsed)))))
1486 (define-erc-response-handler (005)
1487 "Set the variable `erc-server-parameters' and display the received message.
1489 According to RFC 2812, suggests alternate servers on the network.
1490 Many servers, however, use this code to show which parameters they have set,
1491 for example, the network identifier, maximum allowed topic length, whether
1492 certain commands are accepted and more. See documentation for
1493 `erc-server-parameters' for more information on the parameters sent.
1495 A server may send more than one 005 message."
1497 (let ((line (mapconcat 'identity
1498 (setf (erc-response.command-args parsed)
1499 (cdr (erc-response.command-args parsed)))
1500 " ")))
1501 (while (erc-response.command-args parsed)
1502 (let ((section (pop (erc-response.command-args parsed))))
1503 ;; fill erc-server-parameters
1504 (when (string-match "^\\([A-Z]+\\)\=\\(.*\\)$\\|^\\([A-Z]+\\)$"
1505 section)
1506 (add-to-list 'erc-server-parameters
1507 `(,(or (match-string 1 section)
1508 (match-string 3 section))
1510 ,(match-string 2 section))))))
1511 (erc-display-message parsed 'notice proc line)))
1513 (define-erc-response-handler (221)
1514 "Display the current user modes." nil
1515 (let* ((nick (first (erc-response.command-args parsed)))
1516 (modes (mapconcat 'identity
1517 (cdr (erc-response.command-args parsed)) " ")))
1518 (erc-set-modes nick modes)
1519 (erc-display-message parsed 'notice 'active 's221 ?n nick ?m modes)))
1521 (define-erc-response-handler (252)
1522 "Display the number of IRC operators online." nil
1523 (erc-display-message parsed 'notice 'active 's252
1524 ?i (second (erc-response.command-args parsed))))
1526 (define-erc-response-handler (253)
1527 "Display the number of unknown connections." nil
1528 (erc-display-message parsed 'notice 'active 's253
1529 ?i (second (erc-response.command-args parsed))))
1531 (define-erc-response-handler (254)
1532 "Display the number of channels formed." nil
1533 (erc-display-message parsed 'notice 'active 's254
1534 ?i (second (erc-response.command-args parsed))))
1536 (define-erc-response-handler (250 251 255 256 257 258 259 265 266 377 378)
1537 "Generic display of server messages as notices.
1539 See `erc-display-server-message'." nil
1540 (erc-display-server-message proc parsed))
1542 (define-erc-response-handler (275)
1543 "Display secure connection message." nil
1544 (multiple-value-bind (nick user message)
1545 (cdr (erc-response.command-args parsed))
1546 (erc-display-message
1547 parsed 'notice 'active 's275
1548 ?n nick
1549 ?m (mapconcat 'identity (cddr (erc-response.command-args parsed))
1550 " "))))
1552 (define-erc-response-handler (290)
1553 "Handle dancer-ircd CAPAB messages." nil nil)
1555 (define-erc-response-handler (301)
1556 "AWAY notice." nil
1557 (erc-display-message parsed 'notice 'active 's301
1558 ?n (second (erc-response.command-args parsed))
1559 ?r (erc-response.contents parsed)))
1561 (define-erc-response-handler (303)
1562 "ISON reply" nil
1563 (erc-display-message parsed 'notice 'active 's303
1564 ?n (second (erc-response.command-args parsed))))
1566 (define-erc-response-handler (305)
1567 "Return from AWAYness." nil
1568 (erc-process-away proc nil)
1569 (erc-display-message parsed 'notice 'active
1570 's305 ?m (erc-response.contents parsed)))
1572 (define-erc-response-handler (306)
1573 "Set AWAYness." nil
1574 (erc-process-away proc t)
1575 (erc-display-message parsed 'notice 'active
1576 's306 ?m (erc-response.contents parsed)))
1578 (define-erc-response-handler (307)
1579 "Display nick-identified message." nil
1580 (multiple-value-bind (nick user message)
1581 (cdr (erc-response.command-args parsed))
1582 (erc-display-message
1583 parsed 'notice 'active 's307
1584 ?n nick
1585 ?m (mapconcat 'identity (cddr (erc-response.command-args parsed))
1586 " "))))
1588 (define-erc-response-handler (311 314)
1589 "WHOIS/WHOWAS notices." nil
1590 (let ((fname (erc-response.contents parsed))
1591 (catalog-entry (intern (format "s%s" (erc-response.command parsed)))))
1592 (multiple-value-bind (nick user host)
1593 (cdr (erc-response.command-args parsed))
1594 (erc-update-user-nick nick nick host nil fname user)
1595 (erc-display-message
1596 parsed 'notice 'active catalog-entry
1597 ?n nick ?f fname ?u user ?h host))))
1599 (define-erc-response-handler (312)
1600 "Server name response in WHOIS." nil
1601 (multiple-value-bind (nick server-host)
1602 (cdr (erc-response.command-args parsed))
1603 (erc-display-message
1604 parsed 'notice 'active 's312
1605 ?n nick ?s server-host ?c (erc-response.contents parsed))))
1607 (define-erc-response-handler (313)
1608 "IRC Operator response in WHOIS." nil
1609 (erc-display-message
1610 parsed 'notice 'active 's313
1611 ?n (second (erc-response.command-args parsed))))
1613 (define-erc-response-handler (315 318 323 369)
1614 ;; 315 - End of WHO
1615 ;; 318 - End of WHOIS list
1616 ;; 323 - End of channel LIST
1617 ;; 369 - End of WHOWAS
1618 "End of WHO/WHOIS/LIST/WHOWAS notices." nil
1619 (ignore proc parsed))
1621 (define-erc-response-handler (317)
1622 "IDLE notice." nil
1623 (multiple-value-bind (nick seconds-idle on-since time)
1624 (cdr (erc-response.command-args parsed))
1625 (setq time (when on-since
1626 (format-time-string "%T %Y/%m/%d"
1627 (erc-string-to-emacs-time on-since))))
1628 (erc-update-user-nick nick nick nil nil nil
1629 (and time (format "on since %s" time)))
1630 (if time
1631 (erc-display-message
1632 parsed 'notice 'active 's317-on-since
1633 ?n nick ?i (erc-sec-to-time (string-to-number seconds-idle)) ?t time)
1634 (erc-display-message
1635 parsed 'notice 'active 's317
1636 ?n nick ?i (erc-sec-to-time (string-to-number seconds-idle))))))
1638 (define-erc-response-handler (319)
1639 "Channel names in WHOIS response." nil
1640 (erc-display-message
1641 parsed 'notice 'active 's319
1642 ?n (second (erc-response.command-args parsed))
1643 ?c (erc-response.contents parsed)))
1645 (define-erc-response-handler (320)
1646 "Identified user in WHOIS." nil
1647 (erc-display-message
1648 parsed 'notice 'active 's320
1649 ?n (second (erc-response.command-args parsed))))
1651 (define-erc-response-handler (321)
1652 "LIST header." nil
1653 (setq erc-channel-list nil))
1655 (defun erc-server-321-message (proc parsed)
1656 "Display a message for the 321 event."
1657 (erc-display-message parsed 'notice proc 's321)
1658 nil)
1659 (add-hook 'erc-server-321-functions 'erc-server-321-message t)
1661 (define-erc-response-handler (322)
1662 "LIST notice." nil
1663 (let ((topic (erc-response.contents parsed)))
1664 (multiple-value-bind (channel num-users)
1665 (cdr (erc-response.command-args parsed))
1666 (add-to-list 'erc-channel-list (list channel))
1667 (erc-update-channel-topic channel topic))))
1669 (defun erc-server-322-message (proc parsed)
1670 "Display a message for the 322 event."
1671 (let ((topic (erc-response.contents parsed)))
1672 (multiple-value-bind (channel num-users)
1673 (cdr (erc-response.command-args parsed))
1674 (erc-display-message
1675 parsed 'notice proc 's322
1676 ?c channel ?u num-users ?t (or topic "")))))
1677 (add-hook 'erc-server-322-functions 'erc-server-322-message t)
1679 (define-erc-response-handler (324)
1680 "Channel or nick modes." nil
1681 (let ((channel (second (erc-response.command-args parsed)))
1682 (modes (mapconcat 'identity (cddr (erc-response.command-args parsed))
1683 " ")))
1684 (erc-set-modes channel modes)
1685 (erc-display-message
1686 parsed 'notice (erc-get-buffer channel proc)
1687 's324 ?c channel ?m modes)))
1689 (define-erc-response-handler (329)
1690 "Channel creation date." nil
1691 (let ((channel (second (erc-response.command-args parsed)))
1692 (time (erc-string-to-emacs-time
1693 (third (erc-response.command-args parsed)))))
1694 (erc-display-message
1695 parsed 'notice (erc-get-buffer channel proc)
1696 's329 ?c channel ?t (format-time-string "%A %Y/%m/%d %X" time))))
1698 (define-erc-response-handler (330)
1699 "Nick is authed as (on Quakenet network)." nil
1700 ;; FIXME: I don't know what the magic numbers mean. Mummy, make
1701 ;; the magic numbers go away.
1702 ;; No seriously, I have no clue about the format of this command,
1703 ;; and don't sit on Quakenet, so can't test. Originally we had:
1704 ;; nick == (aref parsed 3)
1705 ;; authaccount == (aref parsed 4)
1706 ;; authmsg == (aref parsed 5)
1707 ;; The guesses below are, well, just that. -- Lawrence 2004/05/10
1708 (let ((nick (second (erc-response.command-args parsed)))
1709 (authaccount (third (erc-response.command-args parsed)))
1710 (authmsg (erc-response.contents parsed)))
1711 (erc-display-message parsed 'notice 'active 's330
1712 ?n nick ?a authmsg ?i authaccount)))
1714 (define-erc-response-handler (331)
1715 "No topic set for channel." nil
1716 (let ((channel (second (erc-response.command-args parsed)))
1717 (topic (erc-response.contents parsed)))
1718 (erc-display-message parsed 'notice (erc-get-buffer channel proc)
1719 's331 ?c channel)))
1721 (define-erc-response-handler (332)
1722 "TOPIC notice." nil
1723 (let ((channel (second (erc-response.command-args parsed)))
1724 (topic (erc-response.contents parsed)))
1725 (erc-update-channel-topic channel topic)
1726 (erc-display-message parsed 'notice (erc-get-buffer channel proc)
1727 's332 ?c channel ?T topic)))
1729 (define-erc-response-handler (333)
1730 "Who set the topic, and when." nil
1731 (multiple-value-bind (channel nick time)
1732 (cdr (erc-response.command-args parsed))
1733 (setq time (format-time-string "%T %Y/%m/%d"
1734 (erc-string-to-emacs-time time)))
1735 (erc-update-channel-topic channel
1736 (format "\C-o (%s, %s)" nick time)
1737 'append)
1738 (erc-display-message parsed 'notice (erc-get-buffer channel proc)
1739 's333 ?c channel ?n nick ?t time)))
1741 (define-erc-response-handler (341)
1742 "Let user know when an INVITE attempt has been sent successfully."
1744 (multiple-value-bind (nick channel)
1745 (cdr (erc-response.command-args parsed))
1746 (erc-display-message parsed 'notice (erc-get-buffer channel proc)
1747 's341 ?n nick ?c channel)))
1749 (define-erc-response-handler (352)
1750 "WHO notice." nil
1751 (multiple-value-bind (channel user host server nick away-flag)
1752 (cdr (erc-response.command-args parsed))
1753 (let ((full-name (erc-response.contents parsed))
1754 hopcount)
1755 (when (string-match "\\(^[0-9]+ \\)\\(.*\\)$" full-name)
1756 (setq hopcount (match-string 1 full-name))
1757 (setq full-name (match-string 2 full-name)))
1758 (erc-update-channel-member channel nick nick nil nil nil host
1759 user full-name)
1760 (erc-display-message parsed 'notice 'active 's352
1761 ?c channel ?n nick ?a away-flag
1762 ?u user ?h host ?f full-name))))
1764 (define-erc-response-handler (353)
1765 "NAMES notice." nil
1766 (let ((channel (third (erc-response.command-args parsed)))
1767 (users (erc-response.contents parsed)))
1768 (erc-display-message parsed 'notice (or (erc-get-buffer channel proc)
1769 'active)
1770 's353 ?c channel ?u users)
1771 (erc-with-buffer (channel proc)
1772 (erc-channel-receive-names users))))
1774 (define-erc-response-handler (366)
1775 "End of NAMES." nil
1776 (erc-with-buffer ((second (erc-response.command-args parsed)) proc)
1777 (erc-channel-end-receiving-names)))
1779 (define-erc-response-handler (367)
1780 "Channel ban list entries." nil
1781 (multiple-value-bind (channel banmask setter time)
1782 (cdr (erc-response.command-args parsed))
1783 ;; setter and time are not standard
1784 (if setter
1785 (erc-display-message parsed 'notice 'active 's367-set-by
1786 ?c channel
1787 ?b banmask
1788 ?s setter
1789 ?t (or time ""))
1790 (erc-display-message parsed 'notice 'active 's367
1791 ?c channel
1792 ?b banmask))))
1794 (define-erc-response-handler (368)
1795 "End of channel ban list." nil
1796 (let ((channel (second (erc-response.command-args parsed))))
1797 (erc-display-message parsed 'notice 'active 's368
1798 ?c channel)))
1800 (define-erc-response-handler (379)
1801 "Forwarding to another channel." nil
1802 ;; FIXME: Yet more magic numbers in original code, I'm guessing this
1803 ;; command takes two arguments, and doesn't have any "contents". --
1804 ;; Lawrence 2004/05/10
1805 (multiple-value-bind (from to)
1806 (cdr (erc-response.command-args parsed))
1807 (erc-display-message parsed 'notice 'active
1808 's379 ?c from ?f to)))
1810 (define-erc-response-handler (391)
1811 "Server's time string." nil
1812 (erc-display-message
1813 parsed 'notice 'active
1814 's391 ?s (second (erc-response.command-args parsed))
1815 ?t (third (erc-response.command-args parsed))))
1817 (define-erc-response-handler (401)
1818 "No such nick/channel." nil
1819 (let ((nick/channel (second (erc-response.command-args parsed))))
1820 (when erc-whowas-on-nosuchnick
1821 (erc-log (format "cmd: WHOWAS: %s" nick/channel))
1822 (erc-server-send (format "WHOWAS %s 1" nick/channel)))
1823 (erc-display-message parsed '(notice error) 'active
1824 's401 ?n nick/channel)))
1826 (define-erc-response-handler (403)
1827 "No such channel." nil
1828 (erc-display-message parsed '(notice error) 'active
1829 's403 ?c (second (erc-response.command-args parsed))))
1831 (define-erc-response-handler (404)
1832 "Cannot send to channel." nil
1833 (erc-display-message parsed '(notice error) 'active
1834 's404 ?c (second (erc-response.command-args parsed))))
1837 (define-erc-response-handler (405)
1838 "Can't join that many channels." nil
1839 (erc-display-message parsed '(notice error) 'active
1840 's405 ?c (second (erc-response.command-args parsed))))
1842 (define-erc-response-handler (406)
1843 "No such nick." nil
1844 (erc-display-message parsed '(notice error) 'active
1845 's406 ?n (second (erc-response.command-args parsed))))
1847 (define-erc-response-handler (412)
1848 "No text to send." nil
1849 (erc-display-message parsed '(notice error) 'active 's412))
1851 (define-erc-response-handler (421)
1852 "Unknown command." nil
1853 (erc-display-message parsed '(notice error) 'active 's421
1854 ?c (second (erc-response.command-args parsed))))
1856 (define-erc-response-handler (432)
1857 "Bad nick." nil
1858 (erc-display-message parsed '(notice error) 'active 's432
1859 ?n (second (erc-response.command-args parsed))))
1861 (define-erc-response-handler (433)
1862 "Login-time \"nick in use\"." nil
1863 (erc-nickname-in-use (second (erc-response.command-args parsed))
1864 "already in use"))
1866 (define-erc-response-handler (437)
1867 "Nick temporarily unavailable (on IRCnet)." nil
1868 (let ((nick/channel (second (erc-response.command-args parsed))))
1869 (unless (erc-channel-p nick/channel)
1870 (erc-nickname-in-use nick/channel "temporarily unavailable"))))
1872 (define-erc-response-handler (442)
1873 "Not on channel." nil
1874 (erc-display-message parsed '(notice error) 'active 's442
1875 ?c (second (erc-response.command-args parsed))))
1877 (define-erc-response-handler (461)
1878 "Not enough parameters for command." nil
1879 (erc-display-message parsed '(notice error) 'active 's461
1880 ?c (second (erc-response.command-args parsed))
1881 ?m (erc-response.contents parsed)))
1883 (define-erc-response-handler (465)
1884 "You are banned from this server." nil
1885 (setq erc-server-banned t)
1886 ;; show the server's message, as a reason might be provided
1887 (erc-display-error-notice
1888 parsed
1889 (erc-response.contents parsed)))
1891 (define-erc-response-handler (474)
1892 "Banned from channel errors." nil
1893 (erc-display-message parsed '(notice error) nil
1894 (intern (format "s%s"
1895 (erc-response.command parsed)))
1896 ?c (second (erc-response.command-args parsed))))
1898 (define-erc-response-handler (475)
1899 "Channel key needed." nil
1900 (erc-display-message parsed '(notice error) nil 's475
1901 ?c (second (erc-response.command-args parsed)))
1902 (when erc-prompt-for-channel-key
1903 (let ((channel (second (erc-response.command-args parsed)))
1904 (key (read-from-minibuffer
1905 (format "Channel %s is mode +k. Enter key (RET to cancel): "
1906 (second (erc-response.command-args parsed))))))
1907 (when (and key (> (length key) 0))
1908 (erc-cmd-JOIN channel key)))))
1910 (define-erc-response-handler (477)
1911 "Channel doesn't support modes." nil
1912 (let ((channel (second (erc-response.command-args parsed)))
1913 (message (erc-response.contents parsed)))
1914 (erc-display-message parsed 'notice (erc-get-buffer channel proc)
1915 (format "%s: %s" channel message))))
1917 (define-erc-response-handler (482)
1918 "You need to be a channel operator to do that." nil
1919 (let ((channel (second (erc-response.command-args parsed)))
1920 (message (erc-response.contents parsed)))
1921 (erc-display-message parsed '(error notice) 'active 's482
1922 ?c channel ?m message)))
1924 (define-erc-response-handler (431 445 446 451 462 463 464 481 483 484 485
1925 491 501 502)
1926 ;; 431 - No nickname given
1927 ;; 445 - SUMMON has been disabled
1928 ;; 446 - USERS has been disabled
1929 ;; 451 - You have not registered
1930 ;; 462 - Unauthorized command (already registered)
1931 ;; 463 - Your host isn't among the privileged
1932 ;; 464 - Password incorrect
1933 ;; 481 - Need IRCop privileges
1934 ;; 483 - You can't kill a server!
1935 ;; 484 - Your connection is restricted!
1936 ;; 485 - You're not the original channel operator
1937 ;; 491 - No O-lines for your host
1938 ;; 501 - Unknown MODE flag
1939 ;; 502 - Cannot change mode for other users
1940 "Generic display of server error messages.
1942 See `erc-display-error-notice'." nil
1943 (erc-display-error-notice
1944 parsed
1945 (intern (format "s%s" (erc-response.command parsed)))))
1947 ;; FIXME: These are yet to be implemented, they're just stubs for now
1948 ;; -- Lawrence 2004/05/12
1950 ;; response numbers left here for reference
1952 ;; (define-erc-response-handler (323 364 365 381 382 392 393 394 395
1953 ;; 200 201 202 203 204 205 206 208 209 211 212 213
1954 ;; 214 215 216 217 218 219 241 242 243 244 249 261
1955 ;; 262 302 342 351 402 407 409 411 413 414 415
1956 ;; 423 424 436 441 443 444 467 471 472 473 KILL)
1957 ;; nil nil
1958 ;; (ignore proc parsed))
1960 (provide 'erc-backend)
1962 ;;; erc-backend.el ends here
1963 ;; Local Variables:
1964 ;; indent-tabs-mode: nil
1965 ;; End:
1967 ;; arch-tag: a64e6bb7-a780-4efd-8f98-083b18c7c84a