summaryrefslogtreecommitdiff
path: root/__main__.py
diff options
context:
space:
mode:
Diffstat (limited to '__main__.py')
-rwxr-xr-x__main__.py63
1 files changed, 47 insertions, 16 deletions
diff --git a/__main__.py b/__main__.py
index 26f981e..cf62be7 100755
--- a/__main__.py
+++ b/__main__.py
@@ -13,6 +13,7 @@ import requests, json, traceback, subprocess, hmac, struct, time, os, uuid, getp
import base64
import tkinter as tk
from tkinter.messagebox import showinfo, showerror, askyesno
+from functools import partial
OBFS = uuid.getnode() % 256 # Get a number which *usually* doesn't change
print("Obfuscation key = %d" % OBFS) # <- Just to not leave it in plain text
@@ -72,18 +73,29 @@ except:
else:
saveSettings = False
-
+## Prepare some basic stuff
execute=subprocess.call
serverlist = []
+class HoverButton(tk.Button):
+ def enter(self, e):
+ self["background"] = self["activebackground"]
+ def exit(self, e):
+ self["background"] = self.defaultBackground
+
+ def __init__(self, **kw):
+ tk.Button.__init__(self, **kw)
+ self.defaultBackground = self["background"]
+ self.bind("<Enter>", self.enter)
+ self.bind("<Leave>", self.exit)
## TODO: Get from `sys` args parameters like world auto-selection
## TODO: Use Config and Local folders, not sure if relative path works
#####################################
-VAULT_HOST = "https://localhost:13370"
-SERVERLIST = "http://localhost/launcher"
-#VAULT_HOST = "https://api.themanaworld.org:13370"
-#SERVERLIST = "https://updates.tmw2.org/launcher"
+#VAULT_HOST = "https://localhost:13370"
+#SERVERLIST = "http://localhost/launcher"
+VAULT_HOST = "https://api.themanaworld.org:13370"
+SERVERLIST = "https://updates.tmw2.org/launcher"
# Vault SSL wrapper
vault=requests.Session()
if "localhost" in VAULT_HOST:
@@ -203,6 +215,7 @@ def launch_game(idx):
auth = {"vaultId": vaultId,
"token": vaultToken,
"world": serverlist[idx]["UUID"]}
+ print(repr(auth))
try:
r=vault.post(VAULT_HOST+"/world_pass", json=auth, timeout=15.0)
## We got the access credentials
@@ -226,7 +239,10 @@ def launch_game(idx):
return -1
## Handle server type
- CMD="manaplus"
+ if not sys.platform.startswith('win'):
+ CMD="manaplus"
+ else:
+ CMD="manaplus/Mana/manaplus.exe" # FIXME untested
OPT="-s %s -y %s -p %s -S" % (HOST, serverlist[idx]["Type"], PORT)
## Execute the app
@@ -242,22 +258,35 @@ os.environ["APPIMAGELAUNCHER_DISABLE"]="1"
#################################################################################
## Construct session data
-
update_serverlist(SERVERLIST)
vaultId = -1
saveMail = None
savePass = None
-###### TODO: World Selection Screen
+#################################################################################
+###### World Selection Screen
def world_select():
- global canva
- canva = tk.Canvas(root, width=400, height=600)
+ global canva, serverlist
+ canva = tk.Canvas(root, width=400, height=600, bg="#0c3251")
canva.pack()
- label1 = tk.Label(root, text='You are a winner')
+ label1 = tk.Label(root, text='World Selection', bg="#0c3251", fg="#fff")
label1.config(font=('helvetica', 14))
- canva.create_window(200, 40, window=label1)
+ canva.create_window(200, 20, window=label1)
+
+ # Not really necessary? Or just TODO?
+ #scrollbar = tk.Scrollbar(canva, orient=tk.VERTICAL)
+ #canva.create_window(400, 20, window=scrollbar)
+
+ ## Create a list of all worlds
+ ypos = 60
+ for w in serverlist:
+ button = HoverButton(text=w["Name"], command=partial(launch_game, serverlist.index(w)), bg="#cc6600", fg="#fff", activebackground="#ee9933")
+ canva.create_window(200, ypos, window=button)
+ ypos += 40
+
return
+#################################################################################
## Login function
def login():
global canva, vaultId, vaultToken, saveMail, savePass
@@ -319,7 +348,8 @@ def login():
#################################################################################
## Build Tkinter interface
root=tk.Tk()
-canva = tk.Canvas(root, width=400, height=600, bg="#0c3251") # TODO: Coloring
+root.title("Mana Launcher (tk)")
+canva = tk.Canvas(root, width=400, height=600, bg="#0c3251")
canva.pack()
## Default variables
@@ -335,7 +365,7 @@ canva.create_window(200, 40, window=label1)
entry1 = tk.Entry(root)
entry1.insert(0, pref["user"])
canva.create_window(200, 80, window=entry1)
-c1 = tk.Checkbutton(root, text="Remember", variable=saveMail, bg="#0c3251", fg="#fff")
+c1 = tk.Checkbutton(root, text="Remember", variable=saveMail, bg="#0c3251", fg="#f70")
canva.create_window(350, 80, window=c1)
@@ -345,7 +375,7 @@ canva.create_window(200, 120, window=label2)
entry2 = tk.Entry(root, show="*")
entry2.insert(0, pref["pass"])
canva.create_window(200, 160, window=entry2)
-c1 = tk.Checkbutton(root, text="Remember", variable=savePass, bg="#0c3251", fg="#fff")
+c1 = tk.Checkbutton(root, text="Remember", variable=savePass, bg="#0c3251", fg="#f70")
canva.create_window(350, 160, window=c1)
@@ -357,7 +387,7 @@ entry3 = tk.Entry(root)
canva.create_window(200, 240, window=entry3)
-button1 = tk.Button(text='Login', command=login, bg="#cc6600", fg="#fff")
+button1 = HoverButton(text='Login', command=login, bg="#cc6600", fg="#fff", activebackground="#ee9933")
canva.create_window(200, 300, window=button1)
root.mainloop()
@@ -369,6 +399,7 @@ print("Thanks for playing!")
exit(0) # <- FIXME: Not necessary? Just delete stuff below
+#################################################################################
try:
while True:
command=str(input("> "))