home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 June / ENTER.ISO / files / xampp-win32-1.4.5-installer.exe / xampp / HOWTO < prev    next >
Encoding:
Text File  |  2004-03-24  |  4.8 KB  |  133 lines

  1. /**
  2.  * $Id: HOWTO,v 1.2 2003/01/16 23:02:34 meebey Exp $
  3.  * $Revision: 1.2 $
  4.  * $Author: meebey $
  5.  * $Date: 2003/01/16 23:02:34 $
  6.  *
  7.  * Copyright (c) 2002-2003 Mirco "MEEBEY" Bauer <mail@meebey.net> <http://www.meebey.net>
  8.  * 
  9.  * Full LGPL License: <http://www.meebey.net/lgpl.txt>
  10.  * 
  11.  * This library is free software; you can redistribute it and/or
  12.  * modify it under the terms of the GNU Lesser General Public
  13.  * License as published by the Free Software Foundation; either
  14.  * version 2.1 of the License, or (at your option) any later version.
  15.  *
  16.  * This library is distributed in the hope that it will be useful,
  17.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  19.  * Lesser General Public License for more details.
  20.  *
  21.  * You should have received a copy of the GNU Lesser General Public
  22.  * License along with this library; if not, write to the Free Software
  23.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  24.  */
  25.  
  26. Mini-HowTo for Net_SmartIRC
  27. -------------------------------
  28.  
  29. Contents
  30. - Write your bot methods
  31. - Creating an object of Net_SmartIRC
  32. - Get Net_SmartIRC set up right
  33. - Register actionhandlers for your bot methods
  34. - Get things happen
  35. - Test the bot
  36. - Smart words
  37.  
  38. Here is a guide for setting up the Net_SmartIRC and using it for a little IRC bot.
  39. ie.. You want to create a bot that reacts when the message in a channel is "!test".
  40.  
  41. Write your bot methods:
  42. ----------------------
  43. First you have to write your methods that will be executed when the event ("!test") happens.
  44. The imported thing is that the methods you write have to be methods in a class,
  45. since PHP doesn't allow references to normal PHP functions, only to objects...
  46. All methods you write have to have _2_ parameters and use a '&' in front of the variable name.
  47. With "function yourfunction( &$irc, &$data )" you are on the good side.
  48.  
  49. The objectname for Net_SmartIRC we use in this howto is $irc
  50. After your class, you must make a object out of it, so Net_SmartIRC can call later your
  51. defined methods.
  52.  
  53. Example:
  54. class mybot
  55. {
  56.     function test_command(&$irc, &$data)
  57.     {
  58.         $irc->message(SMARTIRC_TYPE_CHANNEL, '#bots', $data->nick.': no I don't like tests!');
  59.     }
  60. }
  61.  
  62. $mybot = &new mybot();
  63.  
  64. this will send a channel message to the #bots channel and will tell the guy who said !test, that the bot
  65. doesn't like tests..
  66.  
  67. Creating an object of Net_SmartIRC:
  68. ------------------------------------
  69. If you want to use Net_SmartIRC for your program/script you first have to create a object of the class
  70. before you can use the methods or the class itself.
  71. Here is an example:
  72. include('SmartIRC.php');
  73. $irc = &new Net_SmartIRC();
  74.  
  75. now you can call the methods of the class, with $irc->METHODNAME....
  76.  
  77. Get Net_SmartIRC set up right:
  78. -------------------------------
  79. Before you can let the Net_SmartIRC do the IRC handling for you, you first have to tell it which server, username, realname etc..
  80. if you want to use real sockets instead of fsocks you would do this (highly recommend):
  81. $irc->setUseSockets(true);
  82.  
  83. or if you want to get debug messages for testing:
  84. $irc->setDebug(SMARTIRC_DEBUG_ALL);
  85.  
  86. for all settings see the DOCUMENTATION file.
  87.  
  88. Register actionhandlers for your bot methods:
  89. -----------------------------------------
  90. You have a !test method but no relation to Net_SmartIRC yet.
  91. All your bot methods must be registered, or they won't be called, because Net_SmartIRC doesn't
  92. know them... logical...
  93. The test_command() method should be called when someone says "!test" in the channels where the bot is.
  94. Here is an example:
  95. $irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL, '!test', &$mybot, 'test_command');
  96.  
  97. This tells Net_SmartIRC to call method called "test_command" from the object $mybot, when
  98. a message in a channel is "!test"...
  99. There are also different message types. These you will find in DOCUMENTATION 
  100.  
  101. Ok now we have everything ready to go!
  102.  
  103. Get things happening:
  104. -------------------
  105. connect to the IRC server and port:
  106. $irc->connect('irc.server.net', 6667);
  107.  
  108. login with nickname, realname, usermode, username:
  109. $irc->login('MyBot', 'MyBotty Bot', 0,'MyBotty');
  110.  
  111. let the bot join a channel
  112. $irc->join('#bots');
  113.  
  114. now wait for the actionhandlers to happen, or idle:
  115. $irc->listen();
  116.  
  117. If the function listen() will return because of a return signal, 
  118. then we should make a clean disconnect from the IRC server.
  119. $irc->disconnect();
  120.  
  121. Test the bot:
  122. -----------
  123. Spawn the bot with this command "php yourbot.php" (assumes that you have the CGI/CLI version of PHP)
  124. Now just join the same IRC server that the bot is on and goto #bots
  125. and say !test
  126. You should get the "yourNickname: I don't like test" reply from your bot,
  127. yeah thats it... pretty easy if you wrote some methods...
  128.  
  129. Smart words:
  130. -----------
  131. And don't forget, all people on IRC are humans like you and me, be friendly and respect everyone
  132. like you want to be respected!
  133.