1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
7 * <brain@chatspike.net>
8 * <Craig@chatspike.net>
10 * Written by Craig Edwards, Craig McLure, and others.
11 * This program is free but copyrighted software; see
12 * the file COPYING for details.
14 * ---------------------------------------------------
25 #include "helperfuncs.h"
28 /* $ModDesc: Provides support for the /watch command */
39 typedef std::vector<watchentry> watchlist;
42 void handle_watch(char **parameters, int pcnt, userrec *user)
46 for (watchlist::iterator q = watches.begin(); q != watches.end(); q++)
48 if (q->watcher == user)
50 userrec* targ = Srv->FindNick(q->target);
53 WriteServ(user->fd,"604 %s %s %s %s %lu :is online",user->nick,targ->nick,targ->ident,targ->dhost,targ->age);
57 WriteServ(user->fd,"607 %s :End of WATCH list",user->nick);
61 for (int x = 0; x < pcnt; x++)
63 char *nick = parameters[x];
64 if (!strcasecmp(nick,"C"))
71 for (watchlist::iterator q = watches.begin(); q != watches.end(); q++)
73 if (q->watcher == user)
82 if (!strcasecmp(nick,"L"))
84 for (watchlist::iterator q = watches.begin(); q != watches.end(); q++)
86 if (q->watcher == user)
88 userrec* targ = Srv->FindNick(q->target);
91 WriteServ(user->fd,"604 %s %s %s %s %lu :is online",user->nick,targ->nick,targ->ident,targ->dhost,targ->age);
95 WriteServ(user->fd,"607 %s :End of WATCH list",user->nick);
97 if (!strcasecmp(nick,"S"))
99 std::string list = "";
100 for (watchlist::iterator q = watches.begin(); q != watches.end(); q++)
102 if (q->watcher == user)
104 list = list + " " + q->target;
107 char* l = (char*)list.c_str();
110 WriteServ(user->fd,"606 %s :%s",user->nick,l);
111 WriteServ(user->fd,"607 %s :End of WATCH S",user->nick);
115 // removing an item from the list
117 irc::string n1 = nick;
118 for (watchlist::iterator q = watches.begin(); q != watches.end(); q++)
120 if (q->watcher == user)
122 irc::string n2 = q->target.c_str();
123 userrec* a = Srv->FindNick(q->target);
126 WriteServ(user->fd,"602 %s %s %s %s %lu :stopped watching",user->nick,a->nick,a->ident,a->dhost,a->age);
130 WriteServ(user->fd,"602 %s %s * * 0 :stopped watching",user->nick,q->target.c_str());
140 else if (nick[0] == '+')
143 irc::string n1 = nick;
145 for (watchlist::iterator q = watches.begin(); q != watches.end(); q++)
147 if (q->watcher == user)
149 irc::string n2 = q->target.c_str();
152 // already on watch list
162 watches.push_back(w);
163 log(DEBUG,"*** Added %s to watchlist of %s",nick,user->nick);
165 userrec* a = Srv->FindNick(nick);
168 WriteServ(user->fd,"604 %s %s %s %s %lu :is online",user->nick,a->nick,a->ident,a->dhost,a->age);
172 WriteServ(user->fd,"605 %s %s * * 0 :is offline",user->nick,nick);
181 class Modulewatch : public Module
189 Srv->AddCommand("WATCH",handle_watch,0,0,"m_watch.so");
192 virtual void OnUserQuit(userrec* user)
194 log(DEBUG,"*** WATCH: On global quit: user %s",user->nick);
195 irc::string n2 = user->nick;
196 for (watchlist::iterator q = watches.begin(); q != watches.end(); q++)
198 irc::string n1 = q->target.c_str();
201 log(DEBUG,"*** WATCH: On global quit: user %s is in notify of %s",user->nick,q->watcher->nick);
202 WriteServ(q->watcher->fd,"601 %s %s %s %s %lu :went offline",q->watcher->nick,user->nick,user->ident,user->dhost,time(NULL));
209 for (watchlist::iterator q = watches.begin(); q != watches.end(); q++)
211 if (q->watcher == user)
221 virtual void OnGlobalConnect(userrec* user)
223 irc::string n2 = user->nick;
224 log(DEBUG,"*** WATCH: On global connect: user %s",user->nick);
225 for (watchlist::iterator q = watches.begin(); q != watches.end(); q++)
227 irc::string n1 = q->target.c_str();
230 log(DEBUG,"*** WATCH: On global connect: user %s is in notify of %s",user->nick,q->watcher->nick);
231 WriteServ(q->watcher->fd,"600 %s %s %s %s %lu :arrived online",q->watcher->nick,user->nick,user->ident,user->dhost,user->age);
236 virtual void OnUserPostNick(userrec* user, std::string oldnick)
238 irc::string n2 = oldnick.c_str();
239 irc::string n3 = user->nick;
240 log(DEBUG,"*** WATCH: On global nickchange: old nick: %s new nick: %s",oldnick.c_str(),user->nick);
241 for (watchlist::iterator q = watches.begin(); q != watches.end(); q++)
243 irc::string n1 = q->target.c_str();
244 // changed from a nick on the watchlist to one that isnt
247 log(DEBUG,"*** WATCH: On global nickchange: old nick %s was on notify list of %s",oldnick.c_str(),q->watcher->nick);
248 WriteServ(q->watcher->fd,"601 %s %s %s %s %lu :went offline",q->watcher->nick,oldnick.c_str(),user->ident,user->dhost,time(NULL));
252 // changed from a nick not on notify to one that is
253 log(DEBUG,"*** WATCH: On global nickchange: new nick %s is on notify list of %s",user->nick,q->watcher->nick);
254 WriteServ(q->watcher->fd,"600 %s %s %s %s %lu :arrived online",q->watcher->nick,user->nick,user->ident,user->dhost,user->age);
259 virtual void On005Numeric(std::string &output)
261 // we don't really have a limit...
262 output = output + " WATCH=999";
265 virtual ~Modulewatch()
270 virtual Version GetVersion()
272 return Version(1,0,0,1,VF_VENDOR);
277 class ModulewatchFactory : public ModuleFactory
284 ~ModulewatchFactory()
288 virtual Module * CreateModule()
290 return new Modulewatch;
296 extern "C" void * init_module( void )
298 return new ModulewatchFactory;