/amsg & /ame

By Pass on Jan 12, 2006

Improved version of both /amsg and /ame. Easy enough to use: Paste into remotes [alt+r] & executed by "/amsg " [or] "/ame "

alias amsg { 
  if (!$1) echo $color(info) * /amsg: Invalid syntax [/amsg <msg>] 
  elseif ($1) { 
    var %t = 1
    while (%t <= $scon(0)) { 
      scid %t
      var %c = $chan(0)
      while (%c) {
        msg $chan(%c) $1-
        dec %c
      }
      inc %t
    }
  }
}
alias ame { 
  if (!$1) echo $color(info) * /ame: Invalid syntax [/ame <action>]
  elseif ($1) {
    var %t = 1
    while (%t <= $scon(0)) { 
      scid %t
      var %c = $chan(0)
      while (%c) {
        describe $chan(%c) $1-
        dec %c
      }
      inc %t
    }
  }
}

Comments

Sign in to comment.
Pass   -  Jan 16, 2006

Thanks for the info, FiberOPtics. That will come in handy for future references.

 Respond  
QuickStep   -  Jan 13, 2006

ah right my bad didnt actually realised it was called from the scon alias. I know about the recursion problem in mirc since I tried writing some basic functions with this idea (fibonacci most easiest example) but indeed I noticed it closes down my mirc. Anyway thanks for the comments

 Respond  
FiberOPtics   -  Jan 13, 2006

Btw the same recursion happens for example with filter and the -k flag.

Try:

alias test filter -fk $mircini test

Basically, the same case where the alias is called but not directly from the alias, rather it\'s filter that calls test here, which in term calls the filter again, which in term calls test again, etc, infinite recursion, making your mIRC crash.

Same example as the /scon or /scid case.

Here\'s another fun one:

alias test1 test2
alias test2 test1

(the above example used to work fine in older versions for 500 calls or something then it stopped, but in the current version it just crashes instantly)

 Respond  
FiberOPtics   -  Jan 13, 2006

When you pass a command to scon it is called not directly from the same alias anymore, which will create this recursion.

Try this:

alias test scon -a test

(it will close your mIRC)

There used to be a defense mechanism that would prevent mIRC from crashing, but in 6.16 this mechanism is broken.

 Respond  
QuickStep   -  Jan 13, 2006

very usefull fiberoptics, didnt know that

 Respond  
FiberOPtics   -  Jan 12, 2006

Oh btw, I forgot to mention, there is a HUGE mistake in your code.

$scon(0) returns the total amount of open server windows. Let\'s say this is 3.

You are looping from %t = 1 till 3 then, with %t being 1, 2, 3.

You then do: scid %t, which will set the active server window to the one that has as $cid the value %t.

BUT!!!

The $cid of a server window, is a gloval variable in mIRC internal\'s, that is not reset until you close mIRC. When you open a new server window, mIRC checks this value, increments it, and assigns the new value as the $cid to this server window.

Let me illustrate where I am going with this:

->You have 2 server windows open, with $cid\'s 1 and 2.
->You close server window 2, and then open a new one.
-> The new one now has $cid 3, but you still only have 2 server windows open, with $cid\'s 1 and 3.

Do you notice how when you are looping, you will try to do \"scid 2\" which will try to set the active connection to a server window that doesn\'t exist!

The trick here is not to use /scid, but to use /scon. /scid takes a $cid, whilst /scon takes a number that represents the N\'th window, which is what you are looking for.

In our example, when you do scon %c, it will set it to the second server window, which is the one with $cid 3.

 Respond  
FiberOPtics   -  Jan 12, 2006

You can simply do:

alias amsgx var %msg = $1- | scon -at1 amsg % $+ msg
alias amex var %msg = $1- | scon -at1 ame % $+ msg

It\'s really a bad idea to name your aliases the same as the built-in aliases, because now when someone does an /ame, it will do it on all server windows.

The reason that I use a variable and escape it in the code like that, is because there is danger of dubble evaluation when using the scon/scid commands. This is illustrated when doing: //scon -a echo -a $!me

Additionally, you are not checking $status on each server, which will result into an error when you try to describe or message a channel on an offline server window.

Also, as I stated in another comment section, $chan() doesn\'t make a distinction between channels that you are in, and those that were left open after a disconnect (channels you are no longer in, in other words), so you should loop with $comchan($me,%x)

But anyway, like said, looping isn\'t needed at all.

Btw if you decided to recreate the aliases to use scon -at1 ame/amsg, then you MUST escape the ame/amsg commands by prefixing them with a ! or it would close your mIRC because of infinite recursion.

Example:

alias amsg var %msg = $1- | scon -at1 !amsg % $+ msg
alias ame var %msg = $1- | scon -at1 !ame % $+ msg

 Respond  
Pass   -  Jan 12, 2006

Yeah, lemme update [seeing as I forgot there was the \'edit\' function upon my first post.]

 Respond  
xDaeMoN   -  Jan 12, 2006

It would be a good habit on adding checks especially these snippets will now be used by the public =)

 Respond  
Pass   -  Jan 12, 2006

Ah, okay xDaeMon. I never tested the script without the /halt, assuming that the regular /amsg [or /ame] command would get in the way. Also, I didn\'t really give the first parameter a thought since I made this mainly for my own use [figured others may enjoy], and I don\'t normally check my own commands [since I know how to use them, etc.] Thanks for the pointers though, :P

 Respond  
xDaeMoN   -  Jan 12, 2006

Not bad though =)

 Respond  
xDaeMoN   -  Jan 12, 2006

No need for the /halt command & you should also add a check if the 1st parameter is given.

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.