Jump to content
This Topic

Recommended Posts

Posted

I've spent the last few days creating a simple self contained server browser. It will list all the servers of a specific game, allow the user to select a server and send a callback with the selected info.

kqr55SK.gif

Requirements: 

The script from this topic placed in a file here: Scripts/Functions/eventqueuemanager.lua

The Script:

  Reveal hidden contents

A simple example:

It will create a server and open a server browser window. + Starts the move mode, click to exit it. X closes the window.

import("Scripts/Functions/eventqueuemanager.lua")
import("Scripts/serverbrowser.lua")
local window = Window:Create()
local context = Context:Create(window)
local server = Server:Create()
System:Print("Server1 publish::" .. tostring(server:Publish("Example Temp Test Server", "Testing population of server list from masterserver ")))
server:Release()

function test(ip,port,close) -- callback function
	System:Print("Callback")
	System:Print(ip)	
	System:Print(tostring((close == true) and "close" or ""))
end

local serverbrowser = serverBrowser("Example Temp Test Server",context,0,0) -- create the serverbrowser
serverbrowser:SetCallback(test) -- set callback

-- do stuff
while true do
	if window:Closed() then return end
	if window:KeyHit(Key.Escape) then return end	
	Time:Update()
	context:SetColor(0,0,0,0) -- need to clear alpha!! or the gui will stay on screen!!
	context:Clear()	
	EventQueueManager:Update()					
	context:Sync()
end
serverbrowser:ClearCallback() -- remove callback
serverbrowser:Release() -- release everything

The server browser will obey the limits of your window. If any part of it is not on screen, it will be pushed back onto it.

Edits:

-2017-8-24: -Added the ability to directly connect to a ip and port.
                    -Moved the code to put the window into a function and check on server browser creation.

-2017-8-25: -Added the abilitiy to automatically resize to fit inside the bounds of the current context

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...