author | Markus Bröker <mbroeker@largo.dyndns.tv> |
Sat, 13 Dec 2008 15:41:50 +0100 | |
changeset 20 | b94039112f28 |
parent 19 | 66114d944208 |
child 21 | 138537d81dd1 |
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 |
19
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
46 |
#define DEOP 20 |
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
47 |
#define KICK 21 |
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
48 |
#define BAN 22 |
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
49 |
#define UNBAN 23 |
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
50 |
#define KICKBAN 24 |
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
51 |
|
0 | 52 |
const |
53 |
char *COMMAND_LIST[] = { |
|
18
4435146391ae
LOGIN without Password added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
16
diff
changeset
|
54 |
"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
|
55 |
"join: Joins a new channel\r\n", |
4435146391ae
LOGIN without Password added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
16
diff
changeset
|
56 |
"leave: Parts from the current channel\r\n", |
4435146391ae
LOGIN without Password added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
16
diff
changeset
|
57 |
"add: adds an entry\r\n", |
4435146391ae
LOGIN without Password added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
16
diff
changeset
|
58 |
"replace: replaces an entry\r\n", |
4435146391ae
LOGIN without Password added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
16
diff
changeset
|
59 |
"delete: deletes an entry\r\n", |
4435146391ae
LOGIN without Password added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
16
diff
changeset
|
60 |
"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
|
61 |
"search: searches an entry up\r\n", |
4435146391ae
LOGIN without Password added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
16
diff
changeset
|
62 |
"info: Prints the current Bot-Version\r\n", |
4435146391ae
LOGIN without Password added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
16
diff
changeset
|
63 |
"ping: pings an host\r\n", |
4435146391ae
LOGIN without Password added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
16
diff
changeset
|
64 |
"on: enables autolearning mode\r\n", |
4435146391ae
LOGIN without Password added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
16
diff
changeset
|
65 |
"off: disables autolearning\r\n", |
4435146391ae
LOGIN without Password added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
16
diff
changeset
|
66 |
"debug: prints some debug infos\r\n", |
4435146391ae
LOGIN without Password added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
16
diff
changeset
|
67 |
"vaccuum: reorganizes the database\r\n", |
4435146391ae
LOGIN without Password added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
16
diff
changeset
|
68 |
"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
|
69 |
NULL, |
0 | 70 |
}; |
71 |
||
72 |
const |
|
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
73 |
char VISIBLE_ITEMS = 14; |
0 | 74 |
|
75 |
const |
|
76 |
char *Bot_Commands[] = { |
|
77 |
"!help", "!join", "!leave", |
|
78 |
"!add", "!replace", "!delete", |
|
79 |
"!list", "!search", "!info", |
|
80 |
"!ping", "!on", "!off", |
|
81 |
"!debug", "!vaccuum", "!logout", |
|
19
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
82 |
"!who", "!whois", "!time", |
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
83 |
"!tell", "!op", "!deop", |
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
84 |
"!kick", "!ban", "!unban", |
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
85 |
"!kickban", |
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
86 |
NULL |
0 | 87 |
}; |
88 |
||
8
3152de03758e
A critical change was introduced here...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
3
diff
changeset
|
89 |
char *parse (MSG * message) |
0 | 90 |
{ |
91 |
static char msg[513]; |
|
92 |
int cmd = -1; |
|
93 |
int i; |
|
94 |
char *token; |
|
95 |
char *parameters; |
|
96 |
||
97 |
time_t t; |
|
98 |
struct tm *timeptr; |
|
99 |
static int counter = 0; |
|
100 |
||
101 |
/* |
|
102 |
* default message |
|
103 |
*/ |
|
104 |
snprintf (msg, 512, "PRIVMSG %s :%s.\r\n", message->channel, gettext ("Request cannot be performed")); |
|
105 |
||
106 |
/* |
|
107 |
* PRIVATE MESSAGES |
|
108 |
*/ |
|
109 |
if (!strcmp (message->channel, message->nick)) |
|
110 |
message->channel = message->user; |
|
111 |
||
112 |
if (strstr (message->line, message->nick)) { |
|
113 |
if (*message->line != '!') { |
|
114 |
/* |
|
115 |
* DEAD - LOCK - CHECK |
|
116 |
*/ |
|
117 |
if (strcmp (message->user, message->nick)) { |
|
118 |
snprintf (msg, 512, "PRIVMSG %s :%s, %s?\r\n", message->channel, gettext ("What's up"), message->user); |
|
119 |
if (counter++ > 3) |
|
120 |
return NULL; |
|
121 |
return msg; |
|
122 |
} |
|
123 |
/* |
|
124 |
* DEAD - LOCK - CHECK ENDS |
|
125 |
*/ |
|
126 |
} |
|
127 |
return NULL; |
|
128 |
} |
|
129 |
||
130 |
counter = 0; |
|
131 |
||
132 |
/* |
|
133 |
* NO BOT Commands |
|
134 |
*/ |
|
135 |
if (*message->line != '!') { |
|
136 |
return NULL; |
|
137 |
} |
|
138 |
||
139 |
i = 0; |
|
140 |
token = strtok (message->line, " "); |
|
141 |
while (Bot_Commands[i]) { |
|
142 |
if (!strcmp (token, Bot_Commands[i])) { |
|
143 |
switch (i) { |
|
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
144 |
case HELP: |
0 | 145 |
if ((token = strtok (NULL, "\r\n"))) |
146 |
cmd = atoi (token); |
|
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
147 |
if ((cmd > 0) && (cmd < VISIBLE_ITEMS)) |
0 | 148 |
snprintf (msg, 512, "PRIVMSG %s :%s\r\n", message->channel, COMMAND_LIST[cmd]); |
149 |
else |
|
150 |
snprintf (msg, 512, "PRIVMSG %s :%s\r\n", message->channel, COMMAND_LIST[0]); |
|
151 |
return msg; |
|
152 |
||
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
153 |
case JOIN: |
0 | 154 |
if ((token = strtok (NULL, "\r\n"))) |
155 |
snprintf (msg, 512, "JOIN %s\r\n", token); |
|
156 |
return msg; |
|
157 |
||
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
158 |
case LEAVE: |
0 | 159 |
if (*message->channel != '#') |
160 |
return NULL; |
|
161 |
snprintf (msg, 512, "PART %s :Leaving.\r\n", message->channel); |
|
162 |
return msg; |
|
163 |
||
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
164 |
case ADD: |
0 | 165 |
if ((token = strtok (NULL, " "))) { |
166 |
if ((parameters = strtok (NULL, "\r\n"))) { |
|
167 |
snprintf (msg, 512, "PRIVMSG %s :%s, %s\r\n", |
|
168 |
message->channel, message->user, db_insert (DATABASE_FILE, token, parameters, 0)); |
|
169 |
} else { |
|
3
a82a978f23f7
unreachable code removed and gitignore added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
170 |
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
|
171 |
gettext ("I need more parameters to add"), message->user); |
0 | 172 |
} |
173 |
} |
|
174 |
return msg; |
|
175 |
||
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
176 |
case REPLACE: |
0 | 177 |
if ((token = strtok (NULL, " "))) { |
178 |
if ((parameters = strtok (NULL, "\r\n"))) { |
|
179 |
snprintf (msg, 512, "PRIVMSG %s :%s, %s\r\n", |
|
180 |
message->channel, message->user, db_insert (DATABASE_FILE, token, parameters, 1)); |
|
181 |
} else { |
|
3
a82a978f23f7
unreachable code removed and gitignore added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
182 |
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
|
183 |
gettext ("I need more parameters to replace"), message->user); |
0 | 184 |
} |
185 |
} |
|
186 |
return msg; |
|
187 |
||
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
188 |
case DELETE: |
0 | 189 |
if ((token = strtok (NULL, "\r\n"))) { |
190 |
snprintf (msg, 512, "PRIVMSG %s :%s, %s\r\n", |
|
191 |
message->channel, message->user, db_remove (DATABASE_FILE, token)); |
|
192 |
} else { |
|
3
a82a978f23f7
unreachable code removed and gitignore added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
193 |
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
|
194 |
message->user); |
0 | 195 |
} |
196 |
return msg; |
|
197 |
||
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
198 |
case LIST: |
3
a82a978f23f7
unreachable code removed and gitignore added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
199 |
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
|
200 |
db_lookup (DATABASE_FILE, "mcbot.cgi")); |
0 | 201 |
return msg; |
202 |
||
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
203 |
case SEARCH: |
0 | 204 |
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
|
205 |
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
|
206 |
db_lookup (DATABASE_FILE, token)); |
0 | 207 |
} else { |
208 |
snprintf (msg, 512, |
|
3
a82a978f23f7
unreachable code removed and gitignore added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
209 |
"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
|
210 |
message->user); |
0 | 211 |
} |
212 |
return msg; |
|
213 |
||
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
214 |
case INFO: |
3
a82a978f23f7
unreachable code removed and gitignore added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
215 |
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
|
216 |
message->channel, BOT_VERSION, SOURCE_URL); |
0 | 217 |
return msg; |
218 |
||
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
219 |
case PING: |
0 | 220 |
if ((token = strtok (NULL, "\r\n"))) |
221 |
snprintf (msg, 512, "PRIVMSG %s :PING 0815\r\n", token); |
|
222 |
return msg; |
|
223 |
||
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
224 |
case ON: |
3
a82a978f23f7
unreachable code removed and gitignore added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
225 |
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
|
226 |
message->channel); |
0 | 227 |
return msg; |
228 |
||
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
229 |
case OFF: |
3
a82a978f23f7
unreachable code removed and gitignore added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
230 |
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
|
231 |
message->channel); |
0 | 232 |
return msg; |
233 |
||
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
234 |
case DEBUG: |
3
a82a978f23f7
unreachable code removed and gitignore added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
235 |
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
|
236 |
message->user, message->email, message->channel, message->line); |
0 | 237 |
return msg; |
238 |
||
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
239 |
case VACCUUM: |
0 | 240 |
snprintf (msg, 512, "PRIVMSG %s :%s\r\n", message->channel, db_vaccuum (DATABASE_FILE)); |
241 |
return msg; |
|
242 |
||
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
243 |
case LOGOUT: |
3
a82a978f23f7
unreachable code removed and gitignore added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
244 |
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
|
245 |
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
|
246 |
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
|
247 |
gettext ("Bye, have a nice day!")); |
0 | 248 |
} |
249 |
} |
|
250 |
/* |
|
251 |
* the returned message is either the default one or the generated one |
|
252 |
*/ |
|
253 |
return msg; |
|
254 |
||
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
255 |
case WHO: |
0 | 256 |
if ((token = strtok (NULL, "\r\n")) != NULL) { |
257 |
snprintf (msg, 512, "WHO %s\r\n", token); |
|
258 |
} |
|
259 |
return msg; |
|
260 |
||
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
261 |
case WHOIS: |
0 | 262 |
if ((token = strtok (NULL, "\r\n")) != NULL) { |
263 |
snprintf (msg, 512, "WHOIS %s\r\n", token); |
|
264 |
} |
|
265 |
return msg; |
|
3
a82a978f23f7
unreachable code removed and gitignore added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
266 |
|
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
267 |
case TIME: |
0 | 268 |
t = time (NULL); |
269 |
timeptr = localtime (&t); |
|
270 |
if ((token = malloc (81))) { |
|
271 |
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
|
272 |
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
|
273 |
message->user); |
0 | 274 |
free (token); |
275 |
} |
|
276 |
return msg; |
|
3
a82a978f23f7
unreachable code removed and gitignore added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
277 |
|
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
278 |
case TELL: |
0 | 279 |
if ((token = strtok (NULL, " "))) { |
280 |
if ((parameters = strtok (NULL, "\r\n"))) { |
|
13
d3554afaa768
mcbot-0.94-5 Changelog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
11
diff
changeset
|
281 |
if (*token == '*') |
d3554afaa768
mcbot-0.94-5 Changelog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
11
diff
changeset
|
282 |
message->channel = ++token; |
d3554afaa768
mcbot-0.94-5 Changelog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
11
diff
changeset
|
283 |
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
|
284 |
db_lookup (DATABASE_FILE, parameters)); |
0 | 285 |
} |
286 |
} |
|
287 |
return msg; |
|
3
a82a978f23f7
unreachable code removed and gitignore added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
288 |
|
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
289 |
case OP: |
0 | 290 |
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
|
291 |
if (strstr (message->email, db_lookup (DATABASE_FILE, "mcbot.email"))) |
0 | 292 |
snprintf (msg, 512, "MODE %s +o %s\r\n", message->channel, token); |
293 |
} |
|
294 |
return msg; |
|
19
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
295 |
|
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
296 |
case DEOP: |
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
297 |
if ((token = strtok (NULL, "\r\n")) != NULL) { |
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
298 |
if (strstr (message->email, db_lookup (DATABASE_FILE, "mcbot.email"))) |
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
299 |
snprintf (msg, 512, "MODE %s -o %s\r\n", message->channel, token); |
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
300 |
} |
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
301 |
return msg; |
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
302 |
|
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
303 |
case KICK: |
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
304 |
if ((token = strtok (NULL, "\r\n")) != NULL) { |
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
305 |
if (strstr (message->email, db_lookup (DATABASE_FILE, "mcbot.email"))) |
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
306 |
snprintf (msg, 512, "KICK %s %s\r\n", message->channel, token); |
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
307 |
} |
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
308 |
return msg; |
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
309 |
|
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
310 |
case BAN: |
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
311 |
if ((token = strtok (NULL, "\r\n")) != NULL) { |
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
312 |
if (strstr (message->email, db_lookup (DATABASE_FILE, "mcbot.email"))) |
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
313 |
snprintf (msg, 512, "MODE %s +b %s\r\n", message->channel, token); |
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
314 |
} |
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
315 |
return msg; |
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
316 |
|
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
317 |
case UNBAN: |
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
318 |
if ((token = strtok (NULL, "\r\n")) != NULL) { |
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
319 |
if (strstr (message->email, db_lookup (DATABASE_FILE, "mcbot.email"))) |
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
320 |
snprintf (msg, 512, "MODE %s -b %s\r\n", message->channel, token); |
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
321 |
} |
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
322 |
return msg; |
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
323 |
|
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
324 |
case KICKBAN: |
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
325 |
if ((token = strtok (NULL, "\r\n")) != NULL) { |
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
326 |
if (strstr (message->email, db_lookup (DATABASE_FILE, "mcbot.email"))) |
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
327 |
snprintf (msg, 512, "MODE %s +b %s\r\nKICK %s %s\r\n", message->channel, token, |
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
328 |
message->channel, token); |
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
329 |
} |
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
330 |
return msg; |
0 | 331 |
} |
332 |
} |
|
333 |
i++; |
|
334 |
} |
|
335 |
||
336 |
return NULL; |
|
337 |
} |