1<?php 2 3require_once(dirname(__FILE__)."/../pfccommand.class.php"); 4require_once(dirname(__FILE__)."/../commands/join.class.php"); 5 6class pfcCommand_leave extends pfcCommand 7{ 8 var $usage = "/leave [ch|pv [[{channel|nickname}] {reason}]]"; 9 10 function run(&$xml_reponse, $p) 11 { 12 $clientid = $p["clientid"]; 13 $params = $p["params"]; 14 $sender = $p["sender"]; 15 $recipient = $p["recipient"]; 16 $recipientid = $p["recipientid"]; 17 $flag = isset($p["flag"]) ? $p["flag"] : 2; 18 19 $c =& pfcGlobalConfig::Instance(); 20 $u =& pfcUserConfig::Instance(); 21 $ct =& pfcContainer::Instance(); 22 23 $type = isset($params[0]) ? $params[0] : ''; 24 $name = isset($params[1]) ? $params[1] : ''; 25 $reason = isset($params[2]) ? $params[2] : ''; 26 27 if ($type != 'ch' && $type != 'pv' && $type != '') 28 { 29 // error 30 $cmdp = $p; 31 $cmdp["param"] = _pfc("Missing parameter"); 32 $cmdp["param"] .= " (".$this->usage.")"; 33 $cmd =& pfcCommand::Factory("error"); 34 $cmd->run($xml_reponse, $cmdp); 35 return; 36 } 37 38 39 // get the recipientid to close (a pv or a channel) 40 $id = ''; 41 if ($type == 'ch') 42 { 43 if ($name == '') 44 $id = $recipientid; 45 else 46 $id = pfcCommand_join::GetRecipientId($name); 47 } 48 else if ($type == 'pv') 49 { 50 // pv 51 $pvnickid = $ct->getNickId($name); 52 $nickid = $u->nickid; 53 if ($pvnickid != '') 54 { 55 // generate a pvid from the two nicknames ids 56 $a = array($pvnickid, $nickid); sort($a); 57 $pvrecipient = "pv_".$a[0]."_".$a[1]; 58 $id = md5($pvrecipient); 59 } 60 } 61 else 62 $id = $recipientid; 63 64 65 66 $leavech = false; 67 $leavepv = false; 68 $leave_recip = ''; 69 $leave_id = ''; 70 71 // save the new channel list in the session 72 if ( isset($u->channels[$id]) ) 73 { 74 $leave_recip = $u->channels[$id]["recipient"]; 75 $leave_id = $id; 76 unset($u->channels[$id]); 77 $u->saveInCache(); 78 $leavech = true; 79 } 80 81 // save the new private messages list in the session 82 if ( isset($u->privmsg[$id]) ) 83 { 84 $leave_recip = $u->privmsg[$id]["recipient"]; 85 $leave_id = $id; 86 unset($u->privmsg[$id]); 87 $u->saveInCache(); 88 $leavepv = true; 89 } 90 91 if($leavepv || $leavech) 92 { 93 // if ($leavech) 94 { 95 // show a leave message with the showing the reason if present 96 $cmdp = $p; 97 $cmdp["recipient"] = $leave_recip; 98 $cmdp["recipientid"] = $leave_id; 99 $cmdp["flag"] = $flag; 100 $cmdp["param"] = _pfc("%s quit",$u->getNickname()); 101 if ($reason != "") $cmdp["param"] .= " (".$reason.")"; 102 $cmd =& pfcCommand::Factory("notice"); 103 $cmd->run($xml_reponse, $cmdp); 104 } 105 106 // remove the nickname from the channel/pv 107 $ct->removeNick($leave_recip, $u->nickid); 108 109 // reset the sessions indicators 110 $chanrecip = $leave_recip; 111 $chanid = $leave_id; 112 // reset the fromid flag 113 $from_id_sid = "pfc_from_id_".$c->getId()."_".$clientid."_".$chanid; 114 $from_id = $ct->getLastId($chanrecip)-$c->max_msg; 115 $_SESSION[$from_id_sid] = ($from_id<0) ? 0 : $from_id; 116 // reset the oldmsg flag 117 $oldmsg_sid = "pfc_oldmsg_".$c->getId()."_".$clientid."_".$chanid; 118 $_SESSION[$oldmsg_sid] = true; 119 120 // if the /leave command comes from a cmdtoplay then show the reason to the user (ex: kick or ban reason) 121 if ($p['cmdtoplay']) 122 { 123 $cmdp = $p; 124 $cmdp["param"] = $reason; 125 $cmd =& pfcCommand::Factory("error"); 126 $cmd->run($xml_reponse, $cmdp); 127 } 128 129 // return ok to the client 130 // then the client will remove the channel' tab 131 $xml_reponse->script("pfc.handleResponse('leave', 'ok', '".$id."');"); 132 } 133 else 134 { 135 // error 136 $cmdp = $p; 137 $cmdp["param"] = _pfc("Missing parameter"); 138 $cmdp["param"] .= " (".$this->usage.")"; 139 $cmd =& pfcCommand::Factory("error"); 140 $cmd->run($xml_reponse, $cmdp); 141 } 142 } 143} 144 145?>