Index: code/branches/presentation3/data/gui/scripts/MultiplayerMenu.lua
===================================================================
--- code/branches/presentation3/data/gui/scripts/MultiplayerMenu.lua	(revision 7129)
+++ code/branches/presentation3/data/gui/scripts/MultiplayerMenu.lua	(revision 7161)
@@ -4,6 +4,72 @@
 
 function P.onLoad()
-    listbox = winMgr:getWindow("orxonox/MultiplayerLevelListbox")
-    preselect = orxonox.LevelManager:getInstance():getDefaultLevel()
+    P.multiplayerMode = "startClient"
+end
+
+function P.onShow()
+    if P.multiplayerMode == "startClient" then
+        local window = winMgr:getWindow("orxonox/MultiplayerJoinButton")
+        local button = tolua.cast(window,"CEGUI::RadioButton")
+        button:setSelected(true)
+        P.showServerList()
+    end
+    if P.multiplayerMode == "startServer" then
+        local window = winMgr:getWindow("orxonox/MultiplayerHostButton")
+        local button = tolua.cast(window,"CEGUI::RadioButton")
+        button:setSelected(true)
+        P.showLevelList()
+    end
+    if P.multiplayerMode == "startDedicated" then
+        local window = winMgr:getWindow("orxonox/MultiplayerDedicatedButton")
+        local button = tolua.cast(window,"CEGUI::RadioButton")
+        button:setSelected(true)
+        P.showLevelList()
+    end
+end
+
+function P.MultiplayerJoinButton_clicked(e)
+    P.multiplayerMode = "startClient"
+    P.showServerList()
+end
+
+function P.MultiplayerHostButton_clicked(e)
+    P.multiplayerMode = "startServer"
+    P.showLevelList()
+end
+
+function P.MultiplayerDedicatedButton_clicked(e)
+    P.multiplayerMode = "startDedicated"
+    P.showLevelList()
+end
+
+function P.MultiplayerStartButton_clicked(e)
+    local choice = winMgr:getWindow("orxonox/MultiplayerListbox"):getFirstSelectedItem()
+    if P.multiplayerMode == "startClient" then
+        if choice then
+            local client = orxonox.Client:getInstance()
+            local index = tolua.cast(choice, "CEGUI::ListboxItem"):getID()
+            client:setDestination( P.serverList[index][2], 55556 )
+        else
+            return
+        end
+    else
+        if choice then
+            orxonox.LevelManager:getInstance():setDefaultLevel(choice:getText() .. ".oxw")
+        else
+            return
+        end
+    end
+    orxonox.execute(P.multiplayerMode)
+    hideAllMenuSheets()
+end
+
+function P.MultiplayerBackButton_clicked(e)
+    hideMenuSheet(P.name)
+end
+
+function P.showLevelList()
+    local listbox = winMgr:getWindow("orxonox/MultiplayerListbox")
+    CEGUI.toListbox(listbox):resetList()
+    local preselect = orxonox.LevelManager:getInstance():getDefaultLevel()
     orxonox.LevelManager:getInstance():compileAvailableLevelList()
     local levelList = {}
@@ -19,7 +85,10 @@
     end
     table.sort(levelList)
+    index = 1
     for k,v in pairs(levelList) do
-        item = CEGUI.createListboxTextItem(v)
+        local item = CEGUI.createListboxTextItem(v)
         item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
+        item:setID(index)
+        index = index + 1
         CEGUI.toListbox(listbox):addItem(item)
         if v .. ".oxw" == preselect then
@@ -27,45 +96,35 @@
         end
     end
-    local multiplayerMode = "startClient"
-    if multiplayerMode == "startClient" then
-        window = winMgr:getWindow("orxonox/MultiplayerJoinButton")
-        button = tolua.cast(window,"CEGUI::RadioButton")
-        button:setSelected(true)
     end
-    if multiplayerMode == "startServer" then
-        window = winMgr:getWindow("orxonox/MultiplayerHostButton")
-        button = tolua.cast(window,"CEGUI::RadioButton")
-        button:setSelected(true)
+    
+function P.showServerList()
+    local listbox = winMgr:getWindow("orxonox/MultiplayerListbox")
+    CEGUI.toListbox(listbox):resetList()
+    local discovery = orxonox.LANDiscovery:getInstance()
+    discovery:discover()
+    P.serverList = {}
+    local index = 0
+    local servername = ""
+    local serverip = ""
+    while true do
+        servername = discovery:getServerListItemName(index)
+        if servername == "" then
+            break
+        end
+        serverip = discovery:getServerListItemIP(index)
+        if serverip == "" then
+          break
+        end
+        table.insert(P.serverList, {servername, serverip})
+        index = index + 1
     end
-    if multiplayerMode == "startDedicated" then
-        window = winMgr:getWindow("orxonox/MultiplayerDedicatedButton")
-        button = tolua.cast(window,"CEGUI::RadioButton")
-        button:setSelected(true)
+    index = 1
+    for k,v in pairs(P.serverList) do
+        local item = CEGUI.createListboxTextItem( v[1] .. ": " .. v[2] )
+        item:setID(index)
+        index = index + 1
+        item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
+        CEGUI.toListbox(listbox):addItem(item)
     end
-end
-
-function P.MultiplayerJoinButton_clicked(e)
-    multiplayerMode = "startClient"
-end
-
-function P.MultiplayerHostButton_clicked(e)
-    multiplayerMode = "startServer"
-end
-
-function P.MultiplayerDedicatedButton_clicked(e)
-    multiplayerMode = "startDedicated"
-end
-
-function P.MultiplayerStartButton_clicked(e)
-    local choice = winMgr:getWindow("orxonox/MultiplayerLevelListbox"):getFirstSelectedItem()
-    if choice then
-        orxonox.LevelManager:getInstance():setDefaultLevel(choice:getText() .. ".oxw")
-        orxonox.execute(multiplayerMode)
-        hideAllMenuSheets()
-    end
-end
-
-function P.MultiplayerBackButton_clicked(e)
-    hideMenuSheet(P.name)
 end
 
