[Orxonox-commit 3107] r7801 - in code/trunk: . bin data/gui/layouts data/gui/schemes data/gui/scripts src/libraries/core src/libraries/network src/libraries/network/packet src/libraries/network/synchronisable src/libraries/util src/modules/objects src/modules/overlays/hud src/modules/pickup src/modules/weapons src/orxonox src/orxonox/controllers src/orxonox/gamestates src/orxonox/gametypes src/orxonox/infos src/orxonox/worldentities/pawns

dafrick at orxonox.net dafrick at orxonox.net
Wed Dec 22 19:24:25 CET 2010


Author: dafrick
Date: 2010-12-22 19:24:24 +0100 (Wed, 22 Dec 2010)
New Revision: 7801

Added:
   code/trunk/bin/masterserver.bat.in
   code/trunk/bin/masterserver.in
   code/trunk/data/gui/schemes/OrxonoxHUDWidgets.scheme
   code/trunk/data/gui/schemes/OrxonoxMenuWidgets.scheme
   code/trunk/src/libraries/network/MasterServer.cc
   code/trunk/src/libraries/network/MasterServer.h
   code/trunk/src/libraries/network/MasterServerComm.cc
   code/trunk/src/libraries/network/MasterServerComm.h
   code/trunk/src/libraries/network/MasterServerProtocol.h
   code/trunk/src/libraries/network/PeerList.cc
   code/trunk/src/libraries/network/PeerList.h
   code/trunk/src/libraries/network/ServerList.cc
   code/trunk/src/libraries/network/ServerList.h
   code/trunk/src/libraries/network/WANDiscoverable.cc
   code/trunk/src/libraries/network/WANDiscoverable.h
   code/trunk/src/libraries/network/WANDiscovery.cc
   code/trunk/src/libraries/network/WANDiscovery.h
   code/trunk/src/orxonox/gamestates/GSMasterServer.cc
   code/trunk/src/orxonox/gamestates/GSMasterServer.h
Removed:
   code/trunk/data/gui/schemes/OrxonoxLookHUDWidgets.scheme
   code/trunk/data/gui/schemes/OrxonoxLookMenuWidgets.scheme
Modified:
   code/trunk/
   code/trunk/bin/CMakeLists.txt
   code/trunk/data/gui/layouts/AudioMenu.layout
   code/trunk/data/gui/layouts/CreditsMenu.layout
   code/trunk/data/gui/layouts/GraphicsMenu.layout
   code/trunk/data/gui/layouts/InGameMenu.layout
   code/trunk/data/gui/layouts/MultiplayerMenu.layout
   code/trunk/data/gui/scripts/ChatBox-inputonly.lua
   code/trunk/data/gui/scripts/ChatBox.lua
   code/trunk/data/gui/scripts/GraphicsMenu.lua
   code/trunk/data/gui/scripts/InitialiseGUI.lua
   code/trunk/data/gui/scripts/MultiplayerMenu.lua
   code/trunk/src/libraries/core/GUIManager.cc
   code/trunk/src/libraries/core/GUIManager.h
   code/trunk/src/libraries/network/CMakeLists.txt
   code/trunk/src/libraries/network/Client.cc
   code/trunk/src/libraries/network/Client.h
   code/trunk/src/libraries/network/ClientConnection.cc
   code/trunk/src/libraries/network/ClientConnection.h
   code/trunk/src/libraries/network/ClientInformation.cc
   code/trunk/src/libraries/network/ClientInformation.h
   code/trunk/src/libraries/network/Connection.cc
   code/trunk/src/libraries/network/Connection.h
   code/trunk/src/libraries/network/FunctionCallManager.cc
   code/trunk/src/libraries/network/FunctionCallManager.h
   code/trunk/src/libraries/network/GamestateClient.cc
   code/trunk/src/libraries/network/GamestateClient.h
   code/trunk/src/libraries/network/GamestateHandler.cc
   code/trunk/src/libraries/network/GamestateHandler.h
   code/trunk/src/libraries/network/GamestateManager.cc
   code/trunk/src/libraries/network/GamestateManager.h
   code/trunk/src/libraries/network/Host.cc
   code/trunk/src/libraries/network/Host.h
   code/trunk/src/libraries/network/LANDiscoverable.cc
   code/trunk/src/libraries/network/NetworkPrereqs.h
   code/trunk/src/libraries/network/Server.cc
   code/trunk/src/libraries/network/Server.h
   code/trunk/src/libraries/network/ServerConnection.cc
   code/trunk/src/libraries/network/ServerConnection.h
   code/trunk/src/libraries/network/packet/Acknowledgement.cc
   code/trunk/src/libraries/network/packet/Acknowledgement.h
   code/trunk/src/libraries/network/packet/Chat.cc
   code/trunk/src/libraries/network/packet/Chat.h
   code/trunk/src/libraries/network/packet/ClassID.cc
   code/trunk/src/libraries/network/packet/ClassID.h
   code/trunk/src/libraries/network/packet/DeleteObjects.cc
   code/trunk/src/libraries/network/packet/DeleteObjects.h
   code/trunk/src/libraries/network/packet/FunctionCalls.cc
   code/trunk/src/libraries/network/packet/FunctionCalls.h
   code/trunk/src/libraries/network/packet/FunctionIDs.cc
   code/trunk/src/libraries/network/packet/FunctionIDs.h
   code/trunk/src/libraries/network/packet/Gamestate.cc
   code/trunk/src/libraries/network/packet/Gamestate.h
   code/trunk/src/libraries/network/packet/Packet.cc
   code/trunk/src/libraries/network/packet/Packet.h
   code/trunk/src/libraries/network/packet/ServerInformation.cc
   code/trunk/src/libraries/network/packet/ServerInformation.h
   code/trunk/src/libraries/network/packet/Welcome.cc
   code/trunk/src/libraries/network/packet/Welcome.h
   code/trunk/src/libraries/network/synchronisable/Synchronisable.cc
   code/trunk/src/libraries/network/synchronisable/Synchronisable.h
   code/trunk/src/libraries/util/SignalHandler.cc
   code/trunk/src/modules/objects/ForceField.cc
   code/trunk/src/modules/objects/ForceField.h
   code/trunk/src/modules/overlays/hud/HUDBar.cc
   code/trunk/src/modules/overlays/hud/HUDNavigation.cc
   code/trunk/src/modules/pickup/PickupManager.cc
   code/trunk/src/modules/pickup/PickupSpawner.cc
   code/trunk/src/modules/weapons/MuzzleFlash.cc
   code/trunk/src/orxonox/LevelManager.cc
   code/trunk/src/orxonox/Main.cc
   code/trunk/src/orxonox/controllers/ArtificialController.cc
   code/trunk/src/orxonox/controllers/NewHumanController.cc
   code/trunk/src/orxonox/gamestates/CMakeLists.txt
   code/trunk/src/orxonox/gamestates/GSServer.cc
   code/trunk/src/orxonox/gametypes/Gametype.cc
   code/trunk/src/orxonox/gametypes/Gametype.h
   code/trunk/src/orxonox/infos/Bot.cc
   code/trunk/src/orxonox/worldentities/pawns/SpaceShip.cc
   code/trunk/src/orxonox/worldentities/pawns/SpaceShip.h
Log:
Merging presentation2 branch back to trunk.



Property changes on: code/trunk
___________________________________________________________________
Modified: svn:mergeinfo
   - /code/branches/ai:6592-7033
/code/branches/buildsystem:1874-2276,2278-2400
/code/branches/buildsystem2:2506-2658
/code/branches/buildsystem3:2662-2708
/code/branches/ceguilua:1802-1808
/code/branches/chat:6527-6797
/code/branches/chat2:6836-6910
/code/branches/console:5941-6104
/code/branches/consolecommands2:6451-7178
/code/branches/consolecommands3:7178-7283
/code/branches/core3:1572-1739
/code/branches/core4:3221-3224,3227,3234-3238,3242,3244-3250,3252-3254,3256,3259-3261,3264-3265,3268-3275,3277-3278,3280,3284-3285,3287,3289-3294,3305,3309-3310
/code/branches/core5:5768-5928,6009
/code/branches/data_cleanup:7537-7686
/code/branches/doc:7290-7400
/code/branches/dynamicmatch:6584-7030
/code/branches/fps:6591-7072
/code/branches/gamestate:6430-6572,6621-6661
/code/branches/gamestates2:6594-6745
/code/branches/gametypes:2826-3031
/code/branches/gcc43:1580
/code/branches/gui:1635-1723,2795-2894
/code/branches/hudelements:6584-6941
/code/branches/ingamemenu:6000-6023
/code/branches/input:1629-1636
/code/branches/ipv6:7293-7458
/code/branches/lastmanstanding:7479-7644
/code/branches/libraries:5612-5692
/code/branches/libraries2:5703-5737
/code/branches/lod:6586-6911
/code/branches/lodfinal:2372-2411
/code/branches/map:2801-3086,3089
/code/branches/menu:5941-6146,6148,7536-7687
/code/branches/miniprojects:2754-2824
/code/branches/netp2:2835-2988
/code/branches/netp3:2988-3082
/code/branches/netp6:3214-3302
/code/branches/network:2356
/code/branches/network2:6434-6465
/code/branches/network64:2210-2355
/code/branches/notifications:7314-7401
/code/branches/objecthierarchy:1911-2085,2100,2110-2169
/code/branches/objecthierarchy2:2171-2479
/code/branches/overlay:2117-2385
/code/branches/particles:2829-3085
/code/branches/particles2:6050-6106,6109
/code/branches/pch:3113-3194
/code/branches/physics:1912-2055,2107-2439
/code/branches/physics_merge:2436-2457
/code/branches/pickup2:5942-6405
/code/branches/pickup3:6418-6523
/code/branches/pickup4:6594-6710
/code/branches/pickups:1926-2086,2127,2827-2915
/code/branches/pickups2:2107-2497,2915-3071
/code/branches/png2:7262-7263
/code/branches/ppspickups1:6552-6708
/code/branches/ppspickups2:6527-6532,6554-6709
/code/branches/ppspickups3:6757-6997
/code/branches/ppspickups4:7003-7089
/code/branches/presentation:2369-2652,2654-2660
/code/branches/presentation2:6106-6416
/code/branches/presentation3:6913-7162
/code/branches/questsystem:1894-2088
/code/branches/questsystem2:2107-2259
/code/branches/questsystem5:2776-2905
/code/branches/releasetodo:7614-7647
/code/branches/resource:3327-3366
/code/branches/resource2:3372-5694
/code/branches/rocket:6523-6950
/code/branches/rocket2:6953-6970
/code/branches/script_trigger:1295-1953,1955
/code/branches/skybox2:6559-6989
/code/branches/sound:2829-3010
/code/branches/sound3:5941-6102
/code/branches/steering:5949-6091
/code/branches/weapon:1925-2094
/code/branches/weapon2:2107-2488
/code/branches/weapons:2897-3051
/code/branches/weaponsystem:2742-2890
   + /code/branches/ai:6592-7033
/code/branches/buildsystem:1874-2276,2278-2400
/code/branches/buildsystem2:2506-2658
/code/branches/buildsystem3:2662-2708
/code/branches/ceguilua:1802-1808
/code/branches/chat:6527-6797
/code/branches/chat2:6836-6910
/code/branches/console:5941-6104
/code/branches/consolecommands2:6451-7178
/code/branches/consolecommands3:7178-7283
/code/branches/core3:1572-1739
/code/branches/core4:3221-3224,3227,3234-3238,3242,3244-3250,3252-3254,3256,3259-3261,3264-3265,3268-3275,3277-3278,3280,3284-3285,3287,3289-3294,3305,3309-3310
/code/branches/core5:5768-5928,6009
/code/branches/data_cleanup:7537-7686
/code/branches/doc:7290-7400
/code/branches/dynamicmatch:6584-7030
/code/branches/fps:6591-7072
/code/branches/gamestate:6430-6572,6621-6661
/code/branches/gamestates2:6594-6745
/code/branches/gametypes:2826-3031
/code/branches/gcc43:1580
/code/branches/gui:1635-1723,2795-2894
/code/branches/hudelements:6584-6941
/code/branches/ingamemenu:6000-6023
/code/branches/input:1629-1636
/code/branches/ipv6:7293-7458
/code/branches/lastmanstanding:7479-7644
/code/branches/libraries:5612-5692
/code/branches/libraries2:5703-5737
/code/branches/lod:6586-6911
/code/branches/lodfinal:2372-2411
/code/branches/map:2801-3086,3089
/code/branches/masterserver:7502-7738
/code/branches/menu:5941-6146,6148,7536-7687
/code/branches/miniprojects:2754-2824
/code/branches/netp2:2835-2988
/code/branches/netp3:2988-3082
/code/branches/netp6:3214-3302
/code/branches/network:2356
/code/branches/network2:6434-6465
/code/branches/network3:7196-7344
/code/branches/network4:7497-7755
/code/branches/network5:7757-7781
/code/branches/network64:2210-2355
/code/branches/notifications:7314-7401
/code/branches/objecthierarchy:1911-2085,2100,2110-2169
/code/branches/objecthierarchy2:2171-2479
/code/branches/overlay:2117-2385
/code/branches/particles:2829-3085
/code/branches/particles2:6050-6106,6109
/code/branches/pch:3113-3194
/code/branches/physics:1912-2055,2107-2439
/code/branches/physics_merge:2436-2457
/code/branches/pickup2:5942-6405
/code/branches/pickup3:6418-6523
/code/branches/pickup4:6594-6710
/code/branches/pickups:1926-2086,2127,2827-2915
/code/branches/pickups2:2107-2497,2915-3071
/code/branches/png2:7262-7263
/code/branches/ppspickups1:6552-6708
/code/branches/ppspickups2:6527-6532,6554-6709
/code/branches/ppspickups3:6757-6997
/code/branches/ppspickups4:7003-7089
/code/branches/presentation:2369-2652,2654-2660,7736-7786
/code/branches/presentation2:6106-6416,7787-7800
/code/branches/presentation3:6913-7162
/code/branches/questsystem:1894-2088
/code/branches/questsystem2:2107-2259
/code/branches/questsystem5:2776-2905
/code/branches/releasetodo:7614-7647
/code/branches/resource:3327-3366
/code/branches/resource2:3372-5694
/code/branches/rocket:6523-6950
/code/branches/rocket2:6953-6970
/code/branches/script_trigger:1295-1953,1955
/code/branches/skybox2:6559-6989
/code/branches/sound:2829-3010
/code/branches/sound3:5941-6102
/code/branches/steering:5949-6091
/code/branches/weapon:1925-2094
/code/branches/weapon2:2107-2488
/code/branches/weapons:2897-3051
/code/branches/weaponsystem:2742-2890

Modified: code/trunk/bin/CMakeLists.txt
===================================================================
--- code/trunk/bin/CMakeLists.txt	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/bin/CMakeLists.txt	2010-12-22 18:24:24 UTC (rev 7801)
@@ -25,7 +25,7 @@
  #
 
 # Create run scripts for Windows to manually add the DLL path when executing
-SET(RUN_SCRIPTS run standalone client1 client2 server dedicated dedicatedClient)
+SET(RUN_SCRIPTS run standalone client1 client2 server dedicated dedicatedClient masterserver)
 IF(WIN32)
   FOREACH(_script ${RUN_SCRIPTS})
     LIST(REMOVE_ITEM RUN_SCRIPTS ${_script})

Copied: code/trunk/bin/masterserver.bat.in (from rev 7786, code/branches/presentation/bin/masterserver.bat.in)
===================================================================
--- code/trunk/bin/masterserver.bat.in	                        (rev 0)
+++ code/trunk/bin/masterserver.bat.in	2010-12-22 18:24:24 UTC (rev 7801)
@@ -0,0 +1,4 @@
+title @PROJECT_NAME@
+path @RUNTIME_LIBRARY_DIRECTORY_WINDOWS@;%path%
+ at CURRENT_RUNTIME_DIR_WINDOWS@\@ORXONOX_EXECUTABLE_NAME@ --masterserver --writingPathSuffix masterserver
+pause

Copied: code/trunk/bin/masterserver.in (from rev 7786, code/branches/presentation/bin/masterserver.in)
===================================================================
--- code/trunk/bin/masterserver.in	                        (rev 0)
+++ code/trunk/bin/masterserver.in	2010-12-22 18:24:24 UTC (rev 7801)
@@ -0,0 +1,4 @@
+#!/bin/sh
+# convenience script for starting orxonox on Linux
+
+exec @CURRENT_RUNTIME_DIR@/@ORXONOX_EXECUTABLE_NAME@ --masterserver --writingPathSuffix masterserver $@

Modified: code/trunk/data/gui/layouts/AudioMenu.layout
===================================================================
--- code/trunk/data/gui/layouts/AudioMenu.layout	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/data/gui/layouts/AudioMenu.layout	2010-12-22 18:24:24 UTC (rev 7801)
@@ -112,7 +112,7 @@
             <Window Type="MenuWidgets/StaticText" Name="orxonox/AudioInfo" >
                 <Property Name="Text" >Theme changes might take
 up to a minute.</Property>
-                <Property Name="TextColours" Value="FF4444FF" />
+                <Property Name="TextColours" Value="FFFFFFFF" />
                 <Property Name="InheritsAlpha" Value="False" />
                 <Property Name="HorzFormatting" Value="HorzCentred" />
                 <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />

Modified: code/trunk/data/gui/layouts/CreditsMenu.layout
===================================================================
--- code/trunk/data/gui/layouts/CreditsMenu.layout	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/data/gui/layouts/CreditsMenu.layout	2010-12-22 18:24:24 UTC (rev 7801)
@@ -31,28 +31,21 @@
                     <Property Name="HorzScrollPosition" Value="0" />
                     <Property Name="VertScrollPosition" Value="0" />
                     <Window Type="MenuWidgets/StaticText" Name="orxonox/CreditsText" >
-                        <Property Name="TextColours" Value="FF4444FF" />
+                        <Property Name="TextColours" Value="FFFFFFFF" />
                         <Property Name="InheritsAlpha" Value="False" />
                         <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
                         <Property Name="HorzFormatting" Value="HorzCentred" />
                         <Property Name="VertFormatting" Value="TopAligned" />
                         <Property Name="UnifiedAreaRect" Value="{{0,0},{0,0},{1,0},{1,0}}" />
-                        <Property Name="Text">Orxonox version 0.0.3
+                        <Property Name="Text">wird sowieso nicht gelesen
+Orxonox version 0.0.3
 
 Programming Language:  C++ - lua - tcl
 Environment:  OpenAL - Ogre - OIS - CEGUI - enet - ODE
 Licence:  GNU General Public Licence - Creative Commons
 
 http://www.orxonox.net
-n
-n
-n
-n
-n
-n
-n
-n
-n                       </Property>
+                      </Property>
                     </Window>
                 </Window>
             </Window>

Modified: code/trunk/data/gui/layouts/GraphicsMenu.layout
===================================================================
--- code/trunk/data/gui/layouts/GraphicsMenu.layout	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/data/gui/layouts/GraphicsMenu.layout	2010-12-22 18:24:24 UTC (rev 7801)
@@ -14,27 +14,40 @@
             <Property Name="HorzFormatting" Value="HorzCentred" />
             <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
             <Property Name="VertFormatting" Value="TopAligned" />
-            <Property Name="UnifiedAreaRect" Value="{{0.25,0},{0.2875,0},{0.75,0},{0.6375,0}}" />
+            <Property Name="UnifiedAreaRect" Value="{{0.25,0},{0.2,0},{0.75,0},{0.6375,0}}" />
             <Window Type="MenuWidgets/StaticText" Name="orxonox/Resolution" >
                 <Property Name="Text" Value="Resolution" />
                 <Property Name="InheritsAlpha" Value="False" />
                 <Property Name="HorzFormatting" Value="HorzCentred" />
                 <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
                 <Property Name="VertFormatting" Value="TopAligned" />
-                <Property Name="UnifiedAreaRect" Value="{{0.05,0},{0.15,0},{0.475,0},{0.92,0}}" />
+                <Property Name="UnifiedAreaRect" Value="{{0.05,0},{0.10,0},{0.475,0},{0.65,0}}" />
                 <Window Type="MenuWidgets/Listbox" Name="orxonox/ResolutionListbox" >
                     <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
-                    <Property Name="UnifiedAreaRect" Value="{{0.05,0},{0.15,0},{0.95,0},{0.95,0}}" />
+                    <Property Name="UnifiedAreaRect" Value="{{0.05,0},{0.2,0},{0.95,0},{0.95,0}}" />
                     <Event Name="ItemSelectionChanged" Function="GraphicsMenu.GraphicsResolutionListbox_changed"/>
                 </Window>
             </Window>
+            <Window Type="MenuWidgets/StaticText" Name="orxonox/Themes" >
+                <Property Name="Text" Value="Themes" />
+                <Property Name="InheritsAlpha" Value="False" />
+                <Property Name="HorzFormatting" Value="HorzCentred" />
+                <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
+                <Property Name="VertFormatting" Value="TopAligned" />
+                <Property Name="UnifiedAreaRect" Value="{{0.525,0},{0.10,0},{0.95,0},{0.35,0}}" />
+                <Window Type="MenuWidgets/Listbox" Name="orxonox/ThemeDropBox" >
+                    <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
+                    <Property Name="UnifiedAreaRect" Value="{{0.05,0},{0.3,0},{0.95,0},{0.95,0}" />
+                    <Event Name="ItemSelectionChanged" Function="GraphicsMenu.ThemeDropBox_changed"/>
+                </Window>
+            </Window>
             <Window Type="MenuWidgets/StaticText" Name="orxonox/Brightness" >
                 <Property Name="Text" Value="Brightness" />
                 <Property Name="InheritsAlpha" Value="False" />
                 <Property Name="HorzFormatting" Value="HorzCentred" />
                 <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
                 <Property Name="VertFormatting" Value="TopAligned" />
-                <Property Name="UnifiedAreaRect" Value="{{0.525,0},{0.15,0},{0.95,0},{0.35,0}}" />
+                <Property Name="UnifiedAreaRect" Value="{{0.05,0},{0.70,0},{0.475,0},{0.85,0}}" />
                 <Window Type="MenuWidgets/HorizontalScrollbar" Name="orxonox/BrightnessScrollbar" >
                     <Property Name="Disabled" Value="true" />
                     <Property Name="PageSize" Value="0" />
@@ -52,7 +65,7 @@
             <Window Type="MenuWidgets/Checkbox" Name="orxonox/FullscreenCheckbox" >
                 <Property Name="Text" Value="Fullscreen" />
                 <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
-                <Property Name="UnifiedAreaRect" Value="{{0.65,0},{0.4,0},{0.85,0},{0.475,0}}" />
+                <Property Name="UnifiedAreaRect" Value="{{0.65,0},{0.35,0},{0.85,0},{0.425,0}}" />
                 <Event Name="CheckStateChanged" Function="GraphicsMenu.GraphicsFullscreenCheckbox_clicked"/>
             </Window>
             <Window Type="MenuWidgets/StaticText" Name="orxonox/GraphicsInfo" >
@@ -60,12 +73,12 @@
 Changes in graphics
 settings require
 a game restart.</Property>
-                <Property Name="TextColours" Value="FF4444FF" />
+                <Property Name="TextColours" Value="FFFFFFFF" />
                 <Property Name="InheritsAlpha" Value="False" />
                 <Property Name="HorzFormatting" Value="HorzCentred" />
                 <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
                 <Property Name="VertFormatting" Value="TopAligned" />
-                <Property Name="UnifiedAreaRect" Value="{{0.525,0},{0.525,0},{0.95,0},{0.92,0}}" />
+                <Property Name="UnifiedAreaRect" Value="{{0.525,0},{0.425,0},{0.95,0},{0.85,0}}" />
             </Window>
         </Window>
         <Window Type="MenuWidgets/Button" Name="orxonox/GraphicsBackButton" >

Modified: code/trunk/data/gui/layouts/InGameMenu.layout
===================================================================
--- code/trunk/data/gui/layouts/InGameMenu.layout	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/data/gui/layouts/InGameMenu.layout	2010-12-22 18:24:24 UTC (rev 7801)
@@ -9,28 +9,28 @@
             <Property Name="Text" Value="Return to Game" />
             <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
             <Property Name="UnifiedAreaRect" Value="{{0.4,0},{0.3625,0},{0.6,0},{0.4125,0}}" />
-            <Property Name="Alpha" Value="0.7" />
+            <Property Name="Alpha" Value="0.9" />
             <Event Name="Clicked" Function="InGameMenu.button_return_clicked"/>
         </Window>
         <Window Type="MenuWidgets/Button" Name="orxonox/InGameMenu_MainMenuButton" >
             <Property Name="Text" Value="Main Menu" />
             <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
             <Property Name="UnifiedAreaRect" Value="{{0.4,0},{0.4625,0},{0.6,0},{0.5125,0}}" />
-            <Property Name="Alpha" Value="0.7" />
+            <Property Name="Alpha" Value="0.9" />
             <Event Name="Clicked" Function="InGameMenu.button_mainmenu_clicked"/>
         </Window>
         <Window Type="MenuWidgets/Button" Name="orxonox/InGameMenu_SettingsButton" >
             <Property Name="Text" Value="Settings" />
             <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
             <Property Name="UnifiedAreaRect" Value="{{0.4,0},{0.5625,0},{0.6,0},{0.6125,0}}" />
-            <Property Name="Alpha" Value="0.7" />
+            <Property Name="Alpha" Value="0.9" />
             <Event Name="Clicked" Function="InGameMenu.button_settings_clicked"/>
         </Window>
         <Window Type="MenuWidgets/Button" Name="orxonox/InGameMenu_QuitButton" >
             <Property Name="Text" Value="Quit" />
             <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
             <Property Name="UnifiedAreaRect" Value="{{0.4,0},{0.6625,0},{0.6,0},{0.7125,0}}" />
-            <Property Name="Alpha" Value="0.7" />
+            <Property Name="Alpha" Value="0.9" />
             <Event Name="Clicked" Function="InGameMenu.button_quit_clicked"/>
         </Window>
     </Window>

Modified: code/trunk/data/gui/layouts/MultiplayerMenu.layout
===================================================================
--- code/trunk/data/gui/layouts/MultiplayerMenu.layout	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/data/gui/layouts/MultiplayerMenu.layout	2010-12-22 18:24:24 UTC (rev 7801)
@@ -31,8 +31,6 @@
                 <Property Name="UnifiedAreaRect" Value="{{0.6,0},{0.87,0},{0.8,0},{0.97,0}}" />
                 <Event Name="SelectStateChanged" Function="MultiplayerMenu.InternetButton_clicked"/>
             </Window>
-
-
         </Window>
          <Window Type="MenuWidgets/Button" Name="orxonox/MultiplayerBackButton" >
             <Property Name="Text" Value="Back" />

Copied: code/trunk/data/gui/schemes/OrxonoxHUDWidgets.scheme (from rev 7786, code/branches/presentation/data/gui/schemes/OrxonoxHUDWidgets.scheme)
===================================================================
--- code/trunk/data/gui/schemes/OrxonoxHUDWidgets.scheme	                        (rev 0)
+++ code/trunk/data/gui/schemes/OrxonoxHUDWidgets.scheme	2010-12-22 18:24:24 UTC (rev 7801)
@@ -0,0 +1,42 @@
+<?xml version="1.0" ?>
+<GUIScheme Name="OrxonoxHUDWidgets">
+    <WindowAlias Alias="HUDWidgets/StaticImage"              Target="OrxonoxLook/StaticImage" />
+    <WindowAlias Alias="HUDWidgets/StaticText"               Target="OrxonoxLook/StaticText" />
+    <WindowAlias Alias="HUDWidgets/TabButtonPane"            Target="OrxonoxLook/TabButtonPane" />
+    <WindowAlias Alias="HUDWidgets/TabContentPane"           Target="OrxonoxLook/TabContentPane" />
+    <WindowAlias Alias="HUDWidgets/Checkbox"                 Target="OrxonoxLook/Checkbox" />
+    <WindowAlias Alias="HUDWidgets/Combobox"                 Target="OrxonoxLook/Combobox" />
+    <WindowAlias Alias="HUDWidgets/ComboDropList"            Target="OrxonoxLook/ComboDropList" />
+    <WindowAlias Alias="HUDWidgets/ComboEditbox"             Target="OrxonoxLook/ComboEditbox" />
+    <WindowAlias Alias="HUDWidgets/Editbox"                  Target="OrxonoxLook/Editbox" />
+    <WindowAlias Alias="HUDWidgets/FrameWindow"              Target="OrxonoxLook/FrameWindow" />
+    <WindowAlias Alias="HUDWidgets/GroupBox"                 Target="OrxonoxLook/GroupBox" />
+    <WindowAlias Alias="HUDWidgets/ItemListbox"              Target="OrxonoxLook/ItemListbox" />
+    <WindowAlias Alias="HUDWidgets/ListboxItem"              Target="OrxonoxLook/ListboxItem" />
+    <WindowAlias Alias="HUDWidgets/Listbox"                  Target="OrxonoxLook/Listbox" />
+    <WindowAlias Alias="HUDWidgets/ListHeader"               Target="OrxonoxLook/ListHeader" />
+    <WindowAlias Alias="HUDWidgets/ListHeaderSegment"        Target="OrxonoxLook/ListHeaderSegment" />
+    <WindowAlias Alias="HUDWidgets/MultiLineEditbox"         Target="OrxonoxLook/MultiLineEditbox" />
+    <WindowAlias Alias="HUDWidgets/Menubar"                  Target="OrxonoxLook/Menubar" />
+    <WindowAlias Alias="HUDWidgets/MenuItem"                 Target="OrxonoxLook/MenuItem" />
+    <WindowAlias Alias="HUDWidgets/MultiColumnList"          Target="OrxonoxLook/MultiColumnList" />
+    <WindowAlias Alias="HUDWidgets/PopupMenu"                Target="OrxonoxLook/PopupMenu" />
+    <WindowAlias Alias="HUDWidgets/ProgressBar"              Target="OrxonoxLook/ProgressBar" />
+    <WindowAlias Alias="HUDWidgets/Button"                   Target="OrxonoxLook/Button" />
+    <WindowAlias Alias="HUDWidgets/ImageButton"              Target="OrxonoxLook/ImageButton" />
+    <WindowAlias Alias="HUDWidgets/RadioButton"              Target="OrxonoxLook/RadioButton" />
+    <WindowAlias Alias="HUDWidgets/SystemButton"             Target="OrxonoxLook/SystemButton" />
+    <WindowAlias Alias="HUDWidgets/ScrollablePane"           Target="OrxonoxLook/ScrollablePane" />
+    <WindowAlias Alias="HUDWidgets/HorizontalScrollbar"      Target="OrxonoxLook/HorizontalScrollbar" />
+    <WindowAlias Alias="HUDWidgets/VerticalScrollbar"        Target="OrxonoxLook/VerticalScrollbar" />
+    <WindowAlias Alias="HUDWidgets/Slider"                   Target="OrxonoxLook/Slider" />
+    <WindowAlias Alias="HUDWidgets/Spinner"                  Target="OrxonoxLook/Spinner" />
+    <WindowAlias Alias="HUDWidgets/TabButton"                Target="OrxonoxLook/TabButton" />
+    <WindowAlias Alias="HUDWidgets/TabControl"               Target="OrxonoxLook/TabControl" />
+    <WindowAlias Alias="HUDWidgets/HorizontalScrollbarThumb" Target="OrxonoxLook/HorizontalScrollbarThumb" />
+    <WindowAlias Alias="HUDWidgets/SliderThumb"              Target="OrxonoxLook/SliderThumb" />
+    <WindowAlias Alias="HUDWidgets/VerticalScrollbarThumb"   Target="OrxonoxLook/VerticalScrollbarThumb" />
+    <WindowAlias Alias="HUDWidgets/Titlebar"                 Target="OrxonoxLook/Titlebar" />
+    <WindowAlias Alias="HUDWidgets/Tooltip"                  Target="OrxonoxLook/Tooltip" />
+    <WindowAlias Alias="HUDWidgets/Tree"                     Target="OrxonoxLook/Tree" />
+</GUIScheme>

Deleted: code/trunk/data/gui/schemes/OrxonoxLookHUDWidgets.scheme
===================================================================
--- code/trunk/data/gui/schemes/OrxonoxLookHUDWidgets.scheme	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/data/gui/schemes/OrxonoxLookHUDWidgets.scheme	2010-12-22 18:24:24 UTC (rev 7801)
@@ -1,42 +0,0 @@
-<?xml version="1.0" ?>
-<GUIScheme Name="OrxonoxLookHUDWidgets">
-    <WindowAlias Alias="HUDWidgets/StaticImage"              Target="OrxonoxLook/StaticImage" />
-    <WindowAlias Alias="HUDWidgets/StaticText"               Target="OrxonoxLook/StaticText" />
-    <WindowAlias Alias="HUDWidgets/TabButtonPane"            Target="OrxonoxLook/TabButtonPane" />
-    <WindowAlias Alias="HUDWidgets/TabContentPane"           Target="OrxonoxLook/TabContentPane" />
-    <WindowAlias Alias="HUDWidgets/Checkbox"                 Target="OrxonoxLook/Checkbox" />
-    <WindowAlias Alias="HUDWidgets/Combobox"                 Target="OrxonoxLook/Combobox" />
-    <WindowAlias Alias="HUDWidgets/ComboDropList"            Target="OrxonoxLook/ComboDropList" />
-    <WindowAlias Alias="HUDWidgets/ComboEditbox"             Target="OrxonoxLook/ComboEditbox" />
-    <WindowAlias Alias="HUDWidgets/Editbox"                  Target="OrxonoxLook/Editbox" />
-    <WindowAlias Alias="HUDWidgets/FrameWindow"              Target="OrxonoxLook/FrameWindow" />
-    <WindowAlias Alias="HUDWidgets/GroupBox"                 Target="OrxonoxLook/GroupBox" />
-    <WindowAlias Alias="HUDWidgets/ItemListbox"              Target="OrxonoxLook/ItemListbox" />
-    <WindowAlias Alias="HUDWidgets/ListboxItem"              Target="OrxonoxLook/ListboxItem" />
-    <WindowAlias Alias="HUDWidgets/Listbox"                  Target="OrxonoxLook/Listbox" />
-    <WindowAlias Alias="HUDWidgets/ListHeader"               Target="OrxonoxLook/ListHeader" />
-    <WindowAlias Alias="HUDWidgets/ListHeaderSegment"        Target="OrxonoxLook/ListHeaderSegment" />
-    <WindowAlias Alias="HUDWidgets/MultiLineEditbox"         Target="OrxonoxLook/MultiLineEditbox" />
-    <WindowAlias Alias="HUDWidgets/Menubar"                  Target="OrxonoxLook/Menubar" />
-    <WindowAlias Alias="HUDWidgets/MenuItem"                 Target="OrxonoxLook/MenuItem" />
-    <WindowAlias Alias="HUDWidgets/MultiColumnList"          Target="OrxonoxLook/MultiColumnList" />
-    <WindowAlias Alias="HUDWidgets/PopupMenu"                Target="OrxonoxLook/PopupMenu" />
-    <WindowAlias Alias="HUDWidgets/ProgressBar"              Target="OrxonoxLook/ProgressBar" />
-    <WindowAlias Alias="HUDWidgets/Button"                   Target="OrxonoxLook/Button" />
-    <WindowAlias Alias="HUDWidgets/ImageButton"              Target="OrxonoxLook/ImageButton" />
-    <WindowAlias Alias="HUDWidgets/RadioButton"              Target="OrxonoxLook/RadioButton" />
-    <WindowAlias Alias="HUDWidgets/SystemButton"             Target="OrxonoxLook/SystemButton" />
-    <WindowAlias Alias="HUDWidgets/ScrollablePane"           Target="OrxonoxLook/ScrollablePane" />
-    <WindowAlias Alias="HUDWidgets/HorizontalScrollbar"      Target="OrxonoxLook/HorizontalScrollbar" />
-    <WindowAlias Alias="HUDWidgets/VerticalScrollbar"        Target="OrxonoxLook/VerticalScrollbar" />
-    <WindowAlias Alias="HUDWidgets/Slider"                   Target="OrxonoxLook/Slider" />
-    <WindowAlias Alias="HUDWidgets/Spinner"                  Target="OrxonoxLook/Spinner" />
-    <WindowAlias Alias="HUDWidgets/TabButton"                Target="OrxonoxLook/TabButton" />
-    <WindowAlias Alias="HUDWidgets/TabControl"               Target="OrxonoxLook/TabControl" />
-    <WindowAlias Alias="HUDWidgets/HorizontalScrollbarThumb" Target="OrxonoxLook/HorizontalScrollbarThumb" />
-    <WindowAlias Alias="HUDWidgets/SliderThumb"              Target="OrxonoxLook/SliderThumb" />
-    <WindowAlias Alias="HUDWidgets/VerticalScrollbarThumb"   Target="OrxonoxLook/VerticalScrollbarThumb" />
-    <WindowAlias Alias="HUDWidgets/Titlebar"                 Target="OrxonoxLook/Titlebar" />
-    <WindowAlias Alias="HUDWidgets/Tooltip"                  Target="OrxonoxLook/Tooltip" />
-    <WindowAlias Alias="HUDWidgets/Tree"                     Target="OrxonoxLook/Tree" />
-</GUIScheme>

