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/PacketDecoder.cc

    r1360 r1502  
    6868    case COMMAND:
    6969      return command( packet, clientId );
    70     case MOUSE:
    71       mousem( packet, clientId );
    72       return true;
    73     case KEYBOARD:
    74       keystrike( packet, clientId );
    75       return true;
    7670    case CHAT:
    7771      chatMessage( packet, clientId );
     
    9084    return false;
    9185  }
    92  
     86
    9387  bool PacketDecoder::testAndRemoveCRC(ENetPacket *packet){
    9488    uint32_t submittetcrc;
     
    108102    return false;
    109103  }
    110  
     104
    111105  // ATTENTION: TODO watch, that arguments we pass over to the processFunction gets deleted in THE PROCESSXXX function
    112106
     
    124118    enet_packet_destroy( packet );
    125119  }
    126  
     120
    127121  bool PacketDecoder::command( ENetPacket* packet, int clientId ){
    128122    int length = *(int*)((unsigned char *)packet->data+sizeof(int));
     123    if(length<=0)
     124      return false;
    129125    void *data = (void *)new unsigned char[length];
    130126    memcpy(data, (void *)(packet->data+2*sizeof(int)), length);
     
    133129  }
    134130
    135   void PacketDecoder::mousem( ENetPacket* packet, int clientId )
    136   {
    137     mouse* mouseMove = new mouse;
    138     //copy data of packet->data to new struct
    139     *mouseMove = *(mouse*)packet->data;
    140 
    141     //clean memory
    142     enet_packet_destroy( packet );
    143     printMouse( mouseMove ); //debug info
    144   }
    145 
    146   void PacketDecoder::keystrike( ENetPacket* packet, int clientId )
    147   {
    148     keyboard* key = new keyboard;
    149     *key = *(keyboard*)packet->data; //see above
    150 
    151     //clean memory
    152     enet_packet_destroy( packet );
    153     printKey( key ); //debug info
    154 
    155   }
    156 
    157131  void PacketDecoder::chatMessage( ENetPacket* packet, int clientId )
    158132  {
    159133    chat* chatting = new chat;
     134    if(packet->dataLength==4)
     135      return;
    160136    chatting->id = (int)*packet->data; //first copy id into new struct
    161137    //since the chat message is a char*, allocate the memory needed
     
    185161      return;
    186162    }
    187     //since it's not alowed to use void* for pointer arithmetic
    188     //FIXME: variable never used
    189     unsigned char* data = (unsigned char *)(packet->data);
    190163    //copy the GameStateCompressed id into the struct, which is located at second place data+sizeof( int )
    191164    memcpy( (void*)&(currentState->id), (const void*)(packet->data+1*sizeof( int )), sizeof( int) );
     
    202175    //since data is not allocated, because it's just a pointer, allocate it with size of gamestatedatastream
    203176    if(currentState->compsize==0)
     177    {
    204178      COUT(2) << "PacketDecoder: compsize is 0" << std::endl;
     179    }
    205180//     currentState->data = (unsigned char*)(malloc( currentState->compsize ));
     181    if(currentState->compsize==0)
     182      return;
    206183    currentState->data = new unsigned char[currentState->compsize];
    207184    if(currentState->data==NULL)
     185    {
    208186      COUT(2) << "PacketDecoder: Gamestatepacket-decoder: memory leak" << std::endl;
     187    }
    209188    //copy the GameStateCompressed data
    210189    memcpy( (void*)(currentState->data), (const void*)(packet->data+5*sizeof( int ) + 2*sizeof(bool)), currentState->compsize );
     
    221200    cid->id = ((classid *)(packet->data))->id;
    222201    cid->clid = ((classid *)(packet->data))->clid;
     202    if(cid->length==0)
     203      return;
    223204//     cid->message = (const char *)malloc(cid->length);
    224205    cid->message = new char[cid->length];
     
    229210    processClassid(cid);
    230211  }
    231  
    232  
     212
     213
    233214  bool PacketDecoder::decodeWelcome( ENetPacket* packet, int clientID ){
    234215    welcome *w = new welcome;
     
    240221    return processWelcome(w);
    241222  }
    242  
     223
    243224  bool PacketDecoder::decodeConnectRequest( ENetPacket *packet, int clientID ){
    244225    connectRequest *con = new connectRequest;
     
    279260    return;
    280261  }
    281  
     262
    282263  bool PacketDecoder::processWelcome( welcome *w ){
    283264    delete w;
    284265    return true;
    285266  }
    286  
     267
    287268  bool PacketDecoder::processConnectRequest( connectRequest *con, int clientID ){
    288269    COUT(3) << "packetdecoder: processing connectRequest" << std::endl;
     
    299280  }
    300281
    301   void PacketDecoder::printMouse( mouse* data )
    302   {
    303     COUT(5) << "data id: " << data->id << std::endl;
    304     COUT(5) << "data:    " << data->x << " " << data->y << std::endl;
    305   }
    306 
    307   void PacketDecoder::printKey( keyboard* data )
    308   {
    309     COUT(5) << "data id: " << data->id << std::endl;
    310     COUT(5) << "data:    " << (char)data->press << std::endl;
    311   }
    312282
    313283  void PacketDecoder::printChat( chat* data, int clientId )
    314284  {
    315285    if(clientId!=CLIENTID_CLIENT)
     286    {
    316287      COUT(5) << "client: " << clientId << std::endl;
     288    }
    317289    COUT(5) << "data id: " << data->id << std::endl;
    318290    COUT(5) << "data:    " << data->message << std::endl;
Note: See TracChangeset for help on using the changeset viewer.