Page 1 of 1

Making a Protocol Handler for BZ2

Posted: Tue Oct 23, 2012 11:08 am
by Zero Angel
So i've started on a little project to create something called a 'Protocol Handler' which is designed to launch BZ2 and direct connect to an IP when a special link is clicked on (e.g.: bz2game://ip.add.re.ss )

My InnoSetup contains the following registry code:

Code: Select all

Root: HKCR; Subkey: bz2game; ValueType: string; ValueData: "URL:Battlezone 2"; Components: protocolhandler; 
Root: HKCR; Subkey: bz2game; ValueType: string; ValueName: URL Protocol; Components: protocolhandler; 
Root: HKCR; Subkey: bz2game\DefaultIcon; ValueType: string; ValueData: {app}\bzone.exe,0; Components: protocolhandler; 
Root: HKCR; Subkey: bz2game\shell\open\command; ValueType: string; ValueData: """{app}\bzone.exe"" -nointro +connect ""%1"" +name {code:GetBZ2Name}"; Components: protocolhandler; 
Basically it works, sort of. When the special link is entered into the browser, BZ2 does indeed launch -- however I get an error saying that the game cannot find or execute bzone.cfg. This will typically happen if bzone.exe is launched from a different 'working directory' than the bz2 root directory itself -- in this case the working directory seems to be the user's desktop.

So I'd like to know if anyone has any ideas regarding BZ2 to launch using the correct folder when this method is employed.

Re: Making a Protocol Handler for BZ2

Posted: Tue Oct 23, 2012 2:25 pm
by Red Spot
Have it create a shortcut to desktop and launch it from there, possibly cleaning up the shortcut after its done, or at least have it check for an existing one before it makes a new one.

Re: Making a Protocol Handler for BZ2

Posted: Wed Oct 24, 2012 12:30 am
by Zero Angel
From what I understand, the protocol handler in hkey_classes_root cannot launch shortcuts directly. I've tried pointing it directly at a shortcut as well as using a string like "C:\Users\David\Desktop\Battlezone II.lnk" +connect "%1" +name Zero_Angel as well as cmd /c "C:\Users\David\Desktop\Battlezone II.lnk" +connect "%1" +name Zero_Angel. In cases where they would work from the run command dialog, they will return an error that bz2game is not a valid win32 application when used with the bz2game protocol handler.

Re: Making a Protocol Handler for BZ2

Posted: Wed Oct 24, 2012 12:55 am
by Nielk1
Using this, a web based game list could allow direct launches of BZ2 to join said games.

Re: Making a Protocol Handler for BZ2

Posted: Wed Oct 24, 2012 1:43 am
by Zero Angel
Exactly.

Re: Making a Protocol Handler for BZ2

Posted: Wed Oct 24, 2012 7:15 pm
by Cyber
Good idea. Very good.

Re: Making a Protocol Handler for BZ2

Posted: Sat Nov 03, 2012 5:41 am
by Zero Angel
So i've been messing around with making the protocol handler work with TnT's mod selector tool using the following settings (for testing)

Please note that the double backslashes and backslash quotes are part of the .reg file format and are not present in the actual registry entries.

Code: Select all

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\bz2game]
@="URL:Battlezone 2"
"URL Protocol"=""

[HKEY_CLASSES_ROOT\bz2game\DefaultIcon]
@="D:\\Program Files (x86)\\Battlezone2\\bzone.exe,0"

[HKEY_CLASSES_ROOT\bz2game\shell]

[HKEY_CLASSES_ROOT\bz2game\shell\open]

[HKEY_CLASSES_ROOT\bz2game\shell\open\command]
@="\"C:\\Users\\david\\Downloads\\GRBZ2 Selector\\GRBZ2 Selector\\bzone.exe\" -nointro +connect %1 +name testguy"
So when I enter bz2game://222.222.222.222 in the browser, this is the result:

Code: Select all

Enter:   0 to Exit Program
Enter:   1 to launch: Normal BZ2

Select Mod Number:  1

launching D:\Program Files (x86)\Battlezone2\bzone.exe
with arguments: -nointro +connect bz2game://222.222.222.222/ +name testguy  -config bzone.cfg


Press any key to continue . . .
BZ2 launches properly, however does not establish a connection properly.

Now, does anyone know of a way, using the registry, to strip out everything but the IP address from the command line arguments that are passed to the bz2 launcher?

Re: Making a Protocol Handler for BZ2

Posted: Sat Nov 03, 2012 1:26 pm
by General BlackDragon
Did u try 222.222.222.222:17770?

Re: Making a Protocol Handler for BZ2

Posted: Sat Nov 03, 2012 1:34 pm
by Ded10c
General BlackDragon wrote:Did u try 222.222.222.222:17770?
Just a guess, but I think he means that the problem is that bz2game:// gets passed as a part of the argument rather than just the IP.

Re: Making a Protocol Handler for BZ2

Posted: Sun Nov 04, 2012 3:56 am
by TnT
ZA,

If I understand your goal correctly, you wish to have a webpage that lists possible hosts as links. A player would click the link and BZ should then launch using the given IP address. Based on this understanding, I have made a quick change to my Mod List program to incorporate a webbrowser that intercepts navigation to "bz2game://" and pulls the IP info from the link. The user can then choose to launch. I added a button to host as well that tells BZ to host using port 17770. There is also a checkbox to allow for for appending 17770 to the IP address.

You can download this at: http://sdrv.ms/SF3iFx

This version has two tabs, one to define the mods to run and the second is a browser control. The browser starts out on google (I don't like large blank screens). There is a button labeled "Load Bogus Webpage" click on that to bring up the links. This webpage is internal to the program. If you want to test it with addresses relevant to you, just create a webpage on your computer and put the full file path in the textbox and hit go.

If this of possible use to get people playing again, I am more than willing to clean this up for release.

Re: Making a Protocol Handler for BZ2

Posted: Sun Nov 04, 2012 7:58 am
by Zero Angel
Would you be able to get your program to properly detect if bz2game://ip.add.re.ss is passed to it and then strip out the bz2game:// portion that is forwarded to the real bzone.exe ?