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