Deleted: code/trunk/data/gui/schemes/OrxonoxLookMenuWidgets.scheme
===================================================================
--- code/trunk/data/gui/schemes/OrxonoxLookMenuWidgets.scheme	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/data/gui/schemes/OrxonoxLookMenuWidgets.scheme	2010-12-22 18:24:24 UTC (rev 7801)
@@ -1,42 +0,0 @@
-<?xml version="1.0" ?>
-<GUIScheme Name="OrxonoxLookMenuWidgets">
-    <WindowAlias Alias="MenuWidgets/StaticImage"              Target="OrxonoxLook/StaticImage" />
-    <WindowAlias Alias="MenuWidgets/StaticText"               Target="OrxonoxLook/StaticText" />
-    <WindowAlias Alias="MenuWidgets/TabButtonPane"            Target="OrxonoxLook/TabButtonPane" />
-    <WindowAlias Alias="MenuWidgets/TabContentPane"           Target="OrxonoxLook/TabContentPane" />
-    <WindowAlias Alias="MenuWidgets/Checkbox"                 Target="OrxonoxLook/Checkbox" />
-    <WindowAlias Alias="MenuWidgets/Combobox"                 Target="OrxonoxLook/Combobox" />
-    <WindowAlias Alias="MenuWidgets/ComboDropList"            Target="OrxonoxLook/ComboDropList" />
-    <WindowAlias Alias="MenuWidgets/ComboEditbox"             Target="OrxonoxLook/ComboEditbox" />
-    <WindowAlias Alias="MenuWidgets/Editbox"                  Target="OrxonoxLook/Editbox" />
-    <WindowAlias Alias="MenuWidgets/FrameWindow"              Target="OrxonoxLook/FrameWindow" />
-    <WindowAlias Alias="MenuWidgets/GroupBox"                 Target="OrxonoxLook/GroupBox" />
-    <WindowAlias Alias="MenuWidgets/ItemListbox"              Target="OrxonoxLook/ItemListbox" />
-    <WindowAlias Alias="MenuWidgets/ListboxItem"              Target="OrxonoxLook/ListboxItem" />
-    <WindowAlias Alias="MenuWidgets/Listbox"                  Target="OrxonoxLook/Listbox" />
-    <WindowAlias Alias="MenuWidgets/ListHeader"               Target="OrxonoxLook/ListHeader" />
-    <WindowAlias Alias="MenuWidgets/ListHeaderSegment"        Target="OrxonoxLook/ListHeaderSegment" />
-    <WindowAlias Alias="MenuWidgets/MultiLineEditbox"         Target="OrxonoxLook/MultiLineEditbox" />
-    <WindowAlias Alias="MenuWidgets/Menubar"                  Target="OrxonoxLook/Menubar" />
-    <WindowAlias Alias="MenuWidgets/MenuItem"                 Target="OrxonoxLook/MenuItem" />
-    <WindowAlias Alias="MenuWidgets/MultiColumnList"          Target="OrxonoxLook/MultiColumnList" />
-    <WindowAlias Alias="MenuWidgets/PopupMenu"                Target="OrxonoxLook/PopupMenu" />
-    <WindowAlias Alias="MenuWidgets/ProgressBar"              Target="OrxonoxLook/ProgressBar" />
-    <WindowAlias Alias="MenuWidgets/Button"                   Target="OrxonoxLook/Button" />
-    <WindowAlias Alias="MenuWidgets/ImageButton"              Target="OrxonoxLook/ImageButton" />
-    <WindowAlias Alias="MenuWidgets/RadioButton"              Target="OrxonoxLook/RadioButton" />
-    <WindowAlias Alias="MenuWidgets/SystemButton"             Target="OrxonoxLook/SystemButton" />
-    <WindowAlias Alias="MenuWidgets/ScrollablePane"           Target="OrxonoxLook/ScrollablePane" />
-    <WindowAlias Alias="MenuWidgets/HorizontalScrollbar"      Target="OrxonoxLook/HorizontalScrollbar" />
-    <WindowAlias Alias="MenuWidgets/VerticalScrollbar"        Target="OrxonoxLook/VerticalScrollbar" />
-    <WindowAlias Alias="MenuWidgets/Slider"                   Target="OrxonoxLook/Slider" />
-    <WindowAlias Alias="MenuWidgets/Spinner"                  Target="OrxonoxLook/Spinner" />
-    <WindowAlias Alias="MenuWidgets/TabButton"                Target="OrxonoxLook/TabButton" />
-    <WindowAlias Alias="MenuWidgets/TabControl"               Target="OrxonoxLook/TabControl" />
-    <WindowAlias Alias="MenuWidgets/HorizontalScrollbarThumb" Target="OrxonoxLook/HorizontalScrollbarThumb" />
-    <WindowAlias Alias="MenuWidgets/SliderThumb"              Target="OrxonoxLook/SliderThumb" />
-    <WindowAlias Alias="MenuWidgets/VerticalScrollbarThumb"   Target="OrxonoxLook/VerticalScrollbarThumb" />
-    <WindowAlias Alias="MenuWidgets/Titlebar"                 Target="OrxonoxLook/Titlebar" />
-    <WindowAlias Alias="MenuWidgets/Tooltip"                  Target="OrxonoxLook/Tooltip" />
-    <WindowAlias Alias="MenuWidgets/Tree"                     Target="OrxonoxLook/Tree" />
-</GUIScheme>

Copied: code/trunk/data/gui/schemes/OrxonoxMenuWidgets.scheme (from rev 7786, code/branches/presentation/data/gui/schemes/OrxonoxMenuWidgets.scheme)
===================================================================
--- code/trunk/data/gui/schemes/OrxonoxMenuWidgets.scheme	                        (rev 0)
+++ code/trunk/data/gui/schemes/OrxonoxMenuWidgets.scheme	2010-12-22 18:24:24 UTC (rev 7801)
@@ -0,0 +1,42 @@
+<?xml version="1.0" ?>
+<GUIScheme Name="OrxonoxMenuWidgets">
+    <WindowAlias Alias="MenuWidgets/StaticImage"              Target="OrxonoxLook/StaticImage" />
+    <WindowAlias Alias="MenuWidgets/StaticText"               Target="OrxonoxLook/StaticText" />
+    <WindowAlias Alias="MenuWidgets/TabButtonPane"            Target="OrxonoxLook/TabButtonPane" />
+    <WindowAlias Alias="MenuWidgets/TabContentPane"           Target="OrxonoxLook/TabContentPane" />
+    <WindowAlias Alias="MenuWidgets/Checkbox"                 Target="OrxonoxLook/Checkbox" />
+    <WindowAlias Alias="MenuWidgets/Combobox"                 Target="OrxonoxLook/Combobox" />
+    <WindowAlias Alias="MenuWidgets/ComboDropList"            Target="OrxonoxLook/ComboDropList" />
+    <WindowAlias Alias="MenuWidgets/ComboEditbox"             Target="OrxonoxLook/ComboEditbox" />
+    <WindowAlias Alias="MenuWidgets/Editbox"                  Target="OrxonoxLook/Editbox" />
+    <WindowAlias Alias="MenuWidgets/FrameWindow"              Target="OrxonoxLook/FrameWindow" />
+    <WindowAlias Alias="MenuWidgets/GroupBox"                 Target="OrxonoxLook/GroupBox" />
+    <WindowAlias Alias="MenuWidgets/ItemListbox"              Target="OrxonoxLook/ItemListbox" />
+    <WindowAlias Alias="MenuWidgets/ListboxItem"              Target="OrxonoxLook/ListboxItem" />
+    <WindowAlias Alias="MenuWidgets/Listbox"                  Target="OrxonoxLook/Listbox" />
+    <WindowAlias Alias="MenuWidgets/ListHeader"               Target="OrxonoxLook/ListHeader" />
+    <WindowAlias Alias="MenuWidgets/ListHeaderSegment"        Target="OrxonoxLook/ListHeaderSegment" />
+    <WindowAlias Alias="MenuWidgets/MultiLineEditbox"         Target="OrxonoxLook/MultiLineEditbox" />
+    <WindowAlias Alias="MenuWidgets/Menubar"                  Target="OrxonoxLook/Menubar" />
+    <WindowAlias Alias="MenuWidgets/MenuItem"                 Target="OrxonoxLook/MenuItem" />
+    <WindowAlias Alias="MenuWidgets/MultiColumnList"          Target="OrxonoxLook/MultiColumnList" />
+    <WindowAlias Alias="MenuWidgets/PopupMenu"                Target="OrxonoxLook/PopupMenu" />
+    <WindowAlias Alias="MenuWidgets/ProgressBar"              Target="OrxonoxLook/ProgressBar" />
+    <WindowAlias Alias="MenuWidgets/Button"                   Target="OrxonoxLook/Button" />
+    <WindowAlias Alias="MenuWidgets/ImageButton"              Target="OrxonoxLook/ImageButton" />
+    <WindowAlias Alias="MenuWidgets/RadioButton"              Target="OrxonoxLook/RadioButton" />
+    <WindowAlias Alias="MenuWidgets/SystemButton"             Target="OrxonoxLook/SystemButton" />
+    <WindowAlias Alias="MenuWidgets/ScrollablePane"           Target="OrxonoxLook/ScrollablePane" />
+    <WindowAlias Alias="MenuWidgets/HorizontalScrollbar"      Target="OrxonoxLook/HorizontalScrollbar" />
+    <WindowAlias Alias="MenuWidgets/VerticalScrollbar"        Target="OrxonoxLook/VerticalScrollbar" />
+    <WindowAlias Alias="MenuWidgets/Slider"                   Target="OrxonoxLook/Slider" />
+    <WindowAlias Alias="MenuWidgets/Spinner"                  Target="OrxonoxLook/Spinner" />
+    <WindowAlias Alias="MenuWidgets/TabButton"                Target="OrxonoxLook/TabButton" />
+    <WindowAlias Alias="MenuWidgets/TabControl"               Target="OrxonoxLook/TabControl" />
+    <WindowAlias Alias="MenuWidgets/HorizontalScrollbarThumb" Target="OrxonoxLook/HorizontalScrollbarThumb" />
+    <WindowAlias Alias="MenuWidgets/SliderThumb"              Target="OrxonoxLook/SliderThumb" />
+    <WindowAlias Alias="MenuWidgets/VerticalScrollbarThumb"   Target="OrxonoxLook/VerticalScrollbarThumb" />
+    <WindowAlias Alias="MenuWidgets/Titlebar"                 Target="OrxonoxLook/Titlebar" />
+    <WindowAlias Alias="MenuWidgets/Tooltip"                  Target="OrxonoxLook/Tooltip" />
+    <WindowAlias Alias="MenuWidgets/Tree"                     Target="OrxonoxLook/Tree" />
+</GUIScheme>

Modified: code/trunk/data/gui/scripts/ChatBox-inputonly.lua
===================================================================
--- code/trunk/data/gui/scripts/ChatBox-inputonly.lua	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/data/gui/scripts/ChatBox-inputonly.lua	2010-12-22 18:24:24 UTC (rev 7801)
@@ -1,5 +1,5 @@
 -- ChatBox-inputonly.lua
 
-local P = createMenuSheet("ChatBox-inputonly")
+local P = createMenuSheet("ChatBox-inputonly", true, TriBool.True, TriBool.Dontcare, false)
 return P
 

Modified: code/trunk/data/gui/scripts/ChatBox.lua
===================================================================
--- code/trunk/data/gui/scripts/ChatBox.lua	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/data/gui/scripts/ChatBox.lua	2010-12-22 18:24:24 UTC (rev 7801)
@@ -1,6 +1,6 @@
 -- ChatBox.lua
 
-local P = createMenuSheet("ChatBox")
+local P = createMenuSheet("ChatBox", true, TriBool.True, TriBool.Dontcare, false)
 
 function P.ChatBoxCloseButton_clicked(e)
     orxonox.ChatInputHandler:getInstance():deactivate()

Modified: code/trunk/data/gui/scripts/GraphicsMenu.lua
===================================================================
--- code/trunk/data/gui/scripts/GraphicsMenu.lua	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/data/gui/scripts/GraphicsMenu.lua	2010-12-22 18:24:24 UTC (rev 7801)
@@ -3,6 +3,7 @@
 local P = createMenuSheet("GraphicsMenu")
 
 P.buttonList = {}
+P.schemeList = {"TaharezGreen", "Orxonox"}
 
 function P.onShow()
     --indices to iterate through buttonlist (trivial in this menu sheet)
@@ -96,8 +97,31 @@
             ["function"]  = P.GraphicsBackButton_clicked
     }
     P.buttonList[1] = item
+
+    local dropbox = winMgr:getWindow("orxonox/ThemeDropBox")
+    local scheme = orxonox.CommandExecutor:query("getConfig GUIManager guiScheme_")
+    for k,v in pairs(P.schemeList) do
+        local item = CEGUI.createListboxTextItem(P.schemeList[k])
+        item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
+        CEGUI.toListbox(dropbox):addItem(item)
+        if v == scheme then
+            dropbox:setItemSelectState(item, true)
+        end
+    end
+
 end
 
+function P.ThemeDropBox_changed(e)
+    local dropbox = winMgr:getWindow("orxonox/ThemeDropBox")
+    local listbox = CEGUI.toListbox(dropbox)
+    local choice = listbox:getFirstSelectedItem()
+    local index = 0
+    if choice ~= nil then
+        index = listbox:getItemIndex(choice)
+    end
+    orxonox.CommandExecutor:execute("config GUIManager guiScheme_ " .. P.schemeList[index+1])
+end
+
 function P.GraphicsResolutionListbox_changed(e)
     if listboxwindow:isItemSelected(0) then
         resolution = "640 x 480"

Modified: code/trunk/data/gui/scripts/InitialiseGUI.lua
===================================================================
--- code/trunk/data/gui/scripts/InitialiseGUI.lua	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/data/gui/scripts/InitialiseGUI.lua	2010-12-22 18:24:24 UTC (rev 7801)
@@ -4,9 +4,10 @@
 schemeMgr = CEGUI.SchemeManager:getSingleton()
 winMgr    = CEGUI.WindowManager:getSingleton()
 
+local scheme = orxonox.CommandExecutor:query("getConfig GUIManager guiScheme_")
 -- Load all required skins
-schemeMgr:loadScheme("TaharezGreenLook.scheme")
---schemeMgr:loadScheme("OrxonoxLook.scheme")
+--schemeMgr:loadScheme("TaharezGreenLook.scheme")
+schemeMgr:loadScheme(scheme .. "Look.scheme")
 --schemeMgr:loadScheme("TaharezLook.scheme")
 --schemeMgr:loadScheme("WindowsLook.scheme")
 --schemeMgr:loadScheme("VanillaLook.scheme")
@@ -15,14 +16,14 @@
 -- Connect skin specific window types with our own window types
 -- By loading a different file (if there is) you can change the skin
 -- of the menus or the HUD independently
-schemeMgr:loadScheme("TaharezGreenMenuWidgets.scheme")
-menuImageSet = "TaharezGreenLook"
-schemeMgr:loadScheme("TaharezGreenHUDWidgets.scheme")
-hudImageSet = "TaharezGreenLook"
---schemeMgr:loadScheme("OrxonoxLookMenuWidgets.scheme")
---menuImageSet = "OrxonoxLook"
---schemeMgr:loadScheme("OrxonoxLookHUDWidgets.scheme")
---hudImageSet = "OrxonoxLook"
+--schemeMgr:loadScheme("TaharezGreenMenuWidgets.scheme")
+--menuImageSet = "TaharezGreenLook"
+--schemeMgr:loadScheme("TaharezGreenHUDWidgets.scheme")
+--hudImageSet = "TaharezGreenLook"
+schemeMgr:loadScheme(scheme .. "MenuWidgets.scheme")
+menuImageSet = scheme .. "Look"
+schemeMgr:loadScheme(scheme .. "HUDWidgets.scheme")
+hudImageSet = scheme .. "Look"
 
 -- Just a remaining test hack
 schemeMgr:loadScheme("OrxonoxGUIScheme.scheme")

Modified: code/trunk/data/gui/scripts/MultiplayerMenu.lua
===================================================================
--- code/trunk/data/gui/scripts/MultiplayerMenu.lua	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/data/gui/scripts/MultiplayerMenu.lua	2010-12-22 18:24:24 UTC (rev 7801)
@@ -5,8 +5,8 @@
 P.buttonList = {}
 
 --joinMode is 1 for choice "LAN" and 2 for "Internet"
---initial status 0
-P.joinMode = 0
+--initial status 1
+P.joinMode = 1
 
 function P.onLoad()
     P.multiplayerMode = "startClient" 
@@ -32,19 +32,40 @@
 end
 
 function P.onShow()
-    P.showServerList()
+    --P.showServerList()
 
     --indices to iterate through buttonlist
     P.oldindex = -2
     P.index = -1
+    
+    if P.joinMode == 1 then
+        local window = winMgr:getWindow("orxonox/MultiplayerLanButton")
+        local button = tolua.cast(window,"CEGUI::RadioButton")
+        button:setSelected(true)
+    end
+    if P.joinMode == 2 then
+        local window = winMgr:getWindow("orxonox/MultiplayerInternetButton")
+        local button = tolua.cast(window,"CEGUI::RadioButton")
+        button:setSelected(true)
+    end
 end
 
 function P.LanButton_clicked(e)
+    local we = CEGUI.toWindowEventArgs(e)
+    local button = tolua.cast(we.window,"CEGUI::RadioButton")
     P.joinMode = 1
+    if button:isSelected() == true then
+	    P.showServerList()
+    end
 end
 
 function P.InternetButton_clicked(e)
+    local we = CEGUI.toWindowEventArgs(e)
+    local button = tolua.cast(we.window,"CEGUI::RadioButton")
     P.joinMode = 2
+    if button:isSelected() == true then
+	    P.showServerList()
+	end
 end
 
 function P.MultiplayerHostButton_clicked(e)
@@ -54,21 +75,15 @@
 
 function P.MultiplayerJoinButton_clicked(e)
     local choice = winMgr:getWindow("orxonox/MultiplayerListbox"):getFirstSelectedItem()   
-
-    if P.joinMode == 2 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
-        orxonox.execute("startClient")
-        hideAllMenuSheets()
+    if choice then
+        local client = orxonox.Client:getInstance()
+        local index = tolua.cast(choice, "CEGUI::ListboxItem"):getID()
+        client:setDestination( P.serverList[index][2], 55556 )
     else
-        --wait for Sandro's function
+        return
     end
-
+    orxonox.execute("startClient")
+    hideAllMenuSheets()
 end
 
 function P.MultiplayerBackButton_clicked(e)
@@ -76,34 +91,70 @@
 end
 
 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
-    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
+	-- LAN Discovery
+	if P.joinMode == 1 then
+		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
+		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
+	-- WAN Discovery
+	elseif P.joinMode == 2 then
+		local listbox = winMgr:getWindow("orxonox/MultiplayerListbox")
+		CEGUI.toListbox(listbox):resetList()
+		local discovery = orxonox.WANDiscovery:getInstance()
+		cout(0, "discovering.\n" )
+		discovery:discover()
+		cout(0, "discovered.\n" )
+		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
+		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
+	
 end
 
 function P.onKeyPressed() 

Modified: code/trunk/src/libraries/core/GUIManager.cc
===================================================================
--- code/trunk/src/libraries/core/GUIManager.cc	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/libraries/core/GUIManager.cc	2010-12-22 18:24:24 UTC (rev 7801)
@@ -58,7 +58,9 @@
 #include "util/Debug.h"
 #include "util/Exception.h"
 #include "util/OrxAssert.h"
+#include "ConfigValueIncludes.h"
 #include "Core.h"
+#include "CoreIncludes.h"
 #include "GraphicsManager.h"
 #include "LuaState.h"
 #include "PathConfig.h"
@@ -99,6 +101,7 @@
     static CEGUI::MouseButton convertButton(MouseButtonCode::ByEnum button);
 
     GUIManager* GUIManager::singletonPtr_s = 0;
+    /*static*/ const std::string GUIManager::defaultScheme_ = "TaharezGreen";
 
     SetConsoleCommand("showGUI", &GUIManager::showGUI).defaultValue(1, false).defaultValue(2, false);
     SetConsoleCommand("hideGUI", &GUIManager::hideGUI);
@@ -117,6 +120,9 @@
         : resourceProvider_(NULL)
         , camera_(NULL)
     {
+        RegisterRootObject(GUIManager);
+        this->setConfigValues();
+
         using namespace CEGUI;
 
         COUT(3) << "Initialising CEGUI." << std::endl;
@@ -176,6 +182,16 @@
     {
     }
 
+    void GUIManager::setConfigValues(void)
+    {
+        SetConfigValue(guiScheme_, GUIManager::defaultScheme_) .description("Changes the current GUI scheme.") .callback(this, &GUIManager::changedGUIScheme);
+    }
+
+    void GUIManager::changedGUIScheme(void)
+    {
+        
+    }
+
     /**
     @brief
         used to tick the GUI

Modified: code/trunk/src/libraries/core/GUIManager.h
===================================================================
--- code/trunk/src/libraries/core/GUIManager.h	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/libraries/core/GUIManager.h	2010-12-22 18:24:24 UTC (rev 7801)
@@ -48,6 +48,7 @@
 #include "util/TriBool.h"
 #include "util/Singleton.h"
 #include "input/InputHandler.h"
+#include "OrxonoxClass.h"
 
 // Tolua includes (have to be relative to the current directory)
 /*
@@ -69,13 +70,16 @@
         Those input events are then injected into CEGUI in Lua.
     */
     class _CoreExport GUIManager // tolua_export
-        : public Singleton<GUIManager>, public InputHandler
+        : public Singleton<GUIManager>, public InputHandler, public OrxonoxClass
     { // tolua_export
         friend class Singleton<GUIManager>;
     public:
         GUIManager(const std::pair<int, int>& mousePosition);
         ~GUIManager();
 
+        void setConfigValues(void);
+        void changedGUIScheme(void);
+
         void preUpdate(const Clock& time);
 
         void loadGUI(const std::string& name);
@@ -142,6 +146,10 @@
 
         static GUIManager*                   singletonPtr_s;    //!< Singleton reference to GUIManager
 
+        // The used CEGUI scheme.
+        static const std::string defaultScheme_;
+        std::string guiScheme_;
+
     }; // tolua_export
 } // tolua_export
 

Modified: code/trunk/src/libraries/network/CMakeLists.txt
===================================================================
--- code/trunk/src/libraries/network/CMakeLists.txt	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/libraries/network/CMakeLists.txt	2010-12-22 18:24:24 UTC (rev 7801)
@@ -27,13 +27,19 @@
   FunctionCall.cc
   FunctionCallManager.cc
   GamestateManager.cc
-  GamestateClient.cc
+  #GamestateClient.cc
   GamestateHandler.cc
   LANDiscoverable.cc
   LANDiscovery.cc
+  WANDiscoverable.cc
+  WANDiscovery.cc
+  MasterServerComm.cc
   NetworkFunction.cc
   Host.cc
   Server.cc
+  MasterServer.cc
+  PeerList.cc
+  ServerList.cc
   ServerConnection.cc
   TrafficControl.cc
 )
@@ -47,16 +53,22 @@
   Connection.h
   FunctionCall.h
   FunctionCallManager.h
-  GamestateClient.h
+  #GamestateClient.h
   GamestateHandler.h
   GamestateManager.h
   Host.h
   LANDiscoverable.h
   LANDiscovery.h
+  WANDiscoverable.h
+  WANDiscovery.h
+  MasterServerComm.h
   NetworkFunction.h
   NetworkPrecompiledHeaders.h
   NetworkPrereqs.h
   Server.h
+  MasterServer.h
+  PeerList.h
+  ServerList.h
   ServerConnection.h
   TrafficControl.h
 )
@@ -68,6 +80,7 @@
   TOLUA_FILES
     Client.h
     LANDiscovery.h
+    WANDiscovery.h
   PCH_FILE
     NetworkPrecompiledHeaders.h
   LINK_LIBRARIES

Modified: code/trunk/src/libraries/network/Client.cc
===================================================================
--- code/trunk/src/libraries/network/Client.cc	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/libraries/network/Client.cc	2010-12-22 18:24:24 UTC (rev 7801)
@@ -63,7 +63,6 @@
   * initializes the address and the port to default localhost:NETWORK_PORT
   */
   Client::Client():
-      gamestate(0),
       isSynched_(false),
       gameStateFailure_(false),
       timeSinceLastUpdate_(0)
@@ -84,10 +83,10 @@
   bool Client::establishConnection()
   {
     Synchronisable::setClient(true);
-    this->gamestate = new GamestateClient();
     if( ClientConnection::establishConnection() )
     {
       Host::setActive(true);
+      GamestateManager::addPeer(NETWORK_PEER_ID_SERVER);
       return true;
     }
     else
@@ -100,10 +99,8 @@
   */
   bool Client::closeConnection()
   {
-    assert(this->gamestate);
-    delete this->gamestate;
-    this->gamestate = 0;
     Host::setActive(false);
+    GamestateManager::removePeer(NETWORK_PEER_ID_SERVER);
     return ClientConnection::closeConnection();
   }
 
@@ -113,11 +110,9 @@
     ClientConnection::setPort(port);
   }
 
-  bool Client::queuePacket(ENetPacket *packet, int clientID)
+  void Client::queuePacket(ENetPacket *packet, int clientID, uint8_t channelID)
   {
-    bool b = ClientConnection::addPacket(packet);
-    assert(b);
-    return b;
+    ClientConnection::addPacket(packet, channelID);
   }
 
   bool Client::processChat(const std::string& message, unsigned int playerID)
@@ -139,7 +134,7 @@
   bool Client::chat(const std::string& message)
   {
     packet::Chat *m = new packet::Chat(message, Host::getPlayerID());
-    return m->send();
+    return m->send(static_cast<Host*>(this));
   }
 
 
@@ -158,28 +153,35 @@
       if ( isConnected() && isSynched_ )
       {
         COUT(4) << "popping partial gamestate: " << std::endl;
-        packet::Gamestate *gs = gamestate->getGamestate();
+//         packet::Gamestate *gs = GamestateClient::getGamestate();
+        GamestateManager::update();
+        std::vector<packet::Gamestate*> gamestates = GamestateManager::getGamestates();
+        std::vector<packet::Gamestate*>::iterator it;
+        for( it = gamestates.begin(); it != gamestates.end(); ++it )
+        {
+          (*it)->send( static_cast<Host*>(this) );
+        }
         //assert(gs); <--- there might be the case that no data has to be sent, so its commented out now
-        if(gs){
-          COUT(4) << "client tick: sending gs " << gs << std::endl;
-          if( !gs->send() )
-            COUT(3) << "Problem adding partial gamestate to queue" << std::endl;
-        // gs gets automatically deleted by enet callback
-        }
-        FunctionCallManager::sendCalls();
+//         if(gs){
+//           COUT(4) << "client tick: sending gs " << gs << std::endl;
+//           if( !gs->send() )
+//             COUT(2) << "Problem adding partial gamestate to queue" << std::endl;
+//         // gs gets automatically deleted by enet callback
+//         }
+        FunctionCallManager::sendCalls(static_cast<Host*>(this));
       }
     }
-    sendPackets(); // flush the enet queue
+//     sendPackets(); // flush the enet queue
 
     Connection::processQueue();
-    if(gamestate->processGamestates())
+    if(GamestateManager::processGamestates())
     {
       FunctionCallManager::processBufferedFunctionCalls();
       if(!isSynched_)
         isSynched_=true;
     }
-    gamestate->cleanup();
-    Connection::sendPackets();
+//     GamestateManager::cleanup();;
+//     Connection::sendPackets();
 
     return;
   }
@@ -199,7 +201,21 @@
     Game::getInstance().popState();
     Game::getInstance().popState();
   }
+  
+  void Client::processPacket(packet::Packet* packet)
+  {
+    if( packet->isReliable() )
+    {
+      if( this->getLastProcessedGamestateID(packet->getPeerID()) >= packet->getRequiredGamestateID() )
+        packet->process(static_cast<Host*>(this));
+      else
+        this->packetQueue_.push_back(packet);
+    }
+    else
+      packet->process(static_cast<Host*>(this));
+  }
 
 
 
+
 }

Modified: code/trunk/src/libraries/network/Client.h
===================================================================
--- code/trunk/src/libraries/network/Client.h	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/libraries/network/Client.h	2010-12-22 18:24:24 UTC (rev 7801)
@@ -44,11 +44,12 @@
 #include "NetworkPrereqs.h"
 
 #include <string>
+#include <deque>
 
 #include "util/UtilPrereqs.h"
 #include "util/Singleton.h"
 #include "ClientConnection.h"
-#include "GamestateClient.h"
+// #include "GamestateClient.h"
 #include "Host.h"
 #include "LANDiscovery.h"
 #include "packet/ServerInformation.h"
@@ -77,7 +78,8 @@
     bool establishConnection();
     void setDestination( const std::string& serverAddress, unsigned int port ); // tolua_export
     bool closeConnection();
-    bool queuePacket(ENetPacket *packet, int clientID);
+    void queuePacket(ENetPacket* packet, int clientID, uint8_t channelID);
+    virtual bool sendPacket( packet::Packet* packet ){ return packet->send( static_cast<Host*>(this) ); }
     bool processChat(const std::string& message, unsigned int playerID);
     virtual bool chat(const std::string& message);
     virtual bool broadcast(const std::string& message) { return false; }
@@ -89,10 +91,11 @@
   private:
     Client(const Client& copy); // not used
     virtual bool isServer_(){return false;}
+    void processPacket(packet::Packet* packet);
 
     static Client* singletonPtr_s;
-    GamestateClient* gamestate;
     bool isSynched_;
+    std::deque<packet::Packet*> packetQueue_;
 
     bool gameStateFailure_;
     float timeSinceLastUpdate_;

Modified: code/trunk/src/libraries/network/ClientConnection.cc
===================================================================
--- code/trunk/src/libraries/network/ClientConnection.cc	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/libraries/network/ClientConnection.cc	2010-12-22 18:24:24 UTC (rev 7801)
@@ -38,7 +38,6 @@
   const unsigned int NETWORK_CLIENT_WAIT_TIME = 1;
   const unsigned int NETWORK_CLIENT_CONNECTION_TIMEOUT = 3000; //millisecs
   const unsigned int NETWORK_CLIENT_MAX_CONNECTIONS = 1;
-  const unsigned int NETWORK_CLIENT_CHANNELS = 1;
 
 
   ClientConnection::ClientConnection():
@@ -70,13 +69,19 @@
   {
     ENetEvent event;
 
-    this->host_ = enet_host_create(NULL, NETWORK_CLIENT_MAX_CONNECTIONS, 0, 0, 0);
+    // create host
+    this->host_ = enet_host_create(NULL, NETWORK_CLIENT_MAX_CONNECTIONS, NETWORK_CHANNEL_COUNT, 0, 0);
+    
     if ( this->host_ == NULL )
     {
       COUT(1) << "ClientConnection: host_ == NULL" << std::endl;
       // error handling
       return false;
     }
+    
+    // enable compression
+    this->enableCompression();
+    
     assert( this->host_->socket4 != ENET_SOCKET_NULL || this->host_->socket6 != ENET_SOCKET_NULL );
     if (this->host_->socket4 == ENET_SOCKET_NULL)
         COUT(2) << "Warning: IPv4 Socket failed." << std::endl;
@@ -85,7 +90,7 @@
     else
         COUT(3) << "Info: Using IPv4 and IPv6 Sockets." << std::endl;
 
-    this->server_ = enet_host_connect(this->host_, serverAddress_, NETWORK_CLIENT_CHANNELS, 0);
+    this->server_ = enet_host_connect(this->host_, serverAddress_, NETWORK_CHANNEL_COUNT, 0);
     if ( this->server_==NULL )
     {
       COUT(1) << "ClientConnection: server_ == NULL" << std::endl;
@@ -98,6 +103,7 @@
       if( enet_host_service(this->host_, &event, NETWORK_CLIENT_WAIT_TIME)>=0 && event.type == ENET_EVENT_TYPE_CONNECT )
       {
         this->established_=true;
+        Connection::startCommunicationThread();
         return true;
       }
     }
@@ -111,6 +117,7 @@
     if ( !this->established_ )
       return true;
     this->established_ = false;
+    Connection::stopCommunicationThread();
     enet_peer_disconnect(this->server_, 0);
     for( unsigned int i=0; i<NETWORK_CLIENT_CONNECTION_TIMEOUT/NETWORK_CLIENT_WAIT_TIME; i++)
     {
@@ -137,10 +144,10 @@
   }
 
 
-  bool ClientConnection::addPacket(ENetPacket *packet) {
+  void ClientConnection::addPacket(ENetPacket *packet, uint8_t channelID) {
     assert( this->server_ );
     assert( packet );
-    return Connection::addPacket( packet, this->server_ );
+    return Connection::addPacket( packet, this->server_, channelID );
   }
 
   void ClientConnection::addPeer(ENetEvent* event)
@@ -152,6 +159,7 @@
     this->established_=false;
     COUT(1) << "Received disconnect Packet from Server!" << endl;
         // server closed the connection
+    this->stopCommunicationThread();
     this->connectionClosed();
   }
 

Modified: code/trunk/src/libraries/network/ClientConnection.h
===================================================================
--- code/trunk/src/libraries/network/ClientConnection.h	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/libraries/network/ClientConnection.h	2010-12-22 18:24:24 UTC (rev 7801)
@@ -43,14 +43,14 @@
     void setServerAddress( const std::string& serverAddress );
     void setPort( unsigned int port );
 
-    ENetEvent *getEvent();
+//     ENetEvent *getEvent();
     // check wheter the packet queue is empty
-    bool queueEmpty();
+//     bool queueEmpty();
     // create a new listener thread
     virtual bool establishConnection();
     virtual bool closeConnection();
     // add a packet to queue for the server
-    bool addPacket(ENetPacket *packet);
+    void addPacket(ENetPacket *packet, uint8_t channelID);
     inline bool isConnected(){ return this->established_; }
   protected:
     virtual void connectionClosed()=0;

Modified: code/trunk/src/libraries/network/ClientInformation.cc
===================================================================
--- code/trunk/src/libraries/network/ClientInformation.cc	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/libraries/network/ClientInformation.cc	2010-12-22 18:24:24 UTC (rev 7801)
@@ -55,7 +55,6 @@
     gamestateID_=GAMESTATEID_INITIAL;
     preve=0;
     nexte=0;
-    partialGamestateID_=GAMESTATEID_INITIAL-1;
     synched_=false;
   }
 
@@ -132,13 +131,6 @@
     return true;
   }
 
-  bool ClientInformation::setPartialGamestateID(int id){
-    if(!this)
-      return false;
-    partialGamestateID_=id;
-    return true;
-  }
-
   unsigned int ClientInformation::getID() {
     if(!this)
       return CLIENTID_UNKNOWN;
@@ -153,16 +145,6 @@
       return NULL;
   }
 
-  int ClientInformation::getFailures(){
-    return failures_;
-  }
-  void ClientInformation::addFailure(){
-    failures_++;
-  }
-  void ClientInformation::resetFailures(){
-    failures_=0;
-  }
-
   uint32_t ClientInformation::getRTT(){
     return this->peer_->roundTripTime;
   }
@@ -178,13 +160,6 @@
       return static_cast<unsigned int>(-1);
   }
 
