1<?php 2/** 3 * checktimeout.class.php 4 * 5 * Copyright © 2006 Stephane Gully <stephane.gully@gmail.com> 6 * 7 * This library is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU Lesser General Public 9 * License as published by the Free Software Foundation; either 10 * version 2.1 of the License, or (at your option) any later version. 11 * 12 * This library is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Lesser General Public License for more details. 16 * 17 * You should have received a copy of the GNU Lesser General Public 18 * License along with this library; if not, write to the 19 * Free Software Foundation, 51 Franklin St, Fifth Floor, 20 * Boston, MA 02110-1301 USA 21 */ 22require_once dirname(__FILE__)."/../pfci18n.class.php"; 23require_once dirname(__FILE__)."/../pfcuserconfig.class.php"; 24require_once dirname(__FILE__)."/../pfcproxycommand.class.php"; 25 26/** 27 * pfcProxyCommand_checktimeout 28 * this command disconnect obsolete users (timouted) 29 * an obsolete user is an user which didn't update his stats since more than 20 seconds (default timeout value) 30 * @author Stephane Gully <stephane.gully@gmail.com> 31 */ 32class pfcProxyCommand_checktimeout extends pfcProxyCommand 33{ 34 function run(&$xml_reponse, $p) 35 { 36 $clientid = $p["clientid"]; 37 $param = $p["param"]; 38 $sender = $p["sender"]; 39 $recipient = $p["recipient"]; 40 $recipientid = $p["recipientid"]; 41 42 if ($this->name == 'update' || $this->name == 'connect') 43 { 44 $c =& pfcGlobalConfig::Instance(); 45 $u =& pfcUserConfig::Instance(); 46 $ct =& pfcContainer::Instance(); 47 48 // disconnect users from channels when they timeout 49 $disconnected_users = $ct->removeObsoleteNick($c->timeout); 50 for($i=0; $i<count($disconnected_users["nick"]); $i++) 51 { 52 $nick = $disconnected_users["nick"][$i]; 53 for($j=0; $j<count($disconnected_users["channels"][$i]); $j++) 54 { 55 $chan = $disconnected_users["channels"][$i][$j]; 56 if ($chan != 'SERVER') 57 { 58 $online_users = $ct->getOnlineNick($chan); 59 if (count($online_users['nickid']) > 0) 60 { 61 $cmdp = $p; 62 $cmdp["param"] = _pfc("%s quit (timeout)", $nick); 63 $cmdp["flag"] = 2; 64 $cmdp["recipient"] = $chan; 65 $cmdp["recipientid"] = md5($chan); // @todo: clean the recipient/recipientid notion 66 $cmd =& pfcCommand::Factory("notice"); 67 $cmd->run($xml_reponse, $cmdp); 68 } 69 } 70 } 71 } 72 } 73 74 // forward the command to the next proxy or to the final command 75 return $this->next->run($xml_reponse, $p); 76 } 77} 78 79?> 80