mirror of
https://github.com/unrealircd/unrealircd.git
synced 2026-07-07 10:03:13 +02:00
Use generic numeric 531 (ERR_CANTSENDTOUSER) for all such cases and use hook
CAN_SEND_TO_USER rather than HOOKTYPE_PRE_USERMSG (which is now removed). As for the numeric change: this makes it much easier for client devs. You rarely need to differentiate in the client code between the various causes. One only cares about detecting that the message was not sent and that the user needs to be informed. This replaces various NOTICEs, ERR_NOCTCP, ERR_NONONREG etc. with just the new numeric 531, which is taken from InspIRCd. The syntax is: :server 531 yourname targetname :reason for the block This makes it similar to numeric 404 (ERR_CANNOTSENDTOCHAN) that is used to indicate that a channel message was blocked. For module devs, the new hook CAN_SEND_TO_USER prototype is: int hooktype_can_send_to_user(Client *client, Client *target, char **text, char **errmsg, int notice); You can replace the text via this, by setting *text in your function. You can block the message, by returning HOOK_DENY. If doing so, then you must also set *errmsg to an appropriate value. Do not send any error message to the user! UnrealIRCd will take care of sending the error message for you, if you set *errmsg. Only if you need something special you could violate this rule, but preferably not! As you can see, CAN_SEND_TO_USER works just like CAN_SEND_TO_CHANNEL.
This commit is contained in:
@@ -20,7 +20,7 @@ long UMODE_CENSOR = 0L;
|
||||
|
||||
#define IsCensored(x) (x->umodes & UMODE_CENSOR)
|
||||
|
||||
char *censor_pre_usermsg(Client *client, Client *target, char *text, int notice);
|
||||
int censor_can_send_to_user(Client *client, Client *target, char **text, char **errmsg, int notice);
|
||||
|
||||
int censor_config_test(ConfigFile *, ConfigEntry *, int, int *);
|
||||
int censor_config_run(ConfigFile *, ConfigEntry *, int);
|
||||
@@ -46,7 +46,7 @@ MOD_INIT()
|
||||
|
||||
UmodeAdd(modinfo->handle, 'G', UMODE_GLOBAL, 0, NULL, &UMODE_CENSOR);
|
||||
|
||||
HookAddPChar(modinfo->handle, HOOKTYPE_PRE_USERMSG, 0, censor_pre_usermsg);
|
||||
HookAdd(modinfo->handle, HOOKTYPE_CAN_SEND_TO_USER, 0, censor_can_send_to_user);
|
||||
|
||||
HookAdd(modinfo->handle, HOOKTYPE_CONFIGRUN, 0, censor_config_run);
|
||||
return MOD_SUCCESS;
|
||||
@@ -237,22 +237,21 @@ char *stripbadwords_message(char *str, int *blocked)
|
||||
return stripbadwords(str, conf_badword_message, blocked);
|
||||
}
|
||||
|
||||
char *censor_pre_usermsg(Client *client, Client *target, char *text, int notice)
|
||||
int censor_can_send_to_user(Client *client, Client *target, char **text, char **errmsg, int notice)
|
||||
{
|
||||
int blocked;
|
||||
int blocked = 0;
|
||||
|
||||
if (MyUser(client) && IsCensored(target))
|
||||
{
|
||||
text = stripbadwords_message(text, &blocked);
|
||||
*text = stripbadwords_message(*text, &blocked);
|
||||
if (blocked)
|
||||
{
|
||||
if (!notice)
|
||||
sendnumeric(client, ERR_NOSWEAR, target->name);
|
||||
return NULL;
|
||||
*errmsg = "User does not accept private messages containing swearing";
|
||||
return HOOK_DENY;
|
||||
}
|
||||
}
|
||||
|
||||
return text;
|
||||
return HOOK_CONTINUE;
|
||||
}
|
||||
|
||||
// TODO: when stats is modular, make it call this for badwords
|
||||
|
||||
@@ -34,7 +34,7 @@ long UMODE_NOCTCP = 0L;
|
||||
|
||||
#define IsNoCTCP(client) (client->umodes & UMODE_NOCTCP)
|
||||
|
||||
char *noctcp_preusermsg(Client *client, Client *target, char *text, int notice);
|
||||
int noctcp_can_send_to_user(Client *client, Client *target, char **text, char **errmsg, int notice);
|
||||
|
||||
MOD_TEST()
|
||||
{
|
||||
@@ -47,7 +47,7 @@ CmodeInfo req;
|
||||
|
||||
UmodeAdd(modinfo->handle, 'T', UMODE_GLOBAL, 0, NULL, &UMODE_NOCTCP);
|
||||
|
||||
HookAddPChar(modinfo->handle, HOOKTYPE_PRE_USERMSG, 0, noctcp_preusermsg);
|
||||
HookAdd(modinfo->handle, HOOKTYPE_CAN_SEND_TO_USER, 0, noctcp_can_send_to_user);
|
||||
|
||||
MARK_AS_OFFICIAL_MODULE(modinfo);
|
||||
return MOD_SUCCESS;
|
||||
@@ -74,12 +74,12 @@ static int IsACTCP(char *s)
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *noctcp_preusermsg(Client *client, Client *target, char *text, int notice)
|
||||
int noctcp_can_send_to_user(Client *client, Client *target, char **text, char **errmsg, int notice)
|
||||
{
|
||||
if (MyUser(client) && !notice && IsNoCTCP(target) && !IsOper(client) && IsACTCP(text))
|
||||
if (MyUser(client) && !notice && IsNoCTCP(target) && !IsOper(client) && IsACTCP(*text))
|
||||
{
|
||||
sendnumeric(client, ERR_NOCTCP, target->name);
|
||||
return NULL;
|
||||
*errmsg = "User does not accept CTCPs";
|
||||
return HOOK_DENY;
|
||||
}
|
||||
return text;
|
||||
return HOOK_CONTINUE;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ ModuleHeader MOD_HEADER
|
||||
static long UMODE_PRIVDEAF = 0;
|
||||
static Umode *UmodePrivdeaf = NULL;
|
||||
|
||||
char *privdeaf_checkmsg(Client *, Client *, char *, int);
|
||||
int privdeaf_can_send_to_user(Client *client, Client *target, char **text, char **errmsg, int notice);
|
||||
|
||||
MOD_INIT()
|
||||
{
|
||||
@@ -32,7 +32,7 @@ MOD_INIT()
|
||||
return MOD_FAILED;
|
||||
}
|
||||
|
||||
HookAddPChar(modinfo->handle, HOOKTYPE_PRE_USERMSG, 0, privdeaf_checkmsg);
|
||||
HookAdd(modinfo->handle, HOOKTYPE_CAN_SEND_TO_USER, 0, privdeaf_can_send_to_user);
|
||||
|
||||
return MOD_SUCCESS;
|
||||
}
|
||||
@@ -47,13 +47,13 @@ MOD_UNLOAD()
|
||||
return MOD_SUCCESS;
|
||||
}
|
||||
|
||||
char *privdeaf_checkmsg(Client *client, Client *target, char *text, int notice)
|
||||
int privdeaf_can_send_to_user(Client *client, Client *target, char **text, char **errmsg, int notice)
|
||||
{
|
||||
if ((target->umodes & UMODE_PRIVDEAF) && !IsOper(client) &&
|
||||
!IsULine(client) && !IsServer(client) && (client != target))
|
||||
{
|
||||
sendnotice(client, "Message to '%s' not delivered: User does not accept private messages", target->name);
|
||||
return NULL;
|
||||
} else
|
||||
return text;
|
||||
*errmsg = "User does not accept private messages";
|
||||
return HOOK_DENY;
|
||||
}
|
||||
return HOOK_CONTINUE;
|
||||
}
|
||||
|
||||
@@ -35,13 +35,13 @@ ModuleHeader MOD_HEADER
|
||||
long UMODE_REGONLYMSG = 0L;
|
||||
|
||||
/* Forward declarations */
|
||||
char *regonlymsg_pre_usermsg(Client *client, Client *target, char *text, int notice);
|
||||
int regonlymsg_can_send_to_user(Client *client, Client *target, char **text, char **errmsg, int notice);
|
||||
|
||||
MOD_INIT()
|
||||
{
|
||||
UmodeAdd(modinfo->handle, 'R', UMODE_GLOBAL, 0, umode_allow_all, &UMODE_REGONLYMSG);
|
||||
|
||||
HookAddPChar(modinfo->handle, HOOKTYPE_PRE_USERMSG, 0, regonlymsg_pre_usermsg);
|
||||
HookAdd(modinfo->handle, HOOKTYPE_CAN_SEND_TO_USER, 0, regonlymsg_can_send_to_user);
|
||||
|
||||
MARK_AS_OFFICIAL_MODULE(modinfo);
|
||||
return MOD_SUCCESS;
|
||||
@@ -57,17 +57,16 @@ MOD_UNLOAD()
|
||||
return MOD_SUCCESS;
|
||||
}
|
||||
|
||||
char *regonlymsg_pre_usermsg(Client *client, Client *target, char *text, int notice)
|
||||
int regonlymsg_can_send_to_user(Client *client, Client *target, char **text, char **errmsg, int notice)
|
||||
{
|
||||
if (IsRegOnlyMsg(target) && !IsServer(client) && !IsULine(client) && !IsLoggedIn(client))
|
||||
{
|
||||
if (ValidatePermissionsForPath("client:override:message:regonlymsg",client,target,NULL,text))
|
||||
return text; /* TODO: this is actually an override */
|
||||
return HOOK_CONTINUE; /* bypass this restriction */
|
||||
|
||||
sendnumeric(client, ERR_NONONREG, target->name);
|
||||
|
||||
return NULL; /* Block the message */
|
||||
*errmsg = "You must identify to a registered nick to private message this user";
|
||||
return HOOK_DENY;
|
||||
}
|
||||
|
||||
return text;
|
||||
return HOOK_CONTINUE;
|
||||
}
|
||||
|
||||
@@ -36,13 +36,13 @@ ModuleHeader MOD_HEADER
|
||||
long UMODE_SECUREONLYMSG = 0L;
|
||||
|
||||
/* Forward declarations */
|
||||
char *secureonlymsg_pre_usermsg(Client *client, Client *target, char *text, int notice);
|
||||
int secureonlymsg_can_send_to_user(Client *client, Client *target, char **text, char **errmsg, int notice);
|
||||
|
||||
MOD_INIT()
|
||||
{
|
||||
UmodeAdd(modinfo->handle, 'Z', UMODE_GLOBAL, 0, umode_allow_all, &UMODE_SECUREONLYMSG);
|
||||
|
||||
HookAddPChar(modinfo->handle, HOOKTYPE_PRE_USERMSG, 0, secureonlymsg_pre_usermsg);
|
||||
HookAdd(modinfo->handle, HOOKTYPE_CAN_SEND_TO_USER, 0, secureonlymsg_can_send_to_user);
|
||||
|
||||
MARK_AS_OFFICIAL_MODULE(modinfo);
|
||||
return MOD_SUCCESS;
|
||||
@@ -58,36 +58,29 @@ MOD_UNLOAD()
|
||||
return MOD_SUCCESS;
|
||||
}
|
||||
|
||||
char *secureonlymsg_pre_usermsg(Client *client, Client *target, char *text, int notice)
|
||||
int secureonlymsg_can_send_to_user(Client *client, Client *target, char **text, char **errmsg, int notice)
|
||||
{
|
||||
if (IsSecureOnlyMsg(target) && !IsServer(client) && !IsULine(client) && !IsSecureConnect(client))
|
||||
{
|
||||
if (ValidatePermissionsForPath("client:override:message:secureonlymsg",client,target,NULL,text))
|
||||
return text; /* TODO: this is actually an override */
|
||||
return HOOK_CONTINUE; /* bypass this restriction */
|
||||
|
||||
/* A numeric is preferred to indicate the user cannot message.
|
||||
* 492 is ERR_NOCTCP but apparently is also used by some other ircd(s) as a
|
||||
* general "cannot send message" numeric (similar to the generic
|
||||
* ERR_CANNOTSENDTOCHAN for channel messaging).
|
||||
*/
|
||||
sendto_one(client, NULL, ":%s 492 %s :Cannot send to user %s (You must be connected via SSL/TLS to message this user)",
|
||||
me.name, client->name, target->name);
|
||||
|
||||
return NULL; /* Block the message */
|
||||
*errmsg = "You must be connected via SSL/TLS to message this user";
|
||||
return HOOK_DENY;
|
||||
} else
|
||||
if (IsSecureOnlyMsg(client) && !IsSecureConnect(target) && !IsULine(target))
|
||||
{
|
||||
if (ValidatePermissionsForPath("client:override:message:secureonlymsg",client,target,NULL,text))
|
||||
return text; /* TODO: this is actually an override */
|
||||
return HOOK_CONTINUE; /* bypass this restriction */
|
||||
|
||||
/* Similar to above but in this case we are +Z and are trying to message
|
||||
* an SSL user (who does not have +Z set, note the 'else'). This does not
|
||||
* make sense since they could never message back to us. Better block the
|
||||
* message than leave the user confused.
|
||||
*/
|
||||
sendto_one(client, NULL, ":%s 492 %s :Cannot send to user %s (You have user mode +Z set but are not connected via SSL/TLS)",
|
||||
me.name, client->name, target->name);
|
||||
*errmsg = "Recipient is not connected via SSL/TLS and you are +Z";
|
||||
return HOOK_DENY;
|
||||
}
|
||||
|
||||
return text;
|
||||
return HOOK_CONTINUE;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user