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

Commit

Permalink
Remove relay of player online information
Browse files Browse the repository at this point in the history
Previously XpartaMuPP relayed information of players coming online to
EcheLOn. As EcheLOn has to be part of the lobby-MUC as well (e.g. to
post game results) it can watch and handle this information without
having to rely on XpartaMuPP.
  • Loading branch information
Dunedan committed Oct 29, 2017
1 parent bd80add commit 1c5a3a6
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 59 deletions.
20 changes: 4 additions & 16 deletions xpartamupp/echelon.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@

from xpartamupp.elo import get_rating_adjustment
from xpartamupp.lobby_ranking import Game, Player, PlayerInfo
from xpartamupp.stanzas import (BoardListXmppPlugin, GameReportXmppPlugin, PlayerXmppPlugin,
ProfileXmppPlugin)
from xpartamupp.stanzas import (BoardListXmppPlugin, GameReportXmppPlugin, ProfileXmppPlugin)

# Rating that new players should be inserted into the
# database with, before they've played any games.
Expand Down Expand Up @@ -470,13 +469,10 @@ def __init__(self, sjid, password, room, nick, leaderboard):
# stanza
self.nicks = {}

register_stanza_plugin(Iq, PlayerXmppPlugin)
register_stanza_plugin(Iq, BoardListXmppPlugin)
register_stanza_plugin(Iq, GameReportXmppPlugin)
register_stanza_plugin(Iq, ProfileXmppPlugin)

self.register_handler(Callback('Iq Player', StanzaPath('iq/player'),
self._iq_player_handler, instream=True))
self.register_handler(Callback('Iq Boardlist', StanzaPath('iq/boardlist'),
self._iq_board_list_handler, instream=True))
self.register_handler(Callback('Iq GameReport', StanzaPath('iq/gamereport'),
Expand Down Expand Up @@ -515,6 +511,8 @@ def _muc_online(self, presence):
self.nicks[jid] = nick
logging.debug("Client '%s' connected with a nick of '%s'.", jid, nick)

self.leaderboard.get_or_create_player(jid)

def _muc_offline(self, presence):
"""Remove leaving players from the list of players.
Expand All @@ -529,24 +527,14 @@ def _muc_offline(self, presence):
if jid in self.nicks:
del self.nicks[jid]

def _iq_player_handler(self, iq):
"""Handle new clients announcing themselves as online."""
if iq['type'] == 'set':
player = iq['player']['online']
self.leaderboard.get_or_create_player(player)
return

logging.warning("Failed to process stanza type '%s' received from %s",
iq['type'], iq['from'].bare)

def _iq_board_list_handler(self, iq):
"""Handle incoming leaderboard list requests."""
if iq['type'] == 'get':
command = iq['boardlist']['command']
recipient = iq['boardlist']['recipient']
self.leaderboard.get_or_create_player(str(iq['from']))
if command == 'getleaderboard':
try:
self.leaderboard.get_or_create_player(str(iq['from']))
self._send_leaderboard(iq['from'], recipient)
except Exception:
logging.exception("Failed to process get leaderboard request from %s",
Expand Down
19 changes: 0 additions & 19 deletions xpartamupp/stanzas.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,25 +112,6 @@ def get_game(self):
return data


class PlayerXmppPlugin(ElementBase):
"""Class for custom player stanza extension."""

name = 'query'
namespace = 'jabber:iq:player'
interfaces = {'online'}
sub_interfaces = interfaces
plugin_attrib = 'player'

def add_player_online(self, player):
"""Add a player to the extension.
Arguments:
player (str): JID of the player to add
"""
self.xml.append(ET.fromstring("<online>%s</online>" % player))


class ProfileXmppPlugin(ElementBase):
"""Class for custom profile."""

Expand Down
25 changes: 1 addition & 24 deletions xpartamupp/xpartamupp.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from sleekxmpp.xmlstream.matcher import StanzaPath

from xpartamupp.stanzas import (BoardListXmppPlugin, GameListXmppPlugin, GameReportXmppPlugin,
PlayerXmppPlugin, ProfileXmppPlugin)
ProfileXmppPlugin)


class Games(object):
Expand Down Expand Up @@ -123,7 +123,6 @@ def __init__(self, sjid, password, room, nick, ratings_bot):
# stanza
self.nicks = {}

register_stanza_plugin(Iq, PlayerXmppPlugin)
register_stanza_plugin(Iq, GameListXmppPlugin)
register_stanza_plugin(Iq, BoardListXmppPlugin)
register_stanza_plugin(Iq, GameReportXmppPlugin)
Expand Down Expand Up @@ -168,7 +167,6 @@ def _muc_online(self, presence):
if self.ratings_bot in self.nicks:
self._relay_rating_list_request(self.ratings_bot)

self._relay_player_online(jid)
if nick != self.nick:
if jid not in self.nicks:
self.nicks[jid] = nick
Expand Down Expand Up @@ -420,27 +418,6 @@ def _relay_profile_request(self, recipient, player, command):
except Exception:
logging.exception("Failed to send profile request")

def _relay_player_online(self, jid):
"""Tells EcheLOn that someone comes online.
Arguments:
jid (?): ?
"""
to = self.ratings_bot
if to not in self.nicks:
return

iq = self.make_iq_set(ito=to)
stanza = PlayerXmppPlugin()
stanza.add_player_online(jid)
iq.set_payload(stanza)

try:
iq.send(block=False, now=True)
except Exception:
logging.exception("Failed to send player muc online")

def _relay_game_report(self, data, sender):
"""Relay a game report to EcheLOn."""
to = self.ratings_bot
Expand Down

0 comments on commit 1c5a3a6

Please sign in to comment.