Logo Search packages:      
Sourcecode: verlihub version File versions

int nDirectConnect::cServerDC::ValidateUser ( cConnDC conn,
const string &  nick 
)

return 1 if user is valid and can go in return 0 otherwise, and also close the connection

return 1 if user is valid and can go in return 0 otherwise

Definition at line 927 of file cserverdc.cpp.

References nServer::cAsyncConn::AddrIP(), nServer::cAsyncSocketServer::close(), DCPublicHS(), nDirectConnect::nTables::cBan::DisplayUser(), nDirectConnect::nTables::cRegList::FindRegInfo(), nDirectConnect::cConnDC::GetTheoricalClass(), nDirectConnect::nTables::cBanList::IsNickTempBanned(), cObj::Log(), cObj::LogStream(), nDirectConnect::nTables::cDCConf::max_nick, mBanList, nDirectConnect::cConnDC::mCC, nDirectConnect::nTables::cBan::mNick, nDirectConnect::cConnDC::mRegInfo, nDirectConnect::nTables::cDCConf::msg_banned, nDirectConnect::nTables::cDCConf::msg_nick_prefix, nDirectConnect::nTables::cBan::mType, nDirectConnect::nTables::cDCConf::nick_chars, nDirectConnect::nTables::cDCConf::nick_prefix, nDirectConnect::nTables::cDCConf::nick_prefix_cc, nDirectConnect::nTables::cBanList::TestBan(), and ValidateNick().

Referenced by nDirectConnect::nProtocol::cDCProto::DC_ValidateNick().

{
      // first validate the IP and host if any
      stringstream errmsg,os;
      if(!conn) return 0;
      string omsg;
      time_t n;
      bool close=false;

      // phase 1: test nick validity
      // phase 2: test ip/host ban (registered users pass)
      // phase 3: test nickban
      // then we're done

      static cRegUserInfo *sRegInfo = new cRegUserInfo;
      if ((nick.size() < mC.max_nick * 2 ) &&
            mR->FindRegInfo(*sRegInfo,nick) &&
            !conn->mRegInfo )
      {
            conn->mRegInfo = sRegInfo;
            sRegInfo = new cRegUserInfo;
      }

      // validate nick
      
      tVAL_NICK vn=ValidateNick(nick, (conn->GetTheoricalClass() >= eUC_REGUSER ));
      if(vn != eVN_OK)
      {
            close=true;
            errmsg << "Bad nickname: ";
            if (conn->Log(2)) conn->LogStream() << "Bad nick: '" << nick << "' (" << vn << ")" << endl;
      }
      switch(vn)
      {
            case eVN_OK: break;
            case eVN_CHARS: errmsg << "unallowed characters, use these " << mC.nick_chars; break;
            case eVN_SHORT: errmsg << "your nick is too short"; break;
            case eVN_LONG: errmsg << "your nick is too long"; break;
            case eVN_USED: errmsg << "your nick is already used"; break;
            case eVN_PREFIX: errmsg << mC.msg_nick_prefix << mC.nick_prefix; break;
            case eVN_NOT_REGED_OP: errmsg << "not registered operator"; break;
            case eVN_RESERVED: errmsg << "reserved"; break;
            case eVN_BANNED:
                  n = mBanList->IsNickTempBanned(nick) - cTime().Sec();
                  errmsg << "Wait " << n << "sec before reconnecting!!";
                  break;
            default: errmsg << "Uknown error"; break;
      }


      if(close)
      {
            DCPublicHS(errmsg.str(),conn);
            if (conn->Log(3)) conn->LogStream() << "Bad Nick: " << errmsg.str() << endl;
            return 0;
      }

      cBan Ban(this);
      bool banned = false;

      if( conn->GetTheoricalClass() >= eUC_REGUSER )
      {
            banned = mBanList->TestBan(Ban, conn, nick, cBan::eBF_NICK);
            if (banned && !((1 << Ban.mType) & (cBan::eBF_NICK |cBan::eBF_NICKIP))) banned = false;
      }
      else
      {
            //banned = mBanList->IsIPTempBanned(conn->GetSockAddress());
            //if(!banned)
                  banned = mBanList->TestBan(Ban, conn, nick, cBan::eBF_NICKIP | cBan::eBF_RANGE | cBan::eBF_HOST2 | cBan::eBF_HOST1 | cBan::eBF_HOST3 | cBan::eBF_HOSTR1 | cBan::eBF_PREFIX);
      }


      if(banned)
      {
            ReplaceVarInString(mC.msg_banned, "IP", omsg, conn->AddrIP());
            ReplaceVarInString(omsg, "nick", omsg, Ban.mNick);
            errmsg << "Banned." << endl << omsg << endl;
            Ban.DisplayUser(errmsg);
            DCPublicHS(errmsg.str(),conn);
            if(conn->Log(1)) conn->LogStream() << "Unallowed user (" << Ban.mType << "), closing" << endl;
            return 0;
      }

      if(mC.nick_prefix_cc)
      {
            if(conn->mCC.size() && conn->mCC != "--")
            {
                  string Prefix("[");
                  Prefix+=conn->mCC;
                  Prefix+="]";
                  if( 0 != StrCompare(nick,0,4,Prefix))
                  {
                        errmsg << "You need " << Prefix << "In front of your nick" << endl;
                        close = conn->GetTheoricalClass() < eUC_REGUSER;
                  }
            }
      }

      if(close)
      {
            DCPublicHS(errmsg.str(),conn);
            return 0;
      }

      return 1;
}


Generated by  Doxygen 1.6.0   Back to index