egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Code for botnet to run same script (Rev 1.4)

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Support & Releases
View previous topic :: View next topic  
Author Message
incith
Master


Joined: 23 Apr 2005
Posts: 275
Location: Canada

PostPosted: Mon Dec 29, 2008 4:16 pm    Post subject: Code for botnet to run same script (Rev 1.4) Reply with quote

Hard to describe what I mean in the topic. Basically, 2+ bots can all load the same script, and activate it, and only 1 of them will service the request. If that bot drops, the next one in line will start servicing the requests. I chose not to bind bot_disc by default as it will work better this way I think. Consider if a bot just gets .unlinked, only one will keep serving requests if bot_disc isn't called, until the other bot is truly gone (leaves the channel). If bot_disc is enabled, as soon as a bot leaves the partyline, a new bot will start serving requests, but if the old bot isn't actually timing out or disconnecting (just unlinked), then 2 bots will start serving requests. Hope that makes sense. Maybe a check in bot_disc, loop through all the channels the bot is on, and check for the disconnecting bot in them, if the bot is disconnecting + not found, then remove them?


Example of what this code does (visitant is the hub, leaftant and another_leaf are leafs):
Quote:
(visitant, another_leaf, and leaftant are all in the same channel)

(10:32:18) <@incith> !layout http://incith.com
(10:32:18) <@visitant> URL: http://incith.com/ \\ TITLE: incith.com => main menu
(10:32:24) +|+ visitant has quit [Client Quit]

(10:32:33) <@incith> !layout http://incith.com
(10:32:35) <@another_leaf> URL: http://incith.com/ \\ TITLE: incith.com => main menu
(10:33:01) +|+ another_leaf has quit [Client Quit]

(10:33:03) <@incith> !layout http://incith.com
(10:33:05) <@leaftant> URL: http://incith.com/ \\ TITLE: incith.com => main menu


1.4: Apparently if botnet-nick does not exist in your conf file, it is not set until after everything is sourced, so I've accounted for this in the startup portion of the botnet code now. Heh, it also seems I forgot to paste a line in here in startup too.
1.3: removed the 'unbind' else area. Oops.
1.2: Found some bugs in 1.1, cleaned it up. Putlogs being sent when they shouldn't be and bots being added to the static array unnecessarily. Whether you choose to bind disc or not I leave up to the authors.

In your scripts startup, add the below. This initializes an array to remember certain things going on. I use [clock seconds] in order to decide which bot is 'first'.
Code:
namespace eval incith::layout {
  variable botnet 1
  variable debug 0
  variable version {r79}

  global botnet-nick nick
  if {${botnet-nick} == ""} { set botnet-nick ${nick} }
  array set static {}
  if {${incith::layout::botnet} >= 1} {
    set static(botnet,${botnet-nick},time) [clock seconds]
  } else {
    set static(botnet,${botnet-nick},time) "noswarm"
  }
  if {![info exists static(botnet,bots)]} {
    set static(botnet,bots) ${botnet-nick}
  }
}


You will need to bind bot, link, and optionally disc. bind bot works by receiving a message starting with its 'bind', in this case "incith:layout". So any [putallbots "incith:layout *"] messages will be picked up by this.
Code:
# bind the botnet binds
if {${incith::layout::botnet} >= 1} {
  bind bot - incith:layout incith::layout::bot_msg
  bind link - * incith::layout::bot_link
  # it really depends what works better for you, checking if
  # the bot is onchan or just making sure they are linked.
  # bind disc - * incith::layout::bot_disc
}


And add the actual procedures that we are binding to:
Code:
namespace eval incith::layout {
  proc bot_msg {from cmd text} {
    upvar #0 incith::layout::static static
    if {${incith::layout::debug} >= 1} {
      putlog "${incith::layout::version} (botmsg): <${from}> ${cmd} ${text}"
    }

    # receiving a bots load time
    if {[string match "time ?*" $text]} {
      regexp -- {time (.*)} $text - time
      set static(botnet,${from},time) $time
      # make sure this bot is in our bot list
      if {![string match "*${from}*" $static(botnet,bots)]} {
        putlog "${incith::layout::version} (botnet): ${from} has joined the incith:layout swarm."
        append static(botnet,bots) ";${from}"
        regsub -all -- {;;} $static(botnet,bots) {;} static(botnet,bots)
        set static(botnet,bots) [string trimright $static(botnet,bots) {;}]
      }
    }
  }

