Files
TiropitLauncher/CLI/Init.py

358 lines
10 KiB
Python
Raw Normal View History

2025-09-05 17:59:19 +03:00
import configparser
2025-09-05 23:47:51 +03:00
import os
2025-09-05 17:59:19 +03:00
from pathlib import Path
import requests
import argparse
import sys
2025-09-15 16:59:07 +03:00
import tkinter as tk
from tkinter import filedialog
parser = argparse.ArgumentParser(description='TiropitLauncher CLI & Back-End')
parser.add_argument('-backend', help="Runs the app in backend mode (no UI)", action="store_true")
2025-09-05 17:59:19 +03:00
#declare default vars
class Config():
AccountKey = "NK"
AccountID = "NA"
version = 01.02
2025-09-05 17:59:19 +03:00
2025-09-06 02:27:28 +03:00
class ServerObj():
def __init__(self, isReachable=False):
2025-09-06 00:49:46 +03:00
2025-09-06 02:27:28 +03:00
self.host = "0.0.0.0" + ":5000"
self.isReachable = False
self.state = "Resolving IP"
2025-09-06 02:27:28 +03:00
@property
def Icon(self):
if self.isReachable:
return "🌐"
else:
return ""
args = parser.parse_args()
Server = ServerObj()
2025-09-05 17:59:19 +03:00
#declare files
config = configparser.ConfigParser()
configPath = Path("Config.ini")
2025-09-06 00:49:46 +03:00
class Display():
def Clear():
os.system('cls' if os.name == 'nt' else 'clear')
2025-09-06 00:49:46 +03:00
def showIntroText():
print("Tiropit Launcher CLI - Release Branch")
print(f"[TCLI]=============[Select option]==============[{Config.version}]")
2025-09-05 23:47:51 +03:00
def WarnMissingConfig(ConfigError):
print(f"[⚠️ WARNING ⚠️] - Your config file is corrupt , something that has to do with {ConfigError}")
print("Program will exit before it crashes :)")
reset = input("It is recommended that you reset the app data (you will be logged out) y (reset) / n (exit)")
if reset == "y":
os.remove(configPath)
print("[⚠️ WARNING ⚠️] - Reset Done, Re-Open TiropitCLI")
exit(0)
2025-09-05 17:59:19 +03:00
2025-09-05 17:59:19 +03:00
def makeConfig():
2025-09-05 23:47:51 +03:00
config['DEFAULT'] = {'Version': Config.version}
config['ACCOUNT'] = {}
config['ACCOUNT']['KEY'] = "NK"
config['ACCOUNT']["ID"] = "NA"
2025-09-05 17:59:19 +03:00
with open('Config.ini', 'w') as configfile:
config.write(configfile)
2025-09-15 16:59:07 +03:00
def select_folder():
root = tk.Tk()
root.withdraw()
folder_path = filedialog.askdirectory()
if folder_path:
print(f"Selected folder: {folder_path}")
else:
print("No folder was selected.")
return folder_path
2025-09-06 00:49:46 +03:00
def TiropitLogin():
class menuData():
def menuInstructions():
Display.Clear()
showIntroText()
print("|[About: Login Instructions] |")
print("|1. Enter your username & password |")
print("|2. Enter your pin (if you have) |")
print("|3. Save Login key (autologin) |")
print("|[e] Exit [Any] Login > |")
print("======================================================")
def menuUsername():
Display.Clear()
showIntroText()
print(f"|[LogIn: Login page] [{Server.Icon}]|")
print("| Enter your username |")
print("| |")
print("| |")
print("| |")
print("======================================================")
menuData.menuInstructions()
option = input(">> ")
match option:
case "e":
showMenu(1)
return 0
case _:
menuData.menuUsername()
2025-09-05 17:59:19 +03:00
def loadConfig():
try:
config.read(configPath)
Config.version = config["DEFAULT"]["Version"]
Config.AccountID = config["ACCOUNT"]["ID"]
Config.AccountID = config["ACCOUNT"]["KEY"]
except Exception as e:
2025-09-05 23:47:51 +03:00
WarnMissingConfig(e)
2025-09-05 17:59:19 +03:00
2025-09-06 02:35:08 +03:00
def disconnect():
Server.host = "0.0.0.0"
Server.state = "Offline"
Server.isReachable = False
if args.backend: print("4:OFFLINE")
def grabServerResolver():
2025-09-06 02:35:08 +03:00
Server.state = "Resolving IP"
try:
2025-09-06 02:27:28 +03:00
response = requests.get("https://kevinblog.sytes.net/APIS/test1.php")
response.raise_for_status()
data = response.json()
server_ip = data.get("HostIp")
Server.isReachable = True
Server.state = "Connected"
Server.host = server_ip
if args.backend: print(f"2:CONNECTED TO: {server_ip}")
return server_ip
except requests.exceptions.RequestException as e:
Server.isReachable = False
Server.state = f"Failed/Timed Out - {e}"
if args.backend: print(f"3:FAILED CONN TO: {e}")
else: print("Error resolving a host, Considering service is offline.")
pass
2025-09-06 02:35:08 +03:00
def checkConfig():
if configPath.exists():
print("The Config file exists.")
loadConfig()
2025-09-05 17:59:19 +03:00
else:
print("The file Config does not exist. - Creating")
makeConfig()
2025-09-05 17:59:19 +03:00
2025-09-06 02:35:08 +03:00
def debugMenu():
class menuData():
def mainMenu():
Display.Clear()
showIntroText()
print(f"|[DBG] [{Server.Icon}]|")
print("|1. Read Server Data |")
print("|2. |")
print("|3. |")
print("|[e] Exit |")
print("======================================================")
option = input(">> ")
if option == "": menuData.mainMenu()
match option:
case "e":
showMenu(1)
return 0
case "1":
menuData.menuServerData()
case _:
menuData.mainMenu()
def menuServerData():
Display.Clear()
showIntroText()
print(f"|[DBG: Login page] [{Server.Icon}]|")
print(f"| IsReachable : {Server.isReachable}")
print(f"| Host : {Server.host}")
print(f"| State : {Server.state}")
2025-09-06 02:35:08 +03:00
print("[e] Exit | [R] Reconnect | [O] Offline (Disconnect)")
print("======================================================")
option = input(">> ")
if option == "": menuData.menuServerData()
match option:
case "e":
showMenu(1)
return 0
2025-09-06 02:35:08 +03:00
case "r":
grabServerResolver()
menuData.menuServerData()
case "o":
disconnect()
menuData.menuServerData()
case _:
menuData.menuServerData()
menuData.mainMenu()
option = input(">> ")
if option == "": menuData.mainMenu()
match option:
case "e":
showMenu(1)
return 0
case "1":
menuData.menuServerData()
case _:
menuData.mainMenu()
2025-09-15 16:59:07 +03:00
def Gamesmenu():
class menuData():
def mainMenu():
Display.Clear()
showIntroText()
print(f"|[Games] [{Server.Icon}]|")
print("|1. Minecraft Tiropit |")
print("|2. CS2 (Comming Soon) |")
print("| |")
print("|[e] Exit |")
print("======================================================")
2025-09-15 16:59:07 +03:00
option = input(">> ")
if option == "": menuData.mainMenu()
match option:
case "e":
showMenu(1)
return 0
case "1":
menuData.MinecraftMenu()
case _:
menuData.mainMenu()
def MinecraftMenu():
Display.Clear()
showIntroText()
print(f"|[Minecraft] [{Server.Icon}]|")
print("|1. Update |")
print("|2. Install |")
print("| |")
print("|[e] Exit |")
print("======================================================")
option = input(">> ")
if option == "": menuData.mainMenu()
match option:
case "e":
menuData.mainMenu()
return 0
case "2":
menuData.installMenu()
case _:
menuData.MinecraftMenu()
def installMenu():
Display.Clear()
showIntroText()
print(f"|[Minecraft] [{Server.Icon}]|")
print("|1. Select Install Location |")
print("======================================================")
print(select_folder())
print("| |")
print("|[e] Exit |")
print("======================================================")
menuData.mainMenu()
2025-09-06 00:49:46 +03:00
def showMenu(menuID):
Display.Clear()
showIntroText()
match menuID:
case 1:
print("|[Main menu] |")
print("|[1] Log in to tiropit | [2] Reset Data & Config |")
print("|[3] Send / Get Request| [4] My Profile |")
2025-09-15 16:59:07 +03:00
print("|[5] Debug Data | [6] Games |")
2025-09-06 00:49:46 +03:00
print("|[e] Exit |")
print("======================================================")
option = input(">> ")
if option == "": showMenu(1)
print(option)
match option:
case "1":
TiropitLogin()
case "5":
debugMenu()
2025-09-15 16:59:07 +03:00
case "6":
Gamesmenu()
case "e":
print("Cya!")
exit();
2025-09-06 00:49:46 +03:00
case _:
showMenu(1)
pass
2025-09-05 17:59:19 +03:00
#Begin
if not args.backend:
grabServerResolver()
checkConfig()
showMenu(1)
else:
print("1:=== BACKEND MODE ===")
grabServerResolver()