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