示例#1
0
def verify_game_auth():
  game_def = get_definition()
  id = game_def['game_id']
  try:
    game = get_game(id)
  except urllib2.HTTPError as e:
    if e.code == 404:
      print panic("You don't own a game with an Game ID '%s'" %id)
    else:
      raise e
示例#2
0
def submit():
    token, consumer = authenticate()
    game_def = get_definition()
    project_path, y = get_game_dir_info()
    path = "%s/%s" % (project_path,y)
    pack()
    content = open(project_path + "/game.zip", 'rb').read()
    digest = hashlib.sha1()
    digest.update(content)
    game = get_game(game_def['game_id'])
    if game_def['autoVersion']:
      print "Submiting %s" % (game['name'])
    else:  
      print "Submiting %s v%s" % (game['name'],game_def['version'])
    print "Digest (SHA1): " + digest.hexdigest()
    
    
    files = [("submission", 'game', content)]
    params = {
        'oauth_version': "1.0",
        'oauth_nonce': oauth.generate_nonce(),
        'oauth_timestamp': int(time.time()),
        'oauth_token': token.key,
        'oauth_consumer_key': consumer.key,
        'game_id': game_def['game_id'],
    }

    #create a fake request with your upload url and parameters
    faux_req = oauth.Request(method='POST', url="http://localhost:8000/api/submissions.json", parameters=params)

    #sign the fake request.
    signature_method = oauth.SignatureMethod_HMAC_SHA1()
    faux_req.sign_request(signature_method, consumer, token)

    #create a dict out of the fake request signed params
    params = dict(parse_qsl(faux_req.to_postdata()))

    content_type, body = encode_multipart_formdata(params, files)
    headers = {'Content-Type': content_type, 'Content-Length': str(len(body))}
    r = urllib2.Request('%s' % "http://localhost:8000/api/submissions.json", body, headers)
    try:
      urllib2.urlopen(r).read()
      print "Successful"
    except urllib2.HTTPError, ex:
          print >> sys.stderr, 'Received error code: ', ex.code
          print >> sys.stderr
          print >> sys.stderr, ex
          f = open("coredump",'w')
          f.write(ex.read())
          sys.exit(1)
示例#3
0
    def dealWithIt( self ):
      try:
        d = get_definition()
        ph,f = get_game_dir_info();
        entryPoint = d['entryPoint']
        src = d['src']
        rsc = d['resources']
        if self.path == "/":
          self.respond(IDESandboxMain % (800,600,800,600));
      
        elif self.path.startswith("/sandbox"):
          self.respond(IDESandboxRunning % (800,600,id))

        elif self.path == "/runtime/api":
          self.respond(IDESandboxAPI % (d['game_id'], 800,600), mime="text/javascript")

        elif self.path == "/runtime/sbx":
          self.respond(IDESandboxSBX, mime="text/javascript")
      
        elif self.path == "/proxy":
          body = self.rfile.read()
          http = httplib2.Http()
          print "**** Proxying for %s\n" % body;
          resp, content = http.request("http://example.com/foo/bar")
          self.respond(content)
      
        elif self.path.startswith("/src/run"):
          if os.path.exists(ph + "/" + entryPoint):
            content = open(ph + "/" + entryPoint).read()
          
            # <style> body{ margin:0px; padding:0px; background-color:black; color:white; } </style>
            # <script type="text/javascript" src="/runtime/api"></script>
          
            soup = BeautifulSoup(content)
            style = soup.new_tag("style")
            style.append("body{ margin:0px; padding:0px; background-color:black; color:white; }")
            soup.head.insert(1,style)
            script = soup.new_tag("script", type="text/javascript", src="/runtime/api")
            soup.head.insert(1,script)
          
            self.respond(str(soup))
          else:
            self.raise_404();

        elif self.path == "/src/entryPoint":
          if os.path.exists(ph + "/" + entryPoint):
            content = open(ph + "/" + entryPoint).read()
            self.respond(content)
          else:
            self.raise_404();
        elif self.path[0:5] == "/src/":
          if os.path.exists(ph + "/" + src + "/" + self.path[5:]):
            content = open(ph + "/" + src + "/" + self.path[5:]).read()
            self.respond(content)
          else:
            self.raise_404();
        elif self.path == "/favicon.png":
          self.respond(base64.b64decode(FavIcon))
        elif self.path[0:len("/resources/")] == "/resources/":
          file = self.path[len("/resources/"):]
          if os.path.exists(ph + "/" + rsc + "/" + file):
            content = open(ph + "/" + rsc + "/" + file).read()
            self.respond(content)
          else:
            self.raise_404();
        else:
          self.raise_404();
      except Exception, e:
        self.raise_500(); 
        raise