Jump to content

Home

Parsing function returns false


Recommended Posts

The only thing in that function that returns 0 (that I can see) is :

 

if ( !f || len >= 4096)
{
	return 0;
}

 

What that does is if there is no pointer to a file (ex. no file), or the length of the file is bigger than 4096 (you prolly figured that part out).

Link to post
Share on other sites

I was using "\\"'s but i read somewhere in the code that I should only use just one "\", so that fixed the reading problem.

Here's the function again, it crashes at strcat(client->userdb.name, parseBuf);

I used Windows Debugger to pinpoint the location.

int RP_GetProfile(char filename[MAX_QPATH])
{
gentity_t *ent;
gclient_t	*client;
fileHandle_t f;
int len;
int		x;
char	*msg;
char profileInfo[4096];
char parseBuf[4096];
client = ent->client;

len = trap_FS_FOpenFile(filename, &f, FS_READ);



if ( !f || len >= 2048)
{
	msg = "^2!f || len >= 4096\n";
	trap_SendServerCommand( ent-g_entities, va("print \"%s\"", msg) );
	return 0;
}

trap_FS_Read(profileInfo, len, f);

trap_FS_FCloseFile(f);

profileInfo[len] = 0;

RP_GetAccountGroup(profileInfo, "profileInfo", profileInfo);



//Parse Name
if (RP_GetPairedValue(profileInfo, "name", parseBuf))
{
	/*CRASH HERE-->*/strcat(client->userdb.name, parseBuf);
}

//Parse password
if (RP_GetPairedValue(profileInfo, "pass", parseBuf))
{
	strcat(client->userdb.pass, parseBuf);
}

/*//Parse Faction
if (RP_GetPairedValue(profileInfo, "faction", parseBuf))
{
	strcpy(client->userdb.faction, parseBuf);
}

//Parse Class aka Group
if (RP_GetPairedValue(profileInfo, "group", parseBuf))
{
	strcpy(client->userdb.group, parseBuf);
}

//Parse subgroup
if (RP_GetPairedValue(profileInfo, "subgroup", parseBuf))
{
	strcpy(client->userdb.subgroup, parseBuf);
}

//Parse Model
if (RP_GetPairedValue(profileInfo, "model", parseBuf))
{
	strcpy(client->userdb.model, parseBuf);
}

//Parse Credits
if (RP_GetPairedValue(profileInfo, "credits", parseBuf))
{
	client->userdb.credits = atoi(parseBuf);
}

//Parse Health
if (RP_GetPairedValue(profileInfo, "health", parseBuf))
{
	client->userdb.health = atoi(parseBuf);
}

//Parse Armor aka Shield
if (RP_GetPairedValue(profileInfo, "shield", parseBuf))
{
	client->userdb.shield = atoi(parseBuf);
}

//Parse Weapons
if (RP_GetPairedValue(profileInfo, "weapons", parseBuf))
{
	client->userdb.weapons = atoi(parseBuf);
}

//Parse Ammo
if (RP_GetPairedValue(profileInfo, "ammo", parseBuf))
{
	client->userdb.ammo = atoi(parseBuf);
}

//Parse Items
if (RP_GetPairedValue(profileInfo, "items", parseBuf))
{
	client->userdb.items = atoi(parseBuf);
}*/
return 1;
}

 

Here's that struct for userdb

// ===== RP Userdatabase =====
typedef struct {
char		userid[16];
char		name[32];
char		pass[32];
char		faction[16];
char		group[16];
char		subgroup[16];
int			health;
int			shield;
int			credits;
char		model[32];
int			weapons;
int			items;
int			ammo;
} playerInfoDB_t;
// ==== END ====

Link to post
Share on other sites

Likely due to the fact that parseBuf is larger than userdb.name.

 

I'd use Q_strcat with the size of MAX_NETNAME and change the name sizes to that instead (36) vs 32.

 

Why you using strcat in some cases and strcpy in others?

 

The strcpy instances will fail too btw.

 

strcat is append to string.

 

Also, where is the ent ever set?

Link to post
Share on other sites
×
×
  • Create New...