Code archives/Networking/Application protocol

This code has been declared by its author to be Public Domain code.

Download source code

Application protocol by Andres2005
If you have installed a game named Soldat and choose a server from this list -> http://lobby.soldat.pl:13073/ you will be automatically connected to it.

And here's an example how you can do this your own:
For this you need to add some registry entries. I made a function to help you on that. After you have created the reg file you'll need to execute it. After the registry file has been executed you'll be able to easily, by clickin on a link, connect to the server or it can be used on some other purposes.

registryfile$ - Reg file to be created
name$ - name of your protocol (example: My protocol)
protocol$ - protocol name in the url (example: mypro://server:port/)
executable$ - file to be executed when clicked on the protocol link

With link "mypro://server:port/" will CommandLine$() = "/join mypro://server:port/"
You can change "/join" from the function by yourself if you wish to use the feature for other purposes.
%1 will be automatically replaced with link location(in this case with "mypro://server:port/").

EDIT: to execute the reg file you need to use function with that parameter ->CreateProcess("REG IMPORT " + registryfile$)
Function CreateProtocolRegistryFile(registryfile$, name$, protocol$, executable$)
	wf = WriteFile(registryfile$)
	If wf
		While Instr(executable$, "\", i)
			i = Instr(executable$, "\", i)
			executable$ = Mid$(executable$, 1, i) + "\" + Mid$(executable$, i + 1)
			i = i + 2
		Wend
		
		WriteLine wf, "Windows Registry Editor Version 5.00"
		WriteLine wf, ""
		WriteLine wf, "[HKEY_CLASSES_ROOT\" + protocol$ + "]"
		WriteLine wf, "@=" + Chr(34) + "URL:" + name$ + Chr(34)
		WriteLine wf, Chr(34) + "URL Protocol" + Chr(34) + "=" + Chr(34) + Chr(34)
		WriteLine wf, ""
		WriteLine wf, "[HKEY_CLASSES_ROOT\" + protocol$ + "\DefaultIcon]"
		WriteLine wf, "@=" + Chr(34) + "\" + Chr(34) + executable$ + "\" + Chr(34) + Chr(34)
		WriteLine wf, "[HKEY_CLASSES_ROOT\" + protocol$ + "\shell]"
		WriteLine wf, "[HKEY_CLASSES_ROOT\" + protocol$ + "\shell\open]"
		WriteLine wf, "[HKEY_CLASSES_ROOT\" + protocol$ + "\shell\open\command]"
		WriteLine wf, "@=" + Chr(34) + "\" + Chr(34) + executable$ + "\" + Chr(34) + " /join %1" + Chr(34)
		
		CloseFile wf
		Return True
	Else
		Return False
	EndIf
End Function

Comments

GC-Martijn2005
Looks nice, try it later.


Code Archives Forum