Extend String TLO to parse links

A forum for feature requests/discussions and user submitted patches that improve MQ2

Moderator: MacroQuest Developers

dewey2461
Contributing Member
Contributing Member
Posts: 1759
Joined: Sun Apr 17, 2005 1:53 am

Extend String TLO to parse links

Post by dewey2461 » Fri May 10, 2019 11:00 pm

EQ now has active links in most of its text. It would be nice to have a way with in a macro to extract the link text.

String.LinkText[N] would return the TEXT portion of the Nth's link in the string.

For example a simple farming macro might detect when an item is left on corpse by advloot.

Event String:
-- You have decied to not loot 1 item(s): [Bloodstained Journal Vol.5]. The items(s) will be avialable to anyone after the corpse(s) unlock.--

The actual text for the link is hex 0x12, followed by 90 digits, followed by the text you can see and a matching 0x12.

To parse out the text of the link is painful because the link is coded with hidden character 0x12 that we have no way of passing in to the string Arg or Token methods.

The code to perform this function is fairly trivial but since it would need to be part of the string TLO it will take one of the Dev's to make it happen.

EqMule
Developer
Developer
Posts: 2697
Joined: Fri Jan 03, 2003 9:57 pm
Contact:

Re: Extend String TLO to parse links

Post by EqMule » Sat May 11, 2019 10:10 am

go for it
My status o/
If you like MQ2 and would like to contribute, please do. My goal is 25 donations per month.
So far I've received Image donations for this month's patches.

Bitcoin: 1Aq8ackjQ4f7AUvbUL7BE6oPfT8PmNP4Zq
Krono: PM me.
I can always use characters for testing, PM me if you can donate one.

dewey2461
Contributing Member
Contributing Member
Posts: 1759
Joined: Sun Apr 17, 2005 1:53 am

Re: Extend String TLO to parse links

Post by dewey2461 » Sun May 12, 2019 3:56 pm

See below
Last edited by dewey2461 on Sun May 12, 2019 6:42 pm, edited 1 time in total.

dewey2461
Contributing Member
Contributing Member
Posts: 1759
Joined: Sun Apr 17, 2005 1:53 am

Re: Extend String TLO to parse links

Post by dewey2461 » Sun May 12, 2019 6:40 pm

Tested it with the following macro snippet

Usage

Code: Select all

#event TEXT "You #*#"
#event TEXT "Your #*#"
#event TEXT "--You #*#"

Sub Event_TEXT(string line)
     /echo /mqlog LINE [${line}]
     /echo /mqlog LINK [${line.LinkText}]
/return
Went to Everfrost and cast some spells on mobs and got faction hits. Link some items etc.


Here is the TLO code

Code: Select all

	// Return the Text portion of the "Nth" link 
	// Item  Links : [0x12]0044BC000000000000000000000000000000000000000000000000000000000000000000000000000003B91A689Orbweaver Silk[0x12]
	// Spell Links : [0x12]63^6271^'Spirit of Vesagran[0x12]
	// Faction     : [0x12]3CHARNAME^100006100^0^1^1557697699^'Northern Felwithe Traveler[0x12]
	// Hyper Links :  Your faction standing with <a Faction = "1210">Discordant Army</a> has been adjusted by 2.
	// Achivements :  You have completed achievement : [0x12]3CHARNAME^100006100^0^1^1557697699^'Northern Felwithe Traveler[0x12]
	
	case LinkText:
	{
		Dest.Type = pStringType;
		Dest.Ptr = &DataTypeTemp[0];
		strcpy_s(DataTypeTemp, "");

		char *Src = (char *)VarPtr.Ptr;
		char *Des;
		int N = GETNUMBER();
		if (N == 0) N = 1;
		int LinkLen = 92;										// This is the size of the link data. Change it for EMU's
		int i;

		while (Src && Src[0])
		{
			if (Src[0] == 0x12)
			{	
				Src++;											// Found the marker for the start of a link - skip first 0x12
				for (i = 1; i < LinkLen; i++)					// Loop to eat up to LinkLen characters
				{												
					if (Src[0] == '^' && Src[1] == 39)			// Check to see if we have a ending token  "^'"
					{											// 
						i = LinkLen;							// If we do then we need to stop after eating ^'
						Src++;									// Eat one character and let next block eat 2nd
					} 
					if (Src[0] && Src[0] != 0x12) Src++;		// Eat the character
				}
				Des = (char *)&DataTypeTemp[0];
				while (Src[0] && Src[0] != 0x12)
				{												// Copy the text to destination
					*Des++ = *Src++;
				}
				if (Src[0] == 0x12) Src++;						// We should be at the end token - eat it. 
				Des[0] = 0;										// Teminate the output string
				N = N - 1;
				if (N == 0) return true;;						// If we've found the one we want get out
			}

			if (Src[0] == '<' && Src[1] == 'a')					// Start of a hyper link?
			{
				char *pEqual = strchr(Src, '=');				// There should be an equal
				char *pClose = strchr(Src, '>');				// and a closing > 
				char *pEnd = NULL;
				if (pEqual && pClose)						
					pEnd = strstr(pClose, "</a>");				// There should also be a closing </a>
				if (pClose && pEnd) {							// If we have everything then copy it to dest
					Des = (char *)&DataTypeTemp[0];
					Src = &pClose[1];								
					while (Src != pEnd && Src[0])
					{
						*Des++ = *Src++;
					}
					Src = &pEnd[3];								// Skip Src to last character of ending </a>
					Des[0] = 0;									// Terminate output string

					N = N - 1;
					if (N == 0) return true;					// If we've found the one we want get out
				}
			}

			if (Src[0] != 0) Src++;

		}

		strcpy_s(DataTypeTemp, "");								// Overwrite any links that didn't count
		return true;
	}


SwiftyMUSE
Developer
Developer
Posts: 1205
Joined: Tue Sep 23, 2003 10:52 pm

Re: Extend String TLO to parse links

Post by SwiftyMUSE » Mon May 13, 2019 12:20 pm

I don't remember where I have the list, but the first character after the first 0x12, tells you the type of link it is.

0 = Item Link
3 = Achievements Link

I'll try and find that list.
PayPal: Donate to SwiftyMUSE
Bitcoin: 1LuQ6YcEAWxF3fm9yWMiro4K582je7364V
Krono: PM me

dont_know_at_all wrote:Gee, if only there was a way to correctly report a crash...

dewey2461
Contributing Member
Contributing Member
Posts: 1759
Joined: Sun Apr 17, 2005 1:53 am

Re: Extend String TLO to parse links

Post by dewey2461 » Mon May 13, 2019 5:32 pm

SwiftyMUSE wrote:
Mon May 13, 2019 12:20 pm
I don't remember where I have the list, but the first character after the first 0x12, tells you the type of link it is.

0 = Item Link
3 = Achievements Link

I'll try and find that list.
I may not need a complete list if they are get decoded the same way. It seems Item links are a fixed size while other 0x12 links all use a series of numbers with ^ to indicate breaks with a ^` at the end.

I did briefly toy with the idea of trying to make the TLO do something more interesting like return the raw data but ... too much work.