Ejemplo n.º 1
0
def upcache_reader(upcache_path, info=None):
    if upcache_path.startswith('s3:'):
        reader = SpinUpcacheIO.S3Reader(SpinS3.S3(SpinConfig.aws_key_file()),
                                        SpinConfig.upcache_s3_location(
                                            SpinConfig.game())[0],
                                        upcache_path.split(':')[1],
                                        info=info)
        return reader
    else:
        return SpinUpcacheIO.LocalReader(upcache_path, info=info)
Ejemplo n.º 2
0
def bgtask_func():
    time_now = time.time()
    nosql_client.set_time(int(time_now))

    servers = []
    rows = nosql_client.server_status_query({},
                                            fields={
                                                '_id': 1,
                                                'type': 1,
                                                'hostname': 1,
                                                'game_http_port': 1,
                                                'external_http_port': 1,
                                                'server_time': 1
                                            })
    for row in rows:
        key = row['server_name']
        if row['type'] == 'proxyserver':
            url = 'http://%s:%d/PING' % (row['hostname'],
                                         row['external_http_port'])
        elif row['type'] == SpinConfig.game():
            url = 'http://%s:%d/CONTROLAPI?secret=%s&method=ping' % (
                row['hostname'], row['game_http_port'],
                SpinConfig.config['proxy_api_secret'])
        else:
            continue
        servers.append((key, url))

    for key, url in servers:
        if key in requests:
            #print 'still running'
            continue

        requests[key] = {
            'start_time':
            time_now,
            'request':
            http_client.queue_request(
                time_now,
                url,
                functools.partial(on_response, key, True),
                error_callback=functools.partial(on_response, key, False))
        }  # standin parameter
Ejemplo n.º 3
0
            'indices': {'master': {'unique':False, 'keys': [(interval,'ASC')]}},
            }


def get_ad_skynet_from_query_string(qs):
    if qs:
        q = urlparse.parse_qs(qs)
        if 'spin_atgt' in q:
            return q['spin_atgt'][0]
        elif 'spin_rtgt' in q:
            return q['spin_rtgt'][0]
    return None


if __name__ == '__main__':
    game_id = SpinConfig.game()
    commit_interval = 1000
    verbose = True
    do_prune = False
    do_optimize = False

    opts, args = getopt.gnu_getopt(sys.argv[1:], 'g:c:q',
                                   ['prune', 'optimize'])

    for key, val in opts:
        if key == '-g': game_id = val
        elif key == '-c': commit_interval = int(val)
        elif key == '-q': verbose = False
        elif key == '--prune': do_prune = True
        elif key == '--optimize': do_optimize = True
Ejemplo n.º 4
0
def stream_userdb():
    bucket, name = SpinConfig.upcache_s3_location(SpinConfig.game())
    return SpinUpcacheIO.S3Reader(SpinS3.S3(SpinConfig.aws_key_file()), bucket,
                                  name).iter_all()
    for key, val in opts:
        if key == '--dry-run': dry_run = True
        elif key == '-v' or key == '--verbose': verbose = True

    if len(args) != 1:
        print 'usage: %s user_id (with JSON payment graph object on stdin)' % sys.argv[0]
        sys.exit(1)

    user_id = int(args[0])
    response = SpinJSON.load(sys.stdin)
    #response = SpinJSON.loads(test_input)

    user = SpinJSON.loads(SpinUserDB.driver.sync_download_user(user_id))
    player = SpinJSON.loads(SpinUserDB.driver.sync_download_player(user_id))

    zd_game_id = {'mf': 'mars_frontier', 'tr':'thunder_run', 'mf2': 'war_star_empire', 'bfm':'battlefront_mars', 'dv': 'days_of_valor', 'sg':'summoners_gate'}[SpinConfig.game()]
    player_name = user.get('alias', user.get('kg_username', user.get('facebook_name', 'unknown')))
    player_email = user.get('email', 'unknown')
    facebook_id = response['user']['id'] if 'user' in response else user.get('facebook_id', 'unknown')
    payment_id = str(response['id'])
    payment_amount = 'unknown'
    payment_currency = 'unknown'
    for action in response['actions']:
        if ('currency' in action) and ('amount' in action):
            payment_currency = action['currency']
            payment_amount = action['amount']
            break

    dispute_comments = []
    for item in response.get('disputes',[]):
        if 'user_email' in item: player_email = item['user_email']
Ejemplo n.º 6
0
        elif key == '--message-sender':
            message_sender = val
        elif key == '--message-expire-time':
            message_expire_time = max(-1, int(val))
        elif key == '--message-expire-in':
            message_expire_time = time_now + int(val)
        elif key == '--send-message':
            send_message = True

    if len(args) > 0:
        user_id = int(args[0])

    gamedata = SpinJSON.load(
        open(
            SpinConfig.gamedata_filename(
                override_game_id=SpinConfig.game(game_id))))

    # hack - MF's gamebucks item is called "alloy"
    if give_item == 'gamebucks' and SpinConfig.game(game_id) == 'mf':
        give_item = 'alloy'

    if give_item and (give_item not in gamedata['items']):
        print 'error! item "%s" not found in gamedata.items' % give_item
        sys.exit(1)

    if user_id is None and facebook_id is None:
        print 'usage: %s [options]' % sys.argv[0]
        print 'options:'
        print '    --user-id ID        choose player by SpinPunch user ID'
        print '    --facebook-id ID    choose player by Facebook user ID'
        print ''
    opts, args = getopt.gnu_getopt(sys.argv[1:], '', ['dry-run'])
    dry_run = False
    verbose = True

    for key, val in opts:
        if key == '--dry-run':
            dry_run = True
        elif key == '--quiet':
            verbose = False

    for name, data in gamedata['achievements'].iteritems():
        if 'fb_open_graph' not in data: continue
        if not data['fb_open_graph'].get('populate', True): continue

        endpoint = get_endpoint_url({
            'type': SpinConfig.game() + '_achievement',
            'name': name
        })
        params = {
            'access_token': SpinConfig.config['facebook_app_access_token'],
            'achievement': endpoint
        }
        if 'display_order' in data:
            params['display_order'] = str(data['display_order'])

        postdata = urllib.urlencode(params)
        url = SpinFacebook.versioned_graph_endpoint(
            'achievement',
            SpinConfig.config['facebook_app_id'] + '/achievements')
        request = urllib2.Request(url, data=postdata)
        request.get_method = lambda: 'POST'