Code archives/Networking/GNet in BlitzMax

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

Download source code

GNet in BlitzMax by Chroma2009
Let's you use GNet in your BlitzMax program to show your server on the BlitzBasic.com BlitzNet page. This just gets your game up on there. Part 2 will be retrieving the list and connecting. To be continued...

Hope it's useful.
'GNet in BlitzMax

'Original Code by Mark Sibly

'Converted and condensed by Noel Cole (Chroma)

Global GNET_HOST$ = "www.blitzbasic.com"
Global GNET_HOSTIP% = HostIp(GNET_HOST)
Global GNET_PORT=80
Global GNET_GET$="/gnet/gnet.php"

'Example
Local MyGame$ = "This is My Game."
Local MyServer$ = "This is My Server."

GNET_AddServer(MyGame, MyServer)
'GNET_RefreshServer(mygame,"Refreshed")
'GNET_RemoveServer(mygame)

End

'=========================================
'-------------GNET Routines---------------
'=========================================
Function GNET_AddServer(game$, server$="")
	GNET_Exec("add", game, server)
End Function

Function GNET_RefreshServer(game$, server$="")
	GNET_Exec("ref", game, server)
End Function

Function GNET_RemoveServer(game$)
	GNET_Exec("rem", game, "")
End Function

Function GNET_Exec(opt$, game$, server$)
	Local conn:TSockStream = TSockStream.Create()
	ConnectSocket(conn.socket,GNET_HOSTIP,GNET_PORT)
	opt$=opt$+"&game="+Format(game$)
	If server$<>"" opt$=opt$+"&server="+Format(server$)
	WriteLine conn.stream, "GET "+GNET_GET$+"?opt="+opt$+" HTTP/1.0"
	WriteLine conn.stream, "HOST: " + GNET_HOST$
	WriteLine conn.stream, ""
	CloseSocket(conn.socket)
End Function

Type TSockStream
	Field socket:TSocket
	Field stream:TSocketStream
	Function Create:TSockStream(_port%=9050)
		Local ss:TSockStream = New TSockStream
		ss.socket = CreateTCPSocket()
		ss.stream = CreateSocketStream(ss.socket)
		BindSocket(ss.socket, _port)
		Return ss
	End Function
End Type

Function Format$( t$ )
	t$=Replace$( t$,"&","" )
	t$=Replace$( t$,"%","" )
	t$=Replace$( t$,"'","" )
	t$=Replace$( t$,Chr$(34),"" )
	t$=Replace$( t$," ","_" )
	Return t$
End Function
'-----------------------------------------
'=========================================

Comments

Ked2009
?

http://www.blitzbasic.com/codearcs/codearcs.php?code=1413


Chroma2009
Thanks for taking the time to post that there is a similar archive entry. If you look, there's a LOT of similar archive entries. Be sure to go post a link on all those too.


Ked2009
Just making sure you knew before you actually finished this. Also, thanks for the attitude.


Code Archives Forum