summaryrefslogtreecommitdiff
path: root/game
diff options
context:
space:
mode:
authorJesusaves <cpntb1@ymail.com>2021-05-08 02:59:58 -0300
committerJesusaves <cpntb1@ymail.com>2021-05-08 02:59:58 -0300
commitd4b8517586bc3b97cee15698da25c378c83e4669 (patch)
tree3c272e65715d0b146cd3a772cf1f677302f7495f /game
parent04e733c5b536af82b9e68ca41b54d299b52d482c (diff)
downloadrenpy-d4b8517586bc3b97cee15698da25c378c83e4669.tar.gz
renpy-d4b8517586bc3b97cee15698da25c378c83e4669.tar.bz2
renpy-d4b8517586bc3b97cee15698da25c378c83e4669.tar.xz
renpy-d4b8517586bc3b97cee15698da25c378c83e4669.zip
Client Download System (does not update, however)
Diffstat (limited to 'game')
-rw-r--r--game/client.rpy110
-rw-r--r--game/core.rpy24
-rw-r--r--game/options.rpy6
-rw-r--r--game/renpy.rpy9
-rw-r--r--game/update.rpy3
5 files changed, 143 insertions, 9 deletions
diff --git a/game/client.rpy b/game/client.rpy
index eeb981f..a3b30e7 100644
--- a/game/client.rpy
+++ b/game/client.rpy
@@ -4,9 +4,14 @@
#
# Distributed under the MIT license, except for Steam parts.
#################################################################################
-init python:
- def handle_client(CLIENT_NAME, launch=False):
+init 2 python:
+ def handle_client(CLIENT_NAME="", launch=False):
+ ## Local variables
f=False
+ if (CLIENT_NAME == ""):
+ CLIENT_NAME=persistent.client
+
+ ## Main loop
if (CLIENT_NAME == "manaplus"):
f=cli_manaplus(launch)
elif (CLIENT_NAME == "mana"):
@@ -15,26 +20,121 @@ init python:
stdout("ERROR, unrecognized client: %s" % CLIENT_NAME)
return f
-init -1 python:
+init 1 python:
+ #############################################################################
+ def download_manaplus(fname):
+ status_update("Downloading %s on RAM..." % fname, 62)
+ r=requests.get(persistent.host+"/%s" % fname, timeout=60.0)
+ if (r.status_code != 200):
+ stdout("Failure retrieving M+: ERROR %d" % r.status_code)
+ return False
+ status_update("Saving %s..." %fname, 64)
+ with open(installdir+"/%s" % fname, 'wb') as fd:
+ for chunk in r.iter_content(chunk_size=128):
+ fd.write(chunk)
+ status_update("Verifying MD5 hash...", 67)
+ r=requests.get(persistent.host+"/%s.md5" % fname, timeout=10.0)
+ md5up=r.text.replace("\n", "")
+ status_update("Verifying MD5 hash...", 69)
+ md5us=md5sum(installdir+"/%s" % fname)
+ if md5up != md5us:
+ status_update("MD5 Hash Error")
+ stdout("MD5 Mismatch: hashes differ", True)
+ stdout("Ours: %s" % md5us, True)
+ stdout("Them: %s" % md5up, True)
+ return False
+ return True
+
+ def install_manaplus():
+ installdir=get_path("manaplus")
+ ## Detect your plataform
+ if renpy.linux:
+ status_update("Creating ManaPlus directory...", 61)
+ execute("mkdir %s" % installdir, shell=True)
+ if not download_manaplus("ManaPlus.AppImage"):
+ return False
+ status_update("Installation successful!", 75)
+ elif renpy.windows:
+ status_update("Creating ManaPlus directory...", 61)
+ execute("mkdir %s" % installdir, shell=True)
+ if not download_manaplus("ManaPlus.zip"):
+ return False
+ status_update("Unzipping file...", 70)
+ with zipfile.ZipFile(installdir+"/ManaPlus.zip", 'r') as zip_ref:
+ zip_ref.extractall(installdir)
+ status_update("Installation successful!", 75)
+ #elif renpy.android:
+ #elif renpy.macintosh:
+ #elif renpy.emscripten: # web
+ else:
+ status_update("ERROR: Unsupported Plataform")
+ return False
+ return True
+
def cli_manaplus(launch=False):
- ## Check for ManaPlus
+ global SCR_PROMPT, SCR_RESULT
+ ## Check if ManaPlus is already installed
try:
MANAPLUS=os.path.exists(get_path("manaplus"))
except:
traceback.printexc()
MANAPLUS=False
+ ## Installer
+ if not MANAPLUS:
+ SCR_PROMPT=("Selected client \"%s\" is not installed.\nDo you wish to install it now?\n\n{size=14}By installing you agree with its {a=%s}Terms of Use and Conditions{/a}.{/size}" %
+ ("ManaPlus", "https://gitlab.com/themanaworld/manaplus/manaplus/-/raw/master/COPYING"))
+ while SCR_RESULT is None:
+ time.sleep(0.02)
+ ret=copy.copy(SCR_RESULT)
+ SCR_RESULT=None
+ if (not ret):
+ return False
+
+ try:
+ if not install_manaplus():
+ # Delete the failed attempt before raising the exception
+ shutil.rmtree(get_path("manaplus"))
+ #os.rmdir(get_path("manaplus"))
+ raise Exception("Installation failed!")
+ except:
+ traceback.print_exc()
+ stdout("Installation failed!", True)
+ return False
+
+ if launch:
+ if renpy.linux:
+ return get_path("manaplus")+"/ManaPlus.AppImage"
+ elif renpy.windows:
+ return get_path("manaplus")+"/Mana/manaplus.exe"
+ else:
+ stdout("Invalid Plataform!")
+ return False
return True
+ #############################################################################
def cli_mana(launch=False):
stdout("ERROR, Mana Client is not implemented!")
+ return False
+
## Check for Mana
try:
MANA=os.path.exists(get_path("mana"))
except:
traceback.printexc()
MANA=False
- return False
+
+ ## Installer
+ if not MANAPLUS:
+ SCR_PROMPT=("Selected client \"%s\" is not installed.\nDo you wish to install it now?\n\n{size=14}By installing you agree with its {a=%s}Terms of Use and Conditions{/a}.{/size}" %
+ ("Mana", "https://gitlab.com/themanaworld/tmw-client/????/-/raw/master/COPYING"))
+ while SCR_RESULT is None:
+ time.sleep(0.02)
+ ret=copy.copy(SCR_RESULT)
+ SCR_RESULT=None
+ if (not ret):
+ return False
+ return True
diff --git a/game/core.rpy b/game/core.rpy
index f95c289..0d40e66 100644
--- a/game/core.rpy
+++ b/game/core.rpy
@@ -8,7 +8,7 @@
init -3 python:
renpy.add_python_directory("python-extra")
import requests, zlib, base64, sys, copy, uuid, time, json, traceback
- import os.path
+ import os.path, os, shutil, subprocess, hashlib, zipfile
# non-free imports
import _renpysteam as steam
import discord_rpc
@@ -22,12 +22,14 @@ init -3 python:
# Ren'Py should come with Python 2.7.10 (2710), but just in case
# After all, I only tested with 2.7.10, 2.7.13 and 2.7.15
if (PYTHON_VERSION < 2700 or PYTHON_VERSION > 3000):
+ execute=subprocess.run
+ # FIXME: check must be set and True
raise Exception("WARNING: Python version is not 2.7\nStrange bugs may happen on your client.\n\nClick on \"Ignore\" to continue.\nClick on \"Quit\" to exit.")
+ else:
+ execute=subprocess.call
#############################################################################
## Configuration and Defaults
- config.autoreload = False
- config.save_on_mobile_background = False
if (persistent.discord is None):
persistent.discord = True
if (persistent.client is None):
@@ -38,6 +40,20 @@ init -3 python:
VAULT_HOST = "http://localhost:13370"
#############################################################################
+ # Encodes something to md5
+ def md5(string):
+ return hashlib.md5(string.encode()).hexdigest()
+
+ def md5sum(f):
+ md5=hashlib.md5()
+ fp=open(f, "rb")
+ ct=fp.read()
+ md5.update(ct)
+ rt=copy.copy(md5.hexdigest())
+ fp.close()
+ del ct
+ return rt
+
# Smart Print command
def stdout(message, bd=False):
if config.developer:
@@ -131,5 +147,7 @@ default statusmsg = "Not yet initialized"
default progress = 0
default responsive = True
default has_steam = False
+default SCR_PROMPT = None
+default SCR_RESULT = None
diff --git a/game/options.rpy b/game/options.rpy
index cecbfd2..2dd1832 100644
--- a/game/options.rpy
+++ b/game/options.rpy
@@ -44,6 +44,12 @@ define gui.about = _p("""
define build.name = "Mana-Launcher"
+## Some Ren'Py features which must be disabled
+
+define config.autoreload = False
+define config.save_on_mobile_background = False
+define config.has_autosave = False
+
## Sounds and music ############################################################
diff --git a/game/renpy.rpy b/game/renpy.rpy
index 954c117..f66af2a 100644
--- a/game/renpy.rpy
+++ b/game/renpy.rpy
@@ -8,6 +8,8 @@
image TMW2 = "images/TMW2.png"
screen loading():
+ zorder 100
+
fixed:
frame:
xfill True
@@ -42,6 +44,13 @@ label start:
else:
break
+ # Maybe we are waiting some prompt
+ if SCR_PROMPT is not None:
+ SCR_RESULT = renpy.call_screen("confirm", SCR_PROMPT,
+ Return(True), Return(False))
+ SCR_PROMPT = None
+
+
# Kill the program
if not responsive:
jump die
diff --git a/game/update.rpy b/game/update.rpy
index 033657b..edef6d1 100644
--- a/game/update.rpy
+++ b/game/update.rpy
@@ -12,6 +12,7 @@ init python:
progress=min(pc, 100)
if (smsg != ""):
statusmsg=smsg
+ stdout(smsg)
def validate_server(srv):
name="Unknown Server"; ok=False
@@ -139,7 +140,7 @@ init python:
# Check for clients, this block is 60~80%
status_update("Checking for installed clients...", 60)
- r=handle_client(persistent.client)
+ r=handle_client()
## Oh sh--
if not r: