- for (int x = 0; x < pcnt; x++)
- {
- const 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++)
- {
- watchentry* a = (watchentry*)(*q);
- if (a->watcher == user)
- {
- done = false;
- watches.erase(q);
- delete a;
- break;
- }
- }
- }
- }
- else if (!strcasecmp(nick,"L"))
- {
- for (watchlist::iterator q = watches.begin(); q != watches.end(); q++)
- {
- watchentry* a = (watchentry*)(*q);
- if (a->watcher == user)
- {
- userrec* targ = Srv->FindNick(a->target);
- if (targ)
- {
- user->WriteServ("604 %s %s %s %s %lu :is online",user->nick,targ->nick,targ->ident,targ->dhost,targ->age);
- }
- }
- }
- user->WriteServ("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++)
- {
- watchentry* a = (watchentry*)(*q);
- if (a->watcher == user)
- {
- list.append(" ").append(a->target);
- }
- }
- char* l = (char*)list.c_str();
- if (*l == ' ')
- l++;
- user->WriteServ("606 %s :%s",user->nick,l);
- user->WriteServ("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++)
- {
- watchentry* b = (watchentry*)(*q);
- if (b->watcher == user)
- {
- irc::string n2 = b->target.c_str();
- userrec* a = Srv->FindNick(b->target);
- if (a)
- {
- user->WriteServ("602 %s %s %s %s %lu :stopped watching",user->nick,a->nick,a->ident,a->dhost,a->age);
- }
- else
- {
- user->WriteServ("602 %s %s * * 0 :stopped watching",user->nick,b->target.c_str());
- }
- if (n1 == n2)
- {
- watches.erase(q);
- delete b;
- break;
- }
- }
- }
- }
- else if (nick[0] == '+')
- {
- nick++;
- irc::string n1 = nick;
- bool exists = false;
- for (watchlist::iterator q = watches.begin(); q != watches.end(); q++)
- {
- watchentry* a = (watchentry*)(*q);
- if (a->watcher == user)
- {
- irc::string n2 = a->target.c_str();
- if (n1 == n2)
- {
- // already on watch list
- exists = true;
- }
- }
- }
- if (!exists)
- {
- watchentry* w = new watchentry();
- 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)
- {
- user->WriteServ("604 %s %s %s %s %lu :is online",user->nick,a->nick,a->ident,a->dhost,a->age);
- }
- else
- {
- user->WriteServ("605 %s %s * * 0 :is offline",user->nick,nick);
- }
- }
- }