24 Nov, 2008, tphegley wrote in the 1st comment:
Votes: 0
I just put in a quest system into an envy codebase and everything is working great. The quests are saved into a ../quests/ folder by *name*.qdt

I want to create a command that can see what quests players have completed without logging into the shell. I haven't really looked for this yet as I'm at work right now, but how would I read from *name*.qdt and view it ingame? Would it have to do with fread or is that just for the pfiles and such?
24 Nov, 2008, David Haley wrote in the 2nd comment:
Votes: 0
fread should work fine. Depending on how your files are stored, you would do things more or less differently, but basically you want to load the file into memory, parse it, and extract the information. The first part would typically be accomplished with something like fread.
24 Nov, 2008, tphegley wrote in the 3rd comment:
Votes: 0
Hmm. What about the second and third parts?

By parsing do you mean how it would look? By using sprintf?
and then sending the buf to the game for me to see?
24 Nov, 2008, David Haley wrote in the 4th comment:
Votes: 0
Well, again it depends on what exactly your file contains. If all it contains is a list of players that have completed the quest, you would just echo the file to the MUD using fread to get the file contents and send_to_char or something to send it to whoever issued the command.

But if your file contains other things, you'll have to parse the file to figure out which part contains the list of players. For example your file might look like:

Quest name: A Fun Quest
Quest goal: Kill the evil dragon
Successful Players: Fred,George,Bob

In this case, you would need to search through the file until you found "Successful Players" and then echo only that line. Basically you want to do something similar to reading area files or pfiles.
24 Nov, 2008, tphegley wrote in the 5th comment:
Votes: 0
If i complete a quest, my name is saved under the quest folder as tphegley.qdt. When I open tphegley.qdt all I see is the quest name.

So Vi would look like this:



and so on. There is nothing else in the file, so I would just need to see the names of those.
24 Nov, 2008, David Haley wrote in the 6th comment:
Votes: 0
Oh – ok. So you have a list of files, one per player. Each file is a list of quest names that that player has completed.

Is that correct?

In that case, if your command is:
"Show me what quests player P has completed"
your task is as simple as loading P.qdt, reading the file, and sending each line to whoever ran the command.

There are already several file reading utility functions in db.c (I think) – check out how loading areas and pfiles works.

Using fread would mean basically doing the following: (pseudo-code)

char buf[100];
size_t bytes_read = 0;
fp = open_the_file();
// don't read sizeof: leave one for the null char
while ( (bytes_read = fread(buf, sizeof(buf)-1, 1, fp) > 0 ) {
// set the last character to the null char
buf[bytes_read] = '\0';
send_to_char(ch, buf);

Warning: the above is completely untested