Changeset 1021 for code/trunk/src/network/PacketDecoder.cc
- Timestamp:
- Apr 10, 2008, 5:03:34 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/network/PacketDecoder.cc
r790 r1021 38 38 #include "PacketTypes.h" 39 39 #include "PacketManager.h" 40 #include "orxonox/core/Debug.h" 40 41 41 42 namespace network 42 43 { 43 using namespace std;44 44 45 45 PacketDecoder::PacketDecoder(){} … … 52 52 { 53 53 int client = clientId; 54 cout << "clientId: " << client <<endl; //control cout, not important, just debugging info54 COUT(5) << "clientId: " << client << std::endl; //control cout, not important, just debugging info 55 55 int id = (int)*packet->data; //the first 4 bytes are always the enet packet id 56 std::cout<< "packet id: " << id << std::endl;57 std::cout<< "packet size inside packetdecoder: " << packet->dataLength << std::endl;56 COUT(5) << "packet id: " << id << std::endl; 57 // COUT(5) << "packet size inside packetdecoder: " << packet->dataLength << std::endl; 58 58 switch( id ) { 59 59 case ACK: … … 93 93 94 94 95 std::cout<< "got ack id: " << a->id << std::endl;95 COUT(5) << "got ack id: " << a->id << std::endl; 96 96 processAck( a, clientId ); //debug info 97 97 … … 144 144 void PacketDecoder::gstate( ENetPacket* packet ) 145 145 { 146 GameStateCompressed* currentState = new GameStateCompressed; 146 GameStateCompressed* currentState = NULL; 147 currentState = new GameStateCompressed; 148 if(currentState == NULL){ 149 COUT(3) << "could not generate new GameStateCompressed" << std::endl; 150 return; 151 } 147 152 //since it's not alowed to use void* for pointer arithmetic 148 unsigned char* data = (unsigned char *)packet->data;153 unsigned char* data = (unsigned char *)(packet->data); 149 154 //copy the GameStateCompressed id into the struct, which is located at second place data+sizeof( int ) 150 155 //memcpy( (void*)&(currentState->id), (const void*)(data+sizeof( int )), sizeof( int ) ); 151 currentState->id = (int)*(data+sizeof(int)); 152 std::cout << "id: " << currentState->id << std::endl; 156 //currentState->id = *((int *)packet->data+sizeof(int)); 157 memcpy( (void*)&(currentState->id), (const void*)(packet->data+1*sizeof( int )), sizeof( int) ); 158 COUT(5) << "decoder: received gs id: " << currentState->id << std::endl; 159 // std::cout << "id: " << currentState->id << std::endl; 153 160 //copy the size of the GameStateCompressed compressed data into the new GameStateCompressed struct, located at 3th 154 161 //position of the data stream, data+2*sizeof( int ) 155 memcpy( (void*)&(currentState->compsize), (const void*)( data+2*sizeof( int )), sizeof( int) );162 memcpy( (void*)&(currentState->compsize), (const void*)(packet->data+2*sizeof( int )), sizeof( int) ); 156 163 //currentState->compsize = (int)*(data+2*sizeof(int)); 157 std::cout << "compsize: " << currentState->compsize << std::endl;164 // std::cout << "compsize: " << currentState->compsize << std::endl; 158 165 //size of uncompressed data 159 memcpy( (void*)&(currentState->normsize), (const void*)( data+3*sizeof( int )), sizeof( int ) );166 memcpy( (void*)&(currentState->normsize), (const void*)(packet->data+3*sizeof( int )), sizeof( int ) ); 160 167 //currentState->normsize = (int)*(data+3*sizeof(int)); 161 std::cout << "normsize. " << currentState->normsize << std::endl;168 // std::cout << "normsize. " << currentState->normsize << std::endl; 162 169 //since the packetgenerator was changed, due to a new parameter, change this function too 163 memcpy( (void*)&(currentState->diffed), (const void*)( data+4*sizeof(int)), sizeof(bool));170 memcpy( (void*)&(currentState->diffed), (const void*)(packet->data+4*sizeof(int)), sizeof(bool)); 164 171 //currentState->diffed = (bool)*(data+4*sizeof(int)); 165 std::cout << "diffed: " << currentState->diffed << std::endl;172 // std::cout << "diffed: " << currentState->diffed << std::endl; 166 173 //since data is not allocated, because it's just a pointer, allocate it with size of gamestatedatastream 174 if(currentState->compsize==0) 175 COUT(2) << "compsize is 0" << std::endl; 167 176 currentState->data = (unsigned char*)(malloc( currentState->compsize )); 168 177 if(currentState->data==NULL) 169 std::cout << "memory leak" << std::endl;178 COUT(2) << "Gamestatepacket-decoder: memory leak" << std::endl; 170 179 //copy the GameStateCompressed data 171 180 //std::cout << "packet size (enet): " << packet->dataLength << std::endl; 172 181 //std::cout << "totallen: " << 4*sizeof(int)+sizeof(bool)+currentState->compsize << std::endl; 173 memcpy( (void*)(currentState->data), (const void*)(data+4*sizeof( int ) + sizeof(bool)), currentState->compsize ); 174 175 //clean memory 176 enet_packet_destroy( packet ); 177 //run processGameStateCompressed 178 //TODO: not yet implemented! 182 memcpy( (void*)(currentState->data), (const void*)(packet->data+4*sizeof( int ) + sizeof(bool)), currentState->compsize ); 183 184 //clean memory 185 enet_packet_destroy( packet ); 179 186 processGamestate(currentState); 180 187 } … … 189 196 void *data = (void *)cid->message; 190 197 memcpy(data, (const void*)(packet->data+3*sizeof(int)), cid->length); 191 std::cout<< "classid: " << cid->clid << ", name: " << cid->message << std::endl;198 COUT(4) << "classid: " << cid->clid << ", name: " << cid->message << std::endl; 192 199 enet_packet_destroy( packet ); 193 200 processClassid(cid); … … 223 230 void PacketDecoder::printAck( ack* data ) 224 231 { 225 cout << "data id: " << data->id <<endl;226 cout << "data: " << data->a <<endl;232 COUT(5) << "data id: " << data->id << std::endl; 233 COUT(5) << "data: " << data->a << std::endl; 227 234 } 228 235 229 236 void PacketDecoder::printMouse( mouse* data ) 230 237 { 231 cout << "data id: " << data->id <<endl;232 cout << "data: " << data->x << " " << data->y <<endl;238 COUT(5) << "data id: " << data->id << std::endl; 239 COUT(5) << "data: " << data->x << " " << data->y << std::endl; 233 240 } 234 241 235 242 void PacketDecoder::printKey( keyboard* data ) 236 243 { 237 cout << "data id: " << data->id <<endl;238 cout << "data: " << (char)data->press <<endl;244 COUT(5) << "data id: " << data->id << std::endl; 245 COUT(5) << "data: " << (char)data->press << std::endl; 239 246 } 240 247 … … 242 249 { 243 250 if(clientId!=CLIENTID_CLIENT) 244 cout << "client: " << clientId <<endl;245 cout << "data id: " << data->id <<endl;246 cout << "data: " << data->message <<endl;251 COUT(5) << "client: " << clientId << std::endl; 252 COUT(5) << "data id: " << data->id << std::endl; 253 COUT(5) << "data: " << data->message << std::endl; 247 254 } 248 255 249 256 void PacketDecoder::printGamestate( GameStateCompressed* data ) 250 257 { 251 cout << "id of GameStateCompressed: " << data->id <<endl;252 cout << "size of GameStateCompressed: " << data->compsize <<endl;258 COUT(5) << "id of GameStateCompressed: " << data->id << std::endl; 259 COUT(5) << "size of GameStateCompressed: " << data->compsize << std::endl; 253 260 } 254 261 255 262 void PacketDecoder::printClassid( classid *cid) 256 263 { 257 cout << "id of classid: " << cid->id <<endl;258 cout << "size of classid: " << cid->length <<endl;259 cout << "ID of classid: " << cid->clid <<endl;260 cout << "data of classid: " << cid->message <<endl;264 COUT(5) << "id of classid: " << cid->id << std::endl; 265 COUT(5) << "size of classid: " << cid->length << std::endl; 266 COUT(5) << "ID of classid: " << cid->clid << std::endl; 267 COUT(5) << "data of classid: " << cid->message << std::endl; 261 268 } 262 269
Note: See TracChangeset
for help on using the changeset viewer.