Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 1, 2008, 3:54:20 PM (16 years ago)
Author:
rgrieder
Message:
  • @everyone: Do not create a branch until I've added the svn:eol-style property correctly. Otherwise this would cost me another 4 hours or so when we want to merge back.
  • merged network branch back to trunk
  • I had to omit the changes from last evening concerning the line endings
  • might not work yet because of the line endings
  • @beni: script branch is the only branch still open. you probably will have to apply a patch because of inconsistent new lines
File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/network/PacketGenerator.cc

    r1360 r1502  
    7878  {
    7979    COUT(4) << "PacketGenerator: generating new acknowledgement, id: " << state << std::endl;
    80     ack* ackreq = new ack;
     80   
     81    ENetPacket *packet = enet_packet_create( NULL , sizeof( ack ), reliable );
     82    ack* ackreq = (ack *)packet->data;
    8183    ackreq->id = ACK;
    8284    ackreq->a = state;
    83 
    84     ENetPacket *packet = enet_packet_create( ackreq , sizeof( *ackreq ), reliable );
    85     delete ackreq;
     85    //delete ackreq;
    8686    return packet;
    8787  }
     
    8989  ENetPacket* command( int dataLength, void *data, int reliable = ENET_PACKET_FLAG_RELIABLE )
    9090  {
     91    if(dataLength==0)
     92      return NULL;
    9193    unsigned char *stream = new unsigned char[dataLength + 2*sizeof(int)];
    9294    if(!stream)
     
    101103  }
    102104
    103   /*### mouseupdates */
    104   ENetPacket* PacketGenerator::mousem( double x, double y, int reliable )
    105   {
    106     COUT(4) << "PacketGenerator: generating new mouse" << std::endl;
    107     mouse* mousemove = new mouse;
    108     mousemove->id = MOUSE;
    109     mousemove->x = x;
    110     mousemove->y = y;
    111 
    112     ENetPacket *packet = enet_packet_create( mousemove , sizeof( *mousemove ), reliable );
    113     delete mousemove;
    114     return packet;
    115   }
    116 
    117   /*### keystrikes updates */
    118   ENetPacket* PacketGenerator::keystrike( char press, int reliable )
    119   {
    120     COUT(4) << "PacketGenerator: generating new keyboard" << std::endl;
    121     keyboard* key = new keyboard;
    122     key->id = KEYBOARD;
    123     key->press = press;
    124 
    125     ENetPacket *packet = enet_packet_create( key , sizeof( *key ), reliable );
    126     delete key;
    127     return packet;
    128   }
    129105
    130106  /*### chat messages packet */
     
    150126    //std::cout << "totalLen " << totalLen << std::endl;
    151127    //unsigned char *data = (unsigned char*)malloc( totalLen ); //allocate the memory for datastream
    152     unsigned char *data = new unsigned char[totalLen];
     128    if(totalLen==0)
     129      return NULL;
     130    ENetPacket *packet = enet_packet_create( NULL , totalLen+sizeof(uint32_t), reliable );
     131    //unsigned char *data = new unsigned char[totalLen];
     132    unsigned char *data = packet->data;
    153133    memcpy( (void*)(data), (const void*)&gid, sizeof( int ) ); //this is the enet id
    154134    memcpy( (void*)(data+sizeof(int)), (const void*)&(states->id), sizeof(int) ); //the GameStateCompressed id
     
    163143    //create an enet packet with the generated bytestream
    164144    COUT(4) << "PacketGenerator generating totalLen " << totalLen << std::endl;
    165     ENetPacket *packet = enet_packet_create( data , totalLen, reliable );
    166     delete[] data;
     145    //delete[] data;
    167146    if(!addCRC(packet))
    168147      COUT(3) << "could not add crc to gamestate packet" << std::endl;
     
    173152  {
    174153    //unsigned char* data = (unsigned char *)malloc(3*sizeof(int)+classname.length()+1);
     154    if(classname.length()==0)
     155      return NULL;
    175156    unsigned char *data = new unsigned char[3*sizeof(int)+classname.length()+1];
    176157    std::cout << "PacketGenerator: classid: " << classid << ", name: " << classname << std::endl;
     
    206187  bool PacketGenerator::addCRC( ENetPacket *packet){
    207188    unsigned char *data = packet->data;
    208     uint32_t crc32=calcCRC(data, packet->dataLength);
     189    uint32_t crc32=calcCRC(data, packet->dataLength-sizeof(uint32_t));
    209190    // now append the crc to the packet data
    210     int oldlength = packet->dataLength;
    211     if(enet_packet_resize(packet, packet->dataLength+sizeof(uint32_t))==0){
     191    int oldlength = packet->dataLength-sizeof(uint32_t);
     192    //if(enet_packet_resize(packet, packet->dataLength+sizeof(uint32_t))==0){
    212193      memcpy(&packet->data[oldlength], &crc32, sizeof(uint32_t));
    213194      return true;
    214     }else{
    215       COUT(3) << "could not add crc to gamestate" << std::endl;
    216       return false;
    217     }
     195    //}else{
     196     // COUT(3) << "could not add crc to gamestate" << std::endl;
     197     // return false;
     198    //}
    218199  }
    219200
Note: See TracChangeset for help on using the changeset viewer.