mIRC Homepage
Posted By: Aler360 Help with socket and reading from website - 24/07/14 03:26 AM
I want my bot to read what is on this website http://nightdev.com/hosted/followers.php?channel=aler360&limit=5 but when i use my code it doesnt return anything. Im farilly new to sockets and could be doing a very silly mistake plz help

alias test {
sockopen test nightdev.com 80
}

on *:sockopen:test: {
sockwrite -n $sockname get /hosted/followers.php?channel=aler360&limit=5 HTTP/1.0
sockwrite -n $sockname User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)
sockwrite -n $sockname Host: nightdev.com
sockwrite -n $sockname Accept-Language: en-us
sockwrite -n $sockname Accept: */*
sockwrite -n $sockname
}

on *:sockread:test: {
if ($sockerr) {
echo -a Error.
halt
}
else {
var %temp
sockread %temp
if (something isin %temp) {
do something
}
elseif (somethingelse isin %temp) {
do something else
}
}
}
try this instead
Code:
on *:sockopen:test: {
   sockwrite -n $sockname GET /hosted/followers.php?channel=aler360&limit=5 HTTP/1.0
   sockwrite -n $sockname Host: nightdev.com $crlf $+ $crlf
}
it didnt seam to work i just got no responce
what do you mean you don't get a response?

i tried
Code:
on *:text:!followers:#:{
  test
}


alias test {
  sockopen test nightdev.com 80
}

on *:sockopen:test: {
  sockwrite -n $sockname GET /hosted/followers.php?channel=aler360&limit=5 HTTP/1.0
  sockwrite -n $sockname Host: nightdev.com $crlf $+ $crlf
}

on *:sockread:test: {
  if ($sockerr) { return }
  var %read | sockread -f %read
  while ($sockbr) {
    if (%read != $null) echo -ag %read
    sockread -f %read
}



And it echo the entire page back. It's the same code you are using, with my updated sockopen code block that I posted earlier. All the read part is doing is echo anything that is read from the server. This means that you should be getting a response. Your if statements probably aren't checking correctly
Thus echo the website but it doesnt post it back in chat
HELP Plz
well, to message it back in chat, use the msg channel command. You wouldn't want to read the entire website back to chat, though. If it spams the chat really fast, you get kicked off the irc server.
How would i use implement the msg channel command
I'm a little confused, you know how to work sockets, but don't know basic mirc command syntax, usually its the other way around, lol.

anyways, the syntax for sending a message is:
Code:
msg #channelname Message to respond here.


if I put that as the exact message command, and the script bot was named "bot", the chat response would be

bot: Message to respond here.


You can also print out variables, and nick names, like $nick, or %variablename.

If you still have any question about simple mirc scripting commands and variable use, I'd suggest looking over the mirc help documentation, or searching online for some tutorials/wiki/databases. If you already know how to implement sockets, then help documentation or a tutorial might prove more useful to you, then back/forth question answering on a forum.
Code:
on *:text:!followers:#:{
  test msg #
}

alias test {
  sockclose test 
  sockopen test nightdev.com 80
  sockmark test $1-
}

on *:sockopen:test: {
  sockwrite -n $sockname GET /hosted/followers.php?channel=aler360&limit=5 HTTP/1.0
  sockwrite -n $sockname Host: nightdev.com $crlf $+ $crlf
}

on *:sockread:test: {
  if ($sockerr) { return }
  var %read | sockread -f %read
  while ($sockbr) {
    if (%read == $null) { var %data 1 }
    elseif %data { $sock(test).mark %read }
    sockread -f %read
  }
}
© mIRC Discussion Forums