Jump to content

Extremely simple/stupid, but functional, shared save file solution


spiritplumber

Recommended Posts

I wrote this.

It works.

I own emlia.org so feel free to use it.

Save this as ftpsync.bat or something like that, and put it in your KSP folder.

I want to next make a plugin that autosyncs based on when Space Center is entered, but will only do so if this is useful at all. If this gets used, I can see if the server can take the load.

Thanks in advance.

I have nothing witty to say.


:preinit
set savename=overwritable
rem this deletes all empty files (housekeeping)
for %%F in (*) do if %%~zF equ 0 del "%%F"
if exist ftpsync.txt goto init
echo off
cls
echo.
echo You have never run this script, so a settings file has been created.
echo All it contains is the name of your shared save file.
echo Be sure to use the same shared save file as your group!
echo.
echo This settings file is called ftpsync.txt
echo.
echo Right now it contains "overwritable" which is the default, there
echo is no way of knowing what will be in there. Give it a go if you
echo dare...
echo.
echo You can use notepad to change that file and enter a new name. If
echo there is no shared save with that name, you can create one
echo within KSP.
echo.
echo Be sure to ONLY type in the name of the shared save, NO newlines
echo and no spaces. Spaces in shared save games are not allowed right now.
echo Trailing spaces will be ignored.
echo.
echo This script will now let you edit the save name.
echo Hit save when you're done!
echo.
echo Have fun! [email protected]
<nul set /p "savename=overwritable" > ftpsync.txt
start /wait notepad ftpsync.txt
:init
echo off
set /P savename=<ftpsync.txt
rem this is to make sure subassemblymanager works
mkdir pluginData\subassemblyLoader
mkdir pluginData\subassemblyLoader\subassemblies
mkdir pluginData\subassemblyLoader\subassemblies\Landers
mkdir pluginData\subassemblyLoader\subassemblies\Lifters
mkdir pluginData\subassemblyLoader\subassemblies\Probes
mkdir pluginData\subassemblyLoader\subassemblies\Impactors
mkdir pluginData\subassemblyLoader\subassemblies\Other

:start
cls
if not %savename%==overwritable goto nowarn
if "%savename%"=="" goto abort
:warn
echo.
echo You should probably edit the settings file and change the save name to something else!
echo.
echo Close this window now, or press a key to continue with the overwritable save name.
echo.
pause >nul

:nowarn
rem if exist saves move saves single_saves
rem if exist single_saves move synch_saves saves
rem move saves single_saves
rem move synch_saves saves
mkdir saves
cd saves
mkdir %savename%
cd %savename%
mkdir Ships
mkdir Ships\VAB
mkdir Ships\SPH
for %%F in (*) do if %%~zF equ 0 del "%%F"
if exist %savename%.ksp goto abort


:ftp_get
rem I know that I'm giving away a password. I made a ftp account for just this and nothing else. Nyah nyah.
echo open emlia.org > ftp_get.scr
echo [email protected] >> ftp_get.scr
echo c5ZTrG7nHqGr>> ftp_get.scr
echo get %savename%.ksp >> ftp_get.scr
echo disconnect >> ftp_get.scr
echo bye >> ftp_get.scr

ftp -i -s:"ftp_get.scr"
if not %errorlevel%==0 goto abort

copy /y %savename%.ksp persistent.sfs
if not %errorlevel%==0 goto abort
for %%F in (*) do if %%~zF equ 0 del "%%F"
if exist persistent.sfs goto runme

:emptyfile
cd ..
cls
echo.
echo There is no shared save file named %savename% on our server.
echo.
echo Go ahead and create one! Just be sure to name it exactly -^> %savename% ^<-
echo Get to at least the Space Center screen.
echo Be sure to give your group this name! They should be able to download it
echo after you quit KSP and let the script sync.
echo.
rd /S /Q %savename%
if not %errorlevel%==0 goto abort
cd ..
pause
cls
echo.
echo KSP is now running. Be sure to use the %savename% save.
echo.
start /wait /low KSP.exe
if not %errorlevel%==0 goto abort
cd saves
cd %savename%
if not exist persistent.sfs goto abort
goto afterrun

