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: Select all
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);
}