Chatd cleanup finished, from now on only bug fixing.

This commit is contained in:
skodak
2005-02-12 10:54:25 +00:00
parent 21ccc31467
commit e7fbd0b3f2
4 changed files with 45 additions and 104 deletions
+18 -30
View File
@@ -23,8 +23,9 @@ echo 'Moodle chat daemon v1.0 on PHP '.$phpversion." (\$Id$)\n\n";
/// $CFG variables are now defined in database by chat/lib.php
$_SERVER['PHP_SELF'] = 'dummy';
$_SERVER['SERVER_NAME'] = 'dummy';
$_SERVER['PHP_SELF'] = 'dummy';
$_SERVER['SERVER_NAME'] = 'dummy';
$_SERVER['HTTP_USER_AGENT'] = 'dummy';
include('../../config.php');
include('lib.php');
@@ -221,7 +222,7 @@ class ChatDaemon {
static $str;
$info = &$this->sets_info[$sessionid];
$oldlang = chat_language_override($info['lang']);
chat_force_language($info['lang']);
$timenow = time();
@@ -274,7 +275,7 @@ class ChatDaemon {
echo fullname($userinfo['user'])."<br />";
echo "<font color=\"#888888\">$str->idle: ".format_time($lastping, $str)."</font> ";
echo '<a target="empty" href="http://'.$CFG->chat_serverhost.':'.$CFG->chat_serverport.'/?win=beep&amp;beep='.$userinfo['user']->id.
'&chat_sid='.$sessionid.'&amp;groupid='.$this->sets_info[$sessionid]['groupid'].'">'.$str->beep."</a>\n";
'&chat_sid='.$sessionid.'">'.$str->beep."</a>\n";
echo "</font></p>";
echo "<td></tr>";
}
@@ -286,7 +287,6 @@ class ChatDaemon {
echo "</body>\n</html>\n";
chat_language_restore($oldlang);
return ob_get_clean();
}
@@ -373,7 +373,7 @@ class ChatDaemon {
// The refresh value is 2 seconds higher than the configuration variable because we are doing JS refreshes all the time.
// However, if the JS doesn't work for some reason, we still want to refresh once in a while.
$header .= "Refresh: ".(intval($CFG->chat_refresh_userlist) + 2)."; url=http://$CFG->chat_serverhost:$CFG->chat_serverport/?win=users&".
"chat_sid=".$sessionid."&groupid=".$this->sets_info[$sessionid]['groupid']."\n";
"chat_sid=".$sessionid."\n";
$header .= "\n";
// That's enough headers for one lousy dummy response
@@ -458,7 +458,7 @@ class ChatDaemon {
socket_close($handle);
}
function promote_final($sessionid, $groupid, $customdata) {
function promote_final($sessionid, $customdata) {
if(isset($this->conn_sets[$sessionid])) {
$this->trace('Set cannot be finalized: Session '.$sessionid.' is already active');
return false;
@@ -488,18 +488,6 @@ class ChatDaemon {
global $CHAT_HTMLHEAD_JS, $CFG;
// A really sad thing, to have to do this by hand.... :-(
$lang = NULL;
if(empty($lang) && !empty($course->lang)) {
$lang = $course->lang;
}
if(empty($lang) && !empty($user->lang)) {
$lang = $user->lang;
}
if(empty($lang)) {
$lang = $CFG->lang;
}
$this->conn_sets[$sessionid] = $this->conn_half[$sessionid];
// This whole thing needs to be purged of redundant info, and the
@@ -512,8 +500,8 @@ class ChatDaemon {
'chatid' => $chat->id,
'user' => $user,
'userid' => $user->id,
'groupid' => $groupid,
'lang' => $lang,
'groupid' => $chatuser->groupid,
'lang' => $chatuser->lang,
'quirks' => $customdata['quirks']
);
@@ -530,14 +518,14 @@ class ChatDaemon {
$this->dismiss_half($sessionid, false);
$this->write_data($this->conn_sets[$sessionid][CHAT_CONNECTION_CHANNEL], $CHAT_HTMLHEAD_JS);
$this->trace('Connection accepted: '.$this->conn_sets[$sessionid][CHAT_CONNECTION_CHANNEL].', SID: '.$sessionid.' UID: '.$chatuser->userid.' GID: '.intval($groupid), E_USER_WARNING);
$this->trace('Connection accepted: '.$this->conn_sets[$sessionid][CHAT_CONNECTION_CHANNEL].', SID: '.$sessionid.' UID: '.$chatuser->userid.' GID: '.$chatuser->groupid, E_USER_WARNING);
// Finally, broadcast the "entered the chat" message
$msg = &New stdClass;
$msg->chatid = $chatuser->chatid;
$msg->userid = $chatuser->userid;
$msg->groupid = 0;
$msg->groupid = $chatuser->groupid;
$msg->system = 1;
$msg->message = 'enter';
$msg->timestamp = time();
@@ -548,7 +536,7 @@ class ChatDaemon {
return true;
}
function promote_ufo($handle, $type, $sessionid, $groupid, $customdata) {
function promote_ufo($handle, $type, $sessionid, $customdata) {
if(empty($this->conn_ufo)) {
return false;
}
@@ -590,7 +578,7 @@ class ChatDaemon {
$this->conn_half[$sessionid][$type] = $handle;
// Do the bookkeeping
$this->promote_final($sessionid, $groupid, $customdata);
$this->promote_final($sessionid, $customdata);
// It's not an UFO anymore
$this->dismiss_ufo($handle, false);
@@ -712,7 +700,8 @@ class ChatDaemon {
{
// Simply give them the message
$output = chat_format_message_manually($message, $info['courseid'], $sender, $info['user'], $info['lang']);
chat_force_language($info['lang']);
$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->beep) {
@@ -740,7 +729,7 @@ class ChatDaemon {
$msg = &New stdClass;
$msg->chatid = $info['chatid'];
$msg->userid = $info['userid'];
$msg->groupid = 0;
$msg->groupid = $info['groupid'];
$msg->system = 1;
$msg->message = 'exit';
$msg->timestamp = time();
@@ -984,7 +973,7 @@ while(true) {
continue;
}
if(!ereg('win=(chat|users|message|beep).*&chat_sid=([a-zA-Z0-9]*)&groupid=([0-9]*) HTTP', $data, $info)) {
if(!ereg('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);
$DAEMON->dismiss_ufo($handle, true, 'Request with malformed data; connection closed');
@@ -993,7 +982,6 @@ while(true) {
$type = $info[1];
$sessionid = $info[2];
$groupid = $info[3];
$customdata = array();
@@ -1039,7 +1027,7 @@ while(true) {
}
// OK, now we know it's something good... promote it and pass it all the data it needs
$DAEMON->promote_ufo($handle, $type, $sessionid, $groupid, $customdata);
$DAEMON->promote_ufo($handle, $type, $sessionid, $customdata);
continue;
}
}
+20 -28
View File
@@ -6,7 +6,6 @@
require('../lib.php');
$chat_sid = required_param('chat_sid', PARAM_ALPHANUM);
$groupid = optional_param('groupid', 0, PARAM_INT);
if (!$chatuser = get_record('chat_users', 'sid', $chat_sid)) {
error('Not logged in!');
@@ -14,19 +13,8 @@
chat_force_language($chatuser->lang);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=<?php echo get_string('thischarset'); ?>" />
<title>Message Input</title>
<?php
$focus = '';
include("$CFG->javascript");
?>
ob_start();
?>
<script type="text/javascript">
<!--
@@ -36,8 +24,8 @@ function empty_field_and_submit() {
var inpf = document.getElementById('inputform');
cf.chat_msgidnr.value = parseInt(cf.chat_msgidnr.value) + 1;
cf.chat_message.value = inpf.chat_message.value;
cf.submit();
inpf.chat_message.value='';
cf.submit();
inpf.chat_message.focus();
return false;
}
@@ -59,22 +47,26 @@ function reloadusers() {
}
// -->
</script>
</head>
<?php
<body bgcolor="<?php echo $THEME->body ?>" onload="document.getElementById('inputform').chat_message.focus(); prepareusers();">
$meta = ob_get_clean();
// TODO: there will be two onload in body tag, does it matter?
print_header('', '', '', 'inputform.chat_message', $meta, false, '&nbsp;', '', false, 'onload="setfocus(); prepareusers();"');
<form action="../empty.php" method="get" target="empty" id="inputform" onsubmit="return empty_field_and_submit();">
&gt;&gt; <input type="text" name="chat_message" size="60" value="" />
<?php helpbutton("chatting", get_string("helpchatting", "chat"), "chat", true, false); ?>
</form>
?>
<form action="<?php echo "http://$CFG->chat_serverhost:$CFG->chat_serverport/"; ?>" method="get" target="empty" id="sendform">
<input type="hidden" name="win" value="message" />
<input type="hidden" name="chat_message" value="" />
<input type="hidden" name="chat_msgidnr" value="0" />
<input type="hidden" name="chat_sid" value="<?php echo $chat_sid ?>" />
<input type="hidden" name="groupid" value="<?php echo $groupid ?>" />
</form>
<form action="../empty.php" method="get" target="empty" id="inputform"
onsubmit="return empty_field_and_submit();">
&gt;&gt;<input type="text" name="chat_message" size="60" value="" />
<?php helpbutton("chatting", get_string("helpchatting", "chat"), "chat", true, false); ?>
</form>
<form action="<?php echo "http://$CFG->chat_serverhost:$CFG->chat_serverport/"; ?>" method="get" target="empty" id="sendform">
<input type="hidden" name="win" value="message" />
<input type="hidden" name="chat_message" value="" />
<input type="hidden" name="chat_msgidnr" value="0" />
<input type="hidden" name="chat_sid" value="<?php echo $chat_sid ?>" />
</form>
</body>
</html>
+2 -1
View File
@@ -50,13 +50,14 @@
error('Could not log in to chat room!!');
}
$params = "chat_sid=$chat_sid&amp;groupid=$groupid";
$params = "chat_sid=$chat_sid";
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=<?php echo get_string('thischarset'); ?>" />
<title>
<?php echo "$strchat: $course->shortname: $chat->name$groupname" ?>
</title>
+5 -45
View File
@@ -301,7 +301,7 @@ function chat_force_language($lang) {
if(!empty($CFG->locale)) {
unset($CFG->locale);
}
$CFG->lang = clean_filename($lang);
$CFG->lang = $lang;
moodle_setlocale();
}
@@ -359,7 +359,7 @@ function chat_get_latest_message($chatid, $groupid=0) {
function chat_login_user($chatid, $version, $groupid, $course) {
global $USER;
if ($chatuser = get_record_select('chat_users', "chatid='$chatid' AND userid='$USER->id' AND groupid='$groupid'")) {
if (($version != 'sockets') and $chatuser = get_record_select('chat_users', "chatid='$chatid' AND userid='$USER->id' AND groupid='$groupid'")) {
$chatuser->version = $version;
$chatuser->ip = $USER->lastIP;
$chatuser->lastping = time();
@@ -411,13 +411,7 @@ function chat_delete_old_users() {
global $CFG;
if ($CFG->chat_method == 'sockets') {
// delete very outdated users not deleted by chatd,
// let normal deleting to chatd, because it needs to output the message
$timeold = time() - ($CFG->chat_old_ping * 3);
} else {
$timeold = time() - $CFG->chat_old_ping;
}
$timeold = time() - $CFG->chat_old_ping;
$query = "lastping < '$timeold'";
@@ -479,41 +473,14 @@ function chat_update_chat_times($chatid=0) {
}
function chat_language_override($language) {
// Override the highest-ranking language variable from current_language()
// And save it so we can restore it again afterwards
global $CFG;
$oldlang = empty($CFG->courselang) ? NULL : $CFG->courselang;
$CFG->courselang = $language;
return $oldlang;
}
function chat_language_restore($language = NULL) {
// Restore the highest-ranking language variable from current_language()
global $CFG;
if(!empty($language)) {
$CFG->courselang = $language;
}
}
function chat_format_message_manually($message, $courseid, $sender, $currentuser, $language = NULL) {
function chat_format_message_manually($message, $courseid, $sender, $currentuser) {
global $CFG;
$output = New stdClass;
$output->beep = false; // by default
$output->refreshusers = false; // by default
if(empty($language)) {
$language = current_language();
}
$oldcfglang = chat_language_override($language);
// Get some additional info now that the language has been correctly set
// Get some additional info
// But before that :-) let's override get_user_timezone() for this call... messy stuff...
$tz = ($currentuser->timezone == 99) ? $CFG->timezone : $currentuser->timezone;
@@ -536,10 +503,6 @@ function chat_format_message_manually($message, $courseid, $sender, $currentuser
$output->refreshusers = true; //force user panel refresh ASAP
}
// Don't forget to reset the language before returning!!!
if(!empty($oldcfglang)) {
$CFG->courselang = $oldcfglang;
}
return $output;
}
@@ -602,9 +565,6 @@ function chat_format_message_manually($message, $courseid, $sender, $currentuser
}
$output->html .= "</font></td></tr></table>";
// Don't forget to reset the language before returning!!!
chat_language_restore($oldcfglang);
return $output;
}