Example #1
0
def main(play, user=None, pwd=None, new_seed=True, dummy=True):
    if dummy:
        from browserless_dummy import load_justdice, JustDiceSocket
    else:
        from browserless_driver import load_justdice, JustDiceSocket

    print "Connecting..."
    response = load_justdice()
    login_info = {'user': user, 'pwd': pwd} if user is not None else None
    justdice = JustDiceSocket(response, login=login_info)
    sys.stdout.write("Logging in...")
    sys.stdout.flush()
    while not justdice.logged_in:
        if justdice.logged_in is None:
            # Could not login.
            justdice.sock.emit('disconnect')
            return
        sys.stdout.write('.')
        sys.stdout.flush()
        time.sleep(0.75)
    print

    if new_seed:
        print "Generating new server seed.."
        justdice.randomize()
        print

    win, total = play(justdice)
    print "\nWin ratio: %d/%d = %s" % (win, total, Decimal(win) / total)

    justdice.sock.emit('disconnect')
Example #2
0
def login(dummy, response, user, pwd, google_2fa, secret_url, JustDiceSocket):
    sys.stderr.write("Logging in...")
    sys.stderr.flush()

    # When using secret url, we need to POST the login data.
    if not dummy and secret_url is not None and user is not None:
        response = login_on_secret_url(secret_url, user, pwd, google_2fa)

    if user is not None:
        login_info = {'user': user, 'pwd': pwd, '2fa': google_2fa}
    else:
        login_info = None
    justdice = JustDiceSocket(response, login=login_info)
    max_login_wait = 15 # seconds
    now = time.time()
    while not justdice.logged_in:
        if time.time() - now > max_login_wait:
            # Timed out.
            justdice.logged_in = None
        if justdice.logged_in is None:
            # Could not login.
            sys.stderr.write(" Couldn't log in\n")
            justdice.sock.emit('disconnect')
            return
        sys.stderr.write('.')
        sys.stderr.flush()
        time.sleep(0.75)
    sys.stderr.write('\n')

    return justdice
Example #3
0
def login(response, options, JustDiceSocket, jdparams=None):
    sys.stderr.write("Logging in...")
    sys.stderr.flush()

    dummy, secret_url = options.dummy, options.secret
    user, pwd, google_2fa = options.user, options.password, options.gauth
    # When using secret url, we need to POST the login data.
    if not dummy and secret_url is not None and user is not None:
        response = login_on_secret_url(options)

    if user is not None:
        login_info = {'user': user, 'pwd': pwd, '2fa': google_2fa}
    else:
        login_info = None
    justdice = JustDiceSocket(response, login=login_info, params=jdparams)
    max_login_wait = 15  # seconds
    now = time.time()
    while not justdice.logged_in:
        if time.time() - now > max_login_wait:
            # Timed out.
            justdice.logged_in = None
        if justdice.logged_in is None:
            # Could not login.
            sys.stderr.write(" Couldn't log in\n")
            justdice.sock.emit('disconnect')
            return
        sys.stderr.write('.')
        sys.stderr.flush()
        time.sleep(0.75)
    sys.stderr.write('\n')

    return justdice
Example #4
0
def main(play, new_seed=True, **kwargs):
    user, pwd, google_2fa, dummy = _handle_input(sys.argv)

    if dummy:
        from browserless_dummy import load_justdice, JustDiceSocket
    else:
        from browserless_driver import load_justdice, JustDiceSocket
    if 'justdice' in kwargs:
        JustDiceSocket = kwargs['justdice']

    sys.stderr.write("Connecting...\n")
    response = load_justdice()
    if user is not None:
        login_info = {'user': user, 'pwd': pwd, '2fa': google_2fa}
    else:
        login_info = None
    justdice = JustDiceSocket(response, login=login_info)
    max_login_wait = 15 # seconds
    sys.stderr.write("Logging in...")
    sys.stderr.flush()
    now = time.time()
    while not justdice.logged_in:
        if time.time() - now > max_login_wait:
            # Timed out.
            justdice.logged_in = None
        if justdice.logged_in is None:
            # Could not login.
            sys.stderr.write(" Couldn't log in\n")
            justdice.sock.emit('disconnect')
            return
        sys.stderr.write('.')
        sys.stderr.flush()
        time.sleep(0.75)
    sys.stderr.write('\n')

    if new_seed:
        sys.stderr.write("Generating new server seed..")
        justdice.randomize()
        while justdice.waiting_seed:
            sys.stderr.write('.')
            sys.stderr.flush()
            time.sleep(0.1)
        sys.stderr.write('\n')

    try:
        play(justdice)
    finally:
        sys.stderr.write('Leaving..\n')
        justdice.sock.emit('disconnect')