Index: trunk/src/lib/math/quaternion.h
===================================================================
--- trunk/src/lib/math/quaternion.h	(revision 8796)
+++ trunk/src/lib/math/quaternion.h	(revision 8802)
@@ -50,4 +50,6 @@
   /** @param q: the Quaternion to compare with this one. @returns true if the Quaternions are the same, false otherwise */
   inline bool operator== (const Quaternion& q) const { return (unlikely(this->v==q.v&&this->w==q.w))?true:false; };
+  /** @param q: the Quaternion to compare with this one. @returns true if the Quaternions are the same, false otherwise */
+  inline bool operator!= (const Quaternion& q) const { return (unlikely(this->v!=q.v&&this->w!=q.w))?true:false; };
   /** @param f: a real value @return a Quaternion containing the quotient */
   inline Quaternion operator/ (const float& f) const { return (unlikely(f==0.0)) ? Quaternion() : Quaternion(this->v/f, this->w/f); };
Index: trunk/src/lib/network/netdefs.h
===================================================================
--- trunk/src/lib/network/netdefs.h	(revision 8796)
+++ trunk/src/lib/network/netdefs.h	(revision 8802)
@@ -19,5 +19,5 @@
 #define MAX_CONNECTIONS 1000
 
-#define NETWORK_FREQUENCY 33
+#define NETWORK_FREQUENCY 66
 
 
Index: trunk/src/lib/network/udp_server_socket.cc
===================================================================
--- trunk/src/lib/network/udp_server_socket.cc	(revision 8796)
+++ trunk/src/lib/network/udp_server_socket.cc	(revision 8802)
@@ -147,7 +147,4 @@
     res.length = packetBuffer[userId].front().length;
     packetBuffer[userId].pop_front();
-
-    if ( res.length == 0 )
-      res.length = -1;
   }
 
@@ -173,5 +170,5 @@
  * @param ip users host / port
  */
-void UdpServerSocket::initUser( int userId, IPaddress ip )
+void UdpServerSocket::initUser( int userId, IPaddress ip, byte randomByte )
 {
   int channel = SDLNet_UDP_Bind( socket, userId, &ip );
@@ -192,5 +189,6 @@
     userList.resize( userId + 1 );
 
-  userList[ userId ] = ip;
+  userList[ userId ].addr = ip;
+  userList[ userId ].randomByte = randomByte;
 }
 
@@ -206,6 +204,6 @@
     return;
 
-  userList[userId].host = 0;
-  userList[userId].port = 0;
+  userList[userId].addr.host = 0;
+  userList[userId].addr.port = 0;
 
   SDLNet_UDP_Unbind( socket, userId );
@@ -234,5 +232,5 @@
     return false;
   }
-
+  
   return true;
 }
@@ -251,11 +249,13 @@
     bool isNewConnection = false;
 
+    if ( packet->len <= 0 )
+      continue; 
+        
     for ( userId =0; userId < (int)userList.size(); userId++ )
-      if ( userList[userId].host == packet->address.host && userList[userId].port == packet->address.port )
+      if ( userList[userId].addr.host == packet->address.host && userList[userId].addr.port == packet->address.port && userList[userId].randomByte == ( packet->data[0] & 0xFC ) )
         break;
 
     if ( userId >= (int)userList.size() )
     {
-
       newConn++;
       isNewConnection = true;
@@ -268,9 +268,9 @@
 
       for ( userId =0; userId < (int)userList.size(); userId++ )
-        if ( userList[userId].host == 0 && userList[userId].port == 0 )
+        if ( userList[userId].addr.host == 0 && userList[userId].addr.port == 0 )
           break;
 
-      initUser( userId, packet->address );
-      UdpSocket * sock = new UdpSocket( this, packet->address, userId );
+      initUser( userId, packet->address, packet->data[0] & 0xFC );
+      UdpSocket * sock = new UdpSocket( this, packet->address, userId, packet->data[0] & 0xFC );
       newSocketList.push_back( sock );
       PRINTF(0)("NEW CONNECTION %x\n", packet->address.host );
@@ -292,5 +292,4 @@
     memcpy( networkPacket.data, packet->data, packet->len );
     packetBuffer[userId].push_back( networkPacket );
-
   }
 
Index: trunk/src/lib/network/udp_server_socket.h
===================================================================
--- trunk/src/lib/network/udp_server_socket.h	(revision 8796)
+++ trunk/src/lib/network/udp_server_socket.h	(revision 8802)
@@ -33,5 +33,11 @@
 typedef std::vector<NetworkPacketList> PacketBuffer;
 
