Logo Search packages:      
Sourcecode: verlihub version File versions

int nDirectConnect::nProtocol::cDCProto::DC_Search ( cMessageDC msg,
cConnDC conn 
) [protected]

Treat the DC message in a appropriate way

Definition at line 1012 of file cdcproto.cpp.

References nDirectConnect::cUser::Can(), nDirectConnect::nTables::cDCConf::check_asearch, nDirectConnect::cConnDC::CloseNow(), nDirectConnect::cServerDC::ConnCloseMsg(), nDirectConnect::cServerDC::DCPrivateHS(), nDirectConnect::cServerDC::DCPublicHS(), nDirectConnect::nTables::cDCConf::delayed_search, nDirectConnect::nTables::cDCConf::int_search, nDirectConnect::nTables::cDCConf::int_search_op, nDirectConnect::nTables::cDCConf::int_search_pas, nDirectConnect::nTables::cDCConf::int_search_reg, nDirectConnect::nTables::cDCConf::int_search_vip, cObj::Log(), cObj::LogStream(), nDirectConnect::cServerDC::mActiveUsers, nServer::cAsyncConn::mAddrIP, nDirectConnect::cServerDC::mC, nDirectConnect::cServerDC::mCallBacks, nDirectConnect::cUserBase::mClass, nDirectConnect::cUser::mFloodHashes, nDirectConnect::nTables::cDCConf::min_search_chars, nDirectConnect::nTables::cDCConf::min_share_use_hub, nDirectConnect::cServerDC::MinDelay(), nDirectConnect::cUserBase::mInList, nDirectConnect::cUserBase::mNick, nDirectConnect::cConnDC::mpUser, nDirectConnect::cConnDC::mSRCounter, nDirectConnect::cServerDC::mSysLoad, nDirectConnect::cUser::mT, nServer::cAsyncSocketServer::mTime, nDirectConnect::cServerDC::mUserList, nDirectConnect::nTables::cDCConf::search_share_min, nUtils::cTime::Sec(), nDirectConnect::cUserCollection::SendToAll(), and nDirectConnect::nProtocol::cMessageDC::SplitChunks().

{
      string ostr;
      ostringstream os;
      if(msg->SplitChunks()) return -1;

      // check if user is logged in at least
      if(!conn->mpUser)
      {
            if(conn->Log(1)) conn->LogStream() << "Can't search without user" << endl;
            conn->CloseNow();
            return -1;
      }

      if(!conn->mpUser->Can(eUR_SEARCH, mS->mTime.Sec(), 0))
      {
            if(mS->mC.min_share_use_hub > 0)
            {
                  ReplaceVarInString(mS->mC.search_share_min, "min_share_use_hub", ostr, Simplify(mS->mC.min_share_use_hub));
                  mS->DCPrivateHS(ostr, conn);
            }
            return -4;
      }

      if(conn->mpUser->mClass < eUC_OPERATOR) 
      {
            switch(msg->mType)
            {
                  case eDC_MSEARCH:
                  case eDC_SEARCH:
                        if(msg->ChunkString(eCH_AS_SEARCHPATTERN).size() < mS->mC.min_search_chars) {
                              os << "Minimum search charters is: " << mS->mC.min_search_chars;
                              mS->DCPublicHS(os.str(),conn);
                              return -1;
                        }
                        break;
                  case eDC_MSEARCH_PAS:
                  case eDC_SEARCH_PAS:
                        if(msg->ChunkString(eCH_PS_SEARCHPATTERN).size() < mS->mC.min_search_chars) {
                              os << "Minimum search charters is: " << mS->mC.min_search_chars;
                              mS->DCPublicHS(os.str(),conn);
                              return -1;
                        }
                  break;
                  default: break;
            };
      }

      if (mS->mSysLoad >= (eSL_HURRY + conn->mpUser->mClass))
      {
            if(mS->Log(3)) mS->LogStream() << "Skipping search system is: " << mS->mSysLoad << endl;
            os << "Sorry Hub is busy now, no search, try later..";
            mS->DCPublicHS(os.str(),conn);
            return -2;
      }

      if (!conn->mpUser->mInList)
      {
            return -3;
      }

      cUser::tFloodHashType Hash = 0;
      Hash = tHashArray<void*>::HashString(msg->mStr);
      if (Hash && (conn->mpUser->mClass < eUC_OPERATOR) && (Hash == conn->mpUser->mFloodHashes[eFH_SEARCH]))
      {
            return -4;
      }
      conn->mpUser->mFloodHashes[eFH_SEARCH] = Hash;

      // todo kontorly
      // calculate delay & do some verifications
      int delay=10;
      switch(msg->mType)
      {
            case eDC_MSEARCH:
            case eDC_SEARCH:
                  delay=mS->mC.int_search;
                  if(conn->mpUser->mClass >=  eUC_REGUSER) delay=mS->mC.int_search_reg;
                  if(!CheckIP(conn,msg->ChunkString(eCH_AS_IP))) {
                        if(mS->mC.check_asearch) {
                                          os << "Active Search: Your ip isn't " << msg->ChunkString(eCH_AS_IP) << " but " << conn->mAddrIP << " bye bye.";
                                          mS->ConnCloseMsg(conn, os.str(), 4000, eCR_SYNTAX);
                              return -1;
                        }
                  }
                  break;
            case eDC_MSEARCH_PAS:
            case eDC_SEARCH_PAS:
                  delay=mS->mC.int_search_pas;
                  //delay=int(1.5 * mS->mC.int_search);
                  if(conn->mpUser->mClass >=  eUC_REGUSER) delay=int(1.5 * mS->mC.int_search_reg);
                  if(CHECK_NICK_PSRCH &&conn->mpUser->mNick != msg->ChunkString(eCH_PS_NICK))
                  {
                        //if(conn->Log(1)) conn->LogStream() << "Claims to be someone else in Passive search." << endl;
                        os << "Your nick isn't " << msg->ChunkString(eCH_PS_NICK) << " but " << conn->mpUser->mNick << " bye!";
                        mS->ConnCloseMsg(conn, os.str(),4000, eCR_SYNTAX);
                        return -1;
                  }
                  break;
            default: return -5; break;
      }

      if(conn->mpUser->mClass >=  eUC_VIPUSER) delay=mS->mC.int_search_vip;
      if(conn->mpUser->mClass >=  eUC_OPERATOR) delay=mS->mC.int_search_op;
      // verify the delay
      if(!mS->MinDelay(conn->mpUser->mT.search,delay))
      {
            os << "Minimum search interval is:" << delay << "s";
            mS->DCPublicHS(os.str(),conn);
            return -1;
      }

      // translate MultiSearch to Search
      string omsg(msg->mStr);
      if(msg->mType == eDC_MSEARCH)
      {
            omsg="$Search ";
            omsg+=msg->ChunkString(eCH_AS_ADDR);
            omsg+=' ';
            omsg+=msg->ChunkString(eCH_AS_QUERY);
      }

      #ifndef WITHOUT_PLUGINS
      if (!mS->mCallBacks.mOnParsedMsgSearch.CallAll(conn, msg))
            return -2;
      #endif

      // send message finally
      // todo use classdif_search , sendtoall with minclass
      if(msg->mType == eDC_SEARCH_PAS) {
            conn->mSRCounter = 0;
            mS->mActiveUsers.SendToAll(omsg, mS->mC.delayed_search);
      }
      else
            mS->mUserList.SendToAll(omsg, mS->mC.delayed_search);
      return 0;
}


Generated by  Doxygen 1.6.0   Back to index