Changeset 632
- Timestamp:
- Dec 19, 2007, 12:28:42 AM (17 years ago)
- Location:
- code/branches/FICN/src/network
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/FICN/src/network/Client.cc
r624 r632 183 183 while(!(client_connection.queueEmpty())){ 184 184 packet = client_connection.getPacket(); 185 //std::cout << "tick packet size " << packet->dataLength << std::endl; 185 186 elaborate(packet, 0); // ================= i guess we got to change this .... (client_ID is always same = server) 186 187 } -
code/branches/FICN/src/network/ClientConnection.cc
r620 r632 75 75 76 76 ENetPacket *ClientConnection::getPacket(ENetAddress &address){ 77 if(!buffer.isEmpty()) 77 if(!buffer.isEmpty()) { 78 //std::cout << "###BUFFER IS NOT EMPTY###" << std::endl; 78 79 return buffer.pop(address); 79 else 80 } 81 else{ 80 82 return NULL; 83 } 81 84 } 82 85 -
code/branches/FICN/src/network/GameStateClient.cc
r624 r632 153 153 int retval; 154 154 uLongf length=normsize; 155 //std::cout << "gamestateclient" << std::endl; 156 //std::cout << "normsize " << a.normsize << " compsize " << a.compsize << " " << bufsize << std::endl; 155 157 retval = uncompress( dest, &length, a.data, (uLong)compsize ); 156 158 //std::cout << "length " << length << std::endl; 157 159 switch ( retval ) { 158 160 case Z_OK: std::cout << "successfully decompressed" << std::endl; break; … … 167 169 gamestate.data = dest; 168 170 gamestate.diffed = a.diffed; 169 171 170 172 return gamestate; 171 173 } -
code/branches/FICN/src/network/GameStateManager.cc
r630 r632 109 109 //get size of the synchronisable 110 110 tempsize=it->getSize(); 111 //std::cout << "size of temp gamestate: " << tempsize << std::endl; 111 112 //COUT(2) << "size of synchronisable: " << tempsize << std::endl; 112 113 // add place for data and 3 ints (length,classid,objectid) 113 114 totalsize+=tempsize+3*sizeof(int); 115 //std::cout << "totalsize: " << totalsize << std::endl; 114 116 // allocate additional space 115 117 if(totalsize+tempsize>memsize){ … … 188 190 unsigned char* dest = (unsigned char*)malloc( buffer ); 189 191 int retval; 192 //std::cout << "before ziped " << buffer << std::endl; 190 193 retval = compress( dest, &buffer, a->data, (uLong)size ); 194 //std::cout << "after ziped " << buffer << std::endl; 191 195 192 196 switch ( retval ) { … … 199 203 GameStateCompressed compressedGamestate; 200 204 compressedGamestate.compsize = buffer; 205 //std::cout << "compressedGamestate.compsize = buffer; " << buffer << std::endl; 201 206 compressedGamestate.normsize = size; 207 //std::cout << "compressedGamestate.normsize = size; " << size << std::endl; 202 208 compressedGamestate.id = a->id; 203 209 compressedGamestate.data = dest; -
code/branches/FICN/src/network/PacketBuffer.cc
r514 r632 50 50 bool PacketBuffer::push(ENetEvent *ev){ 51 51 boost::mutex::scoped_lock lock(networkPacketBufferMutex); 52 //std::cout << "event size inside packetbuffer " << ev->packet->dataLength << std::endl; 52 53 // if(closed) 53 54 // return false; … … 75 76 ENetPacket *PacketBuffer::pop(){ 76 77 boost::mutex::scoped_lock lock(networkPacketBufferMutex); 78 //std::cout << "packetbuffer pop" << std::endl; 77 79 if(first!=NULL /*&& !closed*/){ 78 80 QueueItem *temp = first; … … 82 84 first = first->next; 83 85 delete temp; 86 //std::cout << "pop size of packet " << pck->dataLength << std::endl; 84 87 return pck; 85 88 } else{ 89 //std::cout << "nothing to return" << std::endl; 86 90 return NULL; 87 91 } … … 90 94 ENetPacket *PacketBuffer::pop(ENetAddress &address){ 91 95 boost::mutex::scoped_lock lock(networkPacketBufferMutex); 96 //std::cout << "packetbuffer pop(address)" << std::endl; 92 97 if(first!=NULL /*&& !closed*/){ 93 98 QueueItem *temp = first; … … 98 103 first = first->next; 99 104 delete temp; 105 //std::cout << "pop(address) size of packet " << pck->dataLength << std::endl; 100 106 return pck; 101 107 } else{ -
code/branches/FICN/src/network/PacketDecoder.cc
r624 r632 52 52 cout << "clientId: " << client << endl; //control cout, not important, just debugging info 53 53 int id = (int)*packet->data; //the first 4 bytes are always the enet packet id 54 std::cout << "packet id: " << id << std::endl; 55 std::cout << "packet size inside packetdecoder: " << packet->dataLength << std::endl; 54 56 switch( id ) { 55 57 case ACK: … … 145 147 unsigned char* data = (unsigned char*)packet->data; 146 148 //copy the GameStateCompressed id into the struct, which is located at second place data+sizeof( int ) 147 //memcpy( (void*)&(currentState->id), (const void*)(data+sizeof( int )), sizeof( int ) );148 currentState->id = (int)*(data+sizeof(int));149 std::cout << "id: " << currentState->id << std::endl;149 //memcpy( (void*)&(currentState->id), (const void*)(data+sizeof( int )), sizeof( int ) ); 150 currentState->id = (int)*(data+sizeof(int)); 151 std::cout << "id: " << currentState->id << std::endl; 150 152 //copy the size of the GameStateCompressed compressed data into the new GameStateCompressed struct, located at 3th 151 153 //position of the data stream, data+2*sizeof( int ) 152 //memcpy( (void*)&(currentState->compsize), (const void*)(data+2*sizeof( int )), sizeof( int) );153 currentState->compsize = (int)*(data+2*sizeof(int));154 std::cout << "compsize: " << currentState->compsize << std::endl;154 memcpy( (void*)&(currentState->compsize), (const void*)(data+2*sizeof( int )), sizeof( int) ); 155 //currentState->compsize = (int)*(data+2*sizeof(int)); 156 std::cout << "compsize: " << currentState->compsize << std::endl; 155 157 //size of uncompressed data 156 //memcpy( (void*)&(currentState->normsize), (const void*)(data+3*sizeof( int )), sizeof( int ) );157 currentState->normsize = (int)*(data+3*sizeof(int));158 std::cout << "normsize. " << currentState->normsize << std::endl;158 memcpy( (void*)&(currentState->normsize), (const void*)(data+3*sizeof( int )), sizeof( int ) ); 159 //currentState->normsize = (int)*(data+3*sizeof(int)); 160 std::cout << "normsize. " << currentState->normsize << std::endl; 159 161 //since the packetgenerator was changed, due to a new parameter, change this function too 160 //memcpy( (void*)&(currentState->diffed), (const void*)(data+4*sizeof(int)), sizeof(bool));161 currentState->diffed = (bool)*(data+4*sizeof(int));162 std::cout << "diffed: " << currentState->diffed << std::endl;162 memcpy( (void*)&(currentState->diffed), (const void*)(data+4*sizeof(int)), sizeof(bool)); 163 //currentState->diffed = (bool)*(data+4*sizeof(int)); 164 std::cout << "diffed: " << currentState->diffed << std::endl; 163 165 //since data is not allocated, because it's just a pointer, allocate it with size of gamestatedatastream 164 166 currentState->data = (unsigned char*)(malloc( currentState->compsize )); 165 if(currentState->data==NULL)166 std::cout << "memory leak" << std::endl;167 if(currentState->data==NULL) 168 std::cout << "memory leak" << std::endl; 167 169 //copy the GameStateCompressed data 168 //std::cout << "packet size (enet): " << packet->dataLength << std::endl;169 //std::cout << "totallen: " << 4*sizeof(int)+sizeof(bool)+currentState->compsize << std::endl;170 //std::cout << "packet size (enet): " << packet->dataLength << std::endl; 171 //std::cout << "totallen: " << 4*sizeof(int)+sizeof(bool)+currentState->compsize << std::endl; 170 172 memcpy( (void*)(currentState->data), (const void*)(data+4*sizeof( int ) + sizeof(bool)), currentState->compsize ); 171 173 172 174 //clean memory 173 175 enet_packet_destroy( packet ); 174 //run processGameStateCompressed175 //TODO: not yet implemented!176 processGamestate(currentState);176 //run processGameStateCompressed 177 //TODO: not yet implemented! 178 processGamestate(currentState); 177 179 } 178 180 -
code/branches/FICN/src/network/PacketGenerator.cc
r624 r632 98 98 ENetPacket* PacketGenerator::gstate( GameStateCompressed* states, int reliable ) 99 99 { 100 int gid = GAMESTATE; //first assign the correct enet id 101 int totalLen = 4*sizeof( int ) + sizeof(bool) + states->compsize; //calculate the total size of the datastream memory 102 unsigned char *data = (unsigned char*)malloc( totalLen ); //allocate the memory for datastream 100 //std::cout << "packetgenerator" << std::endl; 101 //std::cout << "states->normsize " << states->normsize << std::endl; 102 //std::cout << "states->compsize " << states->compsize << std::endl; 103 int gid = GAMESTATE; //first assign the correct enet id 104 int totalLen = 4*sizeof( int ) + sizeof(bool) + states->compsize; //calculate the total size of the datastream memory 105 //std::cout << "totalLen " << totalLen << std::endl; 106 unsigned char *data = (unsigned char*)malloc( totalLen ); //allocate the memory for datastream 103 107 memcpy( (void*)(data), (const void*)&gid, sizeof( int ) ); //this is the enet id 104 108 memcpy( (void*)(data+sizeof(int)), (const void*)&(states->id), sizeof(int) ); //the GameStateCompressed id … … 107 111 memcpy( (void*)(data+4*sizeof(int)), (const void*)&(states->diffed), sizeof(bool)); 108 112 /*(int)*(data) = gid; 109 113 (int)*(data+sizeof(int)) = states->id; 110 114 //this is the compressed size of the GameStateCompressed data, place at 3th position of the enet datastream 111 115 (int)*(data+2*sizeof(int)) = states->compsize; 112 116 //this is the uncompressed size of GameStateCompressed data 113 117 (int)*(data+3*sizeof(int)) = states->normsize; 114 118 //since there is a new parameter inside GameStateCompressed, change this function to create packet 115 119 (bool)*(data+4*sizeof(int)) = states->diffed;*/ 116 117 118 119 120 //place the GameStateCompressed data at the end of the enet datastream 121 memcpy( (void*)(data+4*sizeof( int ) + sizeof(bool)), (const void*)states->data, states->compsize ); 122 //create an enet packet with the generated bytestream 123 ENetPacket *packet = enet_packet_create( data , totalLen, reliable ); 120 124 //delete data; 121 125 return packet; 122 126 } 123 127 -
code/branches/FICN/src/network/Server.cc
r624 r632 86 86 bool Server::sendMSG(const char *msg){ 87 87 ENetPacket *packet = packet_gen.chatMessage(msg); 88 std::cout <<"adding P PPPPackets" << std::endl;88 std::cout <<"adding Packets" << std::endl; 89 89 connection->addPacketAll(packet); 90 90 //std::cout <<"added packets" << std::endl; 91 91 if (connection->sendPackets()){ 92 std::cout << "S SSSSucessfully" << std::endl;92 std::cout << "Sucessfully" << std::endl; 93 93 return true; 94 94 } -
code/branches/FICN/src/network/dummyclient3.cc
r601 r632 28 28 std::cout << "connection established" << std::endl; 29 29 else std::cout << "problems establishing connection" << std::endl; 30 30 char message[10000]; 31 char signs[] = "abcdefghijklmnopqrstuvwxy"; 31 32 while (true) { 32 33 client.tick(0); 33 std::cout << "your message: "; 34 std::getline( std::cin, str ); 35 client.sendChat( str ); 36 std::cout << "sent message" << std::endl; 34 35 std::cout << "your message2: "; 36 for ( int i=0; i<9999; i++ ) { 37 message[i] = signs[0]; 38 } 39 message[9999] = 'z'; 40 std::string str( message ); 41 client.sendChat( str ); 42 std::cout << str << std::endl; 43 std::cin.get(); std::cin.get(); 37 44 } 38 45
Note: See TracChangeset
for help on using the changeset viewer.