Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1299


Ignore:
Timestamp:
May 15, 2008, 10:08:41 PM (16 years ago)
Author:
scheusso
Message:

a huge fix in packetbuffer

Location:
code/branches/merge/src
Files:
10 edited

Legend:

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

    r1284 r1299  
    120120    isConnected=client_connection.createConnection();
    121121    if(isConnected){
    122       COUT(4) << "sending connectrequest" << std::endl;
    123       client_connection.addPacket(pck_gen.generateConnectRequest());
    124       client_connection.sendPackets();
     122      COUT(3) << "sending connectrequest" << std::endl;
     123      if(!client_connection.addPacket(pck_gen.generateConnectRequest()) || !client_connection.sendPackets())
     124        COUT(1) << "could not create connection" << std::endl;
    125125    }else
    126126      COUT(1) << "could not create connection" << std::endl;
     
    229229  */
    230230  void Client::tick(float time){
     231//     COUT(3) << ".";
    231232    if(client_connection.isConnected() && isSynched_){
    232233      COUT(4) << "popping partial gamestate: " << std::endl;
     
    260261      if(!isSynched_)
    261262        isSynched_=true;
    262       client_connection.addPacket(pck_gen.acknowledgement(id));
     263      if(!client_connection.addPacket(pck_gen.acknowledgement(id)))
     264        return;
    263265        // we do this at the end of a tick
    264        if(!client_connection.sendPackets())
    265          COUT(2) << "Could not send acknowledgment" << std::endl;
     266      if(!client_connection.sendPackets())
     267        COUT(2) << "Could not send acknowledgment" << std::endl;
    266268    }
    267269  }
  • code/branches/merge/src/network/ClientInformation.cc

    r1264 r1299  
    121121
    122122  ClientInformation *ClientInformation::insertBefore(ClientInformation *ins){
     123    if(!this)
     124      return NULL;
    123125    this->prev()->setNext(ins);
    124126    ins->setPrev(this->preve);
     
    132134  }
    133135
    134   void ClientInformation::setPeer(ENetPeer *peer){
     136  bool ClientInformation::setPeer(ENetPeer *peer){
     137    if(!this)
     138      return false;
    135139    peer_ = peer;
    136   }
    137 
    138   void ClientInformation::setGamestateID(int id){
     140    return true;
     141  }
     142
     143  bool ClientInformation::setGamestateID(int id){
     144    if(!this)
     145      return false;
    139146    gamestateID_=id;
     147    return true;
    140148  }
    141149
    142150  int ClientInformation::getID() {
    143     return clientID_;
     151    if(!this)
     152      return CLIENTID_UNKNOWN;
     153    else
     154      return clientID_;
    144155  }
    145156
    146157  ENetPeer *ClientInformation::getPeer() {
    147     return peer_;
     158    if(this)
     159      return peer_;
     160    else
     161      return NULL;
    148162  }
    149163
    150164  int ClientInformation::getGamestateID() {
    151     return gamestateID_;
     165    if(this)
     166      return gamestateID_;
     167    else
     168      return -1;
    152169  }
    153170
    154171  ClientInformation *ClientInformation::insertBack(ClientInformation *ins) {
     172    if(!this)
     173      return NULL;
    155174    ClientInformation *temp = this;
    156175    while(temp->next()!=0){
     
    163182
    164183  bool ClientInformation::removeClient(int clientID) {
     184    if(!this || clientID==CLIENTID_UNKNOWN)
     185      return false;
    165186    ClientInformation *temp = this;
    166187    while(temp!=0 && temp->getID()!=clientID)
     
    173194
    174195  bool ClientInformation::removeClient(ENetPeer *peer) {
     196    if(!this || !peer)
     197      return false;
    175198    ClientInformation *temp = this;
    176199    while(temp!=0){
     
    196219    if (temp->head)
    197220      temp=temp->next();
    198     //bugfix: temp to temp->next(), get last elem if not found, not segflt
    199     while(temp->next()!=0 && temp->getID()!=clientID){
     221    while(temp!=0 && temp->getID()!=clientID){
    200222      temp = temp->next();
    201223    }
     
    212234  ClientInformation *ClientInformation::findClient(ENetAddress *address, bool look_backwards) {
    213235    ClientInformation *temp = this;
    214     //bugfix: temp to temp->next(), get last elem if not found, not segflt
    215     while(temp->next()!=0){
     236    while(temp!=0){
    216237      if(temp->head){
    217238        temp = temp->next();
     
    226247  }
    227248
    228   void ClientInformation::setSynched(bool s) {
     249  bool ClientInformation::setSynched(bool s) {
     250    if(!this)
     251      return false;
    229252    synched_=s;
     253    return true;
    230254  }
    231255
    232256  bool ClientInformation::getSynched() {
    233     return synched_;
     257    if(this)
     258      return synched_;
     259    else
     260      return false;
    234261  }
    235262
  • code/branches/merge/src/network/ClientInformation.h

    r1264 r1299  
    4646
    4747#define GAMESTATEID_INITIAL -1
     48#define CLIENTID_UNKNOWN -2
    4849
    4950namespace network
     
    7071    // set functions
    7172    void setID(int clientID);
    72     void setPeer(ENetPeer *peer);
    73     void setGamestateID(int id);
     73    bool setPeer(ENetPeer *peer);
     74    bool setGamestateID(int id);
    7475    inline void setShipID(int id){ShipID_=id;}
    7576   
     
    8889    ClientInformation *findClient(ENetAddress *address, bool look_backwards=false);
    8990
    90     void setSynched(bool s);
     91    bool setSynched(bool s);
    9192    bool getSynched();
    9293
  • code/branches/merge/src/network/ConnectionManager.cc

    r1282 r1299  
    101101    ENetPacket *packet=getPacket(address);
    102102    ClientInformation *temp =head_->findClient(&address);
     103    if(!temp)
     104      return NULL;
    103105    clientID=temp->getID();
    104106    return packet;
     
    124126
    125127  bool ConnectionManager::addPacket(ENetPacket *packet, ENetPeer *peer) {
    126     if(enet_peer_send(peer, (enet_uint8)head_->findClient(&(peer->address))->getID() , packet)!=0)
     128    ClientInformation *temp = head_->findClient(&(peer->address));
     129    if(!temp)
     130      return false;
     131    if(enet_peer_send(peer, (enet_uint8)temp->getID() , packet)!=0)
    127132      return false;
    128133    return true;
     
    130135
    131136  bool ConnectionManager::addPacket(ENetPacket *packet, int clientID) {
    132     if(enet_peer_send(head_->findClient(clientID)->getPeer(), (enet_uint8)clientID, packet)!=0)
     137    ClientInformation *temp = head_->findClient(clientID);
     138    if(!temp)
     139      return false;
     140    if(enet_peer_send(temp->getPeer(), (enet_uint8)clientID, packet)!=0)
    133141      return false;
    134142    return true;
     
    195203          if(head_->findClient(&event->peer->address))
    196204            processData(event);
     205          else
     206            COUT(3) << "received a packet from a client we don't know" << std::endl;
    197207          break;
    198208        case ENET_EVENT_TYPE_DISCONNECT:
     
    233243      case ENET_EVENT_TYPE_DISCONNECT:
    234244        COUT(4) << "disconnecting all clients" << std::endl;
    235         delete head_->findClient(&(event.peer->address));
     245        if(head_->findClient(&(event.peer->address)))
     246          delete head_->findClient(&(event.peer->address));
    236247        //maybe needs bugfix: might also be a reason for the server to crash
    237248        temp = temp->next();
     
    259270  bool ConnectionManager::addClient(ENetEvent *event) {
    260271    ClientInformation *temp = head_->insertBack(new ClientInformation);
     272    if(!temp){
     273      COUT(2) << "Conn.Man. could not add client" << std::endl;
     274      return false;
     275    }
    261276    if(temp->prev()->head) { //not good if you use anything else than insertBack
    262277      temp->prev()->setID(0); //bugfix: not necessary but usefull
     
    266281      temp->setID(temp->prev()->getID()+1);
    267282    temp->setPeer(event->peer);
    268     COUT(4) << "Con.Man: added client id: " << temp->getID() << std::endl;
     283    COUT(3) << "Con.Man: added client id: " << temp->getID() << std::endl;
    269284    return true;
    270285  }
     
    283298
    284299  void ConnectionManager::syncClassid(int clientID) {
    285     unsigned int network_id=0;
     300    unsigned int network_id=0, failures=0;
    286301    std::string classname;
    287302    orxonox::Identifier *id;
     
    295310      COUT(4) << "Con.Man:syncClassid:\tnetwork_id: " << network_id << ", classname: " << classname << std::endl;
    296311
    297       addPacket(packet_gen.clid( (int)network_id, classname ), clientID);
    298 
     312      while(!addPacket(packet_gen.clid( (int)network_id, classname ), clientID) && failures < 10){
     313        failures++;
     314      }
    299315      ++it;
    300316    }
     
    305321  bool ConnectionManager::createClient(int clientID){
    306322    ClientInformation *temp = head_->findClient(clientID);
     323    if(!temp){
     324      COUT(2) << "Conn.Man. could not create client with id: " << clientID << std::endl;
     325      return false;
     326    }
    307327    COUT(4) << "Con.Man: creating client id: " << temp->getID() << std::endl;
    308328    syncClassid(temp->getID());
    309329    COUT(4) << "creating spaceship for clientid: " << temp->getID() << std::endl;
    310330    // TODO: this is only a hack, untill we have a possibility to define default player-join actions
    311     createShip(temp);
    312     COUT(4) << "created spaceship" << std::endl;
     331    if(!createShip(temp))
     332      COUT(2) << "Con.Man. could not create ship for clientid: " << clientID << std::endl;
     333    else
     334      COUT(3) << "created spaceship" << std::endl;
    313335    temp->setSynched(true);
    314     COUT(4) << "sending welcome" << std::endl;
     336    COUT(3) << "sending welcome" << std::endl;
    315337    sendWelcome(temp->getID(), temp->getShipID(), true);
    316338    return true;
     
    319341  bool ConnectionManager::removeClient(int clientID){
    320342    orxonox::Iterator<orxonox::SpaceShip> it = orxonox::ObjectList<orxonox::SpaceShip>::start();
     343    ClientInformation *client = head_->findClient(clientID);
     344    if(!client)
     345      return false;
    321346    while(it){
    322       if(it->objectID!=head_->findClient(clientID)->getShipID()){
     347      if(it->objectID!=client->getShipID()){
    323348        ++it;
    324349        continue;
     
    333358 
    334359  bool ConnectionManager::createShip(ClientInformation *client){
     360    if(!client)
     361      return false;
    335362    orxonox::Identifier* id = ID("SpaceShip");
    336363    if(!id){
     
    369396 
    370397  bool ConnectionManager::sendWelcome(int clientID, int shipID, bool allowed){
    371     addPacket(packet_gen.generateWelcome(clientID, shipID, allowed),clientID);
    372     sendPackets();
    373     return true;
     398    if(addPacket(packet_gen.generateWelcome(clientID, shipID, allowed),clientID)){
     399      sendPackets();
     400      return true;
     401    }else
     402      return false;
    374403  }
    375404 
  • code/branches/merge/src/network/GameStateManager.cc

    r1294 r1299  
    117117        client = it->second;
    118118      GameState *server = reference;
    119       //head_->findClient(clientID)->setGamestateID(id);
    120119      COUT(3) << "client: " << client << " server: " << server << " gamestatemap: " << &gameStateMap << std::endl;
    121120      if(client)
     
    127126      GameState *server = reference;
    128127//       ackGameState(clientID, reference->id);
    129       //head_->findClient(clientID)->setGamestateID(id);
    130128      return encode(server);
    131129      // return an undiffed gamestate and set appropriate flags
     
    427425  void GameStateManager::ackGameState(int clientID, int gamestateID) {
    428426    ClientInformation *temp = head_->findClient(clientID);
    429     if(!temp)
     427    if(temp==0)
    430428      return;
    431429    int curid = temp->getGamestateID();
     
    434432//     deleteUnusedGameState(curid);
    435433    //increase gamestateused
    436     --(gameStateUsed.find(curid)->second);
     434    if(curid!=GAMESTATEID_INITIAL)
     435      --(gameStateUsed.find(curid)->second);
    437436    ++(gameStateUsed.find(gamestateID)->second);
    438437    temp->setGamestateID(gamestateID);
     
    460459 
    461460  void GameStateManager::removeClient(ClientInformation* client){
    462     gameStateUsed[client->getGamestateID()]--;
     461    if(!client)
     462      return;
     463    if(client->getGamestateID()>=0)
     464      gameStateUsed[client->getGamestateID()]--;
    463465    head_->removeClient(client->getID());
    464466  }
  • code/branches/merge/src/network/PacketBuffer.cc

    r1264 r1299  
    6363      // change this!!!!!!!
    6464      last->packet = ev->packet;
     65      last->address = ev->peer->address;
    6566      //last->address = ev->peer->address;
    6667    } else {
     
    7273      // save the packet to the new element
    7374      last->packet = ev->packet;
     75      last->address = ev->peer->address;
    7476      //last->address = ev->peer->address;
    7577    }
  • code/branches/merge/src/network/PacketDecoder.cc

    r1264 r1299  
    111111    void *data = (void *)new unsigned char[length];
    112112    memcpy(data, (void *)(packet->data+2*sizeof(int)), length);
     113    enet_packet_destroy( packet );
    113114    return true;
    114115  }
  • code/branches/merge/src/network/Server.cc

    r1264 r1299  
    117117    ENetPacket *packet = packet_gen.chatMessage(msg.c_str());
    118118    //std::cout <<"adding packets" << std::endl;
    119     connection->addPacketAll(packet);
     119    if(connection->addPacketAll(packet))
    120120    //std::cout <<"added packets" << std::endl;
    121     return connection->sendPackets();
     121      return connection->sendPackets();
     122    else
     123      return false;
    122124  }
    123125
     
    162164      //clientID here is a reference to grab clientID from ClientInformation
    163165      packet = connection->getPacket(clientID);
     166      if(!packet)
     167        continue;
    164168      //if statement to catch case that packetbuffer is empty
    165169      if( !elaborate(packet, clientID) )
    166         COUT(4) << "Server: PacketBuffer empty" << std::endl;
     170        COUT(3) << "Server: could not elaborate" << std::endl;
    167171    }
    168172  }
     
    238242 
    239243  bool Server::processConnectRequest( connectRequest *con, int clientID ){
    240     COUT(4) << "processing connectRequest " << std::endl;
     244    COUT(3) << "processing connectRequest " << std::endl;
    241245    //connection->addPacket(packet_gen.gstate(gamestates->popGameState(clientID)) , clientID);
    242246    connection->createClient(clientID);
     
    250254        COUT(3) << "Could not push gamestate\t\t\t\t=====" << std::endl;
    251255    else
     256      if(clients->findClient(clientID))
    252257        clients->findClient(clientID)->failures_=0;
    253258  }
     
    255260  void Server::disconnectClient(int clientID){
    256261    ClientInformation *client = clients->findClient(clientID);
    257     disconnectClient(client);
     262    if(client)
     263      disconnectClient(client);
    258264  }
    259265  void Server::disconnectClient( ClientInformation *client){
  • code/branches/merge/src/network/diffTest.cc

    r1264 r1299  
    466466bool addClientTest( ENetEvent* event, ClientInformation*& head ) {
    467467  ClientInformation *temp = head->insertBack(new ClientInformation);
     468  if(!temp)
     469    return false;
    468470  if(temp->prev()->head) {
    469471    temp->prev()->setID(0);
     
    475477  std::cout << "added client id: " << temp->getID() << std::endl;
    476478
    477   temp->setSynched(true);
    478   return true;
     479  return temp->setSynched(true);
    479480}
    480481
    481482void printClientInformationBox( ClientInformation* box ) {
     483  if(!box)
     484    return;
    482485  std::cout << "ClientList: id: " << box->getID() << "\t";
    483486  std::cout << "g_id: " << box->getGamestateID() << " \t";
  • code/branches/merge/src/orxonox/objects/SpaceShip.cc

    r1291 r1299  
    152152              {
    153153                  InputManager::addMouseHandler(this, "SpaceShip");
     154                  InputManager::enableMouseHandler("SpaceShip");
    154155                  setMouseEventCallback_ = true;
    155156              }
Note: See TracChangeset for help on using the changeset viewer.