Logo Search packages:      
Sourcecode: verlihub version File versions

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

Treat the DC message in a appropriate way

Definition at line 667 of file cdcproto.cpp.

References nDirectConnect::cUser::Can(), nUtils::cFreqLimiter::Check(), nDirectConnect::nTables::cDCConf::classdif_pm, nDirectConnect::cConnDC::CloseNow(), nDirectConnect::cUserCollection::ContainsNick(), nDirectConnect::cServerDC::DCPrivateHS(), nDirectConnect::cServerDC::DCPublicHS(), nUtils::cTime::Get(), nDirectConnect::cUserCollection::GetUserBaseByNick(), cObj::Log(), cObj::LogStream(), nDirectConnect::nTables::cDCConf::max_flood_counter_pm, nDirectConnect::cServerDC::mC, nDirectConnect::cServerDC::mCallBacks, nDirectConnect::cUserBase::mClass, nDirectConnect::cUser::mFloodCounters, nDirectConnect::cUser::mFloodHashes, nDirectConnect::cUser::mFloodPM, nDirectConnect::cUserBase::mNick, nDirectConnect::cConnDC::mpUser, nDirectConnect::cServerDC::mRobotList, nServer::cAsyncSocketServer::mTime, nDirectConnect::cServerDC::mUserList, nDirectConnect::cUser::mxConn, nDirectConnect::cServerDC::ReportUserToOpchat(), nUtils::cTime::Sec(), nDirectConnect::cConnDC::Send(), and nDirectConnect::nProtocol::cMessageDC::SplitChunks().

{
      if(msg->SplitChunks()) return -1;
      string &str=msg->ChunkString(eCH_PM_TO);
      ostringstream os;

      if(!conn->mpUser) return -1;
      if(!conn->mpUser->Can(eUR_PM, mS->mTime.Sec(), 0)) return -4;

      // verify sender's nick
      if(
                  msg->ChunkString(eCH_PM_FROM) != conn->mpUser->mNick||
                  msg->ChunkString(eCH_PM_NICK) != conn->mpUser->mNick
            )
      {
            if(conn->Log(1)) conn->LogStream() << "Pretends to be someone else i PM (" << msg->ChunkString(eCH_PM_FROM) << ")." <<endl;
            conn->CloseNow();
            return -1;
      }
      cTime now;
      now.Get();
      int fl = 0;
      fl = - conn->mpUser->mFloodPM.Check(now);
      if((conn->mpUser->mClass < eUC_OPERATOR) && fl )
      {
            if(conn->Log(1)) conn->LogStream() << "Floods PM (" << msg->ChunkString(eCH_PM_FROM) << ")." <<endl;
            if( fl >= 3)
            {
                  mS->DCPrivateHS("Flooding PM", conn);
                  mS->ReportUserToOpchat(conn,string("*** PM Flood detected: ")+msg->ChunkString(eCH_PM_MSG));
                  conn->CloseNow();
            }
            return -1;
      }

      cUser::tFloodHashType Hash = 0;
      Hash = tHashArray<void*>::HashString(msg->ChunkString(eCH_PM_MSG));
      if (Hash && (conn->mpUser->mClass < eUC_OPERATOR))
      {
            if(Hash == conn->mpUser->mFloodHashes[eFH_PM])
            {
                  if( conn->mpUser->mFloodCounters[eFC_PM]++ > mS->mC.max_flood_counter_pm)
                  {
                              mS->DCPrivateHS("Flooding PM", conn);
                              mS->ReportUserToOpchat(conn,string("*** PM Same Message Flood detected: ")+msg->ChunkString(eCH_PM_MSG));
                              conn->CloseNow();
                              return -5;
                  }
            } else {
                  conn->mpUser->mFloodCounters[eFC_PM]=0;
            }
      }
      conn->mpUser->mFloodHashes[eFH_PM] = Hash;

      // find other user
      cUser *other = mS->mUserList.GetUserByNick ( str );
      if(!other) return -2;

      if(conn->mpUser->mClass + mS->mC.classdif_pm < other->mClass)
      {
            mS->DCPrivateHS("You cannot talk to this user.", conn);
            mS->DCPublicHS("You cannot talk to this user.", conn);
            return -4;
      }

      // log it
      if(mS->Log(5)) mS->LogStream()
            << "PM from:" << conn->mpUser->mNick
            << " To: " << msg->ChunkString(eCH_PM_TO) << endl;

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

   // send it
      if(other->mxConn)
      {
            other->mxConn->Send(msg->mStr);
      }
      else if (mS->mRobotList.ContainsNick(str))
      {
            ((cUserRobot*)mS->mRobotList.GetUserBaseByNick(str))->ReceiveMsg(conn, msg);
      }
      return 0;
}


Generated by  Doxygen 1.6.0   Back to index