konnwat Posted January 18, 2007 Share Posted January 18, 2007 okay i have a PHP irc bot hosted on a server (not my localhost) and it keeps on leaving at times. theres no pattern, sometimes it leaves after 5 mins of starting, sometimes hours after. but i need it to stay on >:(i thought it was there 3 things but i checked:PHP safe mode is onset_time_limit(0); is in the script and the timeout is at a year :Pthere are no unknown characters anywherewhat is wrong? someone please help me. Quote Link to comment https://forums.phpfreaks.com/topic/34804-php-irc-keeps-leaving/ Share on other sites More sharing options...
tomfmason Posted January 18, 2007 Share Posted January 18, 2007 it could be getting pinged by the server and you are not ponging back.. Can you post the code for your bot. Remove any nicks and passwords before posting.Tom Quote Link to comment https://forums.phpfreaks.com/topic/34804-php-irc-keeps-leaving/#findComment-164030 Share on other sites More sharing options...
konnwat Posted January 18, 2007 Author Share Posted January 18, 2007 yeah i thought it was that, no i got a ping script and i got and "echo $line" and i can see the pings and thats not what disconnects it. Quote Link to comment https://forums.phpfreaks.com/topic/34804-php-irc-keeps-leaving/#findComment-164031 Share on other sites More sharing options...
tomfmason Posted January 18, 2007 Share Posted January 18, 2007 well I could sit here and guess all day but the only real way to tell is by looking at either your logs or the bot.. Or both. Quote Link to comment https://forums.phpfreaks.com/topic/34804-php-irc-keeps-leaving/#findComment-164032 Share on other sites More sharing options...
konnwat Posted January 18, 2007 Author Share Posted January 18, 2007 okay its a bit long though, its about 550 lines :s and it uses a lot of includes to make it simple.[code]<?PHP//add sriposif (!function_exists("stripos")) { function stripos($str,$needle) { return strpos(strtolower($str),strtolower($needle)); }}//connect to IRCset_time_limit(0);//set vars$host = 'irc.barafranca.com';$port = '6667';$nickname = "bot";$channel = file('../bot/channels.txt');//open data.txt$savedline = file('../image/data.txt');$savedline[3] = $savedline[2];$savedline[2] = $savedline[1];$savedline[1] = $savedline[0];$killmode['#chan'] = 'on';$ks = array();//connect$socket = fsockopen($host, $port);stream_set_timeout($socket, 60*60*24*365);fwrite($socket, "NICK ".$nickname."\r\n");fwrite($socket, "USER ".$nickname." 8 * :nick's Bot\r\n");fwrite($socket, "MODE ".$nickname." +B\r\n");while ($line=fgets($socket)) { if (strpos($line, "433")>0) die(); if (strpos($line, "004")>0) { $chancount = count($channel); fwrite($socket, "PRIVMSG nickserv :IDENTIFY bot hello123\r\n"); for ($i = 0; $i < $chancount; $i++) { fwrite($socket, "JOIN ".$channel[$i]."\r\n"); } break; }}//fuctionswhile ($line=fgets($socket)) {$chan = explode("PRIVMSG ", $line);$chan = explode(" :", $chan[1]);$chan = explode("#", $chan[0]);$chan = "#".$chan[1];$nick = explode(":", $line);$nick = explode("!", $nick[1]);$nick = $nick[0];$tempstuff = explode("\r\n", $line);if (stripos($line, ":@")>0) { $tempstuff = explode(":@", $tempstuff[0]);} else { $tempstuff = explode(":!", $tempstuff[0]);}$tempstuff = explode(" ", $tempstuff[1]);$two = $tempstuff[1];$three = $tempstuff[2];$four = $tempstuff[3];?>[/code]and then the scripts are like these[code]if (stripos($line, ":hello bot")>0) { fwrite($socket, "PRIVMSG $chan :hello $nick\r\n");}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/34804-php-irc-keeps-leaving/#findComment-164035 Share on other sites More sharing options...
tomfmason Posted January 18, 2007 Share Posted January 18, 2007 I still don't see where you are ponging back.. Quote Link to comment https://forums.phpfreaks.com/topic/34804-php-irc-keeps-leaving/#findComment-164043 Share on other sites More sharing options...
konnwat Posted January 18, 2007 Author Share Posted January 18, 2007 oh right missed that bit[code]//pong at pingsif (strpos($line,"PING :")===0) {fwrite($socket, "PONG :irc.barafranca.com\r\n");}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/34804-php-irc-keeps-leaving/#findComment-164045 Share on other sites More sharing options...
tomfmason Posted January 18, 2007 Share Posted January 18, 2007 Here is my working bot.. He don't have many features bot it works fine.. You may want to look at it as a general reference.[code]<?phpclass irc_commands{ function message($type, $destination, $message) { switch ($type) { case "ME": return 'PRIVMSG ' . $destination . ' :' . chr(1) . 'ACTION ' . $message . chr(1); break; case "REG": return 'PRIVMSG ' . $destination . ' :' . $message; break; } } function joinChannel($channels) { if (is_array($channels)) { $commands = array(); foreach ($channels as $channel) { $commands[] = 'JOIN' . $channel; } return $commands; }else{ return 'JOIN ' . $channels; } } function partChannel($channels) { if (is_array($channels)) { $commands = array(); foreach($channels as $channel) { $commands[] = 'PART ' . $channel; } return $commands; } else { return 'PART ' . $channels; } } function kick($channel, $nicks, $reason) { if (is_array($nicks)) { $commands = array(); foreach ($nicks as $nick) { $commands[] = 'KICK ' . $channel . ' ' . $nick . ' :' . $reason; } return $commands; } else { return 'KICK' . $channel . ' ' . $nicks . ' :' . $reason; } } function ident($password) { return 'NICKSERV IDENTIFY ' . $password; } function quit($message) { return 'QUIT ' . $message; } }class ircBot extends irc_commands{ var $config = array('server' => 'irc.freenode.net', 'port' => 6667, 'host' => '', 'channel' => '#phpfreaks', 'nick' => '', 'name' => '', 'password' => ''); var $badWords = array('fuck','shit','damn','damm','bitch', 'cunt','whore','hoe','slut','ass'); var $keyPhrases = array('you suck'); var $keyCommands = array('quit','end','shut up','stfu','terminate','talk', 'time','version'); var $con = array(); function cmd_send($command, $con) { $put = fputs($con['sock'], "$command\r\n"); if (!$put) { $error = 'Error : Unable to write to the socket'; print $error . '\n\r'; fwrite($con['fp'], $error, 4096); } else { print "$command\n\r"; fwrite($con['fp'], $command . "\n", 4096); } } function startBot() { $this->con['fp'] = fopen('path/to/log/', 'r+b'); $this->con['sock'] = fsockopen($this->config['server'], $this->config['port']); if (!$this->con['sock']) { $error = "Error: unable to connect to " . $this->config['server'] . '\n\r'; print $error; fwrite($this->fp, $error, 4096); }else{ $this->cmd_send('NICK ' . $this->config['nick'], $this->con); $this->cmd_send('USER ' . $this->config['nick'] . ' ' . $this->config['host'] . ' ' . $this->config['server'] . ' :' . $this->config['name'], $this->con); while (!feof($this->con['sock'])) { $this->con['buffer']['all'] = trim(fgets($this->con['sock'], 4096)); if (strpos($this->con['buffer']['all'], 'NOTICE AUTH :*** Checking ident')) { $this->cmd_send('NICK ' . $this->config['nick'], $this->con); $this->cmd_send('USER ' . $this->config['nick'] . ' ' . $this->config['host'] . ' ' . $this->config['server'] . ' :' . $this->config['name'], $this->con); } else if ($this->con['buffer']['all'] == ':NickServ!NickServ@services. NOTICE ' . $this->config['nick'] . ' :If this is your nickname, type /msg NickServ IDENTIFY <password>') { $command = parent::ident($this->config['password']); $this->cmd_send($command, $this->con); } else if ($this->con['buffer']['all'] == ':services. MODE ' . $this->config['nick'] . ' :+e') { $command = parent::joinChannel($this->config['channel']); $this->cmd_send($command, $this->con); } else if (strpos($this->con['buffer']['all'], $this->config['nick'] . ' !quit')) { $command = parent::quit("Don't hate me because I am bad ass"); $this->cmd_send($command, $this->con); } else if (strpos($this->con['buffer']['all'], $this->config['nick'] . ' you suck')) { $command = parent::message('ME', $this->config['channel'], 'thinks you suck!!'); $this->cmd_send($command, $this->con); } print date("[d/m @ H:i]")."<- ". $this->con['buffer']['all'] . "\n"; fwrite($this->con['fp'], $this->con['buffer']['all'] . "\n", 4096); if (substr($this->con['buffer']['all'], 0, 6) == 'PING :') { $this->cmd_send('PONG :'.substr($this->con['buffer']['all'], 0, 6), $this->con); } } } }}set_time_limit(0);$bot = new ircBot;$bot->startBot(); ?>[/code] Now you may want to pay special attention to this part[code=php:0]f (substr($this->con['buffer']['all'], 0, 6) == 'PING :') { $this->cmd_send('PONG :'.substr($this->con['buffer']['all'], 0, 6), $this->con);} [/code]Well it don't matter what you pong back with but you have to pong something back.. In this case it will be like this PONG :PING.. That works fine..Good Luck,Tom Quote Link to comment https://forums.phpfreaks.com/topic/34804-php-irc-keeps-leaving/#findComment-164049 Share on other sites More sharing options...
konnwat Posted January 18, 2007 Author Share Posted January 18, 2007 WOW impressive :Dso does your bot stay on forever?also i see yours is done in classes, would that make a difference? Quote Link to comment https://forums.phpfreaks.com/topic/34804-php-irc-keeps-leaving/#findComment-164052 Share on other sites More sharing options...
.josh Posted January 18, 2007 Share Posted January 18, 2007 not really. Seeing as how it's php4 oop, It's just more "organized." But anyways, have you tried running your bot from somewhere else? This might help narrow down the issue. Quote Link to comment https://forums.phpfreaks.com/topic/34804-php-irc-keeps-leaving/#findComment-164055 Share on other sites More sharing options...
konnwat Posted January 18, 2007 Author Share Posted January 18, 2007 yeah it used to run on my localhost but1. i needed it to run after i close my laptop :P2. i made a php gd pic that get info from the bot that needs to be on also, all the time.and 3. my php is now broken :( dunno what i did but i go to tick personal web sharing and it take forever to load. i might post that in the other forum though :Pi cant remember what it was like on my computer. also can i try copy and paste your code just to see if your bot stays on, then we will know its my script and not the server. Quote Link to comment https://forums.phpfreaks.com/topic/34804-php-irc-keeps-leaving/#findComment-164063 Share on other sites More sharing options...
.josh Posted January 18, 2007 Share Posted January 18, 2007 you know, i'm looking at your ping code:[code]//pong at pingsif (strpos($line,"PING :")===0) {fwrite($socket, "PONG :irc.barafranca.com\r\n");}[/code]and maybe i'm just having a fubar moment, but isn't your condition only ponging if the strpos is false, meaning, only if it [i]doesn't[/i] find "PING :" ? Quote Link to comment https://forums.phpfreaks.com/topic/34804-php-irc-keeps-leaving/#findComment-164068 Share on other sites More sharing options...
konnwat Posted January 18, 2007 Author Share Posted January 18, 2007 dont think so=== means exact equals (including type eg. boolean, string, integer etc.)!= means doesn't equal:D Quote Link to comment https://forums.phpfreaks.com/topic/34804-php-irc-keeps-leaving/#findComment-164075 Share on other sites More sharing options...
konnwat Posted January 18, 2007 Author Share Posted January 18, 2007 oh right yes i see what you mean,hmmm i downloaded that from a site.instead of 0 you think it should be 1or >0am i right in thinking that :D ? Quote Link to comment https://forums.phpfreaks.com/topic/34804-php-irc-keeps-leaving/#findComment-164079 Share on other sites More sharing options...
.josh Posted January 18, 2007 Share Posted January 18, 2007 right. so, if I do strpos($line,"PING :") it would return the first instance of "PING :" in your string. If it finds nothing, it will return false, or 0. So basically, the only way your condition will be true is if 0 === 0, or in other words, the condition is true if it is not found. edit:yes, you should either change it to != 0 just simply if (substr($line,"PING :")) { ... } Quote Link to comment https://forums.phpfreaks.com/topic/34804-php-irc-keeps-leaving/#findComment-164080 Share on other sites More sharing options...
konnwat Posted January 18, 2007 Author Share Posted January 18, 2007 good thinking xDi shall try that and tell you what happensthank you! Quote Link to comment https://forums.phpfreaks.com/topic/34804-php-irc-keeps-leaving/#findComment-164082 Share on other sites More sharing options...
konnwat Posted January 18, 2007 Author Share Posted January 18, 2007 [23:48] IgBot joined the chat room.[23:48] IgBot was promoted to operator by ChanServ.[23:56] IgBot left the chat room. (Ping timeout: 241 seconds)no that broke it :P[code]<?PHP//pong at pingsif (strpos($line,"PING :") != 0) {fwrite($socket, "PONG :irc.barafranca.com\r\n");}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/34804-php-irc-keeps-leaving/#findComment-164099 Share on other sites More sharing options...
.josh Posted January 19, 2007 Share Posted January 19, 2007 I don't really think that's the problem here. I think you fixed something that needed to be fixed...but let's find out for sure that that's not the problem, by commenting out your condition and doing this instead:[code]// if (strpos($line,"PING :") != 0) {if (substr($line, 0, 6) == 'PING :') { fwrite($socket, "PONG :irc.barafranca.com\r\n");}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/34804-php-irc-keeps-leaving/#findComment-164127 Share on other sites More sharing options...
konnwat Posted January 19, 2007 Author Share Posted January 19, 2007 If it helps anyone, when my bot leaves for no reason, its says: "EOF from client"don't know what the means ^^ Quote Link to comment https://forums.phpfreaks.com/topic/34804-php-irc-keeps-leaving/#findComment-164534 Share on other sites More sharing options...
Adam Posted January 19, 2007 Share Posted January 19, 2007 EOF means "End of file"... Quote Link to comment https://forums.phpfreaks.com/topic/34804-php-irc-keeps-leaving/#findComment-164558 Share on other sites More sharing options...
konnwat Posted January 19, 2007 Author Share Posted January 19, 2007 right so would that mean, the while($line=fgets($socket)) was somehow broken. so fgets($socket) is no more??? Quote Link to comment https://forums.phpfreaks.com/topic/34804-php-irc-keeps-leaving/#findComment-164563 Share on other sites More sharing options...
.josh Posted January 19, 2007 Share Posted January 19, 2007 that seems to be the case. Quote Link to comment https://forums.phpfreaks.com/topic/34804-php-irc-keeps-leaving/#findComment-164567 Share on other sites More sharing options...
konnwat Posted January 19, 2007 Author Share Posted January 19, 2007 do you (or anyone) know why the fgets($socket) has gone? this usually means there is some kind of error in my scripts. but it cant be fatal because then it doesn't connect at allstange :P Quote Link to comment https://forums.phpfreaks.com/topic/34804-php-irc-keeps-leaving/#findComment-164570 Share on other sites More sharing options...
.josh Posted January 19, 2007 Share Posted January 19, 2007 I don't think that's because of something on your end... I mean, the principle here is that the target server keeps spitting out lines, and while it keeps spitting out lines, the loop continues. It would only stop if the server stops spitting out lines. For example, if you have a quit command for your bot that sends a disconnection command: this would disconnect from the server, therefore the server would be sending no more lines, therefore the loop would end. I would first take a look at all of your "event" conditions to see if something isn't causing the server to drop the connection. Like for instance, if you DO have a quit command for your bot, make sure your condition is setup right, because we have already determined one condition of yours that wasn't..Failing that, I can't think of anything else, except for that maybe the server has some kind of anti-bot mechanism in place that drops you if it determines you're a bot... Quote Link to comment https://forums.phpfreaks.com/topic/34804-php-irc-keeps-leaving/#findComment-164573 Share on other sites More sharing options...
konnwat Posted January 19, 2007 Author Share Posted January 19, 2007 I like the sound of the "server stop spitting lines" that sounds true. thank you :D, how can i stop this?theres no errors in my ping script by the way, every time i change it from what it was the bot leaves with a ping time out. but its i have it like it was original it leaves with EOF.and also my server is made for php bots, no safe mode, fsockopen is allowed, and i posted a ticket about CPU usage before and the admins didn't seem to ban me for it ^^ Quote Link to comment https://forums.phpfreaks.com/topic/34804-php-irc-keeps-leaving/#findComment-164578 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.