:runme
cls
echo.
echo KSP is now running. Be sure to use the %savename% save.
echo.
start /wait /low ../../KSP.exe
if not %errorlevel%==0 goto abort


:afterrun
copy /y persistent.sfs %savename%.ksp
if not %errorlevel%==0 goto abort

:ftp_put
rem I know that I'm giving away a password. I made a ftp account for just this and nothing else. Nyah nyah.
echo open emlia.org > ftp_put.scr
echo [email protected] >> ftp_put.scr
echo c5ZTrG7nHqGr>> ftp_put.scr
echo put %savename%.ksp >> ftp_put.scr
echo disconnect >> ftp_put.scr
echo bye >> ftp_put.scr

ftp -i -s:"ftp_put.scr"
if not %errorlevel%==0 goto abort

del %savename%.ksp
del ftp_put.scr
del ftp_get.scr
cd ..
cd ..
rem if exist saves move save synch_saves
rem if exist single_saves move single_saves saves
goto done
:abort
echo %errorlevel%
echo.
echo Something went wrong. See above.
pause
:done

Link to comment
Share on other sites

This is a more granular version, which syncs when stuff happens in game. It uploads a persistent file every time it changes, and downloads when you first load the game OR when you exit to the main menu so that you can load a game. This makes it so you don't have to get out of KSP.

The two are compatible.

I recommend using the first one for playing when there is a great distance in time between turns, and this one for playing turn-based, like in the Battle for Laythe video.


echo off
cls
if exist ftpsync.txt goto init
echo off
cls
echo.
echo You have never run this script, so a settings file has been created.
echo All it contains is the name of your shared save file.
echo Be sure to use the same shared save file as your group!
echo.
echo This settings file is called ftpsync.txt
echo.
echo Right now it contains "overwritable" which is the default, there
echo is no way of knowing what will be in there. Give it a go if you
echo dare...
echo.
echo You can use notepad to change that file and enter a new name. If
echo there is no shared save with that name, you can create one
echo within KSP.
echo.
echo Be sure to ONLY type in the name of the shared save, NO newlines
echo and no spaces. Spaces in shared save games are not allowed right now.
echo Trailing spaces will be ignored.
echo.
echo This script will now let you edit the save name.
echo Hit save when you're done!
echo.
echo Have fun! [email protected]
<nul set /p "savename=overwritable" > ftpsync.txt
start /wait notepad ftpsync.txt

:init
set /P savename=<ftpsync.txt
set ksp_missions_old=noneyet
set ksp_scenetrans_old=notyet
echo %savename%
cd saves
cd %savename%
echo Be sure to use the %savename% save file! No other file will be synchronized.
rem Use log files to see if KSP exists and runs
if not exist ..\..\KSP.log echo dummyfile > ..\..\KSP.log
if not exist KSP.log echo dummyfile > KSP.log
move ..\..\KSP.log ..\..\KSP.mog 2>nul
if %errorlevel%==0 goto kspset
goto noksp
:kspset
move KSP.log KSP.mog 2>nul
if %errorlevel%==0 goto noksp

:loopme
rem see if ksp is still going
move KSP.log KSP.mog 2>nul
if %errorlevel%==0 goto end
if not exist ksp.log goto abort
rem find the magic phrase in ksp.log and write down how often it occurs, to get an idea of game state
for /f "delims=" %%a in ('find /C "Game State Saved as persistent" ksp.log') do @set ksp_missions_new=%%a
for /f "delims=" %%a in ('find /C "to MAINMENU" ksp.log') do @set ksp_scenetrans_new=%%a
rem echo %ksp_missions_new%
if "%ksp_scenetrans_old%"=="notyet" goto syncread
if not "%ksp_missions_old%"=="%ksp_missions_new%" goto syncwrite
if not "%ksp_scenetrans_old%"=="%ksp_scenetrans_new%" goto syncread
rem echo Probably nothing to do, waiting a little to check again.
goto waithere

