Example #1
0
def update_txt(root, y, account, wallet_seed, index, listbox):
    # Process any pending blocks
    print(_("Checking for update"))
    pending = nano.get_pending(str(account))
    if pending == "timeout":
        root.update_idletasks()
        root.after(
            5000,
            lambda: update_txt(root, y, account, wallet_seed, index, listbox))
        return

    previous = nano.get_previous(str(account))
    if len(pending) > 0:
        print(_("Processing..."))
        while len(pending) > 0:
            pending = nano.get_pending(str(account))
            if pending == "timeout":
                continue

            try:
                if len(previous) == 0:
                    print(_("Opening Account"))
                    hash, balance = nano.open_xrb(int(index), account,
                                                  wallet_seed)
                    print(_("Reply {} {}").format(reply, balance))
                    if hash != 'timeout' and hash != None:
                        listbox.insert(
                            END, "{}... {:.4} Nano".format(
                                hash['hash'][:24],
                                Decimal(balance) / Decimal(raw_in_xrb)))
                        listbox.itemconfig(END, {'bg': 'spring green'})
                    #We get previous after opening the account to switch it to receive rather than open
                    previous = nano.get_previous(str(account))
                else:
                    hash, balance = nano.receive_xrb(int(index), account,
                                                     wallet_seed)
                    print(_("Reply {} {}").format(hash, balance))
                    if hash != 'timeout' and hash != None:
                        listbox.insert(
                            END, "{}... {:.4} Nano".format(
                                hash['hash'][:24],
                                Decimal(balance) / Decimal(raw_in_xrb)))
                        listbox.itemconfig(END, {'bg': 'spring green'})
            except:
                print(_("Error processing blocks"))

    try:
        current_balance = nano.get_account_balance(account)
        if current_balance != "timeout":
            y.config(text="{:.3} Nano".format(
                Decimal(current_balance) / Decimal(raw_in_xrb)))
        else:
            y.config(text=_("Timeout"))
    except:
        y.config(text=_("Account Not Open"))

    root.update_idletasks()
    root.after(
        5000,
        lambda: update_txt(root, y, account, wallet_seed, index, listbox))
Example #2
0
 def withdraw(self):
     current_balance = nano.get_account_balance(self.account)
     if current_balance == "timeout":
         print(_("Error - timeout, try again"))
     else:
         nano.send_xrb(self.withdraw_dest.get(), int(current_balance), self.account, int(self.index), self.wallet_seed)
         self.listbox.insert(END, "{}                              {:.4} Nano".format('Withdraw', Decimal(current_balance) / Decimal(raw_in_xrb)))
         self.listbox.itemconfig(END, {'bg':'coral2'})
     self.top.destroy()
