author | Markus Bröker <mbroeker@largo.dyndns.tv> |
Sat, 13 Dec 2008 15:41:35 +0100 | |
changeset 18 | 4435146391ae |
parent 15 | f19c1f9b4cd3 |
child 19 | 66114d944208 |
permissions | -rw-r--r-- |
0 | 1 |
/** |
2 |
* $Id: irc.c 51 2008-01-10 00:19:39Z mbroeker $ |
|
3 |
* $URL: http://localhost/svn/c/mcbot/trunk/src/irc.c $ |
|
4 |
* |
|
5 |
*/ |
|
6 |
||
7 |
#include <stdio.h> |
|
8 |
#include <stdlib.h> |
|
9 |
#include <unistd.h> |
|
10 |
#include <string.h> |
|
11 |
||
12 |
#include <sys/types.h> |
|
13 |
#include <sys/socket.h> |
|
14 |
#include <netinet/in.h> |
|
15 |
#include <arpa/inet.h> |
|
16 |
#include <netdb.h> |
|
17 |
||
18 |
#include <pwd.h> |
|
19 |
||
13
d3554afaa768
mcbot-0.94-5 Changelog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
12
diff
changeset
|
20 |
#include <compat.h> |
0 | 21 |
#include <irc.h> |
22 |
||
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
13
diff
changeset
|
23 |
#define NOTICE 0 |
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
13
diff
changeset
|
24 |
#define MODE 1 |
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
13
diff
changeset
|
25 |
#define JOIN 2 |
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
13
diff
changeset
|
26 |
#define PART 3 |
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
13
diff
changeset
|
27 |
#define TOPIC 4 |
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
13
diff
changeset
|
28 |
#define PING 5 |
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
13
diff
changeset
|
29 |
#define ENOMEM 6 |
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
13
diff
changeset
|
30 |
#define ERROR 7 |
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
13
diff
changeset
|
31 |
#define VERSION 8 |
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
13
diff
changeset
|
32 |
#define PRIVMSG 9 |
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
13
diff
changeset
|
33 |
#define QUIT 10 |
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
13
diff
changeset
|
34 |
#define NICK 11 |
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
13
diff
changeset
|
35 |
|
0 | 36 |
#define VERSION_STRING "MCBOT on GNU/LINUX" |
37 |
||
38 |
const char *IRC_Commands[] = { |
|
39 |
"NOTICE", "MODE", "JOIN", "PART", |
|
40 |
"TOPIC", "PING", "ENOMEM", "ERROR", |
|
41 |
"VERSION", "PRIVMSG", "QUIT", "NICK", |
|
11
a769385a59c6
Many Memory Leaks in config.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
10
diff
changeset
|
42 |
NULL |
0 | 43 |
}; |
44 |
||
45 |
FILE *irc_connect (char *server, unsigned int port) |
|
46 |
{ |
|
47 |
struct hostent *he; |
|
48 |
char *ip; |
|
49 |
struct sockaddr_in ca; |
|
50 |
int csocket; |
|
10
311ea5fa60dd
Code cleanups and debian changelogs
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
51 |
FILE *stream; |
0 | 52 |
|
53 |
he = gethostbyname (server); |
|
54 |
if (he == NULL) { |
|
55 |
perror ("GETHOSTBYNAME"); |
|
56 |
return NULL; |
|
57 |
} |
|
58 |
||
59 |
if ((ip = inet_ntoa (*((struct in_addr *)he->h_addr_list[0]))) == NULL) { |
|
10
311ea5fa60dd
Code cleanups and debian changelogs
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
60 |
perror ("INET_NTOA"); |
0 | 61 |
return NULL; |
62 |
} else |
|
63 |
printf ("IP: %s\n", ip); |
|
64 |
||
65 |
ca.sin_family = AF_INET; |
|
66 |
ca.sin_addr.s_addr = inet_addr (ip); |
|
67 |
ca.sin_port = htons (port); |
|
68 |
||
69 |
csocket = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP); |
|
70 |
if (connect (csocket, (struct sockaddr *)&ca, (socklen_t) sizeof (ca)) == -1) { |
|
71 |
perror ("CONNECT"); |
|
72 |
return NULL; |
|
73 |
} |
|
74 |
||
75 |
/* |
|
76 |
* rw mode,but many seek errors ... |
|
77 |
*/ |
|
5
7c7fc8906920
FreeBSD Stream Handling added and debian control files improved
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
2
diff
changeset
|
78 |
#ifdef NETBSD |
6
7eb12be31bb5
Various Bug Fixes including
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
5
diff
changeset
|
79 |
/* |
7eb12be31bb5
Various Bug Fixes including
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
5
diff
changeset
|
80 |
* BEGIN OF STREAM |
7eb12be31bb5
Various Bug Fixes including
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
5
diff
changeset
|
81 |
*/ |
5
7c7fc8906920
FreeBSD Stream Handling added and debian control files improved
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
2
diff
changeset
|
82 |
stream = fdopen (csocket, "r+"); |
7c7fc8906920
FreeBSD Stream Handling added and debian control files improved
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
2
diff
changeset
|
83 |
#else |
6
7eb12be31bb5
Various Bug Fixes including
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
5
diff
changeset
|
84 |
/* |
7eb12be31bb5
Various Bug Fixes including
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
5
diff
changeset
|
85 |
* END OF STREAM |
7eb12be31bb5
Various Bug Fixes including
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
5
diff
changeset
|
86 |
*/ |
0 | 87 |
stream = fdopen (csocket, "a+"); |
5
7c7fc8906920
FreeBSD Stream Handling added and debian control files improved
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
2
diff
changeset
|
88 |
#endif |
6
7eb12be31bb5
Various Bug Fixes including
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
5
diff
changeset
|
89 |
csocket = fileno (stream); |
5
7c7fc8906920
FreeBSD Stream Handling added and debian control files improved
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
2
diff
changeset
|
90 |
|
7c7fc8906920
FreeBSD Stream Handling added and debian control files improved
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
2
diff
changeset
|
91 |
printf ("Using filedescriptor %d for stream operations\n", csocket); |
0 | 92 |
return stream; |
93 |
} |
|
94 |
||
6
7eb12be31bb5
Various Bug Fixes including
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
5
diff
changeset
|
95 |
int irc_login (FILE * stream, char *server, char *nick, char *password) |
0 | 96 |
{ |
10
311ea5fa60dd
Code cleanups and debian changelogs
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
97 |
MSG message = { NULL, 0, 0, 0, 0, 0, 0 }; |
0 | 98 |
char msg[513]; |
99 |
char *user; |
|
10
311ea5fa60dd
Code cleanups and debian changelogs
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
100 |
struct passwd *pwd; |
0 | 101 |
|
10
311ea5fa60dd
Code cleanups and debian changelogs
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
102 |
if ((user = getenv ("USER")) == NULL) |
311ea5fa60dd
Code cleanups and debian changelogs
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
103 |
return IRC_GENERAL_ERROR; |
311ea5fa60dd
Code cleanups and debian changelogs
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
104 |
|
311ea5fa60dd
Code cleanups and debian changelogs
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
105 |
if ((pwd = getpwnam (user)) == NULL) |
311ea5fa60dd
Code cleanups and debian changelogs
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
106 |
return IRC_GENERAL_ERROR; |
0 | 107 |
|
108 |
if (stream == NULL) |
|
109 |
return IRC_GENERAL_ERROR; |
|
10
311ea5fa60dd
Code cleanups and debian changelogs
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
110 |
else |
311ea5fa60dd
Code cleanups and debian changelogs
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
111 |
message.stream = stream; |
0 | 112 |
|
113 |
fprintf (stream, "NICK %s\r\n", nick); |
|
6
7eb12be31bb5
Various Bug Fixes including
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
5
diff
changeset
|
114 |
fprintf (stream, "USER %s 0 %s %s\r\n", user, server, pwd->pw_gecos); |
18
4435146391ae
LOGIN without Password added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
15
diff
changeset
|
115 |
|
4435146391ae
LOGIN without Password added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
15
diff
changeset
|
116 |
if (password != NULL) |
4435146391ae
LOGIN without Password added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
15
diff
changeset
|
117 |
fprintf (stream, "PRIVMSG NICKSERV :IDENTIFY %s\r\n", password); |
0 | 118 |
|
119 |
for (;;) { |
|
11
a769385a59c6
Many Memory Leaks in config.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
10
diff
changeset
|
120 |
*msg = '\0'; |
0 | 121 |
fgets (msg, 512, stream); |
122 |
if ((user = irc_parsemessage (msg, &message)) != NULL) |
|
123 |
printf ("%10s %s\n", user, message.line); |
|
124 |
||
125 |
if (strstr (msg, "VERSION") != NULL) { |
|
126 |
printf ("%10s %s", "VERSION", msg); |
|
127 |
printf ("%10s %s %s :%s\n", "WRITE", message.command, message.user, VERSION_STRING); |
|
128 |
fprintf (stream, "VERSION :%s\r\n", VERSION_STRING); |
|
129 |
} |
|
130 |
||
131 |
if (strstr (msg, ":Password accepted") != NULL) { |
|
132 |
break; |
|
133 |
} |
|
134 |
||
1
5d249c79842d
quick and dirty freenode connect fix
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
135 |
if (strstr (msg, ":You are now logged in.") != NULL) { |
5d249c79842d
quick and dirty freenode connect fix
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
136 |
break; |
5d249c79842d
quick and dirty freenode connect fix
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
137 |
} |
5d249c79842d
quick and dirty freenode connect fix
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
138 |
|
0 | 139 |
if (strstr (msg, ":Password Incorrect") != NULL) { |
140 |
return IRC_LOGIN_ERROR; |
|
141 |
} |
|
142 |
||
143 |
if (strstr (msg, "ERROR :Closing Link") != NULL) { |
|
144 |
return IRC_GENERAL_ERROR; |
|
145 |
} |
|
146 |
||
147 |
if (strstr (msg, "is not registered") != NULL) { |
|
148 |
return IRC_LOGIN_ERROR; |
|
149 |
} |
|
18
4435146391ae
LOGIN without Password added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
15
diff
changeset
|
150 |
if (strstr (msg, ":Nickname is already in use") != NULL) { |
4435146391ae
LOGIN without Password added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
15
diff
changeset
|
151 |
return IRC_LOGIN_ERROR; |
4435146391ae
LOGIN without Password added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
15
diff
changeset
|
152 |
} |
4435146391ae
LOGIN without Password added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
15
diff
changeset
|
153 |
|
4435146391ae
LOGIN without Password added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
15
diff
changeset
|
154 |
if (password == NULL) |
4435146391ae
LOGIN without Password added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
15
diff
changeset
|
155 |
break; |
0 | 156 |
} |
157 |
||
158 |
sleep (2); |
|
159 |
return 0; |
|
160 |
} |
|
161 |
||
162 |
static char *irc_getmessage (const char *line, MSG * message) |
|
163 |
{ |
|
12
213c3d4abc66
A simple garbage collector fills the memory leaks...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
11
diff
changeset
|
164 |
static char *garbage_collector = NULL; |
0 | 165 |
char *theLine; |
166 |
char *token; |
|
167 |
char *ptr; |
|
168 |
||
13
d3554afaa768
mcbot-0.94-5 Changelog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
12
diff
changeset
|
169 |
if (garbage_collector != NULL) { |
12
213c3d4abc66
A simple garbage collector fills the memory leaks...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
11
diff
changeset
|
170 |
free (garbage_collector); |
13
d3554afaa768
mcbot-0.94-5 Changelog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
12
diff
changeset
|
171 |
garbage_collector = NULL; |
d3554afaa768
mcbot-0.94-5 Changelog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
12
diff
changeset
|
172 |
} |
12
213c3d4abc66
A simple garbage collector fills the memory leaks...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
11
diff
changeset
|
173 |
|
13
d3554afaa768
mcbot-0.94-5 Changelog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
12
diff
changeset
|
174 |
if ((theLine = compat_strdup (line)) == NULL) |
0 | 175 |
return "ENOMEM"; |
12
213c3d4abc66
A simple garbage collector fills the memory leaks...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
11
diff
changeset
|
176 |
else |
213c3d4abc66
A simple garbage collector fills the memory leaks...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
11
diff
changeset
|
177 |
garbage_collector = theLine; |
0 | 178 |
|
179 |
message->user = message->email = NULL; |
|
180 |
message->command = NULL; |
|
181 |
message->channel = message->line = NULL; |
|
182 |
||
183 |
token = strtok (theLine, " "); |
|
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
13
diff
changeset
|
184 |
if (*token != ':') { /* SERVER MESSAGES */ |
0 | 185 |
if ((ptr = strtok (NULL, "\r\n")) != NULL) |
186 |
++ptr; |
|
187 |
message->line = ptr; |
|
188 |
return token; |
|
189 |
} |
|
190 |
||
191 |
message->user = ++token; |
|
192 |
message->command = strtok (NULL, " "); |
|
193 |
message->line = strtok (NULL, "\r\n"); |
|
194 |
||
195 |
return message->command; |
|
196 |
} |
|
197 |
||
9
aff6726b8b87
Private Messages will be send to the proper location
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
6
diff
changeset
|
198 |
/** |
0 | 199 |
* Main prints ("%10s %s %s\n", MSG->command MSG->channel MSG->line). |
200 |
* This functions makes sure, that there will be someting to print... |
|
201 |
*/ |
|
202 |
char *irc_parsemessage (const char *line, MSG * message) |
|
203 |
{ |
|
204 |
int i; |
|
205 |
char *command; |
|
206 |
char *ptr; |
|
207 |
int value; |
|
208 |
||
209 |
i = 0; |
|
210 |
if ((command = irc_getmessage (line, message)) != NULL) { |
|
211 |
while (IRC_Commands[i] != NULL) { |
|
212 |
if (strcmp (IRC_Commands[i], command) == 0) { |
|
213 |
switch (i) { |
|
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
13
diff
changeset
|
214 |
case NOTICE: |
0 | 215 |
if (message->line == NULL) { |
216 |
message->channel = "*"; |
|
217 |
message->line = "*"; |
|
218 |
} else { |
|
219 |
message->channel = strtok (message->line, " "); |
|
220 |
if ((message->line = strtok (NULL, "\r\n")) != NULL) |
|
221 |
++message->line; |
|
222 |
} |
|
223 |
return command; |
|
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
13
diff
changeset
|
224 |
case MODE: |
0 | 225 |
message->channel = strtok (message->line, " "); |
226 |
message->line = strtok (NULL, "\r\n"); |
|
227 |
return command; |
|
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
13
diff
changeset
|
228 |
case JOIN: |
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
13
diff
changeset
|
229 |
case PART: |
0 | 230 |
if ((message->channel = strchr (message->line, ':'))) |
231 |
++message->channel; |
|
232 |
message->line = message->user; |
|
233 |
return command; |
|
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
13
diff
changeset
|
234 |
case TOPIC: |
0 | 235 |
message->channel = strtok (message->line, " "); |
236 |
if ((message->line = strtok (NULL, "\r\n"))) |
|
237 |
++message->line; |
|
238 |
return command; |
|
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
13
diff
changeset
|
239 |
case PING: |
0 | 240 |
#ifdef DEBUG |
9
aff6726b8b87
Private Messages will be send to the proper location
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
6
diff
changeset
|
241 |
/* |
aff6726b8b87
Private Messages will be send to the proper location
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
6
diff
changeset
|
242 |
* DONT NERVE WITH PING PONG MESSAGES |
aff6726b8b87
Private Messages will be send to the proper location
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
6
diff
changeset
|
243 |
*/ |
0 | 244 |
printf ("%10s %s localhost\n", "PING", message->line); |
245 |
#endif |
|
246 |
fprintf (message->stream, "PONG :%s\r\n", message->line); |
|
247 |
message->channel = "localhost"; |
|
248 |
#ifdef DEBUG |
|
249 |
return "PONG"; |
|
250 |
#else |
|
251 |
return NULL; |
|
252 |
#endif |
|
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
13
diff
changeset
|
253 |
case ENOMEM: |
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
13
diff
changeset
|
254 |
case ERROR: |
9
aff6726b8b87
Private Messages will be send to the proper location
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
6
diff
changeset
|
255 |
return command; |
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
13
diff
changeset
|
256 |
case VERSION: |
0 | 257 |
if ((ptr = strchr (message->user, ' '))) |
11
a769385a59c6
Many Memory Leaks in config.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
10
diff
changeset
|
258 |
*ptr = '\0'; |
0 | 259 |
return command; |
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
13
diff
changeset
|
260 |
case PRIVMSG: |
0 | 261 |
if ((message->email = strchr (message->user, '='))) |
262 |
++message->email; |
|
263 |
if ((ptr = strchr (message->user, '!'))) |
|
11
a769385a59c6
Many Memory Leaks in config.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
10
diff
changeset
|
264 |
*ptr = '\0'; |
0 | 265 |
|
266 |
message->channel = strtok (message->line, " "); |
|
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
13
diff
changeset
|
267 |
strncpy (message->current_channel, message->channel, 40); |
0 | 268 |
message->line = strtok (NULL, "\r\n"); |
269 |
message->line++; |
|
270 |
printf ("%10s %s %s :%s\n", "READ", message->command, message->channel, message->line); |
|
271 |
return NULL; |
|
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
13
diff
changeset
|
272 |
case QUIT: |
0 | 273 |
message->channel = message->user; |
274 |
return command; |
|
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
13
diff
changeset
|
275 |
case NICK: |
0 | 276 |
message->channel = message->user; |
277 |
return command; |
|
278 |
} |
|
279 |
} |
|
280 |
i++; |
|
281 |
} |
|
282 |
||
283 |
if ((value = atoi (command)) != 0) { |
|
284 |
switch (value) { |
|
285 |
case 1: /* CONNECTION INFOS */ |
|
286 |
case 2: |
|
287 |
case 3: |
|
288 |
case 4: |
|
289 |
case 5: |
|
290 |
case 250: |
|
291 |
case 251: |
|
292 |
case 252: |
|
293 |
case 254: |
|
294 |
case 255: |
|
295 |
case 265: |
|
296 |
case 266: |
|
297 |
/* |
|
298 |
* prints as is in irc_login |
|
299 |
*/ |
|
300 |
return command; |
|
301 |
case 311: |
|
302 |
case 312: |
|
303 |
case 315: /* END OF WHO */ |
|
304 |
case 318: |
|
305 |
message->channel = strtok (message->line, " "); |
|
306 |
message->line = strtok (NULL, "\r\n"); |
|
307 |
return command; |
|
308 |
case 319: |
|
309 |
message->channel = strtok (message->line, " "); |
|
310 |
message->line = strtok (NULL, "\r\n"); |
|
9
aff6726b8b87
Private Messages will be send to the proper location
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
6
diff
changeset
|
311 |
fprintf (message->stream, "PRIVMSG %s :%s\r\n", message->current_channel, message->line); |
0 | 312 |
return command; |
313 |
case 320: |
|
10
311ea5fa60dd
Code cleanups and debian changelogs
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
314 |
case 328: /* INFORMATION */ |
0 | 315 |
case 332: /* TOPIC OF CHANNEL */ |
316 |
case 333: /* NAMES IN CHANNEL */ |
|
317 |
case 351: /* SVERSION */ |
|
318 |
case 352: /* WHO LIST */ |
|
319 |
case 353: |
|
320 |
case 365: |
|
321 |
case 366: /* END OF NAMES */ |
|
322 |
message->channel = strtok (message->line, " "); |
|
323 |
message->line = strtok (NULL, "\r\n"); |
|
324 |
return command; |
|
325 |
case 372: /* MOTD MESSAGES */ |
|
326 |
case 375: |
|
327 |
case 376: /* END OF MOTD */ |
|
328 |
return command; |
|
329 |
case 401: /* NO SUCH NICK/CHANNEL */ |
|
10
311ea5fa60dd
Code cleanups and debian changelogs
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
330 |
case 403: /* THAT CHANNEL DOESN'T EXIST */ |
13
d3554afaa768
mcbot-0.94-5 Changelog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
12
diff
changeset
|
331 |
case 412: /* NO TEXT TO SEND */ |
10
311ea5fa60dd
Code cleanups and debian changelogs
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
332 |
case 441: /* THEY AREN'T ON THIS CHANNEL */ |
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
13
diff
changeset
|
333 |
message->channel = strtok (message->line, " "); |
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
13
diff
changeset
|
334 |
message->line = strtok (NULL, "\r\n"); |
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
13
diff
changeset
|
335 |
fprintf (message->stream, "PRIVMSG %s :%s\r\n", message->current_channel, message->line); |
0 | 336 |
return command; |
18
4435146391ae
LOGIN without Password added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
15
diff
changeset
|
337 |
case 433: /* NICK ALREADY IN USE */ |
4435146391ae
LOGIN without Password added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
15
diff
changeset
|
338 |
case 451: /* REGISTER FIRST */ |
4435146391ae
LOGIN without Password added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
15
diff
changeset
|
339 |
return command; |
0 | 340 |
case 474: |
341 |
case 475: |
|
342 |
case 476: |
|
343 |
case 477: |
|
9
aff6726b8b87
Private Messages will be send to the proper location
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
6
diff
changeset
|
344 |
case 482: |
2
6a2e88214b80
freenode fix indented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
1
diff
changeset
|
345 |
case 901: /* notify or some crap */ |
6a2e88214b80
freenode fix indented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
1
diff
changeset
|
346 |
message->channel = strtok (message->line, " "); |
6a2e88214b80
freenode fix indented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
1
diff
changeset
|
347 |
message->line = strtok (NULL, "\r\n"); |
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
13
diff
changeset
|
348 |
fprintf (message->stream, "PRIVMSG %s :%s\r\n", message->current_channel, message->line); |
2
6a2e88214b80
freenode fix indented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
1
diff
changeset
|
349 |
return command; |
0 | 350 |
default: |
351 |
printf ("DEBUG %s", line); |
|
9
aff6726b8b87
Private Messages will be send to the proper location
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
6
diff
changeset
|
352 |
printf ("Unknown Command Value: %d\n", value); |
0 | 353 |
} |
354 |
} |
|
355 |
printf ("DEBUG %s", line); |
|
356 |
printf ("Unknown Command: %s\n", command); |
|
357 |
return command; |
|
358 |
} |
|
9
aff6726b8b87
Private Messages will be send to the proper location
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
6
diff
changeset
|
359 |
printf ("NOT PARSEABLE %s", line); |
0 | 360 |
return NULL; |
361 |
} |