barna10
barna10

Reputation: 177

need help creating an internal log file

I have a character creator program for an RPG that I've created and I want a way to log what the initial rolls are before the user gets a chance to edit anything. I could easily dump the info to a text file or something similar, but I want something that can't be edited. I save the character info in a serialized class object. What would be the best way to log this info in serialized form (i.e. inside the class object)? I thought of a string but that could get rather large. Is there a better way?

Upvotes: 0

Views: 50

Answers (1)

Edward Falk
Edward Falk

Reputation: 10083

I would just create an object to hold the initial roll values; can't be more than a couple dozen bytes -- how many times is the user going to roll? You don't really explain what the rolls represent and if there's a fixed number of them.

If this information only has to persist during the running of the application, there's not much more to do beyond that.

If this information has to persist beyond program execution, then you'll have to write it to a file one way or another. If that's the case, then there's no way to truly protect it. RPG game writers have been trying to do this for decades with very little success. Typically, the solution is to keep player stats at a central server that the users have no access to. C.f. the "duping" problem that Diablo suffered from.

Your best bet is to write your "rolls" object to be serializable. Serialize it to a string, convert the string to bytes, encrypt the bytes with an encryption key hidden deep in the code, and write that to a file. Or if you want, just securely sign the string instead. That would allow the users to see the stats file, but not modify it.

The old Hack game used to save game state to a file with similar protection and it worked very well. One trick they used on Unix systems was to make the file's inode number part of the signed state. That way, if the user tried to copy the file (to back up a game in progress), the inode number would change, invalidating the file. Hack was very unforgiving about these things; if it detected a modified save file, your character died on the spot, game over.

The problem here is that dedicated users will reverse-engineer your code and discover the encryption algorithm and key, no matter how hard you try to hide them, or (if you're only signing the file) simply modify your executable so that it doesn't bother checking the signature.

Without more detail on what you're trying to do, this is as much advice as I can give you. It would help if (as is the custom) you told us what you've tried so far.

Upvotes: 2

Related Questions