  proc bot_link {bot hub} {
    global botnet-nick
    upvar #0 incith::layout::static static
    # send our time to the bots
    putallbots "incith:layout time $static(botnet,${botnet-nick},time)"
  }

  proc bot_disc {bot} {
    upvar #0 incith::layout::static static
    if {[string match "*${bot}*" $static(botnet,bots)]} {
      if {$static(botnet,${bot},time) != "noswarm"} {
        putlog "${incith::layout::version} (botnet): ${bot} has left the incith:layout swarm."
      }
    }
    # remove this bot from our bot list.  If they were merely unlinked
    # then this code will make it all fail.  They can be unlinked and still
    # serve seperately since the time will be stored, and they'd have to
    # leave the channel additionally before another bot takes over.
    regsub -all -- $bot $static(botnet,bots) {} static(botnet,bots)
    regsub -all -- {;;} $static(botnet,bots) {;} static(botnet,bots)
    set static(botnet,bots) [string trimright $static(botnet,bots) {;}]
    # remove their time?  If they just lost link, they might still be [onchan]
    # unset static(botnet,${bot},time)
  }
}


And then in your message handler (your proc receiving input), add something like the below (NOTE: This should only be for public (bind pub) messages. If a specific bot receives a private message, they should serve it as normal, as it cannot exactly pass off private messages to another bot. And that would be silly anyway.
Code:
namespace eval incith::layout {
  proc some_public_procedure {nick uhand hand chan input} {
    global botnet-nick
    upvar #0 incith::layout::static static
    set input(where) $chan

    # botnet
    if {${incith::layout::botnet} >= 1 && $input(where) != "private"} {
      foreach bot [split $static(botnet,bots) ";"] {
        # skip ourselves, bots not on the input channel, and bots not participating
        if {${bot} == ${botnet-nick} || ![onchan ${bot} $input(where)] || $static(botnet,${bot},time) == "noswarm"} {
          continue
        # bots that load first will serve first.  change < to > to reverse.
        } elseif {$static(botnet,${bot},time) < $static(botnet,${botnet-nick},time)} {
          if {${incith::layout::debug} >= 1} {
            putlog "${incith::layout::version} (botnet): $bot loaded before me."
          }
          return
        # should 2 bots have the same time, set a new random time (this did happen in testing)
        } elseif {$static(botnet,${bot},time) == $static(botnet,${botnet-nick},time)} {
          if {${incith::layout::debug} >= 1} {
            putlog "${incith::layout::version} (botnet): $bot had the same load time as me, fixing."
          }
          set static(botnet,${botnet-nick},time) [expr [clock seconds] + int(rand()*60)+1]
          putallbots "incith:layout time $static(botnet,${botnet-nick},time)"
          return
        }
      }
      # looks like we're serving, make sure we keep the botnet up to date
      putallbots "incith:layout time $static(botnet,${botnet-nick},time)"
    }
  }
}


And I add this at the end of the script, before the 'putlog "loaded"' type line. This will send the time out to the botnet on a .rehash etc, in case you modify a bots config to be removed from the swarm etc.
Code:
namespace eval incith::layout {
  putallbots "incith:layout time $static(botnet,${botnet-nick},time)"
}

_________________
; Answer a few unanswered posts!


Last edited by incith on Wed Jan 21, 2009 1:57 am; edited 9 times in total
Back to top
View user's profile Send private message
wac
Halfop


Joined: 10 Dec 2006
Posts: 80
Location: in my cardboard box

PostPosted: Wed Jan 07, 2009 7:24 pm    Post subject: Reply with quote

interesting looking script, just thought I should point out that using two similar looking names is confusing, you should try something like hub1, leaf1, leaf2 and so on, even if that's not what they actually are, heck even bot1, bot2, bot3 would work, just a simple glance at what you wrote for your example is kinda confusing... good work on the script though...
_________________
I see j00!
Back to top
View user's profile Send private message
incith
Master


Joined: 23 Apr 2005
Posts: 275
Location: Canada

PostPosted: Thu Jan 08, 2009 1:40 am    Post subject: Reply with quote

Fixed to be more readable, thanks. The above hasn't really changed at all, it does really work quite well at allowing only 1 bot to respond to a trigger at a time. Kind of like giving yourself "backup" bots, so if one goes down, you can still have your !triggers working on another bot.
_________________
; Answer a few unanswered posts!
Back to top
View user's profile Send private message
wac
Halfop


Joined: 10 Dec 2006
Posts: 80
Location: in my cardboard box

PostPosted: Sun Jan 11, 2009 1:04 am    Post subject: Reply with quote

np, I hadn't tried it yet, but it looks interesting, I actually divided up the script s I had running onto several bots because it was causing the bot to become unresponsive, so it wouldn't really work for me to have them all together again, but I guess if I had several more they could do backup for the bot that does it mainly, but that'd be a bit much just to keep the script alive... Razz
_________________
I see j00!
Back to top
View user's profile Send private message
incith
Master


Joined: 23 Apr 2005
Posts: 275
Location: Canada

PostPosted: Sun Jan 11, 2009 3:19 pm    Post subject: Reply with quote

Strange that your bot would get overloaded, on the one hand the above code should help in the sense that, if it gets an incoming message, and it is not the 'active' bot, it will just return.

More appropriate uses of the above code would be for channel security based scripts, so if one bot dies, another one can still have a go.

To be honest this code just came from sitting there going, "why can't my bots realise that another bot is going to serve this request?"... I wanted to fix that.
_________________
; Answer a few unanswered posts!
Back to top
View user's profile Send private message
wac
Halfop


Joined: 10 Dec 2006
Posts: 80
Location: in my cardboard box

PostPosted: Sun Jan 11, 2009 6:04 pm    Post subject: Reply with quote

Yeah makes sense

probably overloaded from the more intensive scripts like tvrage and an rss feed with several feeds...
_________________
I see j00!
Back to top
View user's profile Send private message
incith
Master


Joined: 23 Apr 2005
Posts: 275
Location: Canada

PostPosted: Sun Jan 11, 2009 6:34 pm    Post subject: Reply with quote

(not arguing or anything, just proposing uses for the code).. It could still be adapted for those scripts, e.g., if <leaf_bot> is not first or etc, just return, don't fetch any data or etc, don't run the timers, just return again.. ah well. Smile

I am including it in my future releases, for whatever purpose, my scripts are/will be botnet compatible, lol.
_________________
; Answer a few unanswered posts!
Back to top
View user's profile Send private message
wac
Halfop


Joined: 10 Dec 2006
Posts: 80
Location: in my cardboard box

PostPosted: Mon Jan 12, 2009 7:30 pm    Post subject: Reply with quote

hehe didn't take it as arguing Very Happy but yeah it would work for the tvrage script (I assume), but for rss not sure since it announces every so often, whenever the feed updates, so I'm not sure how that would fit in Very Happy
_________________
I see j00!
Back to top
View user's profile Send private message
incith
Master


Joined: 23 Apr 2005
Posts: 275
Location: Canada

PostPosted: Mon Jan 12, 2009 8:01 pm    Post subject: Reply with quote

It's all the same.. it would check it's priority on the botnet, and decide whether or not to announce or check any rss feeds at all.

I'll post a modified version of (demonds rss script? do you use a different one?) in a bit, just going out at the moment.

Demonds RSS News 2.2 + botnet code:
http://incith.com/eggdrop/rssnews2.2-botnet.tcl

RSS Synd 0.5b1 + botnet code:
http://incith.com/eggdrop/rss-synd-05b1-botnet.tcl
_________________
; Answer a few unanswered posts!


Last edited by incith on Sat Jan 17, 2009 8:29 pm; edited 1 time in total
Back to top
View user's profile Send private message
wac
Halfop


Joined: 10 Dec 2006
Posts: 80
Location: in my cardboard box

PostPosted: Tue Jan 13, 2009 12:38 am    Post subject: Reply with quote

I use rss-synd

http://forum.egghelp.org/viewtopic.php?t=11277
_________________
I see j00!
Back to top
View user's profile Send private message
incith
Master


Joined: 23 Apr 2005
Posts: 275
Location: Canada

PostPosted: Sat Jan 17, 2009 8:28 pm    Post subject: Reply with quote

Ok, I updated/fixed the botnet code some (rev1.2), and added it to rss-synd 0.5b1 as an example, untested but it should work (it loads at least Razz)

Demonds RSS News 2.2 + botnet code:
http://incith.com/eggdrop/rssnews2.2-botnet.tcl

RSS Synd 0.5b1 + botnet code:
http://incith.com/eggdrop/rss-synd-05b1-botnet.tcl
_________________
; Answer a few unanswered posts!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Support & Releases All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber