EG Information
Training Missions
Knowledge Bank
|
|
Enigma Group's Code Bank
Smiple BotBy: NotMyOwn - Date Submitted: 2008-09-12 00:49:42 <?php /* * Written By: NotMyOwn * Email: admin@unrealcomps.org * * This is for Enigma Group and is ment soley for learning. This bot is in no way advanced, but it is a good learning ground. * Note: \n is basically the same as a human hitting enter and makes it so the command runs, this is ONLY for Linux,for it * to work on Windows, you must use \r\n */ //Main variables $host = "unrealcomps.org"; $port = 6667; $nick = "MyBot"; $chan = "#test"; $readbuffer = ""; //Open the socket to the IRC Host $irc = fsockopen($host, $port, $errno, $errstr, 30); //Checks to see if the connection was made and there were no problems { /*fputs is how you write data to the server, it is basically how you make the bot type Bots don't act exactly like a real person and when start a command you must remember it is typing in the main server window, and not the channel window Commands are capitalized and not used like you would with a client, because when you type /nick in a client it turns out as NICK in the main code*/ //Since you aren't using a client that does ths automatically, we must define it all. //This sets the nickname of the bot ^see variables above to change the nickname^ fputs($irc, "NICK " . $nick . "\n"); //This sets the whois of the bot, since this is a simple bot, it will all just be the nickname repatedly fputs($irc, "USER " . $nick . " " . $nick . " " . $nick . " :" . $nick . "\n"); //This is the command to join the channel, see above to change the channel fputs($irc, "JOIN :" . $chan . "\n"); //This is how you talk on the channel, PRIVMSG is basically like PMing a user on IRC only it is //PMing the whole channel because we are on the main server window, and not the channel fputs($irc, "PRIVMSG " . $chan . " :" . $nick . " is now online\n"); //This will keep the bot running because while in this loop you can never read feof (end-of-file) { //fgets is the opisite of fputs, it gets what as already been displayed on the server $line = fgets($irc, 128); //This echos out the $line so we can see what the server has said //This parses $line into an array so we can select certain vlaues from it (for the commands) and using a space as the dilimeter //which is where it will make a new value, so like this: $text = "this is a sentance"; $text = exploit(" ", $text); print_r($text); //which will display something like this: array('this', 'is', 'a', 'sentance'); //This will mainly be used to keep the bot from timing out, see below for usage //This will in general be the main text a user says $command = trim($line[3]); //Uncomment the below to for debugging and figuring out how long the array is and what $line[#] you should use //print_r($line); //Checks to see if the server has pinged us for a timeout { //If it has, says pong to the server, $line[1] is the server name, because the way pong works is: /pong irc.server.net fputs($irc, "PONG " . $line[1] . "\n"); } //This is how to do a basic command, note: the : is required because if you type something it shows up as :My test on the main code //What is inside the "" is what the command will be, so to use this command, you would type "!quit" without quotes into IRC from a client { //Like I said before, this just basically types things into the channel, this notifys us that the bot has quit fputs($irc, "PRIVMSG " . $chan . " :Connection Closed\n"); ///Closes the connection to the server/host //Ends the php code so it doesn't just keep running forever if you ran it from command line } } //Closes the connection to the server/host //Ends the php code so it doesn't just keep running forever if you ran it from command line } { //If there was an error opening the socket, displays the error and the error number echo "Error: " . $errstr . " | #(" . $errno . ")<br />\n"; }
|
| Return to
php category list |
|
|
Who's Online
487 Guests, 99 Users Diznablo, ckryptix, Nicid1, Ios, viper0i0, rabbidmind, Nasrudin, CollapsingWalls, mehtaparag, bitstrike, jnony, C, Nusquam-Redono-Sapientia, bazcrown, saifulfaizan, The End, Ultraminor, psychomarine, st3alth, themastersinner, pgmrlink, login, lionaneesh, ishkur88, mahraja, Mac, chekifr, gandalf88, Vap0r, t0ast, tantrum6226, BnE, Distorted, Psiber_Syn, Ausome1, invas10n, oldgoat, freedaysbecumei, BinaryShinigami, Rex_Mundi, Red_beard, Strobeflux, s0m3nak3dguy, Descent, teehee, machupicchu, Genetix, Anandarl, NotMyOwn, thegamerdude, Godzila, popo12341234, RedEvolution, velocity_b, myne17, teto111, aVoid, Central-Gsm, 1101, JackalReborn, InjectioN, h4lted, c0re, DisPater, markt4death, splatta, Jackowacko, saint556, Pyron2312, Azerion, howsens, white.hat.gone.bad, vazzilly, pwunkz, Inverted, QuarterCask, Infernoe11, deskata, cr4ck3rj4ck, Blizer, jasonmax, j0sh, gwenwavor, N4g4c3N, spizeyboy, Network X, Uino59, Jae Cee, ianFDK, saykov, medhaavee, zofy, demonkiller410, Stumble, SaMTHG, kishore, Raze, helasraizam, Venom1019 |
| |
|
|
|
|
|