From 71090d244b5b366ba165d9cb94fcbb0b9985dd06 Mon Sep 17 00:00:00 2001 From: Aaron Blakely Date: Fri, 8 Mar 2024 04:14:06 -0600 Subject: [PATCH] added command line arguments --- mods/lua/lua.c | 18 ++++++++++++++++-- src/irc.c | 5 ++++- src/main.c | 44 +++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 61 insertions(+), 6 deletions(-) diff --git a/mods/lua/lua.c b/mods/lua/lua.c index f1972e1..c1924a4 100755 --- a/mods/lua/lua.c +++ b/mods/lua/lua.c @@ -2,6 +2,7 @@ #include "irc.h" #include "events.h" #include "module.h" +#include "channel.h" #include "timers.h" #include #include @@ -120,6 +121,9 @@ void lua_eval(struct irc_conn *bot, char *user, char *host, char *chan, const ch { int res; + if (!is_botadmin(user)) + return; + block = 1; printf("lua eval called with %s\n", text); if (strstr(text, "!lua") != NULL) @@ -152,7 +156,12 @@ void lua_load_script(struct irc_conn *bot, char *user, char *host, char *chan, c { char *name; char *script; - char *buf = (char *)malloc(sizeof(char *) * 500); + char *buf; + + if (!is_botadmin(user)) + return; + + buf = (char *)malloc(sizeof(char *) * 500); if (strstr(text, "!load") != NULL) { @@ -267,8 +276,13 @@ void lua_unload_script(struct irc_conn *bot, char *user, char *host, char *chan, int i; char *name; char *script; - char *buf = (char *)malloc(sizeof(char *) * 500); + char *buf; + if (!is_botadmin(user)) + return; + + buf = (char *)malloc(sizeof(char *) * 500); + if (strstr(text, "!unload") != NULL) { text = skip((char *)text, ' '); diff --git a/src/irc.c b/src/irc.c index 03ea1ff..2680b25 100755 --- a/src/irc.c +++ b/src/irc.c @@ -1,6 +1,9 @@ /* * irc.c: IRC connection and parser - * xbot: Just another IRC bot + * xbot: an advanced IRC bot for *nix and Windows + * + * This file contains the functions for connecting to an IRC server, sending + * and receiving data, and parsing the data received from the server. * * Written by Aaron Blakely **/ diff --git a/src/main.c b/src/main.c index 4cce213..009bcf9 100755 --- a/src/main.c +++ b/src/main.c @@ -4,6 +4,8 @@ * Written by Aaron Blakely **/ +#define VERSION "0.1.0" + #include #include #include @@ -29,14 +31,14 @@ static time_t trespond; -int main() +int main(int argc, char **argv) { int n; fd_set rd; struct irc_conn bot; struct timeval tv; struct timeval last_ping; - + char conf[1024]; char *p; int bytesRecv; @@ -59,8 +61,44 @@ int main() init_events(); init_timers(); init_mods(); + + strlcpy(conf, "xbot.cfg", sizeof conf); + + if (argc > 1) + { + if (argc == 2) + { + if (!strcmp(argv[1], "-v")) + { + printf("xbot version: %s\n", VERSION); + printf("Compiled on: %s %s\n\n", __DATE__, __TIME__); + printf("Written by Aaron Blakely \n"); + printf("Licensed under the MIT License\n"); + return 0; + } + else if (!strcmp(argv[1], "-h")) + { + printf("Usage: xbot [-v] [-h] [-c ]\n"); + return 0; + } + } + else if (argc == 3) + { + if (!strcmp(argv[1], "-c")) + { + free(bot.in); + free(bot.out); + + bot.in = calloc(INBUF_SIZE, sizeof(char)); + bot.out = calloc(OUTBUF_SIZE, sizeof(char)); + + strlcpy(conf, argv[2], sizeof conf); + } + } + } + // Read the config - bot = read_config(bot, "xbot.cfg"); + bot = read_config(bot, conf); // check if the db exists, if not, create it #ifdef _WIN32