Skip to content

Commit

Permalink
Raise the empires backup & restore, versiontag
Browse files Browse the repository at this point in the history
  • Loading branch information
Natlies committed Sep 14, 2019
1 parent 3547727 commit 3463854
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 21 deletions.
40 changes: 34 additions & 6 deletions empires-server.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

# import logging.config

version = "0.2"
version = "0.02a"

COMPRESS_MIMETYPES = ['text/html', 'text/css', 'text/xml', 'application/json', 'application/javascript',
'application/x-amf']
Expand Down Expand Up @@ -87,6 +87,7 @@ def more_money():
if 'user_object' in session:
player = session['user_object']["userInfo"]["player"]
player['cash'] += 10000
session['saved'] = True
response = make_response(redirect('/home.html'))
return response
else:
Expand All @@ -97,45 +98,71 @@ def more_money():
def save_editor():
backups = []
s = session
backup_count = 0
while "backup" in s:
backups.append(str(datetime.fromtimestamp(s["backup"].get('saved_on', 0))) + ' - ' \
+ str(datetime.fromtimestamp(s["backup"].get('replaced_on', 0))) + ' @' + s["backup"].get('save_version', 'UNKNOWN VERSION'))
backups.append(format_backup_message(s["backup"]))
s = s["backup"]
backup_count += 1
print("Backups present", backup_count)

return render_template("save-editor.html", savegame=json.dumps(
{
'user_object': session['user_object'] if 'user_object' in session else None,
'quests': session['quests'] if 'quests' in session else None,
'battle': session['battle'] if 'battle' in session else None,
'fleets': session['fleets'] if 'fleets' in session else None,
'population': session['population'] if 'population' in session else None
'population': session['population'] if 'population' in session else None,
'saved': session['saved'] if 'saved' in session else None,
'save_version': session['save_version'] if 'save_version' in session else None,
'original_save_version': session['original_save_version'] if 'original_save_version' in session else None,
}, default=lambda o: '<not serializable>', sort_keys=False, indent=2), uid=get_zid(), backups=backups)


@app.route("/save-editor", methods=['POST'])
def save_savegame():
print("Going to save:")
save_game = json.loads(request.form['savegame'])
restores = [int(key[7:]) for key in request.form.keys() if "restore" in key]

if restores:
save_game = session["backup"]
for i in range(restores[0]):
save_game = save_game["backup"]
save_game = copy.deepcopy(save_game)
print("restoring backup")
message = "Revert to backup \"" + format_backup_message(save_game) + "\""
else:
save_game = json.loads(request.form['savegame'])
message = "before " + request.form.get("message")

print(repr(save_game))
session["backup"] = {k: v for k, v in session.items() if
k in ['user_object', 'quests', 'battle', 'fleets', 'population', 'saved', 'saved_on',
'save_version', 'backup']} # nested backups
'save_version', 'original_save_version', 'backup']} # nested backups

session['user_object'] = save_game['user_object']
session['quests'] = save_game['quests']
session['battle'] = save_game['battle']
session['fleets'] = save_game['fleets']
session['population'] = save_game['population']
session['save_version'] = save_game['save_version']
session['saved'] = True
timestamp = datetime.now().timestamp()
session['saved_on'] = timestamp
session["backup"]['replaced_on'] = timestamp
session["backup"]['message'] = message

response = make_response(redirect('/home.html'))
return response
# return ('', 400)


def format_backup_message(backup):
return datetime.fromtimestamp(backup.get('saved_on', 0)).strftime("%d %b %Y %H:%M:%S") + ' - ' \
+ datetime.fromtimestamp(backup.get('replaced_on', 0)).strftime("%d %b %Y %H:%M:%S") + ' @' \
+ backup.get('save_version', 'UNKNOWN VERSION') + ' ' \
+ backup.get("message", "")


@app.route("/127.0.0.1record_stats.php", methods=['GET', 'POST'])
def record_stats():
return ('', 204)
Expand Down Expand Up @@ -971,6 +998,7 @@ def user_response():
new_quest_with_sequels("Q0516", qc)
session['quests'] = qc
session['save_version'] = version
session['original_save_version'] = version
session['saved_on'] = datetime.now().timestamp()

# session['user_object']["userInfo"]["player"]["tutorialProgress"] = "tut_step_krunsch1Battle2Speeech" #'tut_step_inviteFriendsViral'
Expand Down
2 changes: 2 additions & 0 deletions templates/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
alpha v0.02a
changelog, nodebug Nat 14/09/2019 01:47
basic countState quest progression Nat 14/09/2019 01:23
consumable poison gas (boss fight only), fixes Nat 14/09/2019 00:21
new quest precompletion fix Nat 13/09/2019 01:06
battleDamage, battleKill quest progression Nat 13/09/2019 00:04
Expand Down
4 changes: 2 additions & 2 deletions templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@
<div>
<div class="loggedout_menubar_container">
<div class="clearfix loggedout_menubar">
<a class="lfloat" href="#" title="Go to Facebook Home">
<a class="lfloat" href="/" title="Go to Facebook Home">
<i class="fb_logo img sp_e2gpgs sx_584554">
<u>Facebook logo</u>
</i>
Expand Down Expand Up @@ -280,7 +280,7 @@
<div class="uiInterstitialBar uiBoxGray topborder">
<div class="clearfix">

