示例#1
0
bool BanIPMgr_Impl::ReadBans( )
{
	CButeMgr banBute;
	banBute.Parse( "BanList.txt" );

	char szBanKey[128] = "";
	char szClientIP[16] = "";
	int nBanIndex = 0;

	// Read in the current set of bans.
	while( 1 )
	{
		// Read the next banned IP.
		sprintf( szBanKey, "Ban%d", nBanIndex );
		banBute.GetString( "Bans", szBanKey, "", szClientIP, ARRAY_LEN( szClientIP ));

		// If we didn't find one, the stop looking.
		if( !banBute.Success( ))
			break;

		// Add the ban.
		AddBan( szClientIP );
		nBanIndex++;
	}	

	return true;
}
示例#2
0
bool BanIPMgr_Impl::AddBan( char const* pszBanIP )
{
	ClientIP bannedIP;
	if( !ConvertClientIPFromString( pszBanIP, bannedIP ))
		return false;

	if( !AddBan( bannedIP ))
		return false;
	
	return true;
}
示例#3
0
CBan* CBanManager::AddAccountBan ( const char* szAccount, CClient* pBanner, const char* szReason, time_t tTimeOfUnban )
{
    if ( !IsAccountBanned ( szAccount ) )
	{
		CBan* pBan = AddBan ( pBanner, szReason, tTimeOfUnban );
        pBan->SetSerial ( szAccount );
        SaveBanList ();

        return pBan;
    }

    return NULL;
}
示例#4
0
CBan* CBanManager::AddSerialBan ( const char* szSerial, CClient* pBanner, const char* szReason, time_t tTimeOfUnban )
{
    if ( /*IsValidSerial ( szSerial ) &&*/ !IsSerialBanned ( szSerial ) )
	{
		CBan* pBan = AddBan ( pBanner, szReason, tTimeOfUnban );
        pBan->SetSerial ( szSerial );
        SaveBanList ();

        return pBan;
    }

    return NULL;
}
示例#5
0
void ConBan(IConsole::IResult *pResult, void *pUser, int ClientID)
{
	NETADDR Addr;
	const char *pStr = pResult->GetString(0);
	const char *pReason = "";
	
	if(pResult->NumArguments() > 1)
		pReason = pResult->GetString(1);
	
	if(!net_addr_from_str(&Addr, pStr))
		AddBan(&Addr, pReason);
	else
		dbg_msg("banmaster", "invalid network address to ban");
}
示例#6
0
CBan* CBanManager::AddBan ( const char* szIP, CClient* pBanner, const char* szReason, time_t tTimeOfUnban )
{
    if ( IsValidIP ( szIP ) && !IsSpecificallyBanned ( szIP ) )
    {
        CBan* pBan = AddBan ( pBanner, szReason, tTimeOfUnban );
        pBan->SetIP ( szIP );

        g_pNetServer->AddBan ( szIP );

        // Save the list
        SaveBanList ();
        return pBan;
    }

    return NULL;
}
示例#7
0
CBan* CBanManager::AddAccountBan ( CPlayer* pPlayer, CClient* pBanner, const char* szReason, time_t tTimeOfUnban )
{
    if ( pPlayer )
    {
        if ( !pPlayer->GetSerialUser ().empty() && !IsAccountBanned ( pPlayer->GetSerialUser ().c_str () ) )
	    {
		    CBan* pBan = AddBan ( pBanner, szReason, tTimeOfUnban );
            pBan->SetNick ( pPlayer->GetNick() );
            pBan->SetAccount ( pPlayer->GetSerialUser () );
            SaveBanList ();

            return pBan;
        }
    }

    return NULL;
}
示例#8
0
CBan* CBanManager::AddBan ( CPlayer* pPlayer, CClient* pBanner, const char* szReason, time_t tTimeOfUnban )
{
    if ( pPlayer )
    {
        char szIP[256] = { '\0' };
        pPlayer->GetSourceIP ( szIP );

        if ( IsValidIP ( szIP ) && !IsSpecificallyBanned ( szIP ) )
        {
            CBan* pBan = AddBan ( pBanner, szReason, tTimeOfUnban );
            pBan->SetNick ( pPlayer->GetNick() );
            pBan->SetIP ( szIP );

            g_pNetServer->AddBan ( szIP );

            // Save the list
            SaveBanList ();
            return pBan;
        }
    }

    return NULL;
}
示例#9
0
bool CBanManager::LoadBanList ( void )
{
    // Create the XML
    CXMLFile* pFile = g_pServerInterface->GetXML ()->CreateXML ( m_strPath );
    if ( !pFile )
    {
        return false;
    }

    // Parse it
    if ( !pFile->Parse () )
    {
        delete pFile;
        CLogger::ErrorPrintf ( "Error parsing banlist\n" );
        return false;
    }

    // Grab the XML root node
    CXMLNode* pRootNode = pFile->GetRootNode ();
    if ( !pRootNode )
    {
        pRootNode = pFile->CreateRootNode ( "banlist" );
    }

    // Is the rootnode's name <banlist>?
    if ( pRootNode->GetTagName ().compare ( "banlist" ) != 0 )
    {
        CLogger::ErrorPrintf ( "Wrong root node ('banlist')\n" );
        return false;
    }

    // Iterate the nodes
    CXMLNode* pNode = NULL;
    unsigned int uiCount = pRootNode->GetSubNodeCount ();

    for ( unsigned int i = 0; i < uiCount; i++ )
    {
        // Grab the node
        pNode = pRootNode->GetSubNode ( i );

        if ( pNode )
        {
            if ( pNode->GetTagName ().compare ( "ban" ) == 0 )
            {
                std::string strIP = SafeGetValue ( pNode, "ip" ),
                            strSerial = SafeGetValue ( pNode, "serial" ),
                            strAccount = SafeGetValue ( pNode, "account" );
                if ( !strIP.empty() || !strSerial.empty() || !strAccount.empty() )
                {
                    CBan* pBan = AddBan ();
                    if ( IsValidIP ( strIP.c_str() ) )
                    {
                        pBan->SetIP ( strIP );
                        g_pNetServer->AddBan ( strIP.c_str() );
                    }
                    pBan->SetAccount ( strAccount );
                    pBan->SetSerial ( strSerial );
                    pBan->SetBanner ( SafeGetValue ( pNode, "banner" ) );
                    pBan->SetNick ( SafeGetValue ( pNode, "nick" ) );
                    pBan->SetReason ( SafeGetValue ( pNode, "reason" ) );

                    std::string strTime = SafeGetValue ( pNode, "time" );
                    if ( !strTime.empty() ) pBan->SetTimeOfBan ( ( time_t ) atoi ( strTime.c_str() ) );

                    strTime = SafeGetValue ( pNode, "unban" );
                    if ( !strTime.empty() ) pBan->SetTimeOfUnban ( ( time_t ) atoi ( strTime.c_str() ) );
                }
            }
        }
    }

    delete pFile;
    return true;
}
示例#10
0
void
UpdateChanModes(struct Luser *lptr, char *who, struct Channel *cptr,
                char *modes)

