mIRC Home    About    Download    Register    News    Help

Print Thread
Page 1 of 2 1 2
I need help retrieving text from web #253309 09/06/15 03:35 AM
Joined: Jun 2015
Posts: 10
A
AntuV Offline OP
Pikka bird
OP Offline
Pikka bird
A
Joined: Jun 2015
Posts: 10
What I want to do is to get rid of Nightbot as it isn't fast enough due to certain limitations it has.

So... I have a mini-game in a channel I admin, a PvP mini-game. You'd input "!pvp b" and then retrieve what's in http://agussdg.ga/verificar.php?user1=a&user2=b where "a" is the user who triggered the command and "b" is the target user.

(NOTE: it won't work at this moment if it's not from Nightbot's IP)

I have problems retrieving the text it generates and I don't know if I'm doing it right. Here's the script I got at this moment:

Code:
on 1:text:!pvp*:#: {
  var %sock = pvp
  sockopen %sock agussdg.ga 80
  sockread %sock
}

on 1:sockopen:pvp*: {
  sockwrite -n $sockname GET /verificar.php?user1= $+ $nick $+ &user2= $+ $2 HTTP/1.1
  sockwrite -n $sockname Host: www.agussdg.ga
  sockwrite -n $sockname $crlf
}

on 1:sockread:pvp*: {
  var %t
  sockread %t
  while ($sockbr) {
    echo %t
    sockread %t
  }
  sockclose $sockname
}

