Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 400


Ignore:
Timestamp:
Dec 5, 2007, 3:46:07 PM (16 years ago)
Author:
scheusso
Message:

CLient, Server

Location:
code/branches/FICN/src/network
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • code/branches/FICN/src/network/Client.cc

    r369 r400  
    154154  }
    155155 
     156  void Client::processClassid(classid *clid){
     157   
     158   
     159   
     160  }
     161 
    156162}
  • code/branches/FICN/src/network/Client.h

    r369 r400  
    1919#include "PacketManager.h"
    2020#include "GameStateManager.h"
     21#include "orxonox/core/IdentifierIncludes.h"
    2122
    2223
     
    5657  // implement data processing functions of PacketDecoder
    5758  void processGamestate( GameState *data);
     59  void processClassid(classid *clid);
     60
    5861};
    5962
  • code/branches/FICN/src/network/ConnectionManager.cc

    r381 r400  
    198198
    199199  bool ConnectionManager::addClient(ENetEvent *event){
     200    int id=clientVector.size();
    200201    clientVector.push_back((event->peer->address));
    201     clientMap[event->peer->address]=clientVector.size()-1;
     202    clientMap[event->peer->address]=id;
    202203    peerMap[event->peer->address]=*(event->peer);
     204    syncClassid(id);
    203205    return true;
    204206  }
     
    216218  }
    217219 
     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 
    218237}
  • code/branches/FICN/src/network/ConnectionManager.h

    r381 r400  
    2525#include "ConnectionManager.h"
    2626#include "PacketBuffer.h"
     27#include "PacketManager.h"
     28#include "orxonox/core/IdentifierIncludes.h"
    2729
    2830namespace std{
     
    6769    int getClientID(ENetPeer peer);
    6870    int getClientID(ENetAddress address);
     71    void syncClassid(int clientID);
    6972    ENetPeer getClientPeer(int clientID);
    7073    PacketBuffer buffer;
     74    PacketGenerator packet_gen;
    7175   
    7276    ENetHost *server;
  • code/branches/FICN/src/network/PacketDecoder.cc

    r374 r400  
    4444                return true;
    4545                break;
     46          case CLASSID:
     47                clid(packet);
     48                return true;
     49                break;
    4650        }
    4751        return false;
     
    126130}
    127131
     132void 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
    128144// now the data processing functions:
    129145
     
    131147  printChat(data);
    132148}
     149
     150void PacketDecoder::processClassid( classid *cid){
     151  printClassid(cid);
     152  return;
     153}
     154
     155
    133156
    134157//these are some print functions for test stuff
     
    163186        cout << "size of gamestate: " << data->size << endl;
    164187}
     188
     189void 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  
    8686        return packet;
    8787}
     88
     89ENetPacket* 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  
    22#define PACKETMANAGER_H_
    33
     4#include <string>
    45#include <enet/enet.h>
    56#include "GameStateManager.h"
     
    1314        KEYBOARD,
    1415        CHAT,
    15         GAMESTATE
     16        GAMESTATE ,
     17        CLASSID
    1618};
    1719
     
    3234        ENetPacket* chatMessage( const char* message, int reliable = ENET_PACKET_FLAG_RELIABLE );
    3335        ENetPacket* gstate( GameState* states, int reliable = ENET_PACKET_FLAG_RELIABLE );
     36        ENetPacket* clid( int classid, std::string classname, int reliable = ENET_PACKET_FLAG_RELIABLE );
    3437private:
    3538        //used to set the bytes in the right order
     
    8588                const char* message;
    8689        };
     90       
     91        struct classid{
     92          int id;
     93          int length;
     94          int classid;
     95          const char *message;
     96        };
    8797       
    8898        void acknowledgement( ENetPacket* packet );
     
    91101        void chatMessage( ENetPacket* packet );
    92102        void gstate( ENetPacket* packet );
     103        void clid( ENetPacket *packet);
    93104       
    94105  //process data
     
    96107  //virtual void processGamestate(GameState *state);
    97108  virtual void processChat( chat *data);
     109  virtual void processClassid( classid *cid);
    98110  //virtual void processAck( ack *data);
    99111 
     
    104116        void printChat( chat* data );
    105117        void printGamestate( GameState* data );
     118        void printClassid( classid *cid);
    106119};
    107120}
  • code/branches/FICN/src/network/Server.cc

    r381 r400  
    112112  }
    113113 
     114 
    114115}
Note: See TracChangeset for help on using the changeset viewer.