From 2a854063629dbedef465e8954abbf8840e308a90 Mon Sep 17 00:00:00 2001 From: Daniel Roschka Date: Wed, 15 May 2024 08:41:09 +0200 Subject: [PATCH] Fix profile requests for invalid player names Previously if a player used Pyrogenesis to look up the profile of another player and typed in a player name, which doesn't resemble a valid local part of a JID, EcheLOn would throw an exception. This commit fixes that and properly returns the expected response when the queried player doesn't exist. --- xpartamupp/echelon.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/xpartamupp/echelon.py b/xpartamupp/echelon.py index 3362fe5..d5063ec 100755 --- a/xpartamupp/echelon.py +++ b/xpartamupp/echelon.py @@ -29,7 +29,7 @@ from datetime import datetime, timedelta, timezone from slixmpp import ClientXMPP -from slixmpp.jid import JID +from slixmpp.jid import JID, InvalidJID from slixmpp.stanza import Iq from slixmpp.xmlstream.handler import Callback from slixmpp.xmlstream.matcher import StanzaPath @@ -761,22 +761,23 @@ def _send_profile(self, iq, player_nick): profile for """ + player_jid = None + jid_str = self.plugin['xep_0045'].get_jid_property(self.room, player_nick, 'jid') if jid_str: player_jid = JID(jid_str) player_jid.resource = "0ad" else: - player_jid = None - - # The player the profile got requested for is not online, so - # let's assume the JID contains the nick as local part. - if not player_jid: - player_jid = JID('%s@%s/%s' % (player_nick, self.sjid.domain, '0ad')) + # The player the profile got requested for is not online, so + # let's assume the JID contains the nick as local part. + try: + player_jid = JID('%s@%s/%s' % (player_nick, self.sjid.domain, '0ad')) + except InvalidJID: + pass - try: + if player_jid: stats = self.leaderboard.get_profile(player_jid) - except Exception: - logger.exception("Failed to get leaderboard profile for player %s", player_jid) + else: stats = {} iq = iq.reply()