Changeset 1232 for code/branches/network3/src/network/PacketGenerator.cc
- Timestamp:
- May 5, 2008, 1:19:22 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network3/src/network/PacketGenerator.cc
r1180 r1232 61 61 return packet; 62 62 } 63 64 ENetPacket* command( int dataLength, void *data, int reliable = ENET_PACKET_FLAG_RELIABLE ) 65 { 66 void *stream = new char[dataLength + 2*sizeof(int)]; 67 if(!stream) 68 return NULL; 69 packet_id a = COMMAND; 70 memcpy(stream, (void*)&a, sizeof(int)); 71 memcpy((unsigned char *)stream+sizeof(int), (void*)&dataLength, sizeof(int)); 72 memcpy((unsigned char *)stream+2*sizeof(int), data, dataLength); 73 return enet_packet_create(stream, dataLength+2*sizeof(int), reliable); 74 } 63 75 64 76 /*### mouseupdates */ … … 108 120 //std::cout << "states->compsize " << states->compsize << std::endl; 109 121 int gid = GAMESTATE; //first assign the correct enet id 110 int totalLen = 5*sizeof( int ) + sizeof(bool) + states->compsize; //calculate the total size of the datastream memory122 int totalLen = 5*sizeof( int ) + 2*sizeof(bool) + states->compsize; //calculate the total size of the datastream memory 111 123 //std::cout << "totalLen " << totalLen << std::endl; 112 unsigned char *data = (unsigned char*)malloc( totalLen ); //allocate the memory for datastream 124 //unsigned char *data = (unsigned char*)malloc( totalLen ); //allocate the memory for datastream 125 unsigned char *data = new unsigned char[totalLen]; 113 126 memcpy( (void*)(data), (const void*)&gid, sizeof( int ) ); //this is the enet id 114 127 memcpy( (void*)(data+sizeof(int)), (const void*)&(states->id), sizeof(int) ); //the GameStateCompressed id … … 118 131 memcpy( (void*)(data+5*sizeof(int)), (const void*)&(states->diffed), sizeof(bool)); 119 132 //place the GameStateCompressed data at the end of the enet datastream 120 memcpy( (void*)(data+5*sizeof( int ) + sizeof(bool)), (const void*)states->data, states->compsize ); 133 memcpy( (void*)(data+5*sizeof( int ) + sizeof(bool)), (const void*)&(states->complete), sizeof(bool) ); 134 memcpy( (void*)(data+5*sizeof( int ) + 2*sizeof(bool)), (const void*)states->data, states->compsize ); 121 135 //create an enet packet with the generated bytestream 122 136 COUT(4) << "PacketGenerator generating totalLen " << totalLen << std::endl; … … 128 142 ENetPacket* PacketGenerator::clid( int classid, std::string classname, int reliable ) 129 143 { 130 unsigned char* data = (unsigned char *)malloc(3*sizeof(int)+classname.length()+1); 144 //unsigned char* data = (unsigned char *)malloc(3*sizeof(int)+classname.length()+1); 145 unsigned char *data = new unsigned char[3*sizeof(int)+classname.length()+1]; 131 146 std::cout << "PacketGenerator: classid: " << classid << ", name: " << classname << std::endl; 132 147 *(int *)data = CLASSID; … … 137 152 return packet; 138 153 } 154 155 ENetPacket* PacketGenerator::generateWelcome( int clientID,int shipID, bool allowed , int reliable ){ 156 welcome *wc = new welcome; 157 wc->id = WELCOME; 158 wc->clientID = clientID; 159 wc->shipID = shipID; 160 wc->allowed = true; 161 ENetPacket *packet = enet_packet_create( wc, sizeof(welcome), reliable); 162 return packet; 163 } 164 165 ENetPacket* PacketGenerator::generateConnectRequest( int reliable ){ 166 connectRequest *con = new connectRequest; 167 con->id=CONNECT; 168 return enet_packet_create( con, sizeof(connectRequest), reliable); 169 } 139 170 140 171 }
Note: See TracChangeset
for help on using the changeset viewer.