Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 20, 2008, 5:58:37 PM (16 years ago)
Author:
scheusso
Message:

added crc checksum testing for submitted gamestates (can also be used for other packet types)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/merge/src/network/PacketDecoder.cc

    r1299 r1336  
    8888      return decodeConnectRequest( packet, clientId );
    8989    }
     90    return false;
     91  }
     92 
     93  bool PacketDecoder::testAndRemoveCRC(ENetPacket *packet){
     94    uint32_t submittetcrc;
     95    int dataLength = packet->dataLength;
     96    // get the submittet crc code
     97    memcpy(&submittetcrc, &packet->data[dataLength-sizeof(uint32_t)], sizeof(uint32_t));
     98    unsigned char *data = packet->data;
     99    uint32_t crc32=calcCRC(data, packet->dataLength-sizeof(uint32_t));
     100    // now append the crc to the packet data
     101    if(crc32==submittetcrc){
     102      dataLength-=sizeof(uint32_t);
     103      enet_packet_resize(packet, dataLength);
     104      return true;
     105    }
     106    COUT(3) << "gamestate crc: " << crc32 << std::endl;
     107    COUT(3) << "submitted crc: " << submittetcrc << std::endl;
    90108    return false;
    91109  }
     
    157175  void PacketDecoder::gstate( ENetPacket* packet, int clientID )
    158176  {
     177    if(!testAndRemoveCRC(packet)){
     178      COUT(3) << "crc test of gamestate failed - dropping packet" << std::endl;
     179      return;
     180    }
    159181    GameStateCompressed* currentState = NULL;
    160182    currentState = new GameStateCompressed;
Note: See TracChangeset for help on using the changeset viewer.