Last edited by AntuV; 09/06/15 03:36 AM.
Re: I need help retrieving text from web [Re: AntuV] #253310 09/06/15 09:55 AM
Joined: May 2015
Posts: 249
splinny Offline
Fjord artisan
Offline
Fjord artisan
Joined: May 2015
Posts: 249
(NOTE: it won't work at this moment if it's not from Nightbot's IP)
maybe your way of restricting IP causes problems?


Dont give a fish - teach to fish!
Re: I need help retrieving text from web [Re: splinny] #253312 09/06/15 10:15 AM
Joined: May 2015
Posts: 249
splinny Offline
Fjord artisan
Offline
Fjord artisan
Joined: May 2015
Posts: 249
all i got
Code:
1: HTTP/1.1 200 OK
1: Date: Tue, 09 Jun 2015 10:14:52 GMT
1: Server: Apache
1: X-Powered-By: PHP/5.5.21
1: Content-Encoding: gzip
1: Vary: Accept-Encoding
1: Content-Length: 70
1: Keep-Alive: timeout=2, max=100
1: Connection: Keep-Alive
1: Content-Type: text/html; charset=UTF-8
1:
1:


Dont give a fish - teach to fish!
Re: I need help retrieving text from web [Re: splinny] #253313 09/06/15 11:27 AM
Joined: Jan 2004
Posts: 1,276
L
Loki12583 Online
Hoopy frood
Online
Hoopy frood
L
Joined: Jan 2004
Posts: 1,276
You don't receive all the data in single sockread, so don't sockclose at the end of it.

Re: I need help retrieving text from web [Re: AntuV] #253314 09/06/15 11:34 AM
Joined: Jul 2006
Posts: 3,582
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,582
I wrote a lot about how to properly read with on sockread, see in particular the section about the last line not showing up wink

http://en.wikichip.org/wiki/mirc/commands/sockread

Last edited by Wims; 09/06/15 11:34 AM.

Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: I need help retrieving text from web [Re: splinny] #253321 09/06/15 03:49 PM
Joined: Jun 2015
Posts: 10
A
AntuV Offline OP
Pikka bird
OP Offline
Pikka bird
A
Joined: Jun 2015
Posts: 10
Originally Posted By: splinny
(NOTE: it won't work at this moment if it's not from Nightbot's IP)
maybe your way of restricting IP causes problems?


I was refering to the mini-game itself. If you go to that URL it will show "Esta ({IP}) no es la IP de Nightbot" what translates to: "This ({IP}) isn't Nightbot's IP".

At least it should return that

Last edited by AntuV; 09/06/15 03:50 PM.
Re: I need help retrieving text from web [Re: Loki12583] #253322 09/06/15 03:51 PM
Joined: Jun 2015
Posts: 10
A
AntuV Offline OP
Pikka bird
OP Offline
Pikka bird
A
Joined: Jun 2015
Posts: 10
Originally Posted By: Loki12583
You don't receive all the data in single sockread, so don't sockclose at the end of it.


Originally Posted By: Wims
I wrote a lot about how to properly read with on sockread, see in particular the section about the last line not showing up wink

http://en.wikichip.org/wiki/mirc/commands/sockread


I'll read this and come back later! Thanks to both!

Re: I need help retrieving text from web [Re: AntuV] #253323 09/06/15 03:52 PM
Joined: May 2015
Posts: 249
splinny Offline
Fjord artisan
Offline
Fjord artisan
Joined: May 2015
Posts: 249
tnx to Wims and Loki12583 smile
/pvp a b
Code:
alias pvp {
  var %sock = $+(pvp,$1,$$2)
  if ($sock(%sock)) { sockclose %sock }
  sockopen %sock agussdg.ga 80
  sockmark %sock $1 $2
}

on *:sockopen:pvp*: {
  var %nick1 = $gettok($sock($sockname).mark,1,32)
  var %nick2 = $gettok($sock($sockname).mark,2,32)
  var %u = $+(user1=,%nick1,&user2=,%nick2)
  sockwrite -n $sockname GET /verificar.php HTTP/1.1
  sockwrite -n $sockname Host: agussdg.ga
  sockwrite -n $sockname User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0
  sockwrite -n $sockname Connection: keep-alive
  sockwrite -n $sockname $+($crlf,%u)
}

on *:sockread:pvp*: {
  if ($sockerr) { return }
  var %temp = $null
  sockread %temp
  if ($sockbr == 0) sockread %temp
  echo -ag on-read: %temp
}

on *:sockclose:pvp*:{
  if (!$sockerr) {
    var %temp = $null
    sockread -f %temp
    if ($sockbr == 0) return
    echo -ag on-close: %temp
  }
}


Dont give a fish - teach to fish!
Re: I need help retrieving text from web [Re: splinny] #253325 09/06/15 04:09 PM
Joined: Jun 2015
Posts: 10
A
AntuV Offline OP
Pikka bird
OP Offline
Pikka bird
A
Joined: Jun 2015
Posts: 10
Originally Posted By: splinny
tnx to Wims and Loki12583 smile
/pvp a b
Code:
alias pvp {
  var %sock = $+(pvp,$1,$$2)
  if ($sock(%sock)) { sockclose %sock }
  sockopen %sock agussdg.ga 80
  sockmark %sock $1 $2
}

on *:sockopen:pvp*: {
  var %nick1 = $gettok($sock($sockname).mark,1,32)
  var %nick2 = $gettok($sock($sockname).mark,2,32)
  var %u = $+(user1=,%nick1,&user2=,%nick2)
  sockwrite -n $sockname GET /verificar.php HTTP/1.1
  sockwrite -n $sockname Host: agussdg.ga
  sockwrite -n $sockname User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0
  sockwrite -n $sockname Connection: keep-alive
  sockwrite -n $sockname $+($crlf,%u)
}

on *:sockread:pvp*: {
  if ($sockerr) { return }
  var %temp = $null
  sockread %temp
  if ($sockbr == 0) sockread %temp
  echo -ag on-read: %temp
}

on *:sockclose:pvp*:{
  if (!$sockerr) {
    var %temp = $null
    sockread -f %temp
    if ($sockbr == 0) return
    echo -ag on-close: %temp
  }
}


Wow! You made it to show the text at least! laugh
What I needed was a command that if someone called UserA inputs "!pvp UserB" then it will retrieve the text in "agussdg.ga/verificar.php?user1=UserA&user2=UserB".

I'll see if I can edit it to make it like that!

Re: I need help retrieving text from web [Re: AntuV] #253326 09/06/15 04:27 PM
Joined: May 2015
Posts: 249
splinny Offline
Fjord artisan
Offline
Fjord artisan
Joined: May 2015
Posts: 249
on-text event with calling pvp-alias like !pvp player2 => /pvp $nick $2


Dont give a fish - teach to fish!
Re: I need help retrieving text from web [Re: splinny] #253327 09/06/15 04:48 PM
Joined: Jun 2015
Posts: 10
A
AntuV Offline OP
Pikka bird
OP Offline
Pikka bird
A
Joined: Jun 2015
Posts: 10
Originally Posted By: splinny
on-text event with calling pvp-alias like !pvp player2 => /pvp $nick $2


Code:
on *:text:!pvp*:#: {
  //pvp $nick $2
}

Like this?

If I make it like that, the argument that should be the player2, is null frown

Re: I need help retrieving text from web [Re: AntuV] #253328 09/06/15 04:55 PM
Joined: May 2015
Posts: 249
splinny Offline
Fjord artisan
Offline
Fjord artisan
Joined: May 2015
Posts: 249
And what you typed in chat to test it?


Dont give a fish - teach to fish!
Re: I need help retrieving text from web [Re: splinny] #253329 09/06/15 05:01 PM
Joined: Jun 2015
Posts: 10
A
AntuV Offline OP
Pikka bird
OP Offline
Pikka bird
A
Joined: Jun 2015
Posts: 10
Originally Posted By: splinny
And what you typed in chat to test it?


In twitch I typed "!pvp Agussdg_"

The php file verifies the user exists, but only after veryfing there is an argument that isn't null, which is the case.

Screenshot: http://puu.sh/iiryf/661b07f9f9.png

Re: I need help retrieving text from web [Re: AntuV] #253330 09/06/15 05:24 PM
Joined: May 2015
Posts: 249
splinny Offline
Fjord artisan
Offline
Fjord artisan
Joined: May 2015
Posts: 249


Dont give a fish - teach to fish!
Re: I need help retrieving text from web [Re: splinny] #253331 09/06/15 06:05 PM
Joined: Jun 2015
Posts: 10
A
AntuV Offline OP
Pikka bird
OP Offline
Pikka bird
A
Joined: Jun 2015
Posts: 10
Originally Posted By: splinny


Yes, it does

Re: I need help retrieving text from web [Re: AntuV] #253332 09/06/15 06:16 PM
Joined: May 2015
Posts: 249
splinny Offline
Fjord artisan
Offline
Fjord artisan
Joined: May 2015
Posts: 249
So its your fate.


Dont give a fish - teach to fish!
Re: I need help retrieving text from web [Re: splinny] #253335 09/06/15 07:50 PM
Joined: Jun 2015
Posts: 10
A
AntuV Offline OP
Pikka bird
OP Offline
Pikka bird
A
Joined: Jun 2015
Posts: 10
Originally Posted By: splinny
So its your fate.


I solved it doing this:

Code:
  sockwrite -n $sockname GET /verificar.php?user1= $+ %nick1 $+ &user2= $+ %nick2 HTTP/1.1


But now how do I get it to actually print it on Twitch chat? Because "echo -ag $chan %temp" does not, and "msg $chan %temp" neither frown

Re: I need help retrieving text from web [Re: AntuV] #253337 09/06/15 08:09 PM
Joined: Jan 2004
Posts: 1,276
L
Loki12583 Online
Hoopy frood
Online
Hoopy frood
L
Joined: Jan 2004
Posts: 1,276
$chan is not valid a socket event, you need to associate $chan with $sockname and store it either in a global variable, hash table, or by using the /sockmark command.

Re: I need help retrieving text from web [Re: Loki12583] #253338 09/06/15 08:10 PM
Joined: Jun 2015
Posts: 10
A
AntuV Offline OP
Pikka bird
OP Offline
Pikka bird
A
Joined: Jun 2015
Posts: 10
Originally Posted By: Loki12583
$chan is not valid a socket event, you need to associate $chan with $sockname and store it either in a global variable, hash table, or using the /sockmark command.


How? I'm really new to this smirk

Code:
alias pvp {
  var %sock = $+(pvp,$1,$$2)
  if ($sock(%sock)) { sockclose %sock }
  sockopen %sock agussdg.ga 80
  sockmark %sock $1 $2
}

on *:sockopen:pvp*: {
  var %nick1 = $gettok($sock($sockname).mark,1,32)
  var %nick2 = $gettok($sock($sockname).mark,2,32)
  sockwrite -n $sockname GET /verificar.php?user1= $+ %nick1 $+ &user2= $+ %nick2 HTTP/1.1
  sockwrite -n $sockname Host: agussdg.ga
  sockwrite -n $sockname User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0
  sockwrite -n $sockname Connection: keep-alive
  sockwrite -n $sockname $crlf
}

on *:sockread:pvp*: {
  if ($sockerr) { return }
  var %temp = $null
  sockread %temp
  if ($sockbr == 0) sockread %temp
}

on *:sockclose:pvp*:{
  if (!$sockerr) {
    var %temp = $null
    sockread -f %temp
    if ($sockbr == 0) return
    echo -ag $chan %temp
  }
}

on *:text:!pvp*:#: {
  //pvp $nick $2
}

This is all the code

Last edited by AntuV; 09/06/15 08:13 PM.
Re: I need help retrieving text from web [Re: AntuV] #253339 09/06/15 08:18 PM
Joined: Jan 2004
Posts: 1,276
L
Loki12583 Online
Hoopy frood
Online
Hoopy frood
L
Joined: Jan 2004
Posts: 1,276
You're already using /sockmark, so just add $chan to that. You should understand the code you're running.

Page 1 of 2 1 2