Index: /code/trunk/bin/CMakeLists.txt
===================================================================
--- /code/trunk/bin/CMakeLists.txt	(revision 7800)
+++ /code/trunk/bin/CMakeLists.txt	(revision 7801)
@@ -26,5 +26,5 @@
 
 # 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})
Index: /code/trunk/bin/masterserver.bat.in
===================================================================
--- /code/trunk/bin/masterserver.bat.in	(revision 7801)
+++ /code/trunk/bin/masterserver.bat.in	(revision 7801)
@@ -0,0 +1,4 @@
+title @PROJECT_NAME@
+path @RUNTIME_LIBRARY_DIRECTORY_WINDOWS@;%path%
+@CURRENT_RUNTIME_DIR_WINDOWS@\@ORXONOX_EXECUTABLE_NAME@ --masterserver --writingPathSuffix masterserver
+pause
Index: /code/trunk/bin/masterserver.in
===================================================================
--- /code/trunk/bin/masterserver.in	(revision 7801)
+++ /code/trunk/bin/masterserver.in	(revision 7801)
@@ -0,0 +1,4 @@
+#!/bin/sh
+# convenience script for starting orxonox on Linux
+
+exec @CURRENT_RUNTIME_DIR@/@ORXONOX_EXECUTABLE_NAME@ --masterserver --writingPathSuffix masterserver $@
Index: /code/trunk/data/gui/layouts/AudioMenu.layout
===================================================================
--- /code/trunk/data/gui/layouts/AudioMenu.layout	(revision 7800)
+++ /code/trunk/data/gui/layouts/AudioMenu.layout	(revision 7801)
@@ -113,5 +113,5 @@
                 <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" />
Index: /code/trunk/data/gui/layouts/CreditsMenu.layout
===================================================================
--- /code/trunk/data/gui/layouts/CreditsMenu.layout	(revision 7800)
+++ /code/trunk/data/gui/layouts/CreditsMenu.layout	(revision 7801)
@@ -32,5 +32,5 @@
                     <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}}" />
@@ -38,5 +38,6 @@
                         <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
@@ -45,13 +46,5 @@
 
 http://www.orxonox.net
-n
-n
-n
-n
-n
-n
-n
-n
-n                       </Property>
+                      </Property>
                     </Window>
                 </Window>
Index: /code/trunk/data/gui/layouts/GraphicsMenu.layout
===================================================================
--- /code/trunk/data/gui/layouts/GraphicsMenu.layout	(revision 7800)
+++ /code/trunk/data/gui/layouts/GraphicsMenu.layout	(revision 7801)
@@ -15,5 +15,5 @@
             <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" />
@@ -22,9 +22,22 @@
                 <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>
@@ -35,5 +48,5 @@
                 <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" />
@@ -53,5 +66,5 @@
                 <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>
@@ -61,10 +74,10 @@
 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>
Index: /code/trunk/data/gui/layouts/InGameMenu.layout
===================================================================
--- /code/trunk/data/gui/layouts/InGameMenu.layout	(revision 7800)
+++ /code/trunk/data/gui/layouts/InGameMenu.layout	(revision 7801)
@@ -10,5 +10,5 @@
             <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>
@@ -17,5 +17,5 @@
             <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>
@@ -24,5 +24,5 @@
             <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>
@@ -31,5 +31,5 @@
             <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>
Index: /code/trunk/data/gui/layouts/MultiplayerMenu.layout
===================================================================
--- /code/trunk/data/gui/layouts/MultiplayerMenu.layout	(revision 7800)
+++ /code/trunk/data/gui/layouts/MultiplayerMenu.layout	(revision 7801)
@@ -32,6 +32,4 @@
                 <Event Name="SelectStateChanged" Function="MultiplayerMenu.InternetButton_clicked"/>
             </Window>
-
-
         </Window>
          <Window Type="MenuWidgets/Button" Name="orxonox/MultiplayerBackButton" >
Index: /code/trunk/data/gui/schemes/OrxonoxHUDWidgets.scheme
===================================================================
--- /code/trunk/data/gui/schemes/OrxonoxHUDWidgets.scheme	(revision 7801)
+++ /code/trunk/data/gui/schemes/OrxonoxHUDWidgets.scheme	(revision 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>
Index: de/trunk/data/gui/schemes/OrxonoxLookHUDWidgets.scheme
===================================================================
--- /code/trunk/data/gui/schemes/OrxonoxLookHUDWidgets.scheme	(revision 7800)
+++ 	(revision )
@@ -1,42 +1,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>
Index: de/trunk/data/gui/schemes/OrxonoxLookMenuWidgets.scheme
===================================================================
--- /code/trunk/data/gui/schemes/OrxonoxLookMenuWidgets.scheme	(revision 7800)
+++ 	(revision )
@@ -1,42 +1,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>
Index: /code/trunk/data/gui/schemes/OrxonoxMenuWidgets.scheme
===================================================================
--- /code/trunk/data/gui/schemes/OrxonoxMenuWidgets.scheme	(revision 7801)
+++ /code/trunk/data/gui/schemes/OrxonoxMenuWidgets.scheme	(revision 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>
Index: /code/trunk/data/gui/scripts/ChatBox-inputonly.lua
===================================================================
--- /code/trunk/data/gui/scripts/ChatBox-inputonly.lua	(revision 7800)
+++ /code/trunk/data/gui/scripts/ChatBox-inputonly.lua	(revision 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
 
Index: /code/trunk/data/gui/scripts/ChatBox.lua
===================================================================
--- /code/trunk/data/gui/scripts/ChatBox.lua	(revision 7800)
+++ /code/trunk/data/gui/scripts/ChatBox.lua	(revision 7801)
@@ -1,5 +1,5 @@
 -- ChatBox.lua
 
-local P = createMenuSheet("ChatBox")
+local P = createMenuSheet("ChatBox", true, TriBool.True, TriBool.Dontcare, false)
 
 function P.ChatBoxCloseButton_clicked(e)
Index: /code/trunk/data/gui/scripts/GraphicsMenu.lua
===================================================================
--- /code/trunk/data/gui/scripts/GraphicsMenu.lua	(revision 7800)
+++ /code/trunk/data/gui/scripts/GraphicsMenu.lua	(revision 7801)
@@ -4,4 +4,5 @@
 
 P.buttonList = {}
+P.schemeList = {"TaharezGreen", "Orxonox"}
 
 function P.onShow()
@@ -97,4 +98,27 @@
     }
     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
 
Index: /code/trunk/data/gui/scripts/InitialiseGUI.lua
===================================================================
--- /code/trunk/data/gui/scripts/InitialiseGUI.lua	(revision 7800)
+++ /code/trunk/data/gui/scripts/InitialiseGUI.lua	(revision 7801)
@@ -5,7 +5,8 @@
 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")
@@ -16,12 +17,12 @@
 -- 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
Index: /code/trunk/data/gui/scripts/MultiplayerMenu.lua
===================================================================
--- /code/trunk/data/gui/scripts/MultiplayerMenu.lua	(revision 7800)
+++ /code/trunk/data/gui/scripts/MultiplayerMenu.lua	(revision 7801)
@@ -6,6 +6,6 @@
 
 --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()
@@ -33,17 +33,38 @@
 
 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
 
@@ -55,19 +76,13 @@
 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
 
@@ -77,32 +92,68 @@
 
 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
 
Index: /code/trunk/src/libraries/core/GUIManager.cc
===================================================================
--- /code/trunk/src/libraries/core/GUIManager.cc	(revision 7800)
+++ /code/trunk/src/libraries/core/GUIManager.cc	(revision 7801)
@@ -59,5 +59,7 @@
 #include "util/Exception.h"
 #include "util/OrxAssert.h"
+#include "ConfigValueIncludes.h"
 #include "Core.h"
+#include "CoreIncludes.h"
 #include "GraphicsManager.h"
 #include "LuaState.h"
@@ -100,4 +102,5 @@
 
     GUIManager* GUIManager::singletonPtr_s = 0;
+    /*static*/ const std::string GUIManager::defaultScheme_ = "TaharezGreen";
 
     SetConsoleCommand("showGUI", &GUIManager::showGUI).defaultValue(1, false).defaultValue(2, false);
@@ -118,4 +121,7 @@
         , camera_(NULL)
     {
+        RegisterRootObject(GUIManager);
+        this->setConfigValues();
+
         using namespace CEGUI;
 
@@ -175,4 +181,14 @@
     GUIManager::~GUIManager()
     {
+    }
+
+    void GUIManager::setConfigValues(void)
+    {
+        SetConfigValue(guiScheme_, GUIManager::defaultScheme_) .description("Changes the current GUI scheme.") .callback(this, &GUIManager::changedGUIScheme);
+    }
+
+    void GUIManager::changedGUIScheme(void)
+    {
+        
     }
 
Index: /code/trunk/src/libraries/core/GUIManager.h
===================================================================
--- /code/trunk/src/libraries/core/GUIManager.h	(revision 7800)
+++ /code/trunk/src/libraries/core/GUIManager.h	(revision 7801)
@@ -49,4 +49,5 @@
 #include "util/Singleton.h"
 #include "input/InputHandler.h"
+#include "OrxonoxClass.h"
 
 // Tolua includes (have to be relative to the current directory)
@@ -70,5 +71,5 @@
     */
     class _CoreExport GUIManager // tolua_export
-        : public Singleton<GUIManager>, public InputHandler
+        : public Singleton<GUIManager>, public InputHandler, public OrxonoxClass
     { // tolua_export
         friend class Singleton<GUIManager>;
@@ -76,4 +77,7 @@
         GUIManager(const std::pair<int, int>& mousePosition);
         ~GUIManager();
+
+        void setConfigValues(void);
+        void changedGUIScheme(void);
 
         void preUpdate(const Clock& time);
@@ -143,4 +147,8 @@
         static GUIManager*                   singletonPtr_s;    //!< Singleton reference to GUIManager
 
+        // The used CEGUI scheme.
+        static const std::string defaultScheme_;
+        std::string guiScheme_;
+
     }; // tolua_export
 } // tolua_export
Index: /code/trunk/src/libraries/network/CMakeLists.txt
===================================================================
--- /code/trunk/src/libraries/network/CMakeLists.txt	(revision 7800)
+++ /code/trunk/src/libraries/network/CMakeLists.txt	(revision 7801)
@@ -28,11 +28,17 @@
   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
@@ -48,5 +54,5 @@
   FunctionCall.h
   FunctionCallManager.h
-  GamestateClient.h
+  #GamestateClient.h
   GamestateHandler.h
   GamestateManager.h
@@ -54,8 +60,14 @@
   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
@@ -69,4 +81,5 @@
     Client.h
     LANDiscovery.h
+    WANDiscovery.h
   PCH_FILE
     NetworkPrecompiledHeaders.h
Index: /code/trunk/src/libraries/network/Client.cc
===================================================================
--- /code/trunk/src/libraries/network/Client.cc	(revision 7800)
+++ /code/trunk/src/libraries/network/Client.cc	(revision 7801)
@@ -64,5 +64,4 @@
   */
   Client::Client():
-      gamestate(0),
       isSynched_(false),
       gameStateFailure_(false),
@@ -85,8 +84,8 @@
   {
     Synchronisable::setClient(true);
-    this->gamestate = new GamestateClient();
     if( ClientConnection::establishConnection() )
     {
       Host::setActive(true);
+      GamestateManager::addPeer(NETWORK_PEER_ID_SERVER);
       return true;
     }
@@ -101,8 +100,6 @@
   bool Client::closeConnection()
   {
-    assert(this->gamestate);
-    delete this->gamestate;
-    this->gamestate = 0;
     Host::setActive(false);
+    GamestateManager::removePeer(NETWORK_PEER_ID_SERVER);
     return ClientConnection::closeConnection();
   }
@@ -114,9 +111,7 @@
   }
 
-  bool Client::queuePacket(ENetPacket *packet, int clientID)
-  {
-    bool b = ClientConnection::addPacket(packet);
-    assert(b);
-    return b;
+  void Client::queuePacket(ENetPacket *packet, int clientID, uint8_t channelID)
+  {
+    ClientConnection::addPacket(packet, channelID);
   }
 
@@ -140,5 +135,5 @@
   {
     packet::Chat *m = new packet::Chat(message, Host::getPlayerID());
-    return m->send();
+    return m->send(static_cast<Host*>(this));
   }
 
@@ -159,19 +154,26 @@
       {
         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();
@@ -179,6 +181,6 @@
         isSynched_=true;
     }
-    gamestate->cleanup();
-    Connection::sendPackets();
+//     GamestateManager::cleanup();;
+//     Connection::sendPackets();
 
     return;
@@ -200,4 +202,18 @@
     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));
+  }
+
 
 
Index: /code/trunk/src/libraries/network/Client.h
===================================================================
--- /code/trunk/src/libraries/network/Client.h	(revision 7800)
+++ /code/trunk/src/libraries/network/Client.h	(revision 7801)
@@ -45,9 +45,10 @@
 
 #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"
