messages.c

Go to the documentation of this file.
00001 /* Definitions of IRC message functions and list of messages.
00002  *
00003  * (C) 2003-2007 Anope Team
00004  * Contact us at info@anope.org
00005  *
00006  * Please read COPYING and README for further details.
00007  *
00008  * Based on the original code of Epona by Lara.
00009  * Based on the original code of Services by Andy Church.
00010  *
00011  * $Id: messages.c 1265 2007-08-26 15:33:06Z geniusdex $
00012  *
00013  */
00014 
00015 #include "services.h"
00016 #include "messages.h"
00017 #include "language.h"
00018 
00019 int servernum;
00020 
00021 /*************************************************************************/
00022 
00023 int m_nickcoll(char *user)
00024 {
00025     if (!skeleton && !readonly)
00026         introduce_user(user);
00027     return MOD_CONT;
00028 }
00029 
00030 /*************************************************************************/
00031 
00032 int m_away(char *source, char *msg)
00033 {
00034     User *u;
00035 
00036     u = finduser(source);
00037 
00038     if (u && msg == 0)          /* un-away */
00039         check_memos(u);
00040     return MOD_CONT;
00041 }
00042 
00043 /*************************************************************************/
00044 
00045 int m_kill(char *nick, char *msg)
00046 {
00047     BotInfo *bi;
00048 
00049     /* Recover if someone kills us. */
00050     /* use nickIsServices() to reduce the number of lines of code  - TSL */
00051     if (nickIsServices(nick, 0)) {
00052         if (!readonly && !skeleton)
00053             introduce_user(nick);
00054     } else if (s_BotServ && (bi = findbot(nick))) {
00055         if (!readonly && !skeleton) {
00056             introduce_user(nick);
00057             bot_rejoin_all(bi);
00058         }
00059     } else {
00060         do_kill(nick, msg);
00061     }
00062     return MOD_CONT;
00063 }
00064 
00065 /*************************************************************************/
00066 
00067 int m_time(char *source, int ac, char **av)
00068 {
00069     time_t t;
00070     struct tm *tm;
00071     char buf[64];
00072 
00073     if (!source) {
00074         return MOD_CONT;
00075     }
00076 
00077     time(&t);
00078     tm = localtime(&t);
00079     strftime(buf, sizeof(buf), "%a %b %d %H:%M:%S %Y %Z", tm);
00080     anope_cmd_391(source, buf);
00081     return MOD_CONT;
00082 }
00083 
00084 /*************************************************************************/
00085 
00086 int m_motd(char *source)
00087 {
00088     FILE *f;
00089     char buf[BUFSIZE];
00090 
00091     if (!source) {
00092         return MOD_CONT;
00093     }
00094 
00095     f = fopen(MOTDFilename, "r");
00096     if (f) {
00097         anope_cmd_375(source);
00098         while (fgets(buf, sizeof(buf), f)) {
00099             buf[strlen(buf) - 1] = 0;
00100             anope_cmd_372(source, buf);
00101         }
00102         fclose(f);
00103         anope_cmd_376(source);
00104     } else {
00105         anope_cmd_372_error(source);
00106     }
00107     return MOD_CONT;
00108 }
00109 
00110 /*************************************************************************/
00111 
00112 int m_privmsg(char *source, char *receiver, char *msg)
00113 {
00114     char *s;
00115     time_t starttime, stoptime; /* When processing started and finished */
00116 
00117     BotInfo *bi;
00118     ChannelInfo *ci;
00119     User *u;
00120 
00121     if (!source || !*source || !*receiver || !receiver || !msg) {
00122         return MOD_CONT;
00123     }
00124 
00125     u = finduser(source);
00126 
00127     if (!u) {
00128         alog("%s: user record for %s not found", msg, source);
00129         anope_cmd_notice(receiver, source,
00130                          getstring(NULL, USER_RECORD_NOT_FOUND));
00131         return MOD_CONT;
00132     }
00133 
00134     if (*receiver == '#') {
00135         if (s_BotServ && (ci = cs_findchan(receiver))) {
00136             /* Some paranoia checks */
00137             if (!(ci->flags & CI_VERBOTEN) && ci->c && ci->bi) {
00138                 botchanmsgs(u, ci, msg);
00139             }
00140         }
00141     } else {
00142         /* Check if we should ignore.  Operators always get through. */
00143         if (allow_ignore && !is_oper(u)) {
00144             IgnoreData *ign = get_ignore(source);
00145             if (ign && ign->time > time(NULL)) {
00146                 alog("Ignored message from %s: \"%s\"", source, inbuf);
00147                 return MOD_CONT;
00148             }
00149         }
00150 
00151         /* If a server is specified (nick@server format), make sure it matches
00152          * us, and strip it off. */
00153         s = strchr(receiver, '@');
00154         if (s) {
00155             *s++ = 0;
00156             if (stricmp(s, ServerName) != 0)
00157                 return MOD_CONT;
00158         } else if (UseStrictPrivMsg) {
00159             if (debug) {
00160                 alog("Ignored PRIVMSG without @ from %s", source);
00161             }
00162             notice_lang(receiver, u, INVALID_TARGET, receiver, receiver,
00163                         ServerName, receiver);
00164             return MOD_CONT;
00165         }
00166 
00167         starttime = time(NULL);
00168 
00169         if ((stricmp(receiver, s_OperServ) == 0)
00170             || (s_OperServAlias
00171                 && (stricmp(receiver, s_OperServAlias) == 0))) {
00172             if (!is_oper(u) && OSOpersOnly) {
00173                 notice_lang(s_OperServ, u, ACCESS_DENIED);
00174                 if (WallBadOS)
00175                     anope_cmd_global(s_OperServ,
00176                                      "Denied access to %s from %s!%s@%s (non-oper)",
00177                                      s_OperServ, u->nick, u->username,
00178                                      u->host);
00179             } else {
00180                 operserv(u, msg);
00181             }
00182         } else if ((stricmp(receiver, s_NickServ) == 0)
00183                    || (s_NickServAlias
00184                        && (stricmp(receiver, s_NickServAlias) == 0))) {
00185             nickserv(u, msg);
00186         } else if ((stricmp(receiver, s_ChanServ) == 0)
00187                    || (s_ChanServAlias
00188                        && (stricmp(receiver, s_ChanServAlias) == 0))) {
00189             if (!is_oper(u) && CSOpersOnly)
00190                 notice_lang(s_ChanServ, u, ACCESS_DENIED);
00191             else
00192                 chanserv(u, msg);
00193         } else if ((stricmp(receiver, s_MemoServ) == 0)
00194                    || (s_MemoServAlias
00195                        && (stricmp(receiver, s_MemoServAlias) == 0))) {
00196             memoserv(u, msg);
00197         } else if (s_HostServ && ((stricmp(receiver, s_HostServ) == 0)
00198                                   || (s_HostServAlias
00199                                       &&
00200                                       (stricmp(receiver, s_HostServAlias)
00201                                        == 0)))) {
00202             hostserv(u, msg);
00203         } else if (s_HelpServ && ((stricmp(receiver, s_HelpServ) == 0)
00204                                   || (s_HelpServAlias
00205                                       &&
00206                                       (stricmp(receiver, s_HelpServAlias)
00207                                        == 0)))) {
00208             helpserv(u, msg);
00209         } else if (s_BotServ && ((stricmp(receiver, s_BotServ) == 0)
00210                                  || (s_BotServAlias
00211                                      && (stricmp(receiver, s_BotServAlias)
00212                                          == 0)))) {
00213             botserv(u, msg);
00214         } else if (s_BotServ && (bi = findbot(receiver))) {
00215             botmsgs(u, bi, msg);
00216         }
00217 
00218         /* Add to ignore list if the command took a significant amount of time. */
00219         if (allow_ignore) {
00220             stoptime = time(NULL);
00221             if (stoptime > starttime && *source && !strchr(source, '.'))
00222                 add_ignore(source, stoptime - starttime);
00223         }
00224     }
00225     return MOD_CONT;
00226 }
00227 
00228 /*************************************************************************/
00229 
00230 int m_stats(char *source, int ac, char **av)
00231 {
00232     int i;
00233     User *u;
00234     NickCore *nc;
00235 
00236     if (ac < 1)
00237         return MOD_CONT;
00238 
00239     switch (*av[0]) {
00240     case 'l':
00241         u = finduser(source);
00242 
00243         if (u && is_oper(u)) {
00244 
00245             if (servernum == 1) {
00246                 anope_cmd_211
00247                     ("%s Server SendBuf SentBytes SentMsgs RecvBuf "
00248                      "RecvBytes RecvMsgs ConnTime", source);
00249                 anope_cmd_211("%s %s %d %d %d %d %d %d %ld", source,
00250                               RemoteServer, write_buffer_len(),
00251                               total_written, -1, read_buffer_len(),
00252                               total_read, -1, time(NULL) - start_time);
00253             } else if (servernum == 2) {
00254                 anope_cmd_211
00255                     ("%s Server SendBuf SentBytes SentMsgs RecvBuf "
00256                      "RecvBytes RecvMsgs ConnTime", source);
00257                 anope_cmd_211("%s %s %d %d %d %d %d %d %ld", source,
00258                               RemoteServer2, write_buffer_len(),
00259                               total_written, -1, read_buffer_len(),
00260                               total_read, -1, time(NULL) - start_time);
00261             } else if (servernum == 3) {
00262                 anope_cmd_211
00263                     ("%s Server SendBuf SentBytes SentMsgs RecvBuf "
00264                      "RecvBytes RecvMsgs ConnTime", source);
00265                 anope_cmd_211("%s %s %d %d %d %d %d %d %ld", source,
00266                               RemoteServer3, write_buffer_len(),
00267                               total_written, -1, read_buffer_len(),
00268                               total_read, -1, time(NULL) - start_time);
00269             }
00270         }
00271 
00272         anope_cmd_219(source, av[0]);
00273         break;
00274     case 'o':
00275     case 'O':
00276 /* Check whether the user is an operator */
00277         u = finduser(source);
00278         if (u && !is_oper(u) && HideStatsO) {
00279             anope_cmd_219(source, av[0]);
00280         } else {
00281             for (i = 0; i < RootNumber; i++)
00282                 anope_cmd_243("%s O * * %s Root 0", source,
00283                               ServicesRoots[i]);
00284             for (i = 0; i < servadmins.count && (nc = servadmins.list[i]);
00285                  i++)
00286                 anope_cmd_243("%s O * * %s Admin 0", source, nc->display);
00287             for (i = 0; i < servopers.count && (nc = servopers.list[i]);
00288                  i++)
00289                 anope_cmd_243("%s O * * %s Oper 0", source, nc->display);
00290 
00291             anope_cmd_219(source, av[0]);
00292         }
00293 
00294         break;
00295 
00296     case 'u':{
00297             int uptime = time(NULL) - start_time;
00298             anope_cmd_242("%s :Services up %d day%s, %02d:%02d:%02d",
00299                           source, uptime / 86400,
00300                           (uptime / 86400 == 1) ? "" : "s",
00301                           (uptime / 3600) % 24, (uptime / 60) % 60,
00302                           uptime % 60);
00303             anope_cmd_250("%s :Current users: %d (%d ops); maximum %d",
00304                           source, usercnt, opcnt, maxusercnt);
00305             anope_cmd_219(source, av[0]);
00306             break;
00307         }                       /* case 'u' */
00308 
00309     default:
00310         anope_cmd_219(source, av[0]);
00311         break;
00312     }
00313     return MOD_CONT;
00314 }
00315 
00316 /*************************************************************************/
00317 
00318 int m_version(char *source, int ac, char **av)
00319 {
00320     if (source) {
00321         anope_cmd_351(source);
00322     }
00323     return MOD_CONT;
00324 }
00325 
00326 
00327 /*************************************************************************/
00328 
00329 int m_whois(char *source, char *who)
00330 {
00331     BotInfo *bi;
00332     NickAlias *na;
00333     const char *clientdesc;
00334 
00335     if (source && who) {
00336         if (stricmp(who, s_NickServ) == 0)
00337             clientdesc = desc_NickServ;
00338         else if (stricmp(who, s_ChanServ) == 0)
00339             clientdesc = desc_ChanServ;
00340         else if (stricmp(who, s_MemoServ) == 0)
00341             clientdesc = desc_MemoServ;
00342         else if (s_BotServ && stricmp(who, s_BotServ) == 0)
00343             clientdesc = desc_BotServ;
00344         else if (s_HostServ && stricmp(who, s_HostServ) == 0)
00345             clientdesc = desc_HostServ;
00346         else if (stricmp(who, s_HelpServ) == 0)
00347             clientdesc = desc_HelpServ;
00348         else if (stricmp(who, s_OperServ) == 0)
00349             clientdesc = desc_OperServ;
00350         else if (stricmp(who, s_GlobalNoticer) == 0)
00351             clientdesc = desc_GlobalNoticer;
00352         else if (s_DevNull && stricmp(who, s_DevNull) == 0)
00353             clientdesc = desc_DevNull;
00354         else if (s_BotServ && (bi = findbot(who))) {
00355             /* Bots are handled separately */
00356             anope_cmd_311("%s %s %s %s * :%s", source, bi->nick,
00357                           bi->user, bi->host, bi->real);
00358             anope_cmd_307("%s %s :is a registered nick", source, bi->nick);
00359             anope_cmd_312("%s %s %s :%s", source, bi->nick, ServerName,
00360                           ServerDesc);
00361             anope_cmd_317("%s %s %ld %ld :seconds idle, signon time",
00362                           source, bi->nick, time(NULL) - bi->lastmsg,
00363                           start_time);
00364             anope_cmd_318(source, bi->nick);
00365             return MOD_CONT;
00366         } else if (!(ircd->svshold && UseSVSHOLD) && (na = findnick(who))
00367                    && (na->status & NS_KILL_HELD)) {
00368             /* We have a nick enforcer client here that we need to respond to.
00369              * We can't just say it doesn't exist here, even tho it does for
00370              * other servers :) -GD
00371              */
00372             anope_cmd_311("%s %s %s %s * :Services Enforcer", source,
00373                           na->nick, NSEnforcerUser, NSEnforcerHost);
00374             anope_cmd_312("%s %s %s :%s", source, na->nick, ServerName,
00375                           ServerDesc);
00376             anope_cmd_318(source, na->nick);
00377             return MOD_CONT;
00378         } else {
00379             anope_cmd_401(source, who);
00380             return MOD_CONT;
00381         }
00382         anope_cmd_311("%s %s %s %s * :%s", source, who,
00383                       ServiceUser, ServiceHost, clientdesc);
00384         anope_cmd_312("%s %s %s :%s", source, who, ServerName, ServerDesc);
00385         anope_cmd_317("%s %s %ld %ld :seconds idle, signon time", source,
00386                       who, time(NULL) - start_time, start_time);
00387         anope_cmd_318(source, who);
00388     }
00389     return MOD_CONT;
00390 }
00391 
00392 /* NULL route messages */
00393 int anope_event_null(char *source, int ac, char **av)
00394 {
00395     return MOD_CONT;
00396 }
00397 
00398 /* *INDENT-OFF* */
00399 void moduleAddMsgs(void) {
00400     Message *m;
00401     m = createMessage("STATS",     m_stats); addCoreMessage(IRCD,m);
00402     m = createMessage("TIME",      m_time); addCoreMessage(IRCD,m);
00403     m = createMessage("VERSION",   m_version); addCoreMessage(IRCD,m);
00404 }
00405 
00406 /*************************************************************************/
00407 
00408 Message *find_message(const char *name)
00409 {
00410     Message *m;
00411     m = findMessage(IRCD, name);
00412     return m;
00413 }
00414 
00415 /*************************************************************************/

Generated on Sun Dec 30 09:26:49 2007 for Anope by  doxygen 1.5.1-20070107