:syncwrite
set ksp_missions_old=%ksp_missions_new%
echo Local saveable data has changed, uploading to server.
rem I know that I'm giving away a password. I made a ftp account for just this and nothing else. Nyah nyah.
copy /y persistent.sfs %savename%.ksp >nul
echo open emlia.org > ftp_put.scr
echo [email protected] >> ftp_put.scr
echo c5ZTrG7nHqGr>> ftp_put.scr
echo put %savename%.ksp >> ftp_put.scr
echo disconnect >> ftp_put.scr
echo bye >> ftp_put.scr
ftp -i -s:"ftp_put.scr" > nul
if not %errorlevel%==0 goto abord
echo Done, resuming wait.
goto waithere

:syncread
set ksp_scenetrans_old=%ksp_scenetrans_new%
rem prevents immediate reupload
set ksp_missions_old=%ksp_missions_new%
echo Local saveable data is retrievable, retrieving from server.
rem I know that I'm giving away a password. I made a ftp account for just this and nothing else. Nyah nyah.
echo open emlia.org > ftp_get.scr
echo [email protected] >> ftp_get.scr
echo c5ZTrG7nHqGr>> ftp_get.scr
echo get %savename%.ksp >> ftp_get.scr
echo disconnect >> ftp_get.scr
echo bye >> ftp_get.scr
ftp -i -s:"ftp_get.scr" > nul
if not %errorlevel%==0 goto abort
for %%F in (*) do if %%~zF equ 0 del "%%F"
copy /y %savename%.ksp persistent.sfs >nul
echo Done, resuming wait.
goto waithere

:waithere
ping -n 10 localhost>nul
goto loopme

:noksp
echo Launching KSP for you.
echo.
del ksp.mog >nul 2>nul
del ..\..\ksp.mog >nul 2>nul
start ..\..\KSP.exe
rem if your pc loads ksp in less than 40 seconds, i hate you anyway
ping -n 40 localhost>nul
rem initialize
for /f "delims=" %%a in ('find /C "Game State Saved as persistent" ksp.log') do @set ksp_missions_new=%%a
for /f "delims=" %%a in ('find /C "to MAINMENU" ksp.log') do @set ksp_scenetrans_new=%%a
rem force read (and finish initializing the variables)
goto syncread

:abort
echo Something derped.
pause

:end
del ftp_get.scr
del ftp_put.scr
del %savename%.ksp
del ..\..\ksp.mog >nul 2>nul
del ..\..\ksp_%savename%_old.log >nul 2>nul
move ksp.mog ..\..\ksp_%savename%_old.log
del ksp.mog >nul 2>nul

Link to comment
Share on other sites

Yes, that is what it does.

However, I wrote a better one, in the meantime. The two are compatible.

http://emlia.org/ksp_shared/ You can even see what people are doing.

This one is a bit more bandwidth intensive, but more granular.

Copy and paste it into ftpsync.bat or similar, and run in the KSP folder.

You should have a premade save...

echo off
cls
if exist ftpsync.txt goto init
echo off
cls
echo.
echo You have never run this script, so a settings file has been created.
echo All it contains is the name of your shared save file.
echo Be sure to use the same shared save file as your group!
echo.
echo This settings file is called ftpsync.txt
echo.
echo Right now it contains "overwritable" which is the default, there
echo is no way of knowing what will be in there. Give it a go if you
echo dare...
echo.
echo You can use notepad to change that file and enter a new name. If
echo there is no shared save with that name, you can create one
echo within KSP.
echo.
echo Be sure to ONLY type in the name of the shared save, NO newlines
echo and no spaces. Spaces in shared save games are not allowed right now.
echo Trailing spaces will be ignored.
echo.
echo This script will now let you edit the save name.
echo Hit save when you're done!
echo.
echo Have fun! [email protected]
<nul set /p "savename=overwritable" > ftpsync.txt
start /wait notepad ftpsync.txt

:init
set /P savename=<ftpsync.txt
set ksp_missions_old=noneyet
set ksp_scenetrans_old=notyet
echo %savename%
cd saves
cd %savename%
echo Be sure to use the %savename% save file! No other file will be synchronized.
rem Use log files to see if KSP exists and runs
if not exist ..\..\KSP.log echo dummyfile > ..\..\KSP.log
if not exist KSP.log echo dummyfile > KSP.log
move ..\..\KSP.log ..\..\KSP.mog 2>nul
if %errorlevel%==0 goto kspset
goto noksp
:kspset
move KSP.log KSP.mog 2>nul
if %errorlevel%==0 goto noksp

