mIRC Home    About    Download    Register    News    Help

Print Thread
Need Help with Twitch Autohost Script / Sockets #255857 28/11/15 08:01 AM
Joined: Oct 2015
Posts: 112
B
Blas Offline OP
Vogon poet
OP Offline
Vogon poet
B
Joined: Oct 2015
Posts: 112
I've been trying to wrap my head around this for hours now. I have wrote a complex Twitch Autohost script that is almost completely functional except for this last piece of the puzzle. The issue I am having is that it appears as if variables are not being set/returned fast enough. This is the "checking if channel is live" portion of my autohost script (I got the template on this forum). The issue is that the other portion of my script is quickly scanning each channel in my autohost list in a while loop, and needs to know right away if a channel is live so it can do the hosting and then halt the while loops that keep searching for a channel to host before it tries to host another. The issue in this code is that the "IF (%tuptime == True) { return true }" line of tuptime does not actually return "true" fast enough, as when I used the "!ahtest channelname" in the script show, it will not msg channel until the second time that I run it, which it will then return both "test2" and then "test1" to the channel. However, the %tuptime variable IS getting set in mIRC immediately after I first use the !ahtest command. My question is, how can I have my tuptime alias start and then finish and return true before the tuptime alias is called on again in the while loops I have created in the rest of my script that I have written?

Code:
ON *:TEXT:!ahtest &:#: {
  $tuptime($2)
  IF (%tuptime) MSG $chan test1
}


alias tuptime {

  SET %uptimechan $1
  sockclose tuptime
  sockopen tuptime nightdev.com 80
  IF (%tuptime == True) { msg $chan test2 | return true }
}


ON *:SOCKOPEN:tuptime: {
  if ($sockerr) { sockclose $sockname | halt }
  sockwrite -n $sockname GET /hosted/uptime.php?channel= $+ %uptimechan HTTP/1.1
  sockwrite -n $sockname Host: $sock($sockname).addr
  sockwrite -n $sockname $crlf
}


ON *:SOCKREAD:tuptime: {
  if ($sockerr) { sockclose $sockname }
  var %data
  sockread %data
  if ($gettok(%data,1,32) isnum) && ($gettok(%data,2,32)) {
    SET %tuptime True
  }
}

Re: Need Help with Twitch Autohost Script / Sockets [Re: Blas] #255858 28/11/15 01:41 PM
Joined: Oct 2015
Posts: 112
B
Blas Offline OP
Vogon poet
OP Offline
Vogon poet
B
Joined: Oct 2015
Posts: 112
Well I spent a few more hours on the script, and it appears at the moment that I have a working autohost script with multiple "tiers" of possible hosts. However, I had to set a LOT of various timers to have it function properly due to the above issue.

Re: Need Help with Twitch Autohost Script / Sockets [Re: Blas] #255859 28/11/15 01:45 PM
Joined: Jan 2004
Posts: 1,286
L
Loki12583 Offline
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,286
You can't do that with mIRC sockets, structure the code differently to execute your commands after the sockets have finished.

Re: Need Help with Twitch Autohost Script / Sockets [Re: Loki12583] #255860 28/11/15 02:55 PM
Joined: Dec 2008
Posts: 1,511
westor Offline
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2008
Posts: 1,511
You can have a look at this addon i've made it for an other user but may it is that you want for: http://pastebin.com/zMiwANBC or look and this one: http://hawkee.com/snippet/16314/

Last edited by westor; 28/11/15 02:56 PM.
Re: Need Help with Twitch Autohost Script / Sockets [Re: Blas] #255862 28/11/15 08:34 PM
Joined: Oct 2015
Posts: 112
B
Blas Offline OP
Vogon poet
OP Offline
Vogon poet
B
Joined: Oct 2015
Posts: 112
Thanks for the replies. The scripts that westor linked to are the scripts that I used to start writing my script. I have structured the code in a way now that checks each channel about six seconds after each other to see if they are online. It seems like this method takes a lot longer than it probably needs to, but it is working so far.