Logo Search packages:      
Sourcecode: verlihub version File versions

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

Treat the DC message in a appropriate way

Definition at line 128 of file cdcproto.cpp.

References nDirectConnect::nTables::cDCConf::cc_zone, nDirectConnect::cConnDC::ClearTimeOut(), nDirectConnect::cConnDC::CloseNice(), nDirectConnect::cConnDC::CloseNow(), nDirectConnect::cServerDC::ConnCloseMsg(), nDirectConnect::cServerDC::DCHello(), cObj::ErrLog(), nDirectConnect::cConnDC::GetLSFlag(), nDirectConnect::cConnDC::GetTheoricalClass(), nDirectConnect::nTables::cDCConf::hub_name, nDirectConnect::nTables::cDCConf::hub_topic, nDirectConnect::nTables::cDCConf::int_flood_pm_limit, nDirectConnect::nTables::cDCConf::int_flood_pm_period, cObj::Log(), nDirectConnect::nTables::cRegList::Login(), cObj::LogStream(), nDirectConnect::nTables::cDCConf::max_extra_admins, nDirectConnect::nTables::cDCConf::max_extra_cheefs, nDirectConnect::nTables::cDCConf::max_extra_ops, nDirectConnect::nTables::cDCConf::max_extra_regs, nDirectConnect::nTables::cDCConf::max_extra_vips, nDirectConnect::nTables::cDCConf::max_users, nDirectConnect::nTables::cDCConf::max_users_total, nDirectConnect::cServerDC::mC, nDirectConnect::cServerDC::mCallBacks, nDirectConnect::cConnDC::mCC, nDirectConnect::nTables::cRegUserInfo::mClass, nDirectConnect::cUser::mFloodPM, nDirectConnect::cConnDC::mGeoZone, nDirectConnect::cConnDC::mpUser, nDirectConnect::cServerDC::mR, nDirectConnect::cConnDC::mRegInfo, nDirectConnect::nTables::cDCConf::msg_hub_full, nServer::cAsyncSocketServer::mTime, nDirectConnect::cServerDC::mUserCount, nDirectConnect::cServerDC::mUserCountTot, nDirectConnect::cConnDC::NeedsPassword(), nDirectConnect::cUser::Register(), nDirectConnect::cConnDC::Send(), nDirectConnect::cConnDC::SetLSFlag(), nUtils::cFreqLimiter::SetParams(), nDirectConnect::cConnDC::SetTimeOut(), nDirectConnect::cConnDC::SetUser(), nDirectConnect::nProtocol::cMessageDC::SplitChunks(), nDirectConnect::nTables::cDCConf::timeout_length, and nDirectConnect::cServerDC::ValidateUser().

{
      if(msg->SplitChunks()) return -1;
      if(conn->GetLSFlag(eLS_VALNICK)) return -1;

      string &nick = msg->ChunkString(eCH_1_PARAM);
      static string omsg;
      ostringstream os;

      // log this event
      if(conn->Log(3)) conn->LogStream() << "User " << nick << " tries to login" << endl;

      // test valid ip and nick, close conn eventually
      if(!mS->ValidateUser(conn, nick))
      {
            conn->CloseNice(1000,eCR_INVALID_USER);
            return -1;
      }

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

      int limit=mS->mC.max_users_total; // user limit
      int limit_cc = mS->mC.max_users[conn->mGeoZone];
      int limit_extra=0;

      // calculate user's limit
      if(conn->GetTheoricalClass() == eUC_REGUSER ) limit_extra+=mS->mC.max_extra_regs;
      if(conn->GetTheoricalClass() == eUC_VIPUSER ) limit_extra+=mS->mC.max_extra_vips;
      if(conn->GetTheoricalClass() == eUC_OPERATOR) limit_extra+=mS->mC.max_extra_ops;
      if(conn->GetTheoricalClass() == eUC_OPERATOR) limit_extra+=mS->mC.max_extra_cheefs;
      if(conn->GetTheoricalClass() == eUC_ADMIN   ) limit_extra+=mS->mC.max_extra_admins;

      limit += limit_extra;
      limit_cc += limit_extra;

      // Check the max_users limit
      if( (conn->GetTheoricalClass() < eUC_ADMIN) &&
            (mS->mUserCountTot >= limit) ||
            (mS->mC.cc_zone[0].size() && (mS->mUserCount[conn->mGeoZone] >= limit_cc)
            )
      ){
            os << mS->mC.msg_hub_full << "\r\nOnline users =" << mS->mUserCountTot;
            if(conn->Log(2))
            {
                  conn->LogStream()
                        << "Hub is full (" << mS->mUserCountTot
                        << "/" << limit << "::"
                        << mS->mUserCount[conn->mGeoZone] << "/"
                        << limit_cc << "), closing.(" << conn->mCC << ")" << endl;
            }

            mS->ConnCloseMsg(conn,os.str(),1000, eCR_USERLIMIT);
            return -1;
      }else
      {
            conn->SetLSFlag(eLS_ALOWED);
            mS->mUserCountTot ++;
            mS->mUserCount[conn->mGeoZone] ++;
      }

      // send hubname
      cDCProto::Create_HubName(omsg,mS->mC.hub_name,mS->mC.hub_topic);
      conn->Send(omsg);

      if (conn->NeedsPassword())
      {
            omsg="$GetPass";
            conn->Send(omsg);
      }
      else
      { // the user doesn't need password, so he's already in
            mS->DCHello(nick, conn);
            conn->SetLSFlag(eLS_PASSWD);
      }
      try
      {
            cUser *NewUser = new cUser(nick);
            NewUser->mFloodPM.SetParams(0.0, 1. * mS->mC.int_flood_pm_period, mS->mC.int_flood_pm_limit);
            if(!conn->SetUser(NewUser))
            {
                  conn->CloseNow();
                  return -1;
            }
      }catch(...)
      {
            if(mS->ErrLog(2)) mS->LogStream() << "Unhandled exception in cServerDC::DC_ValidateNick" << endl;
            omsg="Sorry :(";
            if(conn->Log(2)) conn->LogStream() << "Fatal error, in SetUser closing.." << endl;
            mS->ConnCloseMsg(conn,omsg,1000);
            return -1;
      }

      if (conn->mRegInfo && (conn->mRegInfo->mClass == eUC_PINGER))
      {
            conn->mpUser->Register();
            mS->mR->Login(conn, nick);
      }
      conn->SetLSFlag(eLS_VALNICK|eLS_NICKLST); // set NICKLST because user may want to skip getting userlist
      conn->ClearTimeOut(eTO_VALNICK);    
      conn->SetTimeOut(eTO_MYINFO, mS->mC.timeout_length[eTO_MYINFO], mS->mTime);
      return 0;
}


Generated by  Doxygen 1.6.0   Back to index