summaryrefslogtreecommitdiff
path: root/src/modules/m_watch.cpp
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2005-12-16 18:48:07 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2005-12-16 18:48:07 +0000
commit347e25f83d2d8403851e8bdcbf27d987abbd8fd5 (patch)
tree6eff73c25154ac55bfe4167abd79011ac3f06b61 /src/modules/m_watch.cpp
parenta5a8764bfe85e208a622a86295bdf56da575f21c (diff)
Last set of modules converted to new command system
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@2538 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/modules/m_watch.cpp')
-rw-r--r--src/modules/m_watch.cpp247
1 files changed, 128 insertions, 119 deletions
diff --git a/src/modules/m_watch.cpp b/src/modules/m_watch.cpp
index bd3a2f707..1a8d6a658 100644
--- a/src/modules/m_watch.cpp
+++ b/src/modules/m_watch.cpp
@@ -39,155 +39,164 @@ class watchentry
typedef std::vector<watchentry> watchlist;
watchlist watches;
-void handle_watch(char **parameters, int pcnt, userrec *user)
+class cmd_watch : public command_t
{
- if (!pcnt)
+ public:
+ cmd_watch() : command_t("WATCH",0,0)
{
- for (watchlist::iterator q = watches.begin(); q != watches.end(); q++)
- {
- if (q->watcher == user)
- {
- userrec* targ = Srv->FindNick(q->target);
- if (targ)
- {
- WriteServ(user->fd,"604 %s %s %s %s %lu :is online",user->nick,targ->nick,targ->ident,targ->dhost,targ->age);
- }
- }
- }
- WriteServ(user->fd,"607 %s :End of WATCH list",user->nick);
+ this->source = "m_watch.so";
}
- else if (pcnt > 0)
+
+ void Handle (char **parameters, int pcnt, userrec *user)
{
- for (int x = 0; x < pcnt; x++)
+ if (!pcnt)
+ {
+ for (watchlist::iterator q = watches.begin(); q != watches.end(); q++)
+ {
+ if (q->watcher == user)
+ {
+ userrec* targ = Srv->FindNick(q->target);
+ if (targ)
+ {
+ WriteServ(user->fd,"604 %s %s %s %s %lu :is online",user->nick,targ->nick,targ->ident,targ->dhost,targ->age);
+ }
+ }
+ }
+ WriteServ(user->fd,"607 %s :End of WATCH list",user->nick);
+ }
+ else if (pcnt > 0)
{
- char *nick = parameters[x];
- if (!strcasecmp(nick,"C"))
+ for (int x = 0; x < pcnt; x++)
{
- // watch clear
- bool done = false;
- while (!done)
- {
- done = true;
+ char *nick = parameters[x];
+ if (!strcasecmp(nick,"C"))
+ {
+ // watch clear
+ bool done = false;
+ while (!done)
+ {
+ done = true;
+ for (watchlist::iterator q = watches.begin(); q != watches.end(); q++)
+ {
+ if (q->watcher == user)
+ {
+ done = false;
+ watches.erase(q);
+ break;
+ }
+ }
+ }
+ }
+ else if (!strcasecmp(nick,"L"))
+ {
+ for (watchlist::iterator q = watches.begin(); q != watches.end(); q++)
+ {
+ if (q->watcher == user)
+ {
+ userrec* targ = Srv->FindNick(q->target);
+ if (targ)
+ {
+ WriteServ(user->fd,"604 %s %s %s %s %lu :is online",user->nick,targ->nick,targ->ident,targ->dhost,targ->age);
+ }
+ }
+ }
+ WriteServ(user->fd,"607 %s :End of WATCH list",user->nick);
+ }
+ else if (!strcasecmp(nick,"S"))
+ {
+ std::string list = "";
+ for (watchlist::iterator q = watches.begin(); q != watches.end(); q++)
+ {
+ if (q->watcher == user)
+ {
+ list = list + " " + q->target;
+ }
+ }
+ char* l = (char*)list.c_str();
+ if (*l == ' ')
+ l++;
+ WriteServ(user->fd,"606 %s :%s",user->nick,l);
+ WriteServ(user->fd,"607 %s :End of WATCH S",user->nick);
+ }
+ else if (nick[0] == '-')
+ {
+ // removing an item from the list
+ nick++;
+ irc::string n1 = nick;
for (watchlist::iterator q = watches.begin(); q != watches.end(); q++)
{
if (q->watcher == user)
{
- done = false;
- watches.erase(q);
- break;
- }
- }
- }
- }
- else if (!strcasecmp(nick,"L"))
- {
- for (watchlist::iterator q = watches.begin(); q != watches.end(); q++)
- {
- if (q->watcher == user)
- {
- userrec* targ = Srv->FindNick(q->target);
- if (targ)
- {
- WriteServ(user->fd,"604 %s %s %s %s %lu :is online",user->nick,targ->nick,targ->ident,targ->dhost,targ->age);
- }
- }
- }
- WriteServ(user->fd,"607 %s :End of WATCH list",user->nick);
- }
- else if (!strcasecmp(nick,"S"))
- {
- std::string list = "";
- for (watchlist::iterator q = watches.begin(); q != watches.end(); q++)
- {
- if (q->watcher == user)
- {
- list = list + " " + q->target;
- }
- }
- char* l = (char*)list.c_str();
- if (*l == ' ')
- l++;
- WriteServ(user->fd,"606 %s :%s",user->nick,l);
- WriteServ(user->fd,"607 %s :End of WATCH S",user->nick);
- }
- else if (nick[0] == '-')
- {
- // removing an item from the list
- nick++;
- irc::string n1 = nick;
- for (watchlist::iterator q = watches.begin(); q != watches.end(); q++)
- {
- if (q->watcher == user)
- {
- irc::string n2 = q->target.c_str();
- userrec* a = Srv->FindNick(q->target);
- if (a)
- {
- WriteServ(user->fd,"602 %s %s %s %s %lu :stopped watching",user->nick,a->nick,a->ident,a->dhost,a->age);
- }
- else
- {
- WriteServ(user->fd,"602 %s %s * * 0 :stopped watching",user->nick,q->target.c_str());
- }
- if (n1 == n2)
- {
- watches.erase(q);
- break;
- }
+ irc::string n2 = q->target.c_str();
+ userrec* a = Srv->FindNick(q->target);
+ if (a)
+ {
+ WriteServ(user->fd,"602 %s %s %s %s %lu :stopped watching",user->nick,a->nick,a->ident,a->dhost,a->age);
+ }
+ else
+ {
+ WriteServ(user->fd,"602 %s %s * * 0 :stopped watching",user->nick,q->target.c_str());
+ }
+ if (n1 == n2)
+ {
+ watches.erase(q);
+ break;
+ }
+ }
}
}
- }
- else if (nick[0] == '+')
- {
- nick++;
- irc::string n1 = nick;
- bool exists = false;
- for (watchlist::iterator q = watches.begin(); q != watches.end(); q++)
+ else if (nick[0] == '+')
{
- if (q->watcher == user)
+ nick++;
+ irc::string n1 = nick;
+ bool exists = false;
+ for (watchlist::iterator q = watches.begin(); q != watches.end(); q++)
{
- irc::string n2 = q->target.c_str();
- if (n1 == n2)
+ if (q->watcher == user)
{
- // already on watch list
- exists = true;
+ irc::string n2 = q->target.c_str();
+ if (n1 == n2)
+ {
+ // already on watch list
+ exists = true;
+ }
}
}
+ if (!exists)
+ {
+ watchentry w;
+ w.watcher = user;
+ w.target = nick;
+ watches.push_back(w);
+ log(DEBUG,"*** Added %s to watchlist of %s",nick,user->nick);
+ }
+ userrec* a = Srv->FindNick(nick);
+ if (a)
+ {
+ WriteServ(user->fd,"604 %s %s %s %s %lu :is online",user->nick,a->nick,a->ident,a->dhost,a->age);
+ }
+ else
+ {
+ WriteServ(user->fd,"605 %s %s * * 0 :is offline",user->nick,nick);
+ }
}
- if (!exists)
- {
- watchentry w;
- w.watcher = user;
- w.target = nick;
- watches.push_back(w);
- log(DEBUG,"*** Added %s to watchlist of %s",nick,user->nick);
- }
- userrec* a = Srv->FindNick(nick);
- if (a)
- {
- WriteServ(user->fd,"604 %s %s %s %s %lu :is online",user->nick,a->nick,a->ident,a->dhost,a->age);
- }
- else
- {
- WriteServ(user->fd,"605 %s %s * * 0 :is offline",user->nick,nick);
- }
}
}
+ return;
}
- return;
-}
-
+};
class Modulewatch : public Module
{
-
+ cmd_watch* mycommand;
public:
Modulewatch(Server* Me)
: Module::Module(Me)
{
Srv = Me;
- Srv->AddCommand("WATCH",handle_watch,0,0,"m_watch.so");
+ mycommand = new cmd_watch();
+ Srv->AddCommand(mycommand);
}
virtual void OnUserQuit(userrec* user, std::string reason)