Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Entire forum
➜ SMAUG
➜ SMAUG coding
➜ Fread_word errors
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Dace K
Canada (169 posts) Bio
|
Date
| Sun 12 Mar 2006 01:16 AM (UTC) Amended on Sun 12 Mar 2006 01:25 AM (UTC) by Dace K
|
Message
| For some reason, fread_word refuses to read the string 'Elaen', the name of one of my players. Instead, it'll go into an infinate loop, freezing the game and filling up the log file with: fread_word: EOF encountered on read .
It doesn't happen to seem with any other players, just Elaen..
Any ideas why? Here's my fread_word:
char *fread_word( FILE *fp )
{
static char word[MAX_INPUT_LENGTH];
char *pword;
char cEnd;
do
{
if ( feof(fp) )
{
bug("fread_word: EOF encountered on read.\n\r");
if ( fBootDb )
exit(1);
word[0] = '\0';
return word;
}
cEnd = getc( fp );
}
while ( isspace( cEnd ) );
if ( cEnd == '\'' || cEnd == '"' )
{
pword = word;
}
else
{
word[0] = cEnd;
pword = word+1;
cEnd = ' ';
}
for ( ; pword < word + MAX_INPUT_LENGTH; pword++ )
{
if ( feof(fp) )
{
bug("fread_word: EOF encountered on read.\n\r");
if ( fBootDb )
exit(1);
*pword = '\0';
return word;
}
*pword = getc( fp );
if ( cEnd == ' ' ? isspace(*pword) : *pword == cEnd )
{
if ( cEnd == ' ' )
ungetc( *pword, fp );
*pword = '\0';
return word;
}
}
bug( "Fread_word: word too long" );
exit( 1 );
return NULL;
}
Note: Fread_string works perfectly all right with Elaen though. |
ASJ Games - .Dimension 2, Resident Evil, and snippets - oh my!
http://asj.mudmagic.com
Drop by the area archives and find something for your mud. http://areaarchives.servegame.com | Top |
|
Posted by
| David Haley
USA (3,881 posts) Bio
|
Date
| Reply #1 on Sun 12 Mar 2006 02:01 AM (UTC) |
Message
| This might be an obvious thing to ask but are you sure the pfile itself isn't corrupted somehow? I see no explanation why this code would work with one name and not another. |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | Top |
|
Posted by
| Dace K
Canada (169 posts) Bio
|
Date
| Reply #2 on Sun 12 Mar 2006 02:36 AM (UTC) |
Message
| I'm sure. I've tested several times with different pfiles. Any character that is introduced to Elaen will no longer load.
The code I'm using is the AFKmud introduction code.
void fread_introductions(CHAR_DATA *ch, FILE *fp)
{
INTRO_DATA *intro = NULL;
char *word, *str;
bool fMatch;
for ( ; ; )
{
word = feof( fp ) ? "End" : fread_word( fp );
fMatch = FALSE;
switch ( UPPER(word[0]) )
{
case '*':
fMatch = TRUE;
fread_to_eol( fp );
break;
case 'E':
if ( !str_cmp( word, "End" ) )
return;
break;
default:
intro = new_intro(ch, word);
str = fread_word( fp );
update_intro(intro, str);
str = fread_word( fp );
update_recog(intro, str);
break;
}
}
}
It stores the data under a #INTRO heading in each char's pfiles, with '<charname>' '<introname>' '<recognizedname>'. |
ASJ Games - .Dimension 2, Resident Evil, and snippets - oh my!
http://asj.mudmagic.com
Drop by the area archives and find something for your mud. http://areaarchives.servegame.com | Top |
|
Posted by
| David Haley
USA (3,881 posts) Bio
|
Date
| Reply #3 on Sun 12 Mar 2006 02:43 AM (UTC) Amended on Sun 12 Mar 2006 02:44 AM (UTC) by David Haley
|
Message
| OK, well, here's your problem:
case 'E':
if ( !str_cmp( word, "End" ) )
return;
break;
There you go -- that is almost certainly your problem.
If it starts with an 'E', you return if the word is equal to End.
But, then you break in all cases. So, you never get to the code that actually reads in the introduction:
default:
intro = new_intro(ch, word);
str = fread_word( fp );
update_intro(intro, str);
str = fread_word( fp );
update_recog(intro, str);
break;
You probably want to remove that 'break' in the E case. |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | Top |
|
Posted by
| Dace K
Canada (169 posts) Bio
|
Date
| Reply #4 on Sun 12 Mar 2006 02:59 AM (UTC) Amended on Sun 12 Mar 2006 03:08 AM (UTC) by Dace K
|
Message
| Thanks a lot! I'm kicking myself for not seeing that.
I guess it's pretty important that I restrict the player name "End" right now :P |
ASJ Games - .Dimension 2, Resident Evil, and snippets - oh my!
http://asj.mudmagic.com
Drop by the area archives and find something for your mud. http://areaarchives.servegame.com | Top |
|
Posted by
| David Haley
USA (3,881 posts) Bio
|
Date
| Reply #5 on Sun 12 Mar 2006 04:22 AM (UTC) |
Message
| That would be in interp.c somewhere, where you take a line and handle it. You'd simply loop over the line of text and report failure if there's an apostrohpe. I'm not sure why you'd want to prevent apostrophes, though? |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | Top |
|
Posted by
| Dace K
Canada (169 posts) Bio
|
Date
| Reply #6 on Sun 12 Mar 2006 04:28 AM (UTC) Amended on Sun 12 Mar 2006 07:00 PM (UTC) by Dace K
|
Message
| Note to anyone who's using this snippet: Players putting apostrophies in their names will cause nasty crashes. Install this, and you'll be fine :)
char *stripquotes( char *text )
{
int k = 0, j = 0;
if (!text || text[0] == '\0')
{
return NULL;
}
else
{
char *buf;
static char done[MAX_INPUT_LENGTH*2];
done[0] = '\0';
if ( (buf = (char *)malloc( strlen(text) * sizeof(text) )) == NULL)
return text;
/* Loop through until you've hit your terminating 0 */
while (text[k] != '\0')
{
while (text[k] == '\'')
{
k ++;
}
if ( text[k] != '\0' )
{
if ( isspace(text[k]) )
{
buf[j] = ' ';
k++;
j++;
}
else
{
buf[j] = text[k];
k++;
j++;
}
}
else
buf[j] = '\0';
}
buf[j] = '\0';
sprintf(done, "%s", buf);
buf = realloc(buf, j*sizeof(char));
free( buf);
return done;
}
}
|
ASJ Games - .Dimension 2, Resident Evil, and snippets - oh my!
http://asj.mudmagic.com
Drop by the area archives and find something for your mud. http://areaarchives.servegame.com | Top |
|
Posted by
| David Haley
USA (3,881 posts) Bio
|
Date
| Reply #7 on Sun 12 Mar 2006 09:28 AM (UTC) |
Message
| Oh... apostrohpes in the names. Right, that's a bad thing. :-) I think we've disallowed that for a while.
BTW, be careful of [i] in your code posts, since it ends up italicizing the code. |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
18,998 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top