Changeset 1232 for code/branches/network3/src/network/PacketDecoder.cc
- Timestamp:
- May 5, 2008, 1:19:22 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network3/src/network/PacketDecoder.cc
r1199 r1232 53 53 bool PacketDecoder::elaborate( ENetPacket* packet, int clientId ) 54 54 { 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 57 56 int id = (int)*packet->data; //the first 4 bytes are always the enet packet id 58 57 COUT(5) << "PacketDecoder: packet id: " << id << std::endl; … … 64 63 } 65 64 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 ); 90 89 } 91 90 return false; … … 105 104 //clean memory 106 105 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; 107 113 } 108 114 … … 171 177 //since the packetgenerator was changed, due to a new parameter, change this function too 172 178 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)); 173 180 //since data is not allocated, because it's just a pointer, allocate it with size of gamestatedatastream 174 181 if(currentState->compsize==0) … … 178 185 COUT(2) << "PacketDecoder: Gamestatepacket-decoder: memory leak" << std::endl; 179 186 //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 ); 181 188 182 189 //clean memory … … 198 205 processClassid(cid); 199 206 } 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 } 200 225 201 226 … … 224 249 return; 225 250 } 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 } 227 260 228 261 //these are some print functions for test stuff
Note: See TracChangeset
for help on using the changeset viewer.