Index: code/branches/merge/src/network/PacketDecoder.cc
===================================================================
--- code/branches/merge/src/network/PacketDecoder.cc	(revision 1333)
+++ code/branches/merge/src/network/PacketDecoder.cc	(revision 1336)
@@ -88,4 +88,22 @@
       return decodeConnectRequest( packet, clientId );
     }
+    return false;
+  }
+  
+  bool PacketDecoder::testAndRemoveCRC(ENetPacket *packet){
+    uint32_t submittetcrc;
+    int dataLength = packet->dataLength;
+    // get the submittet crc code
+    memcpy(&submittetcrc, &packet->data[dataLength-sizeof(uint32_t)], sizeof(uint32_t));
+    unsigned char *data = packet->data;
+    uint32_t crc32=calcCRC(data, packet->dataLength-sizeof(uint32_t));
+    // now append the crc to the packet data
+    if(crc32==submittetcrc){
+      dataLength-=sizeof(uint32_t);
+      enet_packet_resize(packet, dataLength);
+      return true;
+    }
+    COUT(3) << "gamestate crc: " << crc32 << std::endl;
+    COUT(3) << "submitted crc: " << submittetcrc << std::endl;
     return false;
   }
@@ -157,4 +175,8 @@
   void PacketDecoder::gstate( ENetPacket* packet, int clientID )
   {
+    if(!testAndRemoveCRC(packet)){
+      COUT(3) << "crc test of gamestate failed - dropping packet" << std::endl;
+      return;
+    }
     GameStateCompressed* currentState = NULL;
     currentState = new GameStateCompressed;
Index: code/branches/merge/src/network/PacketGenerator.cc
===================================================================
--- code/branches/merge/src/network/PacketGenerator.cc	(revision 1333)
+++ code/branches/merge/src/network/PacketGenerator.cc	(revision 1336)
@@ -46,4 +46,29 @@
 namespace network
 {
+  void calcCRCBit(uint32_t &crc32, int bit){
+    int hbit;
+ 
+    hbit=(crc32 & 0x80000000) ? 1 : 0;
+    if (hbit != bit)
+      crc32=(crc32<<1) ^ NETWORK_CRC32POLY;
+    else
+      crc32=crc32<<1;
+  }
+  
+  uint32_t calcCRC(unsigned char *data, unsigned int dataLength){
+    uint32_t crc32=0;
+    for(unsigned int i=0; i<dataLength; i++){
+      calcCRCBit(crc32, (data[i]&0x1)>>0); // 1st bit
+      calcCRCBit(crc32, (data[i]&0x2)>>1); // 2nd bit
+      calcCRCBit(crc32, (data[i]&0x3)>>2); // 3rd bit
+      calcCRCBit(crc32, (data[i]&0x4)>>3); // 4th bit
+      calcCRCBit(crc32, (data[i]&0x5)>>4); // 5th bit
+      calcCRCBit(crc32, (data[i]&0x6)>>5); // 6th bit
+      calcCRCBit(crc32, (data[i]&0x7)>>6); // 7th bit
+      calcCRCBit(crc32, (data[i]&0x8)>>7); // 8th bit
+    }
+    return crc32;
+  }
+  
   PacketGenerator::PacketGenerator() { }
 
@@ -135,8 +160,11 @@
     memcpy( (void*)(data+5*sizeof( int ) + sizeof(bool)), (const void*)&(states->complete), sizeof(bool) );
     memcpy( (void*)(data+5*sizeof( int ) + 2*sizeof(bool)), (const void*)states->data, states->compsize );
+    
     //create an enet packet with the generated bytestream
     COUT(4) << "PacketGenerator generating totalLen " << totalLen << std::endl;
     ENetPacket *packet = enet_packet_create( data , totalLen, reliable );
     delete[] data;
+    if(!addCRC(packet))
+      COUT(3) << "could not add crc to gamestate packet" << std::endl;
     return packet;
   }
@@ -174,4 +202,19 @@
     return packet;
   }
+  
+  
+  bool PacketGenerator::addCRC( ENetPacket *packet){
+    unsigned char *data = packet->data;
+    uint32_t crc32=calcCRC(data, packet->dataLength);
+    // now append the crc to the packet data
+    int oldlength = packet->dataLength;
+    if(enet_packet_resize(packet, packet->dataLength+sizeof(uint32_t))==0){
+      memcpy(&packet->data[oldlength], &crc32, sizeof(uint32_t));
+      return true;
+    }else{
+      COUT(3) << "could not add crc to gamestate" << std::endl;
+      return false;
+    }
+  }
 
 }
Index: code/branches/merge/src/network/PacketManager.h
===================================================================
--- code/branches/merge/src/network/PacketManager.h	(revision 1333)
+++ code/branches/merge/src/network/PacketManager.h	(revision 1336)
@@ -33,4 +33,5 @@
 
 #include <string>
+#include <inttypes.h>
 #include <enet/enet.h>
 
@@ -38,4 +39,5 @@
 
 #define CLIENTID_CLIENT -1
+#define NETWORK_CRC32POLY 0x04C11DB7 /* CRC-32 Polynom */
 
 //enum netowk generally used to set the type ID of a packet
@@ -48,4 +50,7 @@
   *
   */
+  //void calcCRC(uint32_t &crc32, int bit);
+  uint32_t calcCRC(unsigned char *data, unsigned int dataLength);
+  
   class PacketGenerator
   {
@@ -63,4 +68,5 @@
     ENetPacket* generateConnectRequest( int reliable = ENET_PACKET_FLAG_RELIABLE );
   private:
+    bool addCRC( ENetPacket *packet);
   };
 
@@ -84,5 +90,5 @@
 
   private:
-
+    bool testAndRemoveCRC(ENetPacket *packet);
 
 
