Skip to content
This repository was archived by the owner on Jun 6, 2021. It is now read-only.

Commit 5c55fa3

Browse files
committed
make override_unaff actually work properly
alternative commit message: "i'm really dumb 2: electric boogaloo"
1 parent 71842e7 commit 5c55fa3

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

facilities.c

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -293,23 +293,24 @@ static void mod_deinit(module_unload_intent_t intent)
293293
hook_del_hook("incoming_host_change", on_host_change);
294294
}
295295

296-
static void facility_set_cloak(user_t *u, const char * cloak, int cloak_override)
296+
static void facility_set_cloak(user_t *u, const char * cloak, bool cloak_override)
297297
{
298298
metadata_add(u, "syn:facility-cloak", cloak);
299299

300-
if (cloak_override > 0)
301-
{
300+
if (cloak_override)
302301
metadata_add(u, "syn:facility-cloak-override", "1");
303-
// Check whether they've already been cloaked. If vhost != host and
304-
// vhost isn't unaffiliated/*, then they have a project cloak that we shouldn't override.
305-
if (strncmp(u->vhost, "unaffiliated/", 13) &&
306-
strncmp(u->vhost, u->host, HOSTLEN))
307-
return;
308302

309-
// Don't send out a no-op cloak change either
310-
if (strcmp(u->vhost, cloak))
311-
user_sethost(syn->me, u, cloak);
312-
}
303+
// Check whether they've already been cloaked. If vhost != host, and
304+
// vhost isn't unaffiliated/*, then they have a project cloak that we shouldn't override.
305+
// If vhost != host, and vhost *is* unaffiliated but we don't override unaffiliated cloaks,
306+
// don't do so either.
307+
if ((strncmp(u->vhost, "unaffiliated/", 13) != 0 || !cloak_override) &&
308+
strncmp(u->vhost, u->host, HOSTLEN) != 0)
309+
return;
310+
311+
// Don't send out a no-op cloak change either
312+
if (strcmp(u->vhost, cloak))
313+
user_sethost(syn->me, u, cloak);
313314
}
314315

315316
void facility_newuser(hook_user_nick_t *data)
@@ -437,6 +438,11 @@ void facility_newuser(hook_user_nick_t *data)
437438
return;
438439
}
439440

441+
if (cloak_override > 0)
442+
cloak_override = 1;
443+
else
444+
cloak_override = 0;
445+
440446
char new_vhost[HOSTLEN];
441447
mowgli_strlcpy(new_vhost, u->host, HOSTLEN);
442448
switch (cloak)
@@ -953,14 +959,13 @@ static void on_host_change(void *vdata)
953959
if (!md)
954960
return;
955961

956-
if (!metadata_find(data->user, "syn:facility-cloak-override"))
957-
return;
962+
metadata_t *override = metadata_find(data->user, "syn:facility-cloak-override");
958963

959-
if (0 == strncmp(data->user->vhost, "unaffiliated/", 13) ||
964+
if ((0 == strncmp(data->user->vhost, "unaffiliated/", 13) && override) ||
960965
0 == strncmp(data->user->vhost, data->user->host, HOSTLEN))
961966
{
962-
// Override the host change -- a facility cloak is being replaced by unaffiliated, or a facility by
963-
// another facility (this happens when removing a nickserv account vhost while a gateway user is logged in)
967+
// Override the host change -- a facility cloak is being replaced by unaffiliated while we're disallowing it,
968+
// or a facility by another facility (this happens when removing a nickserv account vhost while a gateway user is logged in)
964969
strshare_unref(data->user->vhost);
965970
data->user->vhost = strshare_get(md->value);
966971
}

0 commit comments

Comments
 (0)