logo
Main

Forums

Downloads

Unreal-Netiquette

Donate for Oldunreal:
Donate

borderline

Links to our wiki:
Wiki

Walkthrough

Links

Tutorials

Unreal Reference

Usermaps

borderline

Contact us:
Submit News
Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Adding https:// support and proper replacements for <> in game console (Read 794 times)
Masterkent
Developer Team
Offline



Posts: 792
Location: Russia
Joined: Apr 5th, 2013
Gender: Male
Adding https:// support and proper replacements for <> in game console
Jan 12th, 2016 at 10:03pm
Print Post  
Players often share URLs via game chat. We can open a hyperlink by clicking on its area in the console. Unfortunately, URLs that begin with https:// are not clickable (in contrast to http://). I think, there is no reason to keep this limitation.

You could also notice that characters < and > are replaced with ( and ) when drawed in console. I found such a behavior odd and unnecessary. To prevent parsing < and > as parts of HTML tags, it's enough to replace such characters with &lt; and &gt;

Suggested resolution:

- in UWindow/UWindowConsoleTextAreaControl.uc define function AddText as follows:

Code
Select All
function UWindowDynamicTextRow AddText(string NewLine, optional color TxtCol )
{
	local int i, j;
	local UWindowHTMLTextRow L;
	local HTMLStyle CurrentStyle;
	local string Prefix, LowNewLine;

	CurrentStyle.BulletLevel = 0;
	CurrentStyle.LinkDestination = "";
	if( TxtCol.R==0 && TxtCol.G==0 && TxtCol.B==0 )
		CurrentStyle.TextColor = TextColor;
	else CurrentStyle.TextColor = TxtCol;

	// Replace <>
	NewLine = ReplaceStr(NewLine, "<", "&lt;");
	NewLine = ReplaceStr(NewLine, ">", "&gt;");

	// Add links
	while (Len(NewLine) > 0)
	{
		LowNewLine = Locs(NewLine);
		i = InStr(LowNewLine, "http");
		j = InStr(LowNewLine, "www.");

		if (i >= 0 && (j < 0 || i < j)) // parse "http"
		{
			if (Mid(LowNewLine, i, 7) == "http://" || Mid(LowNewLine, i, 8) == "https://")
			{
				if (i > 0 || Len(Prefix) > 0)
				{
					L = UWindowHTMLTextRow(Super(UWindowDynamicTextArea).AddText(Prefix $ Left(NewLine, i)));
					L.StartStyle = CurrentStyle;
					L.StartStyle.bNoBR = true;
				}
				NewLine = Mid(NewLine, i);
				Prefix = "";
				i = InStr(NewLine, " ");
				if (i >= 0)
				{
					L = UWindowHTMLTextRow(Super(UWindowDynamicTextArea).AddText(Left(NewLine, i)));
					L.StartStyle = CurrentStyle;
					L.StartStyle.LinkDestination = L.Text;
					NewLine = Mid(NewLine, i + 1);
				}
				else
				{
					L = UWindowHTMLTextRow(Super(UWindowDynamicTextArea).AddText(NewLine));
					L.StartStyle = CurrentStyle;
					L.StartStyle.LinkDestination = NewLine;
					NewLine = "";
				}
			}
			else
			{
				// skip "http"
				Prefix $= Left(NewLine, i + 3);
				NewLine = Mid(NewLine, i + 3);
				continue;
			}
		}
		else if (j >= 0) // parse "www."
		{
			if (j > 0 && Mid(NewLine, j - 1, 1) != " ")
			{
				Prefix $= Left(NewLine, j + 3);
				NewLine = Mid(NewLine, j + 3);
				continue;
			}
			if (j > 0 || Len(Prefix) > 0)
			{
				L = UWindowHTMLTextRow(Super(UWindowDynamicTextArea).AddText(Prefix $ Left(NewLine, j)));
				L.StartStyle = CurrentStyle;
				L.StartStyle.bNoBR = true;
			}
			NewLine = Mid(NewLine, j);
			Prefix = "";
			i = InStr(NewLine, " ");
			if (i >= 0)
			{
				L = UWindowHTMLTextRow(Super(UWindowDynamicTextArea).AddText("http://" $ Left(NewLine, i)));
				L.StartStyle = CurrentStyle;
				L.StartStyle.LinkDestination = L.Text;
				NewLine = Mid(NewLine, i + 1);
			}
			else
			{
				L = UWindowHTMLTextRow(Super(UWindowDynamicTextArea).AddText("http://" $ NewLine));
				L.StartStyle = CurrentStyle;
				L.StartStyle.LinkDestination = L.Text;
				NewLine = "";
			}
		}
		else
			break;
		L.StartStyle.bLink = true;
		L.StartStyle.bNoBR = true;
	}

	NewLine = Prefix $ NewLine;

	// End line.
	if( Len(NewLine)>0 )
	{
		L = UWindowHTMLTextRow(Super(UWindowDynamicTextArea).AddText(NewLine));
		L.StartStyle = CurrentStyle;
	}
	return L;
} 