<img src="layouts/logo.png">
<img src="layouts/logo.png"><p style="display: inline">0.02a</p>


<div class="rfloat">
Expand Down
4 changes: 2 additions & 2 deletions templates/nodebug.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
<div>
<div class="loggedout_menubar_container">
<div class="clearfix loggedout_menubar">
<a class="lfloat" href="#" title="Go to Facebook Home">
<a class="lfloat" href="/" title="Go to Facebook Home">
<i class="fb_logo img sp_e2gpgs sx_584554">
<u>Facebook logo</u>
</i>
Expand Down Expand Up @@ -147,7 +147,7 @@
<div class="uiInterstitialBar uiBoxGray topborder">
<div class="clearfix">

<img src="layouts/logo.png">
<img src="layouts/logo.png"><p style="display: inline">0.02a</p>


<div class="rfloat">
Expand Down
2 changes: 1 addition & 1 deletion templates/releases.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<div>
<div class="loggedout_menubar_container">
<div class="clearfix loggedout_menubar">
<a class="lfloat" href="#" title="Go to Facebook Home">
<a class="lfloat" href="/" title="Go to Facebook Home">
<i class="fb_logo img sp_e2gpgs sx_584554">
<u>Facebook logo</u>
</i>
Expand Down
26 changes: 16 additions & 10 deletions templates/save-editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<div>
<div class="loggedout_menubar_container">
<div class="clearfix loggedout_menubar">
<a class="lfloat" href="#" title="Go to Facebook Home">
<a class="lfloat" href="/" title="Go to Facebook Home">
<i class="fb_logo img sp_e2gpgs sx_584554">
<u>Facebook logo</u>
</i>
Expand Down Expand Up @@ -85,6 +85,7 @@
<div id="contentArea" role="main" aria-describedby="pageTitle">


<form action="/save-editor" method="post">
<div class="mvl ptm uiInterstitial canvas_error_page uiBoxWhite" title="" style="margin-left: 70px; margin-right: 50px">
<div class="uiHeader uiHeaderBottomBorder mhl mts uiHeaderPage interstitialHeader">
<div class="clearfix uiHeaderTop">
Expand All @@ -93,19 +94,19 @@ <h2 class="uiHeaderTitle" aria-hidden="true"> Raise The Empires Save Editor uid:
</div>
</div>
</div>


<form action="/save-editor" method="post">

<div class="phl ptm uiInterstitialContent">
<textarea rows="30" cols="135" name="savegame" >
{{ savegame | default("ERROR: No savegame present!")}}
</textarea>
<br>
<textarea rows="30" cols="135" name="savegame" >{{ savegame | default("ERROR: No savegame present!")}}</textarea><br>
<input type="text" size="135" name="message" placeholder="What did you change?"><br>
<span style="color: crimson"><b>Warning:</b> This can corrupt your savegame!</span>
</div>
<div class="uiInterstitialBar uiBoxGray topborder">
<div class="clearfix">
<div class="rfloat">
<a class="inputaux uiButton" href="home.html" role="button" name="exit_button">
<span class="uiButtonText">Cancel</span>
</a>
<a class="uiButton uiButtonConfirm" href="home.html" role="button" name="try_again_button">
<span class="uiButtonText"></span>
<input type="submit" value="Save game">
Expand All @@ -115,15 +116,20 @@ <h2 class="uiHeaderTitle" aria-hidden="true"> Raise The Empires Save Editor uid:
</div>
</div>
</div>
</form>

</div>

<div class="mvl ptm uiInterstitial canvas_error_page uiInterstitialLarge uiBoxWhite" id="backup-list" style=" padding: 9px">
<h2 class="uiHeaderTitle" aria-hidden="true"> Backups:</h2>
{{ backups }} <a class="inputaux uiButton" href="#" role="button" name="exit_button">
<span class="">Restore this backup</span>
{% for backup in backups %}
{{ backup }} <a class="inputaux uiButton" href="#" role="button" name="exit_button">
<input type="submit" name="restore{{ backups.index(backup) }}" value="Restore this backup">

</a>
<br />
{% endfor %}
</div>
</form>

<div id="canvas_throbber">
<div class="mbl fsl fwb" id="canvas_throbber_text">Loading...</div>
Expand Down

0 comments on commit 3463854

Please sign in to comment.