mIRC Home    About    Download    Register    News    Help

Print Thread
Sockread help #230660 16/03/11 09:57 PM
Joined: Mar 2011
Posts: 4
C
crreep Offline OP
Self-satisified door
OP Offline
Self-satisified door
C
Joined: Mar 2011
Posts: 4
Hello,

I'm trying to make a script which will take data from a webpage and post it on irc.

I've managed to do it, but im not able to make it repeat its job multiple times.

This is what i tried:

alias mib {
var %i = 0
%bitka = $1
while (%i <= 4) {
$myb(%bitka)
inc %i 1
}
}

Alias "myb" works, it gets the data and posts it.

I tried to make it repeat what alias "myb" does 5 times, but it does it only once. Idealy i want it to keep posting that data until i turn it off, but i wanted to go with baby steps. Not successfuly though.

Help is appreciated. Thanks.

Last edited by crreep; 16/03/11 09:58 PM.
Re: Sockread help [Re: crreep] #230661 16/03/11 10:11 PM
Joined: Sep 2005
Posts: 2,876
H
hixxy Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,876
Please show us your myb alias.

Re: Sockread help [Re: crreep] #230662 16/03/11 10:14 PM
Joined: Mar 2011
Posts: 4
C
crreep Offline OP
Self-satisified door
OP Offline
Self-satisified door
C
Joined: Mar 2011
Posts: 4
Code:
alias myb {
  set %tempchan $chan
  %bitka = $1
  set %kuda a
  if ($sock(myb)) { .sockclose myb }
  .sockopen myb www.erepublik.com 80
}

on *:sockopen:myb:{
  .sockwrite -n $sockname GET /en/military/battle-log/ $+ %bitka HTTP/1.1
  .sockwrite -n $sockname Host: www.erepublik.com
  .sockwrite -n $sockname $crlf
}

on 1:SOCKREAD:myb: {
  .sockread -f %temp
  set %buffer %temp
  while ($sockbr != 0) {
    .sockread -f %temp
    %buffer = %buffer %temp
  }
  if ($pos(%buffer,domination,1) > 0) {
    %bi = $pos(%buffer,domination,1) + $len(domination)
    %ei = $pos(%buffer,att,1)
    %kuda = $mid(%buffer,$calc(%bi + 2),$calc(%ei - %bi - 4))
  }
  if (%kuda != a) {
    if ($sock(myb)) { .sockclose myb }
    msg %tempchan %bitka $+ : $left($calc(100 - %kuda),6) $+ % -  $+ $chr(32) $+  $left(%kuda,6) $+ %    
  }
}

Re: Sockread help [Re: crreep] #230664 16/03/11 11:43 PM
Joined: Mar 2011
Posts: 4
C
crreep Offline OP
Self-satisified door
OP Offline
Self-satisified door
C
Joined: Mar 2011
Posts: 4
Made some tests, and it seems while loop in "mib" is too fast. Alias myb cant follow it. Tried using timer command but failed. Is there a way to slow the script down?

Re: Sockread help [Re: crreep] #230666 17/03/11 12:15 AM
Joined: Sep 2005
Posts: 2,876
H
hixxy Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,876
Why not start the next socket when you close the current one?

Code:
alias myb {
  set %tempchan $chan
  %bitka = $1
  set %kuda a
  set %myb.i 5
  if ($sock(myb)) { .sockclose myb }
  .sockopen myb www.erepublik.com 80
}

on *:sockopen:myb:{
  .sockwrite -n $sockname GET /en/military/battle-log/ $+ %bitka HTTP/1.1
  .sockwrite -n $sockname Host: www.erepublik.com
  .sockwrite -n $sockname $crlf
}

on 1:SOCKREAD:myb: {
  .sockread -f %temp
  set %buffer %temp
  while ($sockbr != 0) {
    .sockread -f %temp
    %buffer = %buffer %temp
  }
  if ($pos(%buffer,domination,1) > 0) {
    %bi = $pos(%buffer,domination,1) + $len(domination)
    %ei = $pos(%buffer,att,1)
    %kuda = $mid(%buffer,$calc(%bi + 2),$calc(%ei - %bi - 4))
  }
  if (%kuda != a) {
    if ($sock(myb)) { 
      .sockclose myb 
      if (%myb.i) {
        sockopen myb www.erepublik.com 80
        dec %myb.i
      }
    }
    msg %tempchan %bitka $+ : $left($calc(100 - %kuda),6) $+ % -  $+ $chr(32) $+  $left(%kuda,6) $+ %    
  }
}

