foreach ($chatroom['users'] as $sessionid => $userid) {
// We will be polling each user as required.
$this->trace('...shall we poll '.$sessionid.'?');
- if ($this->sets_info[$sessionid]['chatuser']->lastmessageping < $this->_last_idle_poll) {
+ if (!empty($this->sets_info[$sessionid]) && isset($this->sets_info[$sessionid]['chatuser']) &&
+ // Having tried to exclude race conditions as already done in user_lazy_update()
+ // please do the real job by checking the last poll.
+ ($this->sets_info[$sessionid]['chatuser']->lastmessageping < $this->_last_idle_poll)) {
$this->trace('YES!');
// This user hasn't been polled since his last message.
$result = $this->write_data($this->conn_sets[$sessionid][CHAT_CONNECTION_CHANNEL], '<!-- poll -->');
return false;
}
+ // Does promote_final() already finish its job?
+ if (!isset($this->sets_info[$sessionid]['lastinfocommit'])) {
+ return false;
+ }
+
$now = time();
// We 'll be cheating a little, and NOT updating the record data as
$timenow = time();
if (empty($str)) {
+ $str = new stdClass();
$str->idle = get_string("idle", "chat");
$str->beep = get_string("beep", "chat");
$str->day = get_string("day");
$monitor = array();
if (!empty($this->conn_ufo)) {
foreach ($this->conn_ufo as $ufoid => $ufo) {
- $monitor[$ufoid] = $ufo->handle;
+ // Avoid socket_select() warnings by preventing the check over invalid resources.
+ if (is_resource($ufo->handle)) {
+ $monitor[$ufoid] = $ufo->handle;
+ } else {
+ $this->dismiss_ufo($ufo->handle, false);
+ }
}
}
// Simply give them the message.
$output = chat_format_message_manually($message, $info['courseid'], $sender, $info['user']);
- $this->trace('Delivering message "'.$output->text.'" to '.$this->conn_sets[$sessionid][CHAT_CONNECTION_CHANNEL]);
+ if ($output !== false) {
+ $this->trace('Delivering message "'.$output->text.'" to ' .
+ $this->conn_sets[$sessionid][CHAT_CONNECTION_CHANNEL]);
- if ($output->beep) {
- $this->write_data($this->conn_sets[$sessionid][CHAT_CONNECTION_CHANNEL],
- '<embed src="'.$this->_beepsoundsrc.'" autostart="true" hidden="true" />');
- }
+ if ($output->beep) {
+ $this->write_data($this->conn_sets[$sessionid][CHAT_CONNECTION_CHANNEL],
+ '<embed src="'.$this->_beepsoundsrc.'" autostart="true" hidden="true" />');
+ }
- if ($info['quirks'] & QUIRK_CHUNK_UPDATE) {
- $output->html .= $GLOBALS['CHAT_DUMMY_DATA'];
- $output->html .= $GLOBALS['CHAT_DUMMY_DATA'];
- $output->html .= $GLOBALS['CHAT_DUMMY_DATA'];
- }
+ if ($info['quirks'] & QUIRK_CHUNK_UPDATE) {
+ $output->html .= $GLOBALS['CHAT_DUMMY_DATA'];
+ $output->html .= $GLOBALS['CHAT_DUMMY_DATA'];
+ $output->html .= $GLOBALS['CHAT_DUMMY_DATA'];
+ }
- if (!$this->write_data($this->conn_sets[$sessionid][CHAT_CONNECTION_CHANNEL], $output->html)) {
- $this->disconnect_session($sessionid);
+ if (!$this->write_data($this->conn_sets[$sessionid][CHAT_CONNECTION_CHANNEL], $output->html)) {
+ $this->disconnect_session($sessionid);
+ }
}
}
}
continue;
}
+ // Ignore desktop browser fake "favorite icon" requests.
+ if (strpos($data, 'GET /favicon.ico HTTP') === 0) {
+ // Known malformed data, drop it without any further notice.
+ continue;
+ }
+
if (!preg_match('/win=(chat|users|message|beep).*&chat_sid=([a-zA-Z0-9]*) HTTP/', $data, $info)) {
// Malformed data.
$daemon->trace('UFO with '.$handle.': Request with malformed data; connection closed', E_USER_WARNING);