Bạn ghé thăm diễn đàn lần đầu? hãy đăng ký ngay bây giờ để tham gia.
  • Đăng nhập:

Chào mừng bạn đến với ITVNN FORUM - Diễn đàn công nghệ thông tin.

Nếu đây là lần đầu tiên bạn tham gia diễn đàn, xin mời bạn xem phần Hỏi/Ðáp để biết cách dùng diễn đàn. Để có thể tham gia thảo luận bạn phải đăng ký làm thành viên, click vào đây để đăng ký.


  • Partner Area
    • ITVNN HOSTING - Thiết kế website, Cung cấp Domain, Hosting, VPS Việt Nam Anh Hùng - Thông tin truyền thông
kết quả từ 1 tới 1 trên 1

Ðề tài: PHP IRC BOTs

Tăng kích thước phông chữ Giảm kích thước phông chữ
  1. #1
    vuontinh's Avatar

    Trạng thái
    Offline
    Họ tên
    Nguyễn Hồng Phúc
    Tham gia ngày
    Sep 2009
    Thành viên thứ
    342
    Đến từ
    Quảng Trị
    Tuổi
    31
    Giới tính
    Bài gởi
    280
    Level: 39 [?]
    Experience: 1,494,894
    Next Level: 1,757,916
    Cảm ơn 65
    Cảm ơn 131 lần / 62 Bài viết

    Default PHP IRC BOTs  

    In this tutorial , I will explain how to create an IRC bot using PHP

    First , let's explain some things !

    set_time_limit() :
    Set the number of seconds a script is allowed to run. If this is reached, the script returns a fatal error. The default limit is 30 seconds or, if it exists, the max_execution_time value defined in the php.ini.
    When called, set_time_limit() restarts the timeout counter from zero. In other words, if the timeout is the default 30 seconds, and 25 seconds into script execution a call such as set_time_limit(20) is made, the script will run for a total of 45 seconds before timing out.

    Warning :
    This function has no effect when PHP is running in safe mode. There is no workaround other than turning off safe mode or changing the time limit in the php.ini.
    socket_open:
    Opens a new connection to hostname:port and returns its handler.
    fsockopen:
    Initiates a socket connection to the resource specified by hostname .

    Warning :
    UDP sockets will sometimes appear to have opened without an error, even if the remote host is unreachable. The error will only become apparent when you read or write data to/from the socket. The reason for this is because UDP is a "connectionless" protocol, which means that the operating system does not try to establish a link for the socket until it actually needs to send or receive data.
    sleep() :
    Stops execution for a few seconds
    fwrite() :
    writes the contents of string to the file stream pointed to by handle .
    fgets() :
    Gets a line from file pointer.
    explode() :
    Returns an array of strings, each of which is a substring of string formed by splitting it on boundaries formed by the string delimiter .
    str_replace() :
    This function returns a string or an array with all occurrences of search in subject replaced with the given replace value.
    eregi() :
    This function is identical to ereg() except that it ignores case distinction when matching alphabetic characters.
    Now , I finish explaining the functions used in this bot ,
    I initialise two commands in my bot :
    Command 1 : !RooT => it will show you a message contain Members
    Command 2 : !quit => Make the bot quit your channel



    Well , now i think that PHP c0der can create an IRC BOT using PHP

    To run the bot you have to configure it , So you have to change this variables :

    $name_server = "irc.domain.net"; ==> change irc.indoirc.net to your server
    $port_server = 6667; ==> change 6667 to the port used by your server
    $name_bot = "ug.boots"; ==> please, don' t change this name
    $channel = "#kusanghi"; ==> change meister to your channel
    $password = ""; ==> here put the password of your channel
    PHP Code: 
    <?php

    set_time_limit
    (0);

    $name_server "irc.domain.net";
    $port_server 6667;
    $name_bot "ug.boots"// please, don' t change this name :)
    $channel "#kusanghi";
    $password "";

    if (!(
    $socket_open fsockopen($name_server$port_server))) {
             echo 
    "Impossible de se connecter!";
       }
       else {
          
    $header "NICK {$name_bot}\n";
       
    sleep(0.2);
          
    $header .= "USER {$name_bot} 127.0.0.1 {$name_server} : {$name_bot}\n";
       
    sleep(0.2);
          
    $header .= "IDENTIFY {$password}\n";
       
    sleep(0.2);
          
    $header .= "JOIN {$channel}\n";
       }
        
       
    fwrite($socket_open$header);

    while(
    true) {
       while(
    $response fgets($socket_open4096)) {
          
    flush();

          
    $explode explode(" "$response);   
          if(
    $explode[0] == "PING") {
             
    fwrite($socket_open"PONG :{$explode[1]}\n");
          }
          
    sleep(0.1);
       
          
    $command str_replace(array(chr(10), chr(13)), ""$explode[3]);
          if (
    $command == ":!RooT") {
             
    fwrite($socket_open"PRIVMSG {$explode[2]} R00t - Kusanghi - Checker.im : df-pro.net\n\r");
          }
          
    sleep(0.1);
       
          if (
    eregi("meister"$explode[0]) && $command == ":!quit") { // change "meister" with your name :)
             
    fwrite($socket_open"QUIT :{$explode[2]} It's a nice exemple , Try t0 mAke iT BetteR\n\r");
             exit();
          }
          
    sleep(0.1);
       }
    }


 

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Trả lời: 7
    Bài mới gởi: 13-11-2011, 10:03 AM
  2. Trả lời: 3
    Bài mới gởi: 04-06-2011, 11:40 AM
  3. Stop the Registration Bots
    By admin in forum v4.0.x Modifications
    Trả lời: 0
    Bài mới gởi: 17-06-2010, 05:27 PM

Tags for this Thread

Bookmarks

Quuyền Hạn Của Bạn

  • Bạn không thể tạo chủ đề mới
  • Bạn không thể trả lời bài viết
  • Bạn không thể gửi file đính kèm
  • Bạn không thể chỉnh sửa bài viết
  •