Example #3
0
def main():
    
    dir_path = str(Path.home())
    print("Starting NanoQuake2...")
    print()
    print("Current Dir: {}".format(dir_path))
    print("System: {}".format(platform.system()))
    
    # determine if application is a script file or frozen exe
    # https://stackoverflow.com/questions/404744/determining-application-path-in-a-python-exe-generated-by-pyinstaller
    if getattr(sys, 'frozen', False):
        work_dir = sys._MEIPASS
    elif __file__:
        work_dir = os.path.dirname(os.path.abspath(__file__))

    print("Work Dir: {}".format(work_dir))
    
    
    if(platform.system() == "Linux" or platform.system() == "Darwin"):
        dir_exists = Path(dir_path + '/.nanoquake').exists()
        if dir_exists == False:
            print("Making a new config directory")
            os.mkdir(dir_path + '/.nanoquake')
        nanoquake_path = dir_path + '/.nanoquake'

    elif(platform.system() == "Windows"):
        dir_exists = Path(dir_path + '/AppData/Local/NanoQuake').exists()
        if dir_exists == False:
            print("Making a new config directory")
            os.mkdir(dir_path + '/AppData/Local/NanoQuake')
        nanoquake_path = dir_path + '/AppData/Local/NanoQuake'

    else:
        print("Error - system not recognised")
        time.sleep(5)
        sys.exit()

    print("Config Directory: {}".format(nanoquake_path))
    
    old_exists = Path(nanoquake_path + '/seed.txt').exists()
    if old_exists == True:
        print("Old seed file detected, as encryption has been upgraded please import your old seed, you can extract it with the decodeOldseed.py script")
    
    exists = Path(nanoquake_path + '/seedAES.txt').exists()

    root = Tk()
    root.geometry("500x700")
    w = Label(root, text="NanoQuake v1.6", bg="blue4", fg="white")
    w.pack(fill=X)
    root.wm_title("NanoQuake v1.6")
    root.iconbitmap("nanoquake.ico")

    root.update()

    parser = configparser.ConfigParser()
    config_files = parser.read(nanoquake_path + '/config.ini')

    if len(config_files) == 0:
        lang = SelectLanguageDialog(root, nanoquake_path)
        root.wait_window(lang.top)
        selected_language = lang.get_lang()
        print(selected_language)
        parser.add_section('general')
        parser.set('general', 'language', selected_language)
        
        cfgfile = open(nanoquake_path + '/config.ini','w')
        parser.write(cfgfile)
        cfgfile.close()

    selected_language = parser.get('general', 'language')
    print(selected_language)
    localedirectory = work_dir + '/locale'
    try:
        lang1 = gettext.translation('nanoquake', localedir=localedirectory, languages=[selected_language])
        lang1.install()
    except:
        print("Error - not able to locate translation files, back to default")

    try:
        disclaimer_bool = parser.get('general', 'disclaimer')
    except:
        disclaimer_bool = "False"

    if disclaimer_bool != "True":
        disclaimer = disclaimerDialog(root)
        root.wait_window(disclaimer.top)
        parser.set('general', 'disclaimer', "True")
        
        cfgfile = open(nanoquake_path + '/config.ini','w')
        parser.write(cfgfile)
        cfgfile.close()
    
    while True:
        
        d = PasswordDialog(root, exists)
        root.wait_window(d.top)

        password = d.get_password()

        if exists == False:
            
            wallet_seed = None
            
            genImpSeed = GenerateSeedDialog(root, wallet_seed)
            root.wait_window(genImpSeed.top)
            
            wallet_seed = genImpSeed.get_seed()

            write_encrypted(password.encode('utf8'), nanoquake_path + '/seedAES.txt', wallet_seed)
            priv_key, pub_key = nano.seed_account(str(wallet_seed), 0)
            public_key = str(binascii.hexlify(pub_key), 'ascii')
            print(_("Public Key: "), str(public_key))

            account = nano.account_xrb(str(public_key))
            print(_("Account Address: "), account)

            seed = wallet_seed
            break

        else:
            print()
            print(_("Seed file found"))
            print(_("Decoding wallet seed with your password"))
            try:
                wallet_seed = read_encrypted(password.encode('utf8'), nanoquake_path + '/seedAES.txt', string=True)
                priv_key, pub_key = nano.seed_account(str(wallet_seed), 0)
                public_key = str(binascii.hexlify(pub_key), 'ascii')
                print(_("Public Key: "), str(public_key))
            
                account = nano.account_xrb(str(public_key))
                print(_("Account Address: "), account)
                break
            except:
                print('\nError decoding seed, check password and try again')


    index = 0
    print()
    print(_("This is your game account address: {}").format(account))
    current_balance = nano.get_account_balance(account)
    if current_balance != "timeout":
        print(_("\nBalance: {:.3} Nano\n").format(Decimal(current_balance) / Decimal(raw_in_xrb)))

    r = nano.get_rates()
    if r != "timeout":

        print()
        print(_("NANO Rates"))
        print("- $:",r.json()['NANO']['USD'])
        print("- £:",r.json()['NANO']['GBP'])
        print("- €:",r.json()['NANO']['EUR'])

    if Path(work_dir + '/release/baseq2/pak0.pak').exists() == False or Path(work_dir + '/release/baseq2/players').exists() == False:
        
        f = DownloadDialog(root, work_dir)
        root.wait_window(f.top)
    
    data = 'xrb:' + account
    xrb_qr = pyqrcode.create(data)
    code_xbm = xrb_qr.xbm(scale=4)
    code_bmp = BitmapImage(data=code_xbm)
    code_bmp.config(background="white")
    label = Label(root, image=code_bmp)
    label.pack()
    
    w = Label(root, text=_("Your Game Account: "))
    w.pack()
    data_string = StringVar()
    data_string.set(account)
    w = Entry(root, textvariable=data_string, fg="black", bg="white", bd=0, state="readonly")
    w.pack()
    w.pack(fill=X)
    y = Label(root, text=_("Your Balance: "))
    y.pack()
    if current_balance != "timeout":
        y = Label(root, text="{:.3} Nano".format(Decimal(current_balance) / Decimal(raw_in_xrb)))
    else:
        y = Label(root, text=_("Timeout"))

    y.pack()

    listbox = Listbox(root)
    listbox.pack(fill=BOTH, expand=1)

    c = Button(root, text=_("Start Game"), command=lambda: thread_startGame(work_dir, account, wallet_seed, index))
    c.pack(pady=5)
 
    withdraw = Button(root, text=_("Withdraw All"), command=lambda: withdrawAllDialog(root, account, index, wallet_seed, listbox))
    withdraw.pack(pady=5)

    settings = Button(root, text=_("Settings"), command=lambda: settingsDialog(root, nanoquake_path, wallet_seed))
    settings.pack(pady=5)

    quit = Button(root, text=_("Exit"), command=exitGame)
    quit.pack(pady=5)

    tcp = threading.Thread(target=start_server, args=(account, wallet_seed, index, listbox,))
    tcp.daemon = True
    tcp.start()
    
    root.update()

    root.after(5000,lambda: update_txt(root, y, account, wallet_seed, index, listbox))
    root.mainloop()
