Changeset 223 for code/branches/network
- Timestamp:
- Nov 20, 2007, 8:33:15 PM (17 years ago)
- Location:
- code/branches/network/src/network
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network/src/network/PacketDecoder.cc
r203 r223 1 /* 2 * Class contains functions to determine and decode incomming packages 3 * 4 * Autor: Dumeni Manatschal 5 * 6 */ 7 8 1 9 #include "enet/enet.h" 2 10 #include "PacketManager.h" … … 8 16 PacketDecoder::PacketDecoder(){} 9 17 18 //call this function out of an instance of PacketDecoder 19 //it will determine the type id and call the right decode function 10 20 bool PacketDecoder::elaborate( ENetPacket* packet, int clientId ) 11 21 { … … 33 43 return false; 34 44 } 45 46 //following are the decode functions for the data of the packets 35 47 36 48 void PacketDecoder::acknowledgement( ENetPacket* packet ) … … 64 76 printChat( chatting ); 65 77 } 66 /* 67 void PacketDecoder::printPeer( ENetPeer* peer ) 68 { 69 cout << "number of chanels: " << peer->channelCount << endl; 70 cout << "incomming bandwidth: " << peer->incomingBandwidth << endl; 71 cout << "outgoing bandwidth: " << peer->outgoingBandwidth << endl; 72 cout << "peer id: " << peer->sessionID << endl; 73 cout << "outgoing peer id: " << peer->outgoingPeerID << endl; 74 cout << "incomming peer id: " << peer->incomingPeerID << endl; 75 cout << "state of peer: " << peer->state << endl; 76 } 77 */ 78 79 //these are some print functions for test stuff 80 78 81 void PacketDecoder::printAck( ack* data ) 79 82 { -
code/branches/network/src/network/PacketGenerator.cc
r199 r223 1 /* 2 *Class generates packets that can be send by enet 3 * 4 * Autor: Dumeni Manatschal 5 * 6 */ 7 1 8 #include "PacketManager.h" 2 9 #include "enet/enet.h" … … 11 18 PacketGenerator::PacketGenerator() {} 12 19 20 //following functions create a packet in form of bytestream 21 13 22 ENetPacket* PacketGenerator::acknowledgement( int state, int reliable ) 14 23 { … … 22 31 return packet; 23 32 } 24 33 /*### mouseupdates */ 25 34 ENetPacket* PacketGenerator::mousem( double x, double y, int reliable ) 26 35 { … … 35 44 return packet; 36 45 } 37 46 /*### keystrikes updates */ 38 47 ENetPacket* PacketGenerator::keystrike( char press, int reliable ) 39 48 { … … 47 56 return packet; 48 57 } 49 58 /*### chat messages packet */ 50 59 ENetPacket* PacketGenerator::chatMessage( const char* message, int reliable ) 51 60 { 52 61 int* trans = new int[sizeof(int) + strlen(message) + 1]; 53 62 *trans = CHAT; 63 //be carefull here, don't forget to allocate the space before using it ;-) 54 64 memcpy( &trans[1], (const void*)message, strlen( message ) + 1); 55 65 ENetPacket *packet = enet_packet_create( trans , sizeof( int ) + strlen( message ) + 1, reliable ); -
code/branches/network/src/network/PacketManager.h
r203 r223 4 4 #include <enet/enet.h> 5 5 6 //enum netowk generaly used to set the type ID of a packet 6 7 namespace network 7 8 { … … 13 14 }; 14 15 16 /* 17 * class to generate packets 18 * 19 * Autor: Dumeni Manatschal 20 * 21 */ 15 22 class PacketGenerator 16 23 { 17 24 public: 18 25 PacketGenerator(); 26 //call one of this functions out of an instance of PacketGenerator to create a packet 19 27 ENetPacket* acknowledgement( int state, int reliable = ENET_PACKET_FLAG_RELIABLE ); 20 28 ENetPacket* mousem( double x, double y, int reliable = ENET_PACKET_FLAG_RELIABLE ); … … 22 30 ENetPacket* chatMessage( const char* message, int reliable = ENET_PACKET_FLAG_RELIABLE ); 23 31 private: 32 //used to set the bytes in the right order 24 33 struct ack { 25 34 int id; … … 39 48 }; 40 49 50 /* 51 * class used to decode incoming packets 52 * 53 * Autor: Dumeni Manatschal 54 * 55 */ 41 56 class PacketDecoder 42 57 { 43 58 public: 44 59 PacketDecoder(); 60 //call this function to decode, it calls the right decoding function below 45 61 bool elaborate( ENetPacket* packet, int clientId ); 46 62 private: … … 60 76 char press; 61 77 }; 78 //only in this class, not PacketGenerator, used as pattern to put incoming 79 //bytes inside 62 80 struct chat { 63 81 int id;
Note: See TracChangeset
for help on using the changeset viewer.