Lobby bot optimizations.

This was SVN commit r16964.
This commit is contained in:
scythetwirler 2015-08-30 17:50:16 +00:00
parent 63e42fbd31
commit 1a15131d2d
2 changed files with 7 additions and 12 deletions

View File

@ -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)

View File

@ -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.