Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/VibeDevelopers/Comet.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319/* modules/m_monitor.c * * Copyright (C) 2005 Lee Hardy <lee@leeh.co.uk> * Copyright (C) 2005 ircd-ratbox development team * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * 1.Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2.Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3.The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */
#include "stdinc.h"#include "client.h"#include "msg.h"#include "parse.h"#include "modules.h"#include "monitor.h"#include "numeric.h"#include "response.h"#include "s_conf.h"#include "send.h"#include "supported.h"
static const char monitor_desc[] = "Provides the MONITOR facility for tracking user signon and signoff";
static int monitor_init(void);static void monitor_deinit(void);static void m_monitor(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
struct Message monitor_msgtab = { "MONITOR", 0, 0, 0, 0, {mg_unreg, {m_monitor, 2}, mg_ignore, mg_ignore, mg_ignore, {m_monitor, 2}}};
mapi_clist_av1 monitor_clist[] = { &monitor_msgtab, NULL };
DECLARE_MODULE_AV2(monitor, monitor_init, monitor_deinit, monitor_clist, NULL, NULL, NULL, NULL, monitor_desc);
static int monitor_init(void){ add_isupport("MONITOR", isupport_intptr, &ConfigFileEntry.max_monitor); return 0;}
static void monitor_deinit(void){ delete_isupport("MONITOR");}
static voidadd_monitor(struct Client *client_p, const char *nicks){ rb_dlink_node *prev_head, *ptr; struct Client *target_p; struct monitor *monptr; const char *name; char *tmp; char *p;
prev_head = client_p->localClient->monitor_list.head; tmp = LOCAL_COPY(nicks);
for(name = rb_strtok_r(tmp, ",", &p); name; name = rb_strtok_r(NULL, ",", &p)) { if(EmptyString(name) || strlen(name) > NICKLEN-1) continue;
if(rb_dlink_list_length(&client_p->localClient->monitor_list) >= (unsigned long)ConfigFileEntry.max_monitor) { break; }
if (!clean_nick(name, 0)) continue;
monptr = find_monitor(name, 1);
/* already monitoring this nick */ if(rb_dlinkFind(client_p, &monptr->users)) continue;
rb_dlinkAddAlloc(client_p, &monptr->users); rb_dlinkAddAlloc(monptr, &client_p->localClient->monitor_list); }
send_multiline_init(client_p, ",", form_str(RPL_MONONLINE), me.name, client_p->name, "");
if (prev_head != NULL) prev_head = prev_head->prev; else prev_head = client_p->localClient->monitor_list.tail;
RB_DLINK_FOREACH_PREV(ptr, prev_head) { monptr = ptr->data; target_p = find_named_person(monptr->name);
if (target_p != NULL) { send_multiline_item(client_p, "%s!%s@%s", target_p->name, target_p->username, target_p->host); } }
send_multiline_fini(client_p, NULL);
send_multiline_init(client_p, ",", form_str(RPL_MONOFFLINE), me.name, client_p->name, "");
RB_DLINK_FOREACH_PREV(ptr, prev_head) { monptr = ptr->data;
if (find_named_person(monptr->name) == NULL) { send_multiline_item(client_p, "%s", monptr->name); } }
send_multiline_fini(client_p, NULL);
if (name) { char buf[400];
if (p) snprintf(buf, sizeof buf, "%s,%s", name, p); else snprintf(buf, sizeof buf, "%s", name);
sendto_one(client_p, form_str(ERR_MONLISTFULL), me.name, client_p->name, ConfigFileEntry.max_monitor, buf); }}
static voiddel_monitor(struct Client *client_p, const char *nicks){ struct monitor *monptr; const char *name; char *tmp; char *p;
if(!rb_dlink_list_length(&client_p->localClient->monitor_list)) return;
tmp = LOCAL_COPY(nicks);
for(name = rb_strtok_r(tmp, ",", &p); name; name = rb_strtok_r(NULL, ",", &p)) { if(EmptyString(name)) continue;
/* not monitored */ if((monptr = find_monitor(name, 0)) == NULL) continue;
rb_dlinkFindDestroy(client_p, &monptr->users); rb_dlinkFindDestroy(monptr, &client_p->localClient->monitor_list);
free_monitor(monptr); }}
static voidlist_monitor(struct Client *client_p){ struct monitor *monptr; rb_dlink_node *ptr;
if(!rb_dlink_list_length(&client_p->localClient->monitor_list)) { sendto_one(client_p, form_str(RPL_ENDOFMONLIST), me.name, client_p->name); return; }
send_multiline_init(client_p, ",", form_str(RPL_MONLIST), me.name, client_p->name, "");
RB_DLINK_FOREACH(ptr, client_p->localClient->monitor_list.head) { monptr = ptr->data;
send_multiline_item(client_p, "%s", monptr->name); }
send_multiline_fini(client_p, NULL); sendto_one(client_p, form_str(RPL_ENDOFMONLIST), me.name, client_p->name);}
static voidshow_monitor_status(struct Client *client_p){ struct Client *target_p; struct monitor *monptr; rb_dlink_node *ptr;
send_multiline_init(client_p, ",", form_str(RPL_MONONLINE), me.name, client_p->name, "");
RB_DLINK_FOREACH(ptr, client_p->localClient->monitor_list.head) { monptr = ptr->data; target_p = find_named_person(monptr->name);
if (target_p != NULL) { send_multiline_item(client_p, "%s!%s@%s", target_p->name, target_p->username, target_p->host); } }
send_multiline_fini(client_p, NULL);
send_multiline_init(client_p, ",", form_str(RPL_MONOFFLINE), me.name, client_p->name, "");
RB_DLINK_FOREACH(ptr, client_p->localClient->monitor_list.head) { monptr = ptr->data;
if (find_named_person(monptr->name) == NULL) { send_multiline_item(client_p, "%s", monptr->name); } }
send_multiline_fini(client_p, NULL);}
static voidm_monitor(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]){ switch(parv[1][0]) { case '+': if(parc < 3 || EmptyString(parv[2])) { sendto_one(client_p, form_str(ERR_NEEDMOREPARAMS), me.name, source_p->name, "MONITOR"); return; }
begin_local_response_batch(); add_monitor(source_p, parv[2]); break; case '-': if(parc < 3 || EmptyString(parv[2])) { sendto_one(client_p, form_str(ERR_NEEDMOREPARAMS), me.name, source_p->name, "MONITOR"); return; }
del_monitor(source_p, parv[2]); break;
case 'C': case 'c': clear_monitor(source_p); break;
case 'L': case 'l': begin_local_response_batch(); list_monitor(source_p); break;
case 'S': case 's': begin_local_response_batch(); show_monitor_status(source_p); break;
default: break; }}