:loopme
rem see if ksp is still going
move KSP.log KSP.mog 2>nul
if %errorlevel%==0 goto end
if not exist ksp.log goto abort
rem find the magic phrase in ksp.log and write down how often it occurs, to get an idea of game state
for /f "delims=" %%a in ('find /C "Game State Saved as persistent" ksp.log') do @set ksp_missions_new=%%a
for /f "delims=" %%a in ('find /C "to MAINMENU" ksp.log') do @set ksp_scenetrans_new=%%a
rem echo %ksp_missions_new%
if "%ksp_scenetrans_old%"=="notyet" goto syncread
if not "%ksp_missions_old%"=="%ksp_missions_new%" goto syncwrite
if not "%ksp_scenetrans_old%"=="%ksp_scenetrans_new%" goto syncread
rem echo Probably nothing to do, waiting a little to check again.
goto waithere

:syncwrite
set ksp_missions_old=%ksp_missions_new%
echo Local saveable data has changed, uploading to server.
rem I know that I'm giving away a password. I made a ftp account for just this and nothing else. Nyah nyah.
copy /y persistent.sfs %savename%.ksp >nul
echo open emlia.org > ftp_put.scr
echo [email protected] >> ftp_put.scr
echo c5ZTrG7nHqGr>> ftp_put.scr
echo put %savename%.ksp >> ftp_put.scr
echo disconnect >> ftp_put.scr
echo bye >> ftp_put.scr
ftp -i -s:"ftp_put.scr" > nul
if not %errorlevel%==0 goto abord
echo Done, resuming wait.
goto waithere

:syncread
set ksp_scenetrans_old=%ksp_scenetrans_new%
rem prevents immediate reupload
set ksp_missions_old=%ksp_missions_new%
echo Local saveable data is retrievable, retrieving from server.
rem I know that I'm giving away a password. I made a ftp account for just this and nothing else. Nyah nyah.
echo open emlia.org > ftp_get.scr
echo [email protected] >> ftp_get.scr
echo c5ZTrG7nHqGr>> ftp_get.scr
echo get %savename%.ksp >> ftp_get.scr
echo disconnect >> ftp_get.scr
echo bye >> ftp_get.scr
ftp -i -s:"ftp_get.scr" > nul
if not %errorlevel%==0 goto abort
for %%F in (*) do if %%~zF equ 0 del "%%F"
copy /y %savename%.ksp persistent.sfs >nul
echo Done, resuming wait.
goto waithere

:waithere
ping -n 10 localhost>nul
goto loopme

:noksp
echo Launching KSP for you.
echo.
del ksp.mog >nul 2>nul
del ..\..\ksp.mog >nul 2>nul
start ..\..\KSP.exe
rem if your pc loads ksp in less than 40 seconds, i hate you anyway
ping -n 40 localhost>nul
rem initialize
for /f "delims=" %%a in ('find /C "Game State Saved as persistent" ksp.log') do @set ksp_missions_new=%%a
for /f "delims=" %%a in ('find /C "to MAINMENU" ksp.log') do @set ksp_scenetrans_new=%%a
rem force read (and finish initializing the variables)
goto syncread

:abort
echo Something derped.
pause

:end
del ftp_get.scr
del ftp_put.scr
del %savename%.ksp
del ..\..\ksp.mog >nul 2>nul
del ..\..\ksp_%savename%_old.log >nul 2>nul
move ksp.mog ..\..\ksp_%savename%_old.log
del ksp.mog >nul 2>nul

Link to comment
Share on other sites

It's not synchronizing, but more like facilitating sharing of saves. You probably should not have multiple people playing using the shared save at the same time as whichever save is uploaded last will be the save game used. This would work to help people who want to play in turns or shifts using the same persistence file.

Link to comment
Share on other sites

It's not synchronizing, but more like facilitating sharing of saves. You probably should not have multiple people playing using the shared save at the same time as whichever save is uploaded last will be the save game used. This would work to help people who want to play in turns or shifts using the same persistence file.

This is in fact the intended use yes :)

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...