started on command/event handling

This commit is contained in:
Aaron Blakely 2015-03-24 12:48:11 -05:00
parent 3c586141c2
commit 74f0b04ad0
7 changed files with 59 additions and 6 deletions

View File

@ -12,6 +12,7 @@ main:
$(CC) $(CFLAGS) $(SRC)/main.c -o $(OBJ)/main.o $(CC) $(CFLAGS) $(SRC)/main.c -o $(OBJ)/main.o
$(CC) $(CFLAGS) $(SRC)/irc.c -o $(OBJ)/irc.o $(CC) $(CFLAGS) $(SRC)/irc.c -o $(OBJ)/irc.o
$(CC) $(CFLAGS) $(SRC)/util.c -o $(OBJ)/util.o $(CC) $(CFLAGS) $(SRC)/util.c -o $(OBJ)/util.o
$(CC) $(CFLAGS) $(SRC)/events.c -o $(OBJ)/events.o
$(CC) -o $(EXEC) $(OBJECTS) $(BINFLAGS) $(CC) -o $(EXEC) $(OBJECTS) $(BINFLAGS)
@echo "All Done!" @echo "All Done!"

9
lib/events.h Normal file
View File

@ -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

View File

@ -14,6 +14,7 @@ struct irc_conn
FILE *srv_fd; FILE *srv_fd;
char nick[32]; char nick[32];
char *admin;
char *host; char *host;
char *port; char *port;
char *real_name; char *real_name;
@ -26,6 +27,7 @@ struct irc_conn
void irc_connect(struct irc_conn *bot); void irc_connect(struct irc_conn *bot);
void irc_auth(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_raw(struct irc_conn *bot, char *fmt, ...);
void irc_parse_raw(struct irc_conn *bot, char *raw); void irc_parse_raw(struct irc_conn *bot, char *raw);

28
src/events.c Normal file
View File

@ -0,0 +1,28 @@
#include "irc.h"
#include "util.h"
#include <stdio.h>
#include <string.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)
{
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.");
}
}
}

View File

@ -7,6 +7,7 @@
#include "irc.h" #include "irc.h"
#include "util.h" #include "util.h"
#include "events.h"
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
@ -61,6 +62,11 @@ void irc_auth(struct irc_conn *bot)
fflush(bot->srv_fd); 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, ...) void irc_raw(struct irc_conn *bot, char *fmt, ...)
{ {
va_list ap; va_list ap;
@ -108,10 +114,13 @@ void irc_parse_raw(struct irc_conn *bot, char *raw)
if (!strcmp("PRIVMSG", raw)) if (!strcmp("PRIVMSG", raw))
{ {
//handle_privmsg(user, par, text) if (strcmp(user, bot->nick))
if (!strcmp("Dark_Aaron", user))
{ {
irc_raw(bot, "JOIN #bots"); handle_self_privmsg(bot, user, text);
}
else
{
handle_chan_privmsg(bot, user, par, text);
} }
} }
else if (!strcmp("PING", raw)) else if (!strcmp("PING", raw))

View File

@ -43,6 +43,9 @@ int main()
if (config_lookup_string(cf, "server.port", &base)) if (config_lookup_string(cf, "server.port", &base))
bot.port = (char *)base; bot.port = (char *)base;
if (config_lookup_string(cf, "bot.admin", &base))
bot.admin = (char *)base;
// Connect to the server // Connect to the server
printf("Connecting to %s...\n", bot.host); printf("Connecting to %s...\n", bot.host);
irc_connect(&bot); irc_connect(&bot);

View File

@ -4,6 +4,7 @@ bot:
{ {
nick = "xbot"; nick = "xbot";
user = "xbot"; user = "xbot";
admin = "Dark_Aaron";
}; };
server: server: