Shoutbox

[Req] Touch/ping a URL - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: [Req] Touch/ping a URL (/showthread.php?tid=74812)

[Req] Touch/ping a URL by MeEtc on 05-28-2007 at 10:45 PM

Hey all you budding script developers!

I was wondering if any of you would be interested in making a script that executes a php file on a remote site every time I either sign in and/or come out of offline status.

I don't need a flashy GUI, just a place to put the URLs in a variable list or array in the code is fine. Oh, and I might need to use more than one URL, so adding it to an array sounds like a good option.


RE: [Req] Touch/ping a URL by Dennis Mike on 05-28-2007 at 10:54 PM

good idea


RE: [Req] Touch/ping a URL by Ezra on 05-30-2007 at 06:09 PM

I felt bad that noone made it for you yet, so I made a quick thingy

code:
var xmlhttp;

var linkarr = new Array();

//Here we fill the array with the addresses we will be "pinging", just add more .push statements to add more servers.
linkarr.push("http://www.testserver.com/ping.php");
linkarr.push("http://www.testserver2.com/ping2.php");

function OnEvent_Initialize(MessengerStart)
{
  //Create the XMLHTTP object we will be re-using the entire time the script runs.
  xmlhttp = new ActiveXObject("Microsoft.XmlHttp");
}

function OnEvent_Uninitialize(MessengerExit)
{
  //Delete the XMLHTTP Object, not really necassary as the Garabage Collector will clean it up too.
  delete xmlhttp;
}

function OnEvent_Signin(Email)
{
  //Status Change is not called when we sign in so here's a seperate function to ping when we sign in.
  //The three means "Online", see Scripting Docs for full explanation of statusCodes.
  ping(3);
}

function OnEvent_MyStatusChange(NewStatus)
{
  //Ping the server and send the new status too.
  ping(NewStatus);
}

function ping(NewStatus)
{
  //Here we will be sending the actual pings.
  var link;
  //Create a so called foreach loop to loop trough all the servers in the array.
  for (link in linkarr)
  {
    //Debug.Trace("  linkarr::linkarr[" + link + "] = "  +linkarr[link]);
    //Debug.Trace("  param::" + "?email=" + Messenger.myEmail + "&NewStatus=" + NewStatus);
    //Open a connection to the server.
    xmlhttp.open("GET", linkarr[link] + "?email=" + Messenger.myEmail + "&NewStatus=" + NewStatus, true);
    //Send nothing, this just creates the actual connection to the server and the params are send as GET params.
    xmlhttp.send();
  }
}

WDZ, code coloring please :'(
RE: [Req] Touch/ping a URL by MeEtc on 05-30-2007 at 08:26 PM

Thanks ezra! I was thinking all statuses except for 2 - offline instead of just online status. I don't need to send status or username or whatever, just need to run the script


RE: [Req] Touch/ping a URL by Ezra on 05-30-2007 at 10:47 PM

Changed the parts below to remove sending the statuses and email address to the server. Now it's just a "ping" :-)

code:
function OnEvent_Signin(Email)
{
  //Status Change is not called when we sign in so here's a seperate function to ping when we sign in.
  //Removed sending the status, just a ping is good.
  ping();
}

function OnEvent_MyStatusChange(NewStatus)
{
  //Ping the server.
  ping();
}

function ping()
{
  //Here we will be sending the actual pings.
  var link;
  //Create a so called foreach loop to loop trough all the servers in the array.
  for (link in linkarr)
  {
    //Debug.Trace("  linkarr::linkarr[" + link + "] = "  +linkarr[link]);
      //Open a connection to the server.
    xmlhttp.open("GET", linkarr[link], true);
    //Send nothing, this just creates the actual connection to the server and the params are send as GET params.
    xmlhttp.send();
  }
}

To add things like a ping on signout just add the correct Events and call the ping function from there.