mIRC Homepage

Need help in Socket

Posted By: SYD

Need help in Socket - 03/05/16 10:07 AM

I need help in socket . I done almost all script work and now just need to parse message from sockread to channel . what to do ??
Posted By: Sakana

Re: Need help in Socket - 03/05/16 02:24 PM

Use /msg followed by the channel name which you store in either a global variable or in $sockmark
Posted By: SYD

Re: Need help in Socket - 03/05/16 06:05 PM

Originally Posted By: Sakana
Use /msg followed by the channel name which you store in either a global variable or in $sockmark


I think I know that but my prob is . The value I want is surrounded by other values but not by "space" . then how will I get the data I want ?

Thanks for the answer anyway smile
Posted By: westor

Re: Need help in Socket - 05/05/16 01:29 PM

If you want to parse an socket data to an channel just follow the ON SOCKREAD event (/help on sockread)
Posted By: SYD

Re: Need help in Socket - 08/05/16 07:43 AM

Tried that . but data needed is from an API . not getting the results as usual .

API : http://maxima.e-sim.org/apiCitizenByName.html?name=dazzler

Found this already : http://hawkee.com/snippet/10194/

But I dont know what json is or how to do it . So if you guys please help me by giving me working script of API above using the JSON parser , it will be a lot more great .

Regards,
Posted By: westor

Re: Need help in Socket - 08/05/16 12:35 PM

It's not hard, the SReject has already provide some examples in his JSON script of how can you do that but anyway, you can add more by your own it's easy just follow this example:

NOTE: Make sure that you are using the latest mIRC version and the latest JSON script addon version.

Code:
alias get_results {
  var %v = res_ $+ $rand(1,100000)
  var %u = http://maxima.e-sim.org/apiCitizenByName.html?name=dazzler
  JSONOpen -ud %v %u
  if ($JSONError) { echo 4 -a Error: There was an connection problem! - (Error Details: $jsonerror $+ ) | return }
  var %str = $json(%v,strength)
  var %rank = $json(%v,rank)
  echo -a Results are - Strength: %str - Rank: %rank
}
Posted By: OrFeAsGr

Re: Need help in Socket - 08/05/16 01:26 PM

Hey.. i didn't reloaded to see that westor replied so i made this script which echos all the items and values. SReject's must work better but here's mine too..
Code:
ON *:SOCKOPEN:maxima: { if ($sockerr) { echo -at Error while retrieving maxima info... | sockclose $sockname } | sockwrite -nt $sockname GET /apiCitizenByName.html?name=dazzler HTTP/1.1 | sockwrite -nt $sockname Connection: close | sockwrite -nt $sockname Host: maxima.e-sim.org | sockwrite $sockname $crlf }


ON *:SOCKREAD:maxima: {
  var %m | sockread -f %m 
  if ({"* iswm %M) {
    var %x = 2
    while (%x <= $numtok(%m,34)) {
      var %t = $gettok(%m,%x,34)
      var %t2 = $gettok(%m,$calc(%x + 1),34)
      var %t3 = $gettok(%m,$calc(%x + 2),34)
      if (%t2 == :) {
        var %item = %t
        var %value = $remove(%t3,:,$chr(44))
        echo -at %item > %value
        inc %x 4
      }
      elseif (%t2 != :) {
        var %item = %t
        var %value = $remove(%t2,:,$chr(44))
        echo -at %item > %value
        inc %x 2
      }
      ;;;You can place your if here
      ;;; example if (%item == eqCriticalHit) { echo -at %value } ;;;
    }
    sockclose $sockname
  }
}

Do
/sockopen maxima maxima.e-sim.org 80
to test it
Posted By: SYD

Re: Need help in Socket - 08/05/16 04:02 PM

Originally Posted By: OrFeAsGr
Hey.. i didn't reloaded to see that westor replied so i made this script which echos all the items and values. SReject's must work better but here's mine too..
Code:
ON *:SOCKOPEN:maxima: { if ($sockerr) { echo -at Error while retrieving maxima info... | sockclose $sockname } | sockwrite -nt $sockname GET /apiCitizenByName.html?name=dazzler HTTP/1.1 | sockwrite -nt $sockname Connection: close | sockwrite -nt $sockname Host: maxima.e-sim.org | sockwrite $sockname $crlf }


ON *:SOCKREAD:maxima: {
  var %m | sockread -f %m 
  if ({"* iswm %M) {
    var %x = 2
    while (%x <= $numtok(%m,34)) {
      var %t = $gettok(%m,%x,34)
      var %t2 = $gettok(%m,$calc(%x + 1),34)
      var %t3 = $gettok(%m,$calc(%x + 2),34)
      if (%t2 == :) {
        var %item = %t
        var %value = $remove(%t3,:,$chr(44))
        echo -at %item > %value
        inc %x 4
      }
      elseif (%t2 != :) {
        var %item = %t
        var %value = $remove(%t2,:,$chr(44))
        echo -at %item > %value
        inc %x 2
      }
      ;;;You can place your if here
      ;;; example if (%item == eqCriticalHit) { echo -at %value } ;;;
    }
    sockclose $sockname
  }
}

Do
/sockopen maxima maxima.e-sim.org 80
to test it



Thanks but I already found a simple without opening socket smile
© 2022 mIRC Discussion Forums