206 lines
8.2 KiB
Python
206 lines
8.2 KiB
Python
#communication stuff here
|
|
|
|
import requests
|
|
import json
|
|
from hashlib import sha256
|
|
from pathlib import Path
|
|
from shutil import copyfileobj
|
|
from . import helpers, savetools
|
|
from websockets.sync.client import connect
|
|
from subprocess import Popen, PIPE
|
|
from sys import platform
|
|
from os import listdir
|
|
from os.path import isfile, join, exists
|
|
import os
|
|
from pathlib import Path
|
|
import subprocess
|
|
|
|
def startClient(self, id):
|
|
cmd = f"steam://rungameid/{id}"
|
|
Popen(['steam', cmd])
|
|
|
|
def downloadLatestDll(self, filepath):
|
|
x = requests.get('https://openwf.io/supplementals/client%20drop-in/meta')
|
|
meta = json.loads(x.text)
|
|
url = f"https://openwf.io/supplementals/client%20drop-in/{meta['version']}/dwmapi.dll"#
|
|
content = requests.get(url, stream=True).content
|
|
hashofdll = sha256()
|
|
hashofdll.update(content)#
|
|
if hashofdll.hexdigest() == meta['sha256']:
|
|
print(filepath)
|
|
with open(filepath + "dwmapi.dll", "wb") as out_file:
|
|
out_file.write(content)
|
|
helpers.messageBox(self=self,title="Bootstrapper Downloaded", message="Bootstrapper Downloaded!", type="info")
|
|
else:
|
|
helpers.messageBox(self=self,title="Unknown Error.", message="SpaceninGUI could not verify the hash of the Bootstrapper. Sorry :(", type="error")#
|
|
|
|
def getLatestVersions(self, cacheFile, value):
|
|
ver = {
|
|
"server" : (
|
|
"no lol" #not finished update check for server, check back later :3
|
|
),
|
|
"client" : ""
|
|
}
|
|
#client code here
|
|
x = requests.get('https://openwf.io/supplementals/client%20drop-in/meta')
|
|
meta = json.loads(x.text)
|
|
ver["client"] = meta['version']
|
|
|
|
try:
|
|
oldVer = savetools.loadFile(self, cacheFile)["client"]
|
|
except:
|
|
with open('tempFile.json', 'w') as f:
|
|
json.dump({
|
|
"client":'notassigned',
|
|
'server':'notassigned'
|
|
},f,indent=2)
|
|
|
|
oldVer = savetools.loadFile(self, cacheFile)["client"]
|
|
if oldVer == ver["client"]:
|
|
client="Up To Date!"
|
|
else:
|
|
client="New Version " + ver["client"]
|
|
server = "server Check Not Implemented"
|
|
value[0].set("Latest Server Version: " + server)
|
|
value[1].set("Latest Client Version: " + client)
|
|
|
|
def startServer(self, cd, logArea): # To my knowledge, running the server in the main thread would stall the gui, fuck that lol
|
|
logmax = helpers.getLogMax(self, self.configFile)
|
|
logarr=[]
|
|
def mongo():
|
|
sysctl = Popen(['systemctl', 'start', 'mongodb'])
|
|
sysctl.wait()#
|
|
def execute(cd):
|
|
popen = Popen(['npm', 'run', 'dev'], stdin=PIPE, stdout=PIPE, universal_newlines=True, cwd=cd, preexec_fn=os.setsid)
|
|
self.popenThreads.append(popen)
|
|
for stdout_line in iter(popen.stdout.readline, ""):
|
|
yield stdout_line
|
|
popen.stdout.close()
|
|
return_code = popen.wait()
|
|
if return_code:
|
|
raise subprocess.CalledProcessError(return_code)#
|
|
def start(cd, logArea):
|
|
for path in execute(cd):
|
|
if len(logarr) < logmax:
|
|
logarr.append(path)
|
|
else:
|
|
logarr.pop(0)
|
|
logarr.append(path)
|
|
if logArea:
|
|
logArea.configure(state="normal")
|
|
logArea.delete(1.0, "end")
|
|
for element in logarr:
|
|
logArea.insert("end", element)
|
|
logArea.configure(state="disabled")
|
|
|
|
if platform == "linux":
|
|
if not self.popenThreads:
|
|
helpers.messageBox(self, title="MongoDB", message="The mongodb server is required to start SNS\nYou will need to give sudo permission for this.", type="info")
|
|
mongo()
|
|
start(cd, logArea)
|
|
else:
|
|
helpers.messageBox(self, title="Already Running!", message="The Server is already running!", type="info")
|
|
|
|
def getClientResponse():
|
|
try:
|
|
with connect("ws://localhost:6155") as websocket:
|
|
message = json.loads(websocket.recv())
|
|
except:
|
|
message=False
|
|
return message
|
|
|
|
def checkForClient(clientpath):
|
|
onlyfiles = [f for f in listdir(clientpath) if isfile(join(clientpath, f))]
|
|
if "dwmapi.dll" in onlyfiles:
|
|
return True
|
|
else:
|
|
return False
|
|
|
|
def runPluto(self, name, runningList):
|
|
openwfpath = self.clientPath + "/OpenWF/scripts/"
|
|
onlyfiles = [f for f in listdir(openwfpath) if isfile(join(openwfpath, f))]
|
|
print("called " + name)
|
|
if getClientResponse():
|
|
running = []
|
|
print(getClientResponse()["running_scripts"])
|
|
if name in running:
|
|
requests.get(url=("http://localhost:6155/stop_script?OpenWF/scripts/" + name))
|
|
else:
|
|
requests.get(url=("http://localhost:6155/start_script?OpenWF/scripts/" + name))
|
|
|
|
for script in getClientesponse()["running_scripts"]:
|
|
running.append(script.removeprefix("OpenWF/scripts/"))#
|
|
for file in onlyfiles:
|
|
if file in running:
|
|
if runningList[file]: runningList[file].set(True)
|
|
else:
|
|
if runningList[file]: runningList[file].set(False)
|
|
else:
|
|
if runningList[name]: runningList[name].set(False)
|
|
|
|
def getSnPath(file):
|
|
if Path(file).is_file():
|
|
with open(file) as f:
|
|
d = json.load(f)
|
|
return d["spaceninjapath"]
|
|
else:
|
|
return False
|
|
|
|
def openClientLogs(self, platform):
|
|
if platform=="linux":
|
|
print("ok")
|
|
helpers.messageBox(self, "")
|
|
|
|
def pushWeapon(self, string, slot):
|
|
if type(string) is list:
|
|
i=0
|
|
for part in string:
|
|
print(i)
|
|
pluto = f"gRegion:GetLocalPlayerAvatar():InventoryControl():RemoveItem({slot[i]}, true) gRegion:GetLocalPlayerAvatar():GiveItem(Type(\"{part}\"), true)"
|
|
requests.get(f"http://localhost:61558/start_script_inline?{pluto}")
|
|
if slot[i] == 3:
|
|
level = f"gRegion:GetLocalPlayerAvatar():InventoryControl():GetActivePowerSuit():SetXP(1600000)"
|
|
else:
|
|
level = f"gRegion:GetLocalPlayerAvatar():InventoryControl():GetWeaponInHand({slot[i]}):SetXP(1600000)"
|
|
requests.get(f"http://localhost:61558/start_script_inline?{level}")
|
|
i+=1
|
|
else:
|
|
pluto = f"gRegion:GetLocalPlayerAvatar():InventoryControl():RemoveItem({slot}, true) gRegion:GetLocalPlayerAvatar():GiveItem(Type(\"{string}\"), true) gRegion:GetLocalPlayerAvatar():InventoryControl():GetWeaponInHand({slot}):SetXP(1600000)"
|
|
requests.get(f"http://localhost:61558/start_script_inline?{pluto}")
|
|
|
|
def pushInline(self, Area):
|
|
#format
|
|
formatted = Area.get(0.0, "end").replace("\n", ' ')
|
|
requests.get(f"http://localhost:61558/start_script_inline?{formatted}")
|
|
|
|
def getWarframeExports(self, path):
|
|
exportList = {
|
|
"weapons":"https://raw.githubusercontent.com/calamity-inc/warframe-public-export/refs/heads/senpai/ExportWeapons_en.json",
|
|
"powersuits":"https://raw.githubusercontent.com/calamity-inc/warframe-public-export/refs/heads/senpai/ExportWarframes_en.json"
|
|
}
|
|
for export in exportList.keys():
|
|
helpers.folderExist(path)
|
|
with open(path + f"{export}.json", "wb") as out_file:
|
|
content = requests.get(exportList[export], stream=True).content
|
|
out_file.write(content)
|
|
|
|
def getWarframeExportsPlus(self, path):
|
|
exportList = {
|
|
"weapons":"https://raw.githubusercontent.com/calamity-inc/warframe-public-export-plus/refs/heads/senpai/ExportWeapons.json",
|
|
"powersuits":"https://raw.githubusercontent.com/calamity-inc/warframe-public-export-plus/refs/heads/senpai/ExportWarframes.json"
|
|
}
|
|
for export in exportList.keys():
|
|
helpers.folderExist((path+"/plus/").replace("//", "/"))
|
|
with open((path + f"/plus/{export}.json").replace('//', '/'), "wb") as out_file:
|
|
content = requests.get(exportList[export], stream=True).content
|
|
out_file.write(content)
|
|
|
|
def getIconDownload(self, path, savePath):
|
|
if not exists("./cache/items/icons" + savePath.rsplit('/', 1)[0]):
|
|
Path("./cache/items/icons" + savePath.rsplit('/', 1)[0]).mkdir(parents=True, exist_ok=True)
|
|
|
|
with open("./cache/items/icons" + savePath, "wb+") as out_file:
|
|
print(f"https://browse.wf{savePath}")
|
|
out_file.write(requests.get(f"https://browse.wf{savePath}").content)
|
|
|
|
print(f"Saved {path} Icon") |