Jump to content

.ini Question


Silo

Recommended Posts

ok... you need to understand "$readini" a tad better.

 

Looking at the help file... $readini(filename, [np], section, item)

So..., in this case... filename is file, don't worry about the np switch, section is the section of the ini you want to look at, in this case "protection", now for the item, looking at the way you do the writeini, your item is $chan/$active, and not the protection name. So, your code should look like this...

 

$readini($_prots,Protection,$active), which will then return the line in the ini file for the active channel, so for #err0rtest, it would return Revenge=1,Profanity=1.

 

Being that that is what you get back, you should then use a comparison of $findtok to find whether or not your code the protection is correct. Looking at the help file... $findtok(text,token,N,C)

text = the string you want to look through.

token = the string you are trying to find, an example is Profanity=1

n = the token you want, as in, if there are several instances, you can find the first or the second or the third or the <nth> token.

C = the character that is the tokenizer, the numeric representation of it that is. So for comma, its 44.

$findtok will return the position of the token. Or $null if it doesn't exist.

 

Linking it all together we have $findtok(text, Profanity=1, 1, 44), and the text would be what you get from the $readini. So... $findtok($readini($_prots,Protection,$active), Profanity=1, 1, 44).

 

Hopefully this will get you quite the way through. I can't be too sure if this is right, been quite some time.

Link to comment
Share on other sites

  • Replies 25
  • Created
  • Last Reply

Top Posters In This Topic

Guest Travis

Yeah that's a way of doing it, but to check if joinflood is on in a channel requires a bit of parsing. First you must check the ini file, then you need to use $gettok or $findtok to get the exact protection, then you need to determine whether it is 1 or 0.

 

The way I posted, you just check to see if the channel is in the joinflood list.

 

if ($chan isin $readini(prot.ini,protects,joinflood))

 

vs something like ...

 

 

if ($gettok($gettok($readini(prot.ini,protects,$chan),2,44),1-,61) == 1)

 

 

It's quite a bit more for mIRC to process. That is why I chose the method that I did.

 

The closest I could logically get to your idea would be something like this...

 

 

 

Protect.ini

 

[#channelA]

joinflood=1

hopflood=0

hammerlock=1

[#channelB]

joinflood=1

hopflood=1

 

 

So you could say ... if ($readini(protect.ini,$chan,joinflood) == 1)

 

 

But this isnt a very clean way of doing it because you could have 50 different channel items of channels you never use anymore. Verses one protection line.

 

 

 

Protect.ini

 

[Protects]

joinflood=#chan1,#chan2,#chan3

hopflood=#chan1,#chan3

 

 

It's less code and cleaner in my opinion. i.e. faster

 

 

I hope David made clear why your $readini was wrong. If not ask away!

 

 

p.s. everytime I write a tutorial it gets deleted by the site manager. Ive done it on a few different sites over the years. I keep meaning to make them for my SoulFly site, just haven't had the inspiration yet. Sorry!

 

 

Link to comment
Share on other sites

Protect.ini

 

[#channelA]

joinflood=1

hopflood=0

hammerlock=1

[#channelB]

joinflood=1

hopflood=1

 

 

So you could say ... if ($readini(protect.ini,$chan,joinflood) == 1)

 

 

But this isnt a very clean way of doing it because you could have 50 different channel items of channels you never use anymore. Verses one protection line.

 

it is true that this may not be a very "clean" way to do it, but i believe that it is the most efficient as you do everything in 1 ini command, instead of doing it in several mIRC commands including ini and gettok. In my opinion this is probably the best method.

Link to comment
Share on other sites

Guys, I cannot thank you enough for the time & patience you've shown me here. Not to mention the amount of detail you've both gone in to :) Getting help & tips from seasoned pros such as yourself is truly an amazing feeling. I cannot begin to tell you how grateful I am... and to everyone here on TG that lends free (and quite often thankless) help & support.

 

I've opted for TGK's (David?) way, for one reason, it used a format I've employed in other areas of my script & it works. At this stage I'd rather get it to do what I want, then, as I learn. Try all these other great techniques you try & teach me (that $addtok worked well, I want to learn more).

 

Travis, I agree with you 100% about all that potential wasted info (and bytes) being stored in the .ini. A couple of weeks ago, when I had my first ever success with ini files. I was pretty excited. I was using the file to store info like Topc, onjoin message and channel pass.

 

An example:

[#Scripters]
topic=So, this is my topic. Big woop, wadda you wanna do, fight about it? Thu Oct 02 18:37:38 2008
Onjoin=Come in and test you scripts without bugging anyone else...
create=Thu Oct 02 21:51:15 2008
key=mypass

 

If I have my dialog open on channel #scripters, all the needed info is there to be changed with a couple of clicks. Neat? Not quite:

[#TG007]
create=Fri Jul 25 08:28:19 2008
[#IRChainScriptz]
create=Mon Jun 23 13:45:15 2008

Working proof of the flaw Travis spoke of. IN this case the <section> is the name of channel. Makes it a bit harder to remove with remini.

 

It just occurred to me after that long winded post, that that may not of been what Travis was speaking after all lol :)

Link to comment
Share on other sites

no worries. we are all here to help and we are glad that you are taking what we say onboard. We don't mind explaining if we know that it does not fall on deaf ears (as the expression goes).

 

PS. and yes, my name is David.

Link to comment
Share on other sites

Guest Travis

Glad yer digging it. I never said I was worried about file size in the ini file. I was talking about the expression you use to check whether a channel has a protect on.

 

The way I like to do is very simple.

 

if ($chan !isin $readini(file.ini,protects,floodprotect)) { return }

 

So it has to get $chan then it has to get the line from the ini file. Then it checks if $v1 isin $v2. Basically 3 steps.

 

 

By the way, tests show that 'isin' is the fastest comparison. Faster than $istok, $regex etc. Use it.

 

 

What I was saying is the way you had it required many more steps for mIRC to go through to determine whether the protect was on or not. Not only did it have to gather the $chan and $readini, it had to perform a couple of $gettoks as well. Or use a $findtok.

 

 

Fewer steps, fewer characters equals faster processing scripts. The size of the ini file doesn't matter much.

 

 

The way David showed you would be the most logical and professional way of doing it. In my opinion.

 

The problem with my way is if you are reckless you can have a ton of channels in onel ine and get a line too long error.

The reason why I chose it though, is that it will check faster and for protections I want fast.

 

if ($chan !isin $hget(prot,joinflood)) { return }

 

This is how I do it. Hash tables?? Make another thread if yer interested.

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...