From 1a15131d2d71f337cc30e65ec6ef768c08f6b279 Mon Sep 17 00:00:00 2001 From: scythetwirler Date: Sun, 30 Aug 2015 17:50:16 +0000 Subject: [PATCH] Lobby bot optimizations. This was SVN commit r16964. --- binaries/data/mods/public/gui/lobby/lobby.js | 3 --- source/tools/XpartaMuPP/XpartaMuPP.py | 16 +++++++--------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/binaries/data/mods/public/gui/lobby/lobby.js b/binaries/data/mods/public/gui/lobby/lobby.js index 8cef1e1b33..6548ed418a 100644 --- a/binaries/data/mods/public/gui/lobby/lobby.js +++ b/binaries/data/mods/public/gui/lobby/lobby.js @@ -46,7 +46,6 @@ function init(attribs) Engine.LobbySetPlayerPresence("available"); Engine.SendGetGameList(); Engine.SendGetBoardList(); - Engine.SendGetRatingList(); updatePlayerList(); updateSubject(Engine.LobbyGetRoomSubject()); @@ -703,7 +702,6 @@ function onTick() presenceList.push(status); nickList.push(nick); ratingList.push(String(rating)); - Engine.SendGetRatingList(); addChatMessage({ "text": "/special " + sprintf(translate("%(nick)s has joined."), { nick: nick }), "key": g_specialKey }); break; case "leave": @@ -728,7 +726,6 @@ function onTick() // presence stays the same nickList[nickIndex] = message.data; addChatMessage({ "text": "/special " + sprintf(translate("%(oldnick)s is now known as %(newnick)s."), { oldnick: nick, newnick: message.data }), "key": g_specialKey }); - Engine.SendGetRatingList(); break; case "presence": if (nickIndex == -1) // Changed presence, but not online (shouldn't ever happen) diff --git a/source/tools/XpartaMuPP/XpartaMuPP.py b/source/tools/XpartaMuPP/XpartaMuPP.py index 7b174b92f1..d149dfebfb 100644 --- a/source/tools/XpartaMuPP/XpartaMuPP.py +++ b/source/tools/XpartaMuPP/XpartaMuPP.py @@ -264,7 +264,7 @@ class LeaderboardList(): """ ratinglist = {} for JID in nicks.keys(): - players = db.query(Player).filter(Player.jid.ilike(str(JID))) + players = db.query(Player.jid, Player.rating).filter(Player.jid.ilike(str(JID))) if players.first(): if players.first().rating == -1: ratinglist[nicks[JID]] = {'name': nicks[JID], 'rating': ''} @@ -490,6 +490,7 @@ class XpartaMuPP(sleekxmpp.ClientXMPP): self.room = room self.nick = nick + self.ratingListUpdate = False # Game collection self.gameList = GameList() @@ -545,6 +546,7 @@ class XpartaMuPP(sleekxmpp.ClientXMPP): """ Process presence stanza from a chat room. """ + self.ratingListUpdate = True if presence['muc']['nick'] != self.nick: # If it doesn't already exist, store player JID mapped to their nick. if str(presence['muc']['jid']) not in self.nicks: @@ -616,13 +618,6 @@ class XpartaMuPP(sleekxmpp.ClientXMPP): except: traceback.print_exc() logging.error("Failed to process leaderboardlist request from %s" % iq['from'].bare) - elif command == 'getratinglist': - try: - self.leaderboard.getOrCreatePlayer(iq['from']) - self.sendRatingList(iq['from']) - except: - traceback.print_exc() - logging.error("Failed to process ratinglist request from %s" % iq['from'].bare) else: logging.error("Failed to process boardlist request from %s" % iq['from'].bare) elif 'profile' in iq.plugins: @@ -690,6 +685,9 @@ class XpartaMuPP(sleekxmpp.ClientXMPP): logging.error("Failed to update game statistics for %s" % iq['from'].bare) else: logging.error("Failed to process stanza type '%s' received from %s" % iq['type'], iq['from'].bare) + if self.ratingListUpdate == True: + self.sendRatingList() + self.ratingListUpdate = False def sendGameList(self, to = ""): """ @@ -778,7 +776,7 @@ class XpartaMuPP(sleekxmpp.ClientXMPP): iq.send(block=False, now=True) except: logging.error("Failed to send leaderboard list") - + def sendRatingList(self, to = ""): """ Send the rating list.