1<?php
2
3require_once(dirname(__FILE__)."/../pfccommand.class.php");
4
5class pfcCommand_join extends pfcCommand
6{
7  var $usage = "/join {channelname}";
8
9  function run(&$xml_reponse, $p)
10  {
11    $clientid    = $p["clientid"];
12    $param       = $p["param"];
13    $sender      = $p["sender"];
14    $recipient   = $p["recipient"];
15    $recipientid = $p["recipientid"];
16
17    $c =& pfcGlobalConfig::Instance();
18    $u =& pfcUserConfig::Instance();
19
20    $channame  = trim($param);
21    $chanrecip = pfcCommand_join::GetRecipient($channame);
22    $chanid    = pfcCommand_join::GetRecipientId($channame);
23
24    if ($channame == "")
25    {
26      $cmdp = $p;
27      $cmdp["param"] = _pfc("Missing parameter");
28      $cmdp["param"] .= " (".$this->usage.")";
29      $cmd =& pfcCommand::Factory("error");
30      $cmd->run($xml_reponse, $cmdp);
31      return;
32    }
33
34    if(!isset($u->channels[$chanid]))
35    {
36      if ($c->max_channels <= count($u->channels))
37      {
38        // the maximum number of joined channels has been reached
39        $xml_reponse->script("pfc.handleResponse('".$this->name."', 'max_channels', Array());");
40        return;
41      }
42
43      $u->channels[$chanid]["recipient"] = $chanrecip;
44      $u->channels[$chanid]["name"]      = $channame;
45      $u->saveInCache();
46
47      // show a join message
48      $cmdp = $p;
49      $cmdp["param"] = _pfc("%s joins %s",$u->getNickname(), $channame);
50      $cmdp["recipient"] = $chanrecip;
51      $cmdp["recipientid"] = $chanid;
52      $cmdp["flag"] = 2;
53      $cmd =& pfcCommand::Factory("notice");
54      $cmd->run($xml_reponse, $cmdp);
55    }
56
57    // register the user (and his metadata) in the channel
58    $ct =& pfcContainer::Instance();
59    //    $ct->createNick($chanrecip, $u->nick, $u->nickid);
60    $ct->joinChan($u->nickid, $chanrecip);
61    $this->forceWhoisReload($u->nickid);
62
63    // return ok to the client
64    // then the client will create a new tab
65    $xml_reponse->script("pfc.handleResponse('".$this->name."', 'ok', Array('".$chanid."','".addslashes($channame)."'));");
66  }
67
68  function GetRecipient($channame)
69  {
70    return "ch_".$channame;
71  }
72
73  function GetRecipientId($channame)
74  {
75    return md5(pfcCommand_join::GetRecipient($channame));
76  }
77
78}
79
80?>