reading file


(s-men) #21

it’s the same code as mine but a bit different. And this does work with sv_pure set to 0 but not when sv_pure is 1.
Maybe it is because of the place I’m trying to read. It’s a file I added, and it’s being called to from within that same new file, and evenatually it is being called from g_cmds.c from the function g_say.


(Mr.Mxyzptlk) #22

maybe you need to force a fs_game cvar setting.
Try running your mod in it’s own specially named sub-dir (instead of etmain), something perhaps like ‘customdir’ . and put the file in there. etmain/ might have special consequences wrt. reading files and sv_pure (but i’m just guessing on this).

what I can tell u is that code, exactly as is, allows me to read jaymod/server.cfg with sv_pure 1 .


(s-men) #23

sv_game is set to imod, and there is a dedicated subdir for imod, right next to etmain, jaymod, etc…
and the file is in there, yet I can’t get it to work
maybe cfg files work, but txt files don’t? even though they are the same, mabye because of the extension it doesn’t consider it pure?

edit: just did some testing, .txt files aren’t considered pure, but .cfg files are, so .cfg files work with sv_pure on.
I’m no going to swithc back to my original code and see of it still works, but that shouldn’t be any problem.


(Mr.Mxyzptlk) #24

I don’t think there’s a difference. Reading a ‘server.cfg’ or ‘test.txt’ file both work for me. Are you on windows or linux?


(s-men) #25

windows
and my original code works perfect too for reading .cfg files, but txt files just won’t work to read with sv_pure 1, with sv_pure 0 it works, so it’s no filename error, and yes windows is set to show known extentions
the file had no changes except his extention while I was testing


(jaybird) #26

The original code was a mess - the code Mxyzptlk gave you works.


(s-men) #27

code i’m using now is:

char *g_acl_ReadFiles(char *filename)
{
	int			len;
	fileHandle_t	f;	
	

	len = trap_FS_FOpenFile( filename, &f, FS_READ );
	if( len <= 0 ) {
		return va( S_COLOR_RED "file not found: %s
", filename );
	}
	
	filetext = malloc(len); 
	trap_FS_Read( filetext, len, f );
	filetext[len] = 0;
	trap_FS_FCloseFile( f );
	return filetext;
}

the return file not found still has to be replaced by something so the calling function knows it failed
filetext is declared global with

static char *filetext;

and after calling the function I do

free(filetext);

so never have to worry about the size of the buffer, but in essence it does the same, and both codes just don’t want to read a .txt file, and if i try a .cfg file, it just works, I’m not making it up :confused:
with +set sv_pure 0 both codes can read both files


(jaybird) #28

I am amazed.


(Mr.Mxyzptlk) #29

insert something like this after your OPEN call:
G_Printf( "result: filename=%s len=%d f=%d
", filename, len, f );

and show as the output for both when u can read the file and when u cannot.


(s-men) #30

screen of showing the files are in place with the names and their contents:

result:

edit
and now I just edited the startup line with +set sv_pure 0, and did it again and i got:


(Mr.Mxyzptlk) #31

i think your definition of server-only file and mine are different.
It sure looks to me like you’re running that from cgame code.


(s-men) #32

no, since i just recompile game, and only copy the newly recreated dll to the imod dir, cgame and ui which are in the pk3 do not change
it is executed from g_say in g_cmds.c so that is server side.
The files contain configurations for the ACL so they should never be on the clients side.


(kamikazee) #33

It’s engine magic. I noticed it before, that was why I talked about the sv_pure thing. Of course, if .cfg works, you could as well use that.

I wonder though what it does for .script and other common extensions.


(s-men) #34

yeah ofcourse if .cfg works, there isn’t really a problem, but since it works with Mr.Mxyzptlk to read .txt, and it doesn’t with me, I just think that’s very odd, and I’d like to know more about it ^^
maybe it depends if you’re running a dedicated server or not.
Anyway big thanks to all those who helped, I can move on to writing the file now :smiley:


(Mr.Mxyzptlk) #35

well one difference is i run qagame seperate from cgame. I notice you are launching a server/client in same process. try splitting them.


(s-men) #36

yep yep, when running a dedicated server it works both:

I still think it’s weird, but hey if it works, it works :smiley: