[Phpfreechat-svn] SF.net SVN: phpfreechat: [984] trunk
Status: Beta
Brought to you by:
kerphi
From: <ke...@us...> - 2007-03-07 19:14:25
|
Revision: 984 http://svn.sourceforge.net/phpfreechat/?rev=984&view=rev Author: kerphi Date: 2007-03-07 11:14:11 -0800 (Wed, 07 Mar 2007) Log Message: ----------- work on simplifications Modified Paths: -------------- trunk/data/public/js/pfcclient.js trunk/src/commands/ban.class.php trunk/src/commands/connect.class.php trunk/src/commands/deop.class.php trunk/src/commands/identify.class.php trunk/src/commands/join.class.php trunk/src/commands/leave.class.php trunk/src/commands/me.class.php trunk/src/commands/nick.class.php trunk/src/commands/notice.class.php trunk/src/commands/op.class.php trunk/src/commands/privmsg.class.php trunk/src/commands/quit.class.php trunk/src/commands/send.class.php trunk/src/commands/update.class.php trunk/src/commands/whois.class.php trunk/src/pfccommand.class.php trunk/src/pfccontainer.class.php trunk/src/pfcglobalconfig.class.php trunk/src/pfcuserconfig.class.php trunk/src/phpfreechat.class.php trunk/src/proxies/auth.class.php trunk/src/proxies/checknickchange.class.php trunk/src/proxies/checktimeout.class.php trunk/themes/default/chat.js.tpl.php Modified: trunk/data/public/js/pfcclient.js =================================================================== --- trunk/data/public/js/pfcclient.js 2007-03-04 13:37:46 UTC (rev 983) +++ trunk/data/public/js/pfcclient.js 2007-03-07 19:14:11 UTC (rev 984) @@ -39,11 +39,12 @@ this.privmsgs = Array(); this.privmsgids = Array(); - this.timeout = null; - this.refresh_delay = pfc_refresh_delay; - this.max_refresh_delay = pfc_max_refresh_delay; + this.timeout = null; + this.refresh_delay = pfc_refresh_delay; + this.max_refresh_delay = pfc_max_refresh_delay; this.last_response_time = new Date().getTime(); this.last_request_time = new Date().getTime(); + this.canupdatenexttime = true; /* unique client id for each windows used to identify a open window * this id is passed every time the JS communicate with server @@ -145,7 +146,12 @@ askNickResponse: function(newnick) { if (newnick) - this.sendRequest('/nick "'+newnick+'"'); + { + if (this.isconnected) + this.sendRequest('/nick "'+newnick+'"'); + else + this.sendRequest('/connect '+newnick); + } }, /** @@ -167,7 +173,10 @@ { //alert(cmd + "-"+resp+"-"+param); if (resp == "ok") - { + { + this.nickname = param[0]; + this.sendRequest('/nick "'+this.nickname+'"'); +/* if (this.nickname == '') // ask to choose a nickname this.askNick(this.nickname); @@ -175,9 +184,59 @@ { this.sendRequest('/nick "'+this.nickname+'"'); } - +*/ this.isconnected = true; +/* + // join the default channels comming from the parameter list + // and the user's channels comming from the + var ch = pfc_defaultchan; + for (var i=0; i<pfc_userchan.length; i++) + { + if (indexOf(ch,pfc_userchan[i]) == -1) + ch.push(pfc_userchan[i]); + } +*/ + // join the default channels comming from the parameter list + if (pfc_userchan.length == 0) + for (var i=0; i<pfc_defaultchan.length; i++) + { + if (i<pfc_defaultchan.length-1) + cmd = '/join2'; + else + cmd = '/join'; + cmd += ' "'+pfc_defaultchan[i]+'"'; + this.sendRequest(cmd); + } + else + // join channels comming from user sessions + for (var i=0; i<pfc_userchan.length; i++) + { + if (i<pfc_userchan.length-1) + cmd = '/join2'; + else + cmd = '/join'; + cmd += ' "'+pfc_userchan[i]+'"'; + this.sendRequest(cmd); + } + + // join the default privmsg comming from the parameter list + for (var i=0; i<pfc_defaultprivmsg.length; i++) + { + if (i<pfc_defaultprivmsg.length-1) + cmd = '/privmsg2'; + else + cmd = '/privmsg'; + cmd += ' "'+pfc_defaultprivmsg[i]+'"'; + this.sendRequest(cmd); + } + // now join privmsg comming from the sessions + for (var i=0; i<pfc_userprivmsg.length; i++) + { + this.sendRequest('/privmsg "'+pfc_userprivmsg[i]+'"'); + } + + // start the polling system this.updateChat(true); } @@ -277,6 +336,7 @@ { cmd = ''; +/* // join the default channels comming from the parameter list for (var i=0; i<pfc_defaultchan.length; i++) { @@ -313,6 +373,7 @@ { this.sendRequest('/privmsg "'+pfc_userprivmsg[i]+'"'); } +*/ } if (resp == "ok" || resp == "notchanged" || resp == "changed" || resp == "connected") @@ -473,7 +534,7 @@ var nickid = meta['users']['nickid'][i]; var nick = meta['users']['nick'][i]; var um = this.getAllUserMeta(nickid); - if (!um) this.sendRequest('/whois2 "'+nick+'"'); + if (!um) this.sendRequest('/whois2 "'+nickid+'"'); } // update the nick list display on the current channel @@ -504,6 +565,9 @@ this.handleComingRequest(param); } } + else if (cmd == "send") + { + } else alert(cmd + "-"+resp+"-"+param); }, @@ -1462,7 +1526,12 @@ if (this.isconnected) this.sendRequest('/quit'); else - this.sendRequest('/connect'); + { + if (this.nickname == '') + this.askNick(); + else + this.sendRequest('/connect '+this.nickname); + } }, refresh_loginlogout: function() { Modified: trunk/src/commands/ban.class.php =================================================================== --- trunk/src/commands/ban.class.php 2007-03-04 13:37:46 UTC (rev 983) +++ trunk/src/commands/ban.class.php 2007-03-07 19:14:11 UTC (rev 984) @@ -39,7 +39,7 @@ // notify all the channel $cmdp = $p; - $cmdp["param"] = _pfc("banished from %s by %s", $channame, $sender); + $cmdp["param"] = _pfc("%s banished from %s by %s", $nick, $channame, $sender); $cmdp["flag"] = 1; $cmd =& pfcCommand::Factory("notice"); $cmd->run($xml_reponse, $cmdp); Modified: trunk/src/commands/connect.class.php =================================================================== --- trunk/src/commands/connect.class.php 2007-03-04 13:37:46 UTC (rev 983) +++ trunk/src/commands/connect.class.php 2007-03-07 19:14:11 UTC (rev 984) @@ -8,13 +8,17 @@ { $clientid = $p["clientid"]; $param = $p["param"]; + $params = $p["params"]; $sender = $p["sender"]; $recipient = $p["recipient"]; $recipientid = $p["recipientid"]; $getoldmsg = isset($p["getoldmsg"]) ? $p["getoldmsg"] : true; - - $c =& pfcGlobalConfig::Instance(); - $u =& pfcUserConfig::Instance(); + + // nickname must be given to be able to connect to the chat + $nick = $params[0]; + + $c =& pfcGlobalConfig::Instance(); + $u =& pfcUserConfig::Instance(); $ct =& pfcContainer::Instance(); // reset the message id indicator (see getnewmsg.class.php) @@ -69,9 +73,21 @@ (count($users["nickid"]) == 0 || (count($users["nickid"]) == 1 && $users["nickid"][0] == $u->nickid))) $isadmin = true; } - + // setup some user meta $nickid = $u->nickid; + + // create the nickid + $ct->joinChan($nickid, NULL); // join the server + $ct->createNick($nickid, $nick); + + $u->nick = $nick; + $u->saveInCache(); + + // setup the active flag in user session + // $u->active = true; + // $u->saveInCache(); + // store the user ip $ip = $_SERVER["REMOTE_ADDR"]; if ($ip == "::1") $ip = "127.0.0.1"; // fix for konqueror & localhost @@ -83,7 +99,7 @@ $ct->setUserMeta($nickid, $k, $v); // connect to the server - $xml_reponse->script("pfc.handleResponse('connect', 'ok', '');"); + $xml_reponse->script("pfc.handleResponse('connect', 'ok', Array('".addslashes($nick)."'));"); } } Modified: trunk/src/commands/deop.class.php =================================================================== --- trunk/src/commands/deop.class.php 2007-03-04 13:37:46 UTC (rev 983) +++ trunk/src/commands/deop.class.php 2007-03-07 19:14:11 UTC (rev 984) @@ -8,8 +8,9 @@ function run(&$xml_reponse, $p) { - $c =& pfcGlobalConfig::Instance(); - $u =& pfcUserConfig::Instance(); + $c =& pfcGlobalConfig::Instance(); + $u =& pfcUserConfig::Instance(); + $ct =& pfcContainer::Instance(); if (trim($p["param"]) == "") { @@ -24,11 +25,10 @@ // just change the "isadmin" meta flag $nicktodeop = trim($p["param"]); - $container =& pfcContainer::Instance(); - $nicktodeopid = $container->getNickId($nicktodeop); - $container->setUserMeta($nicktodeopid, 'isadmin', false); + $nicktodeopid = $ct->getNickId($nicktodeop); + $ct->setUserMeta($nicktodeopid, 'isadmin', false); - $this->forceWhoisReload($nicktodeop); + $this->forceWhoisReload($nicktodeopid); } } Modified: trunk/src/commands/identify.class.php =================================================================== --- trunk/src/commands/identify.class.php 2007-03-04 13:37:46 UTC (rev 983) +++ trunk/src/commands/identify.class.php 2007-03-07 19:14:11 UTC (rev 984) @@ -59,7 +59,7 @@ // ok the current user is an admin, just save the isadmin flag in the metadata $ct =& pfcContainer::Instance(); $ct->setUserMeta($u->nickid, 'isadmin', $isadmin); - $this->forceWhoisReload($u->nick); + $this->forceWhoisReload($u->nickid); $msg .= _pfc("Succesfully identified"); $xml_reponse->script("pfc.handleResponse('".$this->name."', 'ok', '".$msg."');"); Modified: trunk/src/commands/join.class.php =================================================================== --- trunk/src/commands/join.class.php 2007-03-04 13:37:46 UTC (rev 983) +++ trunk/src/commands/join.class.php 2007-03-07 19:14:11 UTC (rev 984) @@ -46,7 +46,7 @@ // show a join message $cmdp = $p; - $cmdp["param"] = _pfc("%s joins %s",$u->nick, $channame); + $cmdp["param"] = _pfc("%s joins %s",$u->getNickname(), $channame); $cmdp["recipient"] = $chanrecip; $cmdp["recipientid"] = $chanid; $cmdp["flag"] = 2; @@ -56,8 +56,9 @@ // register the user (and his metadata) in the channel $ct =& pfcContainer::Instance(); - $ct->createNick($chanrecip, $u->nick, $u->nickid); - $this->forceWhoisReload($u->nick); + // $ct->createNick($chanrecip, $u->nick, $u->nickid); + $ct->joinChan($u->nickid, $chanrecip); + $this->forceWhoisReload($u->nickid); // return ok to the client // then the client will create a new tab Modified: trunk/src/commands/leave.class.php =================================================================== --- trunk/src/commands/leave.class.php 2007-03-04 13:37:46 UTC (rev 983) +++ trunk/src/commands/leave.class.php 2007-03-07 19:14:11 UTC (rev 984) @@ -67,7 +67,7 @@ $leave_recip = ''; $leave_id = ''; - // check into channels + // save the new channel list in the session if ( isset($u->channels[$id]) ) { $leave_recip = $u->channels[$id]["recipient"]; @@ -77,7 +77,7 @@ $leavech = true; } - // check into private messages + // save the new private messages list in the session if ( isset($u->privmsg[$id]) ) { $leave_recip = $u->privmsg[$id]["recipient"]; @@ -89,14 +89,14 @@ if($leavepv || $leavech) { - if ($leavech) + // if ($leavech) { // show a leave message with the showing the reason if present $cmdp = $p; $cmdp["recipient"] = $leave_recip; $cmdp["recipientid"] = $leave_id; $cmdp["flag"] = 2; - $cmdp["param"] = _pfc("%s quit",$u->nick); + $cmdp["param"] = _pfc("%s quit",$u->getNickname()); if ($reason != "") $cmdp["param"] .= " (".$reason.")"; $cmd =& pfcCommand::Factory("notice"); $cmd->run($xml_reponse, $cmdp); Modified: trunk/src/commands/me.class.php =================================================================== --- trunk/src/commands/me.class.php 2007-03-04 13:37:46 UTC (rev 983) +++ trunk/src/commands/me.class.php 2007-03-07 19:14:11 UTC (rev 984) @@ -14,8 +14,9 @@ $recipient = $p["recipient"]; $recipientid = $p["recipientid"]; - $c =& pfcGlobalConfig::Instance(); - $u =& pfcUserConfig::Instance(); + $c =& pfcGlobalConfig::Instance(); + $u =& pfcUserConfig::Instance(); + $ct =& pfcContainer::Instance(); if (trim($param) == "") { @@ -28,9 +29,8 @@ return; } - $container =& pfcContainer::Instance(); $msg = phpFreeChat::PreFilterMsg($param); - $container->write($recipient, "*me*", $this->name, $u->nick." ".$msg); + $ct->write($recipient, "*me*", $this->name, $u->getNickname()." ".$msg); if ($c->debug) pxlog("/me ".$msg, "chat", $c->getId()); } Modified: trunk/src/commands/nick.class.php =================================================================== --- trunk/src/commands/nick.class.php 2007-03-04 13:37:46 UTC (rev 983) +++ trunk/src/commands/nick.class.php 2007-03-07 19:14:11 UTC (rev 984) @@ -14,8 +14,9 @@ $recipient = $p["recipient"]; $recipientid = $p["recipientid"]; - $c =& pfcGlobalConfig::Instance(); - $u =& pfcUserConfig::Instance(); + $c =& pfcGlobalConfig::Instance(); + $u =& pfcUserConfig::Instance(); + $ct =& pfcContainer::Instance(); if (trim($param) == "") { @@ -29,11 +30,10 @@ } $newnick = phpFreeChat::FilterNickname($param); - $oldnick = $u->nick; + $oldnick = $ct->getNickname($u->nickid); - $container =& pfcContainer::Instance(); - $newnickid = $container->getNickId($newnick); - $oldnickid = $container->getNickId($oldnick); + $newnickid = $ct->getNickId($newnick); + $oldnickid = $u->nickid; if ($c->debug) pxlog("/nick ".$newnick, "chat", $c->getId()); @@ -42,13 +42,14 @@ // oldnick is different from new nick // -> this is a nickname change if ($oldnickid == $u->nickid && - $oldnick != $newnick && $oldnick != "") + $oldnick != $newnick && + $oldnick != '') { // really change the nick (rename it) - $container->changeNick($newnick, $oldnick); + $ct->changeNick($newnick, $oldnick); $u->nick = $newnick; $u->saveInCache(); - $this->forceWhoisReload($u->nick); + $this->forceWhoisReload($u->nickid); // notify all the joined channels/privmsg $cmdp = $p; @@ -68,8 +69,10 @@ $cmd->run($xml_reponse, $cmdp); } $xml_reponse->script("pfc.handleResponse('nick', 'changed', '".addslashes($newnick)."');"); + return; } - + + /* // new nickname is undefined (not used) and // current nickname (oldnick) is not mine or is undefined // -> this is a first connection @@ -77,24 +80,24 @@ $oldnickid != $u->nickid) { // this is a first connection : create the nickname on the server - $container->createNick(NULL, $newnick, $u->nickid); - /* - // useless code, it's done in updatemynick command - foreach($u->channels as $chan) - $container->createNick($chan["recipient"], $newnick, $u->nickid); - foreach($u->privmsg as $pv) - $container->createNick($pv["recipient"], $newnick, $u->nickid); - */ - $u->nick = $newnick; - $u->active = true; - $u->saveInCache(); - $this->forceWhoisReload($u->nick); + // $container->createNick(NULL, $newnick, $u->nickid); + $container->createNick($u->nickid, $newnick); + //$u->nick = $newnick; + // $u->active = true; + //$u->saveInCache(); + $this->forceWhoisReload($u->nickid); + $xml_reponse->script("pfc.handleResponse('nick', 'connected', '".addslashes($newnick)."');"); if ($c->debug) pxlog("/nick ".$newnick." (first connection, oldnick=".$oldnick.")", "chat", $c->getId()); + return; } + */ + + // $ct->createNick($u->nickid, $newnick); + } } Modified: trunk/src/commands/notice.class.php =================================================================== --- trunk/src/commands/notice.class.php 2007-03-04 13:37:46 UTC (rev 983) +++ trunk/src/commands/notice.class.php 2007-03-07 19:14:11 UTC (rev 984) @@ -13,15 +13,16 @@ $recipientid = $p["recipientid"]; $flag = isset($p["flag"]) ? $p["flag"] : 3; - $c =& pfcGlobalConfig::Instance(); - $u =& pfcUserConfig::Instance(); + $c =& pfcGlobalConfig::Instance(); + $u =& pfcUserConfig::Instance(); + $ct =& pfcContainer::Instance(); if ($c->shownotice > 0 && ($c->shownotice & $flag) == $flag) { - $container =& pfcContainer::Instance(); $msg = phpFreeChat::FilterSpecialChar($msg); - $res = $container->write($recipient, $u->nick, "notice", $msg); + $nick = $ct->getNickname($u->nickid); + $res = $ct->write($recipient, $nick, "notice", $msg); if (is_array($res)) { $cmdp = $p; Modified: trunk/src/commands/op.class.php =================================================================== --- trunk/src/commands/op.class.php 2007-03-04 13:37:46 UTC (rev 983) +++ trunk/src/commands/op.class.php 2007-03-07 19:14:11 UTC (rev 984) @@ -14,8 +14,9 @@ $recipient = $p["recipient"]; $recipientid = $p["recipientid"]; - $c =& pfcGlobalConfig::Instance(); - $u =& pfcUserConfig::Instance(); + $c =& pfcGlobalConfig::Instance(); + $u =& pfcUserConfig::Instance(); + $ct =& pfcContainer::Instance(); if (trim($param) == "") { @@ -30,11 +31,10 @@ // just change the "isadmin" meta flag $nicktoop = trim($param); - $container =& pfcContainer::Instance(); - $nicktoopid = $container->getNickId($nicktoop); - $container->setUserMeta($nicktoopid, 'isadmin', true); + $nicktoopid = $ct->getNickId($nicktoop); + $ct->setUserMeta($nicktoopid, 'isadmin', true); - $this->forceWhoisReload($nicktoop); + $this->forceWhoisReload($nicktoopid); } } Modified: trunk/src/commands/privmsg.class.php =================================================================== --- trunk/src/commands/privmsg.class.php 2007-03-04 13:37:46 UTC (rev 983) +++ trunk/src/commands/privmsg.class.php 2007-03-07 19:14:11 UTC (rev 984) @@ -14,13 +14,23 @@ $c =& pfcGlobalConfig::Instance(); $u =& pfcUserConfig::Instance(); + $ct =& pfcContainer::Instance(); - $pvname = $param; - // check the pvname exists on the server - $container =& pfcContainer::Instance(); - $pvnickid = $container->getNickId($pvname); + $pvname = ''; + $pvnickid = ''; + if ($this->name == 'privmsg2') + { + $pvnickid = $ct->getNickId($param); + $pvname = $ct->getNickname($pvnickid); + } + else + { + $pvname = $param; + $pvnickid = $ct->getNickId($pvname); + } $nickid = $u->nickid; + $nick = $ct->getNickname($u->nickid); // error: can't speak to myself if ($pvnickid == $nickid) @@ -78,14 +88,14 @@ // reset the message id indicator // i.e. be ready to re-get all last posted messages $from_id_sid = "pfc_from_id_".$c->getId()."_".$clientid."_".$pvrecipientid; - $from_id = $container->getLastId($pvrecipient)-$c->max_msg-1; + $from_id = $ct->getLastId($pvrecipient)-$c->max_msg-1; $_SESSION[$from_id_sid] = ($from_id<0) ? 0 : $from_id; } // register the user (and his metadata) in this pv - $ct =& pfcContainer::Instance(); - $ct->createNick($pvrecipient, $u->nick, $u->nickid); - $this->forceWhoisReload($u->nick); + // $ct->createNick($pvrecipient, $u->nick, $u->nickid); + $ct->joinChan($nickid, $pvrecipient); + $this->forceWhoisReload($nickid); // return ok to the client // then the client will create a new tab Modified: trunk/src/commands/quit.class.php =================================================================== --- trunk/src/commands/quit.class.php 2007-03-04 13:37:46 UTC (rev 983) +++ trunk/src/commands/quit.class.php 2007-03-07 19:14:11 UTC (rev 984) @@ -12,14 +12,13 @@ $recipient = $p["recipient"]; $recipientid = $p["recipientid"]; - $c =& pfcGlobalConfig::Instance(); - $u =& pfcUserConfig::Instance(); + $c =& pfcGlobalConfig::Instance(); + $u =& pfcUserConfig::Instance(); + $ct =& pfcContainer::Instance(); - // then remove the nickname file - $ct =& pfcContainer::Instance(); - $quitmsg = $param == "" ? _pfc("%s quit", $u->nick) : _pfc("%s quit (%s)", $u->nick, $param); + $nick = $ct->getNickname($u->nickid); - // from the channels + // leave the channels foreach( $u->channels as $id => $chandetail ) if ($ct->removeNick($chandetail["recipient"], $u->nickid)) { @@ -30,7 +29,7 @@ $cmd =& pfcCommand::Factory("leave"); $cmd->run($xml_reponse, $cmdp); } - // from the private messages + // leave the private messages foreach( $u->privmsg as $id => $pvdetail ) if ($ct->removeNick($pvdetail["recipient"], $u->nickid)) { @@ -41,16 +40,18 @@ $cmd =& pfcCommand::Factory("leave"); $cmd->run($xml_reponse, $cmdp); } - // from the server + // leave the server $ct->removeNick(NULL, $u->nickid); + /* // then set the chat inactive $u->active = false; $u->saveInCache(); + */ $xml_reponse->script("pfc.handleResponse('quit', 'ok', '');"); - if ($c->debug) pxlog("/quit (a user just quit -> nick=".$u->nick.")", "chat", $c->getId()); + if ($c->debug) pxlog("/quit (a user just quit -> nick=".$nick.")", "chat", $c->getId()); } } Modified: trunk/src/commands/send.class.php =================================================================== --- trunk/src/commands/send.class.php 2007-03-04 13:37:46 UTC (rev 983) +++ trunk/src/commands/send.class.php 2007-03-07 19:14:11 UTC (rev 984) @@ -12,23 +12,13 @@ $recipient = $p["recipient"]; $recipientid = $p["recipientid"]; - $c =& pfcGlobalConfig::Instance(); - $u =& pfcUserConfig::Instance(); - $nick = phpFreeChat::FilterSpecialChar($sender); + $c =& pfcGlobalConfig::Instance(); + $u =& pfcUserConfig::Instance(); + $ct =& pfcContainer::Instance(); + + $nick = $ct->getNickname($u->nickid); //phpFreeChat::FilterSpecialChar($sender); $text = phpFreeChat::PreFilterMsg($param); - - // send an error because the current user is not connected - if (!$u->active) - { - $cmdp = $p; - $cmdp["param"] = _pfc("Your must be connected to send a message"); - $cmd =& pfcCommand::Factory("error"); - $cmd->run($xml_reponse, $cmdp); - return; - } - - // $offline = $container->getMeta("offline", "nickname", $u->privmsg[$recipientid]["name"]); // if this channel is a pv (one to one channel), @@ -37,12 +27,12 @@ $can_send = true; if (isset($u->privmsg[$recipientid])) { - $container =& pfcContainer::Instance(); - $pvnick = $u->privmsg[$recipientid]["name"]; - $pvnickid = $container->getNickId($pvnick); + $pvnickid = $u->privmsg[$recipientid]["pvnickid"]; + $pvnick = $ct->getNickname($pvnickid);//$u->privmsg[$recipientid]["name"]; + // $pvnickid = $ct->getNickId($pvnick); // now check if this user is currently online - $onlineusers = $container->getOnlineNick(NULL); + $onlineusers = $ct->getOnlineNick(NULL); if (!in_array($pvnickid, $onlineusers["nickid"])) { // send an error because the user is not online @@ -63,7 +53,7 @@ { // an error occured, just ignore the message and display errors foreach($errors as $e) - if ($c->debug) pxlog("error /send, user can't send a message -> nick=".$u->nick." err=".$e, "chat", $c->getId()); + if ($c->debug) pxlog("error /send, user can't send a message -> nick=".$nick." err=".$e, "chat", $c->getId()); $cmdp = $p; $cmdp["param"] = $errors; $cmd =& pfcCommand::Factory("error"); @@ -77,8 +67,7 @@ // Now send the message if there is no errors if ($can_send) { - $container =& pfcContainer::Instance(); - $msgid = $container->write($recipient, $nick, "send", $text); + $msgid = $ct->write($recipient, $nick, "send", $text); if (is_array($msgid)) { $cmdp = $p; @@ -87,14 +76,17 @@ $cmd->run($xml_reponse, $cmdp); return; } - if ($c->debug) pxlog("/send ".$text." (a user just sent a message -> nick=".$u->nick.")", "chat", $c->getId()); + if ($c->debug) pxlog("/send ".$text." (a user just sent a message -> nick=".$nick.")", "chat", $c->getId()); // a message has been posted so : // - clear errors // - give focus to "words" field + // @todo move this code in the handleResponse function $xml_reponse->script("pfc.clearError(Array('pfc_words"."','pfc_handle"."'));"); $xml_reponse->script("$('pfc_words').focus();"); } + + $xml_reponse->script("pfc.handleResponse('".$this->name."', 'ok', '');"); } } Modified: trunk/src/commands/update.class.php =================================================================== --- trunk/src/commands/update.class.php 2007-03-04 13:37:46 UTC (rev 983) +++ trunk/src/commands/update.class.php 2007-03-07 19:14:11 UTC (rev 984) @@ -16,7 +16,7 @@ $u =& pfcUserConfig::Instance(); // do not update if user isn't active (didn't connect) - if ($u->active) + if ($u->isOnline()) { // check the user has not been disconnected from the server by timeout // if I found he has been disconnected, then I reconnect him with /connect command @@ -52,7 +52,7 @@ $cmdp["recipientid"] = $id; $cmdp["param"] = ''; // don't forward the parameter because it will be interpreted as a channel name $cmd->run($xml_reponse, $cmdp); - } + } // get new message posted on each channels $cmd =& pfcCommand::Factory("getnewmsg"); Modified: trunk/src/commands/whois.class.php =================================================================== --- trunk/src/commands/whois.class.php 2007-03-04 13:37:46 UTC (rev 983) +++ trunk/src/commands/whois.class.php 2007-03-07 19:14:11 UTC (rev 984) @@ -30,6 +30,7 @@ { $clientid = $p["clientid"]; $param = $p["param"]; + $params = $p["params"]; $sender = $p["sender"]; $recipient = $p["recipient"]; $recipientid = $p["recipientid"]; @@ -38,7 +39,17 @@ $u =& pfcUserConfig::Instance(); $ct =& pfcContainer::Instance(); - $nickid = $ct->getNickId($param); + // $xml_reponse->script("trace('".implode(',',$params)."');"); + // return; + + // get the nickid from the parameters + // if the run command is whois2 then the parameter is a nickid + $nickid = ''; + if ($this->name == 'whois2') + $nickid = $params[0]; + else + $nickid = $ct->getNickId($params[0]); + if ($nickid) { $usermeta = $ct->getAllUserMeta($nickid); @@ -67,4 +78,4 @@ } } -?> +?> \ No newline at end of file Modified: trunk/src/pfccommand.class.php =================================================================== --- trunk/src/pfccommand.class.php 2007-03-04 13:37:46 UTC (rev 983) +++ trunk/src/pfccommand.class.php 2007-03-07 19:14:11 UTC (rev 984) @@ -73,9 +73,9 @@ // instanciate the proxies chaine $firstproxy =& $cmd; - for($i = count($c->_proxies)-1; $i >= 0; $i--) + for($i = count($c->proxies)-1; $i >= 0; $i--) { - $proxy_name = $c->_proxies[$i]; + $proxy_name = $c->proxies[$i]; $proxy_classname = "pfcProxyCommand_" . $proxy_name; // try to include the proxy class file from the default path or from the customized path @@ -131,15 +131,13 @@ /** * Force whois reloading */ - function forceWhoisReload($nicktorewhois) + function forceWhoisReload($nickid) { $c =& pfcGlobalConfig::Instance(); $u =& pfcUserConfig::Instance(); $ct =& pfcContainer::Instance(); - $nickid = $ct->getNickid($nicktorewhois); - - // get the user who have $nicktorewhois in their list + // list the users in the same channel as $nickid $channels = $ct->getMeta("nickid-to-channelid", $nickid); $channels = $channels['value']; $channels = array_diff($channels, array('SERVER')); @@ -150,12 +148,12 @@ $otherids = array_merge($otherids, $ret['nickid']); } - // alert them that $nicktorewhois user info just changed + // alert them that $nickid user info just changed foreach($otherids as $otherid) { $cmdstr = 'whois2'; $cmdp = array(); - $cmdp['param'] = $nicktorewhois; + $cmdp['params'] = array($nickid); pfcCommand::AppendCmdToPlay($otherid, $cmdstr, $cmdp); /* Modified: trunk/src/pfccontainer.class.php =================================================================== --- trunk/src/pfccontainer.class.php 2007-03-04 13:37:46 UTC (rev 983) +++ trunk/src/pfccontainer.class.php 2007-03-07 19:14:11 UTC (rev 984) @@ -75,6 +75,7 @@ * @param $nick the nickname to create * @param $nickid is the corresponding nickname id (taken from session) */ + /* function createNick($chan, $nick, $nickid) { $c =& pfcGlobalConfig::Instance(); @@ -97,7 +98,44 @@ return true; } + */ + + function createNick($nickid, $nick) + { + $c =& pfcGlobalConfig::Instance(); + if ($nick == '') + user_error('pfcContainer::createNick nick is empty', E_USER_ERROR); + if ($nickid == '') + user_error('pfcContainer::createNick nickid is empty', E_USER_ERROR); + + $this->setMeta("nickid-to-metadata", $nickid, 'nick', $nick); + $this->setMeta("metadata-to-nickid", 'nick', $this->encode($nick), $nickid); + + return true; + } + + + function joinChan($nickid, $chan) + { + $c =& pfcGlobalConfig::Instance(); + + if ($nickid == '') + user_error('pfcContainer::joinChan nickid is empty', E_USER_ERROR); + + if ($chan == NULL) $chan = 'SERVER'; + + $this->setMeta("nickid-to-channelid", $nickid, $this->encode($chan)); + $this->setMeta("channelid-to-nickid", $this->encode($chan), $nickid); + + // update the SERVER channel + if ($chan != 'SERVER') $this->updateNick($nickid); + + return true; + } + + + /** * Remove (disconnect/quit) the nickname from the server or from a channel * Notice: when a user quit, the caller must take care removeNick from each channels ('SERVER' included) Modified: trunk/src/pfcglobalconfig.class.php =================================================================== --- trunk/src/pfcglobalconfig.class.php 2007-03-04 13:37:46 UTC (rev 983) +++ trunk/src/pfcglobalconfig.class.php 2007-03-07 19:14:11 UTC (rev 984) @@ -49,6 +49,7 @@ var $skip_proxies = array(); // these proxies will be skiped. ex: append "censor" to the list to disable words censoring var $post_proxies = array(); // these proxies will be handled just before to process commands and just after system proxies var $pre_proxies = array(); // these proxies will be handled before system proxies (at begining) + var $proxies = array(); // will contains proxies to execute on each command (filled in the init step) this parameter could not be overridden var $proxies_cfg = array("auth" => array(), "noflood" => array("charlimit" => 450, "msglimit" => 10, @@ -133,7 +134,6 @@ // private parameters var $_sys_proxies = array("lock", "checktimeout", "checknickchange", "auth", "noflood", "censor", "log"); - var $_proxies = array(); // will contains proxies to execute on each command (filled in the init step) var $_dyn_params = array("nick","isadmin","islocked","admins","frozen_channels", "channels", "privmsg", "nickmeta","baseurl"); var $_params_type = array(); var $_query_string = ''; @@ -428,23 +428,23 @@ $this->errors[] = _pfc("'%s' parameter is not valid. Available values are : '%s'", "language", implode(", ", $lg_list)); // calculate the proxies chaine - $this->_proxies = array(); + $this->proxies = array(); foreach($this->pre_proxies as $px) { - if (!in_array($px,$this->skip_proxies) && !in_array($px,$this->_proxies)) - $this->_proxies[] = $px; + if (!in_array($px,$this->skip_proxies) && !in_array($px,$this->proxies)) + $this->proxies[] = $px; } foreach($this->_sys_proxies as $px) { - if (!in_array($px,$this->skip_proxies) && !in_array($px,$this->_proxies)) - $this->_proxies[] = $px; + if (!in_array($px,$this->skip_proxies) && !in_array($px,$this->proxies)) + $this->proxies[] = $px; } foreach($this->post_proxies as $px) { - if (!in_array($px,$this->skip_proxies) && !in_array($px,$this->_proxies)) - $this->_proxies[] = $px; + if (!in_array($px,$this->skip_proxies) && !in_array($px,$this->proxies)) + $this->proxies[] = $px; } // save the proxies path @@ -452,10 +452,12 @@ // check the customized proxies path if ($this->proxies_path != '' && !is_dir($this->proxies_path)) $this->errors[] = _pfc("'%s' directory doesn't exist", $this->proxies_path); + if ($this->proxies_path == '') $this->proxies_path = $this->proxies_path_default; // save the commands path $this->cmd_path_default = dirname(__FILE__).'/commands'; - + if ($this->cmd_path == '') $this->cmd_path = $this->cmd_path_default; + // load smileys from file $this->loadSmileyTheme(); @@ -513,9 +515,9 @@ function _GetCacheFile($serverid = "", $data_private_path = "") { - if ($serverid == "") $serverid = $this->getId(); - if ($data_private_path == "") $data_private_path = $this->data_private_path; - return $data_private_path."/cache/pfcglobalconfig_".$serverid; + if ($serverid == '') $serverid = $this->getId(); + if ($data_private_path == '') $data_private_path = $this->data_private_path; + return $data_private_path.'/cache/'.$serverid.'.php'; } function destroyCache() @@ -545,6 +547,11 @@ // if a cache file exists, remove the lock file because config has been succesfully stored if (file_exists($cachefile_lock)) @unlink($cachefile_lock); + include $cachefile; + foreach($pfc_conf as $key => $val) + $this->$key = $val; + + /* $pfc_configvar = unserialize(file_get_contents($cachefile)); foreach($pfc_configvar as $key => $val) { @@ -552,6 +559,7 @@ if (!in_array($key,$this->_dyn_params)) $this->$key = $val; } + */ return true; // synchronized } @@ -586,7 +594,22 @@ function saveInCache() { $cachefile = $this->_GetCacheFile(); - file_put_contents($cachefile, serialize(get_object_vars($this))); + $data = '<?php '; + + $conf = get_object_vars($this); + $keys = array_keys($conf); + foreach($keys as $k) + if (preg_match('/^_.*/',$k)) + unset($conf[$k]); + + // remove dynamic parameters + foreach($this->_dyn_params as $k) + unset($conf[$k]); + + $data .= '$pfc_conf = '.var_export($conf,true).";\n"; + $data .= '?>'; + + file_put_contents($cachefile, $data/*serialize(get_object_vars($this))*/); if ($this->debug) pxlog("pfcGlobalConfig::saveInCache()", "chatconfig", $this->getId()); } Modified: trunk/src/pfcuserconfig.class.php =================================================================== --- trunk/src/pfcuserconfig.class.php 2007-03-04 13:37:46 UTC (rev 983) +++ trunk/src/pfcuserconfig.class.php 2007-03-07 19:14:11 UTC (rev 984) @@ -68,7 +68,7 @@ function _setParam($p, $v) { $c =& pfcGlobalConfig::Instance(); - $nickid_param = "pfcuserconfig_".$c->getId()./*"_".$this->nickid.*/"_".$p; + $nickid_param = "pfcuserconfig_".$c->getId()."_".$p; $_SESSION[$nickid_param] = $v; $this->$p = $v; } @@ -76,7 +76,7 @@ function _rmParam($p) { $c =& pfcGlobalConfig::Instance(); - $nickid_param = "pfcuserconfig_".$c->getId()./*"_".$this->nickid.*/"_".$p; + $nickid_param = "pfcuserconfig_".$c->getId()."_".$p; unset($_SESSION[$nickid_param]); unset($this->$p); if ($p == 'active') $this->active = false; @@ -98,15 +98,29 @@ $c =& pfcGlobalConfig::Instance(); // do not save anything as long as nickname is not assigned - if ($this->active && $this->nick != "") + //if ($this->active && $this->nick != "") { - $this->_setParam("nick",$this->nick); - $this->_setParam("active",$this->active); - $this->_setParam("channels",$this->channels); - $this->_setParam("privmsg",$this->privmsg); - $this->_setParam("serverid",$this->serverid); + $this->_setParam("nick", $this->nick); + $this->_setParam("active", $this->active); + $this->_setParam("channels", $this->channels); + $this->_setParam("privmsg", $this->privmsg); + $this->_setParam("serverid", $this->serverid); } } + + function isOnline() + { + $ct =& pfcContainer::Instance(); + $online = ($ct->isNickOnline(NULL, $this->nickid) >= 0); + return $online; + } + + function getNickname() + { + if ($this->nick != '') return $this->nick; + $ct =& pfcContainer::Instance(); + return $ct->getNickname($this->nickid); + } } ?> \ No newline at end of file Modified: trunk/src/phpfreechat.class.php =================================================================== --- trunk/src/phpfreechat.class.php 2007-03-04 13:37:46 UTC (rev 983) +++ trunk/src/phpfreechat.class.php 2007-03-07 19:14:11 UTC (rev 984) @@ -265,7 +265,7 @@ $recipientid = isset($res['params'][1]) ? $res['params'][1] : ""; $params = array_slice(is_array($res['params']) ? $res['params'] : array() ,2); $param = implode(" ",$params); // to keep compatibility (will be removed) - $sender = $u->nick; + $sender = $u->getNickname(); // translate the recipientid to the channel name if (isset($u->channels[$recipientid])) @@ -290,8 +290,8 @@ $nickidtopv = $u->privmsg[$recipientid]["pvnickid"]; $cmdstr = 'privmsg2'; $cmdp = array(); - $cmdp['param'] = $u->nick; - $cmdp['params'][] = $u->nick; + $cmdp['param'] = $u->nickid;//$sender; + $cmdp['params'][] = $u->nickid;//$sender; pfcCommand::AppendCmdToPlay($nickidtopv, $cmdstr, $cmdp); } @@ -336,7 +336,7 @@ // do not update when the user just quit if ($cmdname != "update" && $cmdname != "quit" && - (!isset($u->nick) || $u->nick != "")) + $u->nickid != '') { // force an update just after a command is sent // thus the message user just poster is really fastly displayed Modified: trunk/src/proxies/auth.class.php =================================================================== --- trunk/src/proxies/auth.class.php 2007-03-04 13:37:46 UTC (rev 983) +++ trunk/src/proxies/auth.class.php 2007-03-07 19:14:11 UTC (rev 984) @@ -41,6 +41,20 @@ $c =& pfcGlobalConfig::Instance(); $u =& pfcUserConfig::Instance(); + + // do not allow someone to run a command if he is not online + if ($this->name != 'error' && + $this->name != 'connect' && + !$u->isOnline()) + { + $cmdp = $p; + $cmdp["param"] = _pfc("Your must be connected to send a message"); + $cmd =& pfcCommand::Factory("error"); + $cmd->run($xml_reponse, $cmdp); + return; + } + + // protect admin commands $admincmd = array("kick", "ban", "unban", "op", "deop", "debug", "rehash"); if ( in_array($this->name, $admincmd) ) Modified: trunk/src/proxies/checknickchange.class.php =================================================================== --- trunk/src/proxies/checknickchange.class.php 2007-03-04 13:37:46 UTC (rev 983) +++ trunk/src/proxies/checknickchange.class.php 2007-03-07 19:14:11 UTC (rev 984) @@ -38,19 +38,21 @@ $recipient = $p["recipient"]; $recipientid = $p["recipientid"]; $owner = isset($p["owner"]) ? $p["owner"] : ''; - $c =& pfcGlobalConfig::Instance(); - $u =& pfcUserConfig::Instance(); + $c =& pfcGlobalConfig::Instance(); + $u =& pfcUserConfig::Instance(); + $ct =& pfcContainer::Instance(); + $newnick = phpFreeChat::FilterNickname($param); + $oldnick = $ct->getNickname($u->nickid); + if ( $this->name == 'nick' ) { - $newnick = phpFreeChat::FilterNickname($param); - $oldnick = $u->nick; // if the user want to change his nickname but the frozen_nick is enable // then send him a warning - if ( $this->name == "nick" && - $u->nick != "" && - $param != $u->nick && + if ( $this->name == 'nick' && + $oldnick != '' && + $newnick != $oldnick && $c->frozen_nick == true && $owner != $this->proxyname ) { @@ -59,8 +61,7 @@ return; } - $container =& pfcContainer::Instance(); - $newnickid = $container->getNickId($newnick); + $newnickid = $ct->getNickId($newnick); $oldnickid = $u->nickid; if ($newnick == $oldnick && @@ -90,8 +91,8 @@ // allow nick changes only from the parameters array (server side) if ($this->name != 'connect' && // don't check anything on the connect process or it could block the periodic refresh $c->frozen_nick == true && - $u->nick != $c->nick && - $c->nick != "" && // don't change the nickname to empty or the asknick popup will loop indefinatly + $oldnick != $c->nick && + $c->nick != '' && // don't change the nickname to empty or the asknick popup will loop indefinatly $owner != $this->proxyname) { // change the user nickname Modified: trunk/src/proxies/checktimeout.class.php =================================================================== --- trunk/src/proxies/checktimeout.class.php 2007-03-04 13:37:46 UTC (rev 983) +++ trunk/src/proxies/checktimeout.class.php 2007-03-07 19:14:11 UTC (rev 984) @@ -39,11 +39,11 @@ $recipient = $p["recipient"]; $recipientid = $p["recipientid"]; - $c =& pfcGlobalConfig::Instance(); - $u =& pfcUserConfig::Instance(); + $c =& pfcGlobalConfig::Instance(); + $u =& pfcUserConfig::Instance(); + $ct =& pfcContainer::Instance(); // disconnect users from specific channels - $ct =& pfcContainer::Instance(); $disconnected_users = $ct->removeObsoleteNick($c->timeout); for($i=0; $i<count($disconnected_users["nick"]); $i++) { Modified: trunk/themes/default/chat.js.tpl.php =================================================================== --- trunk/themes/default/chat.js.tpl.php 2007-03-04 13:37:46 UTC (rev 983) +++ trunk/themes/default/chat.js.tpl.php 2007-03-07 19:14:11 UTC (rev 984) @@ -15,7 +15,7 @@ require_once dirname(__FILE__).'/../../src/pfcjson.class.php'; $json = new pfcJSON(); ?> -<?php $nick = $u->nick != "" ? $json->encode($u->nick) : $json->encode($c->nick); ?> +<?php $nick = $u->getNickname() != '' ? $json->encode($u->getNickname()) : $json->encode($c->nick); ?> var pfc = null; // will contains a pfcClient instance var pfc_nickname = <?php echo ($GLOBALS["output_encoding"]=="UTF-8" ? $nick : iconv("UTF-8", $GLOBALS["output_encoding"],$nick)); ?>; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |