Author Topic: Protection Scripts  (Read 33401 times)

DocBeat

  • Newbie
  • *
  • Posts: 43
Re: Protection Scripts
« Reply #45 on: August 05, 2008, 12:56:00 PM »
Thnx Morio everything works perfectly now   :-D (at least for the server i go to)
i don't think it needs anything else unless you guys have any suggestions on it:

anti-ban & anti-kick
Code: [Select]
Sub ONMODE(Channel,ModeSetter,Mode,ServerNumber)

'if you do not have ops on the channel then the script does not need to run
If Not IsOp(GetIdentifier("$me"),Channel,ServerNumber) then Exit Sub

Dim N
MyNick = GetIdentifier("$me",ServerNumber)
MyHost = MyNick & "!" & GetIdentifier("$nick(" & Channel & "," & MyNick & ").host",ServerNumber)
For N = 0 to 10
CurrentHost = GetIdentifier("$mask(" & MyHost & "," & N & ")",ServerNumber)
if LCase(mode) = "+b " & LCase(CurrentHost) then
SendCommand "/mode " & channel & " -b " & CurrentHost,ServerNumber
SendCommand "/kick " & channel & " " & modesetter & " Do Not Ban Me",servernumber
        SendCommand "/mode " & channel & " +b " & modesetter &" !*@*",ServerNumber
end if
Next

End Sub
Sub ONKICK(Nickname,Host,Channel,WhoKicked,Reason,ServerNumber)
if Nickname = GetIdentifier("$me") then
SendCommand "/msg chanserv unban " & channel & " " & MyNickName,ServerNumber
SendCommand "/timer 1 1 1 /join " & channel,ServerNumber
SendCommand "/timer 2 1 2 /mode " & channel & " +b " & WhoKicked &" !*@*",ServerNumber
end if
End Sub

I used echo for the CurrentHost and it returned:

*!ident@83F6219B.5AFFE6DD.2C7D40D.IP
*!*ident@ 83F6219B.5AFFE6DD.2C7D40D.IP
*!*@83F6219B.5AFFE6DD.2C7D40D.IP
*!*ident@*.2C7D40D.IP
*!*@*.2C7D40D.IP
DocBeat!ident@83F6219B.5AFFE6DD.2C7D40D.IP
DocBeat!*ident@ 83F6219B.5AFFE6DD.2C7D40D.IP
DocBeat!*@83F6219B.5AFFE6DD.2C7D40D.IP
DocBeat!*ident@*.2C7D40D.IP
DocBeat!*@*.2C7D40D.IP
DocBeat!*@*

It doesn't counter any type there is
(for example:DocBeat!*ident@*.5AFFE6DD.2C7D40D.IP),
but i don't think it matters since it covers a good variety of types.

A final request if possible  :oops:
Code: [Select]
Sub ONMODE(Channel,ModeSetter,Mode,ServerNumber)
If ModeSetter = GetIdentifier("$me") then exit sub
if LCase(mode) ="-o " & LCase(mynickname) then
SendCommand "/msg chanserv op " & channel & " " & MyNickName,ServerNumber
end if
End Sub
I want my buddies to be able to deop me.Is it possible?

Snerf

  • Administrator
  • Hero Member
  • *****
  • Posts: 1968
    • IceChat IRC Client
Re: Protection Scripts
« Reply #46 on: August 05, 2008, 01:45:44 PM »
If the Mode was DocBeat!*ident@*.5AFFE6DD.2C7D40D.IP tho, you could parse out your nickname quit easily tho.

That may be the 1st thing you could do, is simply check for a nick name match, by getting everything before the "!" character.
In any case, I was working on a solution this weekend, but got side tracked, as it will also work when multiple bans are set, which the current one does not.
The IceChat God

Morio

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 256
Re: Protection Scripts
« Reply #47 on: August 06, 2008, 01:17:33 AM »
When I was working on a bot, I made a function that parses the modes that are set and can be used to counter any mode changes (except if you deop the bot). It separates every mode and the possible parameters for the mode. If you wan't I could post it here when I get home
"I don't know what World War 3 will be fought with, but I know World War 4 with be fought with sticks and stones." - Albert Einstein

DocBeat

  • Newbie
  • *
  • Posts: 43
Re: Protection Scripts
« Reply #48 on: August 06, 2008, 08:45:44 AM »
That would be cool with me.I'd love to check it out when i get back home too.
(going holidays tomorrow  :mrgreen:)

DocBeat

  • Newbie
  • *
  • Posts: 43
Re: Protection Scripts
« Reply #49 on: August 16, 2008, 03:31:54 AM »
 :-D Holidays were awesome  :mrgreen:

Can you send that function sometime Morio  :lol:

DocBeat

  • Newbie
  • *
  • Posts: 43
Re: Protection Scripts
« Reply #50 on: August 20, 2008, 04:42:14 AM »
It just came to my mind that it would be a good idea if i could protect my buddies besides myself.

Is there any way to get the nicknames of my buddies - and maybe place them in an array
 (so that when someone sends a ban,kick or deop command i will just check the array to see if the command refered to any of my friends).

DocBeat

  • Newbie
  • *
  • Posts: 43
Re: Protection Scripts
« Reply #51 on: October 19, 2008, 04:03:20 PM »
I was wondering if anyone will ever make a more functional or better version of the current script (working for multiple modes like Snerf said etc...)

Morio

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 256
Re: Protection Scripts
« Reply #52 on: October 20, 2008, 08:34:50 AM »
Here is a script that parses modes and puts the modes that require a parameter in an array together with the parameter

Code: [Select]
Sub ONMODE(Channel,ModeSetter,Mode,ServerNumber)
ModeParser Mode,Channel,ServerNumber
End Sub

Sub ModeParser(Mode,Channel,ServerNumber)
Dim ModesWithParameters,ParameterModes(),ParameterModeNumber,OtherModes(),OtherModeNumber,ChangePosition,lFound
ModesWithParameters = "voblkeIfLj" 'modes that can (usually will) be followed by a parameter
ParameterModeNumber = 0
OtherModeNumber = 0
lFound = False


If InStr(Mode," ") > 0 then 'there are parameters
Modes = Left(Mode,InStr(Mode," ")-1)
Parameters = Mid(Mode,InStr(Mode," ")+1)

If InStr(Parameters," ") then
ParameterArray = Split(Parameters," ")
Else
Dim ParameterArray(0)
ParameterArray(0) = Parameters
End If


If Left(Modes,1) = "+" then 'no modes have been removed

For i = 1 to Len(Modes)

If InStr(ModesWithParameters,Mid(Modes,i,1))>0 then
ParameterModeNumber = ParameterNumber + 1
ElseIf Mid(Modes,i,1) <> "+" then
OtherModeNumber = OtherModeNumber + 1
End If
Next

ReDim ParameterModes(ParameterModeNumber-1)
ReDim OtherModes(OtherModeNumber-1)
ParameterModeNumber = 0
OtherModeNumber = 0

For i = 1 to Len(Modes)
If InStr(ModesWithParameters,Mid(Modes,i,1))>0 then
ParameterModes(ParameterModeNumber) = "+" & Mid(Modes,i,1)
ParameterModeNumber = ParameterModeNumber + 1
ElseIf Mid(Modes,i,1) <> "+" then
OtherModes(OtherModeNumber) = "+" & Mid(Modes,i,1)
OtherModeNumber = OtherModeNumber + 1
End If
Next

For i = 0 to UBound(ParameterModes)
ParameterModes(i) = ParameterModes(i) & " " & ParameterArray(i)
Next

ElseIf Left(Modes,1) = "-" And InStr(Modes,"+") = 0 then 'modes have been removed but no modes have been added

ModesWithParameters = "vobkeIfLj" 'the mode l doesn't take a parameter when it is removed
For i = 1 to Len(Modes)
If InStr(ModesWithParameters,Mid(Modes,i,1))>0 then
ParameterModeNumber = ParameterNumber + 1
ElseIf Mid(Modes,i,1) <> "-" then
OtherModeNumber = OtherModeNumber + 1
End If
Next