-  unsigned int ClientInformation::getPartialGamestateID() {
-    if(this)
-      return partialGamestateID_;
-    else
-      return static_cast<unsigned int>(-1);
-  }
-
   ClientInformation *ClientInformation::insertBack(ClientInformation *ins) {
     ClientInformation *temp = head_;
     if(temp==ins){

Modified: code/trunk/src/libraries/network/ClientInformation.h
===================================================================
--- code/trunk/src/libraries/network/ClientInformation.h	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/libraries/network/ClientInformation.h	2010-12-22 18:24:24 UTC (rev 7801)
@@ -65,19 +65,14 @@
     void setID(int clientID);
     bool setPeer(ENetPeer *peer);
     bool setGamestateID(int id);
-    bool setPartialGamestateID(int id);
     inline void setShipID(unsigned int id){ShipID_=id;}
 
     // get functions
     inline unsigned int getShipID(){return ShipID_;}
     unsigned int getID();
     unsigned int getGamestateID();
-    unsigned int getPartialGamestateID();
     ENetPeer *getPeer();
 
-    int getFailures();
-    void addFailure();
-    void resetFailures();
     uint32_t getRTT();
     double getPacketLoss();
 
@@ -105,10 +100,8 @@
     ENetPeer *peer_;
     unsigned int clientID_;
     unsigned int gamestateID_;
-    unsigned int partialGamestateID_;
     unsigned int ShipID_;   // this is the unique objectID
     bool synched_;
-    unsigned short failures_;
 
   };
 

Modified: code/trunk/src/libraries/network/Connection.cc
===================================================================
--- code/trunk/src/libraries/network/Connection.cc	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/libraries/network/Connection.cc	2010-12-22 18:24:24 UTC (rev 7801)
@@ -29,57 +29,162 @@
 #include "Connection.h"
 
 #include <cassert>
+#include <deque>
 #define WIN32_LEAN_AND_MEAN
 #include <enet/enet.h>
+#include <boost/thread.hpp>
+#include <boost/thread/mutex.hpp>
+#include <boost/date_time.hpp>
+
 #include "packet/Packet.h"
 
 namespace orxonox
 {
-//   Connection *Connection::instance_=0;
+  const boost::posix_time::millisec NETWORK_COMMUNICATION_THREAD_WAIT_TIME(20);
 
   Connection::Connection():
-    host_(0)
+    host_(0), bCommunicationThreadRunning_(false)
   {
-//     assert(instance_==0);
-//     Connection::instance_=this;
     enet_initialize();
     atexit(enet_deinitialize);
+    this->incomingEventsMutex_ = new boost::mutex;
+    this->outgoingEventsMutex_ = new boost::mutex;
   }
 
-  Connection::~Connection(){
-//     Connection::instance_=0;
+  Connection::~Connection()
+  {
+    delete this->incomingEventsMutex_;
+    delete this->outgoingEventsMutex_;
   }
 
-  int Connection::service(ENetEvent* event) {
-    return enet_host_service( this->host_, event, NETWORK_WAIT_TIMEOUT );
+  void Connection::startCommunicationThread()
+  {
+    this->bCommunicationThreadRunning_ = true;
+    this->communicationThread_ = new boost::thread(&Connection::communicationThread, this);
   }
+  
+  void Connection::stopCommunicationThread()
+  {
+    this->bCommunicationThreadRunning_ = false;
+    if( !this->communicationThread_->timed_join(NETWORK_COMMUNICATION_THREAD_WAIT_TIME) )
+    {
+      // force thread to stop
+      this->communicationThread_->interrupt();
+    }
+    delete this->communicationThread_;
+  }
 
-  void Connection::disconnectPeer(ENetPeer *peer) {
-    enet_peer_disconnect(peer, 0);
+
+//   int Connection::service(ENetEvent* event) {
+//     return enet_host_service( this->host_, event, NETWORK_WAIT_TIMEOUT );
+//   }
+
+  void Connection::disconnectPeer(ENetPeer *peer)
+  {
+    assert(peer);
+    outgoingEvent outEvent = { peer, outgoingEventType::disconnectPeer, (ENetPacket*)10, 15 };
+    
+    this->outgoingEventsMutex_->lock();
+    this->outgoingEvents_.push_back(outEvent);
+    this->outgoingEventsMutex_->unlock();
   }
 
-  bool Connection::addPacket(ENetPacket *packet, ENetPeer *peer) {
-    if(enet_peer_send(peer, NETWORK_DEFAULT_CHANNEL, packet)!=0)
-      return false;
-    else
-      return true;
+  void Connection::addPacket(ENetPacket *packet, ENetPeer *peer, uint8_t channelID)
+  {
+    assert(peer);
+    outgoingEvent outEvent = { peer, outgoingEventType::sendPacket, packet, channelID };
+    
+    this->outgoingEventsMutex_->lock();
+    this->outgoingEvents_.push_back(outEvent);
+    this->outgoingEventsMutex_->unlock();
   }
+  
+  void Connection::broadcastPacket(ENetPacket* packet, uint8_t channelID)
+  {
+    outgoingEvent outEvent = { (ENetPeer*)15, outgoingEventType::broadcastPacket, packet, channelID };
+    
+    this->outgoingEventsMutex_->lock();
+    this->outgoingEvents_.push_back(outEvent);
+    this->outgoingEventsMutex_->unlock();
+  }
 
-  bool Connection::sendPackets() {
-    if ( /*!Connection::instance_ || */this->host_==NULL )
-      return false;
-    enet_host_flush(this->host_);
-    return true;
+  
+  void Connection::communicationThread()
+  {
+    ENetEvent event;
+    
+    while( bCommunicationThreadRunning_ )
+    {
+      // Receive all pending incoming Events (such as packets, connects and disconnects)
+      while( enet_host_check_events( this->host_, &event ) > 0 )
+      {
+//         COUT(0) << "incoming event" << endl;
+        // received an event
+        this->incomingEventsMutex_->lock();
+        this->incomingEvents_.push_back(event);
+        this->incomingEventsMutex_->unlock();
+      }
+      
+      // Send all waiting outgoing packets
+      this->outgoingEventsMutex_->lock();
+      uint32_t outgoingEventsCount = this->outgoingEvents_.size();
+      this->outgoingEventsMutex_->unlock();
+      while( outgoingEventsCount > 0 )
+      {
+//         COUT(0) << "outgoing event" << endl;
+        this->outgoingEventsMutex_->lock();
+        outgoingEvent outEvent = this->outgoingEvents_.front();
+        this->outgoingEvents_.pop_front();
+        this->outgoingEventsMutex_->unlock();
+        
+        switch( outEvent.type )
+        {
+          case outgoingEventType::sendPacket:
+            enet_peer_send( outEvent.peer, outEvent.channelID, outEvent.packet );
+            break;
+          case outgoingEventType::disconnectPeer:
+            enet_peer_disconnect(outEvent.peer, 0);
+            break;
+          case outgoingEventType::broadcastPacket:
+            enet_host_broadcast( this->host_, outEvent.channelID, outEvent.packet );
+            break;
+          default:
+            assert(0);
+        }
+        this->outgoingEventsMutex_->lock();
+        outgoingEventsCount = this->outgoingEvents_.size();
+        this->outgoingEventsMutex_->unlock();
+      }
+      
+      // Wait for incoming events (at most NETWORK_WAIT_TIMEOUT ms)
+      if( enet_host_service( this->host_, &event, NETWORK_WAIT_TIMEOUT ) > 0 )
+      {
+//         COUT(0) << "incoming event after wait" << endl;
+        //received an event
+        this->incomingEventsMutex_->lock();
+        this->incomingEvents_.push_back(event);
+        this->incomingEventsMutex_->unlock();
+      }
+    }
   }
 
-  void Connection::processQueue() {
+  void Connection::processQueue()
+  {
     ENetEvent event;
 
-    assert(this->host_);
-
-    while( enet_host_service( this->host_, &event, NETWORK_WAIT_TIMEOUT ) > 0 )
+    this->incomingEventsMutex_->lock();
+    uint32_t incomingEventsCount = this->incomingEvents_.size();
+    this->incomingEventsMutex_->unlock();
+    while( incomingEventsCount > 0 )
     {
-      switch(event.type){
+      packet::Packet* p;
+      this->incomingEventsMutex_->lock();
+      event = this->incomingEvents_.front();
+      this->incomingEvents_.pop_front();
+      this->incomingEventsMutex_->unlock();
+      
+      switch(event.type)
+      {
         // log handling ================
         case ENET_EVENT_TYPE_CONNECT:
           addPeer( &event );
@@ -88,17 +193,31 @@
           removePeer( &event );
           break;
         case ENET_EVENT_TYPE_RECEIVE:
-          processPacket( &event );
+//           COUT(0) << "ENET_EVENT_TYPE_RECEIVE" << endl;
+          p = createPacket( &event );
+          processPacket(p);
           break;
         case ENET_EVENT_TYPE_NONE:
           break;
       }
+      
+      this->incomingEventsMutex_->lock();
+      incomingEventsCount = this->incomingEvents_.size();
+      this->incomingEventsMutex_->unlock();
     }
   }
 
-  bool Connection::processPacket(ENetEvent* event) {
+  packet::Packet* Connection::createPacket(ENetEvent* event)
+  {
     packet::Packet *p = packet::Packet::createPacket(event->packet, event->peer);
-    return p->process();
+    return p;
+//     return p->process();
   }
+  
+  void Connection::enableCompression()
+  {
+    enet_host_compress_with_range_coder( this->host_ );
+  }
 
+
 }

Modified: code/trunk/src/libraries/network/Connection.h
===================================================================
--- code/trunk/src/libraries/network/Connection.h	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/libraries/network/Connection.h	2010-12-22 18:24:24 UTC (rev 7801)
@@ -42,37 +42,77 @@
 
 #include "NetworkPrereqs.h"
 
+#include <deque>
+#include <enet/enet.h>
+
+namespace boost
+{
+  class thread;
+  class mutex;
+}
+
 namespace orxonox
 {
-    const unsigned int NETWORK_PORT = 55556;
-    const unsigned int NETWORK_MAX_CONNECTIONS = 50;
-    const unsigned int NETWORK_WAIT_TIMEOUT = 0;
-    const unsigned int NETWORK_DEFAULT_CHANNEL = 0;
-    const unsigned int NETWORK_MAX_QUEUE_PROCESS_TIME = 5;
-
-  class _NetworkExport Connection{
+  const unsigned int NETWORK_PORT                   = 55556;
+  const unsigned int NETWORK_MAX_CONNECTIONS        = 50;
+  const unsigned int NETWORK_WAIT_TIMEOUT           = 1;
+  const unsigned int NETWORK_MAX_QUEUE_PROCESS_TIME = 5;
+  
+  namespace outgoingEventType
+  {
+    enum Value
+    {
+      sendPacket      = 1,
+      disconnectPeer  = 2,
+      broadcastPacket = 3
+    };
+    
+  }
+  
+  struct _NetworkExport outgoingEvent
+  {
+    ENetPeer*                 peer;
+    outgoingEventType::Value  type;
+    ENetPacket*               packet;
+    ENetChannelID             channelID;
+  };
+  
+  class _NetworkExport Connection
+  {
   public:
     virtual ~Connection();
 
-    static bool addPacket(ENetPacket *packet, ENetPeer *peer);
-    bool sendPackets();
-    ENetHost* getHost(){ return this->host_; }
+    void addPacket(ENetPacket *packet, ENetPeer *peer, uint8_t channelID);
+    void broadcastPacket(ENetPacket* packet, uint8_t channelID);
+//     ENetHost* getHost(){ return this->host_; }
 
   protected:
     Connection();
 //     static Connection* getInstance(){ return Connection::instance_; }
 
-    int service(ENetEvent* event);
+//     int service(ENetEvent* event);
+    void startCommunicationThread();
+    void stopCommunicationThread();
+    void communicationThread();
     virtual void disconnectPeer(ENetPeer *peer);
+    
+    void enableCompression();
 
     void processQueue();
     virtual void addPeer(ENetEvent* event)=0;
     virtual void removePeer(ENetEvent* event)=0;
-    virtual bool processPacket(ENetEvent* event);
+    virtual void processPacket( packet::Packet* packet)=0;
+    virtual packet::Packet* createPacket(ENetEvent* event);
 
-    ENetHost *host_;
+    ENetHost*                   host_;
   private:
-    ENetAddress *bindAddress_;
+    boost::thread*              communicationThread_;
+    bool                        bCommunicationThreadRunning_;
+    ENetAddress*                bindAddress_;
+    std::deque<ENetEvent>       incomingEvents_;
+    std::deque<outgoingEvent>   outgoingEvents_;
+    boost::mutex*               incomingEventsMutex_;
+    boost::mutex*               outgoingEventsMutex_;
 
 //     static Connection *instance_;
 

Modified: code/trunk/src/libraries/network/FunctionCallManager.cc
===================================================================
--- code/trunk/src/libraries/network/FunctionCallManager.cc	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/libraries/network/FunctionCallManager.cc	2010-12-22 18:24:24 UTC (rev 7801)
@@ -29,155 +29,157 @@
 #include "FunctionCallManager.h"
 #include "packet/FunctionCalls.h"
 #include "core/GameMode.h"
+#include "GamestateHandler.h"
 
 namespace orxonox {
 
-std::map<uint32_t, packet::FunctionCalls*> FunctionCallManager::sClientMap_;
-std::vector<FunctionCall> FunctionCallManager::sIncomingFunctionCallBuffer_;
+std::map<uint32_t, packet::FunctionCalls*> FunctionCallManager::sPeerMap_;
+std::vector<std::pair<FunctionCall, std::pair<uint32_t, uint32_t> > > FunctionCallManager::sIncomingFunctionCallBuffer_;
 
 // Static calls
 
-void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t clientID)
+void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t peerID)
 {
-  if(sClientMap_.find(clientID)==sClientMap_.end())
+  if(sPeerMap_.find(peerID)==sPeerMap_.end())
   {
-    FunctionCallManager::sClientMap_[clientID] = new packet::FunctionCalls;
-    FunctionCallManager::sClientMap_[clientID]->setClientID(clientID);
+    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
+    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
   }
-  FunctionCallManager::sClientMap_[clientID]->addCallStatic(functionID);
+  FunctionCallManager::sPeerMap_[peerID]->addCallStatic(functionID);
 }
-void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1)
+void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1)
 {
-  if(sClientMap_.find(clientID)==sClientMap_.end())
+  if(sPeerMap_.find(peerID)==sPeerMap_.end())
   {
-    FunctionCallManager::sClientMap_[clientID] = new packet::FunctionCalls;
-    FunctionCallManager::sClientMap_[clientID]->setClientID(clientID);
+    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
+    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
   }
-  FunctionCallManager:: sClientMap_[clientID]->addCallStatic(functionID, &mt1);
+  FunctionCallManager:: sPeerMap_[peerID]->addCallStatic(functionID, &mt1);
 }
-void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2)
+void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2)
 {
-  if(sClientMap_.find(clientID)==sClientMap_.end())
+  if(sPeerMap_.find(peerID)==sPeerMap_.end())
   {
-    FunctionCallManager::sClientMap_[clientID] = new packet::FunctionCalls;
-    FunctionCallManager::sClientMap_[clientID]->setClientID(clientID);
+    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
+    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
   }
-  FunctionCallManager:: sClientMap_[clientID]->addCallStatic(functionID, &mt1, &mt2);
+  FunctionCallManager:: sPeerMap_[peerID]->addCallStatic(functionID, &mt1, &mt2);
 }
-void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3)
+void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3)
 {
-  if(sClientMap_.find(clientID)==sClientMap_.end())
+  if(sPeerMap_.find(peerID)==sPeerMap_.end())
   {
-    FunctionCallManager::sClientMap_[clientID] = new packet::FunctionCalls;
-    FunctionCallManager::sClientMap_[clientID]->setClientID(clientID);
+    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
+    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
   }
-  FunctionCallManager:: sClientMap_[clientID]->addCallStatic(functionID, &mt1, &mt2, &mt3);
+  FunctionCallManager:: sPeerMap_[peerID]->addCallStatic(functionID, &mt1, &mt2, &mt3);
 }
-void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4)
+void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4)
 {
-  if(sClientMap_.find(clientID)==sClientMap_.end())
+  if(sPeerMap_.find(peerID)==sPeerMap_.end())
   {
-    FunctionCallManager::sClientMap_[clientID] = new packet::FunctionCalls;
-    FunctionCallManager::sClientMap_[clientID]->setClientID(clientID);
+    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
+    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
   }
-  FunctionCallManager:: sClientMap_[clientID]->addCallStatic(functionID, &mt1, &mt2, &mt3, &mt4);
+  FunctionCallManager:: sPeerMap_[peerID]->addCallStatic(functionID, &mt1, &mt2, &mt3, &mt4);
 }
-void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5)
+void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5)
 {
-  if(sClientMap_.find(clientID)==sClientMap_.end())
+  if(sPeerMap_.find(peerID)==sPeerMap_.end())
   {
-    FunctionCallManager::sClientMap_[clientID] = new packet::FunctionCalls;
-    FunctionCallManager::sClientMap_[clientID]->setClientID(clientID);
+    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
+    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
   }
-  FunctionCallManager:: sClientMap_[clientID]->addCallStatic(functionID, &mt1, &mt2, &mt3, &mt4, &mt5);
+  FunctionCallManager:: sPeerMap_[peerID]->addCallStatic(functionID, &mt1, &mt2, &mt3, &mt4, &mt5);
 }
 
 
 // MemberCalls
 
-void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID)
+void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID)
 {
-  if(sClientMap_.find(clientID)==sClientMap_.end())
+  if(sPeerMap_.find(peerID)==sPeerMap_.end())
   {
-    FunctionCallManager::sClientMap_[clientID] = new packet::FunctionCalls;
-    FunctionCallManager::sClientMap_[clientID]->setClientID(clientID);
+    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
+    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
   }
-  FunctionCallManager::sClientMap_[clientID]->addCallMember(functionID, objectID);
+  FunctionCallManager::sPeerMap_[peerID]->addCallMember(functionID, objectID);
 }
-void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1)
+void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1)
 {
-  if(sClientMap_.find(clientID)==sClientMap_.end())
+  if(sPeerMap_.find(peerID)==sPeerMap_.end())
   {
-    FunctionCallManager::sClientMap_[clientID] = new packet::FunctionCalls;
-    FunctionCallManager::sClientMap_[clientID]->setClientID(clientID);
+    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
+    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
   }
-  FunctionCallManager::sClientMap_[clientID]->addCallMember(functionID, objectID, &mt1);
+  FunctionCallManager::sPeerMap_[peerID]->addCallMember(functionID, objectID, &mt1);
 }
-void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2)
+void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2)
 {
-  if(sClientMap_.find(clientID)==sClientMap_.end())
+  if(sPeerMap_.find(peerID)==sPeerMap_.end())
   {
-    FunctionCallManager::sClientMap_[clientID] = new packet::FunctionCalls;
-    FunctionCallManager::sClientMap_[clientID]->setClientID(clientID);
+    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
+    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
   }
-  FunctionCallManager::sClientMap_[clientID]->addCallMember(functionID, objectID, &mt1, &mt2);
+  FunctionCallManager::sPeerMap_[peerID]->addCallMember(functionID, objectID, &mt1, &mt2);
 }
-void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3)
+void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3)
 {
-  if(sClientMap_.find(clientID)==sClientMap_.end())
+  if(sPeerMap_.find(peerID)==sPeerMap_.end())
   {
-    FunctionCallManager::sClientMap_[clientID] = new packet::FunctionCalls;
-    FunctionCallManager::sClientMap_[clientID]->setClientID(clientID);
+    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
+    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
   }
-  FunctionCallManager::sClientMap_[clientID]->addCallMember(functionID, objectID, &mt1, &mt2, &mt3);
+  FunctionCallManager::sPeerMap_[peerID]->addCallMember(functionID, objectID, &mt1, &mt2, &mt3);
 }
-void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4)
+void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4)
 {
-  if(sClientMap_.find(clientID)==sClientMap_.end())
+  if(sPeerMap_.find(peerID)==sPeerMap_.end())
   {
-    FunctionCallManager::sClientMap_[clientID] = new packet::FunctionCalls;
-    FunctionCallManager::sClientMap_[clientID]->setClientID(clientID);
+    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
+    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
   }
-  FunctionCallManager::sClientMap_[clientID]->addCallMember(functionID, objectID, &mt1, &mt2, &mt3, &mt4);
+  FunctionCallManager::sPeerMap_[peerID]->addCallMember(functionID, objectID, &mt1, &mt2, &mt3, &mt4);
 }
-void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5)
+void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5)
 {
-  if(sClientMap_.find(clientID)==sClientMap_.end())
+  if(sPeerMap_.find(peerID)==sPeerMap_.end())
   {
-    FunctionCallManager::sClientMap_[clientID] = new packet::FunctionCalls;
-    FunctionCallManager::sClientMap_[clientID]->setClientID(clientID);
+    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
+    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
   }
-  FunctionCallManager::sClientMap_[clientID]->addCallMember(functionID, objectID, &mt1, &mt2, &mt3, &mt4, &mt5);
+  FunctionCallManager::sPeerMap_[peerID]->addCallMember(functionID, objectID, &mt1, &mt2, &mt3, &mt4, &mt5);
 }
 
 // Send calls
 
-void FunctionCallManager::sendCalls()
+void FunctionCallManager::sendCalls(orxonox::Host* host)
 {
   std::map<uint32_t, packet::FunctionCalls*>::iterator it;
-  for (it = FunctionCallManager::sClientMap_.begin(); it != FunctionCallManager::sClientMap_.end(); ++it )
+  for (it = FunctionCallManager::sPeerMap_.begin(); it != FunctionCallManager::sPeerMap_.end(); ++it )
   {
-    assert(!FunctionCallManager::sClientMap_.empty());
-    it->second->send();
+    assert(!FunctionCallManager::sPeerMap_.empty());
+    it->second->send(host);
   }
-  FunctionCallManager::sClientMap_.clear();
+  FunctionCallManager::sPeerMap_.clear();
 }
 
-void FunctionCallManager::bufferIncomingFunctionCall(const orxonox::FunctionCall& fctCall)
+void FunctionCallManager::bufferIncomingFunctionCall(const orxonox::FunctionCall& fctCall, uint32_t minGamestateID, uint32_t peerID)
 {
-  if( !GameMode::isMaster() )
-    FunctionCallManager::sIncomingFunctionCallBuffer_.push_back( fctCall );
+  FunctionCallManager::sIncomingFunctionCallBuffer_.push_back( std::make_pair(fctCall, std::make_pair(minGamestateID, peerID)));
 }
 
 void FunctionCallManager::processBufferedFunctionCalls()
 {
-  std::vector<FunctionCall>::iterator it = FunctionCallManager::sIncomingFunctionCallBuffer_.begin();
+  std::vector<std::pair<FunctionCall, std::pair<uint32_t, uint32_t> > >::iterator it = FunctionCallManager::sIncomingFunctionCallBuffer_.begin();
   while( it!=FunctionCallManager::sIncomingFunctionCallBuffer_.end() )
   {
-    if( it->execute() )
+    if( it->first.execute() )
       FunctionCallManager::sIncomingFunctionCallBuffer_.erase(it);
     else
+    {
       ++it;
+    }
   }
 }
 

Modified: code/trunk/src/libraries/network/FunctionCallManager.h
===================================================================
--- code/trunk/src/libraries/network/FunctionCallManager.h	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/libraries/network/FunctionCallManager.h	2010-12-22 18:24:24 UTC (rev 7801)
@@ -33,6 +33,7 @@
 
 #include <map>
 #include <vector>
+#include <utility>
 #include "util/UtilPrereqs.h"
 #include "FunctionCall.h"
 
@@ -44,27 +45,27 @@
 class _NetworkExport FunctionCallManager
 {
 public:
-  static void addCallStatic(uint32_t functionID, uint32_t clientID);
-  static void addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1);
-  static void addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2);
-  static void addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3);
-  static void addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4);
-  static void addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5);
+  static void addCallStatic(uint32_t functionID, uint32_t peerID);
+  static void addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1);
+  static void addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2);
+  static void addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3);
+  static void addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4);
+  static void addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5);
 
-  static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID);
-  static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1);
-  static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2);
-  static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3);
-  static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4);
-  static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5);
+  static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID);
+  static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1);
+  static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2);
+  static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3);
+  static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4);
+  static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5);
 
-  static void sendCalls();
+  static void sendCalls(orxonox::Host* host);
   
-  static void bufferIncomingFunctionCall( const FunctionCall& fctCall );
+  static void bufferIncomingFunctionCall( const FunctionCall& fctCall, uint32_t minGamestateID, uint32_t peerID );
   static void processBufferedFunctionCalls();
 
-  static std::map<uint32_t, packet::FunctionCalls*> sClientMap_;
-  static std::vector<FunctionCall>                  sIncomingFunctionCallBuffer_;
+  static std::map<uint32_t, packet::FunctionCalls*>                           sPeerMap_;
+  static std::vector<std::pair<FunctionCall,std::pair<uint32_t, uint32_t> > > sIncomingFunctionCallBuffer_;
 protected:
   FunctionCallManager();
   ~FunctionCallManager();