Example #4
0
    def dispatch_client(self):
        try:
            while True:
                line = yield self.stream.read_until(b'\n')
                self.log('got |%s|' % line.decode('utf-8').strip())
                print("{} {}".format(time.strftime("%d/%m/%Y %H:%M:%S"),line))
                split_data = line.rstrip().decode('utf8').split(",")
                
                if split_data[0] == "shutdown":
                    print(_("Shutting down Quake"))
                    global quake_running
                    quake_running = 0
                
                elif split_data[0] == "pay_server":
                    print(_("Pay Nano to Server"))
                    global last_pay_time
                    dest_account = 'xrb_' + split_data[1]
                    amount = str(server_payin)
                    current_balance = 'Empty'
                    time_difference = time.time() - last_pay_time
                    print(time_difference)
                    if time_difference > 30:
                        try:
                            current_balance = nano.get_account_balance(self.account)
                        except:
                            pass


                        if current_balance == 'Empty' or current_balance == '':
                            return_string = _("Error - empty balance")
                            yield self.stream.write(return_string.encode('ascii'))
                        elif current_balance == 'timeout':
                            return_string = _("Error - timeout checking balance")
                            yield self.stream.write(return_string.encode('ascii'))
                        
                        if int(current_balance) >= server_payin:
                            t = threading.Thread(target=send_xrb_thread, args=(dest_account, int(amount), self.account, int(self.index), self.wallet_seed,))
                            t.start()
                            last_pay_time = time.time()
                            self.listbox.insert(END, "{}                              {:.4} Nano".format('Pay In', Decimal(amount) / Decimal(raw_in_xrb)))
                            self.listbox.itemconfig(END, {'bg':'coral2'})
                            return_string = _("Payment Sent")
                            yield self.stream.write(return_string.encode('ascii'))
                        else:
                            print(_("Error - insufficient funds"))
                            return_string = _("Error insufficent funds")
                            yield self.stream.write(return_string.encode('ascii'))
                    else:
                        print(_("Last pay in less that 30 seconds ago"))
                        return_string = _("Last pay in less that 30 seconds ago")
                        yield self.stream.write(return_string.encode('ascii'))


                elif split_data[0] == "balance":
                    print(_("Nano Balance"))
                    new_balance = 'Empty'
                    try:
                        current_balance = nano.get_account_balance(self.account)
                        print(current_balance)
                    except:
                        pass

                    if current_balance == 'Empty':
                        return_string = _("Error - empty balance")
                    elif current_balance == 'timeout':
                        return_string = _("Error - timeout checking balance")
                    else:
                        new_balance = Decimal(current_balance) / Decimal(raw_in_xrb)
                        print("Balance: {:.5}".format(new_balance))
                        return_string = "{:.5} Nano".format(new_balance)
                    
                    yield self.stream.write(return_string.encode('ascii'))

                elif split_data[0] == "nano_address":
                    return_string = "{}".format(self.account[4:])
                    yield self.stream.write(return_string.encode('ascii'))

                elif split_data[0] == "rates":
                    try:
                        r = nano.get_rates()
                        return_string = "USD:" + str(r.json()['NANO']['USD']) + " - GBP:" + str(r.json()['NANO']['GBP']) + " - EURO:" + str(r.json()['NANO']['EUR'])
                        yield self.stream.write(return_string.encode('ascii'))

                    except:
                        pass 
                    


        except tornado.iostream.StreamClosedError:
                pass