Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 5, 2008, 1:19:22 AM (17 years ago)
Author:
scheusso
Message:

a lot of changes in order to make it possible to have mulpiple clients with each one a new ship
camera changes
object changes
synchronisable: backsyncronisation should be possible now
gamestatemanager/gamestateclient: functions for backsyncronisation
some changes in order to get the input system (the old one) on the client working
TODO something with the camera position is wrong at the moment (clientside)

File:
1 edited

Legend:

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

    r1199 r1232  
    5353  bool PacketDecoder::elaborate( ENetPacket* packet, int clientId )
    5454  {
    55     int client = clientId;
    56     COUT(5) << "PacketDecoder: clientId: " << client << std::endl; //control cout, not important, just debugging info
     55    COUT(5) << "PacketDecoder: clientId: " << clientId << std::endl; //control cout, not important, just debugging info
    5756    int id = (int)*packet->data; //the first 4 bytes are always the enet packet id
    5857    COUT(5) << "PacketDecoder: packet id: " << id << std::endl;
     
    6463    }
    6564    switch( id ) {
    66   case ACK:
    67     acknowledgement( packet, clientId );
    68     return true;
    69     break;
    70   case MOUSE:
    71     mousem( packet, clientId );
    72     return true;
    73     break;
    74   case KEYBOARD:
    75     keystrike( packet, clientId );
    76     return true;
    77     break;
    78   case CHAT:
    79     chatMessage( packet, clientId );
    80     return true;
    81     break;
    82   case GAMESTATE:
    83     gstate( packet );
    84     return true;
    85     break;
    86   case CLASSID:
    87     clid(packet);
    88     return true;
    89     break;
     65    case ACK:
     66      acknowledgement( packet, clientId );
     67      return true;
     68    case COMMAND:
     69      return command( packet, clientId );
     70    case MOUSE:
     71      mousem( packet, clientId );
     72      return true;
     73    case KEYBOARD:
     74      keystrike( packet, clientId );
     75      return true;
     76    case CHAT:
     77      chatMessage( packet, clientId );
     78      return true;
     79    case GAMESTATE:
     80      gstate( packet );
     81      return true;
     82    case CLASSID:
     83      clid(packet);
     84      return true;
     85    case WELCOME:
     86      return decodeWelcome( packet, clientId );
     87    case CONNECT:
     88      return decodeConnectRequest( packet, clientId );
    9089    }
    9190    return false;
     
    105104    //clean memory
    106105    enet_packet_destroy( packet );
     106  }
     107 
     108  bool PacketDecoder::command( ENetPacket* packet, int clientId ){
     109    int length = *(int*)((unsigned char *)packet->data+sizeof(int));
     110    void *data = (void *)new unsigned char[length];
     111    memcpy(data, (void *)(packet->data+2*sizeof(int)), length);
     112    return true;
    107113  }
    108114
     
    171177    //since the packetgenerator was changed, due to a new parameter, change this function too
    172178    memcpy( (void*)&(currentState->diffed), (const void*)(packet->data+5*sizeof(int)), sizeof(bool));
     179    memcpy( (void*)&(currentState->complete), (const void*)(packet->data+5*sizeof(int)+sizeof(bool)), sizeof(bool));
    173180    //since data is not allocated, because it's just a pointer, allocate it with size of gamestatedatastream
    174181    if(currentState->compsize==0)
     
    178185      COUT(2) << "PacketDecoder: Gamestatepacket-decoder: memory leak" << std::endl;
    179186    //copy the GameStateCompressed data
    180     memcpy( (void*)(currentState->data), (const void*)(packet->data+5*sizeof( int ) + sizeof(bool)), currentState->compsize );
     187    memcpy( (void*)(currentState->data), (const void*)(packet->data+5*sizeof( int ) + 2*sizeof(bool)), currentState->compsize );
    181188
    182189    //clean memory
     
    198205    processClassid(cid);
    199206  }
     207 
     208 
     209  bool PacketDecoder::decodeWelcome( ENetPacket* packet, int clientID ){
     210    welcome *w = new welcome;
     211    w->allowed = ((welcome *)(packet->data))->allowed;
     212    w->shipID = ((welcome *)(packet->data))->shipID;
     213    w->clientID = ((welcome *)(packet->data))->clientID;
     214    w->id = ((welcome *)(packet->data))->id;
     215    enet_packet_destroy( packet );
     216    return processWelcome(w);
     217  }
     218 
     219  bool PacketDecoder::decodeConnectRequest( ENetPacket *packet, int clientID ){
     220    connectRequest *con = new connectRequest;
     221    con->id = ((connectRequest *)(packet->data))->id;
     222    enet_packet_destroy( packet );
     223    return processConnectRequest(con, clientID );
     224  }
    200225
    201226
     
    224249    return;
    225250  }
    226 
     251 
     252  bool PacketDecoder::processWelcome( welcome *w ){
     253    return true;
     254  }
     255 
     256  bool PacketDecoder::processConnectRequest( connectRequest *con, int clientID ){
     257    COUT(3) << "packetdecoder: processing connectRequest" << std::endl;
     258    return true;
     259  }
    227260
    228261  //these are some print functions for test stuff
Note: See TracChangeset for help on using the changeset viewer.