- diff -r c01aae84ab30 usr/share/pyshared/pokersocial/auth.py
- --- a/usr/share/pyshared/pokersocial/auth.py Thu Jan 28 11:38:05 2010 +0000
- +++ b/usr/share/pyshared/pokersocial/auth.py Thu Jan 28 14:13:05 2010 +0000
- -23,17 +23,38 @@
- from pokersocial.core import Pokersocial
- +_opensocial2serial = {}
- +_serial2opensocial = {}
- +_next_serial = 100
- +
- +def opensocial2serial(opensocial_id):
- + global _opensocial2serial, _serial2opensocial, _next_serial
- + if not _opensocial2serial.has_key(opensocial_id):
- + _opensocial2serial[opensocial_id] = _next_serial
- + _serial2opensocial[_next_serial] = opensocial_id
- + _next_serial += 1
- + return _opensocial2serial[opensocial_id]
- +def serial2opensocial(serial):
- + global _serial2opensocial
- + return _serial2opensocial[serial]
- +
- def update_session(site, request):
- + global next_serial
- + global opensocial2serial
- if site.verbose > 3:
- site.message("pokersocial: ")
- - serial = int(request.args['opensocial_owner_id'][0])
- - if serial == int(request.args['opensocial_viewer_id'][0]):
- + opensocial_id = request.args['opensocial_owner_id'][0]
- +
- + serial = opensocial2serial(opensocial_id)
- +
- + if opensocial_id == request.args['opensocial_viewer_id'][0]:
- cert_url = urllib.unquote(request.args['xoauth_signature_publickey'][0])
- container = Pokersocial.info(site.resource.service)['url2container'][cert_url]
- - info = Pokersocial.importUser(site.resource.service, container, serial)
- + info = Pokersocial.importUser(site.resource.service, container, opensocial_id)
- + info['serial'] = serial
- Pokersocial.updateUser(site.resource.service, info)
- Pokersocial.updatePlayerMoney(site.resource.service, serial,
- - Pokersocial.importPlayerMoney(site.resource.service, container, serial))
- + Pokersocial.importPlayerMoney(site.resource.service, container, opensocial_id))
- else:
- info = None
- session = request.getSession()
- diff -r c01aae84ab30 usr/share/pyshared/pokersocial/auth.pyc
- Binary file usr/share/pyshared/pokersocial/auth.pyc has changed
- diff -r c01aae84ab30 usr/share/pyshared/pokersocial/core.py
- --- a/usr/share/pyshared/pokersocial/core.py Thu Jan 28 11:38:05 2010 +0000
- +++ b/usr/share/pyshared/pokersocial/core.py Thu Jan 28 14:13:05 2010 +0000
- -191,16 +191,16 @@
- assert cursor.rowcount in (1, 2), s
- @staticmethod
- - def exportPlayerMoney(service, container, serial, money):
- + def exportPlayerMoney(service, container, opensocial_id, money):
- app_id = container['config'].get('opensocial_app_id')
- - r = request.UpdateAppDataRequest(str(serial), '@self', app_id, ['money'], { 'money': simplejson.dumps(dict(money)) })
- + r = request.UpdateAppDataRequest(opensocial_id, '@self', app_id, ['money'], { 'money': simplejson.dumps(dict(money)) })
- if service.verbose > 2:
- - service.message("pokersocial.exportPlayerMoney(serial = %d, opensocial_app_id = %s): query params = %s rpc body = %s" % ( serial, app_id, r.get_query_params(), r.get_rpc_body() ))
- + service.message("pokersocial.exportPlayerMoney(serial = %s, opensocial_app_id = %s): query params = %s rpc body = %s" % ( opensocial_id, app_id, r.get_query_params(), r.get_rpc_body() ))
- try:
- - data = container['context'].send_request(r)
- + data = container['context'].send_request(r, True)
- except errors.BadResponseError, e:
- if e.code == 404 and 'Data Not Found' in e.message:
- - service.error("pokersocial.exportPlayerMoney(serial = %d, opensocial_app_id = %s): <= %s" % ( serial, app_id, e.message ))
- + service.error("pokersocial.exportPlayerMoney(serial = %s, opensocial_app_id = %s): <= %s" % ( opensocial_id, app_id, e.message ))
- data = None
- else:
- raise
- -209,23 +209,23 @@
- return data
- @staticmethod
- - def importPlayerMoney(service, container, serial):
- + def importPlayerMoney(service, container, opensocial_id):
- app_id = container['config'].get('opensocial_app_id')
- - r = request.FetchAppDataRequest(str(serial), '@self', app_id, ['money'])
- + r = request.FetchAppDataRequest(opensocial_id, '@self', app_id, ['money'])
- try:
- - data = container['context'].send_request(r)
- + data = container['context'].send_request(r, True)
- except errors.BadResponseError, e:
- if e.code == 404 and 'Data Not Found' in e.message:
- - service.error("pokersocial.importPlayerMoney(serial = %d, opensocial_app_id = %s): <= %s" % ( serial, app_id, e.message ))
- + service.error("pokersocial.importPlayerMoney(opensocial_id = %s, opensocial_app_id = %s): <= %s" % ( opensocial_id, app_id, e.message ))
- data = None
- else:
- raise
- except:
- raise
- if service.verbose > 2:
- - service.message("pokersocial.importPlayerMoney(serial = %d, opensocial_app_id = %s): <= %s" % ( serial, app_id, str(data) ))
- - if data:
- - return simplejson.loads(data[str(serial)]['money'])
- + service.message("pokersocial.importPlayerMoney(opensocial_id = %s, opensocial_app_id = %s): <= %s" % ( opensocial_id, app_id, str(data) ))
- + if data.has_key('money'):
- + return result['money']
- else:
- return {}
- -301,10 +301,10 @@
- return True
- @staticmethod
- - def importUser(service, container, serial):
- - person = container['context'].fetch_person(str(serial), [ 'nickname' ])
- - skin = container['config'].get('skin_url') % { 'serial': serial }
- - return { 'serial': serial,
- + def importUser(service, container, opensocial_id):
- + person = container['context'].fetch_person(opensocial_id, [ 'nickname' ])
- + skin = person.get_field('thumbnailUrl')
- + return { 'opensocial_id': opensocial_id,
- 'name': person.get_field('nickname'),
- 'skin_url': skin }
- diff -r c01aae84ab30 usr/share/pyshared/pokersocial/monitor.py
- --- a/usr/share/pyshared/pokersocial/monitor.py Thu Jan 28 11:38:05 2010 +0000
- +++ b/usr/share/pyshared/pokersocial/monitor.py Thu Jan 28 14:13:05 2010 +0000
- -18,6 +18,7 @@
- from pokernetwork.pokerpackets import PacketPokerMonitorEvent
- from pokersocial.core import Pokersocial
- +from pokersocial.auth import serial2opensocial
- event2name = [ 'NONE', 'HAND', 'TOURNEY', 'BUY_IN', 'REFILL', 'PRIZE', 'REGISTER', 'UNREGISTER', 'LEAVE', 'SEAT' ]
- -34,7 +35,7 @@
- ):
- money = Pokersocial.queryPlayerMoney(service, packet.param1)
- for container in info['url2container'].values():
- - Pokersocial.exportPlayerMoney(service, container, packet.param1, money)
- + Pokersocial.exportPlayerMoney(service, container, serial2opensocial(packet.param1), money)
- if packet.event in (
- PacketPokerMonitorEvent.LEAVE,
- diff -r c01aae84ab30 usr/share/pyshared/pokersocial/monitor.pyc
- Binary file usr/share/pyshared/pokersocial/monitor.pyc has changed
