+ 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 = ServerInstance->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 = ServerInstance->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);
+ }