Remove invite moddata access from core (without breaking the api)

This commit is contained in:
k4be 2021-07-15 16:13:02 +02:00
parent db8ff94e7a
commit 3ede47c7fa
No known key found for this signature in database
GPG key ID: CF966708422300DC
3 changed files with 34 additions and 15 deletions

View file

@ -1163,6 +1163,8 @@ extern void SavePersistentLongX(ModuleInfo *modinfo, char *varshortname, long va
#define HOOKTYPE_CLOSE_CONNECTION 103
/** See hooktype_connect_extinfo() */
#define HOOKTYPE_CONNECT_EXTINFO 104
/** See hooktype_is_invited() */
#define HOOKTYPE_IS_INVITED 105
/* Adding a new hook here?
* 1) Add the #define HOOKTYPE_.... with a new number
* 2) Add a hook prototype (see below)
@ -2104,6 +2106,15 @@ int hooktype_close_connection(Client *client);
*/
int hooktype_connect_extinfo(Client *client, NameValuePrioList **list);
/** Called when a user wants to join a channel that require invitation.
* Use hook priorities to enforce a specific policy, especially denying the invitation.
* @param client The client
* @param channel The channel client is willing to join
* @param invited Set to 0 for user who should not be invited, set to 1 if the user is invited.
* @return The return value is ignored (use return 0)
*/
int hooktype_is_invited(Client *client, Channel *channel, int *invited);
/** @} */
#ifdef GCC_TYPECHECKING
@ -2213,7 +2224,8 @@ _UNREAL_ERROR(_hook_error_incompatible, "Incompatible hook function. Check argum
((hooktype == HOOKTYPE_CONFIGRUN_EX) && !ValidateHook(hooktype_configrun_ex, func)) || \
((hooktype == HOOKTYPE_ACCOUNT_LOGIN) && !ValidateHook(hooktype_account_login, func)) || \
((hooktype == HOOKTYPE_CLOSE_CONNECTION) && !ValidateHook(hooktype_close_connection, func)) || \
((hooktype == HOOKTYPE_CONNECT_EXTINFO) && !ValidateHook(hooktype_connect_extinfo, func)) ) \
((hooktype == HOOKTYPE_CONNECT_EXTINFO) && !ValidateHook(hooktype_connect_extinfo, func)) || \
((hooktype == HOOKTYPE_IS_INVITED) && !ValidateHook(hooktype_is_invited, func)) ) \
_hook_error_incompatible();
#endif /* GCC_TYPECHECKING */

View file

@ -972,26 +972,15 @@ Channel *get_channel(Client *client, char *chname, int flag)
return channel;
}
#warning create hook or efunc
#define CLIENT_INVITES(client) (moddata_local_client(client, findmoddata_byname("invite", MODDATATYPE_LOCAL_CLIENT)).ptr)
#define CHANNEL_INVITES(channel) (moddata_channel(channel, findmoddata_byname("invite", MODDATATYPE_CHANNEL)).ptr)
/** Is the user 'client' invited to channel 'channel' by a chanop?
* @param client The client who was invited
* @param channel The channel to which the person was invited
*/
int is_invited(Client *client, Channel *channel)
{
Link *lp;
if(!MyConnect(client))
return 0; // not handling invite lists for remote clients
for (lp = CLIENT_INVITES(client); lp; lp = lp->next)
if (lp->value.channel == channel)
return 1;
return 0;
int invited = 0;
RunHook3(HOOKTYPE_IS_INVITED, client, channel, &invited);
return invited;
}
/** Subtract one user from channel i. Free the channel if it became empty.

View file

@ -38,6 +38,7 @@ void del_invite(Client *client, Channel *channel);
static int invite_channel_destroy(Channel *channel, int *should_destroy);
int invite_user_quit(Client *client, MessageTag *mtags, char *comment);
int invite_user_join(Client *client, Channel *channel, MessageTag *mtags, char *parv[]);
int invite_is_invited(Client *client, Channel *channel, int *invited);
ModuleHeader MOD_HEADER
= {
@ -81,6 +82,7 @@ MOD_INIT()
HookAdd(modinfo->handle, HOOKTYPE_CHANNEL_DESTROY, 1000000, invite_channel_destroy);
HookAdd(modinfo->handle, HOOKTYPE_LOCAL_QUIT, 0, invite_user_quit);
HookAdd(modinfo->handle, HOOKTYPE_LOCAL_JOIN, 0, invite_user_join);
HookAdd(modinfo->handle, HOOKTYPE_IS_INVITED, 0, invite_is_invited);
return MOD_SUCCESS;
}
@ -145,6 +147,22 @@ void send_invite_list(Client *client)
sendnumeric(client, RPL_ENDOFINVITELIST);
}
int invite_is_invited(Client *client, Channel *channel, int *invited)
{
Link *lp;
if(!MyConnect(client))
return 0; // not handling invite lists for remote clients
for (lp = CLIENT_INVITES(client); lp; lp = lp->next)
if (lp->value.channel == channel)
{
*invited = 1;
return 0;
}
return 0;
}
/*
** cmd_invite
** parv[1] - user to invite