@@ -78,5 +79,6 @@
     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);
@@ -90,8 +92,9 @@
     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_;
Index: /code/trunk/src/libraries/network/ClientConnection.cc
===================================================================
--- /code/trunk/src/libraries/network/ClientConnection.cc	(revision 7800)
+++ /code/trunk/src/libraries/network/ClientConnection.cc	(revision 7801)
@@ -39,5 +39,4 @@
   const unsigned int NETWORK_CLIENT_CONNECTION_TIMEOUT = 3000; //millisecs
   const unsigned int NETWORK_CLIENT_MAX_CONNECTIONS = 1;
-  const unsigned int NETWORK_CLIENT_CHANNELS = 1;
 
 
@@ -71,5 +70,7 @@
     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 )
     {
@@ -78,4 +79,8 @@
       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)
@@ -86,5 +91,5 @@
         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 )
     {
@@ -99,4 +104,5 @@
       {
         this->established_=true;
+        Connection::startCommunicationThread();
         return true;
       }
@@ -112,4 +118,5 @@
       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++)
@@ -138,8 +145,8 @@
 
 
-  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 );
   }
 
@@ -153,4 +160,5 @@
     COUT(1) << "Received disconnect Packet from Server!" << endl;
         // server closed the connection
+    this->stopCommunicationThread();
     this->connectionClosed();
   }
Index: /code/trunk/src/libraries/network/ClientConnection.h
===================================================================
--- /code/trunk/src/libraries/network/ClientConnection.h	(revision 7800)
+++ /code/trunk/src/libraries/network/ClientConnection.h	(revision 7801)
@@ -44,12 +44,12 @@
     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:
Index: /code/trunk/src/libraries/network/ClientInformation.cc
===================================================================
--- /code/trunk/src/libraries/network/ClientInformation.cc	(revision 7800)
+++ /code/trunk/src/libraries/network/ClientInformation.cc	(revision 7801)
@@ -56,5 +56,4 @@
     preve=0;
     nexte=0;
-    partialGamestateID_=GAMESTATEID_INITIAL-1;
     synched_=false;
   }
@@ -133,11 +132,4 @@
   }
 
-  bool ClientInformation::setPartialGamestateID(int id){
-    if(!this)
-      return false;
-    partialGamestateID_=id;
-    return true;
-  }
-
   unsigned int ClientInformation::getID() {
     if(!this)
@@ -154,14 +146,4 @@
   }
 
-  int ClientInformation::getFailures(){
-    return failures_;
-  }
-  void ClientInformation::addFailure(){
-    failures_++;
-  }
-  void ClientInformation::resetFailures(){
-    failures_=0;
-  }
-
   uint32_t ClientInformation::getRTT(){
     return this->peer_->roundTripTime;
@@ -175,11 +157,4 @@
     if(this)
       return gamestateID_;
-    else
-      return static_cast<unsigned int>(-1);
-  }
-
-  unsigned int ClientInformation::getPartialGamestateID() {
-    if(this)
-      return partialGamestateID_;
     else
       return static_cast<unsigned int>(-1);
Index: /code/trunk/src/libraries/network/ClientInformation.h
===================================================================
--- /code/trunk/src/libraries/network/ClientInformation.h	(revision 7800)
+++ /code/trunk/src/libraries/network/ClientInformation.h	(revision 7801)
@@ -66,5 +66,4 @@
     bool setPeer(ENetPeer *peer);
     bool setGamestateID(int id);
-    bool setPartialGamestateID(int id);
     inline void setShipID(unsigned int id){ShipID_=id;}
 
@@ -73,10 +72,6 @@
     unsigned int getID();
     unsigned int getGamestateID();
-    unsigned int getPartialGamestateID();
     ENetPeer *getPeer();
 
-    int getFailures();
-    void addFailure();
-    void resetFailures();
     uint32_t getRTT();
     double getPacketLoss();
@@ -106,8 +101,6 @@
     unsigned int clientID_;
     unsigned int gamestateID_;
-    unsigned int partialGamestateID_;
     unsigned int ShipID_;   // this is the unique objectID
     bool synched_;
-    unsigned short failures_;
 
   };
Index: /code/trunk/src/libraries/network/Connection.cc
===================================================================
--- /code/trunk/src/libraries/network/Connection.cc	(revision 7800)
+++ /code/trunk/src/libraries/network/Connection.cc	(revision 7801)
@@ -30,55 +30,160 @@
 
 #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)
