Changeset 400
- Timestamp:
- Dec 5, 2007, 3:46:07 PM (17 years ago)
- Location:
- code/branches/FICN/src/network
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/FICN/src/network/Client.cc
r369 r400 154 154 } 155 155 156 void Client::processClassid(classid *clid){ 157 158 159 160 } 161 156 162 } -
code/branches/FICN/src/network/Client.h
r369 r400 19 19 #include "PacketManager.h" 20 20 #include "GameStateManager.h" 21 #include "orxonox/core/IdentifierIncludes.h" 21 22 22 23 … … 56 57 // implement data processing functions of PacketDecoder 57 58 void processGamestate( GameState *data); 59 void processClassid(classid *clid); 60 58 61 }; 59 62 -
code/branches/FICN/src/network/ConnectionManager.cc
r381 r400 198 198 199 199 bool ConnectionManager::addClient(ENetEvent *event){ 200 int id=clientVector.size(); 200 201 clientVector.push_back((event->peer->address)); 201 clientMap[event->peer->address]= clientVector.size()-1;202 clientMap[event->peer->address]=id; 202 203 peerMap[event->peer->address]=*(event->peer); 204 syncClassid(id); 203 205 return true; 204 206 } … … 216 218 } 217 219 220 void ConnectionManager::syncClassid(int clientID){ 221 int i=0; 222 std::string classname; 223 bool abort=false; 224 orxonox::Identifier *id; 225 while(!abort){ 226 id = orxonox::ID(i); 227 if(id == NULL) 228 abort=true; 229 else{ 230 classname = id->getName(); 231 addPacket(packet_gen.clid( i, classname ),clientID); 232 } 233 } 234 sendPackets(); 235 } 236 218 237 } -
code/branches/FICN/src/network/ConnectionManager.h
r381 r400 25 25 #include "ConnectionManager.h" 26 26 #include "PacketBuffer.h" 27 #include "PacketManager.h" 28 #include "orxonox/core/IdentifierIncludes.h" 27 29 28 30 namespace std{ … … 67 69 int getClientID(ENetPeer peer); 68 70 int getClientID(ENetAddress address); 71 void syncClassid(int clientID); 69 72 ENetPeer getClientPeer(int clientID); 70 73 PacketBuffer buffer; 74 PacketGenerator packet_gen; 71 75 72 76 ENetHost *server; -
code/branches/FICN/src/network/PacketDecoder.cc
r374 r400 44 44 return true; 45 45 break; 46 case CLASSID: 47 clid(packet); 48 return true; 49 break; 46 50 } 47 51 return false; … … 126 130 } 127 131 132 void PacketDecoder::clid( ENetPacket *packet) 133 { 134 classid* cid = new classid; 135 cid->length = ((classid*)(packet->data))->length; 136 cid->id = ((classid *)(packet->data))->id; 137 cid->classid = ((classid *)(packet->data))->classid; 138 cid->message = (const char *)malloc(cid->length); 139 enet_packet_destroy( packet ); 140 processClassid(&cid); 141 } 142 143 128 144 // now the data processing functions: 129 145 … … 131 147 printChat(data); 132 148 } 149 150 void PacketDecoder::processClassid( classid *cid){ 151 printClassid(cid); 152 return; 153 } 154 155 133 156 134 157 //these are some print functions for test stuff … … 163 186 cout << "size of gamestate: " << data->size << endl; 164 187 } 188 189 void PacketDecoder::printClassid( classid *cid) 190 { 191 cout << "id of classid: " << cid->id << endl; 192 cout << "size of classid: " << cid->length << endl; 193 cout << "ID of classid: " << cid->classid <<endl; 194 cout << "data of classid: " << cid->message <<endl; 195 } -
code/branches/FICN/src/network/PacketGenerator.cc
r341 r400 86 86 return packet; 87 87 } 88 89 ENetPacket* PacketGenerator::clid( int classid, std::string classname, int reliable ){ 90 unsigned char* data = (unsigned char *)malloc(3*sizeof(int)+classname.length()+1); 91 *(int *)data = CLASSID; 92 *((int *)data+1) = classname.length()+1; 93 *((int *)data+2) = classid; 94 memcpy( (void *)(data+3*sizeof(int)), classname.c_str(), classname.length()+1); 95 ENetPacket *packet = enet_packet_create( data , 3*sizeof(int)+classname.length()+1, reliable ); 96 return packet; 97 } 98 99 -
code/branches/FICN/src/network/PacketManager.h
r374 r400 2 2 #define PACKETMANAGER_H_ 3 3 4 #include <string> 4 5 #include <enet/enet.h> 5 6 #include "GameStateManager.h" … … 13 14 KEYBOARD, 14 15 CHAT, 15 GAMESTATE 16 GAMESTATE , 17 CLASSID 16 18 }; 17 19 … … 32 34 ENetPacket* chatMessage( const char* message, int reliable = ENET_PACKET_FLAG_RELIABLE ); 33 35 ENetPacket* gstate( GameState* states, int reliable = ENET_PACKET_FLAG_RELIABLE ); 36 ENetPacket* clid( int classid, std::string classname, int reliable = ENET_PACKET_FLAG_RELIABLE ); 34 37 private: 35 38 //used to set the bytes in the right order … … 85 88 const char* message; 86 89 }; 90 91 struct classid{ 92 int id; 93 int length; 94 int classid; 95 const char *message; 96 }; 87 97 88 98 void acknowledgement( ENetPacket* packet ); … … 91 101 void chatMessage( ENetPacket* packet ); 92 102 void gstate( ENetPacket* packet ); 103 void clid( ENetPacket *packet); 93 104 94 105 //process data … … 96 107 //virtual void processGamestate(GameState *state); 97 108 virtual void processChat( chat *data); 109 virtual void processClassid( classid *cid); 98 110 //virtual void processAck( ack *data); 99 111 … … 104 116 void printChat( chat* data ); 105 117 void printGamestate( GameState* data ); 118 void printClassid( classid *cid); 106 119 }; 107 120 } -
code/branches/FICN/src/network/Server.cc
r381 r400 112 112 } 113 113 114 114 115 }
Note: See TracChangeset
for help on using the changeset viewer.