ReDim ParameterModes(ParameterModeNumber-1)
ReDim OtherModes(OtherModeNumber-1)
ParameterModeNumber = 0
OtherModeNumber = 0

For i = 1 to Len(Modes)
If InStr(ModesWithParameters,Mid(Modes,i,1))>0 then
ParameterModes(ParameterModeNumber) = "-" & Mid(Modes,i,1)
ParameterModeNumber = ParameterModeNumber + 1
ElseIf Mid(Modes,i,1) <> "-" then
OtherModes(OtherModeNumber) = "-" & Mid(Modes,i,1)
OtherModeNumber = OtherModeNumber + 1
End If
Next

For i = 0 to UBound(ParameterModes)
ParameterModes(i) = ParameterModes(i) & " " & ParameterArray(i)
Next

ElseIf Left(Modes,1) = "-" And InStr(Modes,"+") > 0 then 'some modes have been removed and some have been added
For i = 1 to Len(Modes)
If lFound = False then
ModesWithParameters = "vobkeIfLj"
Else
ModesWithParameters = "voblkeIfLj"
End If

If InStr(ModesWithParameters,Mid(Modes,i,1))>0 then
ParameterModeNumber = ParameterModeNumber + 1
ElseIf Mid(Modes,i,1) <> "-" And Mid(Modes,i,1) <> "+" then
OtherModeNumber = OtherModeNumber + 1
ElseIf Mid(Modes,i,1) = "+" then
lFound = True
End If
Next

ReDim ParameterModes(ParameterModeNumber-1)
ReDim OtherModes(OtherModeNumber-1)
ParameterModeNumber = 0
OtherModeNumber = 0


lFound = False

For i = 1 to Len(Modes)

If lFound = False then
ModesWithParameters = "vobkeIfLj"
Else
ModesWithParameters = "voblkeIfLj"
End If

If InStr(ModesWithParameters,Mid(Modes,i,1))>0 then

If lFound = False then
ParameterModes(ParameterModeNumber) = "-" & Mid(Modes,i,1)
ParameterModeNumber = ParameterModeNumber + 1
Else
ParameterModes(ParameterModeNumber) = "+" & Mid(Modes,i,1)
ParameterModeNumber = ParameterModeNumber + 1
End If

ElseIf Mid(Modes,i,1) <> "-" And Mid(Modes,i,1) <> "+" then

If lFound = False then
OtherModes(OtherModeNumber) = "-" & Mid(Modes,i,1)
OtherModeNumber = OtherModeNumber + 1
Else

OtherModes(OtherModeNumber) = "+" & Mid(Modes,i,1)
OtherModeNumber = OtherModeNumber + 1
End If

ElseIf Mid(Modes,i,1) = "+" then
lFound = True
End If


Next

For i = 0 to UBound(ParameterModes)
ParameterModes(i) = ParameterModes(i) & " " & ParameterArray(i)
Next

End If

For i = 0 to UBound(ParameterModes)
SendCommand "/echo -a " & ParameterModes(i)
Next
For i = 0 to UBound(OtherModes)
SendCommand "/echo -a " & OtherModes(i)
Next

End If

End Sub

The script doesn't do anything else than parse the modes, and right now it does nothing if a mode without parameters is set (which you won't need anyway) but I'll add that at some point. I did some testing, and it seems to work, but there might still be some bugs.

This part:
Code: [Select]
For i = 0 to UBound(ParameterModes)
SendCommand "/echo -a " & ParameterModes(i)
Next
For i = 0 to UBound(OtherModes)
SendCommand "/echo -a " & OtherModes(i)
Next

prints the arrays to the screen.

To pick out only bans, loop through all modes and only do something when you find a mode that starts with '+b' or '-b'

Load the script and play around with the modes and you'll see what the script actually does
« Last Edit: October 20, 2008, 08:36:55 AM by Morio »
"I don't know what World War 3 will be fought with, but I know World War 4 with be fought with sticks and stones." - Albert Einstein

Snerf

  • Administrator
  • Hero Member
  • *****
  • Posts: 1968
    • IceChat IRC Client
Re: Protection Scripts
« Reply #53 on: October 20, 2008, 11:22:15 AM »
You know, as the 2nd msg in this topic had shown, there are ONOP, ONVOICE events that you can use, to really simplify this.

They should be as follows.

Code: [Select]
Sub ONOP(ModeSet,Nickname,Host,ModeSetter,ModeSetterHost,Channel,ServerNumber)

End Sub

The ModeSet variable will "True" if it is set (+o) and "False" if it is not (-o).

There is also an ONBAN event, except there is no ModeSet variable.
There is no ONUNBAN event.
Code: [Select]
Sub ONBAN(Nickname,Host,ModeSetter,ModeSetterHost,Channel,ServerNumber)

End Sub

Each of these are run individually, so 1 event for each nick/ban, and op/deop, voice, halfop, etc.
You can check the hosts with a banmask if you need to as well, as you had before.
« Last Edit: October 20, 2008, 11:24:56 AM by Snerf »
The IceChat God

DocBeat

  • Newbie
  • *
  • Posts: 43
Re: Protection Scripts
« Reply #54 on: October 20, 2008, 06:50:08 PM »
Thnx Morio i will play with that one to see how it works  :-)

About the ONBAN event:

Does it get triggered (Assuming that it checks whether it was me who got banned using
"if Nickname = GetIdentifier("$me") then") no matter which way the modesetter used the ban
command on me?

I mean, is it built in a way capable of detecting all the different types of banning or do i have to use
a loop for getting my host like i did before:

...
MyNick = GetIdentifier("$me",ServerNumber)
MyHost = MyNick & "!" & GetIdentifier("$nick(" & Channel & "," & MyNick & ").host",ServerNumber)
For N = 0 to 10
CurrentHost = GetIdentifier("$mask(" & MyHost & "," & N & ")",ServerNumber)
...

sorry to be asking silly stuff Snerf i'm still trying to figure some scripting things out  :oops:

DarkStar

  • Full Member
  • ***
  • Posts: 135
  • Scripts for Praise
    • CorpseCorp
Re: Protection Scripts
« Reply #55 on: October 20, 2008, 10:58:32 PM »
Lets try this using the underused Regular expressions, to make things easier.

Code: [Select]
Function MaskMatch(mask,match)
  Set MaskRegex = new RegExp
  MaskRegex.IgnoreCase = True
  MaskRegex.pattern = replace(replace(match,"?","."),"*",".*")
  MaskMatch = MaskRegex.Test(mask)
End Function

Now, we can simply do..

Code: [Select]
if MaskMatch(MyHost, banned_host) then SendCommand "/mode " & channel & " -b " & banned_host,ServerNumber
Edit:

Completed, the code looks like:

Code: [Select]
Sub ONBAN(Nickname,Host,ModeSetter,ModeSetterHost,Channel,ServerNumber)
MyNick = GetIdentifier("$me",ServerNumber)
MyHost = MyNick & "!" & GetIdentifier("$nick(" & Channel & "," & MyNick & ").host",ServerNumber)
if MaskMatch(MyHost,Nickname & "!" & Host) then SendCommand "/mode " & channel & " -b " & Nickname & "!" & Host,ServerNumber
End Sub
« Last Edit: October 22, 2008, 10:39:13 AM by DarkStar »
This message brought to you by the Wonderful Wizard of Oz.

DarkStar

  • Full Member
  • ***
  • Posts: 135
  • Scripts for Praise
    • CorpseCorp
Re: Protection Scripts
« Reply #56 on: October 22, 2008, 10:40:05 AM »
Morio caught a bug in my regular expression example, when there were question marks used in the banmask. I updated my previous post to include the fix.
This message brought to you by the Wonderful Wizard of Oz.

clEEn

  • Newbie
  • *
  • Posts: 21
Re: Protection Scripts
« Reply #57 on: December 15, 2008, 04:11:41 AM »
nice script i will use this but, can u make it like if i type !addowner <nick> it will add a owner on the bot and if the "new owner" will ban/kick or something likes that, the bot wont ban him. thx  :mrgreen: