lfnetwork.com mark read register faq members calendar

Thread: Reading files
Thread Tools Display Modes
Post a new thread. Add a reply to this thread. Indicate all threads in this forum as read. Subscribe to this forum. RSS feed: this forum RSS feed: all forums
Old 07-27-2006, 11:30 AM   #1
Dom_152
Rookie
 
Dom_152's Avatar
 
Join Date: Jan 2006
Location: England
Posts: 150
Reading files

Help me with reading files! At the moment my Mod is only reading the first word in the file (This is for a word filter) but there are 2 others below it. The filedump shows that all 3 have been read and tehre is a \n character separating them. How can I get my mod to read all of the words? I want it to read the first word, check if that word is in the sentence if it is star it out... then move onto the next word in the list. Here is my current code:
Code:
if(mpx_wordFilter.integer == 1)
	{
		len = trap_FS_FOpenFile("wordlist.txt", &file, FS_READ);//Open the bad word list

		if(file)	
		{			
			
			fileDump = BG_TempAlloc(len+1); //Allocate memory for the file dump
			word = BG_TempAlloc(25); //Allocate memory for the bad word
			
			trap_FS_Read(fileDump, 1024, file);
			trap_FS_FCloseFile(file);

			CmdAll(va("print \"Filedump: %s\n\"", fileDump));

			if(len) //only check for bad words if the file has something in it
			{				
				while(i < len+1) //We just keep going through the file
				{
					
					while(y < 25) //25 = max Word length
					{
  						if(fileDump[y * (i+1)] == "\n") //If the character is a space then it will NOT be copied
						{
							y++; //STOP! If there is a space that's the end of the word
						}
						else
						{
							word[y] = fileDump[y * (i+1)]; 
							y++;
						}										

					}
				

					//OK By this point we should have a word so lets check if it's in the file
					//So we check to see if the bad word is ANYWHERE in the sentence
					value = stristr(p, word);				
					
					if(value != NULL)
					{
						start = p - value;

						if(start < 0)
						{
							start = -start;
						}							
						
						while(x < strlen(word))
						{
							p[start + x] = '*';

							x++;
						}	
					}

					//i++;
					CmdAll(va("print \"I = %i\n\"", i));
					i += 25; //Increase I by 25 as this is the size of a word
				}
			}
		
				
				BG_TempFree(25);
				BG_TempFree(len+1);		
		}	
	}


-----------------------------------------------------
MultiPlayer Xtra
Jedi Academy MP Mod
(Released! Source Code and all!)

Jedi Academy - Xtra
Coming Soon...

-----------------------------------------------------
Dom_152 is offline   you may: quote & reply,
Old 07-27-2006, 02:49 PM   #2
ensiform
The Stig
 
ensiform's Avatar
 
Join Date: Nov 2004
Location: Sawtooth Cauldron
Posts: 1,241
Current Game: Borderlands 2
whats the file format? also, use .dat instead because .txt cannot be used opened after first run or on pure servers.


iojamp project lead / coder
ensiform is offline   you may: quote & reply,
Old 07-27-2006, 04:43 PM   #3
Dom_152
Rookie
 
Dom_152's Avatar
 
Join Date: Jan 2006
Location: England
Posts: 150
OK. The format was .txt.


-----------------------------------------------------
MultiPlayer Xtra
Jedi Academy MP Mod
(Released! Source Code and all!)

Jedi Academy - Xtra
Coming Soon...

-----------------------------------------------------
Dom_152 is offline   you may: quote & reply,
Old 07-27-2006, 06:05 PM   #4
ensiform
The Stig
 
ensiform's Avatar
 
Join Date: Nov 2004
Location: Sawtooth Cauldron
Posts: 1,241
Current Game: Borderlands 2
i meant the contents of file like how is it layed out.

like the special admin sys i have called shrubbot is layed out like this:

Code:
[admin]
name     = Admin's Name
ip          = xxx.xxx.xxx.xxx
level      = 9
flags      = *
im assuming you just have some comma delimited string like this:

word,word,word,word?

btw that parse script is god awful

edit: just a thought but, why don't you check out this:

http://linespeed.net/projects/etpub/...r.c?format=txt


iojamp project lead / coder

Last edited by ensiform; 07-27-2006 at 06:18 PM.
ensiform is offline   you may: quote & reply,
Old 07-27-2006, 06:29 PM   #5
ensiform
The Stig
 
ensiform's Avatar
 
Join Date: Nov 2004
Location: Sawtooth Cauldron
Posts: 1,241
Current Game: Borderlands 2
btw... when checking for \n you shouldn't be doing "\n", try '\n' instead because \n is really 1 character.


iojamp project lead / coder
ensiform is offline   you may: quote & reply,
Old 07-28-2006, 12:34 AM   #6
razorace
Impressive, Terran!
 
razorace's Avatar
 
Join Date: May 2002
Posts: 9,172
Quote:
Originally Posted by ensiform
whats the file format? also, use .dat instead because .txt cannot be used opened after first run or on pure servers.
How exactly does that work?


