From c07a9207ca007ef30f2db036eac57eec7773a6fb Mon Sep 17 00:00:00 2001 From: stskeeps Date: Sat, 26 Aug 2000 19:05:09 +0000 Subject: [PATCH] +- Added IRCd bot (raw commands) and the IRC bot, webtv.c --- Changes | 3 +- src/s_misc.c | 19 ++++ src/webtv.c | 261 ++++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 277 insertions(+), 6 deletions(-) diff --git a/Changes b/Changes index 119dbb925..5dbdf1b90 100644 --- a/Changes +++ b/Changes @@ -589,4 +589,5 @@ and FloodOpt->nmsg to an unsigned short - Removed SUMMON totally - Fixed another SJOIN problem, but not the exact one i was looking for -- Added IRCd bot (raw commands) and the IRC bot, webtv.c \ No newline at end of file +- Added IRCd bot (raw commands) and the IRC bot, webtv.c + - Added WHOIS command (working) to IRCbot \ No newline at end of file diff --git a/src/s_misc.c b/src/s_misc.c index 0c804d5ec..4c7072a07 100644 --- a/src/s_misc.c +++ b/src/s_misc.c @@ -118,6 +118,25 @@ char *date(clock) return buf; } + +char *convert_time (time_t ltime) +{ + unsigned long days = 0,hours = 0,minutes = 0,seconds = 0; + static char buffer[40]; + + + *buffer = '\0'; + seconds = ltime % 60; + ltime = (ltime - seconds) / 60; + minutes = ltime%60; + ltime = (ltime - minutes) / 60; + hours = ltime % 24; + days = (ltime - hours) / 24; + sprintf(buffer, "%ludays %luhours %lumonths %lusecs", days, hours, minutes, seconds); + return(*buffer ? buffer : ""); +} + + /* * Fixes a string so that the first white space found becomes an end of * string marker (`\-`). returns the 'fixed' string or "*" if the string diff --git a/src/webtv.c b/src/webtv.c index 95d9cbdee..7d0c1b814 100644 --- a/src/webtv.c +++ b/src/webtv.c @@ -2,9 +2,6 @@ * Unreal Internet Relay Chat Daemon, src/webtv.c * (C) Carsten V. Munk (Stskeeps ) 2000 * - * See file AUTHORS in IRC package for additional names of - * the programmers. - * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 1, or (at your option) @@ -85,7 +82,7 @@ void webtv_parse(aClient *sptr, char *string) break; if (!message->command || !message->func) - { + { sendto_one(sptr, ":IRC %s %s :Sorry, \"%s\" is an unknown command to me", MSG_PRIVATE, sptr->name, cmd); return; @@ -132,5 +129,259 @@ void webtv_parse(aClient *sptr, char *string) int w_whois(aClient *cptr, aClient *sptr, int parc, char *parv[]) { - sendto_one(sptr, ":IRC %s %s :Mooooooooo!", MSG_PRIVATE, sptr->name); + static anUser UnknownUser = { + NULL, /* nextu */ + NULL, /* channel */ + NULL, /* invited */ + NULL, /* silence */ + NULL, /* away */ + 0, /* last */ + 0, /* servicestamp */ + 1, /* refcount */ + 0, /* joined */ + "", /* username */ + "", /* host */ + "" /* server */ + }; + Link *lp; + anUser *user; + aClient *acptr, *a2cptr; + aChannel *chptr; + char *nick, *tmp, *name, *temp; + char *p = NULL; + char buf[512]; + int found, len, mlen, t; + + if (parc < 2) + { + sendto_one(sptr, ":IRC %s %s :Syntax error, correct is WHOIS ", + MSG_PRIVATE, sptr->name); + return 0; + } + + for (tmp = parv[1]; (nick = strtoken(&p, tmp, ",")); tmp = NULL) + { + int invis, showsecret, showperson, member, wilds; + + found = 0; + (void)collapse(nick); + wilds = (index(nick, '?') || index(nick, '*')); + if (wilds) + continue; + + for (acptr = client; (acptr = next_client(acptr, nick)); + acptr = acptr->next) + { + if (IsServer(acptr)) + continue; + /* + * I'm always last :-) and acptr->next == NULL!! + */ + if (IsMe(acptr)) + break; + /* + * 'Rules' established for sending a WHOIS reply: + * + * - only allow a remote client to get replies for + * local clients if wildcards are being used; + * + * - if wildcards are being used dont send a reply if + * the querier isnt any common channels and the + * client in question is invisible and wildcards are + * in use (allow exact matches only); + * + * - only send replies about common or public channels + * the target user(s) are on; + */ + if (!MyConnect(sptr) && !MyConnect(acptr) && wilds) + continue; + user = acptr->user ? acptr->user : &UnknownUser; + name = (!*acptr->name) ? "?" : acptr->name; + + invis = acptr != sptr && IsInvisible(acptr); + member = (user->channel) ? 1 : 0; + showperson = (wilds && !invis && !member) || !wilds; + + for (lp = user->channel; lp; lp = lp->next) + { + chptr = lp->value.chptr; + member = IsMember(sptr, chptr); + if (invis && !member) + continue; + if (member || (!invis && PubChannel(chptr))) + { + showperson = 1; + break; + } + if (!invis && HiddenChannel(chptr) && + !SecretChannel(chptr)) + showperson = 1; + else if (IsAnOper(sptr) && SecretChannel(chptr)) { + showperson = 1; + showsecret = 1; + } + } + if (!showperson) + continue; + a2cptr = find_server_quick(user->server); + + if (!IsPerson(acptr)) + continue; + sendto_one(sptr, ":IRC PRIVMSG %s :WHOIS information for %s", sptr->name, acptr->name); + if (IsWhois(acptr)) + { + sendto_one(acptr, + ":%s NOTICE %s :*** %s (%s@%s) did a /whois on you.", + me.name, acptr->name, sptr->name, + sptr->user->username, + IsHidden(acptr) ? sptr->user-> + virthost : sptr->user->realhost); + } + + sendto_one(sptr, ":IRC PRIVMSG %s :%s is %s@%s * %s", sptr->name, + name, user->username, + IsHidden(acptr) ? user->virthost : user->realhost, + acptr->info); + + if (IsEyes(sptr)) + { + /* send the target user's modes */ + sendto_one(sptr, ":IRC PRIVMSG %s :%s uses modes %s", + sptr->name, acptr->name, get_mode_str(acptr)); + } + if (IsAnOper(sptr) && IsHidden(acptr) || + acptr == sptr && IsHidden(sptr)) + { + sendto_one(sptr, ":IRC PRIVMSG %s :%s is connecting from %s", + sptr->name, acptr->name, + acptr->user->realhost); + } + if (IsARegNick(acptr)) + sendto_one(sptr, ":IRC PRIVMSG %s :%s is a registered nick", + sptr->name, name); + found = 1; + mlen = strlen(me.name) + strlen(sptr->name) + 6 + + strlen(name); + for (len = 0, *buf = '\0', lp = user->channel; lp; + lp = lp->next) + { + chptr = lp->value.chptr; + if (IsAnOper(sptr) || ShowChannel(sptr, chptr) || (acptr == sptr)) + { + if (len + strlen(chptr->chname) + > (size_t)BUFSIZE - 4 - mlen) + { + sendto_one(sptr, + ":IRC PRIVMSG %s :%s is on %s", + sptr->name, name, buf); + *buf = '\0'; + len = 0; + } + if (!(acptr == sptr) && IsAnOper(sptr) + && (showsecret == 1) && SecretChannel(chptr)) + *(buf + len++) = '~'; + if (is_chanowner(acptr, chptr)) + *(buf + len++) = '*'; + else if (is_chanprot(acptr, chptr)) + *(buf + len++) = '^'; + else if (is_chan_op(acptr, chptr)) + *(buf + len++) = '@'; + else if (is_half_op(acptr, chptr)) + *(buf + len++) = '%'; + else if (has_voice(acptr, chptr)) + *(buf + len++) = '+'; + if (len) + *(buf + len) = '\0'; + (void)strcpy(buf + len, chptr->chname); + len += strlen(chptr->chname); + (void)strcat(buf + len, " "); + len++; + } + } + + if (buf[0] != '\0' && !IsULine(acptr, acptr) && (!IsHiding(acptr) || + IsNetAdmin(sptr) || IsTechAdmin(sptr) || sptr == acptr)) + sendto_one(sptr, + ":IRC PRIVMSG %s :%s is on %s", + sptr->name, name, buf); + + sendto_one(sptr, ":IRC PRIVMSG %s :%s is on irc via %s %s", + sptr->name, name, user->server, + a2cptr ? a2cptr->info : "*Not On This Net*"); + + if (user->away) + sendto_one(sptr, ":IRC PRIVMSG %s :%s is away: %s", + sptr->name, name, user->away); + /* makesure they aren't +H (we'll also check + before we display a helpop or IRCD Coder msg) + -- codemastr */ + if ((IsAnOper(acptr) || IsServices(acptr)) + && (!IsHideOper(acptr) || sptr == acptr || IsAnOper(sptr))) + { + buf[0] = '\0'; + if (IsNetAdmin(acptr)) + strcat(buf, "a Network Administrator"); + else if (IsTechAdmin(acptr)) + strcat(buf, + "a Technical Administrator"); + else if (IsSAdmin(acptr)) + strcat(buf, "a Services Operator"); + else if (IsAdmin(acptr) && !IsCoAdmin(acptr)) + strcat(buf, "a Server Administrator"); + else if (IsCoAdmin(acptr)) + strcat(buf, "a Co Administrator"); + else if (IsServices(acptr)) + strcat(buf, "a Network Service"); + else if (IsOper(acptr)) + strcat(buf, "an IRC Operator"); + + else + strcat(buf, "a Local IRC Operator"); + if (buf[0]) + sendto_one(sptr, + ":IRC PRIVMSG %s :%s is an %s on %s", + sptr->name, name, buf, ircnetwork); + } + + if (IsHelpOp(acptr) && (!IsHideOper(acptr) || sptr == acptr || IsAnOper(sptr))) + if (!acptr->user->away) + sendto_one(sptr, ":IRC PRIVMSG %s :%s is available for help.", + sptr->name, acptr->name); + + if (acptr->umodes & UMODE_BOT) + { + sendto_one(sptr, ":IRC PRIVMSG %s :%s is an Bot on %s", + sptr->name, name, ircnetwork); + } + if (acptr->umodes & UMODE_CODER && (!IsHideOper(acptr) || sptr == acptr || IsAnOper(sptr))) + { + sendto_one(sptr, ":IRC PRIVMSG %s :%s is a Coder on %s", + sptr->name, acptr->name, ircnetwork); + } + if (acptr->user->swhois) + { + if (*acptr->user->swhois != '\0') + sendto_one(sptr, ":IRC PRIVMSG %s :%s %s", + sptr->name, acptr->name, + acptr->user->swhois); + } + + if (acptr->user && MyConnect(acptr)) + sendto_one(sptr, ":IRC PRIVMSG %s :%s has been idle for %s signed on at %s", + sptr->name, acptr->name, + (char *)convert_time(TStime() - user->last), + date(acptr->firsttime)); + } + if (!found) + { + sendto_one(sptr, ":IRC PRIVMSG %s :%s - No such nick", + sptr->name, nick); + } + if (p) + p[-1] = ','; + } + sendto_one(sptr, ":IRC PRIVMSG %s :End of whois information for %s", + sptr->name, parv[1]); + + return 0; } \ No newline at end of file