home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2005 June / PCpro_2005_06.ISO / files / opensource / xamp / xampp-win32.exe / xampp / example4.php < prev    next >
Encoding:
PHP Script  |  2004-03-24  |  2.6 KB  |  63 lines

  1. <?php
  2. /**
  3.  * $Id: example4.php,v 1.3 2003/01/16 22:29:55 meebey Exp $
  4.  * $Revision: 1.3 $
  5.  * $Author: meebey $
  6.  * $Date: 2003/01/16 22:29:55 $
  7.  *
  8.  * Copyright (C) 2002-2003 Mirco "MEEBEY" Bauer <mail@meebey.net> <http://www.meebey.net>
  9.  * 
  10.  * Full LGPL License: <http://www.meebey.net/lgpl.txt>
  11.  * 
  12.  * This library is free software; you can redistribute it and/or
  13.  * modify it under the terms of the GNU Lesser General Public
  14.  * License as published by the Free Software Foundation; either
  15.  * version 2.1 of the License, or (at your option) any later version.
  16.  *
  17.  * This library is distributed in the hope that it will be useful,
  18.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  20.  * Lesser General Public License for more details.
  21.  *
  22.  * You should have received a copy of the GNU Lesser General Public
  23.  * License along with this library; if not, write to the Free Software
  24.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  25.  */
  26. // ---EXAMPLE OF HOW TO USE Net_SmartIRC---
  27. // this code shows how a mini php bot could be written
  28. include_once('../SmartIRC.php');
  29.  
  30. class mybot
  31. {
  32.     function realname_check(&$irc, &$data)
  33.     {
  34.         // lets loop through all user that are on the #test channel
  35.         // result is send to #smartirc-test (we don't want to spam #test)
  36.         foreach ($irc->channel['#test']->users as $value) {
  37.             $nickname = $value->nick;
  38.             $realname = $value->realname;
  39.             
  40.             // lets match against this realname regex, which wants (capital-letter) *(small-letter) (space) (capital-letter) *(small-letter)
  41.             if(preg_match('/^[A-Z][a-z]+ ([A-Z][a-z]+(\-[A-Z][a-z]+)?)+/', $realname) == 0)
  42.                 $irc->message(SMARTIRC_TYPE_CHANNEL, '#smartirc-test', $nickname.' has not valid realname! ('.$realname.')');
  43.             else 
  44.                 $irc->message(SMARTIRC_TYPE_CHANNEL, '#smartirc-test', $nickname.' approved ('.$realname.')');
  45.         }
  46.         
  47.         $irc->message(SMARTIRC_TYPE_CHANNEL, '#smartirc-test', '<end of realnamecheck>');
  48.     }
  49. }
  50.  
  51. $bot = &new mybot();
  52. $irc = &new Net_SmartIRC();
  53. $irc->setDebug(SMARTIRC_DEBUG_ALL);
  54. $irc->setUseSockets(TRUE);
  55. // activating the channel synching is important, or we won't have $irc->channel[] available
  56. $irc->setChannelSynching(TRUE);
  57. $irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL, '^!realnamecheck', $bot, 'realname_check');
  58. $irc->connect('irc.freenet.de', 6667);
  59. $irc->login('Net_SmartIRC', 'Net_SmartIRC Client '.SMARTIRC_VERSION.' (example4.php)', 8, 'Net_SmartIRC');
  60. $irc->join(array('#smartirc-test','#test'));
  61. $irc->listen();
  62. $irc->disconnect();
  63. ?>