author | Markus Bröker <mbroeker@largo.dyndns.tv> |
Wed, 03 Mar 2010 18:36:54 +0100 | |
changeset 52 | c9401e6a62cb |
parent 48 | 34094173351c |
child 61 | fb2cfcee38bd |
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 |
|
38
c2f62d1b8d76
enumerated types for parse.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
33
diff
changeset
|
27 |
enum command_map { |
33
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, |
40
5b7e8dba46a0
Topic command added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
39
diff
changeset
|
29 |
VACCUUM, LOGOUT, WHO, WHOIS, TIME, TELL, OP, DEOP, KICK, BAN, UNBAN, KICKBAN, HELLO, |
5b7e8dba46a0
Topic command added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
39
diff
changeset
|
30 |
TOPIC, |
33
56571d34d754
safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
31
diff
changeset
|
31 |
}; |
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
32 |
|
0 | 33 |
const |
34 |
char *COMMAND_LIST[] = { |
|
18
4435146391ae
LOGIN without Password added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
16
diff
changeset
|
35 |
"help Known Commands: join(1), leave(2), add(3), replace(4), delete(5), list(6), search(7), info(8)\r\n", |
39
0ae006af497e
fixed some typos in the help screen
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
38
diff
changeset
|
36 |
"join Joins a new channel\r\n", |
0ae006af497e
fixed some typos in the help screen
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
38
diff
changeset
|
37 |
"leave Parts from the current channel\r\n", |
0ae006af497e
fixed some typos in the help screen
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
38
diff
changeset
|
38 |
"add adds an entry\r\n", |
0ae006af497e
fixed some typos in the help screen
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
38
diff
changeset
|
39 |
"replace replaces an entry\r\n", |
0ae006af497e
fixed some typos in the help screen
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
38
diff
changeset
|
40 |
"delete deletes an entry\r\n", |
0ae006af497e
fixed some typos in the help screen
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
38
diff
changeset
|
41 |
"list lists the number of stored values\r\n", |
0ae006af497e
fixed some typos in the help screen
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
38
diff
changeset
|
42 |
"search searches an entry up\r\n", |
0ae006af497e
fixed some typos in the help screen
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
38
diff
changeset
|
43 |
"info Prints the current Bot-Version\r\n", |
0ae006af497e
fixed some typos in the help screen
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
38
diff
changeset
|
44 |
"ping pings an host\r\n", |
0ae006af497e
fixed some typos in the help screen
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
38
diff
changeset
|
45 |
"on enables autolearning mode\r\n", |
0ae006af497e
fixed some typos in the help screen
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
38
diff
changeset
|
46 |
"off disables autolearning\r\n", |
0ae006af497e
fixed some typos in the help screen
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
38
diff
changeset
|
47 |
"debug prints some debug infos\r\n", |
0ae006af497e
fixed some typos in the help screen
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
38
diff
changeset
|
48 |
"vaccuum reorganizes the database\r\n", |
0ae006af497e
fixed some typos in the help screen
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
38
diff
changeset
|
49 |
"logout Protected logout function\r\n", |
40
5b7e8dba46a0
Topic command added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
39
diff
changeset
|
50 |
"topic Sets a new topic\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
|
51 |
NULL, |
0 | 52 |
}; |
53 |
||
54 |
const |
|
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
55 |
char VISIBLE_ITEMS = 14; |
0 | 56 |
|
57 |
const |
|
58 |
char *Bot_Commands[] = { |
|
59 |
"!help", "!join", "!leave", |
|
60 |
"!add", "!replace", "!delete", |
|
61 |
"!list", "!search", "!info", |
|
62 |
"!ping", "!on", "!off", |
|
63 |
"!debug", "!vaccuum", "!logout", |
|
19
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
64 |
"!who", "!whois", "!time", |
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
65 |
"!tell", "!op", "!deop", |
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
66 |
"!kick", "!ban", "!unban", |
40
5b7e8dba46a0
Topic command added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
39
diff
changeset
|
67 |
"!kickban", "!hello", "!topic", |
19
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
68 |
NULL |
0 | 69 |
}; |
70 |
||
8
3152de03758e
A critical change was introduced here...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
3
diff
changeset
|
71 |
char *parse (MSG * message) |
0 | 72 |
{ |
33
56571d34d754
safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
31
diff
changeset
|
73 |
static char msg[DEFAULT_BUF_SIZE]; |
0 | 74 |
int cmd = -1; |
38
c2f62d1b8d76
enumerated types for parse.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
33
diff
changeset
|
75 |
enum command_map map; |
0 | 76 |
char *token; |
77 |
char *parameters; |
|
78 |
||
79 |
time_t t; |
|
80 |
struct tm *timeptr; |
|
81 |
||
82 |
/* |
|
45
535478a0f482
Prevent further segmentation faults in parse.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
40
diff
changeset
|
83 |
* make sure that parseable data is available |
535478a0f482
Prevent further segmentation faults in parse.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
40
diff
changeset
|
84 |
* this prevents a possible segmentation fault |
535478a0f482
Prevent further segmentation faults in parse.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
40
diff
changeset
|
85 |
*/ |
535478a0f482
Prevent further segmentation faults in parse.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
40
diff
changeset
|
86 |
if (message->user == NULL) |
535478a0f482
Prevent further segmentation faults in parse.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
40
diff
changeset
|
87 |
message->user = "error"; |
48
34094173351c
message.email renamed to message.domain
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
45
diff
changeset
|
88 |
if (message->domain == NULL) |
34094173351c
message.email renamed to message.domain
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
45
diff
changeset
|
89 |
message->domain = "server.err"; |
45
535478a0f482
Prevent further segmentation faults in parse.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
40
diff
changeset
|
90 |
|
535478a0f482
Prevent further segmentation faults in parse.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
40
diff
changeset
|
91 |
/* |
0 | 92 |
* default message |
93 |
*/ |
|
33
56571d34d754
safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
31
diff
changeset
|
94 |
snprintf (msg, sizeof (msg), "PRIVMSG %s :%s.\r\n", message->channel, gettext ("Request cannot be performed")); |
0 | 95 |
|
96 |
/* |
|
97 |
* PRIVATE MESSAGES |
|
98 |
*/ |
|
99 |
if (!strcmp (message->channel, message->nick)) |
|
100 |
message->channel = message->user; |
|
101 |
||
102 |
/* |
|
103 |
* NO BOT Commands |
|
104 |
*/ |
|
105 |
if (*message->line != '!') { |
|
106 |
return NULL; |
|
107 |
} |
|
108 |
||
38
c2f62d1b8d76
enumerated types for parse.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
33
diff
changeset
|
109 |
map = 0; |
0 | 110 |
token = strtok (message->line, " "); |
38
c2f62d1b8d76
enumerated types for parse.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
33
diff
changeset
|
111 |
while (Bot_Commands[map]) { |
c2f62d1b8d76
enumerated types for parse.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
33
diff
changeset
|
112 |
if (!strcmp (token, Bot_Commands[map])) { |
c2f62d1b8d76
enumerated types for parse.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
33
diff
changeset
|
113 |
switch (map) { |
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
114 |
case HELP: |
0 | 115 |
if ((token = strtok (NULL, "\r\n"))) |
116 |
cmd = atoi (token); |
|
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
117 |
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
|
118 |
snprintf (msg, sizeof (msg), "PRIVMSG %s :%s\r\n", message->channel, COMMAND_LIST[cmd]); |
0 | 119 |
else |
33
56571d34d754
safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
31
diff
changeset
|
120 |
snprintf (msg, sizeof (msg), "PRIVMSG %s :%s\r\n", message->channel, COMMAND_LIST[0]); |
0 | 121 |
return msg; |
122 |
||
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
123 |
case JOIN: |
0 | 124 |
if ((token = strtok (NULL, "\r\n"))) |
21
138537d81dd1
Admin Commands secured
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
19
diff
changeset
|
125 |
if (strstr (message->user, db_lookup (DATABASE_FILE, "mcbot.user"))) { |
48
34094173351c
message.email renamed to message.domain
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
45
diff
changeset
|
126 |
if (strstr (message->domain, db_lookup (DATABASE_FILE, "mcbot.domain"))) |
33
56571d34d754
safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
31
diff
changeset
|
127 |
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
|
128 |
} |
0 | 129 |
return msg; |
130 |
||
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
131 |
case LEAVE: |
0 | 132 |
if (*message->channel != '#') |
133 |
return NULL; |
|
21
138537d81dd1
Admin Commands secured
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
19
diff
changeset
|
134 |
if (strstr (message->user, db_lookup (DATABASE_FILE, "mcbot.user"))) { |
48
34094173351c
message.email renamed to message.domain
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
45
diff
changeset
|
135 |
if (strstr (message->domain, db_lookup (DATABASE_FILE, "mcbot.domain"))) |
33
56571d34d754
safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
31
diff
changeset
|
136 |
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
|
137 |
} |
0 | 138 |
return msg; |
139 |
||
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
140 |
case ADD: |
0 | 141 |
if ((token = strtok (NULL, " "))) { |
142 |
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
|
143 |
snprintf (msg, sizeof (msg), "PRIVMSG %s :%s, %s\r\n", |
0 | 144 |
message->channel, message->user, db_insert (DATABASE_FILE, token, parameters, 0)); |
145 |
} else { |
|
33
56571d34d754
safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
31
diff
changeset
|
146 |
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
|
147 |
gettext ("I need more parameters to add"), message->user); |
0 | 148 |
} |
149 |
} |
|
150 |
return msg; |
|
151 |
||
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
152 |
case REPLACE: |
0 | 153 |
if ((token = strtok (NULL, " "))) { |
154 |
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
|
155 |
snprintf (msg, sizeof (msg), "PRIVMSG %s :%s, %s\r\n", |
0 | 156 |
message->channel, message->user, db_insert (DATABASE_FILE, token, parameters, 1)); |
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, |
3
a82a978f23f7
unreachable code removed and gitignore added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
159 |
gettext ("I need more parameters to replace"), message->user); |
0 | 160 |
} |
161 |
} |
|
162 |
return msg; |
|
163 |
||
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
164 |
case DELETE: |
0 | 165 |
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
|
166 |
snprintf (msg, sizeof (msg), "PRIVMSG %s :%s, %s\r\n", |
0 | 167 |
message->channel, message->user, db_remove (DATABASE_FILE, token)); |
168 |
} else { |
|
33
56571d34d754
safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
31
diff
changeset
|
169 |
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
|
170 |
gettext ("I need a key to delete"), message->user); |
0 | 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 LIST: |
33
56571d34d754
safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
31
diff
changeset
|
175 |
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
|
176 |
db_lookup (DATABASE_FILE, "mcbot.cgi")); |
0 | 177 |
return msg; |
178 |
||
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
179 |
case SEARCH: |
0 | 180 |
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
|
181 |
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
|
182 |
db_lookup (DATABASE_FILE, token)); |
0 | 183 |
} else { |
33
56571d34d754
safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
31
diff
changeset
|
184 |
snprintf (msg, sizeof (msg), |
3
a82a978f23f7
unreachable code removed and gitignore added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
185 |
"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
|
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 INFO: |
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), |
56571d34d754
safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
31
diff
changeset
|
192 |
"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
|
193 |
message->channel, BOT_VERSION, BOT_BUILD, SOURCE_URL); |
0 | 194 |
return msg; |
195 |
||
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
196 |
case PING: |
0 | 197 |
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
|
198 |
snprintf (msg, sizeof (msg), "PRIVMSG %s :PING 0815\r\n", token); |
0 | 199 |
return msg; |
200 |
||
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
201 |
case ON: |
33
56571d34d754
safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
31
diff
changeset
|
202 |
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
|
203 |
gettext ("Autolearn enabled for channel"), message->channel); |
0 | 204 |
return msg; |
205 |
||
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
206 |
case OFF: |
33
56571d34d754
safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
31
diff
changeset
|
207 |
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
|
208 |
gettext ("Autolearn disabled for channel"), message->channel); |
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 DEBUG: |
48
34094173351c
message.email renamed to message.domain
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
45
diff
changeset
|
212 |
snprintf (msg, sizeof (msg), "PRIVMSG %s :USER: %s domain: %s CHANNEL: %s LINE: %s\r\n", |
34094173351c
message.email renamed to message.domain
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
45
diff
changeset
|
213 |
message->channel, message->user, message->domain, message->channel, message->line); |
0 | 214 |
return msg; |
215 |
||
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
216 |
case VACCUUM: |
33
56571d34d754
safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
31
diff
changeset
|
217 |
snprintf (msg, sizeof (msg), "PRIVMSG %s :%s\r\n", message->channel, db_vaccuum (DATABASE_FILE)); |
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 LOGOUT: |
3
a82a978f23f7
unreachable code removed and gitignore added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
221 |
if (strstr (message->user, db_lookup (DATABASE_FILE, "mcbot.user"))) { |
48
34094173351c
message.email renamed to message.domain
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
45
diff
changeset
|
222 |
if (strstr (message->domain, db_lookup (DATABASE_FILE, "mcbot.domain"))) { |
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), "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
|
224 |
gettext ("Bye, have a nice day!")); |
0 | 225 |
} |
226 |
} |
|
227 |
/* |
|
228 |
* the returned message is either the default one or the generated one |
|
229 |
*/ |
|
230 |
return msg; |
|
231 |
||
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
232 |
case WHO: |
0 | 233 |
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
|
234 |
snprintf (msg, sizeof (msg), "WHO %s\r\n", token); |
0 | 235 |
} |
236 |
return msg; |
|
237 |
||
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
238 |
case WHOIS: |
0 | 239 |
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
|
240 |
snprintf (msg, sizeof (msg), "WHOIS %s\r\n", token); |
0 | 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 TIME: |
0 | 245 |
t = time (NULL); |
246 |
timeptr = localtime (&t); |
|
247 |
if ((token = malloc (81))) { |
|
248 |
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
|
249 |
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
|
250 |
token, message->user); |
0 | 251 |
free (token); |
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 TELL: |
0 | 256 |
if ((token = strtok (NULL, " "))) { |
257 |
if ((parameters = strtok (NULL, "\r\n"))) { |
|
13
d3554afaa768
mcbot-0.94-5 Changelog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
11
diff
changeset
|
258 |
if (*token == '*') |
d3554afaa768
mcbot-0.94-5 Changelog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
11
diff
changeset
|
259 |
message->channel = ++token; |
33
56571d34d754
safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
31
diff
changeset
|
260 |
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
|
261 |
db_lookup (DATABASE_FILE, parameters)); |
0 | 262 |
} |
263 |
} |
|
264 |
return msg; |
|
3
a82a978f23f7
unreachable code removed and gitignore added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
265 |
|
15
f19c1f9b4cd3
ChangeLog mcbot-0.95-1
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
14
diff
changeset
|
266 |
case OP: |
0 | 267 |
if ((token = strtok (NULL, "\r\n")) != NULL) { |
21
138537d81dd1
Admin Commands secured
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
19
diff
changeset
|
268 |
if (strstr (message->user, db_lookup (DATABASE_FILE, "mcbot.user"))) { |
48
34094173351c
message.email renamed to message.domain
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
45
diff
changeset
|
269 |
if (strstr (message->domain, db_lookup (DATABASE_FILE, "mcbot.domain"))) |
33
56571d34d754
safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
31
diff
changeset
|
270 |
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
|
271 |
} |
0 | 272 |
} |
273 |
return msg; |
|
19
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
274 |
|
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
275 |
case DEOP: |
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
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"))) { |
48
34094173351c
message.email renamed to message.domain
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
45
diff
changeset
|
278 |
if (strstr (message->domain, db_lookup (DATABASE_FILE, "mcbot.domain"))) |
33
56571d34d754
safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
31
diff
changeset
|
279 |
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
|
280 |
} |
19
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 |
return msg; |
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 KICK: |
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"))) { |
48
34094173351c
message.email renamed to message.domain
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
45
diff
changeset
|
287 |
if (strstr (message->domain, db_lookup (DATABASE_FILE, "mcbot.domain"))) |
33
56571d34d754
safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
31
diff
changeset
|
288 |
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
|
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 BAN: |
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"))) { |
48
34094173351c
message.email renamed to message.domain
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
45
diff
changeset
|
296 |
if (strstr (message->domain, db_lookup (DATABASE_FILE, "mcbot.domain"))) |
33
56571d34d754
safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
31
diff
changeset
|
297 |
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
|
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 UNBAN: |
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"))) { |
48
34094173351c
message.email renamed to message.domain
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
45
diff
changeset
|
305 |
if (strstr (message->domain, db_lookup (DATABASE_FILE, "mcbot.domain"))) |
33
56571d34d754
safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
31
diff
changeset
|
306 |
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
|
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 KICKBAN: |
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"))) { |
48
34094173351c
message.email renamed to message.domain
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
45
diff
changeset
|
314 |
if (strstr (message->domain, db_lookup (DATABASE_FILE, "mcbot.domain"))) |
33
56571d34d754
safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
31
diff
changeset
|
315 |
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
|
316 |
message->channel, token); |
138537d81dd1
Admin Commands secured
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
19
diff
changeset
|
317 |
} |
19
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
318 |
} |
66114d944208
op, deop, ban, unban, kick, kickban implemented
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
18
diff
changeset
|
319 |
return msg; |
23
1cd79bb84e9c
ChangeLog for mcbot-0.96
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
22
diff
changeset
|
320 |
|
1cd79bb84e9c
ChangeLog for mcbot-0.96
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
22
diff
changeset
|
321 |
case HELLO: |
33
56571d34d754
safe buffers, a memory leak and cleanups
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
31
diff
changeset
|
322 |
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
|
323 |
message->user); |
23
1cd79bb84e9c
ChangeLog for mcbot-0.96
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
22
diff
changeset
|
324 |
return msg; |
40
5b7e8dba46a0
Topic command added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
39
diff
changeset
|
325 |
|
5b7e8dba46a0
Topic command added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
39
diff
changeset
|
326 |
case TOPIC: |
5b7e8dba46a0
Topic command added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
39
diff
changeset
|
327 |
if ((token = strtok (NULL, "\r\n")) == NULL) |
5b7e8dba46a0
Topic command added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
39
diff
changeset
|
328 |
return NULL; |
5b7e8dba46a0
Topic command added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
39
diff
changeset
|
329 |
|
5b7e8dba46a0
Topic command added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
39
diff
changeset
|
330 |
snprintf (msg, sizeof (msg), "TOPIC %s :%s\r\n", message->channel, token); |
5b7e8dba46a0
Topic command added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
39
diff
changeset
|
331 |
return msg; |
0 | 332 |
} |
333 |
} |
|
38
c2f62d1b8d76
enumerated types for parse.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
33
diff
changeset
|
334 |
map++; |
0 | 335 |
} |
336 |
||
337 |
return NULL; |
|
338 |
} |