author | Markus Bröker <mbroeker@largo.dyndns.tv> |
Sat, 13 Dec 2008 15:41:35 +0100 | |
changeset 18 | 4435146391ae |
parent 16 | 33245bf7873a |
child 19 | 66114d944208 |
permissions | -rw-r--r-- |
0 | 1 |
/** |
2 |
* $Id: parse.c 153 2008-04-27 07:26:15Z mbroeker $ |
|
3 |
* $URL: http://localhost/svn/c/mcbot/trunk/src/parse.c $ |
|
4 |
* |
|
5 |
*/ |
|
6 |
||
7 |
#include <stdio.h> |
|
8 |
#include <stdlib.h> |
|
9 |
#include <string.h> |
|
10 |
#include <time.h> |
|
11 |
||
12 |
#include <mcbot.h> |
|
13 |
#include <database.h> |
|
14 |
||
15 |
#include <locale.h> |
|
16 |
#include <libintl.h> |
|
17 |
||
18 |
#ifndef DATABASE_FILE |
|
19 |
#define DATABASE_FILE "/var/lib/nobody/data/mcbot.dat" |
|
20 |
#endif |
|
21 |
||
14
fe8adc56b109
mcbot shows the proper git location for the source...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
13
diff
changeset
|
22 |
#ifndef SOURCE_URL |
fe8adc56b109
mcbot shows the proper git location for the source...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
13
diff
changeset
|
23 |
#define SOURCE_URL "http://largo.homelinux.org/cgi-bin/gitweb.cgi?p=net/mcbot.git" |
fe8adc56b109
mcbot shows the proper git location for the source...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
13
diff
changeset
|
24 |
#endif |
fe8adc56b109
mcbot shows the proper git location for the source...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
13
diff
changeset
|
25 |
|
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
26 |
#define HELP 0 |
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
27 |
#define JOIN 1 |
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
28 |
#define LEAVE 2 |
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
29 |
#define ADD 3 |
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
30 |
#define REPLACE 4 |
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
31 |
#define DELETE 5 |
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
32 |
#define LIST 6 |
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
33 |
#define SEARCH 7 |
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
34 |
#define INFO 8 |
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
35 |
#define PING 9 |
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
36 |
#define ON 10 |
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
37 |
#define OFF 11 |
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
38 |
#define DEBUG 12 |
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
39 |
#define VACCUUM 13 |
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
40 |
#define LOGOUT 14 |
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
41 |
#define WHO 15 |
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
42 |
#define WHOIS 16 |
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
43 |
#define TIME 17 |
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
44 |
#define TELL 18 |
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
45 |
#define OP 19 |
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
46 |
|
0 | 47 |
const |
48 |
char *COMMAND_LIST[] = { |
|
18
4435146391ae
LOGIN without Password added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
16
diff
changeset
|
49 |
"help Known Commands: join(1), leave(2), add(3), replace(4), delete(5), list(6), search(7), info(8)\r\n", |
4435146391ae
LOGIN without Password added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
16
diff
changeset
|
50 |
"join: Joins a new channel\r\n", |
4435146391ae
LOGIN without Password added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
16
diff
changeset
|
51 |
"leave: Parts from the current channel\r\n", |
4435146391ae
LOGIN without Password added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
16
diff
changeset
|
52 |
"add: adds an entry\r\n", |
4435146391ae
LOGIN without Password added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
16
diff
changeset
|
53 |
"replace: replaces an entry\r\n", |
4435146391ae
LOGIN without Password added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
16
diff
changeset
|
54 |
"delete: deletes an entry\r\n", |
4435146391ae
LOGIN without Password added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
16
diff
changeset
|
55 |
"list: lists the number of stored values\r\n", |
4435146391ae
LOGIN without Password added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
16
diff
changeset
|
56 |
"search: searches an entry up\r\n", |
4435146391ae
LOGIN without Password added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
16
diff
changeset
|
57 |
"info: Prints the current Bot-Version\r\n", |
4435146391ae
LOGIN without Password added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
16
diff
changeset
|
58 |
"ping: pings an host\r\n", |
4435146391ae
LOGIN without Password added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
16
diff
changeset
|
59 |
"on: enables autolearning mode\r\n", |
4435146391ae
LOGIN without Password added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
16
diff
changeset
|
60 |
"off: disables autolearning\r\n", |
4435146391ae
LOGIN without Password added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
16
diff
changeset
|
61 |
"debug: prints some debug infos\r\n", |
4435146391ae
LOGIN without Password added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
16
diff
changeset
|
62 |
"vaccuum: reorganizes the database\r\n", |
4435146391ae
LOGIN without Password added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
16
diff
changeset
|
63 |
"logout: Protected logout function\r\n", |
16
33245bf7873a
The active = 0|1 thingy is essential for a networking application -> re-activated
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
15
diff
changeset
|
64 |
NULL, |
0 | 65 |
}; |
66 |
||
67 |
const |
|
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
68 |
char VISIBLE_ITEMS = 14; |
0 | 69 |
|
70 |
const |
|
71 |
char *Bot_Commands[] = { |
|
72 |
"!help", "!join", "!leave", |
|
73 |
"!add", "!replace", "!delete", |
|
74 |
"!list", "!search", "!info", |
|
75 |
"!ping", "!on", "!off", |
|
76 |
"!debug", "!vaccuum", "!logout", |
|
77 |
"!who", "!whois", "!time", "!tell", |
|
11
a769385a59c6
Many Memory Leaks in config.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
10
diff
changeset
|
78 |
"!op", NULL |
0 | 79 |
}; |
80 |
||
8
3152de03758e
A critical change was introduced here...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
3
diff
changeset
|
81 |
char *parse (MSG * message) |
0 | 82 |
{ |
83 |
static char msg[513]; |
|
84 |
int cmd = -1; |
|
85 |
int i; |
|
86 |
char *token; |
|
87 |
char *parameters; |
|
88 |
||
89 |
time_t t; |
|
90 |
struct tm *timeptr; |
|
91 |
static int counter = 0; |
|
92 |
||
93 |
/* |
|
94 |
* default message |
|
95 |
*/ |
|
96 |
snprintf (msg, 512, "PRIVMSG %s :%s.\r\n", message->channel, gettext ("Request cannot be performed")); |
|
97 |
||
98 |
/* |
|
99 |
* PRIVATE MESSAGES |
|
100 |
*/ |
|
101 |
if (!strcmp (message->channel, message->nick)) |
|
102 |
message->channel = message->user; |
|
103 |
||
104 |
if (strstr (message->line, message->nick)) { |
|
105 |
if (*message->line != '!') { |
|
106 |
/* |
|
107 |
* DEAD - LOCK - CHECK |
|
108 |
*/ |
|
109 |
if (strcmp (message->user, message->nick)) { |
|
110 |
snprintf (msg, 512, "PRIVMSG %s :%s, %s?\r\n", message->channel, gettext ("What's up"), message->user); |
|
111 |
if (counter++ > 3) |
|
112 |
return NULL; |
|
113 |
return msg; |
|
114 |
} |
|
115 |
/* |
|
116 |
* DEAD - LOCK - CHECK ENDS |
|
117 |
*/ |
|
118 |
} |
|
119 |
return NULL; |
|
120 |
} |
|
121 |
||
122 |
counter = 0; |
|
123 |
||
124 |
/* |
|
125 |
* NO BOT Commands |
|
126 |
*/ |
|
127 |
if (*message->line != '!') { |
|
128 |
return NULL; |
|
129 |
} |
|
130 |
||
131 |
i = 0; |
|
132 |
token = strtok (message->line, " "); |
|
133 |
while (Bot_Commands[i]) { |
|
134 |
if (!strcmp (token, Bot_Commands[i])) { |
|
135 |
switch (i) { |
|
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
136 |
case HELP: |
0 | 137 |
if ((token = strtok (NULL, "\r\n"))) |
138 |
cmd = atoi (token); |
|
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
139 |
if ((cmd > 0) && (cmd < VISIBLE_ITEMS)) |
0 | 140 |
snprintf (msg, 512, "PRIVMSG %s :%s\r\n", message->channel, COMMAND_LIST[cmd]); |
141 |
else |
|
142 |
snprintf (msg, 512, "PRIVMSG %s :%s\r\n", message->channel, COMMAND_LIST[0]); |
|
143 |
return msg; |
|
144 |
||
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
145 |
case JOIN: |
0 | 146 |
if ((token = strtok (NULL, "\r\n"))) |
147 |
snprintf (msg, 512, "JOIN %s\r\n", token); |
|
148 |
return msg; |
|
149 |
||
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
150 |
case LEAVE: |
0 | 151 |
if (*message->channel != '#') |
152 |
return NULL; |
|
153 |
snprintf (msg, 512, "PART %s :Leaving.\r\n", message->channel); |
|
154 |
return msg; |
|
155 |
||
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
156 |
case ADD: |
0 | 157 |
if ((token = strtok (NULL, " "))) { |
158 |
if ((parameters = strtok (NULL, "\r\n"))) { |
|
159 |
snprintf (msg, 512, "PRIVMSG %s :%s, %s\r\n", |
|
160 |
message->channel, message->user, db_insert (DATABASE_FILE, token, parameters, 0)); |
|
161 |
} else { |
|
3
a82a978f23f7
unreachable code removed and gitignore added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
162 |
snprintf (msg, 512, "PRIVMSG %s :%s, %s!\r\n", message->channel, |
a82a978f23f7
unreachable code removed and gitignore added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
163 |
gettext ("I need more parameters to add"), message->user); |
0 | 164 |
} |
165 |
} |
|
166 |
return msg; |
|
167 |
||
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
168 |
case REPLACE: |
0 | 169 |
if ((token = strtok (NULL, " "))) { |
170 |
if ((parameters = strtok (NULL, "\r\n"))) { |
|
171 |
snprintf (msg, 512, "PRIVMSG %s :%s, %s\r\n", |
|
172 |
message->channel, message->user, db_insert (DATABASE_FILE, token, parameters, 1)); |
|
173 |
} else { |
|
3
a82a978f23f7
unreachable code removed and gitignore added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
174 |
snprintf (msg, 512, "PRIVMSG %s :%s, %s!\r\n", message->channel, |
a82a978f23f7
unreachable code removed and gitignore added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
175 |
gettext ("I need more parameters to replace"), message->user); |
0 | 176 |
} |
177 |
} |
|
178 |
return msg; |
|
179 |
||
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
180 |
case DELETE: |
0 | 181 |
if ((token = strtok (NULL, "\r\n"))) { |
182 |
snprintf (msg, 512, "PRIVMSG %s :%s, %s\r\n", |
|
183 |
message->channel, message->user, db_remove (DATABASE_FILE, token)); |
|
184 |
} else { |
|
3
a82a978f23f7
unreachable code removed and gitignore added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
185 |
snprintf (msg, 512, "PRIVMSG %s :%s, %s!\r\n", message->channel, gettext ("I need a key to delete"), |
a82a978f23f7
unreachable code removed and gitignore added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
186 |
message->user); |
0 | 187 |
} |
188 |
return msg; |
|
189 |
||
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
190 |
case LIST: |
3
a82a978f23f7
unreachable code removed and gitignore added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
191 |
snprintf (msg, 512, "PRIVMSG %s :%s %s\r\n", message->channel, db_elements (DATABASE_FILE), |
a82a978f23f7
unreachable code removed and gitignore added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
192 |
db_lookup (DATABASE_FILE, "mcbot.cgi")); |
0 | 193 |
return msg; |
194 |
||
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
195 |
case SEARCH: |
0 | 196 |
if ((token = strtok (NULL, "\r\n"))) { |
3
a82a978f23f7
unreachable code removed and gitignore added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
197 |
snprintf (msg, 512, "PRIVMSG %s :%s, %s\r\n", message->channel, message->user, |
a82a978f23f7
unreachable code removed and gitignore added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
198 |
db_lookup (DATABASE_FILE, token)); |
0 | 199 |
} else { |
200 |
snprintf (msg, 512, |
|
3
a82a978f23f7
unreachable code removed and gitignore added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
201 |
"PRIVMSG %s :%s, %s!\r\n", message->channel, gettext ("I need a key to lookup"), |
a82a978f23f7
unreachable code removed and gitignore added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
202 |
message->user); |
0 | 203 |
} |
204 |
return msg; |
|
205 |
||
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
206 |
case INFO: |
3
a82a978f23f7
unreachable code removed and gitignore added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
207 |
snprintf (msg, 512, "PRIVMSG %s :I am MCBot-%1.2f and my source code can be found on %s\r\n", |
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
208 |
message->channel, BOT_VERSION, SOURCE_URL); |
0 | 209 |
return msg; |
210 |
||
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
211 |
case PING: |
0 | 212 |
if ((token = strtok (NULL, "\r\n"))) |
213 |
snprintf (msg, 512, "PRIVMSG %s :PING 0815\r\n", token); |
|
214 |
return msg; |
|
215 |
||
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
216 |
case ON: |
3
a82a978f23f7
unreachable code removed and gitignore added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
217 |
snprintf (msg, 512, "PRIVMSG %s :%s %s.\r\n", message->user, gettext ("Autolearn enabled for channel"), |
a82a978f23f7
unreachable code removed and gitignore added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
218 |
message->channel); |
0 | 219 |
return msg; |
220 |
||
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
221 |
case OFF: |
3
a82a978f23f7
unreachable code removed and gitignore added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
222 |
snprintf (msg, 512, "PRIVMSG %s :%s %s.\r\n", message->user, gettext ("Autolearn disabled for channel"), |
a82a978f23f7
unreachable code removed and gitignore added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
223 |
message->channel); |
0 | 224 |
return msg; |
225 |
||
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
226 |
case DEBUG: |
3
a82a978f23f7
unreachable code removed and gitignore added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
227 |
snprintf (msg, 512, "PRIVMSG %s :USER: %s EMAIL: %s CHANNEL: %s LINE: %s\r\n", message->channel, |
a82a978f23f7
unreachable code removed and gitignore added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
228 |
message->user, message->email, message->channel, message->line); |
0 | 229 |
return msg; |
230 |
||
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
231 |
case VACCUUM: |
0 | 232 |
snprintf (msg, 512, "PRIVMSG %s :%s\r\n", message->channel, db_vaccuum (DATABASE_FILE)); |
233 |
return msg; |
|
234 |
||
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
235 |
case LOGOUT: |
3
a82a978f23f7
unreachable code removed and gitignore added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
236 |
if (strstr (message->user, db_lookup (DATABASE_FILE, "mcbot.user"))) { |
a82a978f23f7
unreachable code removed and gitignore added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
237 |
if (strstr (message->email, db_lookup (DATABASE_FILE, "mcbot.email"))) { |
a82a978f23f7
unreachable code removed and gitignore added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
238 |
snprintf (msg, 512, "PRIVMSG %s :%s!\r\nQUIT\r\n", message->channel, |
a82a978f23f7
unreachable code removed and gitignore added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
239 |
gettext ("Bye, have a nice day!")); |
0 | 240 |
} |
241 |
} |
|
242 |
/* |
|
243 |
* the returned message is either the default one or the generated one |
|
244 |
*/ |
|
245 |
return msg; |
|
246 |
||
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
247 |
case WHO: |
0 | 248 |
if ((token = strtok (NULL, "\r\n")) != NULL) { |
249 |
snprintf (msg, 512, "WHO %s\r\n", token); |
|
250 |
} |
|
251 |
return msg; |
|
252 |
||
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
253 |
case WHOIS: |
0 | 254 |
if ((token = strtok (NULL, "\r\n")) != NULL) { |
255 |
snprintf (msg, 512, "WHOIS %s\r\n", token); |
|
256 |
} |
|
257 |
return msg; |
|
3
a82a978f23f7
unreachable code removed and gitignore added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
258 |
|
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
259 |
case TIME: |
0 | 260 |
t = time (NULL); |
261 |
timeptr = localtime (&t); |
|
262 |
if ((token = malloc (81))) { |
|
263 |
strftime (token, 80, "%I:%M:%S %p", timeptr); |
|
3
a82a978f23f7
unreachable code removed and gitignore added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
264 |
snprintf (msg, 512, "PRIVMSG %s :%s %s, %s!\r\n", message->channel, gettext ("It is"), token, |
a82a978f23f7
unreachable code removed and gitignore added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
265 |
message->user); |
0 | 266 |
free (token); |
267 |
} |
|
268 |
return msg; |
|
3
a82a978f23f7
unreachable code removed and gitignore added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
269 |
|
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
270 |
case TELL: |
0 | 271 |
if ((token = strtok (NULL, " "))) { |
272 |
if ((parameters = strtok (NULL, "\r\n"))) { |
|
13
d3554afaa768
mcbot-0.94-5 Changelog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
11
diff
changeset
|
273 |
if (*token == '*') |
d3554afaa768
mcbot-0.94-5 Changelog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
11
diff
changeset
|
274 |
message->channel = ++token; |
d3554afaa768
mcbot-0.94-5 Changelog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
11
diff
changeset
|
275 |
snprintf (msg, 512, "PRIVMSG %s :%s, %s\r\n", message->channel, token, |
d3554afaa768
mcbot-0.94-5 Changelog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
11
diff
changeset
|
276 |
db_lookup (DATABASE_FILE, parameters)); |
0 | 277 |
} |
278 |
} |
|
279 |
return msg; |
|
3
a82a978f23f7
unreachable code removed and gitignore added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
280 |
|
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
281 |
case OP: |
0 | 282 |
if ((token = strtok (NULL, "\r\n")) != NULL) { |
3
a82a978f23f7
unreachable code removed and gitignore added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
283 |
if (strstr (message->email, db_lookup (DATABASE_FILE, "mcbot.email"))) |
0 | 284 |
snprintf (msg, 512, "MODE %s +o %s\r\n", message->channel, token); |
285 |
} |
|
286 |
return msg; |
|
287 |
} |
|
288 |
} |
|
289 |
i++; |
|
290 |
} |
|
291 |
||
292 |
return NULL; |
|
293 |
} |