> that's not directly related to the game itself. How common is this
> issue elsewhere in the server? I know it's perhaps a shuned topic but a
> little discussion on the typical exploits and the patches around them
> would be nice here.
Well, it's a fairly big problem.. any time players are able to reliably crash
the server, they can duplicate gold, equipment, or pretty much anything else
saved in a pfile simply by controlling the order of their saves , exchanges,
and the crashes.
Player A gives "ungodly sword of power" to Player B
Player B saves
The mud crashes before Player A saves automatically.
Player A logs back on with old pfile, still posessing ungodly sword of power.
Player B logs on with new pfile, still posessing ungodly sword of power.
> Well I've worked with threads before, so I would be curious how to use
> them to relieve this problem, but only perhaps as an example.
As always, there's more than one way to do it. The simplest would probably
be to launch another thread that has an open pipe to the main MUD thread.
Then work out some type of negotiation between the two threads so that the
helper thread knows how to direct incoming data. Use the helper for all
instances when you have to open and close files, so your main thread only
uses new file descriptors for socket connections, and your helper thread has
all the descriptors it needs for writing to files.
This is nearly equivalent to using a DBMS, assuming your helper thread is as
reliable. Most people would probably just opt for using a DBMS, since it can
also be used to control the possibility of duplicating items.
> I'm quite interested in this, code and post away if you would. Your
> knowage of the subject leads you to generate a better solution this way
> then not.
Basically just wrap all of the things you normally do when writing to files
into a function... something like this should work (I don't have access to my
code atm to verify it):
char saved_filename[1024];
#define TMP_FILE "/tmp/mymudstmpfile"
FILE *file_open(char *file)
{
FILE *fp;
fclose(fpReserve);
fp = fopen(TMP_FILE, "w");
strcpy(saved_filename, file);
return fp;
}
void file_close(FILE *fp)
{
fclose(fp);
rename(TMP_FILE, saved_filename);
fpReserve = fopen("/dev/null", "r");
}
--Palrich.