- in UWindow/UWindowHTMLTextArea.uc modify function ProcessURL as follows:

Code
Select All
....
	if ( Left(URL, 7) ~= "http://" )
		GetPlayerOwner().ConsoleCommand("start "$URL);
	if ( Left(URL, 8) ~= "https://" )
		GetPlayerOwner().ConsoleCommand("start "$URL);
.... 


UWindow/UWindowConsoleTextAreaControl.uc
UWindow/UWindowHTMLTextArea.uc

Implementation note: the suggested modification should guarantee that multiple URLs of any of the following forms are drawed correctly:

    http://ref
    https://ref
    www.ref

The original implementation ignores upper-case forms HTTP:// WWW.
The suggested implementation parses URLs in a case-insensitive manner.

If you see any potential problems with the new parser, please, share your thoughts.
  
Back to top
 
IP Logged
 
BobIsUnreal
God Member
*****
Offline


Guy who has too much time
invested to quit now

Posts: 717
Joined: Apr 12th, 2010
Gender: Male
Re: Adding https:// support and proper replacements for <> in game console
Reply #1 - Jan 12th, 2016 at 11:44pm
Print Post  
While not the 'correct' answer, you can simply caught the   "www." !="https;//" replace https: with "http;//" using a chat gamerule,
as well as supporting upperlowercases by replment,
and yes - requesting every https website as http is generally undesirable, but the solution works regaurdless of core changes.

also not having working <> chars is annoying for cosmetic reasons ,  something i was working on yesterday , ran into both of these issues at one time, so yeah fix em both properly.
  

[REM_img]http://i.imgur.com/V3OSsDu.gif.disable[/img]http://i.imgur.com/JOu38Gs.gif
Back to top
IP Logged
 
Smirftsch
Forum Administrator
*****
Offline



Posts: 7359
Location: at home
Joined: Apr 30th, 1998
Gender: Male
Re: Adding https:// support and proper replacements for <> in game console
Reply #2 - Jan 14th, 2016 at 7:05am
Print Post  
nice fix. No objections from my side building it in. While talking about script fixes, could I beg you checking what's the trouble with the 4 teams scoreboard is? Smiley
  

Sometimes you have to lose a fight to win the war.
Back to top
WWWICQ  
IP Logged
 
Masterkent
Developer Team
Offline



Posts: 792
Location: Russia
Joined: Apr 5th, 2013
Gender: Male
Re: Adding https:// support and proper replacements for <> in game console
Reply #3 - Jan 14th, 2016 at 10:25am
Print Post  
Smirftsch wrote on Jan 14th, 2016 at 7:05am:
While talking about script fixes, could I beg you checking what's the trouble with the 4 teams scoreboard is? Smiley

In short, the troubles are caused by using bad offsets.
Fix: UnrealShare/UnrealTeamScoreBoard.uc
  
Back to top
 
IP Logged
 
Smirftsch
Forum Administrator
*****
Offline



Posts: 7359
Location: at home
Joined: Apr 30th, 1998
Gender: Male
Re: Adding https:// support and proper replacements for <> in game console
Reply #4 - Jan 14th, 2016 at 11:58am
Print Post  
very cool. Thanks!
  

Sometimes you have to lose a fight to win the war.
Back to top
WWWICQ  
IP Logged
 
Masterkent
Developer Team
Offline



Posts: 792
Location: Russia
Joined: Apr 5th, 2013
Gender: Male
Re: Adding https:// support and proper replacements for <> in game console
Reply #5 - Jun 27th, 2016 at 10:31am
Print Post  
Version with other parser that supports more types of hyperlinks:
http://pastebin.com/d5QsEnNm

Supported prefixes:
mailto: (new)
http://
https://
ftp:// (new)
www.
ftp. (new)
unreal:// (new)

This parser uses new string function StartsWith and requires a modified implementation of

Code
Select All
native(126) static final function int    InStr  ( coerce string S, coerce string t, optional int Start); 


returning either the actual position pos of the leftmost substring t in S such that pos >= Start [or pos >= Min(Start, Len(S))] or -1 if such a position does not exist.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint
Bookmarks: del.icio.us Digg Facebook Google Google+ Linked in reddit StumbleUpon Twitter Yahoo