[Phpfreechat-svn] SF.net SVN: phpfreechat: [488] trunk/src/commands
Status: Beta
Brought to you by:
kerphi
From: <ke...@us...> - 2006-05-11 15:51:11
|
Revision: 488 Author: kerphi Date: 2006-05-11 08:51:03 -0700 (Thu, 11 May 2006) ViewCVS: http://svn.sourceforge.net/phpfreechat/?rev=488&view=rev Log Message: ----------- Bug fix: When I chat in 1:1. If one of the two members quit the discussion, closing this tab, if I speak again it will open a new tab for him, ok !! But if my correspondent quit the chat because he close his browser, it must appear off line, for the moment we could continue to chat with nobody... It could be fine to detect the off line status of the correspondent and display a "your correspondent is off line" message... Modified Paths: -------------- trunk/src/commands/getonlinenick.class.php trunk/src/commands/send.class.php Modified: trunk/src/commands/getonlinenick.class.php =================================================================== --- trunk/src/commands/getonlinenick.class.php 2006-05-11 15:11:34 UTC (rev 487) +++ trunk/src/commands/getonlinenick.class.php 2006-05-11 15:51:03 UTC (rev 488) @@ -13,6 +13,7 @@ $oldnicklist = isset($_SESSION[$nicklist_sid]) ? $_SESSION[$nicklist_sid] : array(); $container =& $c->getContainerInstance(); + $disconnected_users = $container->removeObsoleteNick(NULL,$c->timeout); $disconnected_users = $container->removeObsoleteNick($recipient,$c->timeout); foreach ($disconnected_users as $u) { Modified: trunk/src/commands/send.class.php =================================================================== --- trunk/src/commands/send.class.php 2006-05-11 15:11:34 UTC (rev 487) +++ trunk/src/commands/send.class.php 2006-05-11 15:51:03 UTC (rev 488) @@ -6,25 +6,54 @@ { function run(&$xml_reponse, $clientid, $param, $sender, $recipient, $recipientid) { - $c =& $this->c; - $u =& $this->u; + $c =& $this->c; + $u =& $this->u; + $nick = phpFreeChat::FilterSpecialChar($sender); + $text = phpFreeChat::PreFilterMsg($param); - //$xml_reponse->addScript("alert('send: sender=".addslashes($sender)." param=".addslashes($param)." recipient=".addslashes($recipient)." recipientid=".addslashes($recipientid)."');"); - // check the nick is not allready known - $nick = phpFreeChat::FilterSpecialChar($sender); - $text = phpFreeChat::PreFilterMsg($param); - + // if this channel is a pv (one to one channel), + // first of all, check if the other user is connected + // if he is not connected anymore, display an error + $can_send = true; + if (isset($u->privmsg[$recipientid])) + { + $pvnick = $u->privmsg[$recipientid]["name"]; + // now check if this user is currently online + $container =& $c->getContainerInstance(); + $onlineusers = $container->getOnlineNick(NULL); + if (!in_array($pvnick,$onlineusers)) + { + $cmd =& pfcCommand::Factory("error"); + $cmd->run($xml_reponse, $clientid, _pfc("Can't send the message, %s is offline", $pvnick)); + $can_send = false; + } + } + + + // check the sent text is not empty and the user has a none empty nickname $errors = array(); if ($text == "") $errors[$c->prefix."words"] = _pfc("Text cannot be empty"); if ($nick == "") $errors[$c->prefix."handle"] = _pfc("Please enter your nickname"); - if (count($errors) == 0) + if (count($errors) > 0) { + // 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()); + $cmd =& pfcCommand::Factory("error"); + $cmd->run($xml_reponse, $clientid, $errors); + if (isset($errors[$c->prefix."handle"])) // the nick is empty so give it focus + $xml_reponse->addScript("$('".$c->prefix."handle').focus();"); + $can_send = false; + } + + + // Now send the message if there is no errors + if ($can_send) + { $container =& $c->getContainerInstance(); $msgid = $container->write($recipient, $nick, "send", $text); if ($c->debug) pxlog("/send ".$text." (a user just sent a message -> nick=".$u->nick.")", "chat", $c->getId()); - - //$xml_reponse->addScript("alert('send: msgid=".$msgid."');"); // a message has been posted so : // - clear errors @@ -32,16 +61,6 @@ $xml_reponse->addScript("pfc.clearError(Array('".$c->prefix."words"."','".$c->prefix."handle"."'));"); $xml_reponse->addScript("$('".$c->prefix."words').focus();"); } - else - { - // 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()); - $cmd =& pfcCommand::Factory("error"); - $cmd->run($xml_reponse, $clientid, $errors); - if (isset($errors[$c->prefix."handle"])) // the nick is empty so give it focus - $xml_reponse->addScript("$('".$c->prefix."handle').focus();"); - } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |