Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 7, 2015, 5:21:45 PM (10 years ago)
Author:
frovelli
Message:

Implemented playercount in multiplayer lobby

Location:
code/branches/multiplayerFS15/src/libraries/network
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • code/branches/multiplayerFS15/src/libraries/network/LANDiscoverable.cc

    r10427 r10434  
    5757  void LANDiscoverable::setConfigValues()
    5858  {
    59     /* update msaddress string from orxonox.ini config file, if it
     59    /* update ownName string from orxonox.ini config file, if it
    6060     * has changed.
    6161     */
    62     SetConfigValueExternal(ownName, "WANDiscovery", "ownName", "tme213");
     62    SetConfigValueExternal(ownName, "Discovery", "ownName", "tme213");
    6363  }
    6464
     
    120120            packet::ServerInformation info;
    121121            info.setServerName(this->ownName);
     122            info.setClientNumber(this->clientNumber);
    122123            info.send(event.peer);
    123124//             ENetPacket* packet = enet_packet_create( LAN_DISCOVERY_ACK, strlen(LAN_DISCOVERY_ACK)+1, ENET_PACKET_FLAG_RELIABLE );
  • code/branches/multiplayerFS15/src/libraries/network/LANDiscoverable.h

    r10427 r10434  
    4343      void setActivity( bool bActive );
    4444      void update();
     45      void updateClientNumber(int clientNumber) {this->clientNumber = clientNumber;}
     46;
    4547      /** Function used for the configuration file parameter update */
    4648      void setConfigValues();
     
    5052      ENetHost*       host_;
    5153      std::string     ownName;
     54      int clientNumber;
    5255  };
    5356
  • code/branches/multiplayerFS15/src/libraries/network/LANDiscovery.cc

    r10334 r10434  
    8989          {
    9090            packet::ServerInformation info(&event);
    91             orxout(internal_info, context::network) << "Received LAN discovery server information; Name: " << info.getServerName() << ", Address: " << info.getServerIP() << ", RTT: " << info.getServerRTT() << endl;
     91            orxout(internal_info, context::network) << "Received LAN discovery server information; Name: " << info.getServerName() << ", Address: " << info.getServerIP() << ", Players: " << info.getClientNumber() << ", RTT: " << info.getServerRTT() << endl;
    9292            std::vector<packet::ServerInformation>::iterator it;
    9393            for( it=this->servers_.begin(); it!=this->servers_.end(); ++it )
     
    132132      return Ogre::StringConverter::toString(serverrtt);
    133133    }
    134 
    135134  }
    136135
    137 
     136  std::string LANDiscovery::getServerListItemPlayerNumber(unsigned int index)
     137  {
     138    if( index >= this->servers_.size() )
     139      return BLANKSTRING;
     140    else{
     141      int playerNumber = this->servers_[index].getClientNumber();
     142      return Ogre::StringConverter::toString(playerNumber);
     143    }
     144  }
    138145} // namespace orxonox
  • code/branches/multiplayerFS15/src/libraries/network/LANDiscovery.h

    r10334 r10434  
    5353      std::string getServerListItemIP( unsigned int index ); // tolua_export
    5454      std::string getServerListItemRTT( unsigned int index ); // tolua_export
     55      std::string getServerListItemPlayerNumber( unsigned int index ); // tolua_export
    5556      static LANDiscovery& getInstance(){ return Singleton<LANDiscovery>::getInstance(); } // tolua_export
    5657
  • code/branches/multiplayerFS15/src/libraries/network/MasterServer.cc

    r10427 r10434  
    127127      /* send this particular server */
    128128      /* build reply string */
    129       int packetlen = MSPROTO_SERVERLIST_ITEM_LEN + 1 + (*i).ServerInfo.getServerIP().length() + 1 + (*i).ServerInfo.getServerName().length() + 1;
     129      int packetlen = MSPROTO_SERVERLIST_ITEM_LEN + 1 + (*i).ServerInfo.getServerIP().length() + 1 + (*i).ServerInfo.getServerName().length() + 1 + sizeof((*i).ServerInfo.getClientNumber()) + 1;
    130130      char *tosend = (char *)calloc(packetlen ,1 );
    131131      if( !tosend )
     
    133133        continue;
    134134      }
    135       sprintf( tosend, "%s %s %s", MSPROTO_SERVERLIST_ITEM,
    136           (*i).ServerInfo.getServerIP().c_str(), (*i).ServerInfo.getServerName().c_str());
     135      sprintf( tosend, "%s %s %s %u", MSPROTO_SERVERLIST_ITEM,
     136          (*i).ServerInfo.getServerIP().c_str(), (*i).ServerInfo.getServerName().c_str(), (*i).ServerInfo.getClientNumber());
    137137
    138138      /* create packet from it */
     
    300300        orxout(internal_info, context::master_server) << "Removed server " << ip << " from list." << endl;
    301301      }
     302      /* TODO add hook for disconnect here */
    302303
    303304      else if( !strncmp( (char *)event->packet->data
     
    317318      }
    318319
    319       /* TODO add hook for disconnect here */
     320      else if( !strncmp( (char *)event->packet->data
     321        + MSPROTO_GAME_SERVER_LEN+1,
     322        MSPROTO_SET_CLIENTS, MSPROTO_SET_CLIENTS_LEN ) )
     323      {
     324        /* create string from peer data */
     325        std::string ip = std::string( addrconv );
     326        std::string data (event->packet->data,event->packet->data + event->packet->dataLength );
     327        std::string textform= data.substr(MSPROTO_GAME_SERVER_LEN + 1 + MSPROTO_SET_CLIENTS_LEN + 1);
     328        int clientNumber = Ogre::StringConverter::parseInt(textform);
     329
     330        this->mainlist.setClientsByAddress( ip, clientNumber);
     331
     332        /* tell the user */
     333        orxout(internal_info, context::master_server) << "Updated server " << ip << " with new client number " << clientNumber << endl;
     334      }
    320335    }
    321336    else if( !strncmp( (char *)event->packet->data, MSPROTO_CLIENT,
  • code/branches/multiplayerFS15/src/libraries/network/MasterServer.h

    r8937 r10434  
    4949#include <cstdio>
    5050
    51 namespace orxonox
     51#include <OgreStringConverter.h>
     52
     53
     54namespace orxonox
    5255{
    5356  /* singleton */
     
    6366      /* static pointer for commands */
    6467      static MasterServer *instance;
    65       static MasterServer *getInstance() 
     68      static MasterServer *getInstance()
    6669        { return instance; }
    67       static void setInstance( MasterServer *setto ) 
     70      static void setInstance( MasterServer *setto )
    6871        { instance = setto;  }
    69      
     72
    7073      /* functions for commands */
    7174      static void listServers( void );
  • code/branches/multiplayerFS15/src/libraries/network/Server.cc

    r10427 r10434  
    114114    /* make discoverable on LAN */
    115115    LANDiscoverable::setActivity(true);
     116    LANDiscoverable::updateClientNumber(0);
    116117
    117118    /* make discoverable on WAN */
    118119    WANDiscoverable::setActivity(true);
     120    WANDiscoverable::updateClientNumber(0);
    119121
    120122    /* done */
     
    289291    // inform all the listeners
    290292    this->clientIDs_.push_back(peerID);
     293    WANDiscoverable::updateClientNumber(this->clientIDs_.size());
     294    LANDiscoverable::updateClientNumber(this->clientIDs_.size());
     295
    291296    ClientConnectionListener::broadcastClientConnected(peerID);
    292297    GamestateManager::addPeer(peerID);
     
    295300
    296301    orxout(internal_info, context::network) << "Server: added client id: " << peerID << endl;
     302
    297303    createClient(peerID);
    298304}
     
    315321    }
    316322  }
     323  WANDiscoverable::updateClientNumber(this->clientIDs_.size());
     324  LANDiscoverable::updateClientNumber(this->clientIDs_.size());
     325
    317326  ClientConnectionListener::broadcastClientDisconnected(peerID);
    318327  GamestateManager::removePeer(peerID);
  • code/branches/multiplayerFS15/src/libraries/network/ServerList.cc

    r10427 r10434  
    159159  };
    160160
     161  bool ServerList::setClientsByAddress( std::string address, int clientNumber ){
     162    /* get an iterator */
     163    std::list<ServerListElem>::iterator i;
     164
     165    /* loop through list elements */
     166    for( i = serverlist.begin(); i != serverlist.end(); ++i )
     167      if( (*i).ServerInfo.getServerIP() == address )
     168      { /* found this adress, rename and quit */
     169        (*i).ServerInfo.setClientNumber( clientNumber );
     170        return true;
     171      }
     172    return false;
     173  };
     174
    161175}
  • code/branches/multiplayerFS15/src/libraries/network/ServerList.h

    r10427 r10434  
    9494      bool setNameByAddress( std::string address, std::string name  );
    9595
     96      bool setClientsByAddress( std::string address, int clientNumber );
     97
    9698      /* SEARCHING */
    9799      /* \param address The address of the server that is to be
  • code/branches/multiplayerFS15/src/libraries/network/WANDiscoverable.cc

    r10427 r10434  
    5858     * has changed.
    5959     */
    60     SetConfigValueExternal(msaddress, "WANDiscovery", "msaddress", "orxonox.net");
    61     SetConfigValueExternal(ownName, "WANDiscovery", "ownName", "tme213");
     60    SetConfigValueExternal(msaddress, "Discovery", "msaddress", "orxonox.net");
     61    SetConfigValueExternal(ownName, "Discovery", "ownName", "tme213");
    6262//     SetConfigValue( msaddress, "orxonox.net");
    6363  }
     
    106106    orxout(verbose, context::master_server) << "Initialization of WANDiscoverable complete." << endl;
    107107
     108    // Now register the server at the master server
     109    this->msc.sendRequest( MSPROTO_GAME_SERVER " " MSPROTO_REGISTER_SERVER );
     110
    108111    std::string request = MSPROTO_GAME_SERVER " " MSPROTO_SET_NAME " ";
    109112    request += this->ownName;
    110 
    111     // Now register the server at the master server
    112     this->msc.sendRequest( MSPROTO_GAME_SERVER " " MSPROTO_REGISTER_SERVER );
    113113    this->msc.sendRequest( request );
    114 
    115114
    116115    return true;
     
    123122  }
    124123
     124  void WANDiscoverable::updateClientNumber(int clientNumber)
     125  {
     126    orxout(verbose, context::master_server) << "Sending new number of clients: " << clientNumber << endl;
     127    std::string request = MSPROTO_GAME_SERVER " " MSPROTO_SET_CLIENTS " ";
     128    std::stringstream ss;
     129    ss << clientNumber;
     130    request +=  ss.str();
     131
     132    this->msc.sendRequest( request );
     133  }
     134
    125135
    126136
  • code/branches/multiplayerFS15/src/libraries/network/WANDiscoverable.h

    r10427 r10434  
    5858      void setActivity( bool bActive );
    5959
     60      void updateClientNumber(int clientNumber);
     61
    6062      /** Master server communications object */
    6163      MasterServerComm msc;
  • code/branches/multiplayerFS15/src/libraries/network/WANDiscovery.cc

    r10427 r10434  
    9696      int separator = datastr.find(" ");
    9797      toadd.setServerIP(datastr.substr(0,separator));
    98       toadd.setServerName(datastr.substr(separator+1));
     98      int secondsep = datastr.find(" ", separator + 1);
     99      toadd.setServerName(datastr.substr(separator + 1, secondsep - separator - 1));
     100      toadd.setClientNumber(Ogre::StringConverter::parseInt(datastr.substr(secondsep+1)));
     101
     102      orxout(internal_info, context::network) << "Received WAN discovery server information; Name: " << toadd.getServerName() << ", Address: " << toadd.getServerIP() << ", Players: " << toadd.getClientNumber() << ", RTT: " << toadd.getServerRTT() << endl;
    99103
    100104      /* add to list */
     
    169173
    170174  }
     175  std::string WANDiscovery::getServerListItemPlayerNumber(unsigned int index)
     176  {
     177    if( index >= this->servers_.size() )
     178      return BLANKSTRING;
     179    else{
     180      int playerNumber = this->servers_[index].getClientNumber();
     181      return Ogre::StringConverter::toString(playerNumber);
     182    }
     183  }
    171184
    172185} // namespace orxonox
  • code/branches/multiplayerFS15/src/libraries/network/WANDiscovery.h

    r10427 r10434  
    8787      std::string getServerListItemRTT( unsigned int index ); // tolua_export
    8888
     89      /** \param index Index to get the RTT of
     90       * \return The number of players on the server
     91       *
     92       * Get the number of players on the server
     93       */
     94      std::string getServerListItemPlayerNumber( unsigned int index ); // tolua_export
     95
    8996      /* todo: might make this private and use getter/setter methods
    9097       * at some later time.
  • code/branches/multiplayerFS15/src/libraries/network/packet/ServerInformation.cc

    r10334 r10434  
    4242    ServerInformation::ServerInformation()
    4343    {
    44 
    4544    }
    4645
  • code/branches/multiplayerFS15/src/libraries/network/packet/ServerInformation.h

    r10427 r10434  
    5151        void          setServerIP( std::string IP ) { this->serverIP_ = IP; }
    5252        std::string   getServerIP() { return this->serverIP_; }
     53        void          setClientNumber( int clientNumber ) { this->clientNumber_ = clientNumber; }
     54        int           getClientNumber() { return this->clientNumber_; }
    5355        uint32_t      getServerRTT() { return this->serverRTT_; }
    5456
     
    5759        std::string   serverIP_;
    5860        uint32_t      serverRTT_;
     61        int           clientNumber_;
    5962    };
    6063
Note: See TracChangeset for help on using the changeset viewer.