-typedef std::vector<IPaddress> UserList;
+struct UserInfo
+{
+  IPaddress addr;
+  byte randomByte;
+};
+
+typedef std::vector<UserInfo> UserList;
 
 typedef std::list<UdpSocket*> UdpSocketList;
@@ -57,5 +63,5 @@
     bool sendPacket( NetworkPacket networkPacket, int userId );
     int getPacketCount( int childId );
-    void initUser( int childId, IPaddress ip );
+    void initUser( int childId, IPaddress ip, byte randomByte );
     
   private:
Index: trunk/src/lib/network/udp_socket.cc
===================================================================
--- trunk/src/lib/network/udp_socket.cc	(revision 8796)
+++ trunk/src/lib/network/udp_socket.cc	(revision 8802)
@@ -25,4 +25,5 @@
   this->socket = NULL;
   this->packet = NULL;
+  this->randomByte = 0;
 }
 
@@ -70,9 +71,10 @@
  * @param userId userid used by serverSocket
  */
-UdpSocket::UdpSocket( UdpServerSocket * serverSocket, IPaddress ip, int userId )
+UdpSocket::UdpSocket( UdpServerSocket * serverSocket, IPaddress ip, int userId, byte randomByte )
 {
   this->init();
   this->serverSocket = serverSocket;
   this->userId = userId;
+  this->randomByte = randomByte;
 }
 
@@ -104,4 +106,6 @@
 
   IPaddress ip;
+  
+  this->randomByte = generateNewRandomByte();
 
   PRINTF(0)("connect to server %s on port %d\n", host.c_str(), port);
@@ -137,5 +141,6 @@
 {
   PRINTF(0)("disconnect\n");
-  writePacket( NULL, 0 );
+  byte cmd = this->randomByte | UDPCMD_DISCONNECT;
+  writeRawPacket( &cmd, 1 );
   SDLNet_UDP_Unbind( socket, -1 );
   SDLNet_UDP_Close( socket );
@@ -152,4 +157,91 @@
 bool UdpSocket::writePacket( byte * data, int length )
 {
+  byte * buf = new byte[length+1];
+  if ( length > 0 )
+    memcpy( buf+1, data, length );
+  buf[0] = this->randomByte;
+  return writeRawPacket( buf, length+1 );
+}
+
+/**
+ * recieve one packet from another host
+ * @param data pointer to buffer to copy data into
+ * @param maxLength maximal length of buffer
+ * @return less than 0 on error, number bytes read else
+ */
+int UdpSocket::readPacket( byte * data, int maxLength )
+{
+  assert( maxLength <= UDP_PACKET_SIZE );
+
+  if ( serverSocket )
+  {
+    NetworkPacket networkPacket = serverSocket->getPacket( this->userId );
+
+    byte udpCmd = 0;
+    
+    if ( networkPacket.length > 0 )
+    {
+      assert( maxLength > networkPacket.length );
+
+      memcpy( data, networkPacket.data+1, networkPacket.length-1 );
+      udpCmd = networkPacket.data[0];
+    }
+    else
+      return 0;
+      
+    if ( !checkRandomByte( networkPacket.data[0] ) )
+      return 0;
+
+    if ( networkPacket.data )
+    {
+      free( networkPacket.data );
+      networkPacket.data = NULL;
+    }
+    
+    if ( !checkUdpCmd( udpCmd ) )
+      return 0;
+
+    return networkPacket.length-1;
+  }
+  else
+  {
+    int numrecv = SDLNet_UDP_Recv( socket, packet);
+    
+    byte udpCmd = 0;
+
+    if ( numrecv > 0)
+    {
+      assert( packet->len <= maxLength );
+
+      if ( packet->len > 0 )
+        memcpy( data, packet->data+1, packet->len-1 );
+      else
+        return 0;
+            
+      if ( !checkRandomByte( packet->data[0] ) )
+        return 0;
+              
+      if ( !checkUdpCmd( udpCmd ) )
+        return 0;
+
+      return packet->len-1;
+    }
+    else if ( numrecv < 0 )
+    {
+      PRINTF(1)("SDLNet_UDP_Recv: %s\n", SDLNet_GetError());
+      bOk = false;
+      return -1;
+    }
+    else
+    {
+      return 0;
+    }
+  }
+
+  return 0;
+}
+
+bool UdpSocket::writeRawPacket( byte * data, int length )
+{
   if ( serverSocket )
   {
@@ -183,70 +275,48 @@
 }
 
-/**
- * recieve one packet from another host
- * @param data pointer to buffer to copy data into
- * @param maxLength maximal length of buffer
- * @return less than 0 on error, number bytes read else
- */
-int UdpSocket::readPacket( byte * data, int maxLength )
-{
-  assert( maxLength <= UDP_PACKET_SIZE );
-
-  if ( serverSocket )
-  {
-    NetworkPacket networkPacket = serverSocket->getPacket( this->userId );
-
-    if ( networkPacket.length == -1 )
-    {
-      this->disconnectServer();
-      return 0;
-    }
-
-    if ( networkPacket.length > 0 )
-    {
-      assert( maxLength > networkPacket.length );
-
-      memcpy( data, networkPacket.data, networkPacket.length );
-    }
-
-    if ( networkPacket.data )
-    {
-      free( networkPacket.data );
-      networkPacket.data = NULL;
-    }
-
-    return networkPacket.length;
+bool UdpSocket::checkUdpCmd( byte udpCmd )
+{
+  if ( udpCmd & UDPCMD_DISCONNECT )
+  {
+    this->disconnectServer();
+    PRINTF(0)("received disconnect byte\n");
+    return false;
+  }
+  
+  if ( !this->serverSocket && ( udpCmd & UDPCMD_INVALIDRNDBYTE ) )
+  {
+    PRINTF(0)("received invlid random number byte\n");
+    byte cmd = this->randomByte | UDPCMD_DISCONNECT;
+    writeRawPacket( &cmd, 1 );
+    this->randomByte = generateNewRandomByte();
+    return false;
+  }
+  
+  return true;
+}
+
+byte UdpSocket::generateNewRandomByte( )
+{
+  srand( SDL_GetTicks() );
+  byte res = ( rand() & 0xFC );
+  
+  PRINTF(0)("generated random byte: %x\n", res);
+  
+  return res;
+}
+
+bool UdpSocket::checkRandomByte( byte rndByte )
+{
+  if ( ( rndByte & 0xFC ) == this->randomByte )
+  {
+    return true;
   }
   else
   {
-    int numrecv = SDLNet_UDP_Recv( socket, packet);
-    if ( numrecv > 0)
-    {
-      assert( packet->len <= maxLength );
-
-      if ( packet->len == 0 )
-      {
-        this->disconnectServer();
-        return 0;
-      }
-
-      memcpy( data, packet->data, packet->len );
-      return packet->len;
-    }
-    else if ( numrecv < 0 )
-    {
-      PRINTF(1)("SDLNet_UDP_Recv: %s\n", SDLNet_GetError());
-      bOk = false;
-      return -1;
-    }
-    else
-    {
-      return 0;
-    }
-  }
-
-  return 0;
-}
-
-
-
+    PRINTF(2)("wrong random byte: %x\n", ( rndByte & 0xFC ));
+    return false;
+  }
+}
+
+
+
Index: trunk/src/lib/network/udp_socket.h
===================================================================
--- trunk/src/lib/network/udp_socket.h	(revision 8796)
+++ trunk/src/lib/network/udp_socket.h	(revision 8802)
@@ -16,9 +16,15 @@
 class UdpServerSocket;
 
+enum
+{
+  UDPCMD_DISCONNECT = 1,
+  UDPCMD_INVALIDRNDBYTE = 2
+};
+
 class UdpSocket : public NetworkSocket
 {
   public:
     UdpSocket();
-    UdpSocket( UdpServerSocket * serverSocket, IPaddress ip, int userId );
+    UdpSocket( UdpServerSocket * serverSocket, IPaddress ip, int userId, byte randomByte );
     UdpSocket( std::string host, int port );
     virtual ~UdpSocket();
@@ -28,5 +34,5 @@
     virtual void disconnectServer();
 
-    virtual bool writePacket(byte * data, int length);
+    virtual bool writePacket(byte * data, int length );
 
     virtual int readPacket(byte * data, int maxLength);
@@ -39,4 +45,11 @@
     UDPpacket *       packet;
     
+    byte              randomByte;     //!< contains random bytes & 0xFC
+    
+    bool writeRawPacket( byte * data, int length );
+    bool checkUdpCmd( byte udpCmd );
+    bool checkRandomByte( byte rndByte );
+    byte generateNewRandomByte();
+    
     void init();
 