Re: Sockread help [Re: crreep] #230667 17/03/11 12:29 AM
Joined: Mar 2011
Posts: 4
C
crreep Offline OP
Self-satisified door
OP Offline
Self-satisified door
C
Joined: Mar 2011
Posts: 4
Thank you hixxy, but it seems that script is still too fast. It posts only one message.

EDIT: i seem to have messed something up on first try, your solution works too hixxy, although its a bit too fast for what i need

Ive managed to work something around with timers though.
Code:
alias myb {
  set %tempchan $chan
  %bitka = $1
  set %kuda a
  if ($sock(myb)) { .sockclose myb }
  .sockopen myb www.erepublik.com 80
  var %wait = 0
  var %bleh = 0
  while (%bleh <= 4) {
    inc %wait 1
    .timer 1 %wait mab
    inc %bleh 1
  }
}

alias mab {
  if ($sock(myb)) { .sockclose myb }
  .sockopen myb www.erepublik.com 80
}



I would appreciate some help with making that alias repeat its job until i stop it. I would like some help with "stopping it" part.

If it cant be done, any insight on how to do it by for example .start and .stop commands if i install it on a bot.

Thanks

EDIT:

I found a "cheat". I set it to do a very high number of repetitions and just stop it by turning the timer off. While loop cant be stopped since it executes too fast but timer continues running.

Code:
alias endit {
  timer* off
}

Last edited by crreep; 17/03/11 12:54 AM.
Re: Sockread help [Re: crreep] #230668 17/03/11 02:22 AM
Joined: Oct 2004
Posts: 8,327
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,327
You can use hixxy's code to start it after closing the socket. Just put a timer on the sockopen he put near the end of the script.

.timermyb 0 5 sockopen myb www.erepublik.com 80

You can adjust the 5 to whatever number of seconds you want to let it wait before repeating.

Then, to end the timer, use:

/timermyb off


Invision Support
#Invision on irc.irchighway.net
Re: Sockread help [Re: Riamus2] #230670 17/03/11 03:47 AM
Joined: Jul 2007
Posts: 1,129
T
Tomao Offline
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
You may not need a timer to open another socket. You can use the sockclose event to open a new one, along with the use of

.sockwrite -n $sockname Connection: close

Then:

on 1:SOCKCLOSE:myb:{
sockopen myb http://www.erepublik.com 80
....

Re: Sockread help [Re: crreep] #230675 17/03/11 08:03 AM
Joined: Sep 2005
Posts: 2,876
H
hixxy Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,876
You could just add a delay to the code I gave you in this:

Code:
alias myb {
  set %tempchan $chan
  %bitka = $1
  set %kuda a
  set %myb.i 5
  if ($sock(myb)) { .sockclose myb }
  .sockopen myb www.erepublik.com 80
}

on *:sockopen:myb:{
  .sockwrite -n $sockname GET /en/military/battle-log/ $+ %bitka HTTP/1.1
  .sockwrite -n $sockname Host: www.erepublik.com
  .sockwrite -n $sockname $crlf
}

on 1:SOCKREAD:myb: {
  .sockread -f %temp
  set %buffer %temp
  while ($sockbr != 0) {
    .sockread -f %temp
    %buffer = %buffer %temp
  }
  if ($pos(%buffer,domination,1) > 0) {
    %bi = $pos(%buffer,domination,1) + $len(domination)
    %ei = $pos(%buffer,att,1)
    %kuda = $mid(%buffer,$calc(%bi + 2),$calc(%ei - %bi - 4))
  }
  if (%kuda != a) {
    if ($sock(myb)) { 
      .sockclose myb 
      if (%myb.i) {
        .timer 1 $calc(6 - %myb.i) sockopen myb www.erepublik.com 80
        dec %myb.i
      }
    }
    msg %tempchan %bitka $+ : $left($calc(100 - %kuda),6) $+ % -  $+ $chr(32) $+  $left(%kuda,6) $+ %    
  }
}


This line:

.timer 1 $calc(6 - %myb.i) sockopen myb www.erepublik.com 80

Will make sure the next socket is called with a 1 second delay after the current one.

Re: Sockread help [Re: Tomao] #230676 17/03/11 10:12 AM
Joined: Oct 2004
Posts: 8,327
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,327
Originally Posted By: Tomao
You may not need a timer to open another socket.


Right, but the OP said it was faster than he wanted. The timer allows slowing it down.


Invision Support
#Invision on irc.irchighway.net