author | Markus Bröker <mbroeker@largo.dyndns.tv> |
Thu, 28 May 2009 14:08:48 +0200 | |
changeset 37 | 85891f91096c |
parent 33 | 56571d34d754 |
child 38 | c2f62d1b8d76 |
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> |
|
33
56571d34d754
safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
31
diff
changeset
|
14 |
#include "common.h" |
0 | 15 |
|
16 |
#include <locale.h> |
|
17 |
#include <libintl.h> |
|
18 |
||
19 |
#ifndef DATABASE_FILE |
|
31
bbcb8a3366b4
mcbot needs a proper system account
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
23
diff
changeset
|
20 |
#define DATABASE_FILE "/var/lib/mcbot/data/mcbot.dat" |
0 | 21 |
#endif |
22 |
||
14
fe8adc56b109
mcbot shows the proper git location for the source...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
13
diff
changeset
|
23 |
#ifndef SOURCE_URL |
fe8adc56b109
mcbot shows the proper git location for the source...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
13
diff
changeset
|
24 |
#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
|
25 |
#endif |
fe8adc56b109
mcbot shows the proper git location for the source...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
13
diff
changeset
|
26 |
|
33
56571d34d754
safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
31
diff
changeset
|
27 |
enum { |
56571d34d754
safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
31
diff
changeset
|
28 |
HELP, JOIN, LEAVE, ADD, REPLACE, DELETE, LIST, SEARCH, INFO, PING, ON, OFF, DEBUG, |
56571d34d754
safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
31
diff
changeset
|
29 |
VACCUUM, LOGOUT, WHO, WHOIS, TIME, TELL, OP, DEOP, KICK, BAN, UNBAN, KICKBAN, HELLO |
56571d34d754
safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
31
diff
changeset
|
30 |
}; |
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
31 |
|
0 | 32 |
const |
33 |
char *COMMAND_LIST[] = { |
|
18
4435146391ae
LOGIN without Password added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
16
diff
changeset
|
34 |
"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
|
35 |
"join: Joins a new channel\r\n", |
4435146391ae
LOGIN without Password added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
16
diff
changeset
|
36 |
"leave: Parts from the current channel\r\n", |
4435146391ae
LOGIN without Password added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
16
diff
changeset
|
37 |
"add: adds an entry\r\n", |
4435146391ae
LOGIN without Password added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
16
diff
changeset
|
38 |
"replace: replaces an entry\r\n", |
4435146391ae
LOGIN without Password added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
16
diff
changeset
|
39 |
"delete: deletes an entry\r\n", |
4435146391ae
LOGIN without Password added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
16
diff
changeset
|
40 |
"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
|
41 |
"search: searches an entry up\r\n", |
4435146391ae
LOGIN without Password added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
16
diff
changeset
|
42 |
"info: Prints the current Bot-Version\r\n", |
4435146391ae
LOGIN without Password added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
16
diff
changeset
|
43 |
"ping: pings an host\r\n", |
4435146391ae
LOGIN without Password added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
16
diff
changeset
|
44 |
"on: enables autolearning mode\r\n", |
4435146391ae
LOGIN without Password added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
16
diff
changeset
|
45 |
"off: disables autolearning\r\n", |
4435146391ae
LOGIN without Password added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
16
diff
changeset
|
46 |
"debug: prints some debug infos\r\n", |
4435146391ae
LOGIN without Password added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
16
diff
changeset
|
47 |
"vaccuum: reorganizes the database\r\n", |
4435146391ae
LOGIN without Password added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
16
diff
changeset
|
48 |
"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
|
49 |
NULL, |
0 | 50 |
}; |
51 |
||
52 |
const |
|
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
53 |
char VISIBLE_ITEMS = 14; |
0 | 54 |
|
55 |
const |
|
56 |
char *Bot_Commands[] = { |
|
57 |
"!help", "!join", "!leave", |
|
58 |
"!add", "!replace", "!delete", |
|
59 |
"!list", "!search", "!info", |
|
60 |
"!ping", "!on", "!off", |
|
61 |
"!debug", "!vaccuum", "!logout", |
|
19
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
62 |
"!who", "!whois", "!time", |
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
63 |
"!tell", "!op", "!deop", |
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
64 |
"!kick", "!ban", "!unban", |
23
1cd79bb84e9c
ChangeLog for mcbot-0.96
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
22
diff
changeset
|
65 |
"!kickban", "!hello", |
19
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
66 |
NULL |
0 | 67 |
}; |
68 |
||
8
3152de03758e
A critical change was introduced here...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
3
diff
changeset
|
69 |
char *parse (MSG * message) |
0 | 70 |
{ |
33
56571d34d754
safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
31
diff
changeset
|
71 |
static char msg[DEFAULT_BUF_SIZE]; |
0 | 72 |
int cmd = -1; |
73 |
int i; |
|
74 |
char *token; |
|
75 |
char *parameters; |
|
76 |
||
77 |
time_t t; |
|
78 |
struct tm *timeptr; |
|
79 |
||
80 |
/* |
|
81 |
* default message |
|
82 |
*/ |
|
33
56571d34d754
safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
31
diff
changeset
|
83 |
snprintf (msg, sizeof (msg), "PRIVMSG %s :%s.\r\n", message->channel, gettext ("Request cannot be performed")); |
0 | 84 |
|
85 |
/* |
|
86 |
* PRIVATE MESSAGES |
|
87 |
*/ |
|
88 |
if (!strcmp (message->channel, message->nick)) |
|
89 |
message->channel = message->user; |
|
90 |
||
91 |
/* |
|
92 |
* NO BOT Commands |
|
93 |
*/ |
|
94 |
if (*message->line != '!') { |
|
95 |
return NULL; |
|
96 |
} |
|
97 |
||
98 |
i = 0; |
|
99 |
token = strtok (message->line, " "); |
|
100 |
while (Bot_Commands[i]) { |
|
101 |
if (!strcmp (token, Bot_Commands[i])) { |
|
102 |
switch (i) { |
|
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
103 |
case HELP: |
0 | 104 |
if ((token = strtok (NULL, "\r\n"))) |
105 |
cmd = atoi (token); |
|
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
106 |
if ((cmd > 0) && (cmd < VISIBLE_ITEMS)) |
33
56571d34d754
safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
31
diff
changeset
|
107 |
snprintf (msg, sizeof (msg), "PRIVMSG %s :%s\r\n", message->channel, COMMAND_LIST[cmd]); |
0 | 108 |
else |
33
56571d34d754
safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
31
diff
changeset
|
109 |
snprintf (msg, sizeof (msg), "PRIVMSG %s :%s\r\n", message->channel, COMMAND_LIST[0]); |
0 | 110 |
return msg; |
111 |
||
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
112 |
case JOIN: |
0 | 113 |
if ((token = strtok (NULL, "\r\n"))) |
21
138537d81dd1
Admin Commands secured
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
19
diff
changeset
|
114 |
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
|
115 |
if (strstr (message->email, db_lookup (DATABASE_FILE, "mcbot.email"))) |
33
56571d34d754
safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
31
diff
changeset
|
116 |
snprintf (msg, sizeof (msg), "JOIN %s\r\n", token); |
21
138537d81dd1
Admin Commands secured
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
19
diff
changeset
|
117 |
} |
0 | 118 |
return msg; |
119 |
||
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
120 |
case LEAVE: |
0 | 121 |
if (*message->channel != '#') |
122 |
return NULL; |
|
21
138537d81dd1
Admin Commands secured
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
19
diff
changeset
|
123 |
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
|
124 |
if (strstr (message->email, db_lookup (DATABASE_FILE, "mcbot.email"))) |
33
56571d34d754
safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
31
diff
changeset
|
125 |
snprintf (msg, sizeof (msg), "PART %s :Leaving.\r\n", message->channel); |
21
138537d81dd1
Admin Commands secured
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
19
diff
changeset
|
126 |
} |
0 | 127 |
return msg; |
128 |
||
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
129 |
case ADD: |
0 | 130 |
if ((token = strtok (NULL, " "))) { |
131 |
if ((parameters = strtok (NULL, "\r\n"))) { |
|
33
56571d34d754
safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
31
diff
changeset
|
132 |
snprintf (msg, sizeof (msg), "PRIVMSG %s :%s, %s\r\n", |
0 | 133 |
message->channel, message->user, db_insert (DATABASE_FILE, token, parameters, 0)); |
134 |
} else { |
|
33
56571d34d754
safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
31
diff
changeset
|
135 |
snprintf (msg, sizeof (msg), "PRIVMSG %s :%s, %s!\r\n", message->channel, |
3
a82a978f23f7
unreachable code removed and gitignore added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
136 |
gettext ("I need more parameters to add"), message->user); |
0 | 137 |
} |
138 |
} |
|
139 |
return msg; |
|
140 |
||
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
141 |
case REPLACE: |
0 | 142 |
if ((token = strtok (NULL, " "))) { |
143 |
if ((parameters = strtok (NULL, "\r\n"))) { |
|
33
56571d34d754
safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
31
diff
changeset
|
144 |
snprintf (msg, sizeof (msg), "PRIVMSG %s :%s, %s\r\n", |
0 | 145 |
message->channel, message->user, db_insert (DATABASE_FILE, token, parameters, 1)); |
146 |
} else { |
|
33
56571d34d754
safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
31
diff
changeset
|
147 |
snprintf (msg, sizeof (msg), "PRIVMSG %s :%s, %s!\r\n", message->channel, |
3
a82a978f23f7
unreachable code removed and gitignore added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
148 |
gettext ("I need more parameters to replace"), message->user); |
0 | 149 |
} |
150 |
} |
|
151 |
return msg; |
|
152 |
||
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
153 |
case DELETE: |
0 | 154 |
if ((token = strtok (NULL, "\r\n"))) { |
33
56571d34d754
safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
31
diff
changeset
|
155 |
snprintf (msg, sizeof (msg), "PRIVMSG %s :%s, %s\r\n", |
0 | 156 |
message->channel, message->user, db_remove (DATABASE_FILE, token)); |
157 |
} else { |
|
33
56571d34d754
safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
31
diff
changeset
|
158 |
snprintf (msg, sizeof (msg), "PRIVMSG %s :%s, %s!\r\n", message->channel, |
56571d34d754
safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
31
diff
changeset
|
159 |
gettext ("I need a key to delete"), message->user); |
0 | 160 |
} |
161 |
return msg; |
|
162 |
||
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
163 |
case LIST: |
33
56571d34d754
safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
31
diff
changeset
|
164 |
snprintf (msg, sizeof (msg), "PRIVMSG %s :%s %s\r\n", message->channel, db_elements (DATABASE_FILE), |
3
a82a978f23f7
unreachable code removed and gitignore added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
165 |
db_lookup (DATABASE_FILE, "mcbot.cgi")); |
0 | 166 |
return msg; |
167 |
||
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
168 |
case SEARCH: |
0 | 169 |
if ((token = strtok (NULL, "\r\n"))) { |
33
56571d34d754
safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
31
diff
changeset
|
170 |
snprintf (msg, sizeof (msg), "PRIVMSG %s :%s, %s\r\n", message->channel, message->user, |
3
a82a978f23f7
unreachable code removed and gitignore added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
171 |
db_lookup (DATABASE_FILE, token)); |
0 | 172 |
} else { |
33
56571d34d754
safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
31
diff
changeset
|
173 |
snprintf (msg, sizeof (msg), |
3
a82a978f23f7
unreachable code removed and gitignore added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
174 |
"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
|
175 |
message->user); |
0 | 176 |
} |
177 |
return msg; |
|
178 |
||
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
179 |
case INFO: |
33
56571d34d754
safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
31
diff
changeset
|
180 |
snprintf (msg, sizeof (msg), |
56571d34d754
safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
31
diff
changeset
|
181 |
"PRIVMSG %s :I am MCBot-%1.2f Build %s and my source code can be found at %s\r\n", |
23
1cd79bb84e9c
ChangeLog for mcbot-0.96
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
22
diff
changeset
|
182 |
message->channel, BOT_VERSION, BOT_BUILD, SOURCE_URL); |
0 | 183 |
return msg; |
184 |
||
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
185 |
case PING: |
0 | 186 |
if ((token = strtok (NULL, "\r\n"))) |
33
56571d34d754
safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
31
diff
changeset
|
187 |
snprintf (msg, sizeof (msg), "PRIVMSG %s :PING 0815\r\n", token); |
0 | 188 |
return msg; |
189 |
||
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
190 |
case ON: |
33
56571d34d754
safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
31
diff
changeset
|
191 |
snprintf (msg, sizeof (msg), "PRIVMSG %s :%s %s.\r\n", message->user, |
56571d34d754
safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
31
diff
changeset
|
192 |
gettext ("Autolearn enabled for channel"), message->channel); |
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 OFF: |
33
56571d34d754
safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
31
diff
changeset
|
196 |
snprintf (msg, sizeof (msg), "PRIVMSG %s :%s %s.\r\n", message->user, |
56571d34d754
safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
31
diff
changeset
|
197 |
gettext ("Autolearn disabled for channel"), message->channel); |
0 | 198 |
return msg; |
199 |
||
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
200 |
case DEBUG: |
33
56571d34d754
safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
31
diff
changeset
|
201 |
snprintf (msg, sizeof (msg), "PRIVMSG %s :USER: %s EMAIL: %s CHANNEL: %s LINE: %s\r\n", |
56571d34d754
safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
31
diff
changeset
|
202 |
message->channel, message->user, message->email, message->channel, message->line); |
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 VACCUUM: |
33
56571d34d754
safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
31
diff
changeset
|
206 |
snprintf (msg, sizeof (msg), "PRIVMSG %s :%s\r\n", message->channel, db_vaccuum (DATABASE_FILE)); |
0 | 207 |
return msg; |
208 |
||
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
209 |
case LOGOUT: |
3
a82a978f23f7
unreachable code removed and gitignore added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
210 |
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
|
211 |
if (strstr (message->email, db_lookup (DATABASE_FILE, "mcbot.email"))) { |
33
56571d34d754
safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
31
diff
changeset
|
212 |
snprintf (msg, sizeof (msg), "PRIVMSG %s :%s!\r\nQUIT\r\n", message->channel, |
3
a82a978f23f7
unreachable code removed and gitignore added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
213 |
gettext ("Bye, have a nice day!")); |
0 | 214 |
} |
215 |
} |
|
216 |
/* |
|
217 |
* the returned message is either the default one or the generated one |
|
218 |
*/ |
|
219 |
return msg; |
|
220 |
||
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
221 |
case WHO: |
0 | 222 |
if ((token = strtok (NULL, "\r\n")) != NULL) { |
33
56571d34d754
safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
31
diff
changeset
|
223 |
snprintf (msg, sizeof (msg), "WHO %s\r\n", token); |
0 | 224 |
} |
225 |
return msg; |
|
226 |
||
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
227 |
case WHOIS: |
0 | 228 |
if ((token = strtok (NULL, "\r\n")) != NULL) { |
33
56571d34d754
safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
31
diff
changeset
|
229 |
snprintf (msg, sizeof (msg), "WHOIS %s\r\n", token); |
0 | 230 |
} |
231 |
return msg; |
|
3
a82a978f23f7
unreachable code removed and gitignore added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
232 |
|
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
233 |
case TIME: |
0 | 234 |
t = time (NULL); |
235 |
timeptr = localtime (&t); |
|
236 |
if ((token = malloc (81))) { |
|
237 |
strftime (token, 80, "%I:%M:%S %p", timeptr); |
|
33
56571d34d754
safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
31
diff
changeset
|
238 |
snprintf (msg, sizeof (msg), "PRIVMSG %s :%s %s, %s!\r\n", message->channel, gettext ("It is"), |
56571d34d754
safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
31
diff
changeset
|
239 |
token, message->user); |
0 | 240 |
free (token); |
241 |
} |
|
242 |
return msg; |
|
3
a82a978f23f7
unreachable code removed and gitignore added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
243 |
|
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
244 |
case TELL: |
0 | 245 |
if ((token = strtok (NULL, " "))) { |
246 |
if ((parameters = strtok (NULL, "\r\n"))) { |
|
13
d3554afaa768
mcbot-0.94-5 Changelog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
11
diff
changeset
|
247 |
if (*token == '*') |
d3554afaa768
mcbot-0.94-5 Changelog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
11
diff
changeset
|
248 |
message->channel = ++token; |
33
56571d34d754
safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
31
diff
changeset
|
249 |
snprintf (msg, sizeof (msg), "PRIVMSG %s :%s, %s\r\n", message->channel, token, |
13
d3554afaa768
mcbot-0.94-5 Changelog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
11
diff
changeset
|
250 |
db_lookup (DATABASE_FILE, parameters)); |
0 | 251 |
} |
252 |
} |
|
253 |
return msg; |
|
3
a82a978f23f7
unreachable code removed and gitignore added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
254 |
|
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
255 |
case OP: |
0 | 256 |
if ((token = strtok (NULL, "\r\n")) != NULL) { |
21
138537d81dd1
Admin Commands secured
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
19
diff
changeset
|
257 |
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
|
258 |
if (strstr (message->email, db_lookup (DATABASE_FILE, "mcbot.email"))) |
33
56571d34d754
safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
31
diff
changeset
|
259 |
snprintf (msg, sizeof (msg), "MODE %s +o %s\r\n", message->channel, token); |
21
138537d81dd1
Admin Commands secured
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
19
diff
changeset
|
260 |
} |
0 | 261 |
} |
262 |
return msg; |
|
19
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
263 |
|
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
264 |
case DEOP: |
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
265 |
if ((token = strtok (NULL, "\r\n")) != NULL) { |
21
138537d81dd1
Admin Commands secured
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
19
diff
changeset
|
266 |
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
|
267 |
if (strstr (message->email, db_lookup (DATABASE_FILE, "mcbot.email"))) |
33
56571d34d754
safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
31
diff
changeset
|
268 |
snprintf (msg, sizeof (msg), "MODE %s -o %s\r\n", message->channel, token); |
21
138537d81dd1
Admin Commands secured
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
19
diff
changeset
|
269 |
} |
19
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
270 |
} |
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
271 |
return msg; |
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
272 |
|
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
273 |
case KICK: |
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
274 |
if ((token = strtok (NULL, "\r\n")) != NULL) { |
21
138537d81dd1
Admin Commands secured
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
19
diff
changeset
|
275 |
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
|
276 |
if (strstr (message->email, db_lookup (DATABASE_FILE, "mcbot.email"))) |
33
56571d34d754
safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
31
diff
changeset
|
277 |
snprintf (msg, sizeof (msg), "KICK %s %s\r\n", message->channel, token); |
21
138537d81dd1
Admin Commands secured
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
19
diff
changeset
|
278 |
} |
19
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
279 |
} |
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
280 |
return msg; |
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
281 |
|
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
282 |
case BAN: |
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
283 |
if ((token = strtok (NULL, "\r\n")) != NULL) { |
21
138537d81dd1
Admin Commands secured
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
19
diff
changeset
|
284 |
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
|
285 |
if (strstr (message->email, db_lookup (DATABASE_FILE, "mcbot.email"))) |
33
56571d34d754
safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
31
diff
changeset
|
286 |
snprintf (msg, sizeof (msg), "MODE %s +b %s\r\n", message->channel, token); |
21
138537d81dd1
Admin Commands secured
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
19
diff
changeset
|
287 |
} |
19
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
288 |
} |
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
289 |
return msg; |
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 |
case UNBAN: |
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
292 |
if ((token = strtok (NULL, "\r\n")) != NULL) { |
21
138537d81dd1
Admin Commands secured
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
19
diff
changeset
|
293 |
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
|
294 |
if (strstr (message->email, db_lookup (DATABASE_FILE, "mcbot.email"))) |
33
56571d34d754
safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
31
diff
changeset
|
295 |
snprintf (msg, sizeof (msg), "MODE %s -b %s\r\n", message->channel, token); |
21
138537d81dd1
Admin Commands secured
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
19
diff
changeset
|
296 |
} |
19
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
297 |
} |
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
298 |
return msg; |
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 |
case KICKBAN: |
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
301 |
if ((token = strtok (NULL, "\r\n")) != NULL) { |
21
138537d81dd1
Admin Commands secured
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
19
diff
changeset
|
302 |
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
|
303 |
if (strstr (message->email, db_lookup (DATABASE_FILE, "mcbot.email"))) |
33
56571d34d754
safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
31
diff
changeset
|
304 |
snprintf (msg, sizeof (msg), "MODE %s +b %s\r\nKICK %s %s\r\n", message->channel, token, |
21
138537d81dd1
Admin Commands secured
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
19
diff
changeset
|
305 |
message->channel, token); |
138537d81dd1
Admin Commands secured
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
19
diff
changeset
|
306 |
} |
19
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; |
23
1cd79bb84e9c
ChangeLog for mcbot-0.96
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
22
diff
changeset
|
309 |
|
1cd79bb84e9c
ChangeLog for mcbot-0.96
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
22
diff
changeset
|
310 |
case HELLO: |
33
56571d34d754
safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
31
diff
changeset
|
311 |
snprintf (msg, sizeof (msg), "PRIVMSG %s :%s, %s?\r\n", message->channel, gettext ("What's up"), |
56571d34d754
safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
31
diff
changeset
|
312 |
message->user); |
23
1cd79bb84e9c
ChangeLog for mcbot-0.96
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
22
diff
changeset
|
313 |
return msg; |
0 | 314 |
} |
315 |
} |
|
316 |
i++; |
|
317 |
} |
|
318 |
||
319 |
return NULL; |
|
320 |
} |