diff --git a/Makefile b/Makefile index da0767b..b3364f8 100644 --- a/Makefile +++ b/Makefile @@ -9,9 +9,10 @@ EXEC=xbot main: @rm -rf build @mkdir build - $(CC) $(CFLAGS) $(SRC)/main.c -o $(OBJ)/main.o - $(CC) $(CFLAGS) $(SRC)/irc.c -o $(OBJ)/irc.o - $(CC) $(CFLAGS) $(SRC)/util.c -o $(OBJ)/util.o + $(CC) $(CFLAGS) $(SRC)/main.c -o $(OBJ)/main.o + $(CC) $(CFLAGS) $(SRC)/irc.c -o $(OBJ)/irc.o + $(CC) $(CFLAGS) $(SRC)/util.c -o $(OBJ)/util.o + $(CC) $(CFLAGS) $(SRC)/events.c -o $(OBJ)/events.o $(CC) -o $(EXEC) $(OBJECTS) $(BINFLAGS) @echo "All Done!" diff --git a/lib/events.h b/lib/events.h new file mode 100644 index 0000000..e1b7a78 --- /dev/null +++ b/lib/events.h @@ -0,0 +1,9 @@ +#ifndef EVENTS_H +#define EVENTS_H + +#include "irc.h" + +void handle_chan_privmsg(struct irc_conn *bot, char *user, char *chan, char *text); +void handle_self_privmsg(struct irc_conn *bot, char *user, char *text); + +#endif \ No newline at end of file diff --git a/lib/irc.h b/lib/irc.h index b9b1151..aff1749 100644 --- a/lib/irc.h +++ b/lib/irc.h @@ -14,6 +14,7 @@ struct irc_conn FILE *srv_fd; char nick[32]; + char *admin; char *host; char *port; char *real_name; @@ -26,6 +27,7 @@ struct irc_conn void irc_connect(struct irc_conn *bot); void irc_auth(struct irc_conn *bot); +void irc_notice(struct irc_conn *bot, char *to, char *msg); void irc_raw(struct irc_conn *bot, char *fmt, ...); void irc_parse_raw(struct irc_conn *bot, char *raw); diff --git a/src/events.c b/src/events.c new file mode 100644 index 0000000..9e83453 --- /dev/null +++ b/src/events.c @@ -0,0 +1,28 @@ +#include "irc.h" +#include "util.h" +#include +#include + +void handle_chan_privmsg(struct irc_conn *bot, char *user, char *chan, char *text) +{ + +} + +void handle_self_privmsg(struct irc_conn *bot, char *user, char *text) +{ + char *cmd, *arg; + cmd = text; + arg = skip(cmd, ' '); + + if (!strcmp("JOIN", cmd)) + { + if (strcmp(bot->admin, user)) + { + irc_raw(bot, "JOIN %s", arg); + } + else + { + irc_notice(bot, user, "You are unauthorized to use this command."); + } + } +} \ No newline at end of file diff --git a/src/irc.c b/src/irc.c index 74eea2c..6a202ab 100644 --- a/src/irc.c +++ b/src/irc.c @@ -7,6 +7,7 @@ #include "irc.h" #include "util.h" +#include "events.h" #include #include #include @@ -61,6 +62,11 @@ void irc_auth(struct irc_conn *bot) fflush(bot->srv_fd); } +void irc_notice(struct irc_conn *bot, char *to, char *msg) +{ + irc_raw(bot, "NOTICE %s :%s", to, msg); +} + void irc_raw(struct irc_conn *bot, char *fmt, ...) { va_list ap; @@ -108,10 +114,13 @@ void irc_parse_raw(struct irc_conn *bot, char *raw) if (!strcmp("PRIVMSG", raw)) { - //handle_privmsg(user, par, text) - if (!strcmp("Dark_Aaron", user)) + if (strcmp(user, bot->nick)) { - irc_raw(bot, "JOIN #bots"); + handle_self_privmsg(bot, user, text); + } + else + { + handle_chan_privmsg(bot, user, par, text); } } else if (!strcmp("PING", raw)) diff --git a/src/main.c b/src/main.c index f82b0c2..34ec8f8 100644 --- a/src/main.c +++ b/src/main.c @@ -43,6 +43,9 @@ int main() if (config_lookup_string(cf, "server.port", &base)) bot.port = (char *)base; + if (config_lookup_string(cf, "bot.admin", &base)) + bot.admin = (char *)base; + // Connect to the server printf("Connecting to %s...\n", bot.host); irc_connect(&bot); diff --git a/xbot.cfg b/xbot.cfg index ed640a8..3b080b3 100644 --- a/xbot.cfg +++ b/xbot.cfg @@ -4,6 +4,7 @@ bot: { nick = "xbot"; user = "xbot"; + admin = "Dark_Aaron"; }; server: