Txt vs. database



  • Hello evereyone,

    i'm at the moment thinking about making a "database" for saving and loading the state of a map (about 200x200 tiles + building information aso.). The program should also run on different pcs.
    Shall I use the more simply .txt-files or "real" database programs like SQL?

    MfG akonshi



  • Can't say from so little information.

    What are your requirements? Atomicity, i.e. how important is data consistency in case of a crash? Speed? Size?

    Why is it not sufficient to just keep those 200x200 datasets completely in your own memory and save them in a binary format (see overloading QDataStream << and >> operators) when necessary?

    Since you're explicitly mentioning textfiles, do the saved files need to be editable by the user by hand (with a plain text editor)?



  • Hi,
    [quote author="DerManu" date="1338727543"]Can't say from so little information.

    What are your requirements? Atomicity, i.e. how important is data consistency in case of a crash? Speed? Size?

    Why is it not sufficient to just keep those 200x200 datasets completely in your own memory and save them in a binary format (see overloading QDataStream << and >> operators) when necessary?

    Since you're explicitly mentioning textfiles, do the saved files need to be editable by the user by hand (with a plain text editor)? [/quote]

    the user shall be able to save one map into a file whenever he wants, it would me brilliant if the wouldnt be changed until the writing into it finished. Speed wouln’t be very important neither when reading or writing a file.

    This QDataStream stuff seems to be good, i assume that the user won’t need any additional programs for that?

    It is forbidden for the user (!!!) to edit any file. Only the programm shall have access. It would be very dumb if you can change your score easily by hand…

    Mfg akonshi



  • [quote author="akonshi" date="1338729553"]the user shall be able to save one map into a file whenever he wants, it would me brilliant if the wouldnt be changed until the writing into it finished. Speed wouln't be very important neither when reading or writing a file. [/quote]Well in that case speed is actually important, since you're blocking your user from changing the map or playing the game (I'm assuming it's a game).
    Anyhow, a real database would be extreme overkill for this. Just save the file with QDataStream (that will be very fast for 200*200 map tile datasets).

    [quote author="akonshi" date="1338729553"]This QDataStream stuff seems to be good, i assume that the user won't need any additional programs for that? [/quote]Yes, that's right.

    [quote author="akonshi" date="1338729553"]It is forbidden for the user (!!!) to edit any file. Only the programm shall have access. It would be very dumb if you can change your score easily by hand...[/quote]You can't (and shouldn't) forbid your users to do anything they want with their files. If they want to change their highscore, they will, and should be allowed to, as long as it's local. If you want a global highscore, where players can compete and compare with eachother, you will need to set up a server which takes high score data. This is the only case where I agree with you, that the user should be prevented to manipulate this global highscore. But making this secure will be very hard, even professional game developers are having a hard time. As an example: How do you make sure the game isn't modified in a way so it just sends a higher score to the server than the original game would. The state-of-the-art way to prevent this is to run the game logic completely in an environment under your control – on a game server – and let the client only be the user interface, i.e. handle user actions and send them to the server and display/draw whatever game state the server sends back.

    If this is a casual game you're writing for fun and that won't have a user base above, say, 100 (i.e there will be no scandal if someone actually breaks highscores by hacking), just save the highscore in binary somewhere in your file. This will be impossible for normal users to hack by just opening with a text editor, and very easy to hack by someone with knowlege how to use a hex editor and how binary files work.
    The next step in security would be to encrypt either the entire file or the portion with the highscore with a hardcoded key (password). This way the hacker would need to disassemble your program and find out the password and the algorithm that is used for encryption, which will be a major hurdle for most scriptkiddies.

    If you want to go for encryption, either set up your own simple encryption algorithm (e.g. xor your data with a hard-coded key), or, if you want to use the big names in encryption, see the "Qt Cryptographic Architecture":http://delta.affinix.com/qca/. But I'd suggest you shouldn't waste your time with this, unless of course, you want to learn new things in this area. Rather concentrate on making a good game instead. Because if 95% of your users play the game, and the 5% of the users that hack the game, can hack it, but can't ruin the game for the 95%, you've got 100% satisified customers :).


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.