ID:139226
 
Code:
client/proc
save()
src.Export()
var/savefile/F = new()
F << mob
safe_save(F, "[key].save")
src.Export(F)

load()
if(fexists("[key].save"))
var/savefile/temp = new("[key].save")
safe_load(temp)
var/savefile/F = new(Import(temp))
if(F)
F >> mob
else
src << "Tampered Save"
del(src)


make_hash(var/text)
return md5("OOG[world.hub_password]OOG")

client
New()
..()
load()

Del
..()
save()


Problem description:

Well, I'm not sure why it isn't working. It doesn't load, but I'm not sure if it saves aswell. The world.hub has been set correctly. Can anyone help me out with this?

Yours truly,
Raimo.

I suppose I didn't provide a good example of how to use safe_save() for client-side saving. The issue is that safe_save() does not encrypt F, it creates a NEW savefile, and encrypts that one, using the contents of F. You need to use the returned value of safe_save() to send to the client, like so:

var/savefile/F = new()
F << mob
var/savefile/F2 = safe_save(F)
src.Export(F2)


As for loading, you aren't loading the client-side savefile at all. You will need to use Import(), like so:

var/savefile/F = Import()
if(F)
var/savefile/F2 = safe_load(F)
if(F2)
F2 >> mob
else
// Hash failed, savefile has been tampered with
In response to Garthor
I tried some things, changed here and there, this is my latest thing I got:
client/proc
save()
var/savefile/F = new()
F << mob
var/savefile/F2 = safe_save(F, "[key].save")
src.Export(F2)

load()
var/savefile/F = Import()
if(F)
var/savefile/F2 = safe_load(F)
if(F2)
F >> mob
else
src << "Tampered Save"
del(src)


make_hash(var/text)
return md5("OOG[world.hub_password]OOG")

client
New()
..()
load()

Del
..()
save()


But it still doesn't work. =/

Yours truly,
Raimo H.
In response to Raimo
You're loading from F, not F2. F2 is the savefile that actually contains your mob.
In response to Garthor
I figured that out myself a while after I posted, but still doesn't load correctly, this is what I have now:
client/proc
save()
var/savefile/F = new()
F << mob
var/savefile/F2 = safe_save(F, "[key].save")
src.Export(F2)

load()
var/savefile/F = Import()
if(F)
var/savefile/F2 = safe_load(F)
if(F2)
F2 >> mob
else
src << "Tampered Save"
del(src)

make_hash(var/text)
return md5("OOG[world.hub_password]OOG")

client
New()
..()
load()

Del()
save()
..()
In response to Raimo
Oh, right:

A fundamental issue is that you don't get a say in when the client closes their connection. So, you can't catch them before they leave and send them some data. You will need to save BEFORE client/Del() is called, which essentially means you'll just have to save periodically (or, ideally, whenever something worth saving happens to the character).