-----

function Lobby.run()
	_joinEvent = Util.newRemoteEvent("JoinEvent", ReplicatedStorage)
	_serverListEvent = Util.newRemoteEvent("ServerListEvent", ReplicatedStorage)
	_statusEvent = Util.newRemoteEvent("StatusEvent", ReplicatedStorage)

	MessagingService:SubscribeAsync("LOBBY", Lobby._dispatchMessage)
	MessagingService:SubscribeAsync(tostring(game.JobId), Lobby._dispatchMessage)

	Lobby._registerHandler("ANNOUNCE", Lobby._handleServerAnnounce)
	Lobby._registerHandler("ANNOUNCE:REMOVAL", Lobby._handleServerRemoval)
	Lobby._registerHandler("ANNOUNCE:RESPONSE", Lobby._handleServerAnnounce)
	Lobby._registerHandler("JOIN:RESPONSE", Lobby._handleJoinResponse)
	Lobby._registerHandler("JOIN:EXPIRED", Lobby._handleJoinExpired)

	Log.Debug.Lobby("run: %s (%s)", game.JobId, game.PlaceId)

	Lobby._requestServerList()

	_joinEvent.OnServerEvent:Connect(Lobby._onJoin)

	Players.PlayerAdded:Connect(Lobby._onPlayerAdded)
	Players.PlayerRemoving:Connect(Lobby._onPlayerRemoving)

	TeleportService.TeleportInitFailed:Connect(Lobby._onTeleportFailure)

	coroutine.wrap(function()
			while true do
				Lobby._detectDeadServers()
				Lobby._processJoinQueue()
				wait(1)
			end
	end)()
end
