Logo Search packages:      
Sourcecode: verlihub version File versions

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

Treat the DC message in a appropriate way

Definition at line 787 of file cdcproto.cpp.

References nUtils::cTime::AsPeriod(), nDirectConnect::cUser::Can(), nDirectConnect::cConnDC::CloseNice(), nUtils::cPCRE::Compare(), nDirectConnect::cServerDC::DCKickNick(), nDirectConnect::cServerDC::DCPublicHS(), nUtils::cPCRE::Exec(), nUtils::cPCRE::Extract(), nDirectConnect::nTables::cDCConf::int_chat_ms, cObj::Log(), cObj::LogStream(), nDirectConnect::nTables::cDCConf::mainchat_class, nDirectConnect::cServerDC::mC, nDirectConnect::cServerDC::mCallBacks, nDirectConnect::cServerDC::mChatUsers, nDirectConnect::cUserBase::mClass, nDirectConnect::cUser::mFloodHashes, nUtils::cTime::MiliSec(), nDirectConnect::cServerDC::MinDelayMS(), nDirectConnect::cUserBase::mInList, mKickChatPattern, nDirectConnect::cUserBase::mNick, nDirectConnect::cConnDC::mpUser, nDirectConnect::cUser::mT, nServer::cAsyncSocketServer::mTime, ParseForCommands(), nUtils::cPCRE::PartFound(), nUtils::cTime::Sec(), nDirectConnect::cUserCollection::SendToAll(), and nDirectConnect::nProtocol::cMessageDC::SplitChunks().

{
      if(msg->SplitChunks()) return -1;
      if(!conn->mpUser) return -2;
      if(!conn->mpUser->mInList) return -3;
      if(!conn->mpUser->Can(eUR_CHAT, mS->mTime.Sec(), 0)) return -4;

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

      stringstream omsg;
      bool send=false;
      // set minimum chat delay
      long delay=mS->mC.int_chat_ms; 
      if(conn->mpUser->mClass >=  eUC_VIPUSER) delay=0;

      // check if nick is ok
      if( (msg->ChunkString(eCH_CH_NICK) != conn->mpUser->mNick) )
      {
            omsg << "You are not " << msg->ChunkString(eCH_CH_NICK) << ".";
            mS->DCPublicHS(omsg.str(),conn);
            if(conn->Log(2))
                  conn->LogStream() << "Claims to be " << msg->ChunkString(eCH_CH_NICK) << " in chat." << endl;
            conn->CloseNice(1000, eCR_CHAT_NICK);
            return -2;
      }

      string &text= msg->ChunkString(eCH_CH_MSG);

      // check if delay is ok, yet here
      if(!mS->MinDelayMS(conn->mpUser->mT.chat,delay))
      {
            cTime now;
            cTime diff=now-conn->mpUser->mT.chat;
            omsg << "Not sent: " <<  text << endl << "Minimum delay for chat is: " << delay << "ms. And you made: " << diff.AsPeriod() << " " << diff.MiliSec();
            mS->DCPublicHS(omsg.str(),conn);
            return 0;
      }

      send = true;


      if(ParseForCommands(text, conn)) return 0;
      if(conn->mpUser->mClass < mS->mC.mainchat_class)
      {
            mS->DCPublicHS("Mainchat is currently disabled for non registered users.",conn);
            return 0;
      }
      ////////// here is the part that finally distributes messages
      // check message length only for less than vip regs
      if(conn->mpUser->mClass < eUC_VIPUSER && !cDCProto::CheckChatMsg(text, conn)) 
            return 0;

      // if this is a kick message, process it separately
      if( (mKickChatPattern.Exec(text) >= 4) &&
            (
                  !mKickChatPattern.PartFound(1) ||
                  (mKickChatPattern.Compare(2,text,conn->mpUser->mNick) == 0)
            )
      ){
            if (conn->mpUser->mClass >= eUC_OPERATOR)
            {
                  // now it is for sure a kick-like message
                  string kick_reason;
                  mKickChatPattern.Extract(4,text,kick_reason);
                  string nick;
                  mKickChatPattern.Extract(3,text,nick);

                  mS->DCKickNick(NULL, conn->mpUser, nick, kick_reason, cServerDC::eKCK_Reason);
            }
            return 0;
      }

      #ifndef WITHOUT_PLUGINS
      if (!mS->mCallBacks.mOnParsedMsgChat.CallAll(conn, msg))
            send = false;
      #endif

      // finally send the message
      if(send) mS->mChatUsers.SendToAll(msg->mStr);
      return 0;
}


Generated by  Doxygen 1.6.0   Back to index