Raised This Month: $ Target: $400
 0% 

Read File question


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
EDUTz
Senior Member
Join Date: Jun 2010
Location: Dracula's Homeland
Old 12-13-2011 , 07:25   Read File question
Reply With Quote #1

Code:
	new auth = get_user_authid(id)
        format(holder, charsmax(holder), "%s", auth)

	new configdir[200]
	get_configsdir(configdir,199)

	new configfile1[200]

	format(configfile1,199,"%s/timer.ini",configdir)
	
	new text[512], len
	new pnum = file_size(configfile1,1)
	for(new i = 1; i < pnum; i++)
	{
		read_file(configfile1, i, text, 511, len)
		if ( contain(text, holder) != -1 ) 
		{
			//here is the problem, explained below
		}
	}
so in that ini file i have some authids and for each one an expiration date in format m%dd%dy%d, something like:
"authid" "pass" "flags" expiration date: m12d25y2011 ...
How can i read that part of the line that holds the date?
something like this:
if ( contain(text, "m%dd%dy%d") != -1 ){ // is this wrong also ?
new day = ?
new month = ?
new year = ?
client_print(id, print_chat, "your access expires on %d.%d.%d", day, month, year)
}

Last edited by EDUTz; 12-13-2011 at 07:35.
EDUTz is offline
joshknifer
Veteran Member
Join Date: Jun 2011
Location: Denver, CO
Old 12-13-2011 , 13:10   Re: Read File question
Reply With Quote #2

Try looking at the code from this plugin:
https://forums.alliedmods.net/showthread.php?t=138273

It does something similar to what you want i believe.
__________________

Last edited by joshknifer; 12-13-2011 at 13:10.
joshknifer is offline
Send a message via Skype™ to joshknifer
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 12-13-2011 , 21:16   Re: Read File question
Reply With Quote #3

You need to parse the date string manually (break it down until you get "12", "25" and "2011") then you can use those to get numbers with str_to_num().

Also, make sure that if you have a single digit month or day that you prepend it with a zero so that the number is always two characters wide.

Here is one I just came up with for parsing the date string:

test "12252011"

PHP Code:
#include <amxmodx>

public plugin_init()
{
    
register_plugin("Plugin""0.1""Author")
    
register_concmd("test""cmdTest")
}
public 
cmdTest(id)
{
    new 
szDate[32], szNum[6]
    
read_argv(1szDatecharsmax(szDate))

    
formatex(szNum2"%c%c"szDate[0], szDate[1])
    new 
month str_to_num(szNum)
    
formatex(szNum2"%c%c"szDate[2], szDate[3])
    new 
day str_to_num(szNum)
    
formatex(szNum4"%c%c%c%c"szDate[4], szDate[5], szDate[6], szDate[7])
    new 
year str_to_num(szNum)
    
server_print("Date: %d/%d/%d"monthdayyear)

__________________

Last edited by fysiks; 12-13-2011 at 21:28.
fysiks is offline
EDUTz
Senior Member
Join Date: Jun 2010
Location: Dracula's Homeland
Old 12-13-2011 , 21:39   Re: Read File question
Reply With Quote #4

that isn't good for me.
we have a text: j3jn34fb4im12d15y2011
how to read and save those numbers from this part of the text: j3jn34fb4im12d15y2011
i've searched for hours but i didn't find anything
EDUTz is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 12-13-2011 , 22:11   Re: Read File question
Reply With Quote #5

Quote:
Originally Posted by EDUTz View Post
that isn't good for me.
we have a text: j3jn34fb4im12d15y2011
how to read and save those numbers from this part of the text: j3jn34fb4im12d15y2011
i've searched for hours but i didn't find anything
What is all that random stuff in front of the date?

Also, you could just use my user extra info plugin and then you can just put the expiration in users.ini.
__________________

Last edited by fysiks; 12-13-2011 at 22:13.
fysiks is offline
EDUTz
Senior Member
Join Date: Jun 2010
Location: Dracula's Homeland
Old 12-13-2011 , 23:00   Re: Read File question
Reply With Quote #6

ok, i understand now what you're saying.
So its better to rewrite the lines in timer.ini to loook like this:
"authid" "pass" "flags" Exp:25102011
What you said there is allright, but how to extract the date from a whole line ?
it should read the line, search for the numbers and then date[32]="thosenumebers" ... i can't think at something else.
EDUTz is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 12-13-2011 , 23:47   Re: Read File question
Reply With Quote #7

Quote:
Originally Posted by EDUTz View Post
ok, i understand now what you're saying.
So its better to rewrite the lines in timer.ini to loook like this:
"authid" "pass" "flags" Exp:25102011
What you said there is allright, but how to extract the date from a whole line ?
it should read the line, search for the numbers and then date[32]="thosenumebers" ... i can't think at something else.
Your file should look like this:

Code:
"STEAM_0:0:12345" "password" "abc" "12252011"
Then you parse that line with parse(). Then use the concept I show in my code above on the date variable.
__________________
fysiks is offline
Reply



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 On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 12:06.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode