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