Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 10, 2018, 3:06:55 PM (6 years ago)
Author:
merholzl
Message:

Merged Masterserver, refresh button had to be removed

Location:
code/branches/mergeFS18
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/mergeFS18

  • code/branches/mergeFS18/src/libraries/network/packet/Packet.cc

    r11071 r12027  
    129129}
    130130
     131/**
     132 * Send the Packet.
     133 * @param host The host which sends the packet
     134 */
    131135bool Packet::send(orxonox::Host* host)
    132136{
     137  // Deny sending incoming packets
    133138  if(packetDirection_ != Direction::Outgoing && packetDirection_ != Direction::Bidirectional )
    134139  {
     
    136141    return false;
    137142  }
     143
    138144  if(!enetPacket_)
    139145  {
    140     if(!data_){
     146    // Deny sending empty packets
     147    if(!data_) {
    141148      assert(0);
    142149      return false;
     
    152159      // without having a reference in the packetMap_
    153160      Packet::packetMapMutex_.lock();
    154       packetMap_[reinterpret_cast<size_t>(enetPacket_)] = this;
     161      Packet::packetMap_[reinterpret_cast<size_t>(enetPacket_)] = this;
    155162      Packet::packetMapMutex_.unlock();
    156163    }
     
    173180  }
    174181#endif
    175 //  ENetPacket *temp = enetPacket_;
    176 //  enetPacket_ = nullptr; // otherwise we have a double free because enet already handles the deallocation of the packet
     182
     183  // Send via reliable or standard channel respectively
    177184  if( this->flags_ & PacketFlag::Reliable )
    178185    host->addPacket( enetPacket_, peerID_, NETWORK_CHANNEL_DEFAULT);
    179186  else
    180187    host->addPacket( enetPacket_, peerID_, NETWORK_CHANNEL_UNRELIABLE);
     188
    181189  return true;
    182190}
    183191
     192/**
     193 * Given an ENetPacket, create an Orxonox packet
     194 * @param packet The ENetPacket
     195 * @param peerID The sender
     196 */
    184197Packet *Packet::createPacket(ENetPacket* packet, uint32_t peerID)
    185198{
    186199  uint8_t *data = packet->data;
    187 //   assert(ClientInformation::findClient(&peer->address)->getID() != static_cast<unsigned int>(-2) || !Host::isServer());
    188 //   unsigned int peerID = ClientInformation::findClient(&peer->address)->getID();
    189   // HACK
    190 //   if( peerID==static_cast<unsigned int>(-2))
    191 //     peerID = NETWORK_PEER_ID_SERVER;
    192200  Packet *p = nullptr;
    193 //   orxout(verbose_ultra, context::packets) << "packet type: " << *(Type *)&data[_PACKETID] << endl;
    194201  switch( *(Type *)(data + _PACKETID) )
    195202  {
    196203    case Type::Acknowledgement:
    197 //       orxout(verbose_more, context::packets) << "ack" << endl;
    198     p = new Acknowledgement( data, peerID );
     204      p = new Acknowledgement( data, peerID );
    199205      break;
    200206    case Type::Chat:
    201 //       orxout(verbose_more, context::packets) << "chat" << endl;
    202207      p = new Chat( data, peerID );
    203208      break;
    204209    case Type::ClassID:
    205 //       orxout(verbose_more, context::packets) << "classid" << endl;
    206210      p = new ClassID( data, peerID );
    207211      break;
    208212    case Type::Gamestate:
    209 //       orxout(verbose_more, context::packets) << "gamestate" << endl;
    210213      p = new Gamestate( data, peerID );
    211214      break;
    212215    case Type::Welcome:
    213 //       orxout(verbose_more, context::packets) << "welcome" << endl;
    214216      p = new Welcome( data, peerID );
    215217      break;
    216218    case Type::DeleteObjects:
    217 //       orxout(verbose_more, context::packets) << "deleteobjects" << endl;
    218219      p = new DeleteObjects( data, peerID );
    219220      break;
    220221    case Type::FunctionCalls:
    221 //       orxout(verbose_more, context::packets) << "functionCalls" << endl;
    222222      p = new FunctionCalls( data, peerID );
    223223      break;
    224224    case Type::FunctionIDs:
    225 //       orxout(verbose_more, context::packets) << "functionIDs" << endl;
    226225      p = new FunctionIDs( data, peerID );
    227226      break;
     
    247246  // Get our Packet from a global map with all Packets created in the send() method of Packet.
    248247  Packet::packetMapMutex_.lock();
    249   std::map<size_t, Packet*>::iterator it = packetMap_.find(reinterpret_cast<size_t>(enetPacket));
     248
     249  std::map<size_t, Packet*>::iterator it = Packet::packetMap_.find(reinterpret_cast<size_t>(enetPacket));
    250250  assert(it != packetMap_.end());
     251
    251252  // Make sure we don't delete it again in the destructor
    252253  it->second->enetPacket_ = nullptr;
    253254  delete it->second;
    254255  packetMap_.erase(it);
     256
    255257  Packet::packetMapMutex_.unlock();
    256 //   orxout(verbose_ultra, context::packets) << "PacketMap size: " << packetMap_.size() << endl;
    257258}
    258259
Note: See TracChangeset for help on using the changeset viewer.