1 | /********************************************************************\ |
---|
2 | * BitlBee -- An IRC to other IM-networks gateway * |
---|
3 | * * |
---|
4 | * Copyright 2002-2010 Wilmer van der Gaast and others * |
---|
5 | \********************************************************************/ |
---|
6 | |
---|
7 | /* The IRC-based UI - Sending responses to commands/etc. */ |
---|
8 | |
---|
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 of the License, or |
---|
13 | (at your option) 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 with |
---|
21 | the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL; |
---|
22 | if not, write to the Free Software Foundation, Inc., 59 Temple Place, |
---|
23 | Suite 330, Boston, MA 02111-1307 USA |
---|
24 | */ |
---|
25 | |
---|
26 | #include "bitlbee.h" |
---|
27 | |
---|
28 | void irc_send_num( irc_t *irc, int code, char *format, ... ) |
---|
29 | { |
---|
30 | char text[IRC_MAX_LINE]; |
---|
31 | va_list params; |
---|
32 | |
---|
33 | va_start( params, format ); |
---|
34 | g_vsnprintf( text, IRC_MAX_LINE, format, params ); |
---|
35 | va_end( params ); |
---|
36 | irc_write( irc, ":%s %03d %s %s", irc->root->host, code, irc->user->nick ? : "*", text ); |
---|
37 | |
---|
38 | return; |
---|
39 | } |
---|
40 | |
---|
41 | void irc_send_login( irc_t *irc ) |
---|
42 | { |
---|
43 | irc_user_t *iu = irc->user; |
---|
44 | |
---|
45 | irc->user = irc_user_new( irc, iu->nick ); |
---|
46 | irc->user->user = iu->user; |
---|
47 | irc->user->fullname = iu->fullname; |
---|
48 | g_free( iu->nick ); |
---|
49 | g_free( iu ); |
---|
50 | |
---|
51 | irc_send_num( irc, 1, ":Welcome to the BitlBee gateway, %s", irc->user->nick ); |
---|
52 | irc_send_num( irc, 2, ":Host %s is running BitlBee " BITLBEE_VERSION " " ARCH "/" CPU ".", irc->root->host ); |
---|
53 | irc_send_num( irc, 3, ":%s", IRCD_INFO ); |
---|
54 | irc_send_num( irc, 4, "%s %s %s %s", irc->root->host, BITLBEE_VERSION, UMODES UMODES_PRIV, CMODES ); |
---|
55 | irc_send_num( irc, 5, "PREFIX=(ov)@+ CHANTYPES=%s CHANMODES=,,,%s NICKLEN=%d NETWORK=BitlBee " |
---|
56 | "CASEMAPPING=rfc1459 MAXTARGETS=1 WATCH=128 :are supported by this server", |
---|
57 | CTYPES, CMODES, MAX_NICK_LENGTH - 1 ); |
---|
58 | irc_send_motd( irc ); |
---|
59 | irc->umode[0] = '\0'; |
---|
60 | /*irc_umode_set( irc, "+" UMODE, 1 );*/ |
---|
61 | |
---|
62 | irc_usermsg( irc, "Welcome to the BitlBee gateway!\n\n" |
---|
63 | "If you've never used BitlBee before, please do read the help " |
---|
64 | "information using the \x02help\x02 command. Lots of FAQs are " |
---|
65 | "answered there.\n" |
---|
66 | "If you already have an account on this server, just use the " |
---|
67 | "\x02identify\x02 command to identify yourself." ); |
---|
68 | |
---|
69 | if( global.conf->runmode == RUNMODE_FORKDAEMON || global.conf->runmode == RUNMODE_DAEMON ) |
---|
70 | ipc_to_master_str( "CLIENT %s %s :%s\r\n", irc->user->host, irc->user->nick, irc->user->fullname ); |
---|
71 | |
---|
72 | irc->status |= USTATUS_LOGGED_IN; |
---|
73 | |
---|
74 | /* This is for bug #209 (use PASS to identify to NickServ). */ |
---|
75 | if( irc->password != NULL ) |
---|
76 | { |
---|
77 | char *send_cmd[] = { "identify", g_strdup( irc->password ), NULL }; |
---|
78 | |
---|
79 | /*irc_setpass( irc, NULL );*/ |
---|
80 | /*root_command( irc, send_cmd );*/ |
---|
81 | g_free( send_cmd[1] ); |
---|
82 | } |
---|
83 | } |
---|
84 | |
---|
85 | void irc_send_motd( irc_t *irc ) |
---|
86 | { |
---|
87 | int fd; |
---|
88 | |
---|
89 | fd = open( global.conf->motdfile, O_RDONLY ); |
---|
90 | if( fd == -1 ) |
---|
91 | { |
---|
92 | irc_send_num( irc, 422, ":We don't need MOTDs." ); |
---|
93 | } |
---|
94 | else |
---|
95 | { |
---|
96 | char linebuf[80]; /* Max. line length for MOTD's is 79 chars. It's what most IRC networks seem to do. */ |
---|
97 | char *add, max; |
---|
98 | int len; |
---|
99 | |
---|
100 | linebuf[79] = len = 0; |
---|
101 | max = sizeof( linebuf ) - 1; |
---|
102 | |
---|
103 | irc_send_num( irc, 375, ":- %s Message Of The Day - ", irc->root->host ); |
---|
104 | while( read( fd, linebuf + len, 1 ) == 1 ) |
---|
105 | { |
---|
106 | if( linebuf[len] == '\n' || len == max ) |
---|
107 | { |
---|
108 | linebuf[len] = 0; |
---|
109 | irc_send_num( irc, 372, ":- %s", linebuf ); |
---|
110 | len = 0; |
---|
111 | } |
---|
112 | else if( linebuf[len] == '%' ) |
---|
113 | { |
---|
114 | read( fd, linebuf + len, 1 ); |
---|
115 | if( linebuf[len] == 'h' ) |
---|
116 | add = irc->root->host; |
---|
117 | else if( linebuf[len] == 'v' ) |
---|
118 | add = BITLBEE_VERSION; |
---|
119 | else if( linebuf[len] == 'n' ) |
---|
120 | add = irc->user->nick; |
---|
121 | else |
---|
122 | add = "%"; |
---|
123 | |
---|
124 | strncpy( linebuf + len, add, max - len ); |
---|
125 | while( linebuf[++len] ); |
---|
126 | } |
---|
127 | else if( len < max ) |
---|
128 | { |
---|
129 | len ++; |
---|
130 | } |
---|
131 | } |
---|
132 | irc_send_num( irc, 376, ":End of MOTD" ); |
---|
133 | close( fd ); |
---|
134 | } |
---|
135 | } |
---|
136 | |
---|
137 | /* FIXME/REPLACEME */ |
---|
138 | int irc_usermsg( irc_t *irc, char *format, ... ) |
---|
139 | { |
---|
140 | char text[1024]; |
---|
141 | va_list params; |
---|
142 | //irc_user_t *iu; |
---|
143 | |
---|
144 | va_start( params, format ); |
---|
145 | g_vsnprintf( text, sizeof( text ), format, params ); |
---|
146 | va_end( params ); |
---|
147 | |
---|
148 | fprintf( stderr, "%s\n", text ); |
---|
149 | |
---|
150 | return 1; |
---|
151 | |
---|
152 | /*return( irc_msgfrom( irc, u->nick, text ) );*/ |
---|
153 | } |
---|