-  {
-//     assert(instance_==0);
-//     Connection::instance_=this;
+    host_(0), bCommunicationThreadRunning_(false)
+  {
     enet_initialize();
     atexit(enet_deinitialize);
-  }
-
-  Connection::~Connection(){
-//     Connection::instance_=0;
-  }
-
-  int Connection::service(ENetEvent* event) {
-    return enet_host_service( this->host_, event, NETWORK_WAIT_TIMEOUT );
-  }
-
-  void Connection::disconnectPeer(ENetPeer *peer) {
-    enet_peer_disconnect(peer, 0);
-  }
-
-  bool Connection::addPacket(ENetPacket *packet, ENetPeer *peer) {
-    if(enet_peer_send(peer, NETWORK_DEFAULT_CHANNEL, packet)!=0)
-      return false;
-    else
-      return true;
-  }
-
-  bool Connection::sendPackets() {
-    if ( /*!Connection::instance_ || */this->host_==NULL )
-      return false;
-    enet_host_flush(this->host_);
-    return true;
-  }
-
-  void Connection::processQueue() {
+    this->incomingEventsMutex_ = new boost::mutex;
+    this->outgoingEventsMutex_ = new boost::mutex;
+  }
+
+  Connection::~Connection()
+  {
+    delete this->incomingEventsMutex_;
+    delete this->outgoingEventsMutex_;
+  }
+
+  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_;
+  }
+
+
+//   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();
+  }
+
+  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();
+  }
+
+  
+  void Connection::communicationThread()
+  {
     ENetEvent event;
-
-    assert(this->host_);
-
-    while( enet_host_service( this->host_, &event, NETWORK_WAIT_TIMEOUT ) > 0 )
+    
+    while( bCommunicationThreadRunning_ )
     {
-      switch(event.type){
+      // 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()
+  {
+    ENetEvent event;
+
+    this->incomingEventsMutex_->lock();
+    uint32_t incomingEventsCount = this->incomingEvents_.size();
+    this->incomingEventsMutex_->unlock();
+    while( incomingEventsCount > 0 )
+    {
+      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:
@@ -89,16 +194,30 @@
           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_ );
+  }
+
 
 }
Index: /code/trunk/src/libraries/network/Connection.h
===================================================================
--- /code/trunk/src/libraries/network/Connection.h	(revision 7800)
+++ /code/trunk/src/libraries/network/Connection.h	(revision 7801)
@@ -43,19 +43,47 @@
 #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:
@@ -63,15 +91,27 @@
 //     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_;
Index: /code/trunk/src/libraries/network/FunctionCallManager.cc
===================================================================
--- /code/trunk/src/libraries/network/FunctionCallManager.cc	(revision 7800)
+++ /code/trunk/src/libraries/network/FunctionCallManager.cc	(revision 7801)
@@ -30,65 +30,66 @@
 #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);
 }
 
@@ -96,87 +97,88 @@
 // 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;
+    }
   }
 }
Index: /code/trunk/src/libraries/network/FunctionCallManager.h
===================================================================
--- /code/trunk/src/libraries/network/FunctionCallManager.h	(revision 7800)
+++ /code/trunk/src/libraries/network/FunctionCallManager.h	(revision 7801)
@@ -34,4 +34,5 @@
 #include <map>
 #include <vector>
+#include <utility>
 #include "util/UtilPrereqs.h"
 #include "FunctionCall.h"
@@ -45,25 +46,25 @@
 {
 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();
Index: /code/trunk/src/libraries/network/GamestateClient.cc
===================================================================
--- /code/trunk/src/libraries/network/GamestateClient.cc	(revision 7800)
+++ /code/trunk/src/libraries/network/GamestateClient.cc	(revision 7801)
@@ -39,17 +39,20 @@
 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 )
@@ -59,10 +62,13 @@
   }
 
-  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())
@@ -74,5 +80,6 @@
   }
 
-  bool GamestateClient::processGamestates(){
+  bool GamestateClient::processGamestates()
+  {
     if(tempGamestate_==NULL)
       return false;
@@ -85,5 +92,7 @@
     NetworkCallbackManager::callCallbacks();
 
-    if (!processed){
+    if (!processed)
+    {
+      assert(0);
       sendAck(0);
       return false;
@@ -92,6 +101,7 @@
     tempGamestate_=NULL;
     gamestateMap_[processed->getID()]=processed;
+    lastProcessedGamestateID_ = processed->getID();
     if(isDiffed)
-      last_diff_ = processed->getBaseID();
+      lastAckedGamestateID_ = processed->getBaseID();
     id = processed->getID();
     sendAck(id);
@@ -105,5 +115,6 @@
   * @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;
@@ -111,7 +122,9 @@
   }
 
-  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;
@@ -120,8 +133,10 @@
   }
 
-  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
@@ -133,8 +148,10 @@
   }
 
-  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 << '|';
     }
@@ -143,11 +160,14 @@
   }
 
-  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;
@@ -155,5 +175,6 @@
   }
 
-  packet::Gamestate *GamestateClient::processGamestate(packet::Gamestate *gs){
+  packet::Gamestate *GamestateClient::processGamestate(packet::Gamestate *gs)
+  {
     if(gs->isCompressed())
     {
Index: /code/trunk/src/libraries/network/GamestateClient.h
===================================================================
--- /code/trunk/src/libraries/network/GamestateClient.h	(revision 7800)
+++ /code/trunk/src/libraries/network/GamestateClient.h	(revision 7801)
@@ -57,6 +57,8 @@
     ~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();
@@ -69,6 +71,6 @@
     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
Index: /code/trunk/src/libraries/network/GamestateHandler.cc
===================================================================
--- /code/trunk/src/libraries/network/GamestateHandler.cc	(revision 7800)
+++ /code/trunk/src/libraries/network/GamestateHandler.cc	(revision 7801)
@@ -32,10 +32,8 @@
 namespace orxonox {
 
-GamestateHandler *GamestateHandler::instance_=0;
+// GamestateHandler *GamestateHandler::instance_=0;
 
 GamestateHandler::GamestateHandler()
 {
-  assert(instance_==0);
-  instance_=this;
 }
 
@@ -43,5 +41,4 @@
 GamestateHandler::~GamestateHandler()
 {
-  instance_=0;
 }
 
Index: /code/trunk/src/libraries/network/GamestateHandler.h
===================================================================
--- /code/trunk/src/libraries/network/GamestateHandler.h	(revision 7800)
+++ /code/trunk/src/libraries/network/GamestateHandler.h	(revision 7801)
@@ -32,4 +32,6 @@
 #include "NetworkPrereqs.h"
 
+#include <cassert>
+
 namespace orxonox {
 
@@ -37,10 +39,7 @@
     @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_;
 
 
@@ -50,6 +49,8 @@
 
   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;
 };
 
Index: /code/trunk/src/libraries/network/GamestateManager.cc
===================================================================
--- /code/trunk/src/libraries/network/GamestateManager.cc	(revision 7800)
+++ /code/trunk/src/libraries/network/GamestateManager.cc	(revision 7801)
@@ -43,22 +43,23 @@
 #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)
-  {
-    trafficControl_ = new TrafficControl();
+  currentGamestate_(0), id_(0)
+  {
+//     trafficControl_ = new TrafficControl();
 //     threadMutex_ = new boost::mutex();
 //     threadPool_ = new ThreadPool();
@@ -67,16 +68,16 @@
   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 )
-    {
-      for( it2 = it1->second.begin(); it2 != it1->second.end(); ++it2 )
-        delete it2->second;
-    }
-    this->trafficControl_->destroy();
+    std::map<uint32_t, peerInfo>::iterator peerIt;
+    std::map<uint32_t, packet::Gamestate*>::iterator gamestateIt;
+    for( peerIt = peerMap_.begin(); peerIt != peerMap_.end(); ++peerIt )
+    {
+      for( gamestateIt = peerIt->second.gamestates.begin(); gamestateIt != peerIt->second.gamestates.end(); ++gamestateIt )
+        delete gamestateIt->second;
+    }
+//     this->trafficControl_->destroy();
 //     delete this->threadMutex_;
 //     delete this->threadPool_;
@@ -88,5 +89,6 @@
   }
 
-  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);
@@ -99,5 +101,6 @@
   }
 
-  bool GamestateManager::processGamestates(){
+  bool GamestateManager::processGamestates()
+  {
     if( this->gamestateQueue.empty() )
         return true;
@@ -107,4 +110,5 @@
       bool b = processGamestate(it->second);
       assert(b);
+      sendAck( it->second->getID(), it->second->getPeerID() );
       delete it->second;
     }
@@ -115,71 +119,92 @@
     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()
-  {
-    ClientInformation *temp = ClientInformation::getBegin();
-    std::queue<packet::Gamestate*> clientGamestates;
-    while(temp != NULL){
-      if( !(temp->getSynched()) ){
+  std::vector<packet::Gamestate*> GamestateManager::getGamestates()
+  {
+    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
-
-      unsigned int gID = temp->getGamestateID();
-      if(!reference)
-        return;
-
-      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;
-        }
-      }
-
-      clientGamestates.push(0);
-      finishGamestate( cid, clientGamestates.back(), client, reference );
+      int peerID = peerIt->first; //get client id
+
+      unsigned int lastAckedGamestateID = peerIt->second.lastAckedGamestateID;
+
+      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;
+      }
+
+      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();
-    }
-  }
-
-
-  void GamestateManager::finishGamestate( unsigned int clientID, packet::Gamestate*& destgamestate, packet::Gamestate* base, packet::Gamestate* gamestate ) {
+    return peerGamestates;
+  }
+
+
+  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?
@@ -194,8 +219,8 @@
 //     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)
@@ -216,8 +241,8 @@
 
 
-    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())
@@ -225,50 +250,101 @@
 //     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++);
-    }
-    temp->setGamestateID(gamestateID);
-    TrafficControl::processAck(clientID, gamestateID);
+    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;
+    }
+    
+//     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;
   }
-
-  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){
+  
+  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::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));
+  }
+
+
+//   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())
     {
@@ -277,5 +353,16 @@
     }
     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;
   }
 
Index: /code/trunk/src/libraries/network/GamestateManager.h
===================================================================
--- /code/trunk/src/libraries/network/GamestateManager.h	(revision 7800)
+++ /code/trunk/src/libraries/network/GamestateManager.h	(revision 7801)
@@ -46,4 +46,6 @@
 #include "GamestateHandler.h"
 #include "core/CorePrereqs.h"
+#include "packet/Gamestate.h"
+#include <boost/concept_check.hpp>
 
 namespace orxonox
@@ -66,27 +68,49 @@
   * @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_;
Index: /code/trunk/src/libraries/network/Host.cc
===================================================================
--- /code/trunk/src/libraries/network/Host.cc	(revision 7800)
+++ /code/trunk/src/libraries/network/Host.cc	(revision 7801)
@@ -45,5 +45,5 @@
   // 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;
 
@@ -76,16 +76,13 @@
   * @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;
   }
 
Index: /code/trunk/src/libraries/network/Host.h
===================================================================
--- /code/trunk/src/libraries/network/Host.h	(revision 7800)
+++ /code/trunk/src/libraries/network/Host.h	(revision 7801)
@@ -31,4 +31,5 @@
 
 #include "NetworkPrereqs.h"
+#include "GamestateManager.h"
 #include "core/CorePrereqs.h"
 
@@ -49,10 +50,11 @@
 *       @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;
@@ -71,11 +73,9 @@
 //     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);
@@ -86,5 +86,4 @@
   private:
     static uint32_t clientID_s;
-    static uint32_t shipID_s;
     static std::vector<Host*> instances_s;
     bool bIsActive_;
Index: /code/trunk/src/libraries/network/LANDiscoverable.cc
===================================================================
--- /code/trunk/src/libraries/network/LANDiscoverable.cc	(revision 7800)
+++ /code/trunk/src/libraries/network/LANDiscoverable.cc	(revision 7801)
@@ -45,5 +45,5 @@
     this->host_ = 0;
     this->bActive_ = false;
-    this->setActivity(true);
+//     this->setActivity(true);
   }
 
Index: /code/trunk/src/libraries/network/MasterServer.cc
===================================================================
--- /code/trunk/src/libraries/network/MasterServer.cc	(revision 7801)
+++ /code/trunk/src/libraries/network/MasterServer.cc	(revision 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 */
+}
Index: /code/trunk/src/libraries/network/MasterServer.h
===================================================================
--- /code/trunk/src/libraries/network/MasterServer.h	(revision 7801)
+++ /code/trunk/src/libraries/network/MasterServer.h	(revision 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__ */
Index: /code/trunk/src/libraries/network/MasterServerComm.cc
===================================================================
--- /code/trunk/src/libraries/network/MasterServerComm.cc	(revision 7801)
+++ /code/trunk/src/libraries/network/MasterServerComm.cc	(revision 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;
+  }
+
+}
Index: /code/trunk/src/libraries/network/MasterServerComm.h
===================================================================
--- /code/trunk/src/libraries/network/MasterServerComm.h	(revision 7801)
+++ /code/trunk/src/libraries/network/MasterServerComm.h	(revision 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__ */
Index: /code/trunk/src/libraries/network/MasterServerProtocol.h
===================================================================
--- /code/trunk/src/libraries/network/MasterServerProtocol.h	(revision 7801)
+++ /code/trunk/src/libraries/network/MasterServerProtocol.h	(revision 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__ */
Index: /code/trunk/src/libraries/network/NetworkPrereqs.h
===================================================================
--- /code/trunk/src/libraries/network/NetworkPrereqs.h	(revision 7800)
+++ /code/trunk/src/libraries/network/NetworkPrereqs.h	(revision 7801)
@@ -64,9 +64,13 @@
 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;
 }
 
@@ -83,7 +87,7 @@
       enum Value
       {
-        Reliable   = 1,
-        Unsequence = 2,
-        NoAllocate = 4
+        Reliable    = 1,
+        Unsequenced = 2,
+        NoAllocate  = 4
       };
     }
@@ -97,13 +101,14 @@
 // 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
@@ -161,3 +166,9 @@
 }
 
+namespace boost
+{
+  class mutex;
+  class thread;
+}
+
 #endif /* _NetworkPrereqs_H__ */
Index: /code/trunk/src/libraries/network/PeerList.cc
===================================================================
--- /code/trunk/src/libraries/network/PeerList.cc	(revision 7801)
+++ /code/trunk/src/libraries/network/PeerList.cc	(revision 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;
+  }
+
+}
+
Index: /code/trunk/src/libraries/network/PeerList.h
===================================================================
--- /code/trunk/src/libraries/network/PeerList.h	(revision 7801)
+++ /code/trunk/src/libraries/network/PeerList.h	(revision 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_ */
Index: /code/trunk/src/libraries/network/Server.cc
===================================================================
--- /code/trunk/src/libraries/network/Server.cc	(revision 7800)
+++ /code/trunk/src/libraries/network/Server.cc	(revision 7801)
@@ -60,4 +60,5 @@
 #include "FunctionCallManager.h"
 #include "GamestateManager.h"
+#include "WANDiscovery.h"
 
 namespace orxonox
@@ -99,4 +100,12 @@
   }
 
+
+  /** 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
@@ -107,5 +116,16 @@
     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;
   }
@@ -120,4 +140,10 @@
     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;
@@ -130,6 +156,6 @@
     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,4 +165,28 @@
   }
 
+
+  /* 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 );
+  }
 
   /**
@@ -149,6 +199,11 @@
     // 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() )
@@ -156,7 +211,8 @@
       // 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
@@ -167,11 +223,11 @@
         updateGamestate();
       }
-      sendPackets(); // flush the enet queue
-    }
-  }
-
-  bool Server::queuePacket(ENetPacket *packet, int clientID)
-  {
-    return ServerConnection::addPacket(packet, clientID);
+//       sendPackets(); // flush the enet queue
+    }
+  }
+
+  void Server::queuePacket(ENetPacket *packet, int clientID, uint8_t channelID)
+  {
+    ServerConnection::addPacket(packet, clientID, channelID);
   }
 
@@ -209,57 +265,27 @@
       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
-  */
-  bool Server::sendGameState()
-  {
-//     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();
+  /**
+  * sends the current gamestate to all peers
+  */
+  bool Server::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()
@@ -286,7 +312,7 @@
       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
@@ -312,4 +338,5 @@
     // inform all the listeners
     ClientConnectionListener::broadcastClientConnected(newid);
+    GamestateManager::addPeer(newid);
 
     ++newid;
@@ -327,4 +354,5 @@
     else
     {
+      GamestateManager::removePeer(client->getID());
       //ServerConnection::disconnectClient( client );
       //ClientConnectionListener::broadcastClientDisconnected( client->getID() ); //this is done in ClientInformation now
@@ -332,4 +360,18 @@
     }
   }
+  
+  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)
@@ -341,5 +383,5 @@
       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
@@ -348,22 +390,25 @@
     // 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();
-    assert(b);
-    b = g->send();
+//     b = g->compressData();
+//     assert(b);
+    b = g->send( static_cast<Host*>(this) );
     assert(b);
     return true;
@@ -373,5 +418,5 @@
   {
     ServerConnection::disconnectClient( client );
-    GamestateManager::removeClient(client);
+    GamestateManager::removePeer(client->getID());
     // inform all the listeners
     // ClientConnectionListener::broadcastClientDisconnected(client->getID()); // this is done in ClientInformation now
@@ -395,6 +440,6 @@
     {
       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();
@@ -411,6 +456,6 @@
     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++;
     }
Index: /code/trunk/src/libraries/network/Server.h
===================================================================
--- /code/trunk/src/libraries/network/Server.h	(revision 7800)
+++ /code/trunk/src/libraries/network/Server.h	(revision 7801)
@@ -32,10 +32,16 @@
 #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
@@ -46,5 +52,6 @@
   * 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();
@@ -53,8 +60,14 @@
     ~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);
@@ -65,14 +78,13 @@
   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);
@@ -82,4 +94,5 @@
 
     float timeSinceLastUpdate_;
+    std::deque<packet::Packet*> packetQueue_;
   };
 
Index: /code/trunk/src/libraries/network/ServerConnection.cc
===================================================================
--- /code/trunk/src/libraries/network/ServerConnection.cc	(revision 7800)
+++ /code/trunk/src/libraries/network/ServerConnection.cc	(revision 7801)
@@ -49,5 +49,6 @@
   }
 
-  ServerConnection::~ServerConnection(){
+  ServerConnection::~ServerConnection()
+  {
     if ( this->bListening_ )
       closeListener();
@@ -55,5 +56,6 @@
   }
 
-  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;
@@ -64,6 +66,9 @@
   }
 
-  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 )
     {
@@ -71,4 +76,7 @@
         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)
@@ -78,19 +86,25 @@
     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
@@ -99,15 +113,7 @@
       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;
   }
 
@@ -117,5 +123,6 @@
   }
 
-  void ServerConnection::disconnectClient(int clientID){
+  void ServerConnection::disconnectClient(int clientID)
+  {
     ClientInformation *client = ClientInformation::findClient(clientID);
     if(client)
@@ -123,28 +130,11 @@
   }
 
-  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;
@@ -152,13 +142,16 @@
 
 
-  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();
   }
Index: /code/trunk/src/libraries/network/ServerConnection.h
===================================================================
--- /code/trunk/src/libraries/network/ServerConnection.h	(revision 7800)
+++ /code/trunk/src/libraries/network/ServerConnection.h	(revision 7801)
@@ -56,6 +56,5 @@
     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);
Index: /code/trunk/src/libraries/network/ServerList.cc
===================================================================
--- /code/trunk/src/libraries/network/ServerList.cc	(revision 7801)
+++ /code/trunk/src/libraries/network/ServerList.cc	(revision 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 ); 
+  }
+
+}
Index: /code/trunk/src/libraries/network/ServerList.h
===================================================================
--- /code/trunk/src/libraries/network/ServerList.h	(revision 7801)
+++ /code/trunk/src/libraries/network/ServerList.h	(revision 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_*/
Index: /code/trunk/src/libraries/network/WANDiscoverable.cc
===================================================================
--- /code/trunk/src/libraries/network/WANDiscoverable.cc	(revision 7801)
+++ /code/trunk/src/libraries/network/WANDiscoverable.cc	(revision 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
Index: /code/trunk/src/libraries/network/WANDiscoverable.h
===================================================================
--- /code/trunk/src/libraries/network/WANDiscoverable.h	(revision 7801)
+++ /code/trunk/src/libraries/network/WANDiscoverable.h	(revision 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__
Index: /code/trunk/src/libraries/network/WANDiscovery.cc
===================================================================
--- /code/trunk/src/libraries/network/WANDiscovery.cc	(revision 7801)
+++ /code/trunk/src/libraries/network/WANDiscovery.cc	(revision 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
Index: /code/trunk/src/libraries/network/WANDiscovery.h
===================================================================
--- /code/trunk/src/libraries/network/WANDiscovery.h	(revision 7801)
+++ /code/trunk/src/libraries/network/WANDiscovery.h	(revision 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__
Index: /code/trunk/src/libraries/network/packet/Acknowledgement.cc
===================================================================
--- /code/trunk/src/libraries/network/packet/Acknowledgement.cc	(revision 7800)
+++ /code/trunk/src/libraries/network/packet/Acknowledgement.cc	(revision 7801)
@@ -31,4 +31,5 @@
 #include "util/Debug.h"
 #include "network/GamestateHandler.h"
+#include "network/Host.h"
 
 namespace orxonox {
@@ -39,5 +40,5 @@
 #define _ACKID              _PACKETID + sizeof(packet::Type::Value)
 
-Acknowledgement::Acknowledgement( unsigned int id, unsigned int clientID )
+Acknowledgement::Acknowledgement( unsigned int id, unsigned int peerID )
  : Packet()
 {
@@ -46,9 +47,9 @@
   *(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)
 {
 }
@@ -62,7 +63,7 @@
 }
 
-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;
Index: /code/trunk/src/libraries/network/packet/Acknowledgement.h
===================================================================
--- /code/trunk/src/libraries/network/packet/Acknowledgement.h	(revision 7800)
+++ /code/trunk/src/libraries/network/packet/Acknowledgement.h	(revision 7801)
@@ -42,10 +42,10 @@
 {
 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();
Index: /code/trunk/src/libraries/network/packet/Chat.cc
===================================================================
--- /code/trunk/src/libraries/network/packet/Chat.cc	(revision 7800)
+++ /code/trunk/src/libraries/network/packet/Chat.cc	(revision 7801)
@@ -80,6 +80,6 @@
 }
 
-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;
Index: /code/trunk/src/libraries/network/packet/Chat.h
===================================================================
--- /code/trunk/src/libraries/network/packet/Chat.h	(revision 7800)
+++ /code/trunk/src/libraries/network/packet/Chat.h	(revision 7801)
@@ -52,5 +52,5 @@
 
   /* 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) */
Index: /code/trunk/src/libraries/network/packet/ClassID.cc
===================================================================
--- /code/trunk/src/libraries/network/packet/ClassID.cc	(revision 7800)
+++ /code/trunk/src/libraries/network/packet/ClassID.cc	(revision 7801)
@@ -120,5 +120,5 @@
 
 
-bool ClassID::process(){
+bool ClassID::process(orxonox::Host* host){
   int nrOfClasses;
   uint8_t *temp = data_+sizeof(uint32_t); //skip the packetid
Index: /code/trunk/src/libraries/network/packet/ClassID.h
===================================================================
--- /code/trunk/src/libraries/network/packet/ClassID.h	(revision 7800)
+++ /code/trunk/src/libraries/network/packet/ClassID.h	(revision 7801)
@@ -48,5 +48,5 @@
 
   uint32_t getSize() const;
-  bool process();
+  virtual bool process(orxonox::Host* host);
 
 private:
Index: /code/trunk/src/libraries/network/packet/DeleteObjects.cc
===================================================================
--- /code/trunk/src/libraries/network/packet/DeleteObjects.cc	(revision 7800)
+++ /code/trunk/src/libraries/network/packet/DeleteObjects.cc	(revision 7801)
@@ -57,5 +57,6 @@
 }
 
-bool DeleteObjects::fetchIDs(){
+bool DeleteObjects::fetchIDs()
+{
   unsigned int number = Synchronisable::getNumberOfDeletedObject();
   if(number==0)
@@ -79,11 +80,14 @@
 }
 
-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)) );
Index: /code/trunk/src/libraries/network/packet/DeleteObjects.h
===================================================================
--- /code/trunk/src/libraries/network/packet/DeleteObjects.h	(revision 7800)
+++ /code/trunk/src/libraries/network/packet/DeleteObjects.h	(revision 7801)
@@ -32,6 +32,8 @@
 #include "Packet.h"
 
-namespace orxonox {
-namespace packet {
+namespace orxonox
+{
+namespace packet
+{
 /**
     @author
@@ -47,5 +49,5 @@
 
   inline unsigned int getSize() const;
-  bool process();
+  virtual bool process(orxonox::Host* host);
 
 private:
Index: /code/trunk/src/libraries/network/packet/FunctionCalls.cc
===================================================================
--- /code/trunk/src/libraries/network/packet/FunctionCalls.cc	(revision 7800)
+++ /code/trunk/src/libraries/network/packet/FunctionCalls.cc	(revision 7801)
@@ -32,4 +32,5 @@
 #include "network/FunctionCall.h"
 #include "network/FunctionCallManager.h"
+#include "network/GamestateHandler.h"
 
 namespace orxonox {
@@ -40,13 +41,13 @@
 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)
 {
 }
@@ -57,9 +58,12 @@
 
 
-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++ )
@@ -68,5 +72,7 @@
     fctCall.loadData(temp);
     if( !fctCall.execute() )
-      FunctionCallManager::bufferIncomingFunctionCall( fctCall );
+    {
+      FunctionCallManager::bufferIncomingFunctionCall( fctCall, minGamestateID_, this->getPeerID() );
+    }
   }
   
@@ -75,5 +81,6 @@
 }
 
-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());
   
@@ -83,5 +90,6 @@
 }
 
-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());
   
@@ -91,11 +99,13 @@
 }
 
-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() )
@@ -107,5 +117,5 @@
   assert( temp==data_+currentSize_ );
   
-  Packet::send();
+  Packet::send(host);
   return true;
 }
Index: /code/trunk/src/libraries/network/packet/FunctionCalls.h
===================================================================
--- /code/trunk/src/libraries/network/packet/FunctionCalls.h	(revision 7800)
+++ /code/trunk/src/libraries/network/packet/FunctionCalls.h	(revision 7801)
@@ -54,12 +54,13 @@
   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_;
 };
Index: /code/trunk/src/libraries/network/packet/FunctionIDs.cc
===================================================================
--- /code/trunk/src/libraries/network/packet/FunctionIDs.cc	(revision 7800)
+++ /code/trunk/src/libraries/network/packet/FunctionIDs.cc	(revision 7801)
@@ -46,5 +46,6 @@
 
 
-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
@@ -55,5 +56,6 @@
   //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();
@@ -76,5 +78,6 @@
   // now save all classids and classnames
   std::pair<uint32_t, std::string> tempPair;
-  while( !tempQueue.empty() ){
+  while( !tempQueue.empty() )
+  {
     tempPair = tempQueue.front();
     tempQueue.pop();
@@ -98,5 +101,6 @@
 }
 
-uint32_t FunctionIDs::getSize() const{
+uint32_t FunctionIDs::getSize() const
+{
   assert(this->data_);
   uint8_t *temp = data_+sizeof(uint32_t); // packet identification
@@ -114,5 +118,6 @@
 
 
-bool FunctionIDs::process(){
+bool FunctionIDs::process(orxonox::Host* host)
+{
   int nrOfFunctions;
   uint8_t *temp = data_+sizeof(uint32_t); //skip the packetid
@@ -127,5 +132,6 @@
   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));
Index: /code/trunk/src/libraries/network/packet/FunctionIDs.h
===================================================================
--- /code/trunk/src/libraries/network/packet/FunctionIDs.h	(revision 7800)
+++ /code/trunk/src/libraries/network/packet/FunctionIDs.h	(revision 7801)
@@ -47,6 +47,6 @@
   ~FunctionIDs();
 
-  uint32_t getSize() const;
-  bool process();
+  virtual uint32_t getSize() const;
+  virtual bool process(orxonox::Host* host);
 
 private:
Index: /code/trunk/src/libraries/network/packet/Gamestate.cc
===================================================================
--- /code/trunk/src/libraries/network/packet/Gamestate.cc	(revision 7800)
+++ /code/trunk/src/libraries/network/packet/Gamestate.cc	(revision 7801)
@@ -36,4 +36,5 @@
 #include "network/synchronisable/Synchronisable.h"
 #include "network/GamestateHandler.h"
+#include "network/Host.h"
 
 namespace orxonox {
@@ -43,5 +44,6 @@
 #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)
@@ -65,5 +67,5 @@
 
 Gamestate::Gamestate():
-  header_(0)
+  header_()
 {
   flags_ = flags_ | PACKET_FLAG_GAMESTATE;
@@ -72,24 +74,22 @@
 
 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_;
 }
@@ -98,6 +98,4 @@
 Gamestate::~Gamestate()
 {
-  if( header_ )
-    delete header_;
 }
 
@@ -105,5 +103,4 @@
 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);
@@ -120,7 +117,6 @@
   }
 
-  // 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
@@ -142,5 +138,5 @@
       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;
@@ -161,14 +157,14 @@
 
   //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;
 }
@@ -177,12 +173,12 @@
 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);
@@ -197,4 +193,5 @@
       else
       {
+//         COUT(4) << "not creating object of classid " << objectheader.getClassID() << endl;
         mem += objectheader.getDataSize() + ( objectheader.isDiffed() ? SynchronisableHeaderLight::getSize() : SynchronisableHeader::getSize() );
       }
@@ -202,8 +199,11 @@
     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
@@ -249,9 +249,9 @@
 {
   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();
   }
 }
@@ -271,7 +271,7 @@
 
 
-bool Gamestate::process()
-{
-  return GamestateHandler::addGamestate(this, getClientID());
+bool Gamestate::process(orxonox::Host* host)
+{
+  return host->addGamestate(this, getPeerID());
 }
 
@@ -280,6 +280,6 @@
 {
   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;
@@ -289,5 +289,5 @@
   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 )
   {
@@ -299,6 +299,7 @@
 
   //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
@@ -306,7 +307,7 @@
   //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;
 }
@@ -316,8 +317,8 @@
 {
   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;
@@ -338,6 +339,7 @@
 
   //copy over the header
-  GamestateHeader *temp = header_;
-  header_ = new GamestateHeader( data_, header_ );
+  GamestateHeader* temp = new GamestateHeader( data_ );
+  header_.setData(ndata);
+  header_ = *temp;
   delete temp;
 
@@ -357,219 +359,236 @@
   //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();
-
-  assert( origLength && baseLength );
-
-  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);
-
-  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 )
+  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();
+
+  // 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);
+
+  std::vector<uint32_t>::iterator sizesIt = this->sizes_.begin();
+
+  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 )
-    {
-      SynchronisableHeader htemp(temp);
-      assert( htemp.getDataSize()!=0 );
-      if ( htemp.getObjectID() == objectID )
-      {
-        assert( h.getClassID() == htemp.getClassID() );
-        goto DODIFF;
-      }
-//       {
-//         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(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 baseHeader(baseDataPtr);
+      assert(Synchronisable::getSynchronisable(baseHeader.getObjectID()));
+      assert(ClassByID(baseHeader.getClassID()));
+      assert(baseHeader.getDataSize() < 500);
+      if( SynchronisableHeader(baseDataPtr).getDataSize()==origHeader.getDataSize() )
+      {
+//         COUT(4) << "diffing object in order: " << Synchronisable::getSynchronisable(origHeader.getObjectID())->getIdentifier()->getName() << endl;
+        diffObject(destDataPtr, origDataPtr, baseDataPtr, origHeader, sizesIt);
+        diffedObject = true;
+      }
+      else
+      {
+//         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);
+      }
         
     }
-    // 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 )
-      {
-        assert( h.getClassID() == htemp.getClassID() );
-        goto DODIFF;
-      }
-//       {
-//         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:
-    {
-//       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 )
-      {
-//         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
+    {
+      assert( baseDataPtr == baseDataEnd );
+      baseDataPtr = GAMESTATE_START(base->data_);
+      if( findObject(baseDataPtr, oldBaseDataPtr, origHeader) )
+      {
+        SynchronisableHeader baseHeader(baseDataPtr);
+        assert(Synchronisable::getSynchronisable(baseHeader.getObjectID()));
+        assert(ClassByID(baseHeader.getClassID()));
+        assert(baseHeader.getDataSize() < 500);
+        if( SynchronisableHeader(baseDataPtr).getDataSize()==origHeader.getDataSize() )
+        {
+//           COUT(4) << "diffing object out of order: " << Synchronisable::getSynchronisable(origHeader.getObjectID())->getIdentifier()->getName() << endl;
+          diffObject(destDataPtr, origDataPtr, baseDataPtr, origHeader, sizesIt);
+          diffedObject = true;
+        }
+        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);
+        }
       }
       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() )
-        {
-          // 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;
-        }
-        
-        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;
-      }
-
-      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 )
-      {
-//         COUT(4) << " " << *sizes;
-        ++sizes;
-      }
-//       COUT(4) << endl;
-      assert(sizes != this->sizes_.end() || origOffset>=origLength);
-      continue;
-    }
-  }
-
-
-  Gamestate *g = new Gamestate(nData, getClientID());
-  assert(g->header_);
-  *(g->header_) = *header_;
-  g->header_->setBaseID( base->getID() );
-  g->header_->setDataSize(dest - nData - GamestateHeader::getSize());
+//         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);
+      }
+    }
+  }
+  assert(sizesIt==this->sizes_.end());
+
+
+  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_;
@@ -579,13 +598,13 @@
 
 
-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)
@@ -595,8 +614,8 @@
   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;
@@ -606,6 +625,6 @@
   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_;
@@ -619,10 +638,10 @@
 {
   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)
@@ -632,10 +651,10 @@
   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_;
@@ -670,13 +689,13 @@
   }
   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);
@@ -694,5 +713,5 @@
 
   //call TrafficControl
-  TrafficControl::getInstance()->processObjectList( clientID, header_->getID(), dataVector_ );
+  TrafficControl::getInstance()->processObjectList( clientID, header_.getID(), dataVector_ );
 
   //copy in the zeros
@@ -725,5 +744,5 @@
 #ifndef NDEBUG
   uint32_t origsize = destsize;
-  while ( origsize < header_->getDataSize() )
+  while ( origsize < header_.getDataSize() )
   {
     SynchronisableHeader oldobjectheader(origdata);
@@ -732,13 +751,13 @@
     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;
Index: /code/trunk/src/libraries/network/packet/Gamestate.h
===================================================================
--- /code/trunk/src/libraries/network/packet/Gamestate.h	(revision 7800)
+++ /code/trunk/src/libraries/network/packet/Gamestate.h	(revision 7801)
@@ -42,30 +42,40 @@
 #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
@@ -75,22 +85,22 @@
 
     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_;
 
 };
@@ -99,5 +109,6 @@
     @author Oliver Scheuss
 */
-class _NetworkExport Gamestate: public Packet{
+class _NetworkExport Gamestate: public Packet
+{
   public:
     Gamestate();
@@ -110,13 +121,13 @@
     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();
@@ -125,12 +136,14 @@
     // 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_;
Index: /code/trunk/src/libraries/network/packet/Packet.cc
===================================================================
--- /code/trunk/src/libraries/network/packet/Packet.cc	(revision 7800)
+++ /code/trunk/src/libraries/network/packet/Packet.cc	(revision 7801)
@@ -35,4 +35,5 @@
 #include <enet/enet.h>
 #include <boost/static_assert.hpp>
+#include <boost/thread/mutex.hpp>
 
 #include "util/Debug.h"
@@ -53,7 +54,7 @@
 
 // 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
@@ -61,4 +62,5 @@
 
 std::map<size_t, Packet *> Packet::packetMap_;
+boost::mutex Packet::packetMapMutex_;
 
 Packet::Packet()
@@ -66,5 +68,5 @@
   flags_ = PACKET_FLAG_DEFAULT;
   packetDirection_ = Direction::Outgoing;
-  clientID_=0;
+  peerID_=0;
   data_=0;
   enetPacket_=0;
@@ -72,9 +74,9 @@
 }
 
-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;
@@ -87,5 +89,5 @@
   flags_=p.flags_;
   packetDirection_ = p.packetDirection_;
-  clientID_ = p.clientID_;
+  peerID_ = p.peerID_;
   if(p.data_){
     data_ = new uint8_t[p.getSize()];
@@ -123,5 +125,5 @@
 }
 
-bool Packet::send(){
+bool Packet::send(orxonox::Host* host){
   if(packetDirection_ != Direction::Outgoing && packetDirection_ != Direction::Bidirectional ){
     assert(0);
@@ -142,5 +144,7 @@
       // 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();
     }
   }
@@ -164,6 +168,8 @@
 //  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;
 }
@@ -172,44 +178,46 @@
   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;
   }
@@ -229,4 +237,5 @@
 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());
@@ -235,5 +244,6 @@
   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;
 }
 
Index: /code/trunk/src/libraries/network/packet/Packet.h
===================================================================
--- /code/trunk/src/libraries/network/packet/Packet.h	(revision 7800)
+++ /code/trunk/src/libraries/network/packet/Packet.h	(revision 7801)
@@ -68,16 +68,20 @@
     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
@@ -85,5 +89,6 @@
 
     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
@@ -96,4 +101,5 @@
   private:
     static std::map<size_t, Packet *> packetMap_;
+    static boost::mutex               packetMapMutex_;
     ENetPacket *enetPacket_;
 };
Index: /code/trunk/src/libraries/network/packet/ServerInformation.cc
===================================================================
--- /code/trunk/src/libraries/network/packet/ServerInformation.cc	(revision 7800)
+++ /code/trunk/src/libraries/network/packet/ServerInformation.cc	(revision 7801)
@@ -21,5 +21,5 @@
  *
  *   Author:
- *      Fabian 'x3n' Landau
+ *      Oliver Scheuss
  *   Co-authors:
  *      ...
@@ -58,5 +58,9 @@
       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);
Index: /code/trunk/src/libraries/network/packet/ServerInformation.h
===================================================================
--- /code/trunk/src/libraries/network/packet/ServerInformation.h	(revision 7800)
+++ /code/trunk/src/libraries/network/packet/ServerInformation.h	(revision 7801)
@@ -21,5 +21,5 @@
  *
  *   Author:
- *      Fabian 'x3n' Landau
+ *      Oliver Scheuss
  *   Co-authors:
  *      ...
@@ -50,4 +50,5 @@
         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_; }
         
Index: /code/trunk/src/libraries/network/packet/Welcome.cc
===================================================================
--- /code/trunk/src/libraries/network/packet/Welcome.cc	(revision 7800)
+++ /code/trunk/src/libraries/network/packet/Welcome.cc	(revision 7801)
@@ -73,9 +73,9 @@
 }
 
-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);
Index: /code/trunk/src/libraries/network/packet/Welcome.h
===================================================================
--- /code/trunk/src/libraries/network/packet/Welcome.h	(revision 7800)
+++ /code/trunk/src/libraries/network/packet/Welcome.h	(revision 7801)
@@ -47,5 +47,5 @@
   uint8_t *getData();
   inline unsigned int getSize() const;
-  bool process();
+  virtual bool process(orxonox::Host* host);
 
 private:
Index: /code/trunk/src/libraries/network/synchronisable/Synchronisable.cc
===================================================================
--- /code/trunk/src/libraries/network/synchronisable/Synchronisable.cc	(revision 7800)
+++ /code/trunk/src/libraries/network/synchronisable/Synchronisable.cc	(revision 7801)
@@ -123,5 +123,10 @@
   {
     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;
@@ -217,9 +222,9 @@
    * 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
@@ -265,4 +270,5 @@
       //tempsize += (*i)->getSize( mode );
     }
+    assert(tempsize!=0);  // if this happens an empty object (with no variables) would be transmitted
 //     COUT(4) << endl;
 
@@ -316,5 +322,5 @@
       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
Index: /code/trunk/src/libraries/network/synchronisable/Synchronisable.h
===================================================================
--- /code/trunk/src/libraries/network/synchronisable/Synchronisable.h	(revision 7800)
+++ /code/trunk/src/libraries/network/synchronisable/Synchronisable.h	(revision 7801)
@@ -65,50 +65,4 @@
     };
   }
-  
-  typedef uint8_t VariableID;
-
-  /**
-   * @brief: stores information about a Synchronisable
-   *
-   * 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 SynchronisableHeader{
-    friend class SynchronisableHeaderLight;
-    private:
-      uint8_t* data_;
-    public:
-      SynchronisableHeader(uint8_t* data)
-        { data_ = data; }
-      inline static uint32_t getSize()
-        { return 14; }
-      inline uint16_t getDataSize() const
-        { return (*(uint16_t*)data_) & 0x7FFF; } //only use the first 15 bits
-      inline void setDataSize(uint16_t size)
-        { *(uint16_t*)(data_) = (size & 0x7FFF) | (*(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_; }
-      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()); }
-  };
 
     /**
@@ -121,6 +75,7 @@
    * Byte 5 to 8: objectID_
    */
-  class _NetworkExport SynchronisableHeaderLight{
-    private:
+  class _NetworkExport SynchronisableHeaderLight
+  {
+    protected:
       uint8_t* data_;
     public:
@@ -141,7 +96,44 @@
       inline void setObjectID(uint32_t objectID_)
         { *(uint32_t*)(data_+2) = objectID_; }
+      inline void operator=(SynchronisableHeaderLight& h)
+        { memcpy(data_, h.data_, SynchronisableHeaderLight::getSize()); }
+  };
+  
+  typedef uint8_t VariableID;
+  
+  /**
+   * @brief: stores information about a Synchronisable
+   *
+   * 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 SynchronisableHeader: public SynchronisableHeaderLight
+  {
+    public:
+      SynchronisableHeader(uint8_t* data): SynchronisableHeaderLight(data)
+        {}
+      inline static uint32_t getSize()
+        { 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());
+//   }
 
   /**
Index: /code/trunk/src/libraries/util/SignalHandler.cc
===================================================================
--- /code/trunk/src/libraries/util/SignalHandler.cc	(revision 7800)
+++ /code/trunk/src/libraries/util/SignalHandler.cc	(revision 7801)
@@ -51,4 +51,5 @@
 #include <X11/Xutil.h>
 #include <X11/keysym.h>
+#include <sys/prctl.h>
 
 namespace orxonox
@@ -137,72 +138,86 @@
       COUT(0) << "Received signal " << sigName.c_str() << std::endl << "Try to write backtrace to file orxonox_crash.log" << std::endl;
 
-      int sigPipe[2];
-      if ( pipe(sigPipe) == -1 )
-      {
-        perror("pipe failed!\n");
-        exit(EXIT_FAILURE);
-      }
-
-      int sigPid = fork();
-
-      if ( sigPid == -1 )
-      {
-        perror("fork failed!\n");
-        exit(EXIT_FAILURE);
-      }
-
-      // gdb will be attached to this process
-      if ( sigPid == 0 )
-      {
-        getInstance().dontCatch();
-        // wait for message from parent when it has attached gdb
-        int someData;
-
-        read( sigPipe[0], &someData, sizeof(someData) );
-
-        if ( someData != 0x12345678 )
-        {
-          COUT(0) << "something went wrong :(" << std::endl;
-        }
-
-        return;
-      }
-
+      
+      // 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");
-        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));
+      }
+      
+      
+      // 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);
+      }
+
+      int sigPid = fork();
+
+      if ( sigPid == -1 )
+      {
+        perror("fork failed!\n");
+        kill( gdbPid, SIGTERM );
+        waitpid( gdbPid, NULL, 0 );
+        exit(EXIT_FAILURE);
+      }
+
+      // gdb will be attached to this process
+      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;
+
+        if( read( sigPipe[0], &someData, sizeof(someData) ) != sizeof(someData) )
+          COUT(0) << "something went wrong :(" << std::endl;
+
+        if ( someData != 0x12345678 )
+        {
+          COUT(0) << "something went wrong :(" << std::endl;
+        }
+
+        return;
       }
 
Index: /code/trunk/src/modules/objects/ForceField.cc
===================================================================
--- /code/trunk/src/modules/objects/ForceField.cc	(revision 7800)
+++ /code/trunk/src/modules/objects/ForceField.cc	(revision 7801)
@@ -60,4 +60,6 @@
         this->setLength(2000);
         this->mode_ = forceFieldMode::tube;
+        
+        this->registerVariables();
     }
 
@@ -83,4 +85,13 @@
         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);
+    }
+
 
     /**
Index: /code/trunk/src/modules/objects/ForceField.h
===================================================================
--- /code/trunk/src/modules/objects/ForceField.h	(revision 7800)
+++ /code/trunk/src/modules/objects/ForceField.h	(revision 7801)
@@ -88,5 +88,7 @@
 
             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.
+            
 
             /**
@@ -141,5 +143,5 @@
             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.
   };
 }
Index: /code/trunk/src/modules/overlays/hud/HUDBar.cc
===================================================================
--- /code/trunk/src/modules/overlays/hud/HUDBar.cc	(revision 7800)
+++ /code/trunk/src/modules/overlays/hud/HUDBar.cc	(revision 7801)
@@ -85,5 +85,5 @@
         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); // <--
@@ -161,5 +161,5 @@
         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);
Index: /code/trunk/src/modules/overlays/hud/HUDNavigation.cc
===================================================================
--- /code/trunk/src/modules/overlays/hud/HUDNavigation.cc	(revision 7800)
+++ /code/trunk/src/modules/overlays/hud/HUDNavigation.cc	(revision 7801)
@@ -24,4 +24,5 @@
  *   Co-authors:
  *      Reto Grieder
+ *      Oliver Scheuss
  *
  */
@@ -410,3 +411,4 @@
     }
 }
