From 80ed79402a21b9e53eef9d4d906b2b0ae4bf44f7 Mon Sep 17 00:00:00 2001 From: LDA Date: Tue, 9 Jul 2024 22:07:16 +0200 Subject: [PATCH] [MOD] Make PL changes not point the real user --- src/XMPPThread.c | 47 +++++++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/src/XMPPThread.c b/src/XMPPThread.c index ed7ba51..f5a52f7 100644 --- a/src/XMPPThread.c +++ b/src/XMPPThread.c @@ -1127,19 +1127,25 @@ PresenceStanza(ParseeData *args, XMLElement *stanza) #define IsStatus(code) (status && \ StrEquals(HashMapGet(status->attrs, "code"), #code)) char *jid = item ? HashMapGet(item->attrs, "jid") : NULL; + char *trim = ParseeTrimJID(jid); char *from = NULL; char *type = HashMapGet(stanza->attrs, "type"); char *room = ParseeGetBridgedRoom(args, stanza); char *decode_from = ParseeLookupJID(oid); - char *from_matrix = ParseeDecodeMXID(decode_from); + char *real_matrix = ParseeDecodeMXID(decode_from); + char *matrix_user_pl = ParseeEncodeJID(args->config, trim, false); char *affiliation = HashMapGet(item->attrs, "affiliation"); int power_level = 0; + char *parsee = ParseeMXID(args); - if (!from_matrix || *from_matrix != '@') + Free(trim); + + if (!real_matrix || *real_matrix != '@') { - Free(from_matrix); - from_matrix = ParseeEncodeJID(args->config, decode_from, false); + Free(real_matrix); + real_matrix = ParseeEncodeJID(args->config, decode_from, false); } + if (StrEquals(affiliation, "owner")) { power_level = 98; @@ -1165,52 +1171,51 @@ PresenceStanza(ParseeData *args, XMLElement *stanza) if (room) { HashMap *powers = ASGetPL(args->config, room); - int64_t level = GrabInteger(powers, 2, "users", from_matrix); - char *parsee = ParseeMXID(args); + HashMap *users = GrabObject(powers, 1, "users"); + int64_t level = GrabInteger(powers, 2, "users", matrix_user_pl); /* I may or may not have fucked up the state hard with this * lacking any checking. (--gen) */ - if (StrEquals(parsee, from_matrix)) + if (StrEquals(parsee, matrix_user_pl)) { /* TODO: Give the user an achievement, this is goofy. */ Log(LOG_ERR, "BAD PL DOWNGRADE (%d->%d)", level, power_level); } - if (powers && level != power_level && - !StrEquals(parsee, from_matrix)) + if (users && level != power_level && + !StrEquals(parsee, matrix_user_pl) && + matrix_user_pl) { - HashMap *users = GrabObject(powers, 1, "users"); JsonValue *val = JsonValueInteger(power_level); - JsonValueFree(HashMapSet(users, - from_matrix, val - )); + JsonValueFree(JsonSet(users, val, 1, matrix_user_pl)); ASSetPL(args->config, room, powers); + JsonValueFree(val); } else { JsonFree(powers); } - Free(parsee); } - if (StrEquals(type, "unavailable")) + + if (StrEquals(type, "unavailable") && !StrEquals(parsee, real_matrix)) { /* If not an MXID, use the Parsee user */ if (IsStatus(301)) { - ASBan(args->config, room, from_matrix); + ASBan(args->config, room, real_matrix); } else if (IsStatus(307)) { - ASKick(args->config, room, from_matrix); + ASKick(args->config, room, real_matrix); } else if (IsStatus(303)) { char *nick = HashMapGet(item->attrs, "nick"); - ASSetName(args->config, from_matrix, nick); + ASSetName(args->config, real_matrix, nick); } else { - ASLeave(args->config, room, from_matrix); + ASLeave(args->config, room, real_matrix); } } @@ -1221,7 +1226,9 @@ PresenceStanza(ParseeData *args, XMLElement *stanza) Free(from); Free(decode_from); - Free(from_matrix); + Free(real_matrix); + Free(matrix_user_pl); + Free(parsee); Free(room); } else if (vc)