Skip to content

Commit

Permalink
Merge pull request #39 from Dunedan/fix-profile-requests-with-invalid…
Browse files Browse the repository at this point in the history
…-jids

Fix profile requests for invalid player names
  • Loading branch information
Dunedan authored May 24, 2024
2 parents 0754214 + 2a85406 commit 52285e5
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions xpartamupp/echelon.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 52285e5

Please sign in to comment.