About Store Forum Documentation Contact



Post Reply 
Gamekeys
Author Message
Dwight Offline
Member

Post: #1
Gamekeys
Dear reader,

I have created a program that creates a document of gamekeys that must be used at registration. Giving a wrong key results in an error and you can thus not register (in the MMO source).

Currently, I'm using files (instead of a database) to read the gamekeys.
Gamekeys.txt:
Code:
flwBAWbdBiGJXZ23aq
vni6bOT3O4pR79hA3V
HmHb98jfGMLyzLOYLv
Atk4Qvhrnq6fWGQL9c
IvXznEqVDsqGEllU5U
SmRtkvgkrNB5qPyjAq
oEw9bfqPkobx7Hn9Ea
KmRzfusYPSd7WPvwBy
qrHitCIv2KiBwTDCr2
HoCQBRLenR17Q7zNiS

I have a question regarding this implementation:

When multiple people are registering at the exact same time (with different keys), then there should be no problem, as it is only reading the file.

However, keys can be re-used again with this method. So in order to solve this problem, I want to delete the line or modify the line. (Thus now the actions are read AND write).

Intuition tells me that if multiple people register at the same time, there will be a conflict: multiple writings to file at the same time.

Is there any way around this without using a database?


(
For the interested reader: removing a line in a text file is really simple; you create a second file in which you copy everything except the used line. Next, you delete the original file (without the line), and rename the temporary file back to the original file name.
)

SnowCloud Entertainment - We are recruiting!
http://www.sc-entertainment.com
09-28-2011 01:52 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #2
RE: Gamekeys
you can use SafeOverwrite it atomically replaces the file
or
you can use SQLite database, it's small and efficient, doesn't require any installation
09-28-2011 02:24 PM
Find all posts by this user Quote this message in a reply
Dwight Offline
Member

Post: #3
RE: Gamekeys
I see you were already 1 step ahead of me with the SafeOverwrite function. It's just like the creation of a temporary file I see.

Thanks!

SnowCloud Entertainment - We are recruiting!
http://www.sc-entertainment.com
09-28-2011 02:31 PM
Find all posts by this user Quote this message in a reply
Post Reply