Modified: code/trunk/src/libraries/network/GamestateClient.cc
===================================================================
--- code/trunk/src/libraries/network/GamestateClient.cc	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/libraries/network/GamestateClient.cc	2010-12-22 18:24:24 UTC (rev 7801)
@@ -38,19 +38,22 @@
 
 namespace orxonox
 {
-  struct _NetworkExport GameStateItem{
+  struct _NetworkExport GameStateItem
+  {
     packet::Gamestate *state;
     unsigned int id;
   };
 
-  GamestateClient::GamestateClient() {
+  GamestateClient::GamestateClient()
+  {
     COUT(5) << "this: " << this << std::endl;
-    last_diff_=0;
-    last_gamestate_=GAMESTATEID_INITIAL-1;
+    lastAckedGamestateID_=GAMESTATEID_INITIAL-1;
+    lastProcessedGamestateID_=GAMESTATEID_INITIAL-1;
     tempGamestate_=NULL;
   }
 
-  GamestateClient::~GamestateClient() {
+  GamestateClient::~GamestateClient()
+  {
       std::map<unsigned int, packet::Gamestate *>::iterator it;
       for ( it = this->gamestateMap_.begin(); it != this->gamestateMap_.end(); ++it )
           delete it->second;
@@ -58,12 +61,15 @@
           delete this->tempGamestate_;
   }
 
-  bool GamestateClient::ack(unsigned int gamestateID, unsigned int clientID){
+  bool GamestateClient::ackGamestate(unsigned int gamestateID, unsigned int clientID)
+  {
     return true;
   }
 
-  bool GamestateClient::add(packet::Gamestate *gs, unsigned int clientID){
-    if(tempGamestate_!=NULL){
+  bool GamestateClient::addGamestate(packet::Gamestate *gs, unsigned int clientID)
+  {
+    if(tempGamestate_!=NULL)
+    {
       //delete the obsolete gamestate
       if(tempGamestate_->getID()>gs->getID())
         return false;
@@ -73,7 +79,8 @@
     return true;
   }
 
-  bool GamestateClient::processGamestates(){
+  bool GamestateClient::processGamestates()
+  {
     if(tempGamestate_==NULL)
       return false;
     bool isDiffed = tempGamestate_->isDiffed();
@@ -84,15 +91,18 @@
     //now call the queued callbacks
     NetworkCallbackManager::callCallbacks();
 
-    if (!processed){
+    if (!processed)
+    {
+      assert(0);
       sendAck(0);
       return false;
     }
     //successfully loaded data from gamestate. now save gamestate for diff and delete the old gs
     tempGamestate_=NULL;
     gamestateMap_[processed->getID()]=processed;
+    lastProcessedGamestateID_ = processed->getID();
     if(isDiffed)
-      last_diff_ = processed->getBaseID();
+      lastAckedGamestateID_ = processed->getBaseID();
     id = processed->getID();
     sendAck(id);
     return true;
@@ -104,25 +114,30 @@
   * @param it iterator of the list pointing to the object
   * @return iterator pointing to the next object in the list
   */
-  void GamestateClient::removeObject(ObjectListIterator<Synchronisable> &it) {
+  void GamestateClient::removeObject(ObjectListIterator<Synchronisable> &it)
+  {
     ObjectListIterator<Synchronisable> temp=it;
     ++it;
     temp->destroy(); // or delete?
   }
 
-  packet::Gamestate *GamestateClient::getGamestate(){
+  packet::Gamestate *GamestateClient::getGamestate()
+  {
     packet::Gamestate *gs = new packet::Gamestate();
-    if(!gs->collectData(0,0x2)){
+    if(!gs->collectData(this->getLastProcessedGamestateID(NETWORK_PEER_ID_SERVER), 0x2))
+    {
       delete gs;
       return 0;
     }
     return gs;
   }
 
-  void GamestateClient::cleanup(){
+  void GamestateClient::cleanup()
+  {
     std::map<unsigned int, packet::Gamestate*>::iterator temp, it = gamestateMap_.begin();
-    while(it!=gamestateMap_.end()){
-      if(it->first>=last_diff_)
+    while(it!=gamestateMap_.end())
+    {
+      if(it->first>=lastAckedGamestateID_)
         break;
       // otherwise delete that stuff
       delete it->second;
@@ -132,29 +147,35 @@
     tempGamestate_=NULL;
   }
 
-  void GamestateClient::printGamestateMap(){
+  void GamestateClient::printGamestateMap()
+  {
     std::map<unsigned int, packet::Gamestate*>::iterator it;
     COUT(4) << "gamestates: ";
-    for(it=gamestateMap_.begin(); it!=gamestateMap_.end(); it++){
+    for(it=gamestateMap_.begin(); it!=gamestateMap_.end(); it++)
+    {
       COUT(4) << it->first << ':' << it->second << '|';
     }
     COUT(4) << std::endl;
 
   }
 
-  bool GamestateClient::sendAck(unsigned int gamestateID){
+  bool GamestateClient::sendAck(unsigned int gamestateID)
+  {
     packet::Acknowledgement *ack = new packet::Acknowledgement(gamestateID, 0);
-    if(!ack->send()){
+    if(!ack->send())
+    {
       COUT(3) << "could not ack gamestate: " << gamestateID << std::endl;
       return false;
     }
-    else{
+    else
+    {
       COUT(5) << "acked a gamestate: " << gamestateID << std::endl;
       return true;
     }
   }
 
-  packet::Gamestate *GamestateClient::processGamestate(packet::Gamestate *gs){
+  packet::Gamestate *GamestateClient::processGamestate(packet::Gamestate *gs)
+  {
     if(gs->isCompressed())
     {
       bool b = gs->decompressData();

Modified: code/trunk/src/libraries/network/GamestateClient.h
===================================================================
--- code/trunk/src/libraries/network/GamestateClient.h	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/libraries/network/GamestateClient.h	2010-12-22 18:24:24 UTC (rev 7801)
@@ -56,8 +56,10 @@
     GamestateClient();
     ~GamestateClient();
 
-    bool add(packet::Gamestate *gs, unsigned int clientID);
-    bool ack(unsigned int gamestateID, unsigned int clientID);
+    virtual bool      addGamestate(packet::Gamestate *gs, unsigned int clientID);
+    virtual bool      ackGamestate(unsigned int gamestateID, unsigned int clientID);
+    virtual uint32_t  getLastProcessedGamestateID(unsigned int clientID=0) { return this->lastProcessedGamestateID_; }
+    virtual uint32_t  getCurrentGamestateID(){ return this->lastProcessedGamestateID_; }
 
     bool processGamestates();
     packet::Gamestate *getGamestate();
@@ -68,8 +70,8 @@
     void printGamestateMap();
     bool sendAck(unsigned int gamestateID);
 
-    unsigned int           last_diff_;
-    unsigned int           last_gamestate_;
+    unsigned int           lastAckedGamestateID_;
+    unsigned int           lastProcessedGamestateID_;
     std::map<unsigned int, packet::Gamestate *> gamestateMap_;
     packet::Gamestate *tempGamestate_; // we save the received gamestates here during processQueue
 

Modified: code/trunk/src/libraries/network/GamestateHandler.cc
===================================================================
--- code/trunk/src/libraries/network/GamestateHandler.cc	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/libraries/network/GamestateHandler.cc	2010-12-22 18:24:24 UTC (rev 7801)
@@ -31,18 +31,15 @@
 
 namespace orxonox {
 
-GamestateHandler *GamestateHandler::instance_=0;
+// GamestateHandler *GamestateHandler::instance_=0;
 
 GamestateHandler::GamestateHandler()
 {
-  assert(instance_==0);
-  instance_=this;
 }
 
 
 GamestateHandler::~GamestateHandler()
 {
-  instance_=0;
 }
 
 

Modified: code/trunk/src/libraries/network/GamestateHandler.h
===================================================================
--- code/trunk/src/libraries/network/GamestateHandler.h	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/libraries/network/GamestateHandler.h	2010-12-22 18:24:24 UTC (rev 7801)
@@ -31,26 +31,27 @@
 
 #include "NetworkPrereqs.h"
 
+#include <cassert>
+
 namespace orxonox {
 
 /**
     @author Oliver Scheuss
 */
-class _NetworkExport GamestateHandler{
+class _NetworkExport GamestateHandler
+{
   private:
-    virtual bool add(packet::Gamestate *gs, unsigned int clientID)=0;
-    virtual bool ack(unsigned int gamestateID, unsigned int clientID)=0;
 
-    static GamestateHandler *instance_;
 
-
   protected:
     GamestateHandler();
     virtual ~GamestateHandler();
 
   public:
-    static bool addGamestate(packet::Gamestate *gs, unsigned int clientID){ return instance_->add(gs, clientID); }
-    static bool ackGamestate(unsigned int gamestateID, unsigned int clientID){ return instance_->ack(gamestateID, clientID); }
+    virtual bool      addGamestate(packet::Gamestate* gs, unsigned int clientID) = 0;
+    virtual bool      ackGamestate(unsigned int gamestateID, unsigned int clientID) = 0;
+    virtual uint32_t  getLastProcessedGamestateID( unsigned int clientID )=0;
+    virtual uint32_t  getCurrentGamestateID()=0;
 };
 
 }

Modified: code/trunk/src/libraries/network/GamestateManager.cc
===================================================================
--- code/trunk/src/libraries/network/GamestateManager.cc	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/libraries/network/GamestateManager.cc	2010-12-22 18:24:24 UTC (rev 7801)
@@ -42,42 +42,43 @@
 
 #include <cassert>
 #include <queue>
-#include "util/Clock.h"
 // #include <boost/thread/mutex.hpp>
 
-#include "util/Debug.h"
-#include "core/ThreadPool.h"
-#include "core/command/Executor.h"
-#include "ClientInformation.h"
 #include "packet/Acknowledgement.h"
 #include "packet/Gamestate.h"
 #include "synchronisable/NetworkCallbackManager.h"
-#include "TrafficControl.h"
 
+#include "core/ThreadPool.h"
+#include "core/command/Executor.h"
+#include "core/GameMode.h"
+#include "util/Debug.h"
+#include "util/Clock.h"
+// #include "TrafficControl.h"
+
 namespace orxonox
 {
   GamestateManager::GamestateManager() :
-  reference(0), id_(0)
+  currentGamestate_(0), id_(0)
   {
-    trafficControl_ = new TrafficControl();
+//     trafficControl_ = new TrafficControl();
 //     threadMutex_ = new boost::mutex();
 //     threadPool_ = new ThreadPool();
   }
 
   GamestateManager::~GamestateManager()
   {
-    if( this->reference )
-        delete this->reference;std::map<unsigned int, packet::Gamestate*>::iterator it;
+    if( this->currentGamestate_ )
+        delete this->currentGamestate_;std::map<unsigned int, packet::Gamestate*>::iterator it;
     for( it = gamestateQueue.begin(); it != gamestateQueue.end(); ++it )
       delete it->second;
-    std::map<unsigned int, std::map<unsigned int, packet::Gamestate*> >::iterator it1;
-    std::map<unsigned int, packet::Gamestate*>::iterator it2;
-    for( it1 = gamestateMap_.begin(); it1 != gamestateMap_.end(); ++it1 )
+    std::map<uint32_t, peerInfo>::iterator peerIt;
+    std::map<uint32_t, packet::Gamestate*>::iterator gamestateIt;
+    for( peerIt = peerMap_.begin(); peerIt != peerMap_.end(); ++peerIt )
     {
-      for( it2 = it1->second.begin(); it2 != it1->second.end(); ++it2 )
-        delete it2->second;
+      for( gamestateIt = peerIt->second.gamestates.begin(); gamestateIt != peerIt->second.gamestates.end(); ++gamestateIt )
+        delete gamestateIt->second;
     }
-    this->trafficControl_->destroy();
+//     this->trafficControl_->destroy();
 //     delete this->threadMutex_;
 //     delete this->threadPool_;
   }
@@ -87,7 +88,8 @@
     return getSnapshot();
   }
 
-  bool GamestateManager::add(packet::Gamestate *gs, unsigned int clientID){
+  bool GamestateManager::addGamestate(packet::Gamestate *gs, unsigned int clientID)
+  {
     assert(gs);
     std::map<unsigned int, packet::Gamestate*>::iterator it = gamestateQueue.find(clientID);
     if(it!=gamestateQueue.end()){
@@ -98,7 +100,8 @@
     return true;
   }
 
-  bool GamestateManager::processGamestates(){
+  bool GamestateManager::processGamestates()
+  {
     if( this->gamestateQueue.empty() )
         return true;
     std::map<unsigned int, packet::Gamestate*>::iterator it;
@@ -106,6 +109,7 @@
     for(it = gamestateQueue.begin(); it!=gamestateQueue.end(); it++){
       bool b = processGamestate(it->second);
       assert(b);
+      sendAck( it->second->getID(), it->second->getPeerID() );
       delete it->second;
     }
     // now clear the queue
@@ -114,73 +118,94 @@
     NetworkCallbackManager::callCallbacks();
     return true;
   }
+  
+  bool GamestateManager::sendAck(unsigned int gamestateID, uint32_t peerID)
+  {
+    packet::Acknowledgement *ack = new packet::Acknowledgement(gamestateID, peerID);
+    if( !this->sendPacket(ack))
+    {
+      COUT(3) << "could not ack gamestate: " << gamestateID << std::endl;
+      return false;
+    }
+    else
+    {
+      COUT(5) << "acked a gamestate: " << gamestateID << std::endl;
+      return true;
+    }
+  }
 
 
   bool GamestateManager::getSnapshot(){
-    if ( reference != 0 )
-      delete reference;
-    reference = new packet::Gamestate();
-    if(!reference->collectData(++id_, 0x1)){ //we have no data to send
-      delete reference;
-      reference=0;
+    if ( currentGamestate_ != 0 )
+      delete currentGamestate_;
+    currentGamestate_ = new packet::Gamestate();
+    uint8_t gsMode;
+    if( GameMode::isMaster() )
+      gsMode = packet::GAMESTATE_MODE_SERVER;
+    else
+      gsMode = packet::GAMESTATE_MODE_CLIENT;
+    uint32_t newID;
+    if( GameMode::isMaster() )
+      newID = ++id_;
+    else
+      newID = peerMap_[NETWORK_PEER_ID_SERVER].lastProcessedGamestateID;
+    
+    if(!currentGamestate_->collectData(newID, gsMode)){ //we have no data to send
+      delete currentGamestate_;
+      currentGamestate_=0;
     }
     return true;
   }
 
-  void GamestateManager::sendGamestates()
+  std::vector<packet::Gamestate*> GamestateManager::getGamestates()
   {
-    ClientInformation *temp = ClientInformation::getBegin();
-    std::queue<packet::Gamestate*> clientGamestates;
-    while(temp != NULL){
-      if( !(temp->getSynched()) ){
+    if(!currentGamestate_)
+      return std::vector<packet::Gamestate*>();
+    std::vector<packet::Gamestate*> peerGamestates;
+    
+    std::map<uint32_t, peerInfo>::iterator peerIt;
+    for( peerIt=peerMap_.begin(); peerIt!=peerMap_.end(); ++peerIt )
+    {
+      if( !peerIt->second.isSynched )
+      {
         COUT(5) << "Server: not sending gamestate" << std::endl;
-        temp=temp->next();
-        if(!temp)
-          break;
         continue;
       }
-      COUT(4) << "client id: " << temp->getID() << " RTT: " << temp->getRTT() << " loss: " << temp->getPacketLoss() << std::endl;
+      COUT(4) << "client id: " << peerIt->first << std::endl;
       COUT(5) << "Server: doing gamestate gamestate preparation" << std::endl;
-      int cid = temp->getID(); //get client id
+      int peerID = peerIt->first; //get client id
 
-      unsigned int gID = temp->getGamestateID();
-      if(!reference)
-        return;
+      unsigned int lastAckedGamestateID = peerIt->second.lastAckedGamestateID;
 
-      packet::Gamestate *client=0;
-      if(gID != GAMESTATEID_INITIAL){
-        assert(gamestateMap_.find(cid)!=gamestateMap_.end());
-        std::map<unsigned int, packet::Gamestate*>::iterator it = gamestateMap_[cid].find(gID);
-        if(it!=gamestateMap_[cid].end())
-        {
-          client = it->second;
-        }
+      packet::Gamestate* baseGamestate=0;
+      if(lastAckedGamestateID != GAMESTATEID_INITIAL)
+      {
+        assert(peerMap_.find(peerID)!=peerMap_.end());
+        std::map<uint32_t, packet::Gamestate*>::iterator it = peerMap_[peerID].gamestates.find(lastAckedGamestateID);
+        assert(it!=peerMap_[peerID].gamestates.end());
+        baseGamestate = it->second;
       }
 
-      clientGamestates.push(0);
-      finishGamestate( cid, clientGamestates.back(), client, reference );
+      peerGamestates.push_back(0);  // insert an empty gamestate* to change
+      finishGamestate( peerID, peerGamestates.back(), baseGamestate, currentGamestate_ );
+      if( peerGamestates.back()==0 )
+        // nothing to send to remove pointer from vector
+        peerGamestates.pop_back();
       //FunctorMember<GamestateManager>* functor =
 //       ExecutorMember<GamestateManager>* executor = createExecutor( createFunctor(&GamestateManager::finishGamestate, this) );
-//       executor->setDefaultValues( cid, &clientGamestates.back(), client, reference );
+//       executor->setDefaultValues( cid, &clientGamestates.back(), client, currentGamestate_ );
 //       (*static_cast<Executor*>(executor))();
 //       this->threadPool_->passFunction( executor, true );
-//       (*functor)( cid, &(clientGamestates.back()), client, reference );
-
-      temp = temp->next();
+//       (*functor)( cid, &(clientGamestates.back()), client, currentGamestate_ );
     }
 
 //     threadPool_->synchronise();
 
-    while( !clientGamestates.empty() )
-    {
-      if(clientGamestates.front())
-        clientGamestates.front()->send();
-      clientGamestates.pop();
-    }
+    return peerGamestates;
   }
 
 
-  void GamestateManager::finishGamestate( unsigned int clientID, packet::Gamestate*& destgamestate, packet::Gamestate* base, packet::Gamestate* gamestate ) {
+  void GamestateManager::finishGamestate( unsigned int peerID, packet::Gamestate*& destgamestate, packet::Gamestate* base, packet::Gamestate* gamestate ) {
     //why are we searching the same client's gamestate id as we searched in
     //Server::sendGameState?
     // save the (undiffed) gamestate in the clients gamestate map
@@ -193,10 +218,10 @@
 //     packet::Gamestate *gs = new packet::Gamestate();
 //     gs->collectData( id_, 0x1 );
 //     this->threadMutex_->lock();
-    gamestateMap_[clientID][gamestate->getID()]=gs;
+    peerMap_[peerID].gamestates[gamestate->getID()]=gs;
 //     this->threadMutex_->unlock();
-      Clock clock;
-      clock.capture();
+    Clock clock;
+    clock.capture();
 
     if(base)
     {
@@ -215,68 +240,130 @@
     }
 
 
-    bool b = gs->compressData();
-    assert(b);
-      clock.capture();
-      COUT(0) << "diff time: " << clock.getDeltaTime() << endl;
+//     bool b = gs->compressData();
+//     assert(b);
+    clock.capture();
+    COUT(4) << "diff and compress time: " << clock.getDeltaTime() << endl;
 //     COUT(5) << "sending gamestate with id " << gs->getID();
 //     if(gamestate->isDiffed())
 //       COUT(5) << " and baseid " << gs->getBaseID() << endl;
 //     else
 //       COUT(5) << endl;
-    gs->setClientID(clientID);
+    gs->setPeerID(peerID);
     destgamestate = gs;
   }
 
 
-  bool GamestateManager::ack(unsigned int gamestateID, unsigned int clientID) {
-    ClientInformation *temp = ClientInformation::findClient(clientID);
-    assert(temp);
-    unsigned int curid = temp->getGamestateID();
+  bool GamestateManager::ackGamestate(unsigned int gamestateID, unsigned int peerID)
+  {
+//     ClientInformation *temp = ClientInformation::findClient(peerID);
+//     assert(temp);
+    std::map<uint32_t, peerInfo>::iterator it = this->peerMap_.find(peerID);
+    assert(it!=this->peerMap_.end());
+    unsigned int curid = it->second.lastAckedGamestateID;
 
     if(gamestateID == ACKID_NACK){
-      temp->setGamestateID(GAMESTATEID_INITIAL);
+      it->second.lastAckedGamestateID = GAMESTATEID_INITIAL;
+//       temp->setGamestateID(GAMESTATEID_INITIAL);
       // now delete all saved gamestates for this client
-      std::map<unsigned int, packet::Gamestate*>::iterator it;
-      for(it = gamestateMap_[clientID].begin(); it!=gamestateMap_[clientID].end(); ){
-        delete it->second;
-
-        gamestateMap_[clientID].erase(it++);
+      std::map<uint32_t, packet::Gamestate*>::iterator it2;
+      for(it2 = it->second.gamestates.begin(); it2!=it->second.gamestates.end(); ++it2 ){
+        delete it2->second;
       }
+      it->second.gamestates.clear();
       return true;
     }
 
-    assert(curid==GAMESTATEID_INITIAL || curid<gamestateID);
-    COUT(5) << "acking gamestate " << gamestateID << " for clientid: " << clientID << " curid: " << curid << std::endl;
-    std::map<unsigned int, packet::Gamestate*>::iterator it;
-    for(it = gamestateMap_[clientID].begin(); it!=gamestateMap_[clientID].end() && it->first<gamestateID; ){
-      delete it->second;
-      gamestateMap_[clientID].erase(it++);
+    assert(curid==GAMESTATEID_INITIAL || curid<=gamestateID);
+    COUT(5) << "acking gamestate " << gamestateID << " for peerID: " << peerID << " curid: " << curid << std::endl;
+    std::map<uint32_t, packet::Gamestate*>::iterator it2;
+    for( it2=it->second.gamestates.begin(); it2!=it->second.gamestates.end(); )
+    {
+      if( it2->second->getID() < gamestateID )
+      {
+        delete it2->second;
+        it->second.gamestates.erase(it2++);
+      }
+      else
+        ++it2;
     }
-    temp->setGamestateID(gamestateID);
-    TrafficControl::processAck(clientID, gamestateID);
+    
+//     std::map<unsigned int, packet::Gamestate*>::iterator it;
+//     for(it = gamestateMap_[peerID].begin(); it!=gamestateMap_[peerID].end() && it->first<gamestateID; ){
+//       delete it->second;
+//       gamestateMap_[peerID].erase(it++);
+//     }
+    it->second.lastAckedGamestateID = gamestateID;
+//     temp->setGamestateID(gamestateID);
+//     TrafficControl::processAck(peerID, gamestateID);
     return true;
   }
+  
+  uint32_t GamestateManager::getLastProcessedGamestateID(unsigned int peerID)
+  {
+    assert( this->peerMap_.find(peerID)!=this->peerMap_.end() );
+    if( this->peerMap_.find(peerID) != this->peerMap_.end() )
+      return this->peerMap_[peerID].lastProcessedGamestateID;
+    else
+      return GAMESTATEID_INITIAL;
+  }
+  
+  
+  void GamestateManager::addPeer(uint32_t peerID)
+  {
+    assert(peerMap_.find(peerID)==peerMap_.end());
+    peerMap_[peerID].peerID = peerID;
+    peerMap_[peerID].lastProcessedGamestateID = GAMESTATEID_INITIAL;
+    peerMap_[peerID].lastAckedGamestateID = GAMESTATEID_INITIAL;
+    if( GameMode::isMaster() )
+      peerMap_[peerID].isSynched = false;
+    else
+      peerMap_[peerID].isSynched = true;
+  }
 
-  void GamestateManager::removeClient(ClientInformation* client){
-    assert(client);
-    std::map<unsigned int, std::map<unsigned int, packet::Gamestate*> >::iterator clientMap = gamestateMap_.find(client->getID());
-    // first delete all remained gamestates
-    std::map<unsigned int, packet::Gamestate*>::iterator it;
-    for(it=clientMap->second.begin(); it!=clientMap->second.end(); it++)
-      delete it->second;
-    // now delete the clients gamestatemap
-    gamestateMap_.erase(clientMap);
+  void GamestateManager::removePeer(uint32_t peerID)
+  {
+    assert(peerMap_.find(peerID)!=peerMap_.end());
+    std::map<uint32_t, packet::Gamestate*>::iterator peerIt;
+    for( peerIt = peerMap_[peerID].gamestates.begin(); peerIt!=peerMap_[peerID].gamestates.end(); ++peerIt )
+    {
+      delete peerIt->second;
+    }
+    peerMap_.erase(peerMap_.find(peerID));
   }
 
-  bool GamestateManager::processGamestate(packet::Gamestate *gs){
+
+//   void GamestateManager::removeClient(ClientInformation* client){
+//     assert(client);
+//     std::map<unsigned int, std::map<unsigned int, packet::Gamestate*> >::iterator clientMap = gamestateMap_.find(client->getID());
+//     // first delete all remained gamestates
+//     std::map<unsigned int, packet::Gamestate*>::iterator it;
+//     for(it=clientMap->second.begin(); it!=clientMap->second.end(); it++)
+//       delete it->second;
+//     // now delete the clients gamestatemap
+//     gamestateMap_.erase(clientMap);
+//   }
+
+  bool GamestateManager::processGamestate(packet::Gamestate *gs)
+  {
     if(gs->isCompressed())
     {
        bool b = gs->decompressData();
        assert(b);
     }
     assert(!gs->isDiffed());
-    return gs->spreadData(0x1);
+    uint8_t gsMode;
+    if( GameMode::isMaster() )
+      gsMode = packet::GAMESTATE_MODE_SERVER;
+    else
+      gsMode = packet::GAMESTATE_MODE_CLIENT;
+    if( gs->spreadData(gsMode) )
+    {
+      this->peerMap_[gs->getPeerID()].lastProcessedGamestateID = gs->getID();
+      return true;
+    }
+    else
+      return false;
   }
 
 }

Modified: code/trunk/src/libraries/network/GamestateManager.h
===================================================================
--- code/trunk/src/libraries/network/GamestateManager.h	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/libraries/network/GamestateManager.h	2010-12-22 18:24:24 UTC (rev 7801)
@@ -45,6 +45,8 @@
 #include <map>
 #include "GamestateHandler.h"
 #include "core/CorePrereqs.h"
+#include "packet/Gamestate.h"
+#include <boost/concept_check.hpp>
 
 namespace orxonox
 {
@@ -65,29 +67,51 @@
   * diff(a,diff(a,x))=x (hope this is correct)
   * @author Oliver Scheuss
   */
-  class _NetworkExport GamestateManager: public GamestateHandler{
+  class _NetworkExport GamestateManager: public GamestateHandler
+  {
+    struct peerInfo
+    {
+      uint32_t  peerID;
+      uint32_t  lastProcessedGamestateID;
+      uint32_t  lastAckedGamestateID;
+      bool      isSynched;
+      std::map< uint32_t, packet::Gamestate* > gamestates;
+    };
+    
   public:
+    
     GamestateManager();
     ~GamestateManager();
 
-    bool add(packet::Gamestate *gs, unsigned int clientID);
+    virtual bool      addGamestate(packet::Gamestate *gs, unsigned int peerID);
+    virtual bool      ackGamestate(unsigned int gamestateID, unsigned int peerID);
+    virtual uint32_t  getLastProcessedGamestateID( unsigned int peerID );
+    virtual uint32_t  getCurrentGamestateID(){ return currentGamestate_->getID(); }
+    
     bool processGamestates();
+    bool sendAck(unsigned int gamestateID, uint32_t peerID);
     bool update();
-    void sendGamestates();
-//     packet::Gamestate *popGameState(unsigned int clientID);
-    void finishGamestate( unsigned int clientID, packet::Gamestate*& destgamestate, packet::Gamestate* base, packet::Gamestate* gamestate );
+    std::vector<packet::Gamestate*> getGamestates();
+    void finishGamestate( unsigned int peerID, packet::Gamestate*& destgamestate, packet::Gamestate* base, packet::Gamestate* gamestate );
 
     bool getSnapshot();
 
-    bool ack(unsigned int gamestateID, unsigned int clientID);
-    void removeClient(ClientInformation *client);
+    void addPeer( uint32_t peerID );
+    void setSynched( uint32_t peerID )
+      { assert(peerMap_.find(peerID)!=peerMap_.end()); peerMap_[peerID].isSynched = true; }
+    void removePeer( uint32_t peerID );
+//     void removeClient(ClientInformation *client);
+  protected:
+    virtual bool sendPacket( packet::Packet* packet ) = 0;
   private:
     bool processGamestate(packet::Gamestate *gs);
 
-    std::map<unsigned int, std::map<unsigned int, packet::Gamestate*> > gamestateMap_;
+//     std::map<unsigned int, std::map<unsigned int, packet::Gamestate*> > gamestateMap_;
     std::map<unsigned int, packet::Gamestate*> gamestateQueue;
-    packet::Gamestate *reference;
-    TrafficControl *trafficControl_;
+//     std::map<unsigned int, uint32_t> lastProcessedGamestateID_;
+    std::map<uint32_t, peerInfo> peerMap_;
+    packet::Gamestate* currentGamestate_;
+//     TrafficControl *trafficControl_;
     unsigned int id_;
 //     boost::mutex* threadMutex_;
     ThreadPool*   /*thread*/Pool_;

Modified: code/trunk/src/libraries/network/Host.cc
===================================================================
--- code/trunk/src/libraries/network/Host.cc	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/libraries/network/Host.cc	2010-12-22 18:24:24 UTC (rev 7801)
@@ -44,7 +44,7 @@
 
   // Host*               Host::instance_=0;
   uint32_t            Host::clientID_s=0;
-  uint32_t            Host::shipID_s=-1;
+//   uint32_t            Host::shipID_s=-1;
   std::vector<Host*>  Host::instances_s;
 
   /**
@@ -75,18 +75,15 @@
   * @param clientID ID of the client the packet should be sent to
   * @return success?
   */
-  bool Host::addPacket(ENetPacket *packet, int clientID)
+  void Host::addPacket(ENetPacket *packet, int clientID, uint8_t channelID)
   {
-    bool result = true;
     for( std::vector<Host*>::iterator it = instances_s.begin(); it!=instances_s.end(); ++it )
     {
       if( (*it)->isActive() )
       {
-        if( !(*it)->queuePacket(packet, clientID) )
-          result = false;
+        (*it)->queuePacket(packet, clientID, channelID);
       }
     }
-    return result;
   }
 
   void Host::Chat(const std::string& message)

Modified: code/trunk/src/libraries/network/Host.h
===================================================================
--- code/trunk/src/libraries/network/Host.h	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/libraries/network/Host.h	2010-12-22 18:24:24 UTC (rev 7801)
@@ -30,6 +30,7 @@
 #define _NETWORK_Host_H__
 
 #include "NetworkPrereqs.h"
+#include "GamestateManager.h"
 #include "core/CorePrereqs.h"
 
 #include <vector>
@@ -48,12 +49,13 @@
 *       - is the interface to be used when communicating with the network
 *       @author Oliver Scheuss
 */
-class _NetworkExport Host{
+class _NetworkExport Host: public GamestateManager
+{
   private:
     //TODO add these functions or adequate
     //virtual bool processChat(packet::Chat *message, unsigned int clientID)=0;
     //virtual bool sendChat(packet::Chat *chat)=0;
-    virtual bool queuePacket(ENetPacket *packet, int clientID)=0;
+    virtual void queuePacket(ENetPacket *packet, int clientID, uint8_t channelID)=0;
     virtual bool chat(const std::string& message)=0;
     virtual bool broadcast(const std::string& message)=0;
     virtual bool processChat(const std::string& message, unsigned int playerID)=0;
@@ -70,13 +72,11 @@
   public:
 //     static Host* getInstance(){ return instance_; }
     static bool running(){ return instances_s.size(); }
-    static bool addPacket(ENetPacket *packet, int clientID=0);
+    static void addPacket(ENetPacket* packet, int clientID = NETWORK_PEER_ID_SERVER, uint8_t channelID = 0);
     //static bool chat(std::string& message);
 //     static bool receiveChat(packet::Chat *message, unsigned int clientID);
     static unsigned int getPlayerID(){ return clientID_s; }
-    static unsigned int getShipID(){return shipID_s;}
     static void setClientID(unsigned int id){ clientID_s = id; }
-    static void setShipID(unsigned int id){ shipID_s = id; }
     static bool isServer();
     static void Chat(const std::string& message);
     static bool Broadcast(const std::string& message);
@@ -85,7 +85,6 @@
     bool isActive(){ return bIsActive_; }
   private:
     static uint32_t clientID_s;
-    static uint32_t shipID_s;
     static std::vector<Host*> instances_s;
     bool bIsActive_;
 };

Modified: code/trunk/src/libraries/network/LANDiscoverable.cc
===================================================================
--- code/trunk/src/libraries/network/LANDiscoverable.cc	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/libraries/network/LANDiscoverable.cc	2010-12-22 18:24:24 UTC (rev 7801)
@@ -44,7 +44,7 @@
   {
     this->host_ = 0;
     this->bActive_ = false;
-    this->setActivity(true);
+//     this->setActivity(true);
   }
 
   LANDiscoverable::~LANDiscoverable()

Copied: code/trunk/src/libraries/network/MasterServer.cc (from rev 7786, code/branches/presentation/src/libraries/network/MasterServer.cc)
===================================================================
--- code/trunk/src/libraries/network/MasterServer.cc	                        (rev 0)
+++ code/trunk/src/libraries/network/MasterServer.cc	2010-12-22 18:24:24 UTC (rev 7801)
@@ -0,0 +1,312 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Sandro 'smerkli' Merkli
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "MasterServer.h"
+#include "util/ScopedSingletonManager.h"
+#include "core/CoreIncludes.h"
+#include "core/CorePrereqs.h"
+
+namespace orxonox 
+{
+  /* helpers */
+  static void 
+  helper_output_debug( ENetEvent *event, char *addrconv )
+  {
+    COUT(4) << "A packet of length" 
+      << event->packet->dataLength
+      << " containing "
+      << (const char*)event->packet->data
+      << " was received from "
+      << addrconv 
+      << " on channel "
+      << event->channelID << "\n";
+  }
+
+  void
+  MasterServer::helper_sendlist( ENetEvent *event )
+  {
+    /* get an iterator */
+    std::list<packet::ServerInformation>::iterator i;
+
+    /* packet holder */
+    ENetPacket *reply;
+
+    /* loop through list elements */
+    for( i = mainlist.serverlist.begin(); i 
+        != mainlist.serverlist.end(); ++i ) 
+    {
+      /* send this particular server */
+      /* build reply string */
+      char *tosend = (char *)calloc( (*i).getServerIP().length() 
+          + MSPROTO_SERVERLIST_ITEM_LEN + 2,1 );
+      if( !tosend ) 
+      { COUT(2) << "Masterserver.cc: Memory allocation failed.\n";
+        continue;
+      } 
+      sprintf( tosend, "%s %s", MSPROTO_SERVERLIST_ITEM, 
+          (*i).getServerIP().c_str() );
+
+      /* create packet from it */
+      reply = enet_packet_create( tosend,
+          strlen( tosend ) + 1, 
+          ENET_PACKET_FLAG_RELIABLE);
+
+      /* Send the reply to the peer over channel id 0. */
+      enet_peer_send( event->peer, 0, reply );
+
+      /* One could just use enet_host_service() instead. */
+      enet_host_flush( this->server );
+
+      /* free the tosend buffer */
+      free( tosend );
+    } 
+
+    /* create end-of-list packet */
+    reply = enet_packet_create( MSPROTO_SERVERLIST_END,
+        MSPROTO_SERVERLIST_END_LEN + 1,
+        ENET_PACKET_FLAG_RELIABLE );
+
+    /* send end-of-list packet */
+    enet_peer_send( event->peer, 0, reply );
+
+    /* One could just use enet_host_service() instead. */
+    enet_host_flush( this->server );
+  }
+
+
+
+
+  /***** EVENTS *****/
+  /* connect event */
+  int 
+  MasterServer::eventConnect( ENetEvent *event )
+  { /* check for bad parameters */
+    if( !event )
+    { COUT(2) << "MasterServer::eventConnect: No event given.\n" ;
+      return -1;
+    }
+
+    /* convert address to string. */
+    char *addrconv = (char *) calloc( 50, 1 );
+    enet_address_get_host_ip( &(event->peer->address), addrconv, 49 );
+
+    /* output debug info */
+    COUT(4) << "A new client connected from " 
+      << addrconv 
+      << " on port " 
+      << event->peer->address.port << "\n";
+
+    /* store string form of address here */
+    event->peer->data = addrconv; 
+
+    /* all fine. */
+    return 0;
+  }
+
+  /* disconnect event */
+  int 
+  MasterServer::eventDisconnect( ENetEvent *event )
+  { /* check for bad parameters */
+    if( !event )
+    { COUT(2) << "No event given.\n";
+      return -1;
+    }
+
+    /* output that the disconnect happened */
+    COUT(4) << (char*)event->peer->data << " disconnected.\n";
+
+    /* create string from peer data */
+    std::string name = std::string( (char*)event->peer->data );
+
+    /* remove the server from the list it belongs to */
+    this->mainlist.delServerByName( name );
+
+    /* Reset the peer's client information. */
+    if( event->peer->data ) free( event->peer->data );
+
+    /* done */
+    return 0;
+  }
+
+  /* data event */
+  int 
+  MasterServer::eventData( ENetEvent *event )
+  { /* validate packet */
+    if( !event || !(event->packet) || !(event->peer) )
+    { COUT(2) << "No complete event given.\n";
+      return -1;
+    }
+     
+    /* generate address in readable form */
+    char *addrconv = (char *) calloc( 50, 1 );
+    enet_address_get_host_ip( &(event->peer->address), addrconv, 49 );
+
+    /* output debug info about the data that has come */
+    helper_output_debug( event, addrconv );
+
+    /* GAME SERVER OR CLIENT CONNECTION? */
+    if( !strncmp( (char *)event->packet->data, MSPROTO_GAME_SERVER, 
+      MSPROTO_GAME_SERVER_LEN ) )
+    { /* Game server */
+
+      if( !strncmp( (char *)event->packet->data 
+        + MSPROTO_GAME_SERVER_LEN+1, 
+        MSPROTO_REGISTER_SERVER, MSPROTO_REGISTER_SERVER_LEN ) )
+      { /* register new server */
+        mainlist.addServer( packet::ServerInformation( event ) );
+        
+        /* tell people we did so */
+        COUT(2) << "Added new server to list: " << 
+          packet::ServerInformation( event ).getServerIP() << "\n";
+      }
+
+      else if( !strncmp( (char *)event->packet->data
+        + MSPROTO_GAME_SERVER_LEN+1,
+        MSPROTO_SERVERDC, MSPROTO_SERVERDC_LEN ) )
+      {
+        /* create string from peer data */
+        std::string name = std::string( addrconv );
+
+        /* remove the server from the list it belongs to */
+        this->mainlist.delServerByAddress( name );
+
+        /* tell the user */
+        COUT(2) << "Removed server " << name << " from list.\n";
+      }
+
+      /* TODO add hook for disconnect here */
+    }
+    else if( !strncmp( (char *)event->packet->data, MSPROTO_CLIENT, 
+      MSPROTO_CLIENT_LEN) )
+    { /* client */
+      if( !strncmp( (char *)event->packet->data + MSPROTO_CLIENT_LEN+1,
+        MSPROTO_REQ_LIST, MSPROTO_REQ_LIST_LEN ) )
+        /* send server list */
+        helper_sendlist( event );
+    }
+    else
+    { /* bad message, don't do anything. */ } 
+
+    /* delete addrconv */
+    if( addrconv ) free( addrconv );
+
+    /* Clean up the packet now that we're done using it. */
+    enet_packet_destroy( event->packet );
+    return 0;
+  }
+
+
+  /**** MAIN ROUTINE *****/
+  int 
+  MasterServer::run()
+  {
+    /***** ENTER MAIN LOOP *****/
+    ENetEvent *event = (ENetEvent *)calloc(sizeof(ENetEvent), sizeof(char));
+    if( event == NULL )
+    { 
+      COUT(1) << "Could not create ENetEvent structure, exiting.\n";
+      exit( EXIT_FAILURE );
+    }
+
+    /* TODO schedule pings for servers somewhere here */
+    
+    /* create an iterator for the loop */
+    enet_host_service( this->server, event, 100 );
+
+    /* check what type of event it is and react accordingly */
+    switch (event->type)
+    { /* new connection */
+      case ENET_EVENT_TYPE_CONNECT: 
+        eventConnect( event ); break;
+
+        /* disconnect */
+      case ENET_EVENT_TYPE_DISCONNECT: 
+        eventDisconnect( event ); break;
+
+        /* incoming data */
+      case ENET_EVENT_TYPE_RECEIVE: eventData( event ); break;
+      default: break;
+    }
+
+    /* done */
+    return 0;
+  } 
+
+  /* constructor */
+  MasterServer::MasterServer()
+  {
+    /***** INITIALIZE NETWORKING *****/
+    if( enet_initialize () != 0)
+    { COUT(1) << "An error occurred while initializing ENet.\n";
+      exit( EXIT_FAILURE );
+    }
+
+    /* register deinitialization */
+    atexit( enet_deinitialize );
+
+    /* set the quit flag to false */
+    this->quit = false;
+
+    /* Bind the server to the default localhost and port ORX_MSERVER_PORT */
+    this->address.host = ENET_HOST_ANY;
+    this->address.port = ORX_MSERVER_PORT;
+
+    /* create a host with the above settings (the last two 0 mean: accept 
+     * any input/output bandwidth */
+    this->server = enet_host_create( &this->address, ORX_MSERVER_MAXCONNS, 
+        ORX_MSERVER_MAXCHANS, 0, 0 );
+    assert(this->server);
+
+    /* see if creation worked */
+    if( !this->server )
+    { COUT(1) << 
+        "An error occurred while trying to create an ENet server host.\n";
+      exit( EXIT_FAILURE );
+    }
+
+    /***** INITIALIZE GAME SERVER AND PEER LISTS *****/
+    this->peers = new PeerList();
+
+    /* tell people we're now initialized */
+    COUT(0) << "MasterServer initialized, waiting for connections.\n";
+  }
+
+  /* destructor */
+  MasterServer::~MasterServer()
+  {
+    /***** CLEANUP PROCESS *****/
+    /* terminate all networking connections */
+    enet_host_destroy( this->server );
+
+    /* free all used memory */
+    /* clear the list of connected game servers */
+    /* clear the list of connected game clients */
+  }
+
+/* end of namespace */
+}

Copied: code/trunk/src/libraries/network/MasterServer.h (from rev 7786, code/branches/presentation/src/libraries/network/MasterServer.h)
===================================================================
--- code/trunk/src/libraries/network/MasterServer.h	                        (rev 0)
+++ code/trunk/src/libraries/network/MasterServer.h	2010-12-22 18:24:24 UTC (rev 7801)
@@ -0,0 +1,84 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Sandro 'smerkli' Merkli
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _MasterServer_H__
+#define _MasterServer_H__
+
+#include "NetworkPrereqs.h"
+
+/* orxonox includes */
+#include <enet/enet.h>
+#include <network/packet/Chat.h>
+#include <network/packet/ClassID.h>
+#include <network/packet/DeleteObjects.h>
+#include <network/packet/FunctionIDs.h>
+#include <network/packet/Gamestate.h>
+#include <network/packet/Welcome.h>
+#include <network/MasterServerProtocol.h>
+
+/* my includes */
+#include "ServerList.h"
+#include "PeerList.h"
+
+/* c compatibility */
+#include <cstdio>
+
+namespace orxonox 
+{
+  /* singleton */
+  class _NetworkExport MasterServer
+  {
+    public:
+      MasterServer();
+      ~MasterServer();
+
+      /* main routine */
+      int run();
+
+    private:
+      /* methods */
+      int eventConnect( ENetEvent *event );
+      int eventDisconnect( ENetEvent *event );
+      int eventData( ENetEvent *event );
+
+      /* helpers */
+      void helper_sendlist( ENetEvent *event );
+
+      /* members */
+      ENetAddress address;
+      ENetHost *server;
+      ServerList mainlist;
+      PeerList *peers;
+
+      unsigned int port;
+      bool quit;
+
+  };
+}
+
+#endif /* _MasterServer_H__ */

Copied: code/trunk/src/libraries/network/MasterServerComm.cc (from rev 7786, code/branches/presentation/src/libraries/network/MasterServerComm.cc)
===================================================================
--- code/trunk/src/libraries/network/MasterServerComm.cc	                        (rev 0)
+++ code/trunk/src/libraries/network/MasterServerComm.cc	2010-12-22 18:24:24 UTC (rev 7801)
@@ -0,0 +1,256 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Sandro 'smerkli' Merkli
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "MasterServerComm.h"
+
+namespace orxonox
+{
+
+  MasterServerComm::MasterServerComm()
+  { /* nothing anymore, everything's been outsourced to 
+     * the initialize method to facilitate debugging
+     */
+    /* register object in orxonox */
+  } 
+
+  int MasterServerComm::initialize()
+  {
+    /* initialize Enet */
+    if( enet_initialize () != 0 )
+    { COUT(1) << "An error occurred while initializing ENet.\n";
+      return 1;
+    }
+
+    /* initialize the event holder */
+//     this->event = (ENetEvent *)calloc( sizeof(ENetEvent), 1 );
+    
+
+    /* initiate the client */
+    this->client = enet_host_create( NULL /* create a client host */,
+        1,
+        2, /* allow up 2 channels to be used, 0 and 1 */
+        0, 
+        0 ); 
+
+    /* see if it worked */
+    if (this->client == NULL)
+    { COUT(1) << "An error occurred while trying to create an " 
+        << "ENet client host.\n";
+      return 1;
+    }
+
+    return 0;
+  }
+
+  MasterServerComm::~MasterServerComm()
+  {
+    /* destroy the enet facilities */
+    enet_host_destroy(this->client);
+  }
+
+  int MasterServerComm::connect( const char *address, unsigned int port )
+  {
+    /* Connect to address:port. */
+    enet_address_set_host( &this->address, address );
+    this->address.port = port;
+
+    /* Initiate the connection, allocating the two channels 0 and 1. */
+    this->peer = enet_host_connect(this->client, &this->address, 2, 0);    
+
+    if( this->peer == NULL )
+    { COUT(2) << "ERROR: No available peers for initiating an ENet"
+        << " connection.\n";
+      return -1;
+    }
+
+    /* Wait up to 2 seconds for the connection attempt to succeed. */
+    if (enet_host_service (this->client, &this->event, 500) > 0 &&
+        this->event.type == ENET_EVENT_TYPE_CONNECT )
+      COUT(3) << "Connection to master server succeeded.\n";
+    else
+    {
+      enet_peer_reset (this->peer);
+      COUT(2) << "ERROR: connection to " << address << " failed.\n";
+      return -1;
+    }
+
+    /* all fine */
+    return 0;
+  }
+  
+void MasterServerComm::update()
+{
+  while( enet_host_service( this->client, &this->event, 1 ) );
+}
+
+
+  int MasterServerComm::disconnect( void )
+  {
+    while( enet_host_service( this->client, &this->event, 1 ) );
+    enet_peer_disconnect( this->peer, 0 );
+
+    /* Allow up to 1 second for the disconnect to succeed
+     * and drop any packets received packets.
+     */
+    while (enet_host_service (this->client, &this->event, 1000) > 0)
+    {
+      switch (this->event.type)
+      {
+        case ENET_EVENT_TYPE_RECEIVE:
+          enet_packet_destroy (event.packet);
+          break;
+
+        case ENET_EVENT_TYPE_DISCONNECT:
+          COUT(4) << "Disconnect from master server successful.\n"; 
+          return 0;
+        default: break;
+      }
+    }
+
+    /* We've arrived here, so the disconnect attempt didn't
+     * succeed yet, hence: force the connection down.            
+     */
+    enet_peer_reset( this->peer );
+
+    /* done */
+    return 0;
+  }
+
+  /* NOTE this is to be reimplemented soon to return 
+   * a structure containing 
+   * - addrconv
+   * - the event
+   * so we can also make callbacks from objects
+   */
+  int MasterServerComm::pollForReply( int (*callback)( char*, ENetEvent* ),
+    int delayms )
+  { 
+    /* see whether anything happened */
+    /* WORK MARK REMOVE THIS OUTPUT */
+    COUT(2) << "polling masterserver...\n";
+
+    /* address buffer */
+    char *addrconv = NULL;
+    int retval = 0;
+
+    /* enet_host_service returns 0 if no event occured */
+    /* just newly set below test to >0 from >= 0, to be tested */
+    if( enet_host_service( this->client, &this->event, delayms ) > 0 )
+    { 
+      /* check what type of event it is and react accordingly */
+      switch (this->event.type)
+      { /* new connection, not supposed to happen. */
+        case ENET_EVENT_TYPE_CONNECT: break;
+
+        /* disconnect */
+        case ENET_EVENT_TYPE_DISCONNECT: /* ?? */ break;
+
+        /* incoming data */
+        case ENET_EVENT_TYPE_RECEIVE: 
+          addrconv = (char *) calloc( 50, 1 );
+          if( !addrconv ) 
+          { COUT(2) << "MasterServerComm.cc: Could not allocate memory!\n";
+            break;
+          }
+
+          /* resolve IP */
+          enet_address_get_host_ip( &(this->event.peer->address), 
+            addrconv, 49 );
+
+          /* DEBUG */
+          COUT(3) << "MasterServer Debug: A packet of length " 
+            << this->event.packet->dataLength 
+            << " containing " << this->event.packet->data
+            << " was received from " << addrconv 
+            << " on channel " << this->event.channelID;
+          /* END DEBUG */
+
+          /* call the supplied callback, if any. */
+          if( (*callback) != NULL )
+            retval = (*callback)( addrconv, &(this->event) );
+
+          /* clean up */
+          enet_packet_destroy( event.packet );
+          if( addrconv ) 
+            free( addrconv );
+
+          break;
+        default: break;
+      }
+
+      /* event handled, return 0 */
+      return retval;
+    }
+
+    /* show that no event occured */
+    return 0;
+  }
+
+  int MasterServerComm::sendRequest( const char *data )
+  {
+    /* send the data to the friend */
+    /* Create a reliable packet of size 7 containing "packet\0" */
+    ENetPacket * packet = enet_packet_create( data, 
+        strlen( data ) + 1, 
+        ENET_PACKET_FLAG_RELIABLE);
+
+    /* Send the packet to the peer over channel id 0. */
+    enet_peer_send (this->peer, 0, packet);
+
+    /* One could just use enet_host_service() instead. */
+    enet_host_flush( this->client );
+   
+    /* free the packet */
+    // PLEASE: never do this, because enet will free the packet once it's delivered. this will cause double frees
+//     enet_packet_destroy( packet );
+
+    /* all done. */
+    return 0;
+  }
+
+  int MasterServerComm::sendRequest( std::string data )
+  {
+    /* send the data to the friend */
+    /* Create a reliable packet of size 7 containing "packet\0" */
+    ENetPacket * packet = enet_packet_create( data.c_str(), 
+        data.length() + 1, 
+        ENET_PACKET_FLAG_RELIABLE);
+
+    /* Send the packet to the peer over channel id 0. */
+    enet_peer_send (this->peer, 0, packet);
+
+    /* One could just use enet_host_service() instead. */
+    enet_host_flush( this->client );
+    // PLEASE: never do this, because enet will free the packet once it's delivered. this will cause double frees
+//     enet_packet_destroy( packet );
+
+    /* all done. */
+    return 0;
+  }
+
+}

Copied: code/trunk/src/libraries/network/MasterServerComm.h (from rev 7786, code/branches/presentation/src/libraries/network/MasterServerComm.h)
===================================================================
--- code/trunk/src/libraries/network/MasterServerComm.h	                        (rev 0)
+++ code/trunk/src/libraries/network/MasterServerComm.h	2010-12-22 18:24:24 UTC (rev 7801)
@@ -0,0 +1,112 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Sandro 'smerkli' Merkli
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _MasterServerComm_H__
+#define _MasterServerComm_H__
+
+#include "NetworkPrereqs.h"
+
+#include <cstdlib>
+#include <cstdio>
+#include <string>
+#include <cstring>
+#include <enet/enet.h>
+
+
+namespace orxonox
+{
+  class _NetworkExport MasterServerComm 
+  { 
+    public: 
+      /** constructor */
+      MasterServerComm();
+
+      /** destructor */
+      ~MasterServerComm();
+
+      /** \return 0 for success, other for error
+       * 
+       * Initialize everything for the master server communication 
+       */
+      int initialize();
+      
+      void update();
+
+
+      /** \param address Address to connect to (Host name or IP in text form)
+       * \param port Port to connect on 
+       * \return 0 for success, other for error 
+       * 
+       * Connect to the master server with the given address on the given port. 
+       */
+      int connect( const char *address, unsigned int port );
+
+      /** \return 0 for success, other for error
+       * 
+       * Disconnect from master server.
+       */
+      int disconnect( void );
+
+      /** \param data The data to be sent. 
+       * \return 0 for success, other for error. 
+       * 
+       * Send a request to the master server containing data specified in data
+       */
+      int sendRequest( const char *data );
+
+      /** \param data The data to be sent. 
+       * \return 0 for success, other for error. 
+       * 
+       * Send a request to the master server containing data specified in data
+       * (string version)
+       */
+      int sendRequest( std::string data );
+
+      /** \param callback The callback function to call with data receivced.
+       * \return 0 for success, other for error
+       * 
+       * Poll the master server for new data and act accordingly */
+      int pollForReply( int (*callback)( char*, ENetEvent* ), int delayms );
+
+    private:
+      /** client handle */
+      ENetHost* client;
+
+      /** event data holder */
+      ENetEvent event;
+
+      /** address holder */
+      ENetAddress address;
+
+      /** peer data holder */
+      ENetPeer* peer;
+  }; 
+
+} 
+
+#endif /* _MasterServerComm_H__ */

Copied: code/trunk/src/libraries/network/MasterServerProtocol.h (from rev 7786, code/branches/presentation/src/libraries/network/MasterServerProtocol.h)
===================================================================
--- code/trunk/src/libraries/network/MasterServerProtocol.h	                        (rev 0)
+++ code/trunk/src/libraries/network/MasterServerProtocol.h	2010-12-22 18:24:24 UTC (rev 7801)
@@ -0,0 +1,92 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Sandro 'smerkli' Merkli
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _MasterServerProtocol_H__
+#define _MasterServerProtocol_H__
+
+/* master server address (to be moved elsewhere later) */
+#define MS_ADDRESS "129.132.3.8"
+
+
+/*** CLIENT COMMUNICATIONS ***/
+/* Client token (shows that the party sending data is a client */
+#define MSPROTO_CLIENT "CL"
+#define MSPROTO_CLIENT_LEN 2 
+
+/* Request: Serverlist (requiest made from client to master server */
+#define MSPROTO_REQ_LIST "REQ:LIST"
+#define MSPROTO_REQ_LIST_LEN 8
+
+
+
+
+/*** GAME SERVER COMMUNICATIONS ***/
+/* Game server token (shows that the party sending data is a game server) */
+#define MSPROTO_GAME_SERVER "GS"
+#define MSPROTO_GAME_SERVER_LEN 2
+
+/* Register game server at the master server, meaning request to be taken into$
+ * the master servers game server list.
+ */
+#define MSPROTO_REGISTER_SERVER "REG:SER"
+#define MSPROTO_REGISTER_SERVER_LEN 7
+
+/* Server list item token */
+#define MSPROTO_SERVERLIST_ITEM "SI"
+#define MSPROTO_SERVERLIST_ITEM_LEN 2
+
+/* server list end token */
+#define MSPROTO_SERVERLIST_END "SL_END"
+#define MSPROTO_SERVERLIST_END_LEN 6
+
+/* ping request from server */
+#define MSPROTO_PING_GAMESERVER "PING"
+#define MSPROTO_PING_GAMESERVER_LEN 4 
+
+/* server disconnect */
+#define MSPROTO_SERVERDC "DC"
+#define MSPROTO_SERVERDC_LEN 2
+
+/* ping reply */
+#define MSPROTO_ACK "ACK"
+#define MSPROTO_ACK_LEN 3 
+
+
+
+/* default master server port */
+#define ORX_MSERVER_PORT 55557
+
+
+/* some constants for the networking of the master server, not very important.
+ * play with those if things don't work out well.$
+ */
+#define ORX_MSERVER_MAXCONNS 32
+#define ORX_MSERVER_MAXCHANS 2
+
+
+#endif /* _MasterServerProtocol_H__ */

Modified: code/trunk/src/libraries/network/NetworkPrereqs.h
===================================================================
--- code/trunk/src/libraries/network/NetworkPrereqs.h	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/libraries/network/NetworkPrereqs.h	2010-12-22 18:24:24 UTC (rev 7801)
@@ -63,11 +63,15 @@
 
 namespace orxonox
 {
-  static const unsigned int GAMESTATEID_INITIAL     = static_cast<unsigned int>(-1);
-  static const unsigned int CLIENTID_UNKNOWN        = static_cast<unsigned int>(-2);
+  static const unsigned int GAMESTATEID_INITIAL       = static_cast<unsigned int>(-1);
+  static const unsigned int CLIENTID_UNKNOWN          = static_cast<unsigned int>(-2);
   extern const char* LAN_DISCOVERY_MESSAGE;
   extern const char* LAN_DISCOVERY_ACK;
-  static const unsigned int LAN_DISCOVERY_PORT      = 55557;
+  static const unsigned int LAN_DISCOVERY_PORT          = 55558;
+  static const unsigned int NETWORK_PEER_ID_SERVER      = 0;
+  static const unsigned int NETWORK_CHANNEL_DEFAULT     = 0;
+  static const unsigned int NETWORK_CHANNEL_UNRELIABLE  = 1;
+  static const unsigned int NETWORK_CHANNEL_COUNT       = 2;
 }
 
 //-----------------------------------------------------------------------
@@ -82,9 +86,9 @@
     {
       enum Value
       {
-        Reliable   = 1,
-        Unsequence = 2,
-        NoAllocate = 4
+        Reliable    = 1,
+        Unsequenced = 2,
+        NoAllocate  = 4
       };
     }
   }
@@ -96,15 +100,16 @@
 
 // from ENet
 struct _ENetPeer;
-typedef _ENetPeer ENetPeer;
+typedef _ENetPeer     ENetPeer;
 struct _ENetPacket;
-typedef _ENetPacket ENetPacket;
+typedef _ENetPacket   ENetPacket;
 struct _ENetEvent;
-typedef _ENetEvent ENetEvent;
+typedef _ENetEvent    ENetEvent;
 struct _ENetHost;
-typedef _ENetHost ENetHost;
+typedef _ENetHost     ENetHost;
 struct _ENetAddress;
-typedef _ENetAddress ENetAddress;
+typedef _ENetAddress  ENetAddress;
+typedef uint8_t       ENetChannelID;
 
 namespace orxonox
 {
@@ -160,4 +165,10 @@
   class SynchronisableVariableBidirectional;
 }
 
+namespace boost
+{
+  class mutex;
+  class thread;
+}
+
 #endif /* _NetworkPrereqs_H__ */

Copied: code/trunk/src/libraries/network/PeerList.cc (from rev 7786, code/branches/presentation/src/libraries/network/PeerList.cc)
===================================================================
--- code/trunk/src/libraries/network/PeerList.cc	                        (rev 0)
+++ code/trunk/src/libraries/network/PeerList.cc	2010-12-22 18:24:24 UTC (rev 7801)
@@ -0,0 +1,96 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Sandro 'smerkli' Merkli
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "PeerList.h"
+#include <network/packet/ServerInformation.h>
+#include <cstdio>
+
+namespace orxonox
+{
+  PeerList::PeerList() { }
+  PeerList::~PeerList() { }
+
+  int 
+  PeerList::addPeer( ENetPeer *toadd )
+  { /* error correction */
+    if( toadd == NULL ) 
+    { fprintf( stderr, "PeerList::addPeer: empty peer given.\n" );
+      return -1;
+    }
+
+    /* if all went well, push to back of list */
+    this->peerlist.push_back( toadd );
+    return 0;
+  }
+
+  bool sub_compAddr( ENetAddress addr1, ENetAddress addr2 )
+  { 
+    for( int i = 0; i < 16; ++i )
+      if( addr1.host.addr[i] < addr2.host.addr[i] )
+        return -i;
+      else if( addr1.host.addr[i] > addr2.host.addr[i] )
+        return i;
+
+    return 0;
+  }
+    
+
+  bool
+  PeerList::remPeerByAddr( ENetAddress addr )
+  { /* get an iterator */
+    std::list<ENetPeer *>::iterator i;
+
+    /* loop through list elements */
+    for( i = peerlist.begin(); i != peerlist.end(); ++i ) 
+      if( !sub_compAddr((*i)->address, addr ) )
+      { /* found this name, remove and quit */
+        this->peerlist.remove( *i );
+        return true;
+      }
+
+    /* not found */
+    return false;
+  }
+
+  ENetPeer *
+  PeerList::findPeerByAddr( ENetAddress addr )
+  { /* get an iterator */
+    std::list<ENetPeer *>::iterator i;
+
+    /* loop through list elements */
+    for( i = peerlist.begin(); i != peerlist.end(); ++i ) 
+      if( !sub_compAddr((*i)->address, addr ) )
+        /* found this name, remove and quit */
+        return *i;
+
+    /* not found */
+    return NULL;
+  }
+
+}
+

Copied: code/trunk/src/libraries/network/PeerList.h (from rev 7786, code/branches/presentation/src/libraries/network/PeerList.h)
===================================================================
--- code/trunk/src/libraries/network/PeerList.h	                        (rev 0)
+++ code/trunk/src/libraries/network/PeerList.h	2010-12-22 18:24:24 UTC (rev 7801)
@@ -0,0 +1,83 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Sandro 'smerkli' Merkli
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _PeerList_
+#define _PeerList_
+
+#include <list>
+#include <string>
+#include <enet/enet.h>
+
+/* peer list */
+namespace orxonox 
+{
+  /** This class keeps a list of open connections 
+   * and some info about them.
+   */
+  class PeerList 
+  { public:
+      /** constructor */
+      PeerList();
+
+      /** destructor */
+      ~PeerList();
+
+      /** \param toadd The peer to add
+       * \return 0 for success, -1 for error.
+       * 
+       * Add new peer to list 
+       */
+      int addPeer( ENetPeer *toadd );
+
+      /** \param addr Address to look for
+       * \return if the peer was found or not
+       * 
+       * Remove peer from list by address 
+       */
+      bool remPeerByAddr( ENetAddress addr );
+
+      /** \param addr The address to find by
+       * 
+       * Find a connection by address */
+      ENetPeer *findPeerByAddr( ENetAddress addr );
+
+      /* NOTE: making this list public so it can easily 
+       * be iterated. This makes sense since iterating it
+       * will happen all the time, and using getter methods
+       * for the next in list would slow things down unnecessarily.
+       */
+      /** the list of servers for internal storage */
+      std::list<ENetPeer *> peerlist;
+    private:
+      /* nothing so far. */
+  };
+}
+
+
+
+#endif /* _PeerList_ */

Modified: code/trunk/src/libraries/network/Server.cc
===================================================================
--- code/trunk/src/libraries/network/Server.cc	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/libraries/network/Server.cc	2010-12-22 18:24:24 UTC (rev 7801)
@@ -59,6 +59,7 @@
 #include "ClientInformation.h"
 #include "FunctionCallManager.h"
 #include "GamestateManager.h"
+#include "WANDiscovery.h"
 
 namespace orxonox
 {
@@ -98,6 +99,14 @@
   {
   }
 
+
+  /** helper that connects to the master server */
+  void Server::helper_ConnectToMasterserver()
+  {
+//     WANDiscovery::getInstance().msc.sendRequest( MSPROTO_GAME_SERVER " " 
+//       MSPROTO_REGISTER_SERVER );
+  }
+
   /**
   * This function opens the server by creating the listener thread
   */
@@ -106,7 +115,18 @@
     Host::setActive(true);
     COUT(4) << "opening server" << endl;
     this->openListener();
+    
+    /* make discoverable on LAN */
     LANDiscoverable::setActivity(true);
+
+    /* make discoverable on WAN */
+    WANDiscoverable::setActivity(true);
+    /* TODO this needs to be optional, we need a switch from the UI to
+     * enable/disable this 
+     */
+//     helper_ConnectToMasterserver();
+
+    /* done */
     return;
   }
 
@@ -119,6 +139,12 @@
     COUT(4) << "closing server" << endl;
     this->disconnectClients();
     this->closeListener();
+
+    /* tell master server we're closing */
+    COUT(2) << "disconnecting." << endl;
+    WANDiscoverable::setActivity(false);    
+    COUT(2) << "disconnecting done" << endl;
+
     LANDiscoverable::setActivity(false);
     return;
   }
@@ -129,8 +155,8 @@
     packet::Chat *chat;
     while(temp){
       chat = new packet::Chat(message, playerID);
-      chat->setClientID(temp->getID());
-      if(!chat->send())
+      chat->setPeerID(temp->getID());
+      if(!chat->send( static_cast<Host*>(this) ))
         COUT(3) << "could not send Chat message to client ID: " << temp->getID() << std::endl;
       temp = temp->next();
     }
@@ -139,6 +165,30 @@
   }
 
 
+  /* handle incoming data */
+  int rephandler( char *addr, ENetEvent *ev )
+  { 
+    /* reply to pings */
+    if( !strncmp( (char *)ev->packet->data, MSPROTO_PING_GAMESERVER, 
+      MSPROTO_PING_GAMESERVER_LEN ) )
+      //this->msc.sendRequest( MSPROTO_ACK );
+      /* NOTE implement this after pollForReply
+       * reimplementation 
+       */
+      return 0;
+
+    /* done handling, return all ok code 0 */
+    return 0;
+  }
+
+  void Server::helper_HandleMasterServerRequests()
+  { 
+    /* poll the master server for replies and see whether something 
+     * has to be done or changed.
+     */
+    //WANDiscovery::getInstance().msc.pollForReply( rhandler, 10 );
+  }
+
   /**
   * Run this function once every tick
   * calls processQueue and updateGamestate
@@ -148,16 +198,22 @@
   {
     // receive incoming packets
     Connection::processQueue();
+
     // receive and process incoming discovery packets
     LANDiscoverable::update();
+    
+    // receive and process requests from master server
+    /* todo */
+    //helper_HandleMasterServerRequests();
 
     if ( ClientInformation::hasClients() )
     {
       // process incoming gamestates
       GamestateManager::processGamestates();
+      FunctionCallManager::processBufferedFunctionCalls();
 
       // send function calls to clients
-      FunctionCallManager::sendCalls();
+      FunctionCallManager::sendCalls( static_cast<Host*>(this) );
 
       //this steers our network frequency
       timeSinceLastUpdate_+=time.getDeltaTime();
@@ -166,13 +222,13 @@
         timeSinceLastUpdate_ -= static_cast<unsigned int>( timeSinceLastUpdate_ / NETWORK_PERIOD ) * NETWORK_PERIOD;
         updateGamestate();
       }
-      sendPackets(); // flush the enet queue
+//       sendPackets(); // flush the enet queue
     }
   }
 
-  bool Server::queuePacket(ENetPacket *packet, int clientID)
+  void Server::queuePacket(ENetPacket *packet, int clientID, uint8_t channelID)
   {
-    return ServerConnection::addPacket(packet, clientID);
+    ServerConnection::addPacket(packet, clientID, channelID);
   }
 
   /**
@@ -208,60 +264,30 @@
       //no client connected
       return;
     GamestateManager::update();
-    COUT(5) << "Server: one gamestate update complete, goig to sendGameState" << std::endl;
+//     COUT(5) << "Server: one gamestate update complete, goig to sendGameState" << std::endl;
     //std::cout << "updated gamestate, sending it" << std::endl;
     //if(clients->getGamestateID()!=GAMESTATEID_INITIAL)
-    sendGameState();
+    sendGameStates();
     sendObjectDeletes();
-    COUT(5) << "Server: one sendGameState turn complete, repeat in next tick" << std::endl;
+//     COUT(5) << "Server: one sendGameState turn complete, repeat in next tick" << std::endl;
     //std::cout << "sent gamestate" << std::endl;
   }
 
-  bool Server::processPacket( ENetPacket *packet, ENetPeer *peer ){
-    packet::Packet *p = packet::Packet::createPacket(packet, peer);
-    return p->process();
-  }
-
   /**
-  * sends the gamestate
+  * sends the current gamestate to all peers
   */
-  bool Server::sendGameState()
+  bool Server::sendGameStates()
   {
-//     COUT(5) << "Server: starting function sendGameState" << std::endl;
-//     ClientInformation *temp = ClientInformation::getBegin();
-//     bool added=false;
-//     while(temp != NULL){
-//       if( !(temp->getSynched()) ){
-//         COUT(5) << "Server: not sending gamestate" << std::endl;
-//         temp=temp->next();
-//         if(!temp)
-//           break;
-//         continue;
-//       }
-//       COUT(4) << "client id: " << temp->getID() << " RTT: " << temp->getRTT() << " loss: " << temp->getPacketLoss() << std::endl;
-//       COUT(5) << "Server: doing gamestate gamestate preparation" << std::endl;
-//       int cid = temp->getID(); //get client id
-//       packet::Gamestate *gs = GamestateManager::popGameState(cid);
-//       if(gs==NULL){
-//         COUT(2) << "Server: could not generate gamestate (NULL from compress)" << std::endl;
-//         temp = temp->next();
-//         continue;
-//       }
-//       //std::cout << "adding gamestate" << std::endl;
-//       gs->setClientID(cid);
-//       if ( !gs->send() ){
-//         COUT(3) << "Server: packet with client id (cid): " << cid << " not sended: " << temp->getFailures() << std::endl;
-//         temp->addFailure();
-//       }else
-//         temp->resetFailures();
-//       added=true;
-//       temp=temp->next();
-//       // gs gets automatically deleted by enet callback
-//     }
-    GamestateManager::sendGamestates();
+    std::vector<packet::Gamestate*> gamestates = GamestateManager::getGamestates();
+    std::vector<packet::Gamestate*>::iterator it;
+    for( it = gamestates.begin(); it != gamestates.end(); ++it )
+    {
+      (*it)->send(static_cast<Host*>(this));
+    }
     return true;
   }
 
+
   bool Server::sendObjectDeletes()
   {
     ClientInformation *temp = ClientInformation::getBegin();
@@ -285,9 +311,9 @@
       int cid = temp->getID(); //get client id
       packet::DeleteObjects *cd = new packet::DeleteObjects(*del);
       assert(cd);
-      cd->setClientID(cid);
-      if ( !cd->send() )
-        COUT(3) << "Server: packet with client id (cid): " << cid << " not sended: " << temp->getFailures() << std::endl;
+      cd->setPeerID(cid);
+      if ( !cd->send( static_cast<Host*>(this) ) )
+        COUT(3) << "Server: packet with client id (cid): " << cid << " not sended" << std::endl;
       temp=temp->next();
       // gs gets automatically deleted by enet callback
     }
@@ -311,6 +337,7 @@
 
     // inform all the listeners
     ClientConnectionListener::broadcastClientConnected(newid);
+    GamestateManager::addPeer(newid);
 
     ++newid;
 
@@ -326,12 +353,27 @@
       return;
     else
     {
+      GamestateManager::removePeer(client->getID());
       //ServerConnection::disconnectClient( client );
       //ClientConnectionListener::broadcastClientDisconnected( client->getID() ); //this is done in ClientInformation now
       delete client;
     }
   }
+  
+  void Server::processPacket(packet::Packet* packet)
+  {
+    if( packet->isReliable() )
+    {
+      if( this->getLastProcessedGamestateID(packet->getPeerID()) >= packet->getRequiredGamestateID() )
+        packet->process(static_cast<Host*>(this));
+      else
+        this->packetQueue_.push_back(packet);
+    }
+    else
+      packet->process(static_cast<Host*>(this));
+  }
 
+
   bool Server::createClient(int clientID)
   {
     ClientInformation *temp = ClientInformation::findClient(clientID);
@@ -340,39 +382,42 @@
       COUT(2) << "Conn.Man. could not create client with id: " << clientID << std::endl;
       return false;
     }
-    COUT(5) << "Con.Man: creating client id: " << temp->getID() << std::endl;
+    COUT(4) << "Con.Man: creating client id: " << temp->getID() << std::endl;
 
     // synchronise class ids
     syncClassid(temp->getID());
 
     // now synchronise functionIDs
     packet::FunctionIDs *fIDs = new packet::FunctionIDs();
-    fIDs->setClientID(clientID);
-    bool b = fIDs->send();
+    fIDs->setPeerID(clientID);
+    bool b = fIDs->send( static_cast<Host*>(this) );
     assert(b);
 
     temp->setSynched(true);
+    GamestateManager::setSynched(clientID);
+    
     COUT(4) << "sending welcome" << std::endl;
     packet::Welcome *w = new packet::Welcome(temp->getID(), temp->getShipID());
-    w->setClientID(temp->getID());
-    b = w->send();
+    w->setPeerID(temp->getID());
+    b = w->send( static_cast<Host*>(this) );
     assert(b);
     packet::Gamestate *g = new packet::Gamestate();
-    g->setClientID(temp->getID());
-    b = g->collectData(0,0x1);
+    g->setPeerID(temp->getID());
+    b = g->collectData(0,packet::GAMESTATE_MODE_SERVER);
+    assert(b);
     if(!b)
       return false; //no data for the client
-    b = g->compressData();
+//     b = g->compressData();
+//     assert(b);
+    b = g->send( static_cast<Host*>(this) );
     assert(b);
-    b = g->send();
-    assert(b);
     return true;
   }
 
   void Server::disconnectClient( ClientInformation *client )
   {
     ServerConnection::disconnectClient( client );
-    GamestateManager::removeClient(client);
+    GamestateManager::removePeer(client->getID());
     // inform all the listeners
     // ClientConnectionListener::broadcastClientDisconnected(client->getID()); // this is done in ClientInformation now
   }
@@ -394,8 +439,8 @@
     while(temp)
     {
       chat = new packet::Chat(message, clientID);
-      chat->setClientID(temp->getID());
-      if(!chat->send())
+      chat->setPeerID(temp->getID());
+      if(!chat->send( static_cast<Host*>(this) ))
         COUT(3) << "could not send Chat message to client ID: " << temp->getID() << std::endl;
       temp = temp->next();
     }
@@ -410,8 +455,8 @@
   {
     int failures=0;
     packet::ClassID *classid = new packet::ClassID();
-    classid->setClientID(clientID);
-    while(!classid->send() && failures < 10){
+    classid->setPeerID(clientID);
+    while(!classid->send( static_cast<Host*>(this) ) && failures < 10){
       failures++;
     }
     assert(failures<10);

Modified: code/trunk/src/libraries/network/Server.h
===================================================================
--- code/trunk/src/libraries/network/Server.h	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/libraries/network/Server.h	2010-12-22 18:24:24 UTC (rev 7801)
@@ -31,13 +31,19 @@
 
 #include "NetworkPrereqs.h"
 
+#include <deque>
+
 #include "util/UtilPrereqs.h"
 #include "core/CorePrereqs.h"
 #include "Host.h"
-#include "GamestateManager.h"
+// #include "GamestateManager.h"
 #include "ServerConnection.h"
 #include "LANDiscoverable.h"
+#include "WANDiscoverable.h"
+// #include "MasterServerComm.h"
+// #include "MasterServerProtocol.h"
 
+
 namespace orxonox
 {
 
@@ -45,17 +51,24 @@
   * This class is the root class of the network module for a server.
   * It implements all functions necessary for a Server
   */
-  class _NetworkExport Server : public Host, public ServerConnection, public GamestateManager, public LANDiscoverable{
+  class _NetworkExport Server : public Host, public ServerConnection, public LANDiscoverable, public WANDiscoverable
+  {
   public:
     Server();
     Server(int port);
     Server(int port, const std::string& bindAddress);
     ~Server();
 
+    /* helpers */
+    void helper_ConnectToMasterserver();
+    void helper_HandleMasterServerRequests();
+    int replyhandler( char *addr, ENetEvent *ev );
+
     void open();
     void close();
     bool processChat(const std::string& message, unsigned int playerID);
-    bool queuePacket(ENetPacket *packet, int clientID);
+    void queuePacket(ENetPacket *packet, int clientID, uint8_t channelID);
+    virtual bool sendPacket( packet::Packet* packet ){ return packet->send( static_cast<Host*>(this) ); }
     void update(const Clock& time);
     unsigned int getRTT(unsigned int clientID);
     virtual void printRTT();
@@ -64,16 +77,15 @@
     void updateGamestate();
   private:
     virtual bool isServer_(){return true;}
-    unsigned int shipID(){return 0;}
     unsigned int playerID(){return 0;}
 
     void addPeer(ENetEvent *event);
     void removePeer(ENetEvent *event);
+    void processPacket(packet::Packet* packet);
 
     bool createClient(int clientID);
     void disconnectClient( ClientInformation *client);
-    bool processPacket( ENetPacket *packet, ENetPeer *peer );
-    bool sendGameState();
+    bool sendGameStates();
     bool sendObjectDeletes();
     virtual bool chat(const std::string& message);
     virtual bool broadcast(const std::string& message);
@@ -81,6 +93,7 @@
     void syncClassid(unsigned int clientID);
 
     float timeSinceLastUpdate_;
+    std::deque<packet::Packet*> packetQueue_;
   };
 
 

Modified: code/trunk/src/libraries/network/ServerConnection.cc
===================================================================
--- code/trunk/src/libraries/network/ServerConnection.cc	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/libraries/network/ServerConnection.cc	2010-12-22 18:24:24 UTC (rev 7801)
@@ -48,13 +48,15 @@
     this->bindAddress_->port = NETWORK_PORT;
   }
 
-  ServerConnection::~ServerConnection(){
+  ServerConnection::~ServerConnection()
+  {
     if ( this->bListening_ )
       closeListener();
     delete this->bindAddress_;
   }
 
-  void ServerConnection::setBindAddress( const std::string& bindAddress ) {
+  void ServerConnection::setBindAddress( const std::string& bindAddress )
+  {
     if (enet_address_set_host (this->bindAddress_, bindAddress.c_str()) < 0)
         COUT(1) << "Error: Could not resolve \"" << bindAddress << "\"." << std::endl;
   }
@@ -63,13 +65,19 @@
       this->bindAddress_->port = port;
   }
 
-  bool ServerConnection::openListener() {
-    this->host_ = enet_host_create(this->bindAddress_, NETWORK_MAX_CONNECTIONS, 0, 0, 0);
+  bool ServerConnection::openListener()
+  {
+    // create host
+    this->host_ = enet_host_create(this->bindAddress_, NETWORK_MAX_CONNECTIONS, NETWORK_CHANNEL_COUNT, 0, 0);
+    
     if ( this->host_ == NULL )
     {
         COUT(1) << "ServerConnection: host_ == NULL" << std::endl;
         return false;
     }
+    
+    // enable compression
+    this->enableCompression();
     assert( this->host_->socket4 != ENET_SOCKET_NULL || this->host_->socket6 != ENET_SOCKET_NULL );
     if (this->host_->socket4 == ENET_SOCKET_NULL)
         COUT(2) << "Warning: IPv4 Socket failed." << std::endl;
@@ -77,89 +85,74 @@
         COUT(2) << "Warning: IPv6 Socket failed." << std::endl;
     else
         COUT(3) << "Info: Using IPv4 and IPv6 Sockets." << std::endl;
+    
+    // start communication thread
+    Connection::startCommunicationThread();
 
     return true;
   }
 
-  bool ServerConnection::closeListener() {
+  bool ServerConnection::closeListener()
+  {
     this->bListening_=false;
     disconnectClients();
+    Connection::stopCommunicationThread();
     enet_host_destroy(this->host_);
     return true;
   }
 
-  bool ServerConnection::addPacket(ENetPacket *packet, unsigned int clientID) {
+  void ServerConnection::addPacket(ENetPacket *packet, unsigned int clientID, uint8_t channelID)
+  {
     if ( clientID == CLIENTID_UNKNOWN )
     {
-      return addPacketAll(packet);
+      broadcastPacket(packet, channelID);
     }
     else
     {
       ClientInformation *temp = ClientInformation::findClient(clientID);
       if(!temp){
         COUT(3) << "C.Man: addPacket findClient failed" << std::endl;
-        return false;
       }
-      return Connection::addPacket(packet, temp->getPeer());
+      Connection::addPacket(packet, temp->getPeer(), channelID);
     }
   }
 
-  bool ServerConnection::addPacketAll(ENetPacket *packet) {
-//     if ( !Connection::getInstance() )
-//       return false;
-    enet_host_broadcast( Connection::getHost(), 0, packet);
-    return true;
-  }
-
   void ServerConnection::disconnectClient(ClientInformation *client)
   {
     Connection::disconnectPeer( client->getPeer() );
   }
 
-  void ServerConnection::disconnectClient(int clientID){
+  void ServerConnection::disconnectClient(int clientID)
+  {
     ClientInformation *client = ClientInformation::findClient(clientID);
     if(client)
       ServerConnection::disconnectClient(client);
   }
 
-  void ServerConnection::disconnectClients() {
-    ENetEvent event;
+  void ServerConnection::disconnectClients()
+  {
     ClientInformation *temp = ClientInformation::getBegin();
-    while(temp!=0){
+    while(temp!=0)
+    {
       ServerConnection::disconnectClient( temp );
       temp = temp->next();
     }
-    temp = ClientInformation::getBegin();
-    while( temp!=0 ){
-      if( service( &event ) )
-      {
-        switch (event.type)
-        {
-        case ENET_EVENT_TYPE_NONE: break;
-        case ENET_EVENT_TYPE_CONNECT: break;
-        case ENET_EVENT_TYPE_RECEIVE:
-          enet_packet_destroy(event.packet);
-          break;
-        case ENET_EVENT_TYPE_DISCONNECT:
-          removePeer( &event );
-          temp = ClientInformation::getBegin();
-          break;
-        }
-      }
-    }
     return;
   }
 
 
-  int ServerConnection::getClientID(ENetPeer* peer) {
+  int ServerConnection::getClientID(ENetPeer* peer)
+  {
     return getClientID(&(peer->address));
   }
 
-  int ServerConnection::getClientID(ENetAddress* address) {
+  int ServerConnection::getClientID(ENetAddress* address)
+  {
     return ClientInformation::findClient(address)->getID();
   }
 
-  ENetPeer *ServerConnection::getClientPeer(int clientID) {
+  ENetPeer *ServerConnection::getClientPeer(int clientID)
+  {
     return ClientInformation::findClient(clientID)->getPeer();
   }
 

Modified: code/trunk/src/libraries/network/ServerConnection.h
===================================================================
--- code/trunk/src/libraries/network/ServerConnection.h	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/libraries/network/ServerConnection.h	2010-12-22 18:24:24 UTC (rev 7801)
@@ -55,8 +55,7 @@
 
     bool openListener();
     bool closeListener();
-    bool addPacket(ENetPacket *packet, unsigned int ID);
-    bool addPacketAll(ENetPacket *packet);
+    void addPacket(ENetPacket *packet, unsigned int ID, uint8_t channelID);
     virtual void disconnectClient(ClientInformation *client);
     void disconnectClient(int clientID);
   protected:

Copied: code/trunk/src/libraries/network/ServerList.cc (from rev 7786, code/branches/presentation/src/libraries/network/ServerList.cc)
===================================================================
--- code/trunk/src/libraries/network/ServerList.cc	                        (rev 0)
+++ code/trunk/src/libraries/network/ServerList.cc	2010-12-22 18:24:24 UTC (rev 7801)
@@ -0,0 +1,102 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Sandro 'smerkli' Merkli
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "ServerList.h"
+
+namespace orxonox
+{ 
+  ServerList::ServerList()
+  { /* create a new list */ }
+
+  ServerList::~ServerList()
+  { /* delete the list */
+    serverlist.clear();
+  }
+
+  int 
+  ServerList::addServer( packet::ServerInformation toadd )
+  { this->serverlist.push_back( toadd ); 
+    return 0;
+  }
+
+  bool 
+  ServerList::delServerByName( std::string name )
+  { 
+    /* get an iterator */
+    std::list<packet::ServerInformation>::iterator i;
+
+    /* loop through list elements */
+    for( i = serverlist.begin(); i != serverlist.end(); ++i ) 
+      if( (*i).getServerName() == name )
+      { /* found this name, remove and quit */
+        this->serverlist.erase( i );
+        return true;
+      }
+    return false;
+  }
+
+  bool ServerList::delServerByAddress( std::string address )
+  { 
+    /* get an iterator */
+    std::list<packet::ServerInformation>::iterator i;
+
+    /* loop through list elements */
+    for( i=serverlist.begin(); i != serverlist.end(); ++i ) 
+      if( (*i).getServerIP() == address )
+      { /* found this name, remove and quit */
+        this->serverlist.erase( i );
+        return true;
+      }
+    return false;
+  }
+
+
+  /* sort by name */
+  bool sub_compare_names( packet::ServerInformation no1, 
+    packet::ServerInformation no2 )
+  { return no1.getServerName() > no2.getServerName(); }
+
+  void ServerList::sortByName()
+  { 
+    this->serverlist.sort( sub_compare_names ); 
+  }
+  
+  /* sort by ping */
+  bool sub_compare_pings( packet::ServerInformation no1, 
+    packet::ServerInformation no2 )
+  { 
+    /* TODO */
+    return no1.getServerName() > no2.getServerName();
+  }
+
+  void ServerList::sortByPing()
+  {
+    this->serverlist.sort( sub_compare_pings ); 
+  }
+
+}

Copied: code/trunk/src/libraries/network/ServerList.h (from rev 7786, code/branches/presentation/src/libraries/network/ServerList.h)
===================================================================
--- code/trunk/src/libraries/network/ServerList.h	                        (rev 0)
+++ code/trunk/src/libraries/network/ServerList.h	2010-12-22 18:24:24 UTC (rev 7801)
@@ -0,0 +1,85 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Sandro 'smerkli' Merkli
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _ServerList_
+#define _ServerList_
+
+#include <list>
+#include <string>
+#include <network/packet/ServerInformation.h>
+
+/* methods necessary */
+namespace orxonox 
+{ 
+  /** This class is keeps a list of game servers
+   * and some info about them.
+   */
+  class ServerList 
+  { public:
+      /** constructor */
+      ServerList();
+
+      /** destructor */
+      ~ServerList();
+
+
+      /* BASIC MANIPULATION */
+      /** \param toadd the server to add.
+       * 
+       * Add server to the game server list
+       */
+      int addServer( packet::ServerInformation toadd );
+
+      /** \param name Name of the server to remove
+       * 
+       * Remove server by name 
+       */
+      bool delServerByName( std::string name );
+
+      /** \param address IP address of the server to remove
+       * 
+       * Remove server by address
+       */
+      bool delServerByAddress( std::string address );
+
+
+      /* SORTING (to be implemented) */
+
+      /** sort by name  */
+      void sortByName();
+      
+      /** sort by ping */
+      void sortByPing();
+
+      /** the list of servers for internal storage */
+      std::list<packet::ServerInformation> serverlist;
+    private:
+  };
+}
+
+#endif /*_ServerList_*/

Copied: code/trunk/src/libraries/network/WANDiscoverable.cc (from rev 7800, code/branches/presentation2/src/libraries/network/WANDiscoverable.cc)
===================================================================
--- code/trunk/src/libraries/network/WANDiscoverable.cc	                        (rev 0)
+++ code/trunk/src/libraries/network/WANDiscoverable.cc	2010-12-22 18:24:24 UTC (rev 7801)
@@ -0,0 +1,124 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Fabian 'x3n' Landau (original)
+ *   Co-authors:
+ *      Sandro 'smerkli' Merkli (adaptions to WAN)
+ *      ...
+ *
+ */
+
+#include "WANDiscoverable.h"
+
+#include <enet/enet.h>
+#include <cstring>
+
+#include "MasterServerProtocol.h"
+#include "core/ConfigValueIncludes.h"
+#include "core/CoreIncludes.h"
+
+
+namespace orxonox
+{
+
+  WANDiscoverable::WANDiscoverable(): bActive_(false)
+  {
+    /* debugging output */
+    COUT(4) << "Creating WANDiscoverable.\n";
+  
+    /* register object in orxonox */
+    RegisterObject(WANDiscoverable);
+
+    /* check for the masterserver address option in orxonox.ini */
+    this->setConfigValues();
+    
+  }
+
+  void WANDiscoverable::setConfigValues()
+  {
+    /* update msaddress string from orxonox.ini config file, if it 
+     * has changed. 
+     */
+    SetConfigValueExternal(msaddress, "WANDiscovery", "msaddress", "orxonox.net");
+//     SetConfigValue( msaddress, "orxonox.net");
+  } 
+
+  WANDiscoverable::~WANDiscoverable()
+  {
+    if( this->bActive_ )
+      this->disconnect();
+  }
+  
+  void WANDiscoverable::setActivity(bool bActive)
+  {
+    if( bActive==this->bActive_ )
+      return;
+    
+    if( bActive )
+    {
+      if( this->connect() )
+        this->bActive_ = true;
+    }
+    else
+    {
+      this->disconnect();
+      this->bActive_ = false;
+    }
+  }
+  
+  bool WANDiscoverable::connect()
+  {
+    /* initialize it and see if it worked */
+    if( msc.initialize() )
+    {
+      COUT(2) << "Error: could not initialize master server communications!\n";
+      return false;
+    }
+    
+    /* connect and see if it worked */
+    if( msc.connect( this->msaddress.c_str(), ORX_MSERVER_PORT ) )
+    {
+      COUT(2) << "Error: could not connect to master server at " 
+                 << this->msaddress << std::endl;
+      return false;
+    }
+                 
+    /* debugging output */
+    COUT(4) << "Initialization of WANDiscoverable complete.\n";
+    
+    
+    // Now register the server at the master server
+    this->msc.sendRequest( MSPROTO_GAME_SERVER " " MSPROTO_REGISTER_SERVER );
+    
+    return true;
+  }
+
+  void WANDiscoverable::disconnect()
+  {
+    this->msc.sendRequest( MSPROTO_GAME_SERVER " " MSPROTO_SERVERDC );
+    msc.disconnect();
+  }
+
+
+
+  
+} // namespace orxonox

Copied: code/trunk/src/libraries/network/WANDiscoverable.h (from rev 7800, code/branches/presentation2/src/libraries/network/WANDiscoverable.h)
===================================================================
--- code/trunk/src/libraries/network/WANDiscoverable.h	                        (rev 0)
+++ code/trunk/src/libraries/network/WANDiscoverable.h	2010-12-22 18:24:24 UTC (rev 7801)
@@ -0,0 +1,77 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or modify it
+ *   under the terms of the GNU General Public License as published by the Free
+ *   Software Foundation; either version 2 of the License, or (at your option)
+ *   any later version.
+ *
+ *   This program is distributed in the hope that it will be useful, but
+ *   WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ *   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ *   for more details.
+ *
+ *   You should have received a copy of the GNU General Public License along
+ *   with this program; if not, write to the Free Software Foundation, Inc., 51
+ *   Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author: Fabian 'x3n' Landau (original) Co-authors: Sandro 'smerkli' Merkli
+ *   (copied and adapted to WAN)
+ *
+ */
+
+#ifndef _WANDiscoverable_H__
+#define _WANDiscoverable_H__
+
+#include "NetworkPrereqs.h"
+// #include "core/OrxonoxClass.h"
+#include "core/CoreIncludes.h"
+#include "MasterServerComm.h"
+
+namespace orxonox
+{
+
+  class _NetworkExport WANDiscoverable: public OrxonoxClass
+  {
+    public:
+      /** constructor */
+      WANDiscoverable();
+
+      /** destructor */
+      ~WANDiscoverable();
+
+      /** \return Address of the master server
+       * 
+       * Get the master server address 
+       */
+      std::string getMSAddress()
+      { return this->msaddress; }
+
+      /** Function used for the configuration file parameter update */
+      void setConfigValues();
+      
+      /** Function used to set the activity/discoverability */
+      void setActivity( bool bActive );
+
+      /** Master server communications object */
+      MasterServerComm msc;
+      
+    private:
+      /** Function used to connect to the master server */
+      bool connect();
+      
+      /** Function used to disconnect from the master server */
+      void disconnect();
+      
+      /** master server address */
+      std::string msaddress;
+      bool        bActive_;
+
+  };
+
+}
+
+#endif // _WANDiscoverable_H__

Copied: code/trunk/src/libraries/network/WANDiscovery.cc (from rev 7786, code/branches/presentation/src/libraries/network/WANDiscovery.cc)
===================================================================
--- code/trunk/src/libraries/network/WANDiscovery.cc	                        (rev 0)
+++ code/trunk/src/libraries/network/WANDiscovery.cc	2010-12-22 18:24:24 UTC (rev 7801)
@@ -0,0 +1,167 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Fabian 'x3n' Landau (original)
+ *   Co-authors:
+ *      Sandro 'smerkli' Merkli (adaptions to WAN)
+ *      ...
+ *
+ */
+
+#include "WANDiscovery.h"
+
+#include <enet/enet.h>
+#include <cstring>
+
+#include "util/ScopedSingletonManager.h"
+#include "core/CoreIncludes.h"
+
+
+namespace orxonox
+{
+  ManageScopedSingleton(WANDiscovery, ScopeID::Graphics, true);
+
+
+  WANDiscovery::WANDiscovery()
+  {
+    /* debugging output */
+    COUT(4) << "Creating WANDiscovery.\n";
+  
+    /* register object in orxonox */
+    RegisterObject(WANDiscovery);
+
+    /* check for the masterserver address option in orxonox.ini */
+    this->setConfigValues();
+
+    /* initialize it and see if it worked */
+    if( msc.initialize() )
+      COUT(2) << "Error: could not initialize master server communications!\n";
+
+    /* connect and see if it worked */
+    if( msc.connect( this->msaddress.c_str(), ORX_MSERVER_PORT ) )
+      COUT(2) << "Error: could not connect to master server at " 
+        << this->msaddress << std::endl;
+
+    /* debugging output */
+    COUT(4) << "Initialization of WANDiscovery complete.\n";
+  }
+
+  void WANDiscovery::setConfigValues()
+  {
+    /* update msaddress string from orxonox.ini config file, if it 
+     * has changed. 
+     */
+    SetConfigValue( msaddress, "orxonox.net");
+  } 
+
+  WANDiscovery::~WANDiscovery()
+  { 
+    /* clear server list */
+    this->servers_.clear();  
+  }
+
+  /* callback for the network reply poller */
+  int rhandler( char *addr, ENetEvent *ev )
+  { 
+    /* error recognition */
+    if( !ev || !ev->packet || !ev->packet->data )
+    { COUT(2) << "Bad arguments received in WANDiscovery's reply handler.\n";
+      return 0;
+    }
+
+    /* handle incoming data */
+    /* if a list entry arrives add to list */
+    if( !strncmp( (char*)ev->packet->data, MSPROTO_SERVERLIST_ITEM,
+      MSPROTO_SERVERLIST_ITEM_LEN ) )
+    { 
+      /* create server structure from that item */
+      packet::ServerInformation toadd;
+
+      /* fill in data, -1 for the index: index should be length -1 */
+      toadd.setServerName( std::string((char*)ev->packet->data + 
+        MSPROTO_SERVERLIST_ITEM_LEN+1) );
+      toadd.setServerIP( std::string((char*)ev->packet->data + 
+        MSPROTO_SERVERLIST_ITEM_LEN+1) );
+
+      /* add to list */
+      WANDiscovery::getInstance().servers_.push_back( toadd );
+    }
+    else if( !strncmp( (char*)ev->packet->data, MSPROTO_SERVERLIST_END,
+      MSPROTO_SERVERLIST_END_LEN ) )
+    { 
+      /* this is the only case where 2 should be returned,
+       * as 1 is used to signal that we're done receiving
+       * the list
+       */
+      return 2; 
+    }
+
+    /* done handling, return all ok code 0 */
+    return 1;
+  }
+ 
+  void WANDiscovery::discover()
+  {
+    /* clear list */
+    this->servers_.clear();
+
+    /* send request to server */
+    this->msc.sendRequest( MSPROTO_CLIENT " " MSPROTO_REQ_LIST );
+
+    /* poll for replies */
+    int i = WANDISC_MAXTRIES;
+    while( i > 0 )
+    {
+      /* poll for reply and act according to what was received */
+      switch( this->msc.pollForReply( rhandler, 500 ) )
+      { case 0: /* no event occured, decrease timeout */
+          --i; break;
+        case 1: /* got a list element, continue */ 
+          break;
+        case 2: /* done. */
+          i = 0; break;
+      }
+    }
+  }
+
+  std::string WANDiscovery::getServerListItemName(unsigned int index)
+  {
+    /* if the index is out of range, return empty */
+    if( index >= this->servers_.size() )
+      return BLANKSTRING;
+    else
+      /* else return the name of the server */
+      return this->servers_[index].getServerName();
+  }
+
+  std::string WANDiscovery::getServerListItemIP(unsigned int index)
+  {
+    /* if the index is out of range, return empty */
+    if( index >= this->servers_.size() )
+      return BLANKSTRING;
+    else
+      /* else return the IP of the server */
+      return this->servers_[index].getServerIP();
+  }
+
+
+} // namespace orxonox

Copied: code/trunk/src/libraries/network/WANDiscovery.h (from rev 7786, code/branches/presentation/src/libraries/network/WANDiscovery.h)
===================================================================
--- code/trunk/src/libraries/network/WANDiscovery.h	                        (rev 0)
+++ code/trunk/src/libraries/network/WANDiscovery.h	2010-12-22 18:24:24 UTC (rev 7801)
@@ -0,0 +1,112 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or modify it
+ *   under the terms of the GNU General Public License as published by the Free
+ *   Software Foundation; either version 2 of the License, or (at your option)
+ *   any later version.
+ *
+ *   This program is distributed in the hope that it will be useful, but
+ *   WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ *   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ *   for more details.
+ *
+ *   You should have received a copy of the GNU General Public License along
+ *   with this program; if not, write to the Free Software Foundation, Inc., 51
+ *   Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author: Fabian 'x3n' Landau (original) Co-authors: Sandro 'smerkli' Merkli
+ *   (copied and adapted to WAN)
+ *
+ */
+
+#ifndef _WANDiscovery_H__
+#define _WANDiscovery_H__
+
+#include "NetworkPrereqs.h"
+#include "packet/ServerInformation.h"
+#include "core/ConfigFileManager.h"
+#include "util/Singleton.h"
+#include "core/OrxonoxClass.h"
+#include "core/ConfigValueIncludes.h"
+#include "core/CoreIncludes.h"
+#include "MasterServerComm.h"
+#include "MasterServerProtocol.h"
+
+#include <vector>
+
+#define WANDISC_MAXTRIES 5
+
+// tolua_begin
+namespace orxonox
+{
+
+  class _NetworkExport WANDiscovery
+// tolua_end
+    : public Singleton<WANDiscovery>, public OrxonoxClass
+  { // tolua_export
+    friend class Singleton<WANDiscovery>;
+    public:
+      /** constructor */
+      WANDiscovery();
+
+      /** destructor */
+      ~WANDiscovery();
+
+      /** \return Address of the master server
+       * 
+       * Get the master server address 
+       */
+      std::string getMSAddress()
+      { return this->msaddress; }
+
+      /** ask server for server list  */
+      void discover(); // tolua_export
+
+      /** \param index Index to get the name of 
+       * \return The name of the server
+       * 
+       * Get the name of the server at index index. 
+       */
+      std::string getServerListItemName( unsigned int index ); // tolua_export
+
+      /** \param index Index to get the IP of 
+       * \return The IP of the server
+       * 
+       * Get the IP of the server at index index. 
+       */
+      std::string getServerListItemIP( unsigned int index ); // tolua_export
+
+      /** \return an instance of WANDiscovery
+       * 
+       * Create and return an instance of WANDiscovery.
+       */
+      static WANDiscovery& getInstance() { return Singleton<WANDiscovery>::getInstance(); } // tolua_export
+    
+      /* todo: might make this private and use getter/setter methods
+       * at some later time. 
+       */
+      /** game server list */
+      std::vector<packet::ServerInformation> servers_;
+
+      /** Function used for the configuration file parameter update */
+      void setConfigValues();
+
+      /** Master server communications object */
+      MasterServerComm msc;
+      
+    private:
+      /** Singleton pointer */
+      static WANDiscovery* singletonPtr_s;
+
+      /** master server address */
+      std::string msaddress;
+
+  }; // tolua_export
+
+} // tolua_export
+
+#endif // _WANDiscovery_H__

Modified: code/trunk/src/libraries/network/packet/Acknowledgement.cc
===================================================================
--- code/trunk/src/libraries/network/packet/Acknowledgement.cc	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/libraries/network/packet/Acknowledgement.cc	2010-12-22 18:24:24 UTC (rev 7801)
@@ -30,6 +30,7 @@
 
 #include "util/Debug.h"
 #include "network/GamestateHandler.h"
+#include "network/Host.h"
 
 namespace orxonox {
 namespace packet {
@@ -38,18 +39,18 @@
 #define _PACKETID           0
 #define _ACKID              _PACKETID + sizeof(packet::Type::Value)
 
-Acknowledgement::Acknowledgement( unsigned int id, unsigned int clientID )
+Acknowledgement::Acknowledgement( unsigned int id, unsigned int peerID )
  : Packet()
 {
   flags_ = flags_ | PACKET_FLAGS_ACK;
   data_=new uint8_t[ getSize() ];
   *(Type::Value *)(data_ + _PACKETID ) = Type::Acknowledgement;
   *(uint32_t *)(data_ + _ACKID ) = id;
-  clientID_=clientID;
+  peerID_=peerID;
 }
 
-Acknowledgement::Acknowledgement( uint8_t *data, unsigned int clientID )
-  : Packet(data, clientID)
+Acknowledgement::Acknowledgement( uint8_t *data, unsigned int peerID )
+  : Packet(data, peerID)
 {
 }
 
@@ -61,9 +62,9 @@
   return _ACKID + sizeof(uint32_t);
 }
 
-bool Acknowledgement::process(){
+bool Acknowledgement::process(orxonox::Host* host){
   COUT(5) << "processing ACK with ID: " << getAckID() << endl;
-  bool b = GamestateHandler::ackGamestate(getAckID(), clientID_);
+  bool b = host->ackGamestate(getAckID(), peerID_);
   delete this;
   return b;
 }

Modified: code/trunk/src/libraries/network/packet/Acknowledgement.h
===================================================================
--- code/trunk/src/libraries/network/packet/Acknowledgement.h	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/libraries/network/packet/Acknowledgement.h	2010-12-22 18:24:24 UTC (rev 7801)
@@ -41,12 +41,12 @@
 class _NetworkExport Acknowledgement : public Packet
 {
 public:
-  Acknowledgement( unsigned int id, unsigned int clientID );
-  Acknowledgement( uint8_t* data, unsigned int clientID );
+  Acknowledgement( unsigned int id, unsigned int peerID );
+  Acknowledgement( uint8_t* data, unsigned int peerID );
   ~Acknowledgement();
 
   inline unsigned int getSize() const;
-  bool process();
+  virtual bool process(orxonox::Host* host);
 
   unsigned int getAckID();
 private:

Modified: code/trunk/src/libraries/network/packet/Chat.cc
===================================================================
--- code/trunk/src/libraries/network/packet/Chat.cc	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/libraries/network/packet/Chat.cc	2010-12-22 18:24:24 UTC (rev 7801)
@@ -79,8 +79,8 @@
   return _MESSAGE + messageLength_;
 }
 
-bool Chat::process(){
-  bool b = Host::incomingChat(std::string((const char*)data_+_MESSAGE), *(uint32_t *)(data_+_PLAYERID));
+bool Chat::process(orxonox::Host* host){
+  bool b = host->incomingChat(std::string((const char*)data_+_MESSAGE), *(uint32_t *)(data_+_PLAYERID));
   delete this;
   return b;
 }

Modified: code/trunk/src/libraries/network/packet/Chat.h
===================================================================
--- code/trunk/src/libraries/network/packet/Chat.h	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/libraries/network/packet/Chat.h	2010-12-22 18:24:24 UTC (rev 7801)
@@ -51,7 +51,7 @@
   inline unsigned int getSize() const;
 
   /* process chat message packet and remove it afterwards */
-  bool process();
+  virtual bool process(orxonox::Host* host);
 
   /* Get the length of the message (not the full size of the packet) */
   unsigned int getMessageLength(){ return messageLength_; };

Modified: code/trunk/src/libraries/network/packet/ClassID.cc
===================================================================
--- code/trunk/src/libraries/network/packet/ClassID.cc	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/libraries/network/packet/ClassID.cc	2010-12-22 18:24:24 UTC (rev 7801)
@@ -119,7 +119,7 @@
 }
 
 
-bool ClassID::process(){
+bool ClassID::process(orxonox::Host* host){
   int nrOfClasses;
   uint8_t *temp = data_+sizeof(uint32_t); //skip the packetid
   uint32_t networkID;

Modified: code/trunk/src/libraries/network/packet/ClassID.h
===================================================================
--- code/trunk/src/libraries/network/packet/ClassID.h	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/libraries/network/packet/ClassID.h	2010-12-22 18:24:24 UTC (rev 7801)
@@ -47,7 +47,7 @@
   ~ClassID();
 
   uint32_t getSize() const;
-  bool process();
+  virtual bool process(orxonox::Host* host);
 
 private:
 };

Modified: code/trunk/src/libraries/network/packet/DeleteObjects.cc
===================================================================
--- code/trunk/src/libraries/network/packet/DeleteObjects.cc	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/libraries/network/packet/DeleteObjects.cc	2010-12-22 18:24:24 UTC (rev 7801)
@@ -56,7 +56,8 @@
 {
 }
 
-bool DeleteObjects::fetchIDs(){
+bool DeleteObjects::fetchIDs()
+{
   unsigned int number = Synchronisable::getNumberOfDeletedObject();
   if(number==0)
     return false;
@@ -78,13 +79,16 @@
   return true;
 }
 
-unsigned int DeleteObjects::getSize() const{
+unsigned int DeleteObjects::getSize() const
+{
   assert(data_);
   return _OBJECTIDS + *(uint32_t*)(data_+_QUANTITY)*sizeof(uint32_t);
 }
 
-bool DeleteObjects::process(){
-  for(unsigned int i=0; i<*(unsigned int *)(data_+_QUANTITY); i++){
+bool DeleteObjects::process(orxonox::Host* host)
+{
+  for(unsigned int i=0; i<*(unsigned int *)(data_+_QUANTITY); i++)
+  {
     COUT(4) << "deleting object with id: " << *(uint32_t*)(data_+_OBJECTIDS+i*sizeof(uint32_t)) << std::endl;
     Synchronisable::deleteObject( *(uint32_t*)(data_+_OBJECTIDS+i*sizeof(uint32_t)) );
   }

Modified: code/trunk/src/libraries/network/packet/DeleteObjects.h
===================================================================
--- code/trunk/src/libraries/network/packet/DeleteObjects.h	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/libraries/network/packet/DeleteObjects.h	2010-12-22 18:24:24 UTC (rev 7801)
@@ -31,8 +31,10 @@
 #include "network/NetworkPrereqs.h"
 #include "Packet.h"
 
-namespace orxonox {
-namespace packet {
+namespace orxonox
+{
+namespace packet
+{
 /**
     @author
 */
@@ -46,7 +48,7 @@
   bool fetchIDs();
 
   inline unsigned int getSize() const;
-  bool process();
+  virtual bool process(orxonox::Host* host);
 
 private:
 };

Modified: code/trunk/src/libraries/network/packet/FunctionCalls.cc
===================================================================
--- code/trunk/src/libraries/network/packet/FunctionCalls.cc	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/libraries/network/packet/FunctionCalls.cc	2010-12-22 18:24:24 UTC (rev 7801)
@@ -31,6 +31,7 @@
 #include <cassert>
 #include "network/FunctionCall.h"
 #include "network/FunctionCallManager.h"
+#include "network/GamestateHandler.h"
 
 namespace orxonox {
 namespace packet {
@@ -39,15 +40,15 @@
 #define   _PACKETID         0
 const unsigned int FUNCTIONCALLS_MEM_ALLOCATION = 1000;
 
-FunctionCalls::FunctionCalls()
- : Packet()
+FunctionCalls::FunctionCalls():
+  Packet(), minGamestateID_(GAMESTATEID_INITIAL)
 {
   flags_ = flags_ | PACKET_FLAGS_FUNCTIONCALLS;
-  currentSize_ = 2*sizeof(uint32_t); // for packetid and nrOfCalls
+  currentSize_ = 3*sizeof(uint32_t); // for packetid, nrOfCalls and minGamestateID_
 }
 
-FunctionCalls::FunctionCalls( uint8_t* data, unsigned int clientID )
-  : Packet(data, clientID)
+FunctionCalls::FunctionCalls( uint8_t* data, unsigned int clientID ): 
+  Packet(data, clientID), minGamestateID_(GAMESTATEID_INITIAL)
 {
 }
 
@@ -56,25 +57,31 @@
 }
 
 
-bool FunctionCalls::process(){
+bool FunctionCalls::process(orxonox::Host* host)
+{
   assert(isDataENetAllocated());
   
   uint8_t* temp = data_+sizeof(uint32_t); //skip packetid
   uint32_t nrOfCalls = *(uint32_t*)temp;
   temp += sizeof(uint32_t);
+  this->minGamestateID_ = *(uint32_t*)temp;
+  temp += sizeof(uint32_t);
   for( unsigned int i = 0; i<nrOfCalls; i++ )
   {
     FunctionCall fctCall;
     fctCall.loadData(temp);
     if( !fctCall.execute() )
-      FunctionCallManager::bufferIncomingFunctionCall( fctCall );
+    {
+      FunctionCallManager::bufferIncomingFunctionCall( fctCall, minGamestateID_, this->getPeerID() );
+    }
   }
   
   delete this;
   return true;
 }
 
-void FunctionCalls::addCallStatic( uint32_t networkID, const MultiType* mt1, const MultiType* mt2, const MultiType* mt3, const MultiType* mt4, const MultiType* mt5){
+void FunctionCalls::addCallStatic( uint32_t networkID, const MultiType* mt1, const MultiType* mt2, const MultiType* mt3, const MultiType* mt4, const MultiType* mt5)
+{
   assert(!isDataENetAllocated());
   
   this->functionCalls_.push(orxonox::FunctionCall());
@@ -82,7 +89,8 @@
   this->currentSize_ += this->functionCalls_.back().getSize();
 }
 
-void FunctionCalls::addCallMember( uint32_t networkID, uint32_t objectID, const MultiType* mt1, const MultiType* mt2, const MultiType* mt3, const MultiType* mt4, const MultiType* mt5){
+void FunctionCalls::addCallMember( uint32_t networkID, uint32_t objectID, const MultiType* mt1, const MultiType* mt2, const MultiType* mt3, const MultiType* mt4, const MultiType* mt5)
+{
   assert(!isDataENetAllocated());
   
   this->functionCalls_.push(orxonox::FunctionCall());
@@ -90,13 +98,15 @@
   this->currentSize_ += this->functionCalls_.back().getSize();
 }
 
-bool FunctionCalls::send()
+bool FunctionCalls::send(orxonox::Host* host)
 {
+  this->minGamestateID_ = host->getCurrentGamestateID();
   assert(this->functionCalls_.size());
   data_=new uint8_t[ currentSize_ ];
   *(Type::Value *)(data_ + _PACKETID ) = Type::FunctionCalls; // Set the Packet ID
-  *(uint32_t*)(data_+sizeof(uint32_t)) = this->functionCalls_.size(); // set nrOfCalls to 0
-  uint8_t* temp = data_+2*sizeof(uint32_t);
+  *(uint32_t*)(data_+sizeof(uint32_t)) = this->functionCalls_.size(); // set nrOfCalls
+  *(uint32_t*)(data_+2*sizeof(uint32_t)) = this->minGamestateID_; // set minGamestateID_
+  uint8_t* temp = data_+3*sizeof(uint32_t);
   
   while( this->functionCalls_.size() )
   {
@@ -106,7 +116,7 @@
   
   assert( temp==data_+currentSize_ );
   
-  Packet::send();
+  Packet::send(host);
   return true;
 }
 

Modified: code/trunk/src/libraries/network/packet/FunctionCalls.h
===================================================================
--- code/trunk/src/libraries/network/packet/FunctionCalls.h	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/libraries/network/packet/FunctionCalls.h	2010-12-22 18:24:24 UTC (rev 7801)
@@ -53,14 +53,15 @@
 
   inline unsigned int getSize() const
     { assert(!this->isDataENetAllocated()); return currentSize_; }
-  bool process();
+  virtual bool process(orxonox::Host* host);
 
   void addCallStatic( uint32_t networkID, const MultiType* mt1=0, const MultiType* mt2=0, const MultiType* mt3=0, const MultiType* mt4=0, const MultiType* mt5=0);
   void addCallMember( uint32_t networkID, uint32_t objectID, const MultiType* mt1=0, const MultiType* mt2=0, const MultiType* mt3=0, const MultiType* mt4=0, const MultiType* mt5=0);
-  virtual bool send();
+  virtual bool send(orxonox::Host* host);
 private:
   std::queue<orxonox::FunctionCall> functionCalls_;
   unsigned int                      clientID_;
+  uint32_t                          minGamestateID_;
   uint32_t                          currentSize_;
 };
 

Modified: code/trunk/src/libraries/network/packet/FunctionIDs.cc
===================================================================
--- code/trunk/src/libraries/network/packet/FunctionIDs.cc	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/libraries/network/packet/FunctionIDs.cc	2010-12-22 18:24:24 UTC (rev 7801)
@@ -45,7 +45,8 @@
 #define _PACKETID                 0
 
 
-FunctionIDs::FunctionIDs( ) : Packet(){
+FunctionIDs::FunctionIDs( ) : Packet()
+{
   unsigned int nrOfFunctions=0;
   unsigned int packetSize=2*sizeof(uint32_t); //space for the packetID and for the nroffunctions
   uint32_t networkID;
@@ -54,7 +55,8 @@
 
   //calculate total needed size (for all strings and integers)
   ObjectList<NetworkFunctionBase>::iterator it;
-  for(it = ObjectList<NetworkFunctionBase>::begin(); it; ++it){
+  for(it = ObjectList<NetworkFunctionBase>::begin(); it; ++it)
+  {
     const std::string& functionname = it->getName();
     networkID = it->getNetworkID();
     // now push the network id and the classname to the stack
@@ -75,7 +77,8 @@
 
   // now save all classids and classnames
   std::pair<uint32_t, std::string> tempPair;
-  while( !tempQueue.empty() ){
+  while( !tempQueue.empty() )
+  {
     tempPair = tempQueue.front();
     tempQueue.pop();
     *(uint32_t*)temp = tempPair.first;
@@ -97,7 +100,8 @@
 {
 }
 
-uint32_t FunctionIDs::getSize() const{
+uint32_t FunctionIDs::getSize() const
+{
   assert(this->data_);
   uint8_t *temp = data_+sizeof(uint32_t); // packet identification
   uint32_t totalsize = sizeof(uint32_t); // data size
@@ -113,7 +117,8 @@
 }
 
 
-bool FunctionIDs::process(){
+bool FunctionIDs::process(orxonox::Host* host)
+{
   int nrOfFunctions;
   uint8_t *temp = data_+sizeof(uint32_t); //skip the packetid
   uint32_t networkID;
@@ -126,7 +131,8 @@
   nrOfFunctions = *(uint32_t*)temp;
   temp += sizeof(uint32_t);
 
-  for( int i=0; i<nrOfFunctions; i++){
+  for( int i=0; i<nrOfFunctions; i++)
+  {
     networkID = *(uint32_t*)temp;
     stringsize = *(uint32_t*)(temp+sizeof(uint32_t));
     functionname = temp+2*sizeof(uint32_t);

Modified: code/trunk/src/libraries/network/packet/FunctionIDs.h
===================================================================
--- code/trunk/src/libraries/network/packet/FunctionIDs.h	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/libraries/network/packet/FunctionIDs.h	2010-12-22 18:24:24 UTC (rev 7801)
@@ -46,8 +46,8 @@
   FunctionIDs( uint8_t* data, unsigned int clientID );
   ~FunctionIDs();
 
-  uint32_t getSize() const;
-  bool process();
+  virtual uint32_t getSize() const;
+  virtual bool process(orxonox::Host* host);
 
 private:
 };

Modified: code/trunk/src/libraries/network/packet/Gamestate.cc
===================================================================
--- code/trunk/src/libraries/network/packet/Gamestate.cc	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/libraries/network/packet/Gamestate.cc	2010-12-22 18:24:24 UTC (rev 7801)
@@ -35,6 +35,7 @@
 #include "core/ObjectList.h"
 #include "network/synchronisable/Synchronisable.h"
 #include "network/GamestateHandler.h"
+#include "network/Host.h"
 
 namespace orxonox {
 
@@ -42,7 +43,8 @@
 
 #define GAMESTATE_START(data) (data + GamestateHeader::getSize())
 
-#define PACKET_FLAG_GAMESTATE  PacketFlag::Reliable
+// #define PACKET_FLAG_GAMESTATE  PacketFlag::Reliable
+#define PACKET_FLAG_GAMESTATE  0
 
 inline bool memzero( uint8_t* data, uint32_t datalength)
 {
@@ -64,47 +66,42 @@
 
 
 Gamestate::Gamestate():
-  header_(0)
+  header_()
 {
   flags_ = flags_ | PACKET_FLAG_GAMESTATE;
 }
 
 
 Gamestate::Gamestate(uint8_t *data, unsigned int clientID):
-  Packet(data, clientID)
+  Packet(data, clientID), header_(data)
 {
   flags_ = flags_ | PACKET_FLAG_GAMESTATE;
-  header_ = new GamestateHeader(data_);
 }
 
 
-Gamestate::Gamestate(uint8_t *data)
+Gamestate::Gamestate(uint8_t *data):
+  header_(data)
 {
   flags_ = flags_ | PACKET_FLAG_GAMESTATE;
   data_ = data;
-  header_ = new GamestateHeader(data_);
 }
 
 
 Gamestate::Gamestate(const Gamestate& g) :
-    Packet( *(Packet*)&g ), nrOfVariables_(0)
+  Packet( *(Packet*)&g ), header_(this->data_), nrOfVariables_(0)
 {
   flags_ = flags_ | PACKET_FLAG_GAMESTATE;
-  header_ = new GamestateHeader(data_);
   sizes_ = g.sizes_;
 }
 
 
 Gamestate::~Gamestate()
 {
-  if( header_ )
-    delete header_;
 }
 
 
 bool Gamestate::collectData(int id, uint8_t mode)
 {
-  assert(this->header_==0); // make sure the header didn't exist before
   uint32_t tempsize=0, currentsize=0;
   assert(data_==0);
   uint32_t size = calcGamestateSize(id, mode);
@@ -119,9 +116,8 @@
     return false;
   }
 
-  // create the header object
-  assert( header_ == 0 );
-  header_ = new GamestateHeader(data_);
+  // tell the gamestate header where to store the data
+  header_.setData(this->data_);
 
   //start collect data synchronisable by synchronisable
   uint8_t *mem = data_; // in this stream store all data of the variables and the headers of the synchronisable
@@ -141,7 +137,7 @@
     {
       assert(0); // if we don't use multithreading this part shouldn't be neccessary
       // start allocate additional memory
-      COUT(3) << "G.St.Man: need additional memory" << std::endl;
+      COUT(3) << "Gamestate: need additional memory" << std::endl;
       ObjectList<Synchronisable>::iterator temp = it;
       uint32_t addsize=tempsize;
       while(++temp)
@@ -160,30 +156,30 @@
 
 
   //start write gamestate header
-  header_->setDataSize( currentsize );
-  header_->setID( id );
-  header_->setBaseID( GAMESTATEID_INITIAL );
-  header_->setDiffed( false );
-  header_->setComplete( true );
-  header_->setCompressed( false );
+  header_.setDataSize( currentsize );
+  header_.setID( id );
+  header_.setBaseID( GAMESTATEID_INITIAL );
+  header_.setDiffed( false );
+  header_.setComplete( true );
+  header_.setCompressed( false );
   //stop write gamestate header
 
-  COUT(5) << "G.ST.Man: Gamestate size: " << currentsize << std::endl;
-  COUT(5) << "G.ST.Man: 'estimated' (and corrected) Gamestate size: " << size << std::endl;
+  COUT(5) << "Gamestate: Gamestate size: " << currentsize << std::endl;
+  COUT(5) << "Gamestate: 'estimated' (and corrected) Gamestate size: " << size << std::endl;
   return true;
 }
 
 
 bool Gamestate::spreadData(uint8_t mode)
 {
-  COUT(4) << "processing gamestate with id " << header_->getID() << endl;
+  COUT(5) << "processing gamestate with id " << header_.getID() << endl;
   assert(data_);
-  assert(!header_->isCompressed());
+  assert(!header_.isCompressed());
   uint8_t *mem=data_+GamestateHeader::getSize();
   Synchronisable *s;
-
+  
   // update the data of the objects we received
-  while(mem < data_+GamestateHeader::getSize()+header_->getDataSize())
+  while(mem < data_+GamestateHeader::getSize()+header_.getDataSize())
   {
     SynchronisableHeader objectheader(mem);
 
@@ -196,15 +192,19 @@
       }
       else
       {
+//         COUT(4) << "not creating object of classid " << objectheader.getClassID() << endl;
         mem += objectheader.getDataSize() + ( objectheader.isDiffed() ? SynchronisableHeaderLight::getSize() : SynchronisableHeader::getSize() );
       }
     }
     else
     {
+//       COUT(4) << "updating object of classid " << objectheader.getClassID() << endl;
       bool b = s->updateData(mem, mode);
       assert(b);
     }
   }
+  assert(mem-data_ == GamestateHeader::getSize()+header_.getDataSize());
+  
    // In debug mode, check first, whether there are no duplicate objectIDs
 #ifndef NDEBUG
   if(this->getID()%1000==1)
@@ -248,11 +248,11 @@
 uint32_t Gamestate::getSize() const
 {
   assert(data_);
-  if(header_->isCompressed())
-    return header_->getCompSize()+GamestateHeader::getSize();
+  if(header_.isCompressed())
+    return header_.getCompSize()+GamestateHeader::getSize();
   else
   {
-    return header_->getDataSize()+GamestateHeader::getSize();
+    return header_.getDataSize()+GamestateHeader::getSize();
   }
 }
 
@@ -270,17 +270,17 @@
 }
 
 
-bool Gamestate::process()
+bool Gamestate::process(orxonox::Host* host)
 {
-  return GamestateHandler::addGamestate(this, getClientID());
+  return host->addGamestate(this, getPeerID());
 }
 
 
 bool Gamestate::compressData()
 {
   assert(data_);
-  assert(!header_->isCompressed());
-  uLongf buffer = (uLongf)(((header_->getDataSize() + 12)*1.01)+1);
+  assert(!header_.isCompressed());
+  uLongf buffer = (uLongf)(((header_.getDataSize() + 12)*1.01)+1);
   if(buffer==0)
     return false;
 
@@ -288,7 +288,7 @@
   uint8_t *dest = ndata + GamestateHeader::getSize();
   uint8_t *source = data_ + GamestateHeader::getSize();
   int retval;
-  retval = compress( dest, &buffer, source, (uLong)(header_->getDataSize()) );
+  retval = compress( dest, &buffer, source, (uLong)(header_.getDataSize()) );
   switch ( retval )
   {
     case Z_OK: COUT(5) << "G.St.Man: compress: successfully compressed" << std::endl; break;
@@ -298,16 +298,17 @@
   }
 
   //copy and modify header
-  GamestateHeader *temp = header_;
-  header_ = new GamestateHeader(ndata, temp);
+  GamestateHeader *temp = new GamestateHeader(data_);
+  header_.setData(ndata);
+  header_ = *temp;
   delete temp;
   //delete old data
   delete[] data_;
   //save new data
   data_ = ndata;
-  header_->setCompSize( buffer );
-  header_->setCompressed( true );
-  COUT(0) << "gamestate compress datasize: " << header_->getDataSize() << " compsize: " << header_->getCompSize() << std::endl;
+  header_.setCompSize( buffer );
+  header_.setCompressed( true );
+  COUT(4) << "gamestate compress datasize: " << header_.getDataSize() << " compsize: " << header_.getCompSize() << std::endl;
   return true;
 }
 
@@ -315,10 +316,10 @@
 bool Gamestate::decompressData()
 {
   assert(data_);
-  assert(header_->isCompressed());
-  COUT(4) << "GameStateClient: uncompressing gamestate. id: " << header_->getID() << ", baseid: " << header_->getBaseID() << ", datasize: " << header_->getDataSize() << ", compsize: " << header_->getCompSize() << std::endl;
-  uint32_t datasize = header_->getDataSize();
-  uint32_t compsize = header_->getCompSize();
+  assert(header_.isCompressed());
+  COUT(4) << "GameStateClient: uncompressing gamestate. id: " << header_.getID() << ", baseid: " << header_.getBaseID() << ", datasize: " << header_.getDataSize() << ", compsize: " << header_.getCompSize() << std::endl;
+  uint32_t datasize = header_.getDataSize();
+  uint32_t compsize = header_.getCompSize();
   uint32_t bufsize;
   bufsize = datasize;
   assert(bufsize!=0);
@@ -337,8 +338,9 @@
   }
 
   //copy over the header
-  GamestateHeader *temp = header_;
-  header_ = new GamestateHeader( data_, header_ );
+  GamestateHeader* temp = new GamestateHeader( data_ );
+  header_.setData(ndata);
+  header_ = *temp;
   delete temp;
 
   if (this->bDataENetAllocated_)
@@ -356,221 +358,238 @@
 
   //set new pointers
   data_ = ndata;
-  header_->setCompressed( false );
-  assert(header_->getDataSize()==datasize);
-  assert(header_->getCompSize()==compsize);
+  header_.setCompressed( false );
+  assert(header_.getDataSize()==datasize);
+  assert(header_.getCompSize()==compsize);
   return true;
 }
 
 
+inline void /*Gamestate::*/diffObject( uint8_t*& newDataPtr, uint8_t*& origDataPtr, uint8_t*& baseDataPtr, SynchronisableHeader& objectHeader, std::vector<uint32_t>::iterator& sizes )
+{
+  assert( objectHeader.getDataSize() == SynchronisableHeader(baseDataPtr).getDataSize() );
+  
+  uint32_t objectOffset = SynchronisableHeader::getSize(); // offset inside the object in the origData and baseData
+  // Check whether the whole object stayed the same
+  if( memcmp( origDataPtr+objectOffset, baseDataPtr+objectOffset, objectHeader.getDataSize()) == 0 )
+  {
+//     COUT(4) << "skip object " << Synchronisable::getSynchronisable(objectHeader.getObjectID())->getIdentifier()->getName() << endl;
+    origDataPtr += objectOffset + objectHeader.getDataSize(); // skip the whole object
+    baseDataPtr += objectOffset + objectHeader.getDataSize();
+    sizes += Synchronisable::getSynchronisable(objectHeader.getObjectID())->getNrOfVariables();
+  }
+  else
+  {
+    // Now start to diff the Object
+    SynchronisableHeaderLight newObjectHeader(newDataPtr);
+    newObjectHeader = objectHeader; // copy over the objectheader
+    VariableID variableID = 0;
+    uint32_t diffedObjectOffset = SynchronisableHeaderLight::getSize();
+    // iterate through all variables
+    while( objectOffset < objectHeader.getDataSize()+SynchronisableHeader::getSize() )
+    {
+      // check whether variable changed and write id and copy over variable to the new stream
+      // otherwise skip variable
+      uint32_t varSize = *sizes;
+      assert( varSize == Synchronisable::getSynchronisable(objectHeader.getObjectID())->getVarSize(variableID) );
+      if ( varSize != 0 )
+      {
+        if ( memcmp(origDataPtr+objectOffset, baseDataPtr+objectOffset, varSize) != 0 )
+        {
+          *(VariableID*)(newDataPtr+diffedObjectOffset) = variableID; // copy over the variableID
+          diffedObjectOffset += sizeof(VariableID);
+          memcpy( newDataPtr+diffedObjectOffset, origDataPtr+objectOffset, varSize );
+          diffedObjectOffset += varSize;
+          objectOffset += varSize;
+        }
+        else
+        {
+          objectOffset += varSize;
+        }
+      }
+
+      ++variableID;
+      ++sizes;
+    }
+    
+    // if there are variables from this object with 0 size left in sizes
+    if( Synchronisable::getSynchronisable(objectHeader.getObjectID())->getNrOfVariables() != variableID )
+      sizes += Synchronisable::getSynchronisable(objectHeader.getObjectID())->getNrOfVariables() - variableID;
+    
+    newObjectHeader.setDiffed(true);
+    newObjectHeader.setDataSize(diffedObjectOffset-SynchronisableHeaderLight::getSize());
+    assert(objectOffset == objectHeader.getDataSize()+SynchronisableHeader::getSize());
+    assert(newObjectHeader.getDataSize()>0);
+    
+    origDataPtr += objectOffset;
+    baseDataPtr += objectOffset;
+    newDataPtr += diffedObjectOffset;
+  }
+}
+
+inline void /*Gamestate::*/copyObject( uint8_t*& newData, uint8_t*& origData, uint8_t*& baseData, SynchronisableHeader& objectHeader, std::vector<uint32_t>::iterator& sizes )
+{
+  //       COUT(4) << "docopy" << endl;
+  // Just copy over the whole Object
+  memcpy( newData, origData, objectHeader.getDataSize()+SynchronisableHeader::getSize() );
+  SynchronisableHeader(newData).setDiffed(false);
+  
+  newData += objectHeader.getDataSize()+SynchronisableHeader::getSize();
+  origData += objectHeader.getDataSize()+SynchronisableHeader::getSize();
+//   SynchronisableHeader baseHeader( baseData );
+//   baseData += baseHeader.getDataSize()+SynchronisableHeader::getSize();
+  //       COUT(4) << "copy " << h.getObjectID() << endl;
+  //       COUT(4) << "copy " << h.getObjectID() << ":";
+  sizes += Synchronisable::getSynchronisable(objectHeader.getObjectID())->getNrOfVariables();
+//   for( unsigned int i = 0; i < Synchronisable::getSynchronisable(objectHeader.getObjectID())->getNrOfVariables(); ++i )
+//   {
+//     //         COUT(4) << " " << *sizes;
+//     ++sizes;
+//   }
+    //       COUT(4) << endl;
+}
+
+inline bool findObject(uint8_t*& dataPtr, uint8_t* endPtr, SynchronisableHeader& objectHeader)
+{
+  // Some assertions to make sure the dataPtr is valid (pointing to a SynchronisableHeader)
+  {
+    SynchronisableHeader htemp2(dataPtr);
+    assert(htemp2.getClassID()<500);
+    assert(htemp2.getDataSize()!=0 && htemp2.getDataSize()<1000);
+    assert(htemp2.isDiffed()==false);
+  }
+  uint32_t objectID = objectHeader.getObjectID();
+  while ( dataPtr < endPtr )
+  {
+    SynchronisableHeader htemp(dataPtr);
+    assert( htemp.getDataSize()!=0 );
+    if ( htemp.getObjectID() == objectID )
+    {
+      assert( objectHeader.getClassID() == htemp.getClassID() );
+      assert( objectHeader.getCreatorID() == htemp.getCreatorID() );
+      return true;
+    }
+    {
+      if( dataPtr+htemp.getDataSize()+SynchronisableHeader::getSize() < endPtr )
+      {
+        SynchronisableHeader htemp2(dataPtr+htemp.getDataSize()+SynchronisableHeader::getSize());
+        assert(htemp2.getClassID()<500);
+        assert(htemp2.getDataSize()!=0 && htemp2.getDataSize()<1000);
+        assert(htemp2.isDiffed()==false);
+      }
+    }
+    dataPtr += htemp.getDataSize()+SynchronisableHeader::getSize();
+    
+  }
+  assert(dataPtr == endPtr);
+  
+  return false;
+}
+
 Gamestate* Gamestate::diffVariables(Gamestate *base)
 {
   assert(this && base); assert(data_ && base->data_);
-  assert(!header_->isCompressed() && !base->header_->isCompressed());
-  assert(!header_->isDiffed());
+  assert(!header_.isCompressed() && !base->header_.isCompressed());
+  assert(!header_.isDiffed());
+  assert( header_.getDataSize() && base->header_.getDataSize() );
 
 
   // *** first do a raw diff of the two gamestates
 
-  uint8_t *baseData = GAMESTATE_START(base->data_);
-  uint8_t *origData = GAMESTATE_START(this->data_);
-  uint32_t origLength = header_->getDataSize();
-  uint32_t baseLength = base->header_->getDataSize();
+  uint8_t *baseDataPtr = GAMESTATE_START(base->data_);
+  uint8_t *origDataPtr = GAMESTATE_START(this->data_);
+  uint8_t *origDataEnd = origDataPtr + header_.getDataSize();
+  uint8_t *baseDataEnd = baseDataPtr + base->header_.getDataSize();
+//   uint32_t origLength = header_.getDataSize();
+//   uint32_t baseLength = base->header_.getDataSize();
 
-  assert( origLength && baseLength );
+  // Allocate new space for diffed gamestate
+  uint32_t newDataSize = header_.getDataSize() + GamestateHeader::getSize() + sizeof(uint32_t)*this->nrOfVariables_;
+  uint8_t *newData = new uint8_t[newDataSize]; // this is the maximum size needed in the worst case
+  uint8_t *destDataPtr = GAMESTATE_START(newData);
 
-  uint8_t *nData = new uint8_t[origLength + GamestateHeader::getSize() + sizeof(uint32_t)*this->nrOfVariables_]; // this is the maximum size needed in the worst case
-  uint8_t *dest = GAMESTATE_START(nData);
+  std::vector<uint32_t>::iterator sizesIt = this->sizes_.begin();
 
-  uint32_t baseOffset = 0; //offset in the diffed stream
-  uint32_t origOffset = 0; //offset in the new stream with removed 0's
-  std::vector<uint32_t>::iterator sizes = this->sizes_.begin();
-
-  while( origOffset < origLength )
+  while( origDataPtr < origDataEnd )
   {
     //iterate through all objects
 
-    SynchronisableHeader h(origData+origOffset);
+    SynchronisableHeader origHeader(origDataPtr);
 
     // Find (if possible) the current object in the datastream of the old gamestate
     // Start at the current offset position
-    if(baseOffset >= baseLength)
-      baseOffset = 0;
-    uint8_t* temp = baseData + baseOffset;
-    uint32_t objectID = h.getObjectID();
-    assert(temp < baseData+baseLength);
-    assert(dest < nData + origLength + GamestateHeader::getSize() + sizeof(uint32_t)*this->nrOfVariables_);
-    assert(sizes != this->sizes_.end());
-    while ( temp < baseData+baseLength )
+    if(baseDataPtr == baseDataEnd)
+      baseDataPtr = GAMESTATE_START(base->data_);
+    uint8_t* oldBaseDataPtr = baseDataPtr;
+    
+    assert(baseDataPtr < baseDataEnd);
+    assert(destDataPtr < newData + newDataSize);
+    assert(sizesIt != this->sizes_.end());
+    
+    assert(Synchronisable::getSynchronisable(origHeader.getObjectID()));
+    assert(ClassByID(origHeader.getClassID()));
+    assert(origHeader.getDataSize() < 500);
+    
+    bool diffedObject = false;
+    if( findObject(baseDataPtr, baseDataEnd, origHeader) )
     {
-      SynchronisableHeader htemp(temp);
-      assert( htemp.getDataSize()!=0 );
-      if ( htemp.getObjectID() == objectID )
+      SynchronisableHeader baseHeader(baseDataPtr);
+      assert(Synchronisable::getSynchronisable(baseHeader.getObjectID()));
+      assert(ClassByID(baseHeader.getClassID()));
+      assert(baseHeader.getDataSize() < 500);
+      if( SynchronisableHeader(baseDataPtr).getDataSize()==origHeader.getDataSize() )
       {
-        assert( h.getClassID() == htemp.getClassID() );
-        goto DODIFF;
+//         COUT(4) << "diffing object in order: " << Synchronisable::getSynchronisable(origHeader.getObjectID())->getIdentifier()->getName() << endl;
+        diffObject(destDataPtr, origDataPtr, baseDataPtr, origHeader, sizesIt);
+        diffedObject = true;
       }
-//       {
-//         SynchronisableHeader htemp2(temp+htemp.getDataSize()+SynchronisableHeader::getSize());
-//         if( temp+htemp.getDataSize()+SynchronisableHeader::getSize() < baseData+baseLength )
-//         {
-//           assert(htemp2.getClassID()<500);
-//           assert(htemp2.getDataSize()!=0 && htemp2.getDataSize()<1000);
-//           assert(htemp2.isDiffed()==false);
-//         }
-//       }
-      temp += htemp.getDataSize()+SynchronisableHeader::getSize();
-        
-    }
-    // If not found start looking at the beginning
-    assert( temp==baseData+baseLength );
-    temp = baseData;
-//     {
-//       SynchronisableHeader htemp2(temp);
-//       if( temp < baseData+baseLength )
-//       {
-//         assert(htemp2.getClassID()<500);
-//         assert(htemp2.getDataSize()!=0 && htemp2.getDataSize()<1000);
-//         assert(htemp2.isDiffed()==false);
-//       }
-//     }
-    while ( temp < baseData+baseOffset )
-    {
-      SynchronisableHeader htemp(temp);
-      if ( htemp.getObjectID() == objectID )
+      else
       {
-        assert( h.getClassID() == htemp.getClassID() );
-        goto DODIFF;
+//         COUT(4) << "copy object because of different data sizes (1): " << Synchronisable::getSynchronisable(origHeader.getObjectID())->getIdentifier()->getName() << endl;
+        copyObject(destDataPtr, origDataPtr, baseDataPtr, origHeader, sizesIt);
+        assert(sizesIt != this->sizes_.end() || origDataPtr==origDataEnd);
       }
-//       {
-//         SynchronisableHeader htemp2(temp+htemp.getDataSize()+SynchronisableHeader::getSize());
-//         if( temp+htemp.getDataSize()+SynchronisableHeader::getSize() < baseData+baseLength )
-//         {
-//           assert(htemp2.getClassID()<500);
-//           assert(htemp2.getDataSize()!=0 && htemp2.getDataSize()<1000);
-//           assert(htemp2.isDiffed()==false);
-//         }
-//       }
-      temp += htemp.getDataSize()+SynchronisableHeader::getSize();
+        
     }
-    // Object is new, thus never transmitted -> just copy over
-    goto DOCOPY;
-
-
-DODIFF:
+    else
     {
-//       COUT(4) << "dodiff" << endl;
-//       if(baseOffset==0)
-//       {
-//         assert(origOffset==0);
-//       }
-      uint32_t objectOffset = SynchronisableHeader::getSize(); // offset inside the object in the origData and baseData
-      // Check whether the whole object stayed the same
-      if( memcmp( origData+origOffset+objectOffset, temp+objectOffset, h.getDataSize()) == 0 )
+      assert( baseDataPtr == baseDataEnd );
+      baseDataPtr = GAMESTATE_START(base->data_);
+      if( findObject(baseDataPtr, oldBaseDataPtr, origHeader) )
       {
-//         COUT(4) << "skip object" << Synchronisable::getSynchronisable(h.getObjectID())->getIdentifier()->getName() << endl;
-        origOffset += objectOffset+ h.getDataSize(); // skip the whole object
-        baseOffset = temp + h.getDataSize()+SynchronisableHeader::getSize() - baseData;
-        sizes += Synchronisable::getSynchronisable(h.getObjectID())->getNrOfVariables();
-      }
-      else
-      {
-//         if( Synchronisable::getSynchronisable(h.getObjectID())->getIdentifier()->getName() == "Bot" )
-//           COUT(0) << "blub" << endl;
-//         COUT(4) << "object diff: " << Synchronisable::getSynchronisable(h.getObjectID())->getIdentifier()->getName() << endl;
-//         COUT(4) << "diff " << h.getObjectID() << ":";
-        // Now start to diff the Object
-        SynchronisableHeaderLight h2(dest);
-        h2 = h; // copy over the objectheader
-        VariableID variableID = 0;
-        uint32_t newObjectOffset = SynchronisableHeaderLight::getSize();
-        // iterate through all variables
-        while( objectOffset < h.getDataSize()+SynchronisableHeader::getSize() )
+        SynchronisableHeader baseHeader(baseDataPtr);
+        assert(Synchronisable::getSynchronisable(baseHeader.getObjectID()));
+        assert(ClassByID(baseHeader.getClassID()));
+        assert(baseHeader.getDataSize() < 500);
+        if( SynchronisableHeader(baseDataPtr).getDataSize()==origHeader.getDataSize() )
         {
-          // check whether variable changed and write id and copy over variable to the new stream
-          // otherwise skip variable
-          assert(sizes != this->sizes_.end());
-          uint32_t varSize = *sizes;
-          assert( varSize == Synchronisable::getSynchronisable(h.getObjectID())->getVarSize(variableID) );
-          if ( varSize != 0 )
-          {
-            if ( memcmp(origData+origOffset+objectOffset, temp+objectOffset, varSize) != 0 )
-            {
-//               COUT(4) << "copy variable" << endl;
-              *(VariableID*)(dest+newObjectOffset) = variableID; // copy over the variableID
-              newObjectOffset += sizeof(VariableID);
-              memcpy( dest+newObjectOffset, origData+origOffset+objectOffset, varSize );
-              newObjectOffset += varSize;
-              objectOffset += varSize;
-            }
-            else
-            {
-//               COUT(4) << "skip variable" << endl;
-              objectOffset += varSize;
-            }
-          }
-//           else
-//             COUT(4) << "varsize 0" << endl;
-
-          ++variableID;
-          ++sizes;
+//           COUT(4) << "diffing object out of order: " << Synchronisable::getSynchronisable(origHeader.getObjectID())->getIdentifier()->getName() << endl;
+          diffObject(destDataPtr, origDataPtr, baseDataPtr, origHeader, sizesIt);
+          diffedObject = true;
         }
-        
-        if( Synchronisable::getSynchronisable(h.getObjectID())->getNrOfVariables() != variableID )
-          sizes += Synchronisable::getSynchronisable(h.getObjectID())->getNrOfVariables() - variableID;
-//         COUT(4) << endl;
-        h2.setDiffed(true);
-        h2.setDataSize(newObjectOffset-SynchronisableHeaderLight::getSize());
-        assert(objectOffset == h.getDataSize()+SynchronisableHeader::getSize());
-        origOffset += objectOffset;
-//         baseOffset += temp + h.getDataSize()+SynchronisableHeader::getSize() - baseData;
-        //baseOffset += objectOffset;
-//         SynchronisableHeader htemp(temp);
-//         baseOffset += SynchronisableHeader::getSize() + htemp.getDataSize();
-//         {
-//           SynchronisableHeader htemp2( baseData+(temp-baseData+objectOffset) );
-//           if( baseData+(temp-baseData+objectOffset) < baseData+baseLength )
-//           {
-//             assert(htemp2.getClassID()<500);
-//             assert(htemp2.getDataSize()!=0 && htemp2.getDataSize()<1000);
-//             assert(htemp2.isDiffed()==false);
-//           }
-//         }
-        baseOffset = temp-baseData + objectOffset;
-        dest += newObjectOffset;
+        else
+        {
+//           COUT(4) << "copy object because of different data sizes (2): " << Synchronisable::getSynchronisable(origHeader.getObjectID())->getIdentifier()->getName() << endl;
+          copyObject(destDataPtr, origDataPtr, baseDataPtr, origHeader, sizesIt);
+          assert(sizesIt != this->sizes_.end() || origDataPtr==origDataEnd);
+        }
       }
-
-      continue;
-    }
-
-DOCOPY:
-    {
-//       COUT(4) << "docopy" << endl;
-      // Just copy over the whole Object
-      memcpy( dest, origData+origOffset, h.getDataSize()+SynchronisableHeader::getSize() );
-      dest += h.getDataSize()+SynchronisableHeader::getSize();
-      origOffset += h.getDataSize()+SynchronisableHeader::getSize();
-      assert( Synchronisable::getSynchronisable(h.getObjectID()) );
-//       COUT(4) << "copy " << h.getObjectID() << endl;
-//       COUT(4) << "copy " << h.getObjectID() << ":";
-      //sizes += Synchronisable::getSynchronisable(h.getObjectID())->getNrOfVariables();
-      for( unsigned int i = 0; i < Synchronisable::getSynchronisable(h.getObjectID())->getNrOfVariables(); ++i )
+      else
       {
-//         COUT(4) << " " << *sizes;
-        ++sizes;
+//         COUT(4) << "copy object: " << Synchronisable::getSynchronisable(origHeader.getObjectID())->getIdentifier()->getName() << endl;
+        assert(baseDataPtr == oldBaseDataPtr);
+        copyObject(destDataPtr, origDataPtr, baseDataPtr, origHeader, sizesIt);
+        assert(sizesIt != this->sizes_.end() || origDataPtr==origDataEnd);
       }
-//       COUT(4) << endl;
-      assert(sizes != this->sizes_.end() || origOffset>=origLength);
-      continue;
     }
   }
+  assert(sizesIt==this->sizes_.end());
 
 
-  Gamestate *g = new Gamestate(nData, getClientID());
-  assert(g->header_);
-  *(g->header_) = *header_;
-  g->header_->setBaseID( base->getID() );
-  g->header_->setDataSize(dest - nData - GamestateHeader::getSize());
+  Gamestate *g = new Gamestate(newData, getPeerID());
+  (g->header_) = header_;
+  g->header_.setBaseID( base->getID() );
+  g->header_.setDataSize(destDataPtr - newData - GamestateHeader::getSize());
   g->flags_=flags_;
   g->packetDirection_ = packetDirection_;
   assert(!g->isCompressed());
@@ -578,15 +597,15 @@
 }
 
 
-Gamestate* Gamestate::diffData(Gamestate *base)
+/*Gamestate* Gamestate::diffData(Gamestate *base)
 {
   assert(this && base); assert(data_ && base->data_);
-  assert(!header_->isCompressed() && !base->header_->isCompressed());
-  assert(!header_->isDiffed());
+  assert(!header_.isCompressed() && !base->header_.isCompressed());
+  assert(!header_.isDiffed());
 
   uint8_t *basep = GAMESTATE_START(base->data_);
   uint8_t *gs = GAMESTATE_START(this->data_);
-  uint32_t dest_length = header_->getDataSize();
+  uint32_t dest_length = header_.getDataSize();
 
   if(dest_length==0)
     return NULL;
@@ -594,10 +613,10 @@
   uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+GamestateHeader::getSize()];
   uint8_t *dest = GAMESTATE_START(ndata);
 
-  rawDiff( dest, gs, basep, header_->getDataSize(), base->header_->getDataSize() );
+  rawDiff( dest, gs, basep, header_.getDataSize(), base->header_.getDataSize() );
 #ifndef NDEBUG
   uint8_t *dest2 = new uint8_t[dest_length];
-  rawDiff( dest2, dest, basep, header_->getDataSize(), base->header_->getDataSize() );
+  rawDiff( dest2, dest, basep, header_.getDataSize(), base->header_.getDataSize() );
   assert( memcmp( dest2, gs, dest_length) == 0 );
   delete dest2;
 #endif
@@ -605,8 +624,8 @@
   Gamestate *g = new Gamestate(ndata, getClientID());
   assert(g->header_);
   *(g->header_) = *header_;
-  g->header_->setDiffed( true );
-  g->header_->setBaseID( base->getID() );
+  g->header_.setDiffed( true );
+  g->header_.setBaseID( base->getID() );
   g->flags_=flags_;
   g->packetDirection_ = packetDirection_;
   assert(g->isDiffed());
@@ -618,12 +637,12 @@
 Gamestate* Gamestate::undiff(Gamestate *base)
 {
   assert(this && base); assert(data_ && base->data_);
-  assert(!header_->isCompressed() && !base->header_->isCompressed());
-  assert(header_->isDiffed());
+  assert(!header_.isCompressed() && !base->header_.isCompressed());
+  assert(header_.isDiffed());
 
   uint8_t *basep = GAMESTATE_START(base->data_);
   uint8_t *gs = GAMESTATE_START(this->data_);
-  uint32_t dest_length = header_->getDataSize();
+  uint32_t dest_length = header_.getDataSize();
 
   if(dest_length==0)
     return NULL;
@@ -631,12 +650,12 @@
   uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+GamestateHeader::getSize()];
   uint8_t *dest = ndata + GamestateHeader::getSize();
 
-  rawDiff( dest, gs, basep, header_->getDataSize(), base->header_->getDataSize() );
+  rawDiff( dest, gs, basep, header_.getDataSize(), base->header_.getDataSize() );
 
   Gamestate *g = new Gamestate(ndata, getClientID());
   assert(g->header_);
   *(g->header_) = *header_;
-  g->header_->setDiffed( false );
+  g->header_.setDiffed( false );
   g->flags_=flags_;
   g->packetDirection_ = packetDirection_;
   assert(!g->isDiffed());
@@ -669,15 +688,15 @@
       *(newdata+j) = *(data+j); // just copy
   }
   assert(j==datalength);
-}
+}*/
 
 
-Gamestate* Gamestate::doSelection(unsigned int clientID, unsigned int targetSize){
+/*Gamestate* Gamestate::doSelection(unsigned int clientID, unsigned int targetSize){
   assert(data_);
   std::list<obj>::iterator it;
 
   // allocate memory for new data
-  uint8_t *gdata = new uint8_t[header_->getDataSize()+GamestateHeader::getSize()];
+  uint8_t *gdata = new uint8_t[header_.getDataSize()+GamestateHeader::getSize()];
   // create a gamestate out of it
   Gamestate *gs = new Gamestate(gdata);
   uint8_t *newdata = gdata + GamestateHeader::getSize();
@@ -693,7 +712,7 @@
   //Synchronisable *object;
 
   //call TrafficControl
-  TrafficControl::getInstance()->processObjectList( clientID, header_->getID(), dataVector_ );
+  TrafficControl::getInstance()->processObjectList( clientID, header_.getID(), dataVector_ );
 
   //copy in the zeros
 //   std::list<obj>::iterator itt;
@@ -724,22 +743,22 @@
   }
 #ifndef NDEBUG
   uint32_t origsize = destsize;
-  while ( origsize < header_->getDataSize() )
+  while ( origsize < header_.getDataSize() )
   {
     SynchronisableHeader oldobjectheader(origdata);
     objectsize = oldobjectheader.getDataSize()+SynchronisableHeader::getSize();
     origdata += objectsize;
     origsize += objectsize;
   }
-  assert(origsize==header_->getDataSize());
+  assert(origsize==header_.getDataSize());
   assert(destsize!=0);
 #endif
-  gs->header_->setDataSize( destsize );
+  gs->header_.setDataSize( destsize );
   return gs;
-}
+}*/
 
 
-uint32_t Gamestate::calcGamestateSize(int32_t id, uint8_t mode)
+uint32_t Gamestate::calcGamestateSize(uint32_t id, uint8_t mode)
 {
   uint32_t size = 0;
   uint32_t nrOfVariables = 0;

Modified: code/trunk/src/libraries/network/packet/Gamestate.h
===================================================================
--- code/trunk/src/libraries/network/packet/Gamestate.h	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/libraries/network/packet/Gamestate.h	2010-12-22 18:24:24 UTC (rev 7801)
@@ -41,32 +41,42 @@
 #include "network/TrafficControl.h"
 #include "Packet.h"
 
-namespace orxonox {
+namespace orxonox
+{
 
-namespace packet {
+namespace packet
+{
+    
+static const uint8_t GAMESTATE_MODE_SERVER = 0x1;
+static const uint8_t GAMESTATE_MODE_CLIENT = 0x2;
 
-class _NetworkExport GamestateHeader{
+class _NetworkExport GamestateHeader
+{
   public:
-    GamestateHeader(uint8_t *data){ assert(data); data_ = data; *(uint32_t*)data_ = Type::Gamestate; }
-    GamestateHeader(uint8_t *data, GamestateHeader* h)
-    { assert(data); data_=data; memcpy(data_, h->data_, getSize()); }
+    GamestateHeader(){ data_=0; }
+    GamestateHeader(uint8_t* data)
+      { assert(data); data_ = data; *(uint32_t*)data_ = Type::Gamestate; }
+    /*GamestateHeader(uint8_t* data, GamestateHeader* h)
+      { assert(data); data_=data; memcpy(data_, h->data_, getSize()); }*/
+    void setData(uint8_t* data)
+      { assert(data); data_ = data; *(uint32_t*)data_ = Type::Gamestate; }
     static inline uint32_t getSize()
-    { return 21; }
+      { return 21; }
 
-    inline int32_t getID() const
-    { assert(data_); return *(int32_t*)(data_+4); }
-    inline void setID(int32_t id)
-    { assert(data_); *(int32_t*)(data_+4) = id; }
+    inline uint32_t getID() const
+      { assert(data_); return *(uint32_t*)(data_+4); }
+    inline void setID(uint32_t id)
+      { assert(data_); *(uint32_t*)(data_+4) = id; }
 
-    inline int32_t getBaseID() const
-    { assert(data_); return *(int32_t*)(data_+8); }
-    inline void setBaseID(int32_t id)
-    { assert(data_); *(int32_t*)(data_+8) = id; }
+    inline uint32_t getBaseID() const
+      { assert(data_); return *(uint32_t*)(data_+8); }
+    inline void setBaseID(uint32_t id)
+      { assert(data_); *(uint32_t*)(data_+8) = id; }
 
     inline uint32_t getDataSize() const
-    { assert(data_); return *(uint32_t*)(data_+12); }
+      { assert(data_); return *(uint32_t*)(data_+12); }
     inline void setDataSize(uint32_t size)
-    { assert(data_); *(uint32_t*)(data_+12) = size; }
+      { assert(data_); *(uint32_t*)(data_+12) = size; }
 
     inline uint32_t getCompSize() const
     { assert(data_); return *(uint32_t*)(data_+16); }
@@ -74,31 +84,32 @@
     { assert(data_); *(uint32_t*)(data_+16) = size; }
 
     inline bool isDiffed() const
-    { assert(data_); return *(int8_t*)(data_+20) & 0x1; }
+      { assert(data_); return *(int8_t*)(data_+20) & 0x1; }
     inline void setDiffed(bool b)
-    { assert(data_); *(int8_t*)(data_+20) = (b<<0) | (*(int8_t*)(data_+20) & 0x6 ); }
+      { assert(data_); *(int8_t*)(data_+20) = (b<<0) | (*(int8_t*)(data_+20) & 0x6 ); }
 
     inline bool isComplete() const
-    { assert(data_); return *(int8_t*)(data_+20) & 0x2; }
+      { assert(data_); return *(int8_t*)(data_+20) & 0x2; }
     inline void setComplete(bool b)
-    { assert(data_); *(int8_t*)(data_+20) = (b<<1) | (*(int8_t*)(data_+20) & 0x5 ); }
+      { assert(data_); *(int8_t*)(data_+20) = (b<<1) | (*(int8_t*)(data_+20) & 0x5 ); }
 
     inline bool isCompressed() const
-    { assert(data_); return *(int8_t*)(data_+20) & 0x4; }
+      { assert(data_); return *(int8_t*)(data_+20) & 0x4; }
     inline void setCompressed(bool b)
-    { assert(data_); *(int8_t*)(data_+20) = (b<<2) | (*(int8_t*)(data_+20) & 0x3 ); }
+      { assert(data_); *(int8_t*)(data_+20) = (b<<2) | (*(int8_t*)(data_+20) & 0x3 ); }
 
     inline void operator=(GamestateHeader& h)
-    { assert(data_); assert(h.data_); memcpy( data_, h.data_, getSize()); }
+      { assert(data_); assert(h.data_); memcpy( data_, h.data_, getSize()); }
   private:
-    uint8_t *data_;
+    uint8_t* data_;
 
 };
 
 /**
     @author Oliver Scheuss
 */
-class _NetworkExport Gamestate: public Packet{
+class _NetworkExport Gamestate: public Packet
+{
   public:
     Gamestate();
     Gamestate(uint8_t *data, unsigned int clientID);
@@ -109,29 +120,31 @@
 
     bool collectData(int id, uint8_t mode=0x0);
     bool spreadData( uint8_t mode=0x0);
-    inline int32_t getID() const { return header_->getID(); }
-    inline bool isDiffed() const { return header_->isDiffed(); }
-    inline bool isCompressed() const { return header_->isCompressed(); }
-    inline int32_t getBaseID() const { return header_->getBaseID(); }
-    inline uint32_t getDataSize() const { return header_->getDataSize(); }
+    inline uint32_t getID() const { return header_.getID(); }
+    inline bool isDiffed() const { return header_.isDiffed(); }
+    inline bool isCompressed() const { return header_.isCompressed(); }
+    inline int32_t getBaseID() const { return header_.getBaseID(); }
+    inline uint32_t getDataSize() const { return header_.getDataSize(); }
     Gamestate* diffVariables(Gamestate *base);
-    Gamestate* diffData(Gamestate *base);
-    Gamestate *undiff(Gamestate *base);
-    Gamestate* doSelection(unsigned int clientID, unsigned int targetSize);
+//     Gamestate* diffData(Gamestate *base);
+//     Gamestate *undiff(Gamestate *base);
+//     Gamestate* doSelection(unsigned int clientID, unsigned int targetSize);
     bool compressData();
     bool decompressData();
     bool operator ==(packet::Gamestate gs);
 
     // Packet functions
   private:
-    void rawDiff( uint8_t* newdata, uint8_t* data, uint8_t* basedata, uint32_t datalength, uint32_t baselength);
-    inline uint32_t findObject( const SynchronisableHeader& header, uint8_t* mem, uint32_t dataLength, uint32_t startPosition = 0 );
+//     void rawDiff( uint8_t* newdata, uint8_t* data, uint8_t* basedata, uint32_t datalength, uint32_t baselength);
+//     inline uint32_t findObject( const SynchronisableHeader& header, uint8_t* mem, uint32_t dataLength, uint32_t startPosition = 0 );
     virtual uint32_t getSize() const;
-    virtual inline bool process();
-    uint32_t calcGamestateSize(int32_t id, uint8_t mode=0x0);
+    virtual bool process(orxonox::Host* host);
+    uint32_t calcGamestateSize(uint32_t id, uint8_t mode=0x0);
+//     inline void diffObject( uint8_t*& newData, uint8_t*& origData, uint8_t*& baseData, SynchronisableHeader& objectHeader, std::vector<uint32_t>::iterator& sizes );
+//     inline void copyObject( uint8_t*& newData, uint8_t*& origData, uint8_t*& baseData, SynchronisableHeader& objectHeader, std::vector<uint32_t>::iterator& sizes );
     
     std::list<obj>          dataVector_;
-    GamestateHeader*        header_;
+    GamestateHeader         header_;
     std::vector<uint32_t>   sizes_;
     uint32_t                nrOfVariables_;
 };

Modified: code/trunk/src/libraries/network/packet/Packet.cc
===================================================================
--- code/trunk/src/libraries/network/packet/Packet.cc	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/libraries/network/packet/Packet.cc	2010-12-22 18:24:24 UTC (rev 7801)
@@ -34,6 +34,7 @@
 #define WIN32_LEAN_AND_MEAN
 #include <enet/enet.h>
 #include <boost/static_assert.hpp>
+#include <boost/thread/mutex.hpp>
 
 #include "util/Debug.h"
 #include "Acknowledgement.h"
@@ -52,30 +53,31 @@
 namespace packet{
 
 // Make sure we assume the right values
-BOOST_STATIC_ASSERT(static_cast<int>(PacketFlag::Reliable)   == static_cast<int>(ENET_PACKET_FLAG_RELIABLE));
-BOOST_STATIC_ASSERT(static_cast<int>(PacketFlag::Unsequence) == static_cast<int>(ENET_PACKET_FLAG_UNSEQUENCED));
-BOOST_STATIC_ASSERT(static_cast<int>(PacketFlag::NoAllocate) == static_cast<int>(ENET_PACKET_FLAG_NO_ALLOCATE));
+BOOST_STATIC_ASSERT(static_cast<int>(PacketFlag::Reliable)    == static_cast<int>(ENET_PACKET_FLAG_RELIABLE));
+BOOST_STATIC_ASSERT(static_cast<int>(PacketFlag::Unsequenced) == static_cast<int>(ENET_PACKET_FLAG_UNSEQUENCED));
+BOOST_STATIC_ASSERT(static_cast<int>(PacketFlag::NoAllocate)  == static_cast<int>(ENET_PACKET_FLAG_NO_ALLOCATE));
 
 #define PACKET_FLAG_DEFAULT PacketFlag::NoAllocate
 #define _PACKETID           0
 
 std::map<size_t, Packet *> Packet::packetMap_;
+boost::mutex Packet::packetMapMutex_;
 
 Packet::Packet()
 {
   flags_ = PACKET_FLAG_DEFAULT;
   packetDirection_ = Direction::Outgoing;
-  clientID_=0;
+  peerID_=0;
   data_=0;
   enetPacket_=0;
   bDataENetAllocated_ = false;
 }
 
-Packet::Packet(uint8_t *data, unsigned int clientID)
+Packet::Packet(uint8_t *data, unsigned int peerID)
 {
   flags_ = PACKET_FLAG_DEFAULT;
   packetDirection_ = Direction::Incoming;
-  clientID_=clientID;
+  peerID_=peerID;
   data_=data;
   enetPacket_=0;
   bDataENetAllocated_ = false;
@@ -86,7 +88,7 @@
   enetPacket_=p.enetPacket_;
   flags_=p.flags_;
   packetDirection_ = p.packetDirection_;
-  clientID_ = p.clientID_;
+  peerID_ = p.peerID_;
   if(p.data_){
     data_ = new uint8_t[p.getSize()];
     memcpy(data_, p.data_, p.getSize());
@@ -122,7 +124,7 @@
   }
 }
 
-bool Packet::send(){
+bool Packet::send(orxonox::Host* host){
   if(packetDirection_ != Direction::Outgoing && packetDirection_ != Direction::Bidirectional ){
     assert(0);
     return false;
@@ -141,7 +143,9 @@
     {
       // Assures we don't create a packet and destroy it right after in another thread
       // without having a reference in the packetMap_
+      Packet::packetMapMutex_.lock();
       packetMap_[reinterpret_cast<size_t>(enetPacket_)] = this;
+      Packet::packetMapMutex_.unlock();
     }
   }
 #ifndef NDEBUG
@@ -163,54 +167,58 @@
 #endif
 //  ENetPacket *temp = enetPacket_;
 //  enetPacket_ = 0; // otherwise we have a double free because enet already handles the deallocation of the packet
-  if(!Host::addPacket( enetPacket_, clientID_))
-    enet_packet_destroy(this->enetPacket_); // if we could not add the packet to the enet queue delete it manually
+  if( this->flags_ & PacketFlag::Reliable )
+    host->addPacket( enetPacket_, peerID_, NETWORK_CHANNEL_DEFAULT);
+  else
+    host->addPacket( enetPacket_, peerID_, NETWORK_CHANNEL_UNRELIABLE);
   return true;
 }
 
 Packet *Packet::createPacket(ENetPacket *packet, ENetPeer *peer){
   uint8_t *data = packet->data;
   assert(ClientInformation::findClient(&peer->address)->getID() != static_cast<unsigned int>(-2) || !Host::isServer());
-  unsigned int clientID = ClientInformation::findClient(&peer->address)->getID();
+  unsigned int peerID = ClientInformation::findClient(&peer->address)->getID();
+  // HACK
+  if( peerID==static_cast<unsigned int>(-2))
+    peerID = NETWORK_PEER_ID_SERVER;
   Packet *p = 0;
-  COUT(6) << "packet type: " << *(Type::Value *)&data[_PACKETID] << std::endl;
+//   COUT(6) << "packet type: " << *(Type::Value *)&data[_PACKETID] << std::endl;
   switch( *(Type::Value *)(data + _PACKETID) )
   {
     case Type::Acknowledgement:
-      COUT(5) << "ack" << std::endl;
-      p = new Acknowledgement( data, clientID );
+//       COUT(5) << "ack" << std::endl;
+    p = new Acknowledgement( data, peerID );
       break;
     case Type::Chat:
-      COUT(5) << "chat" << std::endl;
-      p = new Chat( data, clientID );
+//       COUT(5) << "chat" << std::endl;
+      p = new Chat( data, peerID );
       break;
     case Type::ClassID:
-      COUT(5) << "classid" << std::endl;
-      p = new ClassID( data, clientID );
+//       COUT(5) << "classid" << std::endl;
+      p = new ClassID( data, peerID );
       break;
     case Type::Gamestate:
-      COUT(5) << "gamestate" << std::endl;
-      // TODO: remove brackets
-      p = new Gamestate( data, clientID );
+//       COUT(5) << "gamestate" << std::endl;
+      p = new Gamestate( data, peerID );
       break;
     case Type::Welcome:
-      COUT(5) << "welcome" << std::endl;
-      p = new Welcome( data, clientID );
+//       COUT(5) << "welcome" << std::endl;
+      p = new Welcome( data, peerID );
       break;
     case Type::DeleteObjects:
-      COUT(5) << "deleteobjects" << std::endl;
-      p = new DeleteObjects( data, clientID );
+//       COUT(5) << "deleteobjects" << std::endl;
+      p = new DeleteObjects( data, peerID );
       break;
     case Type::FunctionCalls:
-      COUT(5) << "functionCalls" << std::endl;
-      p = new FunctionCalls( data, clientID );
+//       COUT(5) << "functionCalls" << std::endl;
+      p = new FunctionCalls( data, peerID );
       break;
     case Type::FunctionIDs:
-      COUT(5) << "functionIDs" << std::endl;
-      p = new FunctionIDs( data, clientID );
+//       COUT(5) << "functionIDs" << std::endl;
+      p = new FunctionIDs( data, peerID );
       break;
     default:
-      assert(0); //TODO: repair this
+      assert(0);
       break;
   }
 
@@ -228,13 +236,15 @@
 */
 void Packet::deletePacket(ENetPacket *enetPacket){
   // Get our Packet from a global map with all Packets created in the send() method of Packet.
+  Packet::packetMapMutex_.lock();
   std::map<size_t, Packet*>::iterator it = packetMap_.find(reinterpret_cast<size_t>(enetPacket));
   assert(it != packetMap_.end());
   // Make sure we don't delete it again in the destructor
   it->second->enetPacket_ = 0;
   delete it->second;
   packetMap_.erase(it);
-  COUT(6) << "PacketMap size: " << packetMap_.size() << std::endl;
+  Packet::packetMapMutex_.unlock();
+//   COUT(6) << "PacketMap size: " << packetMap_.size() << std::endl;
 }
 
 } // namespace packet

Modified: code/trunk/src/libraries/network/packet/Packet.h
===================================================================
--- code/trunk/src/libraries/network/packet/Packet.h	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/libraries/network/packet/Packet.h	2010-12-22 18:24:24 UTC (rev 7801)
@@ -67,24 +67,29 @@
 
     virtual unsigned char *getData(){ return data_; };
     virtual unsigned int getSize() const =0;
-    virtual bool process()=0;
+    virtual bool process(orxonox::Host* host)=0;
     inline uint32_t getFlags()
       { return flags_; }
-    inline int getClientID()
-      { return clientID_; }
-    inline void setClientID( int id )
-      { clientID_ = id; }
+    inline int getPeerID()
+      { return peerID_; }
+    inline void setPeerID( int id )
+      { peerID_ = id; }
+    inline bool isReliable()
+      { return this->flags_ & PacketFlag::Reliable; }
+    inline uint32_t getRequiredGamestateID()
+      { return this->requiredGamestateID_; }
 
-    virtual bool send();
+    virtual bool send(orxonox::Host* host);
   protected:
     Packet();
-    Packet(uint8_t *data, unsigned int clientID);
+    Packet(uint8_t *data, unsigned int peerID);
 //    Packet(ENetPacket *packet, ENetPeer *peer);
     inline bool isDataENetAllocated() const
       { return bDataENetAllocated_; }
 
     uint32_t flags_;
-    unsigned int clientID_;
+    unsigned int peerID_;
+    uint32_t requiredGamestateID_;
     Direction::Value packetDirection_;
     /** Pointer to the data. Be careful when deleting it because it might
         point to a location that was allocated by ENet.
@@ -95,6 +100,7 @@
     bool bDataENetAllocated_;
   private:
     static std::map<size_t, Packet *> packetMap_;
+    static boost::mutex               packetMapMutex_;
     ENetPacket *enetPacket_;
 };
 

Modified: code/trunk/src/libraries/network/packet/ServerInformation.cc
===================================================================
--- code/trunk/src/libraries/network/packet/ServerInformation.cc	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/libraries/network/packet/ServerInformation.cc	2010-12-22 18:24:24 UTC (rev 7801)
@@ -20,7 +20,7 @@
  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  *
  *   Author:
- *      Fabian 'x3n' Landau
+ *      Oliver Scheuss
  *   Co-authors:
  *      ...
  *
@@ -57,7 +57,11 @@
       uint8_t* temp = event->packet->data;
       char* ack = new char[strlen(LAN_DISCOVERY_ACK)+1];
       loadAndIncrease((char*&)ack, temp);
-      assert(strcmp(ack, (const char*)LAN_DISCOVERY_ACK)==0);
+
+      /* Fabian, what is this used for? it crashes the masterserver, hence commenting it */
+      // written by Oli: this is just to make sure that loadAndIncrease really writes the whole ACK string into char* ack
+//       assert(strcmp(ack, (const char*)LAN_DISCOVERY_ACK)==0);
+
       // Save Server Name
       loadAndIncrease(this->serverName_, temp);
     }

Modified: code/trunk/src/libraries/network/packet/ServerInformation.h
===================================================================
--- code/trunk/src/libraries/network/packet/ServerInformation.h	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/libraries/network/packet/ServerInformation.h	2010-12-22 18:24:24 UTC (rev 7801)
@@ -20,7 +20,7 @@
  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  *
  *   Author:
- *      Fabian 'x3n' Landau
+ *      Oliver Scheuss
  *   Co-authors:
  *      ...
  *
@@ -49,6 +49,7 @@
         std::string   getServerIP() { return this->serverIP_; }
         std::string   getServerName() { return this->serverName_; }
         void          setServerName(std::string name) { this->serverName_ = name; }
+        void          setServerIP( std::string IP ) { this->serverIP_ = IP; }
         uint32_t      getServerRTT() { return this->serverRTT_; }
         
       private:

Modified: code/trunk/src/libraries/network/packet/Welcome.cc
===================================================================
--- code/trunk/src/libraries/network/packet/Welcome.cc	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/libraries/network/packet/Welcome.cc	2010-12-22 18:24:24 UTC (rev 7801)
@@ -72,11 +72,11 @@
   return sizeof(packet::Type::Value) + 2*sizeof(uint32_t);
 }
 
-bool Welcome::process(){
+bool Welcome::process(orxonox::Host* host){
   uint32_t clientID;
   clientID = *(uint32_t *)(data_ + _CLIENTID );
   assert(*(uint32_t *)(data_ + _ENDIANTEST ) == 0xFEDC4321);
-  Host::setClientID(clientID);
+  host->setClientID(clientID);
   COUT(3) << "Welcome set clientId: " << clientID << endl;
   Synchronisable::setClient(true);
   delete this;

Modified: code/trunk/src/libraries/network/packet/Welcome.h
===================================================================
--- code/trunk/src/libraries/network/packet/Welcome.h	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/libraries/network/packet/Welcome.h	2010-12-22 18:24:24 UTC (rev 7801)
@@ -46,7 +46,7 @@
 
   uint8_t *getData();
   inline unsigned int getSize() const;
-  bool process();
+  virtual bool process(orxonox::Host* host);
 
 private:
 };

Modified: code/trunk/src/libraries/network/synchronisable/Synchronisable.cc
===================================================================
--- code/trunk/src/libraries/network/synchronisable/Synchronisable.cc	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/libraries/network/synchronisable/Synchronisable.cc	2010-12-22 18:24:24 UTC (rev 7801)
@@ -122,7 +122,12 @@
   Synchronisable *Synchronisable::fabricate(uint8_t*& mem, uint8_t mode)
   {
     SynchronisableHeader header(mem);
-    assert( !header.isDiffed() );
+    if( header.isDiffed() )
+    {
+      mem += header.getDataSize() + header.getSize();
+      return 0;
+    }
+//     assert( !header.isDiffed() );
 
     COUT(4) << "fabricating object with id: " << header.getObjectID() << std::endl;
 
@@ -216,11 +221,11 @@
    * |totalsize,objectID_,classID_,var1,var2,string1_length,string1,var3,...|
    * length of varx: size saved int syncvarlist
    * @param mem pointer to allocated memory with enough size
-   * @param sizes FIXME - add doc!
+   * @param sizes vector containing sizes of all objects in gamestate (to be appended)
    * @param id gamestateid of the gamestate to be saved (important for priorities)
    * @param mode defines the direction in which the data will be send/received
    *             0x1: server->client
-   *             0x2: client->server (not recommended)
+   *             0x2: client->server
    *             0x3: bidirectional
    * @return true: if !doSync or if everything was successfully saved
    */
@@ -264,6 +269,7 @@
       ++test;
       //tempsize += (*i)->getSize( mode );
     }
+    assert(tempsize!=0);  // if this happens an empty object (with no variables) would be transmitted
 //     COUT(4) << endl;
 
     header.setObjectID( this->objectID_ );
@@ -315,7 +321,7 @@
       assert( this->getCreatorID() == syncHeader2.getCreatorID() );
       mem += SynchronisableHeader::getSize();
       std::vector<SynchronisableVariableBase *>::iterator i;
-      for(i=syncList_.begin(); i!=syncList_.end(); i++)
+      for(i=syncList_.begin(); i!=syncList_.end(); ++i)
       {
         assert( mem <= data+syncHeader2.getDataSize()+SynchronisableHeader::getSize() ); // always make sure we don't exceed the datasize in our stream
         (*i)->putData( mem, mode, forceCallback );

Modified: code/trunk/src/libraries/network/synchronisable/Synchronisable.h
===================================================================
--- code/trunk/src/libraries/network/synchronisable/Synchronisable.h	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/libraries/network/synchronisable/Synchronisable.h	2010-12-22 18:24:24 UTC (rev 7801)
@@ -64,33 +64,29 @@
       VeryLow     = 100
     };
   }
-  
-  typedef uint8_t VariableID;
 
-  /**
-   * @brief: stores information about a Synchronisable
+    /**
+   * @brief: stores information about a Synchronisable (light version)
    *
-   * This class stores the information about a Synchronisable (objectID_, classID_, creatorID_, dataSize)
+   * This class stores the information about a Synchronisable (objectID_, dataSize)
    * in an emulated bitset.
    * Bit 1 to 31 store the size of the Data the synchronisable consumes in the stream
    * Bit 32 is a bool and defines whether the variables are stored in diff mode
    * Byte 5 to 8: objectID_
-   * Byte 9 to 12: classID_
-   * Byte 13 to 16: creatorID_
    */
-  class _NetworkExport SynchronisableHeader{
-    friend class SynchronisableHeaderLight;
-    private:
+  class _NetworkExport SynchronisableHeaderLight
+  {
+    protected:
       uint8_t* data_;
     public:
-      SynchronisableHeader(uint8_t* data)
+      SynchronisableHeaderLight(uint8_t* data)
         { data_ = data; }
       inline static uint32_t getSize()
-        { return 14; }
+        { return 6; }
       inline uint16_t getDataSize() const
-        { return (*(uint16_t*)data_) & 0x7FFF; } //only use the first 15 bits
+        { return (*(uint16_t*)data_) & 0x7FFF; } //only use the first 31 bits
       inline void setDataSize(uint16_t size)
-        { *(uint16_t*)(data_) = (size & 0x7FFF) | (*(uint16_t*)(data_) & 0x8000 ); }
+        { *(uint16_t*)(data_) = (size & 0x7FFFFFFF) | (*(uint16_t*)(data_) & 0x8000 ); }
       inline bool isDiffed() const
         { return ( (*(uint16_t*)data_) & 0x8000 ) == 0x8000; }
       inline void setDiffed( bool b)
@@ -99,50 +95,46 @@
         { return *(uint32_t*)(data_+2); }
       inline void setObjectID(uint32_t objectID_)
         { *(uint32_t*)(data_+2) = objectID_; }
-      inline uint32_t getClassID() const
-        { return *(uint32_t*)(data_+6); }
-      inline void setClassID(uint32_t classID_)
-        { *(uint32_t*)(data_+6) = classID_; }
-      inline uint32_t getCreatorID() const
-        { return *(uint32_t*)(data_+10); }
-      inline void setCreatorID(uint32_t creatorID_)
-        { *(uint32_t*)(data_+10) = creatorID_; }
-      inline void operator=(SynchronisableHeader& h)
-        { memcpy(data_, h.data_, getSize()); }
+      inline void operator=(SynchronisableHeaderLight& h)
+        { memcpy(data_, h.data_, SynchronisableHeaderLight::getSize()); }
   };
-
-    /**
-   * @brief: stores information about a Synchronisable (light version)
+  
+  typedef uint8_t VariableID;
+  
+  /**
+   * @brief: stores information about a Synchronisable
    *
-   * This class stores the information about a Synchronisable (objectID_, dataSize)
+   * This class stores the information about a Synchronisable (objectID_, classID_, creatorID_, dataSize)
    * in an emulated bitset.
    * Bit 1 to 31 store the size of the Data the synchronisable consumes in the stream
    * Bit 32 is a bool and defines whether the variables are stored in diff mode
    * Byte 5 to 8: objectID_
+   * Byte 9 to 12: classID_
+   * Byte 13 to 16: creatorID_
    */
-  class _NetworkExport SynchronisableHeaderLight{
-    private:
-      uint8_t* data_;
+  class _NetworkExport SynchronisableHeader: public SynchronisableHeaderLight
+  {
     public:
-      SynchronisableHeaderLight(uint8_t* data)
-        { data_ = data; }
+      SynchronisableHeader(uint8_t* data): SynchronisableHeaderLight(data)
+        {}
       inline static uint32_t getSize()
-        { return 6; }
-      inline uint16_t getDataSize() const
-        { return (*(uint16_t*)data_) & 0x7FFF; } //only use the first 31 bits
-      inline void setDataSize(uint16_t size)
-        { *(uint16_t*)(data_) = (size & 0x7FFFFFFF) | (*(uint16_t*)(data_) & 0x8000 ); }
-      inline bool isDiffed() const
-        { return ( (*(uint16_t*)data_) & 0x8000 ) == 0x8000; }
-      inline void setDiffed( bool b)
-        { *(uint16_t*)(data_) = (b << 15) | (*(uint16_t*)(data_) & 0x7FFF ); }
-      inline uint32_t getObjectID() const
-        { return *(uint32_t*)(data_+2); }
-      inline void setObjectID(uint32_t objectID_)
-        { *(uint32_t*)(data_+2) = objectID_; }
+        { return SynchronisableHeaderLight::getSize()+8; }
+      inline uint32_t getClassID() const
+        { return *(uint32_t*)(data_+SynchronisableHeaderLight::getSize()); }
+      inline void setClassID(uint32_t classID_)
+        { *(uint32_t*)(data_+SynchronisableHeaderLight::getSize()) = classID_; }
+      inline uint32_t getCreatorID() const
+        { return *(uint32_t*)(data_+SynchronisableHeaderLight::getSize()+4); }
+      inline void setCreatorID(uint32_t creatorID_)
+        { *(uint32_t*)(data_+SynchronisableHeaderLight::getSize()+4) = creatorID_; }
       inline void operator=(SynchronisableHeader& h)
         { memcpy(data_, h.data_, getSize()); }
   };
+  
+//   inline void operator=(SynchronisableHeaderLight& h1, SynchronisableHeader& h2)
+//   {
+//     memcpy(h1.data_, h2.data_, h1.getSize());
+//   }
 
   /**
   * This class is the base class of all the Objects in the universe that need to be synchronised over the network

Modified: code/trunk/src/libraries/util/SignalHandler.cc
===================================================================
--- code/trunk/src/libraries/util/SignalHandler.cc	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/libraries/util/SignalHandler.cc	2010-12-22 18:24:24 UTC (rev 7801)
@@ -50,6 +50,7 @@
 #include <X11/Xlib.h>
 #include <X11/Xutil.h>
 #include <X11/keysym.h>
+#include <sys/prctl.h>
 
 namespace orxonox
 {
@@ -136,10 +137,52 @@
 
       COUT(0) << "Received signal " << sigName.c_str() << std::endl << "Try to write backtrace to file orxonox_crash.log" << std::endl;
 
+      
+      // First start GDB which will be attached to this process later on
+      
+      int gdbIn[2];
+      int gdbOut[2];
+      int gdbErr[2];
+      
+      if ( pipe(gdbIn) == -1 || pipe(gdbOut) == -1 || pipe(gdbErr) == -1 )
+      {
+        perror("pipe failed!\n");
+        exit(EXIT_FAILURE);
+      }
+      
+      int gdbPid = fork();
+      // this process will run gdb
+      
+      if ( gdbPid == -1 )
+      {
+        perror("fork failed\n");
+        exit(EXIT_FAILURE);
+      }
+      
+      if ( gdbPid == 0 )
+      {
+        // start gdb
+        
+        close(gdbIn[1]);
+        close(gdbOut[0]);
+        close(gdbErr[0]);
+        
+        dup2( gdbIn[0], STDIN_FILENO );
+        dup2( gdbOut[1], STDOUT_FILENO );
+        dup2( gdbErr[1], STDERR_FILENO );
+        
+        execlp( "sh", "sh", "-c", "gdb", static_cast<void*>(NULL));
+      }
+      
+      
+      // Now start a fork of this process on which GDB will be attached on
+      
       int sigPipe[2];
       if ( pipe(sigPipe) == -1 )
       {
         perror("pipe failed!\n");
+        kill( gdbPid, SIGTERM );
+        waitpid( gdbPid, NULL, 0 );
         exit(EXIT_FAILURE);
       }
 
@@ -148,6 +191,8 @@
       if ( sigPid == -1 )
       {
         perror("fork failed!\n");
+        kill( gdbPid, SIGTERM );
+        waitpid( gdbPid, NULL, 0 );
         exit(EXIT_FAILURE);
       }
 
@@ -155,10 +200,18 @@
       if ( sigPid == 0 )
       {
         getInstance().dontCatch();
+        
+        // make sure gdb is allowed to attach to our PID even if there are some system restrictions
+#ifdef PR_SET_PTRACER
+        if( prctl(PR_SET_PTRACER, gdbPid, 0, 0, 0) == -1 )
+          COUT(0) << "could not set proper permissions for GDB to attach to process..." << endl;
+#endif
+        
         // wait for message from parent when it has attached gdb
         int someData;
 
-        read( sigPipe[0], &someData, sizeof(someData) );
+        if( read( sigPipe[0], &someData, sizeof(someData) ) != sizeof(someData) )
+          COUT(0) << "something went wrong :(" << std::endl;
 
         if ( someData != 0x12345678 )
         {
@@ -168,44 +221,6 @@
         return;
       }
 
-      int gdbIn[2];
-      int gdbOut[2];
-      int gdbErr[2];
-
-      if ( pipe(gdbIn) == -1 || pipe(gdbOut) == -1 || pipe(gdbErr) == -1 )
-      {
-        perror("pipe failed!\n");
-        kill( sigPid, SIGTERM );
-        waitpid( sigPid, NULL, 0 );
-        exit(EXIT_FAILURE);
-      }
-
-      int gdbPid = fork();
-      // this process will run gdb
-
-      if ( gdbPid == -1 )
-      {
-        perror("fork failed\n");
-        kill( sigPid, SIGTERM );
-        waitpid( sigPid, NULL, 0 );
-        exit(EXIT_FAILURE);
-      }
-
-      if ( gdbPid == 0 )
-      {
-        // start gdb
-
-        close(gdbIn[1]);
-        close(gdbOut[0]);
-        close(gdbErr[0]);
-
-        dup2( gdbIn[0], STDIN_FILENO );
-        dup2( gdbOut[1], STDOUT_FILENO );
-        dup2( gdbErr[1], STDERR_FILENO );
-
-        execlp( "sh", "sh", "-c", "gdb", static_cast<void*>(NULL));
-      }
-
       char cmd[256];
       snprintf( cmd, 256, "file %s\nattach %d\nc\n", getInstance().appName.c_str(), sigPid );
       write( gdbIn[1], cmd, strlen(cmd) );

Modified: code/trunk/src/modules/objects/ForceField.cc
===================================================================
--- code/trunk/src/modules/objects/ForceField.cc	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/modules/objects/ForceField.cc	2010-12-22 18:24:24 UTC (rev 7801)
@@ -59,6 +59,8 @@
         this->setDiameter(500);
         this->setLength(2000);
         this->mode_ = forceFieldMode::tube;
+        
+        this->registerVariables();
     }
 
     /**
@@ -82,7 +84,16 @@
         XMLPortParam(ForceField, "length", setLength  , getLength  , xmlelement, mode).defaultValues(2000);
         XMLPortParam(ForceField, "mode", setMode, getMode, xmlelement, mode);
     }
+    
+    void ForceField::registerVariables()
+    {
+        registerVariable(this->velocity_, VariableDirection::ToClient);
+        registerVariable(this->radius_, VariableDirection::ToClient);
+        registerVariable(this->halfLength_, VariableDirection::ToClient);
+        registerVariable(this->mode_, VariableDirection::ToClient);
+    }
 
+
     /**
     @brief
         A method that is called every tick.

Modified: code/trunk/src/modules/objects/ForceField.h
===================================================================
--- code/trunk/src/modules/objects/ForceField.h	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/modules/objects/ForceField.h	2010-12-22 18:24:24 UTC (rev 7801)
@@ -87,7 +87,9 @@
             virtual ~ForceField();
 
             virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Creates a ForceField object through XML.
+            void registerVariables(); //!< Registers the variables that should get synchronised over the network
             virtual void tick(float dt); //!< A method that is called every tick.
+            
 
             /**
             @brief Set the velocity of the ForceField.
@@ -140,7 +142,7 @@
             float velocity_; //!< The velocity of the ForceField.
             float radius_; //!< The radius of the ForceField.
             float halfLength_; //!< Half of the length of the ForceField.
-            forceFieldMode::Value mode_; //!< The mode of the ForceField.
+            int mode_; //!< The mode of the ForceField.
   };
 }
 

Modified: code/trunk/src/modules/overlays/hud/HUDBar.cc
===================================================================
--- code/trunk/src/modules/overlays/hud/HUDBar.cc	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/modules/overlays/hud/HUDBar.cc	2010-12-22 18:24:24 UTC (rev 7801)
@@ -84,7 +84,7 @@
             .createOverlayElement("Panel", "HUDBar_bar_" + getUniqueNumberString()));
         this->bar_->setMaterialName(materialname);
 
-        this->value_ = 1.0f;  // initielize with 1.0f to trigger a change when calling setValue(0.0f) on the line below
+        this->value_ = 1.0f;  // initialize with 1.0f to trigger a change when calling setValue(0.0f) on the line below
         this->setAutoColour(true);
         this->setValue(0.0f); // <--
         this->setRightToLeft(false);
@@ -160,7 +160,7 @@
         // set value
         if (this->right2Left_)
         {
-            // backward casew
+            // backward case
             this->bar_->setPosition(0.06f + 0.88f * (1 - this->value_), 0.0f);
             this->bar_->setDimensions(0.88f * this->value_, 1.0f);
         }

Modified: code/trunk/src/modules/overlays/hud/HUDNavigation.cc
===================================================================
--- code/trunk/src/modules/overlays/hud/HUDNavigation.cc	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/modules/overlays/hud/HUDNavigation.cc	2010-12-22 18:24:24 UTC (rev 7801)
@@ -23,6 +23,7 @@
  *      Felix Schulthess
  *   Co-authors:
  *      Reto Grieder
+ *      Oliver Scheuss
  *
  */
 
@@ -409,4 +410,5 @@
             this->addObject ( *it );
     }
 }
+
 }

Modified: code/trunk/src/modules/pickup/PickupManager.cc
===================================================================
--- code/trunk/src/modules/pickup/PickupManager.cc	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/modules/pickup/PickupManager.cc	2010-12-22 18:24:24 UTC (rev 7801)
@@ -60,7 +60,7 @@
     // Initialization of the name of the PickupInventory GUI.
     /*static*/ const std::string PickupManager::guiName_s = "PickupInventory";
 
-    // Register static newtork functions that are used to communicate changes to pickups over the network, such that the PickupInventory can display the information about the pickups properly.
+    // Register static network functions that are used to communicate changes to pickups over the network, such that the PickupInventory can display the information about the pickups properly.
     registerStaticNetworkFunction(PickupManager::pickupChangedUsedNetwork);
     registerStaticNetworkFunction(PickupManager::pickupChangedPickedUpNetwork);
     registerStaticNetworkFunction(PickupManager::dropPickupNetworked);

Modified: code/trunk/src/modules/pickup/PickupSpawner.cc
===================================================================
--- code/trunk/src/modules/pickup/PickupSpawner.cc	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/modules/pickup/PickupSpawner.cc	2010-12-22 18:24:24 UTC (rev 7801)
@@ -119,7 +119,7 @@
     */
     PickupSpawner::~PickupSpawner()
     {
-        if(this->selfDestruct_ && this->pickup_ != NULL)
+        if(this->isInitialized() && this->selfDestruct_ && this->pickup_ != NULL)
             this->pickup_->destroy();
     }
 
@@ -316,7 +316,9 @@
 
             assert(pickup);
             assert(target);
-            assert(pickup->pickup(target));
+            bool pickedUp = pickup->pickup(target);
+            assert(pickedUp);
+            pickedUp = false; // To avoid compiler warning.
 
             this->decrementSpawnsRemaining();
         }

Modified: code/trunk/src/modules/weapons/MuzzleFlash.cc
===================================================================
--- code/trunk/src/modules/weapons/MuzzleFlash.cc	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/modules/weapons/MuzzleFlash.cc	2010-12-22 18:24:24 UTC (rev 7801)
@@ -41,6 +41,7 @@
         RegisterObject(MuzzleFlash);
         this->setScale(0.1f);
 
-        this->delayTimer_.setTimer(0.1f, false, createExecutor(createFunctor(&MuzzleFlash::destroy, this)));
+        if( GameMode::isMaster() )
+          this->delayTimer_.setTimer(0.1f, false, createExecutor(createFunctor(&MuzzleFlash::destroy, this)));
     }
 }

Modified: code/trunk/src/orxonox/LevelManager.cc
===================================================================
--- code/trunk/src/orxonox/LevelManager.cc	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/orxonox/LevelManager.cc	2010-12-22 18:24:24 UTC (rev 7801)
@@ -151,6 +151,7 @@
     {
         Ogre::StringVectorPtr levels = Resource::findResourceNames("*.oxw");
         // Iterate over all *.oxw level files.
+        COUT(3) << "Loading LevelInfos..." << std::endl;
         for (Ogre::StringVector::const_iterator it = levels->begin(); it != levels->end(); ++it)
         {
             //TODO: Replace with tag,

Modified: code/trunk/src/orxonox/Main.cc
===================================================================
--- code/trunk/src/orxonox/Main.cc	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/orxonox/Main.cc	2010-12-22 18:24:24 UTC (rev 7801)
@@ -53,6 +53,9 @@
     SetCommandLineSwitch(standalone).information("Start in standalone mode");
     SetCommandLineSwitch(dedicatedClient).information("Start in dedicated client mode");
 
+    /* ADD masterserver command */
+    SetCommandLineSwitch(masterserver).information("Start in masterserver mode");
+
     SetCommandLineArgument(generateDoc, "")
         .information("Generates a Doxygen file from things like SetConsoleCommand");
 
@@ -66,13 +69,14 @@
 
         if (CommandLineParser::getValue("generateDoc").getString().empty())
         {
+            /* TODO make this clear */
             game->setStateHierarchy(
             "root"
             " graphics"
             "  mainMenu"
             "  standalone,server,client"
             "   level"
-            " server,client"
+            " server,client,masterserver"
             "  level"
             );
 
@@ -89,6 +93,9 @@
                 Game::getInstance().requestStates("server, level");
             else if (CommandLineParser::getValue("dedicatedClient").getBool())
                 Game::getInstance().requestStates("client, level");
+            /* ADD masterserver command */
+            else if (CommandLineParser::getValue("masterserver").getBool())
+                Game::getInstance().requestStates("masterserver");
             else
             {
                 if (!CommandLineParser::getValue("console").getBool())

Modified: code/trunk/src/orxonox/controllers/ArtificialController.cc
===================================================================
--- code/trunk/src/orxonox/controllers/ArtificialController.cc	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/orxonox/controllers/ArtificialController.cc	2010-12-22 18:24:24 UTC (rev 7801)
@@ -68,7 +68,7 @@
         RegisterObject(ArtificialController);
 
         this->target_ = 0;
-        this->formationFlight_ = true;
+        this->formationFlight_ = false;
         this->passive_ = false;
         this->maxFormationSize_ = STANDARD_MAX_FORMATION_SIZE;
         this->myMaster_ = 0;

Modified: code/trunk/src/orxonox/controllers/NewHumanController.cc
===================================================================
--- code/trunk/src/orxonox/controllers/NewHumanController.cc	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/orxonox/controllers/NewHumanController.cc	2010-12-22 18:24:24 UTC (rev 7801)
@@ -374,7 +374,7 @@
         for (itr = result.begin(); itr != result.end(); ++itr)
         {
 //             CCOUT(0) << "testing object as target" << endl;
-            if (itr->movable->isInScene() && itr->movable->getMovableType() == "Entity" /*&& itr->distance > 500*/)
+            if (itr->movable->isInScene() && itr->movable->getMovableType() == "Entity" && itr->distance > 200)
             {
                 // Try to cast the user pointer
                 WorldEntity* wePtr;

Modified: code/trunk/src/orxonox/gamestates/CMakeLists.txt
===================================================================
--- code/trunk/src/orxonox/gamestates/CMakeLists.txt	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/orxonox/gamestates/CMakeLists.txt	2010-12-22 18:24:24 UTC (rev 7801)
@@ -5,5 +5,6 @@
   GSMainMenu.cc
   GSRoot.cc
   GSServer.cc
+  GSMasterServer.cc
   GSStandalone.cc
 )

Copied: code/trunk/src/orxonox/gamestates/GSMasterServer.cc (from rev 7786, code/branches/presentation/src/orxonox/gamestates/GSMasterServer.cc)
===================================================================
--- code/trunk/src/orxonox/gamestates/GSMasterServer.cc	                        (rev 0)
+++ code/trunk/src/orxonox/gamestates/GSMasterServer.cc	2010-12-22 18:24:24 UTC (rev 7801)
@@ -0,0 +1,68 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Sandro 'smerkli' Merkli 
+ *   Co-authors:
+ *      Reto Grieder (original file for GSServer.cc)
+ *      Fabian 'x3n' Landau (original file for GSServer.cc)
+ *
+ */
+
+#include "GSMasterServer.h"
+
+#include "util/Debug.h"
+#include "core/Game.h"
+#include "core/GameMode.h"
+
+namespace orxonox
+{
+  DeclareGameState(GSMasterServer, "masterserver", false, false);
+
+  GSMasterServer::GSMasterServer(const GameStateInfo& info)
+    : GameState(info)
+  {
+
+  }
+
+  GSMasterServer::~GSMasterServer()
+  {
+  }
+
+  void GSMasterServer::activate()
+  {
+    /* TODO make this work for masterserver as well */
+    //GameMode::setIsServer(true);
+
+    this->mserver = new MasterServer();
+    COUT(0) << "Loading masterserver mode" << std::endl;
+
+    this->mserver->run();
+  }
+
+  void GSMasterServer::deactivate()
+  { /* nothing so far */ }
+
+  void GSMasterServer::update(const Clock& time)
+  { 
+    this->mserver->run();
+  }
+}

Copied: code/trunk/src/orxonox/gamestates/GSMasterServer.h (from rev 7786, code/branches/presentation/src/orxonox/gamestates/GSMasterServer.h)
===================================================================
--- code/trunk/src/orxonox/gamestates/GSMasterServer.h	                        (rev 0)
+++ code/trunk/src/orxonox/gamestates/GSMasterServer.h	2010-12-22 18:24:24 UTC (rev 7801)
@@ -0,0 +1,58 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Sandro 'smerkli' Merkli 
+ *   Co-authors:
+ *      Reto Grieder (Original GSServer.h file this was adapted from)
+ *      ...
+ *
+ */
+
+#ifndef _GSMasterServer_H__
+#define _GSMasterServer_H__
+
+#include "OrxonoxPrereqs.h"
+
+#include "core/GameState.h"
+#include "network/NetworkPrereqs.h"
+#include "network/MasterServer.h"
+
+namespace orxonox
+{
+  class _OrxonoxExport GSMasterServer : public GameState
+  {
+    public:
+      GSMasterServer(const GameStateInfo& info);
+      ~GSMasterServer();
+
+      void activate();
+      void deactivate();
+      void update(const Clock& time);
+
+    private:
+      MasterServer *mserver;
+
+
+  };
+}
+
+#endif /* _GSServer_H__ */

Modified: code/trunk/src/orxonox/gamestates/GSServer.cc
===================================================================
--- code/trunk/src/orxonox/gamestates/GSServer.cc	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/orxonox/gamestates/GSServer.cc	2010-12-22 18:24:24 UTC (rev 7801)
@@ -33,12 +33,13 @@
 #include "core/Game.h"
 #include "core/GameMode.h"
 #include "network/Server.h"
+#include "network/Connection.h"
 
 namespace orxonox
 {
     DeclareGameState(GSServer, "server", false, false);
 
-    SetCommandLineArgument(port, 55556).shortcut("p").information("Network communication port to be used 0-65535 (default: 55556)");
+    SetCommandLineArgument(port, NETWORK_PORT).shortcut("p").information("Network communication port to be used 0-65535 (default: 55556)");
 
     GSServer::GSServer(const GameStateInfo& info)
         : GameState(info)

Modified: code/trunk/src/orxonox/gametypes/Gametype.cc
===================================================================
--- code/trunk/src/orxonox/gametypes/Gametype.cc	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/orxonox/gametypes/Gametype.cc	2010-12-22 18:24:24 UTC (rev 7801)
@@ -78,6 +78,11 @@
         }
         else
             this->scoreboard_ = 0;
+
+        /* HACK HACK HACK */
+        this->dedicatedAddBots_ = createConsoleCommand( "dedicatedAddBots", createExecutor( createFunctor(&Gametype::addBots, this) ) );
+        this->dedicatedKillBots_ = createConsoleCommand( "dedicatedKillBots", createExecutor( createFunctor(&Gametype::killBots, this) ) );
+        /* HACK HACK HACK */
     }
 
     Gametype::~Gametype()
@@ -85,6 +90,10 @@
         if (this->isInitialized())
         {
             this->gtinfo_->destroy();
+            if( this->dedicatedAddBots_ )
+                delete this->dedicatedAddBots_;
+            if( this->dedicatedKillBots_ )
+                delete this->dedicatedKillBots_;
         }
     }
 

Modified: code/trunk/src/orxonox/gametypes/Gametype.h
===================================================================
--- code/trunk/src/orxonox/gametypes/Gametype.h	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/orxonox/gametypes/Gametype.h	2010-12-22 18:24:24 UTC (rev 7801)
@@ -183,6 +183,11 @@
 
             // Config Values
             std::string scoreboardTemplate_;
+
+            /* HACK HACK HACK */
+            ConsoleCommand* dedicatedAddBots_;
+            ConsoleCommand* dedicatedKillBots_;
+            /* HACK HACK HACK */
     };
 }
 

Modified: code/trunk/src/orxonox/infos/Bot.cc
===================================================================
--- code/trunk/src/orxonox/infos/Bot.cc	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/orxonox/infos/Bot.cc	2010-12-22 18:24:24 UTC (rev 7801)
@@ -85,7 +85,7 @@
             "Franz Sanchez",
             "Alec Trevelyan",
             "Elliot Carver",
-            "Elektra King"
+            "Elektra King",
             "Viktor Zokas",
             "Gustav Graves",
             "Le Chiffre",

Modified: code/trunk/src/orxonox/worldentities/pawns/SpaceShip.cc
===================================================================
--- code/trunk/src/orxonox/worldentities/pawns/SpaceShip.cc	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/orxonox/worldentities/pawns/SpaceShip.cc	2010-12-22 18:24:24 UTC (rev 7801)
@@ -56,6 +56,12 @@
         this->steering_ = Vector3::ZERO;
         this->engine_ = 0;
 
+        this->boostPower_ = 10.0f;
+        this->initialBoostPower_ = 10.0f;
+        this->boostRate_ = 5.0;
+        this->boostPowerRate_ = 1.0;
+        this->boostCooldownDuration_ = 5.0;
+        this->bBoostCooldown_ = false;
 
         this->bInvertYAxis_ = false;
 
@@ -85,6 +91,10 @@
         XMLPortParamVariable(SpaceShip, "primaryThrust",  primaryThrust_,  xmlelement, mode);
         XMLPortParamVariable(SpaceShip, "auxilaryThrust", auxilaryThrust_, xmlelement, mode);
         XMLPortParamVariable(SpaceShip, "rotationThrust", rotationThrust_, xmlelement, mode);
+        XMLPortParamVariable(SpaceShip, "boostPower", initialBoostPower_, xmlelement, mode);
+        XMLPortParamVariable(SpaceShip, "boostPowerRate", boostPowerRate_, xmlelement, mode);
+        XMLPortParamVariable(SpaceShip, "boostRate", boostRate_, xmlelement, mode);
+        XMLPortParamVariable(SpaceShip, "boostCooldownDuration", boostCooldownDuration_, xmlelement, mode);
     }
 
     void SpaceShip::registerVariables()
@@ -133,8 +143,28 @@
                 this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * this->localAngularAcceleration_);
                 this->localAngularAcceleration_.setValue(0, 0, 0);
             }
+            
+            if(!this->bBoostCooldown_ && this->boostPower_ < this->initialBoostPower_)
+            {
+                this->boostPower_ += this->boostPowerRate_*dt;
+            }
+            if(this->bBoost_)
+            {
+                this->boostPower_ -=this->boostRate_*dt;
+                if(this->boostPower_ <= 0.0f)
+                {
+                    this->bBoost_ = false;
+                    this->bBoostCooldown_ = true;
+                    this->timer_.setTimer(this->boostCooldownDuration_, false, createExecutor(createFunctor(&SpaceShip::boostCooledDown, this)));
+                }
+            }
         }
     }
+    
+    void SpaceShip::boostCooledDown(void)
+    {
+        this->bBoostCooldown_ = false;
+    }
 
     void SpaceShip::moveFrontBack(const Vector2& value)
     {
@@ -174,6 +204,20 @@
 
         Pawn::rotateRoll(value);
     }
+    
+    // TODO: something seems to call this function every tick, could probably handled a little more efficiently!
+    void SpaceShip::setBoost(bool bBoost)
+    {
+        if(bBoost == this->bBoost_)
+            return;
+    
+        if(bBoost)
+            this->boost();
+        else
+        {
+            this->bBoost_ = false;
+        }
+    }
 
     void SpaceShip::fire()
     {
@@ -181,7 +225,8 @@
 
     void SpaceShip::boost()
     {
-        this->bBoost_ = true;
+        if(!this->bBoostCooldown_)
+            this->bBoost_ = true;
     }
 
     void SpaceShip::loadEngineTemplate()

Modified: code/trunk/src/orxonox/worldentities/pawns/SpaceShip.h
===================================================================
--- code/trunk/src/orxonox/worldentities/pawns/SpaceShip.h	2010-12-22 12:38:02 UTC (rev 7800)
+++ code/trunk/src/orxonox/worldentities/pawns/SpaceShip.h	2010-12-22 18:24:24 UTC (rev 7801)
@@ -33,6 +33,7 @@
 
 #include <string>
 #include <LinearMath/btVector3.h>
+#include "tools/Timer.h"
 #include "util/Math.h"
 #include "Pawn.h"
 
@@ -68,8 +69,7 @@
             inline const Vector3& getSteeringDirection() const
                 { return this->steering_; }
 
-            inline void setBoost(bool bBoost)
-                { this->bBoost_ = bBoost; }
+            void setBoost(bool bBoost);
             inline bool getBoost() const
                 { return this->bBoost_; }
 
@@ -88,7 +88,13 @@
             bool bInvertYAxis_;
 
             bool bBoost_;
+            bool bBoostCooldown_;
             bool bPermanentBoost_;
+            float boostPower_;
+            float initialBoostPower_;
+            float boostRate_;
+            float boostPowerRate_;
+            float boostCooldownDuration_;
             Vector3 steering_;
             float primaryThrust_;
             float auxilaryThrust_;
@@ -101,9 +107,12 @@
             virtual bool isCollisionTypeLegal(WorldEntity::CollisionType type) const;
 
             void loadEngineTemplate();
+            
+            void boostCooledDown(void);
 
             std::string enginetemplate_;
             Engine* engine_;
+            Timer timer_;
     };
 }
 




More information about the Orxonox-commit mailing list