modification of the timer and prohibition of launching the application without the Internet

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
Andredron
Miko-Class Veteran
Posts: 700
Joined: Thu Dec 28, 2017 2:37 pm
Location: Russia
Contact:

modification of the timer and prohibition of launching the application without the Internet

#1 Post by Andredron »

Once upon a time, a timer was created that works even after exiting the game, as well as modified by Mr. Python, and I often receive requests from familiar mobile developers to upgrade it.

viewtopic.php?f=51&t=47774

the bottom line is, users rewind time, and it makes no sense for them to buy buffs to speed up time in their mobile farms.

the first thing that came to my mind was checking the time via the Internet.



I found one site, and the corresponding module so that users can use json ,

https://pypi.org/project/world-time-api/

http://worldtimeapi.org/

but then there is a 2 problem, how to prevent the application from starting if there is no Internet access?


help please

User avatar
_ticlock_
Miko-Class Veteran
Posts: 910
Joined: Mon Oct 26, 2020 5:41 pm
Contact:

Re: modification of the timer and prohibition of launching the application without the Internet

#2 Post by _ticlock_ »

Andredron wrote: Sun Dec 04, 2022 1:57 am
Rough idea:

Maybe make a python function that does all the job and if necessary call some label like bad_connection with an option to try and reconnect(or call screen in new context). Possibly put this function in some callbacks (Configuration Variables) and/or some part of the game that is supposed to check the time before doing anything.
Function:
1) To reduce internet connection or not completely avoid offline mode, introduce variables last_internet_time and last_system_time.

Code: Select all

# just logic, not actual code
if (current_system_time > last_internet_time and 
    current_system_time > last_system_time and 
    current_system_time - last_internet_time < 4 hours):
     
    last_system_time = current_system_time
    return
else
    #check internet time
2) To check internet time, I think you can simply try to retrieve it, if it fails, one can assume that there is no internet connection and call label like bad_connection

Code: Select all

try:
    #retrieve internet time
except:
    #call bad_connection

User avatar
Andredron
Miko-Class Veteran
Posts: 700
Joined: Thu Dec 28, 2017 2:37 pm
Location: Russia
Contact:

Re: modification of the timer and prohibition of launching the application without the Internet

#3 Post by Andredron »

https://github.com/valery-iwanofu suggested:

1) Through requests, you can do this:

Code: Select all

import requests

time_data = requests.get('http://worldtimeapi.org/api/timezone/Etc/UTC').json()


2) You can also install the package via pip, but for this you need a downloaded python:
pip install —target game/python-packages world-time-api

And then use the API of this package


then I will dig thoroughly in this direction, thank you for your help

User avatar
Andredron
Miko-Class Veteran
Posts: 700
Joined: Thu Dec 28, 2017 2:37 pm
Location: Russia
Contact:

Re: modification of the timer and prohibition of launching the application without the Internet

#4 Post by Andredron »

author 7dots
https://store.steampowered.com/curator/29064054

https://pastebin.com/Hd0XnvXU

Code: Select all

a timer on renpy that checks time over the internet
 
init python:
    import requests
    import datetime
 
    # get current datetime from site
    def get_worldtime():
        res = None
        try:
            # get data from worldtimeapi.org
            data = requests.get('http://worldtimeapi.org/api/timezone/Etc/UTC').json()["datetime"]
            # convert string to datetime format
            res = datetime.datetime.fromisoformat(data)
        except requests.RequestException as e:
            renpy.notify("Something wrong: " + str(e))
        return res
 
    # using sample
    def check_time():
        world_now = get_worldtime().timestamp()
        now = datetime.utcnow().timestamp()
        # do what you want
        # ***
        dt = now - world_now
        renpy.notify(str(dt))
 
label start:
    # test
    # $ check_time()
    # $ t = get_worldtime()
    # "[t]"
 
    python:
        now = datetime.utcnow().timestamp()
        world_now = get_worldtime().timestamp()
        dt = now - world_now
    $ xxx = str(dt)
    "No pause: [xxx]"
 
    python:
        now = datetime.utcnow().timestamp()
        renpy.pause(2)
        world_now = get_worldtime().timestamp()
        dt = now - world_now
    $ xxx = str(dt)
    "With pause: [xxx]"
 
    return
it remains to solve the problem with the error when there is no Internet

https://www.renpy.org/doc/html/label.ht ... ew_context

use this code, and

Code: Select all

python:
..now = somehow_get_local_time()
..server_now = somehow_get_server_time()
if server_now is None:
..call bad_connection

...there will be trouble with saving...

Post Reply

Who is online

Users browsing this forum: No registered users