diff --git a/README.md b/README.md index c7efd4c..a76fa14 100755 --- a/README.md +++ b/README.md @@ -18,5 +18,6 @@ These are commands which allow the bot's admin to control it once it's connected * LOADMOD * UNLOADMOD +* MODLIST * JOIN diff --git a/lib/module.h b/lib/module.h index 7bc39ab..37e0825 100755 --- a/lib/module.h +++ b/lib/module.h @@ -9,12 +9,12 @@ #endif struct module { - char *name; - char *author; - char *version; - char *description; + char name[25]; + char author[50]; + char version[10]; + char description[256]; - char *fname; + char fname[256]; #ifdef _WIN32 HMODULE handle; @@ -35,5 +35,9 @@ struct mods { void init_mods(); void load_module(struct irc_conn *bot, char *where, char *stype, char *file); void unload_module(struct irc_conn *bot, char *where, char *file); +void list_modules(struct irc_conn *bot, char *where); +MY_API void register_module(char *name, char *author, char *version, char *description); +MY_API void unregister_module(char *name); +MY_API struct mods *get_mods(); #endif diff --git a/mods/autojoin/autojoin.c b/mods/autojoin/autojoin.c index 41b1e9a..994bc32 100755 --- a/mods/autojoin/autojoin.c +++ b/mods/autojoin/autojoin.c @@ -1,5 +1,6 @@ #define MY_DLL_EXPORTS 1 +#include "module.h" #include "irc.h" #include "events.h" #include @@ -46,10 +47,12 @@ MY_API void aj(struct irc_conn *bot, char *text) MY_API void mod_init() { + register_module("autojoin", "Aaron Blakely", "v0.2", "Autojoin module"); add_handler(IRC_CONNECTED, aj); } MY_API void mod_unload() { + unregister_module("autojoin"); del_handler(IRC_CONNECTED, aj); } diff --git a/mods/buildmod.bat b/mods/buildmod.bat index e326952..06b1e73 100755 --- a/mods/buildmod.bat +++ b/mods/buildmod.bat @@ -4,5 +4,5 @@ for %%F in ("%filename%") do ( set "basename=%%~nF" ) -cl /I..\lib /I..\include\libconfig-1.7.3\lib /LD /EHsc ..\include\xbot.lib ..\include\libconfig.lib %filename% -link /DLL /out:.\%basename%.dll %basename%.obj ..\include\xbot.lib ..\include\libconfig.lib +cl /I..\lib /I..\include\libconfig-1.7.3\lib /LD /EHsc ..\Debug\xbot.lib ..\include\libconfig.lib %filename% +link /DLL /out:.\%basename%.dll %basename%.obj ..\Debug\xbot.lib ..\include\libconfig.lib diff --git a/mods/hello/hello.c b/mods/hello/hello.c index f943fd8..dbbf4f9 100755 --- a/mods/hello/hello.c +++ b/mods/hello/hello.c @@ -31,12 +31,14 @@ MY_API void hello_join(struct irc_conn *bot, char *user, char *host, char *chan) MY_API void mod_init() { + register_module("hello", "Aaron Blakely", "v0.05", "Test module"); add_handler(PRIVMSG_CHAN, hello); add_handler(JOIN, hello_join); } MY_API void mod_unload() { + unregister_module("hello"); del_handler(PRIVMSG_CHAN, hello); del_handler(JOIN, hello_join); } diff --git a/mods/uptime/uptime.c b/mods/uptime/uptime.c index 2ee467b..f3f17c1 100755 --- a/mods/uptime/uptime.c +++ b/mods/uptime/uptime.c @@ -25,12 +25,14 @@ MY_API void up(struct irc_conn *bot, char *user, char *host, char *chan, char *t MY_API void mod_init() { + register_module("uptime", "Aaron Blakely", "v0.1", "Uptime module"); printf("installing up handler\n"); add_handler(PRIVMSG_CHAN, up); } MY_API void mod_unload() { + unregister_module("uptime"); printf("unloading up handler\n"); del_handler(PRIVMSG_CHAN, up); } diff --git a/src/events.c b/src/events.c index 03b9b70..e68e2ff 100755 --- a/src/events.c +++ b/src/events.c @@ -190,6 +190,19 @@ void fire_handler(struct irc_conn *bot, char *type, ...) irc_notice(bot, usr, "You are unauthorized to use this command."); } } + else if (!strcmp("MODLIST", cmd)) + { + if (!strcmp(bot->admin, usr)) + { + list_modules(bot, usr); + } + else + { + irc_notice(bot, usr, "You are unauthorized to use this command."); + } + } + + va_end(args); } for (i = 0; i < handlers_count; i++) diff --git a/src/module.c b/src/module.c index 61eccae..6e174e3 100755 --- a/src/module.c +++ b/src/module.c @@ -24,7 +24,7 @@ void init_mods() void load_module(struct irc_conn *bot, char *where, char *stype, char *file) { char *error = (char *)malloc(sizeof(char *)*1024); - mods->modules[mods->count].fname = file; + strlcpy(mods->modules[mods->count].fname, file, 256); #ifdef _WIN32 mods->modules[mods->count].handle = LoadLibrary(file); @@ -236,7 +236,65 @@ void unload_module(struct irc_conn *bot, char *where, char *file) printf("Module '%s' unloaded.\n", file); } + while (i < mods->count) + { + mods->modules[i] = mods->modules[i+1]; + i++; + } + return; } } } + +void list_modules(struct irc_conn *bot, char *where) +{ + int i; + char *msg = malloc(512); + char *tmp = malloc(512); + + for (i = 0; i < mods->count; i++) + { + sprintf(tmp, "%s (%s) by %s - %s", mods->modules[i].name, mods->modules[i].version, mods->modules[i].author, mods->modules[i].description); + irc_notice(bot, where, tmp); + } + + free(msg); + free(tmp); +} + +MY_API void register_module(char *name, char *author, char *version, char *description) +{ + if (mods->count >= 512) + { + eprint("Error: Too many modules loaded.\n"); + return; + } + + strlcpy(mods->modules[mods->count].name, name, 25); + strlcpy(mods->modules[mods->count].author, author, 50); + strlcpy(mods->modules[mods->count].version, version, 10); + strlcpy(mods->modules[mods->count].description, description, 256); +} + +MY_API void unregister_module(char *name) +{ + int i; + for (i = 0; i < mods->count; i++) + { + if (strcmp(mods->modules[i].fname, name) == 0) + { + while (i < mods->count) + { + mods->modules[i] = mods->modules[i+1]; + i++; + } + return; + } + } +} + +MY_API struct mods *get_mods() +{ + return mods; +}