Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 22, 2018, 4:12:23 PM (6 years ago)
Author:
mdedial
Message:

WIP 22.03.18: Begin documenting server-side code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/Masterserver_FS18/src/libraries/network/Host.cc

    r11071 r11829  
    4444  SetConsoleCommand(__CC_printRTT_group, __CC_printRTT_name, &Host::printRTT);
    4545
    46   // Host*               Host::instance_=nullptr;
    47   uint32_t            Host::clientID_s=0;
    48 //   uint32_t            Host::shipID_s=-1;
     46  uint32_t            Host::clientID_s = 0;
    4947  std::vector<Host*>  Host::instances_s;
    5048
     
    5452  Host::Host()
    5553  {
    56   //   assert(instance_==nullptr);
    57     instances_s.push_back(this);
     54    Host::instances_s.push_back(this);
     55
     56    // TODO: What does this do?
    5857    ModifyConsoleCommand(__CC_printRTT_group, __CC_printRTT_name).setObject(this);
     58
    5959    this->bIsActive_ = false;
    6060  }
     
    6666  Host::~Host()
    6767  {
    68     assert( std::find( instances_s.begin(), instances_s.end(), this )!=instances_s.end() );
    69     instances_s.erase(std::find( instances_s.begin(), instances_s.end(), this ));
     68    assert(std::find( instances_s.begin(), instances_s.end(), this ) != instances_s.end());
     69    Host::instances_s.erase(std::find( instances_s.begin(), instances_s.end(), this ));
    7070    ModifyConsoleCommand(__CC_printRTT_group, __CC_printRTT_name).setObject(nullptr);
    7171  }
     
    8080  void Host::addPacket(ENetPacket *packet, int clientID, uint8_t channelID)
    8181  {
    82     for(Host* host : instances_s)
     82    for (Host* host : instances_s)
    8383    {
    84       if( host->isActive() )
     84      if (host->isActive())
    8585      {
    8686        host->queuePacket(packet, clientID, channelID);
     
    9797  void Host::sendChat(const std::string& message, unsigned int sourceID, unsigned int targetID)
    9898  {
    99     for(Host* host : instances_s)
    100       if( host->isActive() )
     99    for (Host* host : instances_s)
     100    {
     101      if (host->isActive())
     102      {
    101103        host->doSendChat(message, sourceID, targetID);
     104      }
     105    }
    102106  }
    103107
     
    108112  {
    109113    for (NetworkChatListener* listener : ObjectList<NetworkChatListener>())
     114    {
    110115      listener->incomingChat(message, sourceID);
     116    }
    111117  }
    112118
     
    114120  bool Host::isServer()
    115121  {
    116     for (Host* host : instances_s)
     122    for (Host* host : Host::instances_s)
    117123    {
    118       if( host->isActive() )
     124      if (host->isActive())
    119125      {
    120         if( host->isServer_() )
     126        if (host->isServer_())
     127        {
    121128          return true;
     129        }
    122130      }
    123131    }
     
    125133  }
    126134
     135  /**
     136   * Singleton implementation. Return the first active instance.
     137   */
    127138  Host* Host::getActiveInstance()
    128139  {
    129140    std::vector<Host*>::iterator it = Host::instances_s.begin();
    130     while( it != Host::instances_s.end() )
     141    while (it != Host::instances_s.end())
    131142    {
    132       if( (*it)->isActive() )
     143      if ((*it)->isActive())
     144      {
    133145        return *it;
     146      }
    134147      else
     148      {
    135149        ++it;
     150      }
    136151    }
    137152    return nullptr;
Note: See TracChangeset for help on using the changeset viewer.