Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 20, 2007, 8:33:15 PM (17 years ago)
Author:
dumenim
Message:

dumenim added some comment to the code

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
    19#include "enet/enet.h"
    210#include "PacketManager.h"
     
    816PacketDecoder::PacketDecoder(){}
    917
     18//call this function out of an instance of PacketDecoder
     19//it will determine the type id and call the right decode function
    1020bool PacketDecoder::elaborate( ENetPacket* packet, int clientId )
    1121{
     
    3343        return false;
    3444}
     45
     46//following are the decode functions for the data of the packets
    3547
    3648void PacketDecoder::acknowledgement( ENetPacket* packet )
     
    6476        printChat( chatting );
    6577}
    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
    7881void PacketDecoder::printAck( ack* data )
    7982{
  • 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
    18#include "PacketManager.h"
    29#include "enet/enet.h"
     
    1118PacketGenerator::PacketGenerator() {}
    1219
     20//following functions create a packet in form of bytestream
     21
    1322ENetPacket* PacketGenerator::acknowledgement( int state, int reliable )
    1423{
     
    2231        return packet;
    2332}
    24 
     33/*### mouseupdates */
    2534ENetPacket* PacketGenerator::mousem( double x, double y, int reliable )
    2635{
     
    3544        return packet;
    3645}
    37 
     46/*### keystrikes updates */
    3847ENetPacket* PacketGenerator::keystrike( char press, int reliable )
    3948{
     
    4756        return packet;
    4857}
    49 
     58/*### chat messages packet */
    5059ENetPacket* PacketGenerator::chatMessage( const char* message, int reliable )
    5160{
    5261        int* trans = new int[sizeof(int) + strlen(message) + 1];
    5362        *trans = CHAT;
     63        //be carefull here, don't forget to allocate the space before using it ;-)
    5464        memcpy( &trans[1], (const void*)message, strlen( message ) + 1);
    5565        ENetPacket *packet = enet_packet_create( trans , sizeof( int ) + strlen( message ) + 1, reliable );
  • code/branches/network/src/network/PacketManager.h

    r203 r223  
    44#include <enet/enet.h>
    55
     6//enum netowk generaly used to set the type ID of a packet
    67namespace network
    78{
     
    1314};
    1415
     16/*
     17 * class to generate packets
     18 *
     19 * Autor: Dumeni Manatschal
     20 *
     21*/
    1522class PacketGenerator
    1623{
    1724public:
    1825        PacketGenerator();
     26        //call one of this functions out of an instance of PacketGenerator to create a packet
    1927        ENetPacket* acknowledgement( int state, int reliable = ENET_PACKET_FLAG_RELIABLE );
    2028        ENetPacket* mousem( double x, double y, int reliable = ENET_PACKET_FLAG_RELIABLE );
     
    2230        ENetPacket* chatMessage( const char* message, int reliable = ENET_PACKET_FLAG_RELIABLE );
    2331private:
     32        //used to set the bytes in the right order
    2433        struct ack {
    2534                int id;
     
    3948};
    4049
     50/*
     51 * class used to decode incoming packets
     52 *
     53 * Autor: Dumeni Manatschal
     54 *
     55*/
    4156class PacketDecoder
    4257{
    4358public:
    4459        PacketDecoder();
     60        //call this function to decode, it calls the right decoding function below
    4561        bool elaborate( ENetPacket* packet, int clientId );
    4662private:
     
    6076                char press;
    6177        };
     78        //only in this class, not PacketGenerator, used as pattern to put incoming
     79        //bytes inside
    6280        struct chat {
    6381                int id;
Note: See TracChangeset for help on using the changeset viewer.