{
  int add;
  char *tmp, *p;
  register char ch;
  struct Luser *userptr;
#if defined(NICKSERVICES) && defined(CHANNELSERVICES)
  int cs_deoped = 0; /* was chanserv deoped? */
#endif

  char **modeargs; /* arguements to +l/k/o/v modes */
  char tempargs[MAXLINE];
  int argcnt; /* number of arguements */
  int argidx; /* current index in modeargs[] */

#ifndef SAVE_TS
  char sendstr[MAXLINE];
#endif

  if (!cptr)
    return;

  assert(lptr || who);

  if (lptr)
  {
    SendUmode(OPERUMODE_M,
      "*** %s: Mode [%s] by %s!%s@%s",
      cptr->name,
      modes,
      lptr->nick,
      lptr->username,
      lptr->hostname);

    putlog(LOG3,
      "%s: mode change \"%s\" by %s!%s@%s",
      cptr->name,
      modes,
      lptr->nick,
      lptr->username,
      lptr->hostname);
  }
  else
  {
    SendUmode(OPERUMODE_M,
      "*** %s: Mode [%s] by %s",
      cptr->name,
      modes,
      who);

    putlog(LOG3,
      "%s: mode change \"%s\" by %s",
      cptr->name,
      modes,
      who);
  }

  if ((tmp = strchr(modes, ' ')))
    strcpy(tempargs, *(tmp + 1) ? tmp + 1 : "");
  else
    tempargs[0] = '\0';

  argcnt = SplitBuf(tempargs, &modeargs);

  /*
   * This routine parses the given channel modes and keeps
   * the corresponding lists correctly updated - also make
   * sure OperServ and ChanServ remain opped
   */

  add = 0;
  argidx = (-1);

  for (tmp = modes; *tmp; ++tmp)
  {
    ch = *tmp;

    if (IsSpace(ch))
      break;

    switch (ch)
    {
      case ' ':
      case '\n':
      case '\r': break;

      case '-':
      {
        add = 0;
        break;
      }
      case '+':
      {
        add = 1;
        break;
      }

      /*
       * Op/DeOp
       */
      case 'o':
      {
        ++argidx;
        if (argidx >= argcnt)
        {
          /*
           * there are more 'o' flags than there are nicknames,
           * just break
           */
          break;
        }

        if (!(userptr = FindClient(modeargs[argidx])))
          break;

        SetChannelMode(cptr, add, MODE_O, userptr, 0);

        if (add)
        {
        #ifdef STATSERVICES
          if (lptr)
            ++lptr->numops;
        #endif
        } /* if (add) */
        else
        {
          if (userptr == Me.osptr)
          {
            if (!FloodCheck(cptr, lptr, Me.osptr, 0))
            {
	      #ifdef SAVE_TS
                os_part(cptr);
                os_join(cptr);
	      #else
                toserv(":%s MODE %s +o %s\n",
                  n_OperServ,
                  cptr->name,
                  n_OperServ);
	      #endif
            }

            if (!lptr)
            {
              putlog(LOG1, "%s: %s attempted to deop %s",
                cptr->name,
                who,
                n_OperServ);
            }
            else
            {
              putlog(LOG1, "%s: %s!%s@%s attempted to deop %s",
                cptr->name,
                lptr->nick,
                lptr->username,
                lptr->hostname,
                n_OperServ);
            }
          }
        #if defined(NICKSERVICES) && defined(CHANNELSERVICES)
          else if (userptr == Me.csptr)
          {
            cs_deoped = 1;
          }
        #endif /* defined(NICKSERVICES) && defined(CHANNELSERVICES) */

        #ifdef STATSERVICES
          if (lptr)
            ++lptr->numdops;
        #endif
        } /* else if (!add) */

        #if defined(NICKSERVICES) && defined(CHANNELSERVICES)
          cs_CheckModes(lptr,
            FindChan(cptr->name),
            !add,
            MODE_O,
            userptr);
        #endif

        break;
      } /* case 'o' */

      /*
       * Voice/DeVoice
       */
      case 'v':
      {
        ++argidx;
        if (argidx >= argcnt)
          break;

        if (!(userptr = FindClient(modeargs[argidx])))
          break;

        SetChannelMode(cptr, add, MODE_V, userptr, 0);

        if (add)
        {
        #ifdef STATSERVICES
          if (lptr)
            ++lptr->numvoices;
        #endif
        }
        else
        {
        #ifdef STATSERVICES
          if (lptr)
            ++lptr->numdvoices;
        #endif
        } /* else if (!add) */

      #if defined(NICKSERVICES) && defined(CHANNELSERVICES)
        cs_CheckModes(lptr,
          FindChan(cptr->name),
          !add,
          MODE_V,
          userptr);
      #endif

        break;
      } /* case 'v' */

#ifdef HYBRID7
      /* HalfOp/DeHalfOp -Janos */
      case 'h':
      {
        ++argidx;
        if (argidx >= argcnt)
          break;

        if (!(userptr = FindClient(modeargs[argidx])))
          break;

        SetChannelMode(cptr, add, MODE_H, userptr, 0);

        if (add)
        {
#ifdef STATSERVICES
          if (lptr)
            ++lptr->numhops;
#endif
        }
        else
        {
#ifdef STATSERVICES
          if (lptr)
            ++lptr->numdhops;
#endif
        } /* else if (!add) */

#if defined(NICKSERVICES) && defined(CHANNELSERVICES)
        cs_CheckModes(lptr, FindChan(cptr->name), !add, MODE_H, userptr);
#endif
        break;
      } /* case 'h'*/
#endif /* HYBRID7 */

      /*
       * Channel limit
       */
      case 'l':
      {
        if (add)
        {
          ++argidx;
          if (argidx >= argcnt)
            break;

          cptr->limit = atoi(modeargs[argidx]);
        }
        else
          cptr->limit = 0;

      #if defined(NICKSERVICES) && defined(CHANNELSERVICES)
        cs_CheckModes(lptr,
          FindChan(cptr->name),
          !add,
          MODE_L,
          0);
      #endif

        break;
      } /* case 'l' */

      /*
       * Channel key
       */
      case 'k':
      {
        ++argidx;
        if (argidx >= argcnt)
          break;

      #ifndef BLOCK_ALLOCATION
        if (cptr->key)
          MyFree(cptr->key);
      #endif

        if (add)
        {
        #ifdef BLOCK_ALLOCATION
          strncpy(cptr->key, modeargs[argidx], KEYLEN);
          cptr->key[KEYLEN] = '\0';
        #else
          cptr->key = MyStrdup(modeargs[argidx]);
        #endif /* BLOCK_ALLOCATION */
        }
        else
        {
        #ifdef BLOCK_ALLOCATION
          cptr->key[0] = '\0';
        #else
          cptr->key = 0;
        #endif /* BLOCK_ALLOCATION */
        }

      #if defined(NICKSERVICES) && defined(CHANNELSERVICES)
        cs_CheckModes(lptr,
          FindChan(cptr->name),
          !add,
          MODE_K,
          0);
      #endif

        break;
      } /* case 'k' */

      /*
       * Channel forwarding target
       */
      case 'f':
      {
        ++argidx;
        if (argidx >= argcnt)
          break;

      #ifndef BLOCK_ALLOCATION
        if (cptr->forward)
          MyFree(cptr->forward);
      #endif

        if (add)
        {
        #ifdef BLOCK_ALLOCATION
          strncpy(cptr->forward, modeargs[argidx], CHANNELLEN);
          cptr->forward[CHANNELLEN] = '\0';
        #else
          cptr->forward = MyStrdup(modeargs[argidx]);
        #endif /* BLOCK_ALLOCATION */
        }
        else
        {
        #ifdef BLOCK_ALLOCATION
          cptr->forward[0] = '\0';
        #else
          cptr->forward = 0;
        #endif /* BLOCK_ALLOCATION */
        }

      #if defined(NICKSERVICES) && defined(CHANNELSERVICES)
        cs_CheckModes(lptr,
          FindChan(cptr->name),
          !add,
          MODE_F,
          0);
      #endif

        break;
      } /* case 'f' */

      /*
       * Channel ban
       */
      case 'b':
      {
        ++argidx;
        if (argidx >= argcnt)
          break;

	/* if it's a forwarding ban like nick!ident@host!#channel
	 * just drop the forward channel
	 * found by CheeToS  -- jilles */
	p = strchr(modeargs[argidx], '!');
	if (p != NULL)
	{
	  p = strchr(p + 1, '!');
	  if (p != NULL)
	    *p = '\0';
	}

        if (add)
          AddBan(who, cptr, modeargs[argidx]);
        else
          DeleteBan(cptr, modeargs[argidx]);

	if (p != NULL)
	  *p = '!';

        break;
      } /* case 'b' */

#ifdef GECOSBANS
      /*
       * Channel deny
       */
      case 'd':
      {
        ++argidx;
        if (argidx >= argcnt)
          break;

        if (add)
          AddGecosBan(who, cptr, modeargs[argidx]);
        else
          DeleteGecosBan(cptr, modeargs[argidx]);

        break;
      } /* case 'd' */
#endif /* GECOSBANS */

      /*
       * Channel exception
       */
      case 'e':
      {
        ++argidx;
        if (argidx >= argcnt)
          break;

        if (add)
          AddException(who, cptr, modeargs[argidx]);
        else
          DeleteException(cptr, modeargs[argidx]);

        break;
      } /* case 'e' */

#ifdef HYBRID7
    /* Channel invite exception -Janos */
     case 'I':
     {
       ++argidx;
       if (argidx >= argcnt)
         break;

       if (add)
         AddInviteException(who, cptr, modeargs[argidx]);
       else
         DeleteInviteException(cptr, modeargs[argidx]);
       break;
     } /* case 'I' */
#endif /* HYBRID7 */

      default:
      {
        int modeflag = 0;

        if (ch == 's')
          modeflag = MODE_S;
        else if (ch == 'p')
          modeflag = MODE_P;
        else if (ch == 'n')
          modeflag = MODE_N;
        else if (ch == 't')
          modeflag = MODE_T;
        else if (ch == 'm')
          modeflag = MODE_M;
        else if (ch == 'i')
          modeflag = MODE_I;
        else if (ch == 'r')
          modeflag = MODE_R;
        else if (ch == 'z')
          modeflag = MODE_Z;
        else if (ch == 'P')
          modeflag = MODE_CAPP;
#if 0
        /* doesn't exist in 1.0.34 */
        else if (ch == 'F')
          modeflag = MODE_CAPF;
#endif
        else if (ch == 'Q')
          modeflag = MODE_CAPQ;
#ifdef HYBRID7
        else if (ch == 'a')
          modeflag = MODE_A;
#endif 
        else if (ch == 'c')
          modeflag = MODE_C;
        else if (ch == 'g')
          modeflag = MODE_G;
        else if (ch == 'L')
          modeflag = MODE_CAPL;
        else if (ch == 'R')
          modeflag = MODE_CAPR;

        if (modeflag)
        {
          if (add)
            cptr->modes |= modeflag;
          else
            cptr->modes &= ~modeflag;
        }

      #if defined(NICKSERVICES) && defined(CHANNELSERVICES)
        if (modeflag)
          cs_CheckModes(lptr,
            FindChan(cptr->name),
            !add,
            modeflag,
            0);
      #endif

        break;
      } /* default: */
    } /* switch (*tmp) */
  } /* for (tmp = modes; *tmp; ++tmp) */

  MyFree(modeargs);

#if defined(NICKSERVICES) && defined(CHANNELSERVICES)
  if ((cs_deoped) && (!FloodCheck(cptr, lptr, Me.csptr, 0)))
  {
    /* reop ChanServ */
    #ifdef SAVE_TS
      cs_part(cptr);
      cs_join(FindChan(cptr->name));
    #else
      toserv(":%s MODE %s +o %s\n",
        n_ChanServ,
        cptr->name,
        n_ChanServ);
    #endif

    if (!lptr)
      putlog(LOG1, "%s: %s attempted to deop %s",
        cptr->name,
        who,
        n_ChanServ);
    else
      putlog(LOG1, "%s: %s!%s@%s attempted to deop %s",
        cptr->name,
        lptr->nick,
        lptr->username,
        lptr->hostname,
        n_ChanServ);
  }
#endif /* defined(NICKSERVICES) && defined(CHANNELSERVICES) */

} /* UpdateChanModes() */
示例#11
0
void CChannel::SetModes ( const CString& szModes, const std::vector < CString >& vecModeParams )
{
    unsigned int uiParamIndex = 0;
    enum { ADD, DEL } eDirection = ADD;
    CServer& me = CProtocol::GetSingleton ().GetMe ();

    const char* p = szModes.c_str ();
    while ( *p != '\0' )
    {
        switch ( *p )
        {
        case '+':
        {
            eDirection = ADD;
            break;
        }
        case '-':
        {
            eDirection = DEL;
            break;
        }
        default:
        {
            unsigned long ulMode = ms_ulChannelModes [ (unsigned char)*p ];
            if ( ulMode != 0 )
            {
                if ( ulMode < CMODE_PARAMSMAX )
                {
                    if ( eDirection == ADD )
                        m_ulModes |= ulMode;
                    else
                        m_ulModes &= ~ulMode;

                    if ( ulMode >= CMODE_MAX )
                    {
                        // El modo lleva parámetros
                        switch ( ulMode )
                        {
                        case CMODE_KEY:
                            if ( eDirection == ADD )
                                SetKey ( vecModeParams [ uiParamIndex ] );
                            else
                                SetKey ( "" );
                            ++uiParamIndex;
                            break;
                        case CMODE_LIMIT:
                            if ( eDirection == ADD )
                            {
                                SetLimit ( atoi ( vecModeParams [ uiParamIndex ] ) );
                                ++uiParamIndex;
                            }
                            else
                                SetLimit ( 0 );
                            break;
                        }
                    }
                }
                else
                {
                    // Cambiamos flags de usuarios o bans
                    if ( ulMode == CFLAG_BAN )
                    {
                        if ( eDirection == ADD )
                            AddBan ( vecModeParams [ uiParamIndex ] );
                        else
                            RemoveBan ( vecModeParams [ uiParamIndex ] );
                        ++uiParamIndex;
                    }
                    else
                    {
                        CUser* pUser = me.GetUserAnywhere ( base64toint ( vecModeParams [ uiParamIndex ] ) );
                        ++uiParamIndex;

                        if ( pUser )
                        {
                            CMembership* pMembership = GetMembership ( pUser );
                            if ( pMembership )
                            {
                                unsigned long ulCurFlags = pMembership->GetFlags ();
                                if ( eDirection == ADD )
                                    pMembership->SetFlags ( ulCurFlags | ulMode );
                                else
                                    pMembership->SetFlags ( ulCurFlags & ~ulMode );
                            }
                        }
                    }
                }
            }
        }
        }
        ++p;
    }
}