Game server list

BlitzMax Forums/BlitzMax Programming/Game server list

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Ultimately all this does is retrieve a list of server IPs. Therefore it can be completely separate from whatever networking code you might use. My goal is to make a module that only adds, removes, refreshes, and retrieves a list of servers. Then it can be used with whatever networking system you want.

This all works, but it opens a new stream each time an action is performed. This can take hundreds of milliseconds. Does anyone know how I can write to and from the stream to send new messages? I looked at BlitzHTTPGet but if I use more than one Get command it crashes:

If http.Open("www.google.com") 
	'POST Example
	Print http.Post("/search", ["hl", "q", "btnG"] , ["en", "fantasaar", "Google Search"] )
	Print http.Post("/search", ["hl", "q", "btnG"] , ["en", "fantasaar", "Google Search"] ) 
End If
http.Close()


If it takes 300 millisecs to refresh the server every minute, that is not usable.

SuperStrict

'=========================================
'test
Local s$
Local servers$[]
Local server:TPubServer

server=TPubServer.Create("http::www.leadwerks.com/gameservers/game1.php","My_Server","My_Game")
servers=TPubServer.list("http::www.leadwerks.com/gameservers/game1.php","My_Game")
If servers
	For s=EachIn servers
		Print s
	Next
EndIf

'=========================================


Type TPubServer
	
	Field url$
	Field stream:TStream
	
	Method Delete()
		Remove()
	EndMethod

	Function Create:TPubServer(url$,servername$,gamename$="")
		Local stream:TStream
		Local server:TPubServer
		server=New TPubServer
		server.url=url
		server.stream=OpenStream(url+"?action=addserver&gamename="+gamename+"&servername="+servername)
		If Not server.stream Return Null
		While Not server.stream.Eof()
			If ReadLine(server.stream).Trim()
				server.stream.close()
				Return Null
			EndIf
		Wend
		Return server	
	EndFunction

	Method Refresh:Int()
		stream=OpenStream(url+"?action=refreshserver")
		If Not stream Return False
		stream.close()
		Return True	
	EndMethod
	
	Method Remove:Int()
		stream=OpenStream(url+"?action=removeserver")
		stream.close()
		stream=Null
		Return True	
	EndMethod

	Function List:String[](url$,gamename$="")
		Local descarray:String[]
		Local list:TList
		Local stream:TStream
		Local s$,sarr$[],n:Int
		stream=OpenStream(url+"?action=listservers&gamename="+gamename)
		If Not stream Return Null
		list=New TList
		While Not stream.Eof()
			s=ReadLine(stream)
			If s.contains("|")
				list.addfirst(s)
			EndIf
		Wend
		stream.close()
		If list.IsEmpty() Return Null
		descarray=New String[list.count()]
		For s=EachIn list
			descarray[n]=s
			n:+1
		Next
		Return descarray
	EndFunction
	
EndType