Wiki :: Search :: Usergroups :: Register :: Profile :: Log in to check your private messages :: Log in
GamingTools Subscription: Not logged in
Opening a Web page through EQWatcher

 
Post new topic   Reply to topic    Lavish Software Forum Index -> GamingTools Public::EQWatcher Evolution
View previous topic :: View next topic  
Author Message
spointman

 

Rank: Non-Subscriber

Joined: 24 Jul 2004

Posts: 8

Post subject: Opening a Web page through EQWatcher
Reply with quote
Heya. I'm trying to get a script that will open a Web page whenever it sees certain text in the log file. It doesn't have to actually open it in a browser, but it does have to register a hit on the Web page.

Example:
Quote:
Soandso tells you, 'GotLink 23456'

This causes a connection to the following page, which would increment an internal counter for item 23456:
http://www.some.site.or.other.com/dir1/page1.htm?item=23456

I would then write another page to show which items have been counted the most. (Yes, I know this is a trivial example; I'm trying to simplify things a bit.)

I saw the sockets documentation in EQWatcher, but I'm hoping someone has a more elegant solution than writing my own mini Web browser into EQW. Smile Does anyone know of an existing script that can act as a wrapper to the sockets commands?

Alternately, could I use the Spawn() command to launch a Web browser pointing to that page? Something like:

Spawn("c:\program files\Mozilla Firefox", "firefox.exe http://www.some.site.or.other.com/dir1/page1.htm?item=23456")

Or would the command line parameter cause an error?
PostSat Sep 15, 2007 11:03 am
View user's profile Send private message
spointman

 

Rank: Non-Subscriber

Joined: 24 Jul 2004

Posts: 8

Post subject:
Reply with quote
OK, so it turns out Spawn() doesn't work with command-line parameters, such as the target page to open in the Web browser.

I was able to sort-of get around this limitation by using EQWatcher's SQL support to write directly to the database, but the upshot is that I now have to rewrite all my validation code into EQWatcher scripts. I'm still looking for a way to open or call a Web page with a query string, if anyone knows of one.

Hmm ... this fails too:
Code:
Spawn("", "http://www.yahoo.com?a=b");


I wonder if I could use the file I/O functions to write a batch file, then Spawn() to run the file? That's a bit roundabout, though.
PostSun Sep 16, 2007 3:16 pm
View user's profile Send private message
spointman

 

Rank: Non-Subscriber

Joined: 24 Jul 2004

Posts: 8

Post subject:
Reply with quote
For those wondering what happened, I ended up doing it through the sockets functionality in EQWatcher. I basically used sockets to simulate a Web browser request. Since I don't really care about a detailed response, I used the HEAD method instead of GET, and encoded the results into headers that the Web page would generate and include. If you actually need to parse the content of the page, it's not much harder than what's below, although you have to remember that it's parsed line by line.

Here's the gist of what I did. You'll probably have to change most of this to suit your own needs, but the structure should get you started.

Code:
function main () {} // Needed for the script to compile.

// the g prefix indicates global
public string gSender = "";
public string gItem = "";
public unsigned long gSocketID = 0;
public string gSocketName = "";
public string gResponse = "";
public string gCode = "";


// Returns a string containing the hex value of the passed-in char.
function Hex (char Value)
{
   byte HighOrder = Value / 16; // hopefully this truncates
   byte LowOrder = Value % 16;

   string HexResult = "";

   if (HighOrder < 10)
   {
      HexResult = chr(HighOrder + 48);
   }
   else
   {
      HexResult = chr(HighOrder + 55);
   }

   if (LowOrder < 10)
   {
      strcat(HexResult, chr(LowOrder + 48));
   }
   else
   {
      strcat(HexResult, chr(LowOrder + 55));
   }

   return HexResult;
}



// Converts any characters in the incoming string that are outside the normal
// alphanumeric range into hex equivalents.  The resulting string is URL-safe.
function MakeURLSafe(string incoming)
{
   unsigned long i = 0;
   unsigned long length = strlen(incoming);
   string ResultString = "";
   char Single = 0;

   // Loop through and replace any character outside our desired ASCII range
   // Basically encode everything except letters and digits.
   // No FOR loop, so we have to improvise with a WHILE loop

   while (i < length)
   {
      Single = strpos(incoming, i);
      if ( Single < 48 ||                  // less than number
          (Single > 57 && Single < 65) ||   // Greater than number, less than Uppercase
          (Single > 90 && Single < 97) ||   // Greater than Uppercase, less than Lowercase
          Single > 122                  // Greater than Lowercase
         )
      {
         // Replace and append
         strcat(ResultString, "%", Hex(Single));
      }
      else
      {
         // Just append
         strcat(ResultString, chr(Single));
      }

      i++;
   }
   return ResultString;
}


// Trigger for the incoming tell.  This calls the Web page function
trigger("[@trash@] @gSender@ tells you, 'GotItem @gItem@'")
{
   // If you want validate who's sending you tells, you can do that here.
   // For example, maybe only process tells from your own characters.
   // Or maybe you only want to record certain items.

   // Once you determine whether you want to parse this tell, call the next function.
   ParseTell (gSender, gItem);
}



function ParseTell (string Sender, string Item)
{
   gSocketID++;
   string SocketName = "Item_" + gSocketID;

   boolean result = false;

   result = SockNew(SocketName, 0, "DoOnReceive");
   if (!result)
   {
      // Couldn't initialize the socket. Most likely, the user didn't enable
      // Internet access from the EQWatcher GUI.
      SpeakSync("Socket Failure! Is Internet access enabled?");
      return;
   }
   
   result = false;
   // Change the Web site in the line below. 
   // The 80 means port 80, which is the standard for Web requests,
   // so you probably won't have to change that.
   result = SockConnect(SocketName, "www.YourWebSite.com", 80);

   if (!result)
   {
      // Couldn't find the Web site, or the site didn't respond.
      SpeakSync("Connection Failure!");
      return;
   }

   // We use the HEAD method since we don't need the body of the Web page.
   // If you need the body, use GET instead.
   // Change the path and page to your own page.
   string Request = "HEAD /dir1/dir2/YourPage.php";
   
   // first parameter must be preceded by a question mark
   strcat(Request, "?sender=", MakeURLSafe(Sender));
   
   // Subsequent parameters must be separated by ampersands
   strcat(Request, "&item=", MakeURLSafe(Item));

   // Add the protocol name and version
   strcat(Request, " HTTP/1.0", chr(13), chr(10));

   // A user-agent string isn't mandatory, but it's polite to include it.
   strcat(Request, "User-Agent: EQWatcher Evolution/2.39");
   
   // Two new-lines (CR and LF) indicate the end of your request.
   strcat(Request, chr(13), chr(10), chr(13), chr(10));

   SockSend(SocketName, Request);

   // We don't get a direct response, so we don't know whether the request
   // made it to the destination server or not.
}

alias ("DoOnReceive \"@gSocketName@\" X-EQWatcher-Result: @gCode@ @gResponse@")
{
   // Handle the response here.  My setup used a two-part header value, a
   // number and a response text.  The Code was what I used to decide
   // whether the request succeeded or not.  The text response was just so
   // I didn't have to keep guessing what happened when I forgot what the
   // codes meant! :)
   SpeakSync("Got Response");
   SpeakSync(gResponse);
}
PostSun Oct 07, 2007 6:57 pm
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Lavish Software Forum Index -> GamingTools Public::EQWatcher Evolution All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



Powered by phpBB © 2002 phpBB Group