Share Pastebin
Guest
Public paste!

root

By: a guest | Jan 28th, 2010 | Syntax: None | Size: 7.07 KB | Hits: 75 | Expires: Never
Copy text to clipboard
  1. diff -r c01aae84ab30 usr/share/pyshared/pokersocial/auth.py
  2. --- a/usr/share/pyshared/pokersocial/auth.py    Thu Jan 28 11:38:05 2010 +0000
  3. +++ b/usr/share/pyshared/pokersocial/auth.py    Thu Jan 28 14:13:05 2010 +0000
  4.  -23,17 +23,38 @@
  5.  
  6.  from pokersocial.core import Pokersocial
  7.  
  8. +_opensocial2serial = {}
  9. +_serial2opensocial = {}
  10. +_next_serial = 100
  11. +
  12. +def opensocial2serial(opensocial_id):
  13. +    global _opensocial2serial, _serial2opensocial, _next_serial
  14. +    if not _opensocial2serial.has_key(opensocial_id):
  15. +        _opensocial2serial[opensocial_id] = _next_serial
  16. +        _serial2opensocial[_next_serial] = opensocial_id
  17. +        _next_serial += 1
  18. +    return _opensocial2serial[opensocial_id]
  19. +def serial2opensocial(serial):
  20. +    global _serial2opensocial
  21. +    return _serial2opensocial[serial]
  22. +
  23.  def update_session(site, request):
  24. +    global next_serial
  25. +    global opensocial2serial
  26.      if site.verbose > 3:
  27.          site.message("pokersocial: ")
  28. -    serial = int(request.args['opensocial_owner_id'][0])
  29. -    if serial == int(request.args['opensocial_viewer_id'][0]):
  30. +    opensocial_id = request.args['opensocial_owner_id'][0]
  31. +    
  32. +    serial = opensocial2serial(opensocial_id)
  33. +
  34. +    if opensocial_id == request.args['opensocial_viewer_id'][0]:
  35.          cert_url = urllib.unquote(request.args['xoauth_signature_publickey'][0])
  36.          container = Pokersocial.info(site.resource.service)['url2container'][cert_url]
  37. -        info = Pokersocial.importUser(site.resource.service, container, serial)
  38. +        info = Pokersocial.importUser(site.resource.service, container, opensocial_id)
  39. +        info['serial'] = serial
  40.          Pokersocial.updateUser(site.resource.service, info)
  41.          Pokersocial.updatePlayerMoney(site.resource.service, serial,
  42. -                                      Pokersocial.importPlayerMoney(site.resource.service, container, serial))
  43. +                                      Pokersocial.importPlayerMoney(site.resource.service, container, opensocial_id))
  44.      else:
  45.          info = None
  46.      session = request.getSession()
  47. diff -r c01aae84ab30 usr/share/pyshared/pokersocial/auth.pyc
  48. Binary file usr/share/pyshared/pokersocial/auth.pyc has changed
  49. diff -r c01aae84ab30 usr/share/pyshared/pokersocial/core.py
  50. --- a/usr/share/pyshared/pokersocial/core.py    Thu Jan 28 11:38:05 2010 +0000
  51. +++ b/usr/share/pyshared/pokersocial/core.py    Thu Jan 28 14:13:05 2010 +0000
  52.  -191,16 +191,16 @@
  53.              assert cursor.rowcount in (1, 2), s
  54.  
  55.      @staticmethod
  56. -    def exportPlayerMoney(service, container, serial, money):
  57. +    def exportPlayerMoney(service, container, opensocial_id, money):
  58.          app_id = container['config'].get('opensocial_app_id')
  59. -        r = request.UpdateAppDataRequest(str(serial), '@self', app_id, ['money'], { 'money': simplejson.dumps(dict(money)) })
  60. +        r = request.UpdateAppDataRequest(opensocial_id, '@self', app_id, ['money'], { 'money': simplejson.dumps(dict(money)) })
  61.          if service.verbose > 2:
  62. -            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() ))
  63. +            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() ))
  64.          try:
  65. -            data = container['context'].send_request(r)
  66. +            data = container['context'].send_request(r, True)
  67.          except errors.BadResponseError, e:
  68.              if e.code == 404 and 'Data Not Found' in e.message:
  69. -                service.error("pokersocial.exportPlayerMoney(serial = %d, opensocial_app_id = %s): <= %s" % ( serial, app_id, e.message ))
  70. +                service.error("pokersocial.exportPlayerMoney(serial = %s, opensocial_app_id = %s): <= %s" % ( opensocial_id, app_id, e.message ))
  71.                  data = None
  72.              else:
  73.                  raise
  74.  -209,23 +209,23 @@
  75.          return data
  76.  
  77.      @staticmethod
  78. -    def importPlayerMoney(service, container, serial):
  79. +    def importPlayerMoney(service, container, opensocial_id):
  80.          app_id = container['config'].get('opensocial_app_id')
  81. -        r = request.FetchAppDataRequest(str(serial), '@self', app_id, ['money'])
  82. +        r = request.FetchAppDataRequest(opensocial_id, '@self', app_id, ['money'])
  83.          try:
  84. -            data = container['context'].send_request(r)
  85. +            data = container['context'].send_request(r, True)
  86.          except errors.BadResponseError, e:
  87.              if e.code == 404 and 'Data Not Found' in e.message:
  88. -                service.error("pokersocial.importPlayerMoney(serial = %d, opensocial_app_id = %s): <= %s" % ( serial, app_id, e.message ))
  89. +                service.error("pokersocial.importPlayerMoney(opensocial_id = %s, opensocial_app_id = %s): <= %s" % ( opensocial_id, app_id, e.message ))
  90.                  data = None
  91.              else:
  92.                  raise
  93.          except:
  94.              raise
  95.          if service.verbose > 2:
  96. -            service.message("pokersocial.importPlayerMoney(serial = %d, opensocial_app_id = %s): <= %s" % ( serial, app_id, str(data) ))
  97. -        if data:
  98. -            return simplejson.loads(data[str(serial)]['money'])
  99. +            service.message("pokersocial.importPlayerMoney(opensocial_id = %s, opensocial_app_id = %s): <= %s" % ( opensocial_id, app_id, str(data) ))
  100. +        if data.has_key('money'):
  101. +            return result['money']
  102.          else:
  103.              return {}
  104.  
  105.  -301,10 +301,10 @@
  106.          return True
  107.  
  108.      @staticmethod
  109. -    def importUser(service, container, serial):
  110. -        person = container['context'].fetch_person(str(serial), [ 'nickname' ])
  111. -        skin = container['config'].get('skin_url') % { 'serial': serial }
  112. -        return { 'serial': serial,
  113. +    def importUser(service, container, opensocial_id):
  114. +        person = container['context'].fetch_person(opensocial_id, [ 'nickname' ])
  115. +        skin = person.get_field('thumbnailUrl')
  116. +        return { 'opensocial_id': opensocial_id,
  117.                   'name': person.get_field('nickname'),
  118.                   'skin_url': skin }
  119.  
  120. diff -r c01aae84ab30 usr/share/pyshared/pokersocial/monitor.py
  121. --- a/usr/share/pyshared/pokersocial/monitor.py Thu Jan 28 11:38:05 2010 +0000
  122. +++ b/usr/share/pyshared/pokersocial/monitor.py Thu Jan 28 14:13:05 2010 +0000
  123.  -18,6 +18,7 @@
  124.  from pokernetwork.pokerpackets import PacketPokerMonitorEvent
  125.  
  126.  from pokersocial.core import Pokersocial
  127. +from pokersocial.auth import serial2opensocial
  128.  
  129.  event2name = [ 'NONE', 'HAND', 'TOURNEY', 'BUY_IN', 'REFILL', 'PRIZE', 'REGISTER', 'UNREGISTER', 'LEAVE', 'SEAT' ]
  130.  
  131.  -34,7 +35,7 @@
  132.          ):
  133.          money = Pokersocial.queryPlayerMoney(service, packet.param1)
  134.          for container in info['url2container'].values():
  135. -            Pokersocial.exportPlayerMoney(service, container, packet.param1, money)
  136. +            Pokersocial.exportPlayerMoney(service, container, serial2opensocial(packet.param1), money)
  137.  
  138.      if packet.event in (
  139.          PacketPokerMonitorEvent.LEAVE,
  140. diff -r c01aae84ab30 usr/share/pyshared/pokersocial/monitor.pyc
  141. Binary file usr/share/pyshared/pokersocial/monitor.pyc has changed