Author Topic: Mode subroutine which respects a servers MAXMODES setting  (Read 2286 times)

DarkStar

  • Full Member
  • ***
  • Posts: 135
  • Scripts for Praise
    • CorpseCorp
Mode subroutine which respects a servers MAXMODES setting
« on: August 07, 2008, 06:55:34 AM »
Sometimes a problem in scripting is setting to many moes at once, especially accross multiple servers which may have different settings. Servers will ignore extra mode changes in one command, some servers allow 12 mode changes at once, others 8, etc. This script Respects the server's maxmodes setting and still sends all the mode changes.

I think I got most of the common modes which accept paremeters - If there are some missing simply add them to the args variable, and please post here so I can update the script.

Code: [Select]
Sub Mode(channel, data, ServerNumber)
  maxmodes = GetIdentifier("$maxmodes",ServerNumber)
  args = "abefhIjklLoqv"
  outmodes = ""
  outitems = ""
  count = 0
  lastsign = ""
  if instr(data," ") then
    modelist = left(data,instr(data," ")-1)
    items = Mid(data,instr(data," ")+1)
  else
    modelist = data
    items = ""
  end if
  For i=1 to len(modelist)
    if count = int(maxmodes) then
      str = "/mode " & channel & " " & outmodes
      if len(outitems) > 0 then str = str & " " & trim(outitems)
      SendCommand str,ServerNumber
      count = 0
      outmodes = lastsign
      outitems = ""
    end if
    c = Mid(modelist,i,1)
    if instr("+-",c) then
      outmodes = outmodes + c
      lastsign = c
    elseif instr(args,c) then
      count = count + 1
      outmodes = outmodes & c
      if instr(items," ") and len(items) > 0 then
        item = left(items,instr(items," ")-1)
        items = trim(Mid(items,instr(items," ")+1))
      elseif len(items) > 0 then
        item = items
        items = ""
      else
        item = ""
      end if
      outitems = outitems & " " & item
    else
      count = count + 1
      outmodes = outmodes & c
    end if
  Next
  str = "/mode " & channel & " " & outmodes
  if len(outitems) > 0 then str = str & " " & trim(outitems)
  SendCommand str,ServerNumber
End Sub

To use:
Code: [Select]
Mode "#channel","mode string",ServerNumber
As usual, if you find any bugs please post them here.
This message brought to you by the Wonderful Wizard of Oz.