Fixed.
[riece] / lisp / riece-irc.el
1 ;;; riece-irc.el --- IRC protocol
2 ;; Copyright (C) 1998-2004 Daiki Ueno
3
4 ;; Author: Daiki Ueno <ueno@unixuser.org>
5 ;; Created: 1998-09-28
6 ;; Keywords: IRC, riece
7
8 ;; This file is part of Riece.
9
10 ;; This program is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14
15 ;; This program is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
22 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 ;; Boston, MA 02110-1301, USA.
24
25 ;;; Code:
26
27 (require 'riece-filter)
28 (require 'riece-server)
29 (require 'riece-mcat)
30
31 (defun riece-irc-open-server (server server-name)
32   (riece-server-keyword-bind server
33     (let (selective-display
34           (coding-system-for-read 'binary)
35           (coding-system-for-write 'binary)
36           process)
37       (if (equal server-name "")
38           (message (riece-mcat "Connecting to IRC server..."))
39         (message (riece-mcat "Connecting to %s...") server-name))
40       (condition-case error
41           (setq process
42                 (funcall function (riece-server-process-name server-name)
43                          (concat " *IRC*" server-name)
44                          host service))
45         (error
46          (if (equal server-name "")
47              (message (riece-mcat "Connecting to IRC server...failed: %S")
48                       error)
49            (message (riece-mcat "Connecting to %s...failed: %S") server-name
50                     error))
51          (signal (car error) (cdr error))))
52       (if (equal server-name "")
53           (message (riece-mcat "Connecting to IRC server...done"))
54         (message (riece-mcat "Connecting to %s...done") server-name))
55       (riece-reset-process-buffer process)
56       (with-current-buffer (process-buffer process)
57         (setq riece-server-name server-name))
58       (set-process-sentinel process 'riece-sentinel)
59       (set-process-filter process 'riece-filter)
60       (if (equal server-name "")
61           (message (riece-mcat "Logging in to IRC server..."))
62         (message (riece-mcat "Logging in to %s...") server-name))
63       (if riece-reconnect-with-password ;password incorrect or not set.
64           (unwind-protect
65               (setq password
66                     (condition-case nil
67                         (let (inhibit-quit)
68                           (if (equal server-name "")
69                               (riece-read-passwd (riece-mcat "Password: "))
70                             (riece-read-passwd
71                              (format (riece-mcat "Password for %s: ")
72                                      server-name))))
73                       (quit
74                        (if (equal server-name "")
75                            (message (riece-mcat "Password: Quit"))
76                          (message (riece-mcat "Password for %s: Quit")
77                                   server-name))
78                        'quit)))
79             (setq riece-reconnect-with-password nil)))
80       (if (eq password 'quit)
81           (delete-process process)
82         (if password
83             (riece-process-send-string process
84                                        (format "PASS %s\r\n" password)))
85         (riece-process-send-string process
86                                    (format "USER %s * * :%s\r\n"
87                                            (or username
88                                                (user-real-login-name))
89                                            (or realname
90                                                "No information given")))
91         (riece-process-send-string process (format "NICK %s\r\n" nickname))
92         (with-current-buffer (process-buffer process)
93           (setq riece-last-nickname riece-real-nickname
94                 riece-nick-accepted 'sent
95                 riece-coding-system coding))
96         process))))
97
98 (defun riece-irc-quit-server-process (process &optional message)
99   (if riece-quit-timeout
100       (riece-run-at-time riece-quit-timeout nil
101                          (lambda (process)
102                            (if (rassq process riece-server-process-alist)
103                                (delete-process process)))
104                          process))
105   (let ((server-name (with-current-buffer (process-buffer process)
106                        riece-server-name)))
107     (if (equal server-name "")
108         (message (riece-mcat "Sending QUIT..."))
109       (message (riece-mcat "Sending QUIT to \"%s\"...") server-name))
110     (riece-process-send-string process
111                                (if message
112                                    (format "QUIT :%s\r\n" message)
113                                  "QUIT\r\n"))
114     (if (equal server-name "")
115         (message (riece-mcat "Sending QUIT...done"))
116       (message (riece-mcat "Sending QUIT to \"%s\"...done") server-name))))
117
118 (provide 'riece-irc)
119
120 ;;; riece-irc.el ends here