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
404 Guests, 116 Users raven001, c0re, Ops, hettoo, apablo, hemiptera, Predatorc, Link-, Bloodmaster25, sameer kumar, damo, Nasrudin, Rex_Mundi, bakiido, N4g4c3N, klesco, destroyer, Bago, Psiber_Syn, psychomarine, darkang3l, m4r71an, shane007, glockz, somisettynaresh, lacanian, iwanlearn, cutie117098, Drakelx, jarlskov, Vahakn, buffer, flower, Brave, KingSpawn, avalor, RedEvolution, tkb2999, EngGi235, dark_void, hacker807, noother, omnipresence, blink_212, NotMyOwn, lgee227, Ghostrider, Calumoo, livinbeneath, deskata, lionaneesh, cracker, data, invas10n, LiquidSnake, TheFender, kcaz, T-Metal, ace386, hulk9914, BinaryShinigami, cd365, st3alth, Burning_Hardware, mark63534, Distorted, Pizza, Lingt, spumoni27, j0sh, KaosFactor, Protagoras, DeKoala, pimpsta5000, computerbp13, Ausome1, enyo, Ultraminor, mm256, Bearmaul, sirEgghead, cracker18, Ashok_thepower, C, aVoid, Base, chaos-angel, ergo, DnA-Ender, InjectioN, Virgin Mary, xXxAngelBabykxXx, obrigadoo, timmy, ishkur88, TrAnE, forty2, SaMTHG, FatalNIX, totalnoob, figjam, knight_pars, snozzberries, naren211, zofy, tucak, strycnine, TheRetech, chekifr, teehee, Zheka, aloksaini, greatness87, tnhtm, piking, nicks_707 |
| |
|
|
|
|
|