def main(): print("Starting NanoQuake2...") print() parser = ConfigParser() config_files = parser.read('config.ini') while True: password = prompt('Enter password: '******'Confirm password: '******'seed.txt', wallet_seed) cfgfile = open("config.ini", 'w') parser.add_section('wallet') 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) parser.set('wallet', 'account', account) parser.set('wallet', 'index', '0') parser.write(cfgfile) cfgfile.close() index = 0 seed = wallet_seed else: print() print("Config file found") print("Decoding wallet seed with your password") try: wallet_seed = read_encrypted(password, 'seed.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) except: print('\nError decoding seed, check password and try again') sys.exit() index = 0 previous = nano.get_previous(str(account)) print() print("This is your game account address: {}".format(account)) if previous != "": current_balance = Decimal( nano.get_balance(previous)) / Decimal(raw_in_xrb) print("Your balance is {:.5} Nano".format( print_decimal(current_balance))) else: current_balance = 0 print("Your balance is 0 Nano") r = nano.get_rates() print() print("NANO Rates") print("- $:", r.json()['NANO']['USD']) print("- £:", r.json()['NANO']['GBP']) print("- €:", r.json()['NANO']['EUR']) while True: print() print("--------------") print("NanoQuake Menu") print("--------------") print("1. Start Game - Lets Get REKT...") print("2. Top-up Game Balance") print("3. Withdraw Funds") print("4. Display Seed") print("5. Check Balance") print("6. Exit") print() menu1 = 0 try: menu1 = int(input("Please select an option: ")) except: pass if menu1 == 6: print("Exiting NanoQuake") sys.exit() elif menu1 == 5: previous = nano.get_previous(str(account)) current_balance = nano.get_balance(previous) if current_balance == "": current_balance = 0 if int(current_balance) < server_payin: print() print("Insufficient funds - please deposit at least 0.1 Nano") print("{} Raw Detected...".format(current_balance)) #Scan for new blocks, wait for pending pending = nano.get_pending(str(account)) if len(pending) > 0: print() print( "This account has pending transactions. Follow option 2 to process..." .format(current_balance)) print("\nBalance: {:.5} Nano\n".format( Decimal(current_balance) / Decimal(raw_in_xrb))) elif menu1 == 4: print("\nSeed: {}\n".format(wallet_seed)) elif menu1 == 3: print("Withdraw Funds") withdraw_dest = input("Destination Address: ") previous = nano.get_previous(str(account)) current_balance = nano.get_balance(previous) nano.send_xrb(withdraw_dest, int(current_balance), account, int(index), wallet_seed) elif menu1 == 2: display_qr(account) previous = nano.get_previous(str(account)) pending = nano.get_pending(str(account)) #Scan for new blocks, wait for pending if len(pending) == 0: print("Waiting for funds...") wait_for_reply(account) # Process any pending blocks pending = nano.get_pending(str(account)) if len(pending) > 0: print("Processing...") while len(pending) > 0: pending = nano.get_pending(str(account)) if len(previous) == 0: print("Opening Account") nano.open_xrb(int(index), account, wallet_seed) #We get previous after opening the account to switch it to receive rather than open time.sleep( 2) #Just to make sure that the block as been recorded previous = nano.get_previous(str(account)) else: nano.receive_xrb(int(index), account, wallet_seed) print('.', end='', flush=True) time.sleep( 2) #give it chance so we down display message twice previous = nano.get_previous(str(account)) current_balance = nano.get_balance(previous) if int(current_balance) < server_payin: print() print("Insufficient funds - please deposit at least 0.1 Nano") print("({} Raw Detected)".format(current_balance)) else: print() print("Sufficient Funds - Lets Go!") print("Your balance is {:.5} Nano".format( Decimal(current_balance) / Decimal(raw_in_xrb))) elif menu1 == 1: previous = nano.get_previous(str(account)) current_balance = nano.get_balance(previous) #try: current_dir = os.getcwd() print(current_dir) #os.remove('~/.yq2/baseq2/config.cfg') #except OSError: # pass print("Starting Quake2") #game_args = "+set nano_address {} +set vid_fullscreen 0".format(account[4:]) game_args = "+set vid_fullscreen 0 &" print(game_args) if platform.system() == 'Windows': full_command = "start quake2 " + game_args else: full_command = "release/quake2 " + game_args print(full_command) process = subprocess.run(full_command, shell=True) # tcp server server = SimpleTcpServer(account, wallet_seed, index) server.listen(PORT, HOST) print("Listening on %s:%d..." % (HOST, PORT)) # pc = tornado.ioloop.PeriodicCallback( lambda: check_account(account, wallet_seed, index), 20000) pc.start() # infinite loop tornado.ioloop.IOLoop.instance().start() else: print("Error, incorrect option selected") sys.exit()
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()
parser.set('wallet', 'seed', wallet_seed) parser.set('wallet', 'index', '0') index = 0 parser.write(cfgfile) cfgfile.close() else: print("Config file successfully loaded") index = int(parser.get('wallet', 'index')) wallet_seed = parser.get('wallet', 'seed') priv_key, pub_key = nano.seed_account(str(wallet_seed), 0) public_key = str(binascii.hexlify(pub_key), 'ascii') account = nano.account_xrb(str(public_key)) print('\rWelcome to a p2p emoji sending service on the Nano Network') print( 'Please be aware that the internal seed is not encrypted so please be careful' ) print() print("\nConnecting to Nano Network...") previous = nano.get_previous(str(account)) pending = nano.get_pending(str(account)) if (len(previous) == 0) and (len(pending) == 0): print("Account not open, please send value to " + account + " to activate") time.sleep(2) print("Closing Channel")
def main(): print("Starting Nanoquake2") parser = ConfigParser() config_files = parser.read('config.ini') while True: password = prompt('Enter password: '******'Confirm password: '******'seed.txt', wallet_seed) cfgfile = open("config.ini", 'w') parser.add_section('wallet') 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) parser.set('wallet', 'account', account) parser.set('wallet', 'index', '0') parser.write(cfgfile) cfgfile.close() index = 0 seed = wallet_seed else: print("Config file found") print("Decoding wallet seed with your password") try: wallet_seed = read_encrypted(password, 'seed.txt', string=True) except: print('\nError decoding seed, check password and try again') sys.exit() account = parser.get('wallet', 'account') index = int(parser.get('wallet', 'index')) previous = nano.get_previous(str(account)) if previous != "": current_balance = float(nano.get_balance(previous)) / raw_in_xrb else: current_balance = 0 print("This is your game account address: {}, your balance is {} Nano". format(account, current_balance)) while True: print("Nanoquake Menu") print("1. Start the Game") print("2. TopUp Your Game Balance") print("3. Withdraw Funds") print("4. Display Seed") print("5. Exit") menu1 = 0 try: menu1 = int(input("Please select an option: ")) except: pass if menu1 == 5: print("Exiting Nanoquake") sys.exit() elif menu1 == 4: print("\nSeed: {}\n".format(wallet_seed)) elif menu1 == 3: print("Withdraw Funds") withdraw_dest = input("Destination Address: ") previous = nano.get_previous(str(account)) current_balance = nano.get_balance(previous) nano.send_xrb(withdraw_dest, int(current_balance), account, int(index), wallet_seed) elif menu1 == 2: display_qr(account) previous = nano.get_previous(str(account)) pending = nano.get_pending(str(account)) #print(previous) if (len(previous) == 0) and (len(pending) == 0): print("Please send at least 0.1Nano to this account") print("Waiting for funds...") wait_for_reply(account) pending = nano.get_pending(str(account)) if (len(previous) == 0) and (len(pending) > 0): print("Opening Account") nano.open_xrb(int(index), account, wallet_seed) #print("Rx Pending: ", pending) pending = nano.get_pending(str(account)) #print("Pending Len:" + str(len(pending))) while len(pending) > 0: pending = nano.get_pending(str(account)) print(len(pending)) nano.receive_xrb(int(index), account, wallet_seed) previous = nano.get_previous(str(account)) current_balance = nano.get_balance(previous) while int(current_balance) < server_payin: print("Insufficient funds - please deposit at least 0.1 Nano") wait_for_reply(account) while len(pending) > 0: pending = nano.get_pending(str(account)) print(len(pending)) nano.receive_xrb(int(index), account, wallet_seed) else: print("Sufficient Funds - Lets Go!") print("Your Balance: {}".format(current_balance)) elif menu1 == 1: previous = nano.get_previous(str(account)) current_balance = nano.get_balance(previous) print("Starting Quake2") #game_args = "+set nano_address {} +set vid_fullscreen 0".format(account[4:]) game_args = "+set nano_address {} +set vid_fullscreen 0 &".format( account[4:]) print(game_args) if platform.system() == 'Windows': full_command = "start quake2 " + game_args else: full_command = "release/quake2 " + game_args print(full_command) process = subprocess.run(full_command, shell=True) # tcp server server = SimpleTcpServer(account, wallet_seed, index) server.listen(PORT, HOST) print("Listening on %s:%d..." % (HOST, PORT)) # pc = tornado.ioloop.PeriodicCallback( lambda: check_account(account, wallet_seed, index), 10000) pc.start() # infinite loop tornado.ioloop.IOLoop.instance().start() else: print("Error, incorret option selected") sys.exit()