Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jul 28, 2010, 8:29:32 PM (14 years ago)
Author:
scheusso
Message:

some new features:
-Orxonox servers announce themselves now inside a LAN (and can provide some information (e.g. server name, etc.) to the client )
-Orxonox clients discover the servers inside the LAN and list them in the menu

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation3/src/libraries/network/Server.cc

    r6417 r7161  
    6969  *
    7070  */
    71   Server::Server() {
     71  Server::Server()
     72  {
    7273    this->timeSinceLastUpdate_=0;
    7374  }
    7475
    75   Server::Server(int port){
     76  Server::Server(int port)
     77  {
    7678    this->setPort( port );
    7779    this->timeSinceLastUpdate_=0;
     
    8385  * @param bindAddress Address to listen on
    8486  */
    85   Server::Server(int port, const std::string& bindAddress) {
     87  Server::Server(int port, const std::string& bindAddress)
     88  {
    8689    this->setPort( port );
    8790    this->setBindAddress( bindAddress );
     
    9295  * @brief Destructor
    9396  */
    94   Server::~Server(){
     97  Server::~Server()
     98  {
    9599  }
    96100
     
    98102  * This function opens the server by creating the listener thread
    99103  */
    100   void Server::open() {
     104  void Server::open()
     105  {
     106    Host::setActive(true);
    101107    COUT(4) << "opening server" << endl;
    102108    this->openListener();
     109    LANDiscoverable::setActivity(true);
    103110    return;
    104111  }
     
    107114  * This function closes the server
    108115  */
    109   void Server::close() {
     116  void Server::close()
     117  {
     118    Host::setActive(false);
    110119    COUT(4) << "closing server" << endl;
    111120    this->disconnectClients();
    112121    this->closeListener();
     122    LANDiscoverable::setActivity(false);
    113123    return;
    114124  }
    115125
    116   bool Server::processChat(const std::string& message, unsigned int playerID){
     126  bool Server::processChat(const std::string& message, unsigned int playerID)
     127  {
    117128    ClientInformation *temp = ClientInformation::getBegin();
    118129    packet::Chat *chat;
     
    134145  * @param time time since last tick
    135146  */
    136   void Server::update(const Clock& time) {
     147  void Server::update(const Clock& time)
     148  {
    137149    // receive incoming packets
    138150    Connection::processQueue();
     151    // receive and process incoming discovery packets
     152    LANDiscoverable::update();
    139153
    140154    if ( ClientInformation::hasClients() )
     
    157171  }
    158172
    159   bool Server::queuePacket(ENetPacket *packet, int clientID){
     173  bool Server::queuePacket(ENetPacket *packet, int clientID)
     174  {
    160175    return ServerConnection::addPacket(packet, clientID);
    161176  }
     
    164179   * @brief: returns ping time to client in milliseconds
    165180   */
    166   unsigned int Server::getRTT(unsigned int clientID){
     181  unsigned int Server::getRTT(unsigned int clientID)
     182  {
    167183    assert(ClientInformation::findClient(clientID));
    168184    return ClientInformation::findClient(clientID)->getRTT();
     
    178194   * @brief: return packet loss ratio to client (scales from 0 to 1)
    179195   */
    180   double Server::getPacketLoss(unsigned int clientID){
     196  double Server::getPacketLoss(unsigned int clientID)
     197  {
    181198    assert(ClientInformation::findClient(clientID));
    182199    return ClientInformation::findClient(clientID)->getPacketLoss();
     
    186203  * takes a new snapshot of the gamestate and sends it to the clients
    187204  */
    188   void Server::updateGamestate() {
     205  void Server::updateGamestate()
     206  {
    189207    if( ClientInformation::getBegin()==NULL )
    190208      //no client connected
     
    208226  * sends the gamestate
    209227  */
    210   bool Server::sendGameState() {
     228  bool Server::sendGameState()
     229  {
    211230//     COUT(5) << "Server: starting function sendGameState" << std::endl;
    212231//     ClientInformation *temp = ClientInformation::getBegin();
     
    244263  }
    245264
    246   bool Server::sendObjectDeletes(){
     265  bool Server::sendObjectDeletes()
     266  {
    247267    ClientInformation *temp = ClientInformation::getBegin();
    248268    if( temp == NULL )
     
    257277//     COUT(3) << "sending DeleteObjects" << std::endl;
    258278    while(temp != NULL){
    259       if( !(temp->getSynched()) ){
     279      if( !(temp->getSynched()) )
     280      {
    260281        COUT(5) << "Server: not sending gamestate" << std::endl;
    261282        temp=temp->next();
     
    276297
    277298
    278   void Server::addPeer(ENetEvent *event){
     299  void Server::addPeer(ENetEvent *event)
     300  {
    279301    static unsigned int newid=1;
    280302
    281303    COUT(2) << "Server: adding client" << std::endl;
    282304    ClientInformation *temp = ClientInformation::insertBack(new ClientInformation);
    283     if(!temp){
     305    if(!temp)
     306    {
    284307      COUT(2) << "Server: could not add client" << std::endl;
    285308    }
     
    310333  }
    311334
    312   bool Server::createClient(int clientID){
     335  bool Server::createClient(int clientID)
     336  {
    313337    ClientInformation *temp = ClientInformation::findClient(clientID);
    314     if(!temp){
     338    if(!temp)
     339    {
    315340      COUT(2) << "Conn.Man. could not create client with id: " << clientID << std::endl;
    316341      return false;
     
    345370  }
    346371
    347   void Server::disconnectClient( ClientInformation *client ){
     372  void Server::disconnectClient( ClientInformation *client )
     373  {
    348374    ServerConnection::disconnectClient( client );
    349375    GamestateManager::removeClient(client);
     
    352378  }
    353379
    354   bool Server::chat(const std::string& message){
     380  bool Server::chat(const std::string& message)
     381  {
    355382      return this->sendChat(message, Host::getPlayerID());
    356383  }
    357384
    358   bool Server::broadcast(const std::string& message){
     385  bool Server::broadcast(const std::string& message)
     386  {
    359387      return this->sendChat(message, CLIENTID_UNKNOWN);
    360388  }
    361389
    362   bool Server::sendChat(const std::string& message, unsigned int clientID){
     390  bool Server::sendChat(const std::string& message, unsigned int clientID)
     391  {
    363392    ClientInformation *temp = ClientInformation::getBegin();
    364393    packet::Chat *chat;
    365     while(temp){
     394    while(temp)
     395    {
    366396      chat = new packet::Chat(message, clientID);
    367397      chat->setClientID(temp->getID());
     
    377407  }
    378408
    379   void Server::syncClassid(unsigned int clientID) {
     409  void Server::syncClassid(unsigned int clientID)
     410  {
    380411    int failures=0;
    381412    packet::ClassID *classid = new packet::ClassID();
Note: See TracChangeset for help on using the changeset viewer.