This code adds a server to a central list of available servers. The program must refresh itself on the server or it will be automatically removed after five minutes.
First I tried opening a stream each time I needed to refresh. This causes a delay as the stream is opened. I want to be able to just leave the stream open and write a line to make it refresh every four minutes or so. How can I do this?:
SuperStrict
Import brl.stream
Import brl.socket
Import brl.httpstream
Type TServer
'Field url:String
Field stream:TStream
Method Delete()
If stream
stream.WriteLine("?action=removeserver")
stream.close()
EndIf
'Local stream:TStream
'If url
'stream=OpenStream(url+"?action=removeserver")
'If stream stream.close()
'EndIf
EndMethod
Method Refresh:Int()
'Local stream:TStream
'stream=OpenStream(url+"?action=refreshserver")
'If Not stream Return False
'stream.close()
stream.WriteLine("?action=refreshserver")
Return True
EndMethod
Function Create:TServer(url:String,name$="",game$="")
Local server:TServer=New TServer
'server.url=url
server.stream=OpenStream(url+"?action=addserver&gamename="+game+"&servername="+name)
If Not server.stream Return Null
While Not server.stream.Eof()
If server.stream.ReadLine().Trim()
server.stream.close()
Return Null
EndIf
Wend
Return server
EndFunction
Function Request:String[](url:String,game:String="")
Local stream:TStream
Local s$,sarr$[],n:Int
stream=OpenStream(url+"?action=listservers&gamename="+game)
If Not stream Return Null
While Not stream.Eof()
s=ReadLine(stream)
If s.Trim().length>0
sarr=sarr[..sarr.length+1]
sarr[sarr.length-1]=s
EndIf
Wend
stream.close()
Return sarr
EndFunction
EndType
Rem
bbdoc:Requests a list of available servers
EndRem
Function RequestServers:String[](url:String,game:String="")
Return TServer.Request(url,game)
EndFunction
|