Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 1, 2008, 3:54:20 PM (16 years ago)
Author:
rgrieder
Message:
  • @everyone: Do not create a branch until I've added the svn:eol-style property correctly. Otherwise this would cost me another 4 hours or so when we want to merge back.
  • merged network branch back to trunk
  • I had to omit the changes from last evening concerning the line endings
  • might not work yet because of the line endings
  • @beni: script branch is the only branch still open. you probably will have to apply a patch because of inconsistent new lines
File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/network/Client.cc

    r1360 r1502  
    8585    isConnected=false;
    8686    isSynched_=false;
     87    gameStateFailure_=false;
    8788  }
    8889
     
    9596    isConnected=false;
    9697    isSynched_=false;
     98    gameStateFailure_=false;
    9799  }
    98100
     
    105107    isConnected=false;
    106108    isSynched_=false;
     109    gameStateFailure_=false;
    107110  }
    108111
     
    120123    isConnected=client_connection.createConnection();
    121124    if(isConnected){
    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;
     125//       COUT(3) << "sending connectrequest" << std::endl;
     126//       if(!client_connection.addPacket(pck_gen.generateConnectRequest()) || !client_connection.sendPackets())
     127//         COUT(1) << "could not send connection request !!!!!!!!!" << std::endl;
    125128    }else
    126       COUT(1) << "could not create connection" << std::endl;
     129      COUT(1) << "could not create connection laber" << std::endl;
    127130    return isConnected;
    128131  }
     
    137140  }
    138141
    139   /**
    140   * submits a MouseAction to the server
    141   * @param x x Coordinate
    142   * @param y y Coordinate
    143   * @return true/false
    144   */
    145   bool Client::sendMouse(double x, double y){
    146     // generate packet and add it to the queue
    147     if(!isConnected)
    148       return false;
    149     if(!client_connection.addPacket(pck_gen.mousem(x, y)))
    150       return false;
    151     // send packets
    152     return client_connection.sendPackets();
    153   }
    154 
    155   /**
    156   * submits a Keystrike to the server
    157   * @param key_code code to submit
    158   * @return true/false
    159   */
    160   bool Client::sendKeyboard(char key_code){
    161     // generate packet and add it to queue
    162     if(!isConnected)
    163       return false;
    164     if(!client_connection.addPacket(pck_gen.keystrike(key_code)))
    165       return false;
    166     // send packets
    167     return client_connection.sendPackets();
    168   }
     142 
     143
     144 
    169145
    170146  /**
     
    177153    if(!isConnected)
    178154      return false;
    179     if(client_connection.addPacket(pck_gen.chatMessage( message.c_str() )))
    180       return client_connection.sendPackets();
     155    return client_connection.addPacket(pck_gen.chatMessage( message.c_str() ));
     156      //return client_connection.sendPackets();
    181157    // send packets
    182158    return false;
    183   }
    184 
    185   /**
    186   * Adds a MouseAction to the PacketQueue
    187   * @param x x Coordinate
    188   * @param y y Coordinate
    189   * @return true/false
    190   */
    191   bool Client::addMouse(double x, double y){
    192     // generate packet and add it to the queue
    193     if(client_connection.addPacket(pck_gen.mousem(x, y)))
    194       return true;
    195     else
    196       return false;
    197   }
    198 
    199   /**
    200   * Adds a Keystrike to the PacketQueue
    201   * @param key_code
    202   * @return true/false
    203   */
    204   bool Client::addKeyboard(char key_code){
    205     // generate packet and add it to queue
    206     if(client_connection.addPacket(pck_gen.keystrike(key_code)))
    207       return true;
    208     else
    209       return false;
    210   }
    211 
    212   /**
    213   * Sends out all the packets queued by addXXX
    214   */
    215   bool Client::sendPackets(){
    216     if(!isConnected)
    217       return false;
    218     ENetEvent event;
    219     // send packets
    220     client_connection.sendPackets(&event);
    221     if(event.type==ENET_EVENT_TYPE_NONE)
    222       return true;
    223     else
    224       return false;
    225159  }
    226160
     
    243177      }
    244178    }
    245     ENetPacket *packet;
     179    ENetEvent *event;
    246180    // stop if the packet queue is empty
    247181    while(!(client_connection.queueEmpty())){
    248       packet = client_connection.getPacket();
    249       COUT(5) << "tick packet size " << packet->dataLength << std::endl;
    250       elaborate(packet, 0); // ================= i guess we got to change this .... (client_ID is always same = server)
    251     }
    252     if(!client_connection.sendPackets())
    253       COUT(3) << "Problem sending packets to server" << std::endl;
    254     return;
    255   }
    256 
    257   void Client::processGamestate( GameStateCompressed *data, int clientID){
    258     int id = data->id;
    259     COUT(5) << "received gamestate id: " << data->id << std::endl;
    260     if(gamestate.pushGameState(data)){
     182      event = client_connection.getEvent();
     183      COUT(5) << "tick packet size " << event->packet->dataLength << std::endl;
     184      elaborate(event->packet, 0); // ================= i guess we got to change this .... (client_ID is always same = server)
     185    }
     186    int gameStateID = gamestate.processGameState();
     187    if(gameStateID==GAMESTATEID_INITIAL)
     188      if(gameStateFailure_){
     189        if(!client_connection.addPacket(pck_gen.acknowledgement(GAMESTATEID_INITIAL)))
     190          COUT(3) << "could not (negatively) ack gamestate" << std::endl;
     191        else
     192          COUT(4) << "negatively acked a gamestate" << std::endl;
     193        }
     194      else
     195        gameStateFailure_=true;
     196    else if(gameStateID!=0){
     197      // ack gamestate and set synched
    261198      if(!isSynched_)
    262199        isSynched_=true;
    263       if(!client_connection.addPacket(pck_gen.acknowledgement(id)))
    264         return;
    265         // we do this at the end of a tick
    266       if(!client_connection.sendPackets())
    267         COUT(2) << "Could not send acknowledgment" << std::endl;
    268     }
     200      gameStateFailure_=false;
     201      if(!client_connection.addPacket(pck_gen.acknowledgement(gameStateID)))
     202        COUT(3) << "could not ack gamestate" << std::endl;
     203    }// otherwise we had no gamestate to load
     204    gamestate.cleanup();
     205    /*if(!client_connection.sendPackets())
     206      COUT(3) << "Problem sending packets to server" << std::endl;*/
     207    return;
     208  }
     209
     210  void Client::processGamestate( GameStateCompressed *data, int clientID){
     211    COUT(5) << "received gamestate id: " << data->id << std::endl;
     212    gamestate.addGameState(data);
    269213  }
    270214
     
    275219      id->setNetworkID(clid->clid);
    276220    COUT(4) << "Client: received and set network id: " << clid->clid << "; classname: " << clid->message << std::endl;
     221    COUT(4) << "id(classid)->getName " << ID((unsigned int)clid->clid)->getName() << std::endl;
    277222    delete clid;
    278223    return;
Note: See TracChangeset for help on using the changeset viewer.