unrealircd

- supernets unrealircd source & configuration
git clone git://git.acid.vegas/unrealircd.git
Log | Files | Refs | Archive | README | LICENSE

extended-monitor.c (4892B)

      1 /*
      2  *   IRC - Internet Relay Chat, src/modules/extended-monitor.c
      3  *   (C) 2021 The UnrealIRCd Team
      4  *
      5  *   See file AUTHORS in IRC package for additional names of
      6  *   the programmers.
      7  *
      8  *   This program is free software; you can redistribute it and/or modify
      9  *   it under the terms of the GNU General Public License as published by
     10  *   the Free Software Foundation; either version 1, or (at your option)
     11  *   any later version.
     12  *
     13  *   This program is distributed in the hope that it will be useful,
     14  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     15  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16  *   GNU General Public License for more details.
     17  *
     18  *   You should have received a copy of the GNU General Public License
     19  *   along with this program; if not, write to the Free Software
     20  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
     21  */
     22 
     23 #include "unrealircd.h"
     24 
     25 long CAP_EXTENDED_MONITOR = 0L;
     26 
     27 int extended_monitor_away(Client *client, MessageTag *mtags, const char *reason, int already_as_away);
     28 int extended_monitor_account_login(Client *client, MessageTag *mtags);
     29 int extended_monitor_userhost_change(Client *client, const char *olduser, const char *oldhost);
     30 int extended_monitor_realname_change(Client *client, const char *oldinfo);
     31 int extended_monitor_notification(Client *client, Watch *watch, Link *lp, int event);
     32 
     33 ModuleHeader MOD_HEADER
     34   = {
     35 	"extended-monitor",
     36 	"5.0",
     37 	"extended functionality for /monitor", 
     38 	"UnrealIRCd Team",
     39 	"unrealircd-6",
     40     };
     41 
     42 MOD_INIT()
     43 {
     44 	ClientCapabilityInfo cap;
     45 	ClientCapability *c;
     46 	
     47 	MARK_AS_OFFICIAL_MODULE(modinfo);
     48 
     49 	ModDataInfo mreq;
     50 
     51 	memset(&cap, 0, sizeof(cap));
     52 	cap.name = "extended-monitor";
     53 	c = ClientCapabilityAdd(modinfo->handle, &cap, &CAP_EXTENDED_MONITOR);
     54 	if (!c)
     55 	{
     56 		config_error("[%s] Failed to request extended-monitor cap: %s", MOD_HEADER.name, ModuleGetErrorStr(modinfo->handle));
     57 		return MOD_FAILED;
     58 	}
     59 
     60 	HookAdd(modinfo->handle, HOOKTYPE_AWAY, 0, extended_monitor_away);
     61 	HookAdd(modinfo->handle, HOOKTYPE_ACCOUNT_LOGIN, 0, extended_monitor_account_login);
     62 	HookAdd(modinfo->handle, HOOKTYPE_USERHOST_CHANGE, 0, extended_monitor_userhost_change);
     63 	HookAdd(modinfo->handle, HOOKTYPE_REALNAME_CHANGE, 0, extended_monitor_realname_change);
     64 
     65 	return MOD_SUCCESS;
     66 }
     67 
     68 MOD_LOAD()
     69 {
     70 	return MOD_SUCCESS;
     71 }
     72 
     73 MOD_UNLOAD()
     74 {
     75 	return MOD_SUCCESS;
     76 }
     77 
     78 int extended_monitor_away(Client *client, MessageTag *mtags, const char *reason, int already_as_away)
     79 {
     80 	if (reason)
     81 		watch_check(client, WATCH_EVENT_AWAY, extended_monitor_notification);
     82 	else
     83 		watch_check(client, WATCH_EVENT_NOTAWAY, extended_monitor_notification);
     84 
     85 	return 0;
     86 }
     87 
     88 int extended_monitor_account_login(Client *client, MessageTag *mtags)
     89 {
     90 	if (IsLoggedIn(client))
     91 		watch_check(client, WATCH_EVENT_LOGGEDIN, extended_monitor_notification);
     92 	else
     93 		watch_check(client, WATCH_EVENT_LOGGEDOUT, extended_monitor_notification);
     94 
     95 	return 0;
     96 }
     97 
     98 int extended_monitor_userhost_change(Client *client, const char *olduser, const char *oldhost)
     99 {
    100 	watch_check(client, WATCH_EVENT_USERHOST, extended_monitor_notification);
    101 	return 0;
    102 }
    103 
    104 int extended_monitor_realname_change(Client *client, const char *oldinfo)
    105 {
    106 	watch_check(client, WATCH_EVENT_REALNAME, extended_monitor_notification);
    107 	return 0;
    108 }
    109 
    110 int extended_monitor_notification(Client *client, Watch *watch, Link *lp, int event)
    111 {
    112 	if (!(lp->flags & WATCH_FLAG_TYPE_MONITOR))
    113 		return 0;
    114 
    115 	if (!HasCapabilityFast(lp->value.client, CAP_EXTENDED_MONITOR))
    116 		return 0; /* this client does not support our notifications */
    117 
    118 	if (has_common_channels(client, lp->value.client))
    119 		return 0; /* will be notified anyway */
    120 
    121 	switch (event)
    122 	{
    123 		case WATCH_EVENT_AWAY:
    124 			if (HasCapability(lp->value.client, "away-notify"))
    125 				sendto_prefix_one(lp->value.client, client, NULL, ":%s AWAY :%s", client->name, client->user->away);
    126 			break;
    127 		case WATCH_EVENT_NOTAWAY:
    128 			if (HasCapability(lp->value.client, "away-notify"))
    129 				sendto_prefix_one(lp->value.client, client, NULL, ":%s AWAY", client->name);
    130 			break;
    131 		case WATCH_EVENT_LOGGEDIN:
    132 			if (HasCapability(lp->value.client, "account-notify"))
    133 				sendto_prefix_one(lp->value.client, client, NULL, ":%s ACCOUNT :%s", client->name, client->user->account);
    134 			break;
    135 		case WATCH_EVENT_LOGGEDOUT:
    136 			if (HasCapability(lp->value.client, "account-notify"))
    137 				sendto_prefix_one(lp->value.client, client, NULL, ":%s ACCOUNT :*", client->name);
    138 			break;
    139 		case WATCH_EVENT_USERHOST:
    140 			if (HasCapability(lp->value.client, "chghost"))
    141 				sendto_prefix_one(lp->value.client, client, NULL, ":%s CHGHOST %s %s", client->name, client->user->username, GetHost(client));
    142 			break;
    143 		case WATCH_EVENT_REALNAME:
    144 			if (HasCapability(lp->value.client, "setname"))
    145 				sendto_prefix_one(lp->value.client, client, NULL, ":%s SETNAME :%s", client->name, client->info);
    146 			break;
    147 		default:
    148 			break;
    149 	}
    150 	
    151 	return 0;
    152 }
    153