-}
+
+}
Index: /code/trunk/src/modules/pickup/PickupManager.cc
===================================================================
--- /code/trunk/src/modules/pickup/PickupManager.cc	(revision 7800)
+++ /code/trunk/src/modules/pickup/PickupManager.cc	(revision 7801)
@@ -61,5 +61,5 @@
     /*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);
Index: /code/trunk/src/modules/pickup/PickupSpawner.cc
===================================================================
--- /code/trunk/src/modules/pickup/PickupSpawner.cc	(revision 7800)
+++ /code/trunk/src/modules/pickup/PickupSpawner.cc	(revision 7801)
@@ -120,5 +120,5 @@
     PickupSpawner::~PickupSpawner()
     {
-        if(this->selfDestruct_ && this->pickup_ != NULL)
+        if(this->isInitialized() && this->selfDestruct_ && this->pickup_ != NULL)
             this->pickup_->destroy();
     }
@@ -317,5 +317,7 @@
             assert(pickup);
             assert(target);
-            assert(pickup->pickup(target));
+            bool pickedUp = pickup->pickup(target);
+            assert(pickedUp);
+            pickedUp = false; // To avoid compiler warning.
 
             this->decrementSpawnsRemaining();
Index: /code/trunk/src/modules/weapons/MuzzleFlash.cc
===================================================================
--- /code/trunk/src/modules/weapons/MuzzleFlash.cc	(revision 7800)
+++ /code/trunk/src/modules/weapons/MuzzleFlash.cc	(revision 7801)
@@ -42,5 +42,6 @@
         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)));
     }
 }
Index: /code/trunk/src/orxonox/LevelManager.cc
===================================================================
--- /code/trunk/src/orxonox/LevelManager.cc	(revision 7800)
+++ /code/trunk/src/orxonox/LevelManager.cc	(revision 7801)
@@ -152,4 +152,5 @@
         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)
         {
Index: /code/trunk/src/orxonox/Main.cc
===================================================================
--- /code/trunk/src/orxonox/Main.cc	(revision 7800)
+++ /code/trunk/src/orxonox/Main.cc	(revision 7801)
@@ -54,4 +54,7 @@
     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");
@@ -67,4 +70,5 @@
         if (CommandLineParser::getValue("generateDoc").getString().empty())
         {
+            /* TODO make this clear */
             game->setStateHierarchy(
             "root"
@@ -73,5 +77,5 @@
             "  standalone,server,client"
             "   level"
-            " server,client"
+            " server,client,masterserver"
             "  level"
             );
@@ -90,4 +94,7 @@
             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
             {
Index: /code/trunk/src/orxonox/controllers/ArtificialController.cc
===================================================================
--- /code/trunk/src/orxonox/controllers/ArtificialController.cc	(revision 7800)
+++ /code/trunk/src/orxonox/controllers/ArtificialController.cc	(revision 7801)
@@ -69,5 +69,5 @@
 
         this->target_ = 0;
-        this->formationFlight_ = true;
+        this->formationFlight_ = false;
         this->passive_ = false;
         this->maxFormationSize_ = STANDARD_MAX_FORMATION_SIZE;
Index: /code/trunk/src/orxonox/controllers/NewHumanController.cc
===================================================================
--- /code/trunk/src/orxonox/controllers/NewHumanController.cc	(revision 7800)
+++ /code/trunk/src/orxonox/controllers/NewHumanController.cc	(revision 7801)
@@ -375,5 +375,5 @@
         {
 //             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
Index: /code/trunk/src/orxonox/gamestates/CMakeLists.txt
===================================================================
--- /code/trunk/src/orxonox/gamestates/CMakeLists.txt	(revision 7800)
+++ /code/trunk/src/orxonox/gamestates/CMakeLists.txt	(revision 7801)
@@ -6,4 +6,5 @@
   GSRoot.cc
   GSServer.cc
+  GSMasterServer.cc
   GSStandalone.cc
 )
Index: /code/trunk/src/orxonox/gamestates/GSMasterServer.cc
===================================================================
--- /code/trunk/src/orxonox/gamestates/GSMasterServer.cc	(revision 7801)
+++ /code/trunk/src/orxonox/gamestates/GSMasterServer.cc	(revision 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();
+  }
+}
Index: /code/trunk/src/orxonox/gamestates/GSMasterServer.h
===================================================================
--- /code/trunk/src/orxonox/gamestates/GSMasterServer.h	(revision 7801)
+++ /code/trunk/src/orxonox/gamestates/GSMasterServer.h	(revision 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__ */
Index: /code/trunk/src/orxonox/gamestates/GSServer.cc
===================================================================
--- /code/trunk/src/orxonox/gamestates/GSServer.cc	(revision 7800)
+++ /code/trunk/src/orxonox/gamestates/GSServer.cc	(revision 7801)
@@ -34,4 +34,5 @@
 #include "core/GameMode.h"
 #include "network/Server.h"
+#include "network/Connection.h"
 
 namespace orxonox
@@ -39,5 +40,5 @@
     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)
Index: /code/trunk/src/orxonox/gametypes/Gametype.cc
===================================================================
--- /code/trunk/src/orxonox/gametypes/Gametype.cc	(revision 7800)
+++ /code/trunk/src/orxonox/gametypes/Gametype.cc	(revision 7801)
@@ -79,4 +79,9 @@
         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 */
     }
 
@@ -86,4 +91,8 @@
         {
             this->gtinfo_->destroy();
+            if( this->dedicatedAddBots_ )
+                delete this->dedicatedAddBots_;
+            if( this->dedicatedKillBots_ )
+                delete this->dedicatedKillBots_;
         }
     }
Index: /code/trunk/src/orxonox/gametypes/Gametype.h
===================================================================
--- /code/trunk/src/orxonox/gametypes/Gametype.h	(revision 7800)
+++ /code/trunk/src/orxonox/gametypes/Gametype.h	(revision 7801)
@@ -184,4 +184,9 @@
             // Config Values
             std::string scoreboardTemplate_;
+
+            /* HACK HACK HACK */
+            ConsoleCommand* dedicatedAddBots_;
+            ConsoleCommand* dedicatedKillBots_;
+            /* HACK HACK HACK */
     };
 }
Index: /code/trunk/src/orxonox/infos/Bot.cc
===================================================================
--- /code/trunk/src/orxonox/infos/Bot.cc	(revision 7800)
+++ /code/trunk/src/orxonox/infos/Bot.cc	(revision 7801)
@@ -86,5 +86,5 @@
             "Alec Trevelyan",
             "Elliot Carver",
-            "Elektra King"
+            "Elektra King",
             "Viktor Zokas",
             "Gustav Graves",
Index: /code/trunk/src/orxonox/worldentities/pawns/SpaceShip.cc
===================================================================
--- /code/trunk/src/orxonox/worldentities/pawns/SpaceShip.cc	(revision 7800)
+++ /code/trunk/src/orxonox/worldentities/pawns/SpaceShip.cc	(revision 7801)
@@ -57,4 +57,10 @@
         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;
@@ -86,4 +92,8 @@
         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);
     }
 
@@ -134,5 +144,25 @@
                 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;
     }
 
@@ -175,4 +205,18 @@
         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()
@@ -182,5 +226,6 @@
     void SpaceShip::boost()
     {
-        this->bBoost_ = true;
+        if(!this->bBoostCooldown_)
+            this->bBoost_ = true;
     }
 
Index: /code/trunk/src/orxonox/worldentities/pawns/SpaceShip.h
===================================================================
--- /code/trunk/src/orxonox/worldentities/pawns/SpaceShip.h	(revision 7800)
+++ /code/trunk/src/orxonox/worldentities/pawns/SpaceShip.h	(revision 7801)
@@ -34,4 +34,5 @@
 #include <string>
 #include <LinearMath/btVector3.h>
+#include "tools/Timer.h"
 #include "util/Math.h"
 #include "Pawn.h"
@@ -69,6 +70,5 @@
                 { return this->steering_; }
 
-            inline void setBoost(bool bBoost)
-                { this->bBoost_ = bBoost; }
+            void setBoost(bool bBoost);
             inline bool getBoost() const
                 { return this->bBoost_; }
@@ -89,5 +89,11 @@
 
             bool bBoost_;
+            bool bBoostCooldown_;
             bool bPermanentBoost_;
+            float boostPower_;
+            float initialBoostPower_;
+            float boostRate_;
+            float boostPowerRate_;
+            float boostCooldownDuration_;
             Vector3 steering_;
             float primaryThrust_;
@@ -102,7 +108,10 @@
 
             void loadEngineTemplate();
+            
+            void boostCooledDown(void);
 
             std::string enginetemplate_;
             Engine* engine_;
+            Timer timer_;
     };
 }
