ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/FreeBSDAdmin/IRC/smart_ison.cpp
(Generate patch)

Comparing FreeBSDAdmin/IRC/smart_ison.cpp (file contents):
Revision 1263 by douglas, 2010-03-21T06:30:15-07:00 vs.
Revision 1295 by douglas, 2010-04-09T05:48:07-07:00

# Line 20 | Line 20
20  
21   struct SmartISONTimer : public CTimer
22   {
23 <        SmartISONTimer(CModule *module) : CTimer(module, 15, 0, "Smart ISON", "Smart ISON") {}
23 >        SmartISONTimer(CModule *module) : CTimer(module, 15, 0, "Smart ISON", "Keeps track of online and offline nicks so ISON requests from Pidgin are not truncated") {}
24          virtual ~SmartISONTimer() {}
25  
26          virtual void RunJob();
# Line 44 | Line 44 | public:
44          MODCONSTRUCTOR(SmartISON) {}
45          virtual ~SmartISON() {}
46  
47 +        virtual EModRet OnCTCPReply(CNick &nick, CString &message)
48 +        {
49 +                nicks_[nick.GetNick()] = true;
50 +
51 +                return CONTINUE;
52 +        }
53 +
54 +        virtual void OnKick(const CNick &nick, const CString &opNick, CChan &chan, const CString &message)
55 +        {
56 +                queue_.push_front(nick.GetNick());
57 +        }
58 +
59          virtual bool OnLoad(const CString &args, CString &message)
60          {
61                  return AddTimer(new SmartISONTimer(this));
# Line 65 | Line 77 | public:
77                          table.AddRow();
78                          table.SetCell("Command", "Queue");
79                          table.SetCell("Description", "List the nick status queue");
80 +                        table.AddRow();
81 +                        table.SetCell("Command", "Request");
82 +                        table.SetCell("Description", "List the last nick request");
83 +                        table.AddRow();
84 +                        table.SetCell("Command", "Stats");
85 +                        table.SetCell("Description", "List nick and queue statistics");
86 +                        table.AddRow();
87 +                        table.SetCell("Command", "Version");
88 +                        table.SetCell("Description", "Display module version");
89  
90                          PutModule(table);
91                  }
# Line 106 | Line 127 | public:
127  
128                                  PutModule(table);
129                          }
130 +                else if (theCommand.Equals("Request"))
131 +                        if (request_.empty())
132 +                                PutModule("Last nick request empty");
133 +                        else
134 +                        {
135 +                                CTable table;
136 +
137 +                                table.AddColumn("Nick");
138 +
139 +                                typedef std::set<CString, Compare> NickSet;
140 +
141 +                                _foreach (NickSet, nick, request_)
142 +                                {
143 +                                        table.AddRow();
144 +                                        table.SetCell("Nick", *nick);
145 +                                }
146 +
147 +                                PutModule(table);
148 +                        }
149 +                else if (theCommand.Equals("Stats"))
150 +                {
151 +                        CTable table;
152 +
153 +                        table.AddColumn("Item");
154 +                        table.AddColumn("Count");
155 +                        table.AddRow();
156 +                        table.SetCell("Item", "Nicks");
157 +                        table.SetCell("Count", CString(nicks_.size()));
158 +
159 +                        typedef std::map<CString, bool, Compare> NickMap;
160 +                        size_t online(0), offline(0);
161 +
162 +                        _foreach (NickMap, nick, nicks_)
163 +                                if (nick->second)
164 +                                        ++online;
165 +                                else
166 +                                        ++offline;
167 +
168 +                        table.AddRow();
169 +                        table.SetCell("Item", "Online");
170 +                        table.SetCell("Count", CString(online));
171 +                        table.AddRow();
172 +                        table.SetCell("Item", "Offline");
173 +                        table.SetCell("Count", CString(offline));
174 +                        table.AddRow();
175 +                        table.SetCell("Item", "Queue");
176 +                        table.SetCell("Count", CString(queue_.size()));
177 +                        table.AddRow();
178 +                        table.SetCell("Item", "Request");
179 +                        table.SetCell("Count", CString(request_.size()));
180 +
181 +                        PutModule(table);
182 +                }
183 +                else if (theCommand.Equals("Version"))
184 +                        PutModule("$Id$");
185                  else
186                          PutModule("Unknown command [" + theCommand + "] try 'Help'");
187          }
188  
189 +        virtual void OnModCTCP(const CString &message)
190 +        {
191 +                CString command(message.Token(0));
192 +
193 +                if (command.Equals("PING"))
194 +                        PutModNotice("\001PING " + message.Token(1, true) + "\001");
195 +                else if (command.Equals("Version"))
196 +                        PutModNotice("\001VERSION $Id$\001");
197 +        }
198 +
199          virtual void OnNick(const CNick &nick, const CString &newNick, const std::vector<CChan *> &chans)
200          {
201                  const CString &oldNick(nick.GetNick());
# Line 118 | Line 204 | public:
204                  nicks_[newNick] = true;
205          }
206  
207 +        virtual void OnPart(const CNick &nick, CChan &chan)
208 +        {
209 +                queue_.push_front(nick.GetNick());
210 +        }
211 +
212 +        virtual EModRet OnPrivAction(CNick &nick, CString &message)
213 +        {
214 +                nicks_[nick.GetNick()] = true;
215 +
216 +                return CONTINUE;
217 +        }
218 +
219 +        virtual EModRet OnPrivCTCP(CNick &nick, CString &message)
220 +        {
221 +                nicks_[nick.GetNick()] = true;
222 +
223 +                return CONTINUE;
224 +        }
225 +
226 +        virtual EModRet OnPrivMsg(CNick &nick, CString &message)
227 +        {
228 +                nicks_[nick.GetNick()] = true;
229 +
230 +                return CONTINUE;
231 +        }
232 +
233 +        virtual EModRet OnPrivNotice(CNick &nick, CString &message)
234 +        {
235 +                nicks_[nick.GetNick()] = true;
236 +
237 +                return CONTINUE;
238 +        }
239 +
240          virtual void OnQuit(const CNick &nick, const CString &message, const std::vector<CChan *> &chans)
241          {
242                  const CString &theNick(nick.GetNick());
# Line 155 | Line 274 | private:
274          {
275                  Type nicks;
276  
277 <                _foreach (const std::vector<CChan *>, channel, GetUser()->GetChans())
277 >                _foreach (const std::vector<CChan *>, chan, GetUser()->GetChans())
278                  {
279                          typedef std::map<CString, CNick *> NickMap;
280  
281 <                        _foreach (const NickMap, nick, (*channel)->GetNicks())
281 >                        _foreach (const NickMap, nick, (*chan)->GetNicks())
282                          {
283                                  nicks_[nick->first] = true;
284                                  nicks.insert(nick->first);
# Line 181 | Line 300 | void SmartISONTimer::RunJob()
300   {
301          SmartISON *module(static_cast<SmartISON *>(GetModule()));
302  
184        if (module->queue_.empty())
185        {
186                typedef std::map<CString, bool, SmartISON::Compare> NickMap;
187
188                _foreach (NickMap, nick, module->nicks_)
189                        module->queue_.push_back(nick->first);
190        }
191
303          module->request_.clear();
304  
305          std::set<CString, SmartISON::Compare> online(module->CheckChans<std::set<CString, SmartISON::Compare> >());
# Line 198 | Line 309 | void SmartISONTimer::RunJob()
309          {
310                  CString nick(module->queue_.front());
311  
312 <                if (!online.count(nick))
312 >                if (!online.count(nick) && !module->request_.count(nick))
313                  {
314                          if ((size += nick.size() + 1) > 512)
315                                  break;
# Line 220 | Line 331 | void SmartISONTimer::RunJob()
331  
332                  module->PutIRC(request);
333          }
334 +
335 +        if (module->queue_.empty())
336 +        {
337 +                typedef std::map<CString, bool, SmartISON::Compare> NickMap;
338 +
339 +                _foreach (NickMap, nick, module->nicks_)
340 +                        module->queue_.push_back(nick->first);
341 +        }
342   }
343  
344   template <>
# Line 253 | Line 372 | CModule::EModRet SmartISON::OnUserRaw(CS
372                                  if (nick->Equals(prefix, false, prefix.size()))
373                                  {
374                                          CString modNick(nick->substr(prefix.size()));
375 +                                        CModule *module(NULL);
376  
377 <                                        if (modNick.Equals("status") || GetUser()->GetModules().FindModule(modNick) || CZNC::Get().GetModules().FindModule(modNick))
378 <                                                goto online;
377 >                                        if (modNick.Equals("status") || (module = GetUser()->GetModules().FindModule(modNick)) || (module = CZNC::Get().GetModules().FindModule(modNick)))
378 >                                        {
379 >                                                response += (module ? module->GetModNick() : prefix + "status") + " ";
380 >                                                continue;
381 >                                        }
382                                  }
383  
384 <                                if (!nicks_.count(*nick))
385 <                                        queue_.push_front(*nick);
384 >                                std::map<CString, bool, Compare>::iterator theNick(nicks_.find(*nick));
385 >
386 >                                if (theNick == nicks_.end())
387 >                                {
388 >                                        nicks_[*nick] = false;
389  
390 <                                if (nicks_[*nick])
391 < online:                         response += *nick + " ";
390 >                                        queue_.push_front(*nick);
391 >                                }
392 >                                else if (theNick->second)
393 >                                        response += theNick->first + " ";
394                          }
395  
396                          PutUser(response);
# Line 274 | Line 402 | online:                                response += *nick + " ";
402          return CONTINUE;
403   }
404  
405 < MODULEDEFS(SmartISON, "Smart ISON");
405 > MODULEDEFS(SmartISON, "Keeps track of online and offline nicks so ISON requests from Pidgin are not truncated");

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines