⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mucroom.cpp

📁 Jabber code library, developed with c
💻 CPP
📖 第 1 页 / 共 3 页
字号:
      switch( state )      {        case AffiliationOutcast:          newRoA = "outcast";          action = SetOutcast;          break;        case AffiliationNone:          newRoA = "none";          action = SetANone;          break;        case AffiliationMember:          newRoA = "member";          action = SetMember;          break;        case AffiliationAdmin:          newRoA = "admin";          action = SetAdmin;          break;        case AffiliationOwner:          newRoA = "owner";          action = SetOwner;          break;      }    }    Tag *i = new Tag( "item" );    i->addAttribute( "nick", nick );    i->addAttribute( roa, newRoA );    if( !reason.empty() )      new Tag( i, "reason", reason );    const std::string& id = m_parent->getID();    JID j( m_nick.bare() );    Stanza *k = Stanza::createIqStanza( j, id, StanzaIqSet, XMLNS_MUC_ADMIN, i );    m_parent->trackID( this, id, action );    m_parent->send( k );  }  void MUCRoom::requestList( MUCOperation operation )  {    if( !m_parent || !m_joined || !m_roomConfigHandler )      return;    Tag *i = new Tag( "item" );    switch( operation )    {      case RequestVoiceList:        i->addAttribute( "role", "participant" );        break;      case RequestBanList:        i->addAttribute( "affiliation", "outcast" );        break;      case RequestMemberList:        i->addAttribute( "affiliation", "member" );        break;      case RequestModeratorList:        i->addAttribute( "role", "moderator" );        break;      case RequestOwnerList:        i->addAttribute( "affiliation", "owner" );        break;      case RequestAdminList:        i->addAttribute( "affiliation", "admin" );        break;      default:        delete i;        return;        break;    }    const std::string& id = m_parent->getID();    JID j( m_nick.bare() );    Stanza *iq = Stanza::createIqStanza( j, id, StanzaIqGet, XMLNS_MUC_ADMIN, i );    m_parent->trackID( this, id, operation );    m_parent->send( iq );  }  void MUCRoom::storeList( const MUCListItemList items, MUCOperation operation )  {    if( !m_parent || !m_joined )      return;    std::string roa;    std::string value;    switch( operation )    {      case RequestVoiceList:        roa = "role";        value = "participant";        break;      case RequestBanList:        roa = "affiliation";        value = "outcast";        break;      case RequestMemberList:        roa = "affiliation";        value = "member";        break;      case RequestModeratorList:        roa = "role";        value = "moderator";        break;      case RequestOwnerList:        roa = "affiliation";        value = "owner";        break;      case RequestAdminList:        roa = "affiliation";        value = "admin";        break;      default:        return;        break;    }    const std::string& id = m_parent->getID();    Tag *iq = new Tag( "iq" );    iq->addAttribute( "id", id );    iq->addAttribute( "type", "set" );    iq->addAttribute( "to", m_nick.bare() );    Tag *q = new Tag( iq, "query" );    q->addAttribute( "xmlns", XMLNS_MUC_ADMIN );    MUCListItemList::const_iterator it = items.begin();    for( ; it != items.end(); ++it )    {      if( (*it).nick.empty() )        continue;      Tag *i = new Tag( q, "item" );      i->addAttribute( "nick", (*it).nick );      i->addAttribute( roa, value );      if( !(*it).reason.empty() )        new Tag( i, "reason", (*it).reason );    }    m_parent->trackID( this, id, operation );    m_parent->send( iq );  }  void MUCRoom::handlePresence( Stanza *stanza )  {    if( ( stanza->from().bare() != m_nick.bare() ) || !m_roomHandler )      return;    if( stanza->subtype() == StanzaPresenceError )    {      if( m_newNick.empty() )        m_joined = false;      else        m_newNick = "";      m_roomHandler->handleMUCError( this, stanza->error() );    }    else    {      Tag* x = 0;      if( m_roomHandler && ( x = stanza->findChild( "x", "xmlns", XMLNS_MUC_USER ) ) != 0 )      {        MUCRoomParticipant party;        party.flags = 0;        party.nick = new JID( stanza->from() );        party.jid = 0;        party.actor = 0;        party.alternate = 0;        const Tag::TagList& l = x->children();        Tag::TagList::const_iterator it = l.begin();        for( ; it != l.end(); ++it )        {          if( (*it)->name() == "item" )          {            const std::string& affiliation = (*it)->findAttribute( "affiliation" );            if( affiliation == "owner" )              party.affiliation = AffiliationOwner;            else if( affiliation == "admin" )              party.affiliation = AffiliationAdmin;            else if( affiliation == "member" )              party.affiliation = AffiliationMember;            else if( affiliation == "outcast" )              party.affiliation = AffiliationOutcast;            else              party.affiliation = AffiliationNone;            const std::string& role = (*it)->findAttribute( "role" );            if( role == "moderator" )              party.role = RoleModerator;            else if( role == "participant" )              party.role = RoleParticipant;            else if( role == "visitor" )              party.role = RoleVisitor;            else              party.role = RoleNone;            const std::string& jid = (*it)->findAttribute( "jid" );            if( !jid.empty() )              party.jid = new JID( jid );            if( (*it)->hasChild( "actor" ) )            {              const std::string& actor = (*it)->findChild( "actor" )->findAttribute( "jid" );              if( !actor.empty() )                party.actor = new JID( actor );            }            if( (*it)->hasChild( "reason" ) )            {              party.reason = (*it)->findChild( "reason" )->cdata();            }            party.newNick = (*it)->findAttribute( "nick" );          }          else if( (*it)->name() == "status" )          {            const std::string& code = (*it)->findAttribute( "code" );            if( code == "100" )              setNonAnonymous();            else if( code == "101" )            {              // affiliation changed while not in the room. not to be handled here, I guess            }            else if( code == "110" )            {              party.flags |= UserSelf;              m_role = party.role;              m_affiliation = party.affiliation;            }            else if( code == "201" )            {              m_creationInProgress = true;              if( instantRoomHook() || m_roomHandler->handleMUCRoomCreation( this ) )                acknowledgeInstantRoom();            }            else if( code == "210" )              m_nick.setResource( stanza->from().resource() );            else if( code == "301" )              party.flags |= UserBanned;            else if( code == "303" )              party.flags |= UserNickChanged;            else if( code == "307" )              party.flags |= UserKicked;            else if( code == "321" )              party.flags |= UserAffiliationChanged;          }          else if( (*it)->name() == "destroy" )          {            if( (*it)->hasAttribute( "jid" ) )              party.alternate = new JID( (*it)->findAttribute( "jid" ) );            if( (*it)->hasChild( "reason" ) )              party.reason = (*it)->findChild( "reason" )->cdata();            party.flags |= UserRoomDestroyed;          }        }        if( party.flags & UserNickChanged && !party.newNick.empty()            && m_nick.resource() == stanza->from().resource()            && party.newNick == m_newNick )          party.flags |= UserSelf;        if( party.flags & UserNickChanged && party.flags & UserSelf && !party.newNick.empty() )          m_nick.setResource( party.newNick );        party.status = stanza->status();        m_roomHandler->handleMUCParticipantPresence( this, party, stanza->presence() );        delete party.jid;        delete party.nick;        delete party.actor;        delete party.alternate;      }    }  }  void MUCRoom::acknowledgeInstantRoom()  {    if( !m_creationInProgress || !m_parent || !m_joined )      return;    Tag *x = new Tag( "x" );    x->addAttribute( "xmlns", XMLNS_X_DATA );    x->addAttribute( "type", "submit" );    JID j( m_nick.bare() );    const std::string& id = m_parent->getID();    Stanza *iq = Stanza::createIqStanza( j, id, StanzaIqSet, XMLNS_MUC_OWNER, x );    m_parent->trackID( this, id, CreateInstantRoom );    m_parent->send( iq );    m_creationInProgress = false;  }  void MUCRoom::cancelRoomCreation()  {    if( !m_creationInProgress || !m_parent || !m_joined )      return;    Tag *x = new Tag( "x" );    x->addAttribute( "xmlns", XMLNS_X_DATA );    x->addAttribute( "type", "cancel" );    JID j( m_nick.bare() );    const std::string& id = m_parent->getID();    Stanza *iq = Stanza::createIqStanza( j, id, StanzaIqSet, XMLNS_MUC_OWNER, x );    m_parent->trackID( this, id, CancelRoomCreation );    m_parent->send( iq );    m_creationInProgress = false;  }  void MUCRoom::requestRoomConfig()  {    if( !m_parent || !m_joined )      return;    JID j( m_nick.bare() );    const std::string& id = m_parent->getID();    Stanza *iq = Stanza::createIqStanza( j, id, StanzaIqGet, XMLNS_MUC_OWNER, 0 );    m_parent->trackID( this, id, RequestRoomConfig );    m_parent->send( iq );    if( m_creationInProgress )      m_creationInProgress = false;  }  void MUCRoom::setNonAnonymous()  {    m_flags |= FlagNonAnonymous;    m_flags &= ~FlagSemiAnonymous;    m_flags &= ~FlagFullyAnonymous;  }  void MUCRoom::setSemiAnonymous()  {    m_flags &= ~FlagNonAnonymous;    m_flags |= FlagSemiAnonymous;    m_flags &= ~FlagFullyAnonymous;  }  void MUCRoom::setFullyAnonymous()  {    m_flags &= ~FlagNonAnonymous;    m_flags &= ~FlagSemiAnonymous;    m_flags |= FlagFullyAnonymous;  }  void MUCRoom::handleMessage( Stanza *stanza, MessageSession * /*session*/ )  {    if( !m_roomHandler )      return;    if( stanza->subtype() == StanzaMessageError )    {      m_roomHandler->handleMUCError( this, stanza->error() );    }    else    {      Tag *x;      if( ( x = stanza->findChild( "x", "xmlns", XMLNS_MUC_USER ) ) != 0 )      {        const Tag::TagList& l = x->children();        Tag::TagList::const_iterator it = l.begin();        for( ; it != l.end(); ++it )        {          if( (*it)->name() == "status" )          {            const std::string& code = (*it)->findAttribute( "code" );            if( code == "100" )            {              setNonAnonymous();            }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -