ID:153612
 
What is the best way to encrypt mobs in savefiles?

I got it to the point where I encrypt and decrypt mobs, but if it is not directly from the savefile, it doesn't appear that you can input stuff straight into the mob.

How can I do this last part without it giving me a bad input run-time error, and have it working?


Will I need to encrypt each var on it's own?

Here is the code I am using now:

//Saving:

mob/proc/Save_Character()
var/savefile/F = new(client.Import())
var/RC5var
RC5var << client.mob
RC5var = RC5_Encrypt(RC5var,"encryptcode")
F["[src.name]/mob"] << RC5var
F["[src.name]/name"] << client.mob.name
client.Export(F)
src << "[src.name] saved."

//Loading (Done during login, after selecting what character you want (INP is your character)):

var/mob/mobe
var/mob/RC5var
F["[INP]/mob"] >> RC5var
RC5var = RC5_Decrypt(RC5var,"encryptcode")
RC5var >> mobe
client.mob = mobe



[edit]

It seems to be saving mobs as null as well:


\[GM\]\ Kunark
mob = null
name = "\[GM] Kunark"

Is in the savefile.
RC5var = client.mob maybe?
In response to Jon88 (#1)
Nope. And it is still saving it as null...
In response to Kunark (#2)
Then
F["[src.name]/mob"] = RC5var
maybe?
In response to Jon88 (#3)
I have an idea.\

Save the mob to a normal save file datum. use file2text (or another proc) to make it text. Encrypt then save on hard disk. Do this in reverse to decrypt. (using text2file after decryption should work I think)

I'll edit this with the real procedures once I look them up.
In response to Exadv1 (#4)
Actually, what you'd want is savefile.Export() and savefile.Import(). Otherwise, you're good to go :)