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