How do you store your data now? Presumably you have a bunch of setting files or even XML. Let's say your data looks like this:
<Character name="Jim-Bob the Peasant">
<Item name="Shirt">
<Protection>1</Protection>
<Weight>1</Weight>
</Item>
<Item name="Belt">
<Weight>1</Weight>
</Item>
<Item name="Pants">
<Protection>1</Protection>
<Weight>2</Weight>
</Item>
<Item name="Shoes">
<Speed>2</Speed>
<Weight>1</Weight>
</Item>
</Character>
Before you go out and start encrypting your datafiles, I would strongly suggest you first establish an intermediate format like the one I gave you. Why? Because then you have a file that you can read and edit using any text editor. When you have an encrypted file, you can only access it using your game and any tools you write.
But on to the question at hand: how do you protect this data from tampering in a multiplayer game?
Remember the golden rule of multiplayer programming: Never trust the client. Clients lie, all the time.
So the first step would be to verify that the server's datafile is exactly the same as the client's datafile. An easy implementation would be to hash the file using MD5. If the hashes don't match, the client has tampered with his file.
You'll note that the datafile we have now is very high "noise-to-signal": a lot of the bytes aren't for data, but for human-readability. We can improve that by compressing the file until only the raw data is left, by making a binary format.
- First, let's write a header for our custom format. Let's write the bytes "ITE" to show that this is a ".items" file.
- Next, write the name of the character and end with a 0.
- Then, write the properties of each item: name, protection, weight, speed.
Here's what it looks like in 010 editor:
You can see (with a bit of trouble) that every string ends with 0 and that for every item, we have a byte for protection, weight and speed.
Our datafile just went from 327 bytes (intermediate) to 58 bytes (binary)! But it came at a high price: it's now very hard to read what's going on and even harder to add new properties. But it gives us access to all kinds of neat tricks:
- Encoding the data with a XOR-key, so only if you have the key will you be able to read the data.
- Compressing the data further with run-length encoding, zlib or some other custom implementation.
- Shuffling the bytes around.
However, each of these encryptions comes at a cost: you first have to decrypt the file in memory before you can use it. And that's fine for files that are 58 bytes, but if you have 5 MB files and you have 100 of them, that could become a problem.
P.S. Your English is fine. ;)