mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Aug 2004
Posts: 42
T
Ameglian cow
OP Offline
Ameglian cow
T
Joined: Aug 2004
Posts: 42
I think it is possible to do the following thing:

For example I have the ini file like this:
Code:
[Nickname1]
HOSTS=*!*@bla.com *ident@* Nickname!*@192.168.*
OP=1


The idea is when someone joins an active channel mirc to scan the file for a matching host. If the user host exists and OP=1 to give +o to this nickname.

I know how to do the scripting except for the host search for a given nickname category in the ini file.

Edit: Hosts in HOST= are seperated with spaces. I think didtok should do the job for adding new hosts and removing.

Thanks

Last edited by The_Only; 27/10/05 06:58 PM.
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Are you using the INI for anything else? If not, there are better ways to do this.


Invision Support
#Invision on irc.irchighway.net
Joined: Aug 2004
Posts: 42
T
Ameglian cow
OP Offline
Ameglian cow
T
Joined: Aug 2004
Posts: 42
I also use it for welcome message storage and custom user flags. Like a database file (:

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Still might be a better option, but we'll stick to this just because you already have it set up.

Code:
on @*:join:[color:red]#yourchannel[/color]: {
  var %hostchk = $readini([color:red]yourini.ini[/color],$nick,Hosts)
  [color:green]; Check to see if you have data for that nick.[/color]
  if (%hostchk != $null) {
    [color:green]; Loop through each host. [/color]
    var %c = 1
    var %i = $numtok(%hostchk,32)
    while (%c <= %i) {
      [color:green]; Check to see if hte host matches the address of the $nick. [/color]
      if ($gettok(%hostchk,%c,32) iswm $address($nick,5)) {
        [color:green]; Check to see if the status is OP. [/color]
        if ($readini([color:red]yourini.ini[/color],$nick,OP) == 1) {
          mode $chan +o $nick
        }
        [color:green]; Halt the script once a host matches the nick to prevent wasted time.[/color]
        return
      }
      inc %c
    }
  }
}


Change the reds as needed.

Last edited by Riamus2; 27/10/05 07:22 PM.
Joined: Aug 2004
Posts: 42
T
Ameglian cow
OP Offline
Ameglian cow
T
Joined: Aug 2004
Posts: 42
The thing I want is if a person changes his/her nickname not to lose the privileges... That's the use of the hosts (:

Last edited by The_Only; 27/10/05 07:30 PM.
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
That is one of the problems with using this type of "database". If nothing else, your section should not be the nick, but the host. You may end up with multiple sections per person, but it will make it much easier to deal with:

[HOST]
NICKS=Nick1 Nick2 Nick3

This is also more likely to prevent problems with multiple people using the same nick (with common nicks).

Personally, I'd start using hash tables rather than ini files... much faster and easier to work with.

A simple "quick" option to make the opping work is to make a new section/item called OPS. Have all hosts for ops go into that item and then you just check that one item. The only thing to be careful of is the line length limit (I think it's somewhere around 950 characters for $readini). But, I highly doubt you have that many ops and hosts for the ops.

Example:
[OPS]
OPS=address1.com address2.com address3.com

Last edited by Riamus2; 27/10/05 07:41 PM.

Invision Support
#Invision on irc.irchighway.net
Joined: Aug 2004
Posts: 42
T
Ameglian cow
OP Offline
Ameglian cow
T
Joined: Aug 2004
Posts: 42
I'm not very familiar with the hash tables ): Can you give an example? I'll take a look in the hash tables section in the help file...

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Hash tables are very much like INI files, but because they are fully loaded into memory (unless/until you save them and free them), they work faster than having to read through a file.

The first thing you have to decide is how you want to store the data. In a hash table, you have an item name and a data value. Personally, I would use the address as the item name for what you are doing. Just make sure you use standard address masks for the addresses so you can easily find the data. For example, using an address of *!ident@* isn't a standard mask and would make searching for it more difficult (it can be done easily enough, but it requires extra coding for it to work). Also, such a mask is REALLY bad for choosing to op someone. Anyone can change their ident to anything else and suddenly be opped. To see a list of the masks, type /help $mask and scroll down one page.

Here is a short example:

Code:
[color:green]; Create your table and load the saved copy and set up automatic saving of the table.[/color]
on *:connect: {
  if ($hget(UserData) == $null) {
    hmake UserData 30
    hload UserData UserData.hash
  }
  if ($timer(UserData) == $null) {
    .timerUserData 0 30 hsave UserData UserData.hash
  }
}


Now, when you're adding data, I would consider doing it something like this (in a script, or on command line):

//hadd UserData $address(nick1,2) OP ~ Setting1 Setting2 Setting3 ~ Nick1 Nick2 Nick3
//hadd UserData $address(nick2,2) VOICE ~ Setting1 Setting2 Setting3 ~ Nick1 Nick2 Nick3
//hadd UserData $address(nick3,2) REGULAR ~ Setting1 Setting2 Setting3 ~ Nick1 Nick2 Nick3

Ok, so we just set 3 nicks that were in the channel up in the table. One for op, one for voice, and one for regular. We did them using the mask of *!*@host.com (mask 2).

Now, when someone joins...
Code:
on @:join:#yourchannel: {
  [color:green]; Get the data for the address using mask 2.  If that fails, you can try other masks as shown... you only need to use the ones that you used when adding the data.[/color]
  var %data = $hget(UserData,$address($nick,2))
  if (%data == $null) {
    var %data = $hget(UserData,$address($nick,4))
  }
  [color:green]; After checking for all masks that you want to check for, see if there is any data.  If not, then you don't have data on that nick and can halt the script.  Otherwise, check the first token of the data to find out what status the nick has.[/color]
  if (%data != $null) {
    if ($gettok(%data,1,32) == OP) { mode $chan +o $nick }
    elseif ($gettok(%data,1,32) == VOICE) { mode $chan +v $nick }
  }
}


Just as a note... If you don't like using just the masks, you can also set the address manually:

Example:
//hadd UserData nick!ident@* OP ~ Setting1 Setting2 Setting3 ~ Nick1 Nick2 Nick3

Then, since you know that's one way you're using, you can use:
Code:
  if (%data == $null) {
    var %data = $hget(UserData,$gettok($address($nick,5),1,64) $+ @*)
  }


That would take everything before the @ in the address and then put @* at the end...

So, nick!ident@host.com would become nick!ident@* ... that would give you the ability to use any mask you like, even if it's not standard. But, you really need to be careful of using masks that do not include a host name.

One last note... if you want to include both DNS and IP, you'll probably need to manually add at least one of those:

//hadd UserData nick!ident@123.456.789.012 OP ~ Setting1 Setting2 Setting3 ~ Nick1 Nick2 Nick3

Whether it's IP or DNS, you still use the same masks...

var %data = $hget(UserData,$address($nick,2)) will still work regardless if you used IP or DNS as long as they are both in there.

Anyhow, that may get confusing... If you have questions, just ask.


Invision Support
#Invision on irc.irchighway.net
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Oh, btw... as you can see, I put in sections in the data for "settings" and "nicks". I separated those by ~. This lets you use tokens to pull up either section as needed. Then, you can use tokens on that if needed.

Example:

//echo -a $gettok($hget(UserData,address),2,126)
Settings1 Settings2 Settings3

//echo -a $gettok($gettok($hget(UserData,address),2,126),1,32)
Settings1

(That's assuming you put in an address that is in the table)


Invision Support
#Invision on irc.irchighway.net

Link Copied to Clipboard