Skip to content

Commit 3d1d9e4

Browse files
authored
Properly deal with joins.
1 parent 82ab2ea commit 3d1d9e4

File tree

1 file changed

+31
-12
lines changed

1 file changed

+31
-12
lines changed

files/restrict-chans.c

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* LICENSE: GPLv3
2+
* LICENSE: GPLv3 or later
33
* Copyright Ⓒ 2023 Valerie Pond
44
*
55
* Restricts channels to registered users
@@ -23,12 +23,12 @@ module
2323
*** <<<MODULE MANAGER END>>>
2424
*/
2525
#include "unrealircd.h"
26-
int isreg_can_join(Client *client, Channel *channel, const char *key, char **errmsg);
27-
26+
int isreg_can_join(Client *client, Channel *channel, const char *key);
27+
int isreg_check_join(Client *client, Channel *channel, const char *key, char **errmsg);
2828
ModuleHeader MOD_HEADER =
2929
{
3030
"third/restrict-chans",
31-
"1.1",
31+
"1.2",
3232
"Restrict channel creation to logged-in users",
3333
"Valware",
3434
"unrealircd-6",
@@ -37,7 +37,8 @@ MOD_INIT()
3737
{
3838
MARK_AS_GLOBAL_MODULE(modinfo);
3939

40-
HookAdd(modinfo->handle, HOOKTYPE_CAN_JOIN, 0, isreg_can_join);
40+
HookAdd(modinfo->handle, HOOKTYPE_CAN_JOIN, 0, isreg_check_join);
41+
HookAdd(modinfo->handle, HOOKTYPE_PRE_LOCAL_JOIN, 0, isreg_can_join);
4142
return MOD_SUCCESS;
4243
}
4344

@@ -55,16 +56,34 @@ MOD_TEST()
5556
return MOD_SUCCESS;
5657
}
5758

58-
int isreg_can_join(Client *client, Channel *channel, const char *key, char **errmsg)
59+
int isreg_check_join(Client *client, Channel *channel, const char *key, char **errmsg)
5960
{
60-
/* allow people to join permanent empty channels and allow opers to create new channels */
61-
if (!channel->users && !IsLoggedIn(client) && !has_channel_mode(channel, 'P') && !IsOper(client))
61+
if (has_channel_mode(channel, 'P')) // it's permanent, continue;
62+
return HOOK_CONTINUE;
63+
if (channel->users == 0)
6264
{
63-
/* there aren't actually any users in the channel but sub1_from_channel()
64-
will destroy the channel best without duplicating code */
65-
sub1_from_channel(channel);
65+
if (IsLoggedIn(client))
66+
return HOOK_CONTINUE;
67+
6668
*errmsg = "%s :You must be logged in to create new channels", channel->name;
6769
return ERR_CANNOTDOCOMMAND;
6870
}
69-
return 0;
71+
return HOOK_CONTINUE;
72+
73+
}
74+
75+
int isreg_can_join(Client *client, Channel *channel, const char *key)
76+
{
77+
if (has_channel_mode(channel, 'P')) // it's permanent, continue;
78+
return HOOK_CONTINUE;
79+
/* allow people to join permanent empty channels and allow opers to create new channels */
80+
if (channel->users == 0)
81+
{
82+
if (IsLoggedIn(client))
83+
return HOOK_CONTINUE;
84+
85+
sendnumeric(client, ERR_CANNOTDOCOMMAND, channel->name, "You must be logged in to create new channels");
86+
return HOOK_DENY;
87+
}
88+
return HOOK_CONTINUE;
7089
}

0 commit comments

Comments
 (0)