Renpy Upload Save File To Server

MonaLav

New Member
Oct 3, 2024
8
5
Hello guys today im show you how to upload your save file to the server so the user not lost her save file.

Firstly you should have a hosting service or your own VPS to do it anyway i will guide both server side & renpy code

I will choose a PHP language to hosting the save file & store him

a server side code

PHP:
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_FILES['save_file'])) {
    $target_dir = "uploads/";
    $target_file = $target_dir . basename($_FILES["save_file"]["name"]);
    if (move_uploaded_file($_FILES["save_file"]["tmp_name"], $target_file)) {
        echo "The file ". htmlspecialchars(basename($_FILES["save_file"]["name"])). " has been uploaded.";
    } else {
        echo "Sorry, there was an error uploading your file.";
    }
}
?>
Now we should add a logic to our game to upload the save file lets do it

Open script.rpy

Code:
define upload_url = "http://yourserver.com/upload.php"

label upload_save_file:
    $ save_name = renpy.save("save_name")  # Adjust the save name as necessary
    $ save_path = renpy.config.save_dir + "/save_name"  # Get the path to the save file

    $ upload_file = renpy.file("upload_file", save_path)

    python:
        import requests

        with open(upload_file, 'rb') as f:
            files = {'save_file': f}
            response = requests.post(upload_url, files=files)
            renpy.say("Upload response: {}".format(response.text))

    return
Now the save should be upload to the server

Good luck
 

Catapo

Member
Jun 14, 2018
257
464
Hello, first of I would suggest if you want to upload tutorials to do it maybe in a single thread as opposed to spawning new threads for each small thing.
You may also consider posting in the Dev Help subforum.

Second, I would not encourage at all what you are suggesting here for multiple reasons:
- Players should ALWAYS know / be told that the game is connecting to a network location to collect data.
- Some players might want to do a full reset or they started over while offline so loading saves once connected might not be something they want at all.
- Depending on the number of players and the game the service should be prepared to store a lot of save files since the average players make more than one save. Also consider for how long do they need to keep them.
- There are methods to unpack games and look at the RenPy / Python code. If people get access to the post method towards the hosting service and with no validation in place, be prepared for the worst.
At best you might be spammed with memes at worst... I think you can imagine what sort of files circulate around the internet.

I don't want to shit on your content but IMO amateur developers should not be pushed towards this kind of stuff.

Good luck
 
  • Like
Reactions: gojira667

MonaLav

New Member
Oct 3, 2024
8
5
Do you read the post content i say a simple one i just give a idea, make threads for small things what do you thing? renpy code is short because use a python language the syntax or grammer are short what should i do, should i write a thousand line of word I don't care someone decompile the script i just give a idea & code there's many game upload the file to the server without any problem. also if the player use android they gonna be warning when they install & also this method just a algorithm you can tell the player in the main menu.

also i post in programming section I didn't see anything wrong with it because it's coding & I don't break the forum rule i respect you but i follow the forum rule not her user .

wish you luck too
 
  • Sad
Reactions: osanaiko

Catapo

Member
Jun 14, 2018
257
464
There was nothing wrong with where you posted, just considered that Dev Help might be more appropriate and a single thread more organized

I also did not say that a small tutorial was not fine or expecting "thousands of lines of code". I just said that a disclaimer should be added for people who might want to attempt this that there is a lot more to take into account ( on the ideea that many here copy paste code without thinking too much about it ).

But since someone is very defensive about their post feel free to ignore me and my "user rules" :rolleyes:

I genuinely wish you the best though :)
 

MonaLav

New Member
Oct 3, 2024
8
5
There was nothing wrong with where you posted, just considered that Dev Help might be more appropriate and a single thread more organized

I also did not say that a small tutorial was not fine or expecting "thousands of lines of code". I just said that a disclaimer should be added for people who might want to attempt this that there is a lot more to take into account ( on the ideea that many here copy paste code without thinking too much about it ).

But since someone is very defensive about their post feel free to ignore me and my "user rules" :rolleyes:

I genuinely wish you the best though :)
ok buddy im sorry if i say something not nice :)anyway we are to share a great things