|
|||
|
|||
|
Inheritance diagram for cmd_watch:


Public Member Functions | |
| CmdResult | remove_watch (userrec *user, const char *nick) |
| CmdResult | add_watch (userrec *user, const char *nick) |
| cmd_watch (InspIRCd *Instance, unsigned int &maxwatch) | |
| CmdResult | Handle (const char **parameters, int pcnt, userrec *user) |
| Handle the command from a user. | |
Private Attributes | |
| unsigned int & | MAX_WATCH |
Definition at line 83 of file m_watch.cpp.
|
||||||||||||
|
Definition at line 203 of file m_watch.cpp. References command_t::source, and command_t::syntax. 00203 : command_t(Instance,"WATCH",0,0), MAX_WATCH(maxwatch) 00204 { 00205 this->source = "m_watch.so"; 00206 syntax = "[C|L|S]|[+|-<nick>]"; 00207 }
|
|
||||||||||||
|
Definition at line 142 of file m_watch.cpp. References classbase::age, CMD_FAILURE, ConvToStr(), userrec::dhost, Extensible::Extend(), InspIRCd::FindNick(), Extensible::GetExt(), userrec::ident, InspIRCd::IsNick(), MAX_WATCH, userrec::nick, command_t::ServerInstance, userrec::Visibility, VisData::VisibleTo(), whos_watching_me, and userrec::WriteServ(). Referenced by Handle(). 00143 { 00144 if (!ServerInstance->IsNick(nick)) 00145 { 00146 user->WriteServ("942 %s %s :Invalid nickname",user->nick,nick); 00147 return CMD_FAILURE; 00148 } 00149 00150 watchlist* wl; 00151 if (!user->GetExt("watchlist", wl)) 00152 { 00153 wl = new watchlist(); 00154 user->Extend("watchlist", wl); 00155 } 00156 00157 if (wl->size() == MAX_WATCH) 00158 { 00159 user->WriteServ("512 %s %s :Too many WATCH entries", user->nick, nick); 00160 return CMD_FAILURE; 00161 } 00162 00163 watchlist::iterator n = wl->find(nick); 00164 if (n == wl->end()) 00165 { 00166 /* Don't already have the user on my watch list, proceed */ 00167 watchentries::iterator x = whos_watching_me->find(nick); 00168 if (x != whos_watching_me->end()) 00169 { 00170 /* People are watching this user, add myself */ 00171 x->second.push_back(user); 00172 } 00173 else 00174 { 00175 std::deque<userrec*> newlist; 00176 newlist.push_back(user); 00177 (*(whos_watching_me))[nick] = newlist; 00178 } 00179 00180 userrec* target = ServerInstance->FindNick(nick); 00181 if (target) 00182 { 00183 if (target->Visibility && !target->Visibility->VisibleTo(user)) 00184 { 00185 (*wl)[nick] = ""; 00186 user->WriteServ("605 %s %s * * 0 :is offline",user->nick, nick); 00187 return CMD_FAILURE; 00188 } 00189 00190 (*wl)[nick] = std::string(target->ident).append(" ").append(target->dhost).append(" ").append(ConvToStr(target->age)); 00191 user->WriteServ("604 %s %s %s :is online",user->nick, nick, (*wl)[nick].c_str()); 00192 } 00193 else 00194 { 00195 (*wl)[nick] = ""; 00196 user->WriteServ("605 %s %s * * 0 :is offline",user->nick, nick); 00197 } 00198 } 00199 00200 return CMD_FAILURE; 00201 }
|
|
||||||||||||||||
|
Handle the command from a user.
Implements command_t. Definition at line 209 of file m_watch.cpp. References add_watch(), CMD_FAILURE, Extensible::GetExt(), userrec::nick, remove_watch(), Extensible::Shrink(), whos_watching_me, and userrec::WriteServ(). 00210 { 00211 if (!pcnt) 00212 { 00213 watchlist* wl; 00214 if (user->GetExt("watchlist", wl)) 00215 { 00216 for (watchlist::iterator q = wl->begin(); q != wl->end(); q++) 00217 { 00218 if (!q->second.empty()) 00219 user->WriteServ("604 %s %s %s :is online", user->nick, q->first.c_str(), q->second.c_str()); 00220 } 00221 } 00222 user->WriteServ("607 %s :End of WATCH list",user->nick); 00223 } 00224 else if (pcnt > 0) 00225 { 00226 for (int x = 0; x < pcnt; x++) 00227 { 00228 const char *nick = parameters[x]; 00229 if (!strcasecmp(nick,"C")) 00230 { 00231 // watch clear 00232 watchlist* wl; 00233 if (user->GetExt("watchlist", wl)) 00234 { 00235 for (watchlist::iterator i = wl->begin(); i != wl->end(); i++) 00236 { 00237 watchentries::iterator x = whos_watching_me->find(i->first); 00238 if (x != whos_watching_me->end()) 00239 { 00240 /* People are watching this user, am i one of them? */ 00241 std::deque<userrec*>::iterator n = std::find(x->second.begin(), x->second.end(), user); 00242 if (n != x->second.end()) 00243 /* I'm no longer watching you... */ 00244 x->second.erase(n); 00245 00246 if (!x->second.size()) 00247 whos_watching_me->erase(x); 00248 } 00249 } 00250 00251 delete wl; 00252 user->Shrink("watchlist"); 00253 } 00254 } 00255 else if (!strcasecmp(nick,"L")) 00256 { 00257 watchlist* wl; 00258 if (user->GetExt("watchlist", wl)) 00259 { 00260 for (watchlist::iterator q = wl->begin(); q != wl->end(); q++) 00261 { 00262 if (!q->second.empty()) 00263 user->WriteServ("604 %s %s %s :is online", user->nick, q->first.c_str(), q->second.c_str()); 00264 else 00265 user->WriteServ("605 %s %s * * 0 :is offline", user->nick, q->first.c_str()); 00266 } 00267 } 00268 user->WriteServ("607 %s :End of WATCH list",user->nick); 00269 } 00270 else if (!strcasecmp(nick,"S")) 00271 { 00272 watchlist* wl; 00273 int you_have = 0; 00274 int youre_on = 0; 00275 std::string list; 00276 00277 if (user->GetExt("watchlist", wl)) 00278 { 00279 for (watchlist::iterator q = wl->begin(); q != wl->end(); q++) 00280 list.append(q->first.c_str()).append(" "); 00281 you_have = wl->size(); 00282 } 00283 00284 watchentries::iterator x = whos_watching_me->find(user->nick); 00285 if (x != whos_watching_me->end()) 00286 youre_on = x->second.size(); 00287 00288 user->WriteServ("603 %s :You have %d and are on %d WATCH entries", user->nick, you_have, youre_on); 00289 user->WriteServ("606 %s :%s",user->nick, list.c_str()); 00290 user->WriteServ("607 %s :End of WATCH S",user->nick); 00291 } 00292 else if (nick[0] == '-') 00293 { 00294 nick++; 00295 remove_watch(user, nick); 00296 } 00297 else if (nick[0] == '+') 00298 { 00299 nick++; 00300 add_watch(user, nick); 00301 } 00302 } 00303 } 00304 /* So that spanningtree doesnt pass the WATCH commands to the network! */ 00305 return CMD_FAILURE; 00306 }
|
|
||||||||||||
|
Definition at line 87 of file m_watch.cpp. References CMD_FAILURE, Extensible::GetExt(), InspIRCd::IsNick(), userrec::nick, command_t::ServerInstance, Extensible::Shrink(), whos_watching_me, and userrec::WriteServ(). Referenced by Handle(). 00088 { 00089 // removing an item from the list 00090 if (!ServerInstance->IsNick(nick)) 00091 { 00092 user->WriteServ("942 %s %s :Invalid nickname", user->nick, nick); 00093 return CMD_FAILURE; 00094 } 00095 00096 watchlist* wl; 00097 if (user->GetExt("watchlist", wl)) 00098 { 00099 /* Yup, is on my list */ 00100 watchlist::iterator n = wl->find(nick); 00101 00102 if (!wl) 00103 return CMD_FAILURE; 00104 00105 if (n != wl->end()) 00106 { 00107 if (!n->second.empty()) 00108 user->WriteServ("602 %s %s %s :stopped watching", user->nick, n->first.c_str(), n->second.c_str()); 00109 else 00110 user->WriteServ("602 %s %s * * 0 :stopped watching", user->nick, nick); 00111 00112 wl->erase(n); 00113 } 00114 00115 if (!wl->size()) 00116 { 00117 user->Shrink("watchlist"); 00118 delete wl; 00119 } 00120 00121 watchentries::iterator x = whos_watching_me->find(nick); 00122 if (x != whos_watching_me->end()) 00123 { 00124 /* People are watching this user, am i one of them? */ 00125 std::deque<userrec*>::iterator n = std::find(x->second.begin(), x->second.end(), user); 00126 if (n != x->second.end()) 00127 /* I'm no longer watching you... */ 00128 x->second.erase(n); 00129 00130 if (!x->second.size()) 00131 whos_watching_me->erase(nick); 00132 } 00133 } 00134 00135 /* This might seem confusing, but we return CMD_FAILURE 00136 * to indicate that this message shouldnt be routed across 00137 * the network to other linked servers. 00138 */ 00139 return CMD_FAILURE; 00140 }
|
|
|
Definition at line 85 of file m_watch.cpp. Referenced by add_watch(). |