Visualizzazione risultati 1 fino 1 di 1

Discussione: [Php]Bot IRC e POSIX regex

  1. #1
    Guest

    Predefinito [Php]Bot IRC e POSIX regex

    Salve a tutti. Sto scrivendo un bot per irc ad oggetti. Sono fondamentali le regex, per recuperare alcuni dati passati dal socket. Le regex mi stanno proprio antipatiche, fatto sta che sbaglio sempre qualcosa. Il codice è questo:
    Codice PHP:
    <?php
    /*
    Core per un bot. Crea un IRC Bot in modo semplice e facile!
    */
    class Core {
    private
    $server = null;
    private
    $port = 6667;
    private
    $chan = null;
    private
    $log = null;
    public
    $logfile = "log.txt";
    public
    $botname = null;
    public
    $wel = null;
    private
    $sock = null;
    private
    $logp = null;
    private
    $buffer = null;
    public function
    __construct($server,$chan,$botname,$log=true,$wel=true) {
    $this->server = $server;
    $this->chan = $chan;
    $this->botname = $botname;
    $this->log = (!is_bool($log)) ? true : $log;
    $this->wel = (!is_bool($wel)) ? true : $wel;
    }
    public function
    write($msg) {
    return
    fwrite($this->sock, "PRIVMSG {$this->chan} :{$msg}");
    }
    public function
    connect() {
    $this->sock = fsockopen($this->server,$this->port,$errno,$errstr);
    if(!
    is_resource($this->sock))
    die(
    "Errore {$errno}: {$errstr}");
    print
    "Connesso a {$this->server} sulla porta {$this->port}";
    fwrite($this->sock, "USER {$this->botname} {$this->botname} {$this->botname} {$this->botname} :{$this->botname}\r\n");
    fwrite($this->sock, "NICK {$this->botname} \r\n");
    fwrite($this->sock, "JOIN {$this->chan}\r\n");
    }
    public function
    main() {
    while(!
    feof($this->sock)) {
    $this->buffer = fgets($this->sock, 1024);
    print
    $this->buffer;
    if(
    preg_match ("/PING :(.+)/",$this->buffer,$str))
    fwrite($this->sock, "PONG :{$str[1]}");
    if(
    preg_match("/:(.+)!(~{0,1})(.+) JOIN :{$this->chan}/",$this->buffer,$m))
    $this->write("Benvenuto nel canale {$this->chan}, ".$m[1]);
    }
    }
    }
    $i = new Core("irc.azzurra.org","#bots","PBot");
    $i->connect();
    $i->main();
    ?>
    Il metodo incriminato è main(), il secondo if. Il socket, quando un'utente entra nel canale, restituisce questa stringa:
    Codice:
    :Utente!~Utente@Server-1C151990.t2.dsl.vodafone.it JOIN :#canale
    Devo recuperare utente, ma la regex:
    Codice PHP:
    "/:(.+)!(~{0,1})(.+) JOIN :{$this->chan}/"
    non funzia. Qualcuno mi sa aiutare?
    EDIT: risolto, regex corretta:
    Codice:
    "/:(.+)!(~{0,1})(.+)JOIN :{$this->chan}/"
    Ultima modifica di gabryhacker : 01-06-2009 alle ore 17.57.07

Regole di scrittura

  • Non puoi creare nuove discussioni
  • Non puoi rispondere ai messaggi
  • Non puoi inserire allegati.
  • Non puoi modificare i tuoi messaggi
  •