---Jedi Guardian of the Newbie Questions
---Masters of the Force Team Leader / Creator
---Open Jedi Project Lead Moderator / Co-Founder
razorace is offline   you may: quote & reply,
Old 07-28-2006, 12:57 AM   #7
ensiform
The Stig
 
ensiform's Avatar
 
Join Date: Nov 2004
Location: Sawtooth Cauldron
Posts: 1,241
Current Game: Borderlands 2
huh? i dunno but ive used .txt before and it eats sh1t after a map_restart and wont load the file anymore. and pure server of course it wont load because it is not one of the valid out-of-pk3 files that can be read.

These are the only valid ones:
Code:
.dat
.menu
.cfg
.game
.dm_26


iojamp project lead / coder
ensiform is offline   you may: quote & reply,
Old 07-28-2006, 05:19 AM   #8
Dom_152
Rookie
 
Dom_152's Avatar
 
Join Date: Jan 2006
Location: England
Posts: 150
Thanks for the link. The format of the file is simply:

word
word
more words

Oh and it was '\n' but I changed it because I was trying different things. I have never tried writing parsing scripts before. Most of the stuff I'm doing in this Mod is new to me so that's why it's probably no good.


-----------------------------------------------------
MultiPlayer Xtra
Jedi Academy MP Mod
(Released! Source Code and all!)

Jedi Academy - Xtra
Coming Soon...

-----------------------------------------------------
Dom_152 is offline   you may: quote & reply,
Old 07-29-2006, 03:56 PM   #9
stubert
 
Join Date: Aug 2002
Location: Philadelphia
Posts: 227
i still think making a space for C++ language runtime is a better idea than figuring out old C style bull****
stubert is offline   you may: quote & reply,
Old 08-07-2006, 04:51 PM   #10
Dom_152
Rookie
 
Dom_152's Avatar
 
Join Date: Jan 2006
Location: England
Posts: 150
I made some progress. But I'm gonna scrap it and start again. How can I read multi line files and then grab each individual line for use with the filter?


-----------------------------------------------------
MultiPlayer Xtra
Jedi Academy MP Mod
(Released! Source Code and all!)

Jedi Academy - Xtra
Coming Soon...

-----------------------------------------------------
Dom_152 is offline   you may: quote & reply,
Old 08-07-2006, 07:41 PM   #11
ensiform
The Stig
 
ensiform's Avatar
 
Join Date: Nov 2004
Location: Sawtooth Cauldron
Posts: 1,241
Current Game: Borderlands 2
Quote:
Originally Posted by stubert
i still think making a space for C++ language runtime is a better idea than figuring out old C style bull****
be my guest and write an idStr and idLexer class stu.


iojamp project lead / coder
ensiform is offline   you may: quote & reply,
Old 08-10-2006, 02:22 PM   #12
dumbledore
Rookie
 
Join Date: Nov 2005
Posts: 85
u could try this, didn't get a chance to test it extensively :S
Code:
	if(mpx_wordFilter.integer == 1)
	{
		len = trap_FS_FOpenFile("wordlist.txt", &file, FS_READ);//Open the bad word list

		if(file)	
		{			
			
			fileDump = BG_TempAlloc(len+1); //Allocate memory for the file dump
			word = BG_TempAlloc(25); //Allocate memory for the bad word
			
			trap_FS_Read(fileDump, len, file);
			trap_FS_FCloseFile(file);
			
			if(len) //only check for bad words if the file has something in it
			{	
				while(fileDump[i])
				{
					if(fileDump[i] == '\n') //If the character is a space then it will NOT be copied
					{
						word[y] = 0;
						i++;
						//STOP! If there is a space that's the end of the word
						while( value = stristr(p, word) )
						{
							start = value - p;
							x = 0;
							while(x < y)
							{
								p[start + x] = '*';
	
								x++;
							}
						}
						y = 0;
					}
					else
					{
						word[y++] = fileDump[i++]; 
					}										

				}
			}
			BG_TempFree(25);
			BG_TempFree(len+1);
		}	
	}
of course the real solution would be to rewrite it using com_parse, but if it's that simple you probably don't need to
dumbledore is offline   you may: quote & reply,
Old 08-13-2006, 07:37 AM   #13
Dom_152
Rookie
 
Dom_152's Avatar
 
Join Date: Jan 2006
Location: England
Posts: 150
Hmm, how does Com_Parse work? How can I use it? I'm lookign through the code at the moment seeing how it's used.


-----------------------------------------------------
MultiPlayer Xtra
Jedi Academy MP Mod
(Released! Source Code and all!)

Jedi Academy - Xtra
Coming Soon...

-----------------------------------------------------
Dom_152 is offline   you may: quote & reply,
Old 08-14-2006, 08:22 PM   #14
stubert
 
Join Date: Aug 2002
Location: Philadelphia
Posts: 227
i have a better idea

only huge tools have word filters

don't do it
stubert is offline   you may: quote & reply,
Post a new thread. Add a reply to this thread. Indicate all threads in this forum as read. Subscribe to this forum. RSS feed: this forum RSS feed: all forums
Go Back   LucasForums > Network > JediKnight Series > Editing Central > JA Coding > Reading files

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 05:43 AM.

LFNetwork, LLC ©2002-2011 - All rights reserved.
Powered by vBulletin®
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.