#include "services.h" #include #include "stickman.h" #include "config.h" #include "server.h" #include "module.h" #include "hooks.h" #include "privmsg.h" static const char rcsid[] = "$Id: stickman.c,v 1.5 2000/06/18 06:25:45 mhh Exp $"; extern struct sfuncs_t *sfuncs; static struct stickman_t { char nick[NICK_SIZE]; char user[USER_SIZE]; char host[HOST_SIZE]; char name[NAME_SIZE]; char chans[BUF_SIZE]; } stickman; struct modinfo_t modinfo = { "STICKMAN", "\\o/", MOD_LOADER, MOD_INIT_POSTNETBURST, stick_init, stick_clean }; static struct configfile_t sconfig[] = { { "STICKNICK", &stickman.nick, NULL }, { "STICKUSER", &stickman.user, NULL }, { "STICKHOST", &stickman.host, NULL }, { "STICKNAME", &stickman.name, NULL }, { "STICKCHANS", &stickman.chans, NULL }, }; static void stick_init(void) { parsecfg(CONFIGFILE, sconfig, arraysize(sconfig)); add_normal_hook(stick_killed, HOOK_KILL, stickman.nick, "", 0); /* FIXME: hardcoded */ add_public_hook(stick_complete, NULL, "#anynet", "", 0); if (sfuncs) sfuncs->createuser(stickman.nick, stickman.user, stickman.host, stickman.name, "N"); } static void stick_clean(void) { del_normal_hook(HOOK_KILL, stickman.nick, ""); /* FIXME: hardcoded */ del_public_hook(NULL, "#anynet", ""); if (sfuncs) sfuncs->quit(stickman.nick, "module unloaded"); } static void stick_killed(struct userlist_ll *u, char *dest, char *content) { stick_clean(); stick_init(); } static void stick_complete(struct userlist_ll *u, struct chanlist_ll *c, char *content) { const char *stickloc, *pos; char line1[BUF_SIZE], line2[BUF_SIZE], spaces[BUF_SIZE]; int x, nd; struct userlist_ll *stickuser; stripcodes(content); /* shouldn't happen */ if (!sfuncs) return; /* abort if the line is too long (no wrapping) */ if (strlen(u->nick) + strlen(content) + 3 > 79) return; /* abort now if there's no \o/ man */ if ((stickloc = strstr(content, "\\o/")) == NULL) return; /* attempt to join the channel if we haven't already */ /* FIXME: hardcoded */ if ((stickuser = find_user_by_nick(stickman.nick)) != NULL) if (!onchan(stickuser, "#anynet")) sfuncs->join(stickman.nick, "#anynet"); pos = content; line1[0] = line2[0] = '\0'; /* calculate nick length difference and adjust appropriately */ nd = strlen(u->nick) - strlen(stickman.nick); if (nd < 0) { /* skip past the part we can't complete */ pos += -nd; if (stickloc < pos) { /* the \o/ we found was uncompletable, try again */ if ((stickloc = strstr(pos, "\\o/")) == NULL) return; /* no more, bail */ } } else { /* pad for the differences in nick length */ for (x = 0; x < nd; x++) spaces[x] = ' '; spaces[x] = '\0'; strcat(line1, spaces); strcat(line2, spaces); } for (; stickloc != NULL; stickloc = strstr(pos, "\\o/")) { /* generate spacing */ for (x = 0; x < stickloc - pos; x++) spaces[x] = ' '; spaces[x] = '\0'; strcat(line1, spaces); strcat(line2, spaces); strcat(line1, " | "); strcat(line2, "/ \\"); /* skip this one, we're done */ pos = stickloc + 3; } sfuncs->privmsg(stickman.nick, c->name, line1); sfuncs->privmsg(stickman.nick, c->name, line2); }