Latest goodness from PJ the MAN!

This commit is contained in:
moodler 2004-08-14 16:45:13 +00:00
parent d167ee0786
commit dfd629d768
2 changed files with 28 additions and 14 deletions

View File

@ -135,9 +135,9 @@ class ChatDaemon {
else {
foreach ($this->sets_info as $usersid => $userinfo) {
$lastping = $timenow - $userinfo['chatuser']->lastmessageping;
$popuppar = '\'/user/view.php?id='.$userinfo['user']->id.'&course='.$userinfo['courseid'].'\',\'user'.$userinfo['chatuser']->id.'\',\'\'';
echo '<tr><td width="35">';
echo '<a target="_new" onclick="return openpopup(\'/user/view.php?id='.$userinfo['chatuser']->id.'&amp;course='.$userinfo['courseid'].'\',\'user'.$userinfo['chatuser']->id.'\',\'\');" href="'.$CFG->wwwroot.'/user/view.php?id='.$userinfo['chatuser']->id.'&amp;course='.$userinfo['courseid'].'">';
echo '<a target="_new" onclick="return openpopup('.$popuppar.');" href="'.$CFG->wwwroot.'/user/view.php?id='.$userinfo['chatuser']->id.'&amp;course='.$userinfo['courseid'].'">';
print_user_picture($userinfo['user']->id, 0, $userinfo['user']->picture, false, false, false);
echo "</a></td><td valign=center>";
echo "<p><font size=1>";
@ -282,6 +282,20 @@ class ChatDaemon {
break;
case CHAT_SIDEKICK_MESSAGE:
// Incoming message
// Browser stupidity protection from duplicate messages:
$messageindex = intval($customdata['index']);
if($this->sets_info[$sessionid]['lastmessageindex'] >= $messageindex) {
// We have already broadcasted that!
trace('discarding message with stale index');
break;
}
else {
// Update our info
$this->sets_info[$sessionid]['lastmessageindex'] = $messageindex;
}
$msg = &New stdClass;
$msg->chatid = $this->sets_info[$sessionid]['chatid'];
$msg->userid = $this->sets_info[$sessionid]['userid'];
@ -377,6 +391,7 @@ class ChatDaemon {
// code base to follow suit. But AFTER development is done.
$this->sets_info[$sessionid] = array(
'lastinfocommit' => 0,
'lastmessageindex' => 0,
'courseid' => $course->id,
'chatuser' => $chatuser,
'chatid' => $chatuser->chatid,
@ -795,13 +810,13 @@ while(true) {
break;
case 'message':
$type = CHAT_SIDEKICK_MESSAGE;
if(!ereg('chat_message=([^&]*)[& ]', $data, $info)) {
if(!ereg('chat_message=([^&]*)[& ]chat_msgidnr=([^&]*)[& ]', $data, $info)) {
trace('Message sidekick did not contain a valid message', E_USER_WARNING);
$DAEMON->dismiss_ufo($handle);
continue;
}
else {
$customdata = array('message' => $info[1]);
$customdata = array('message' => $info[1], 'index' => $info[2]);
}
break;
default:

View File

@ -32,7 +32,8 @@ optional_variable($chat_pretext, '');
scroll_active = true;
function empty_field_and_submit() {
cf = document.getElementById('chatform');
cf.chat_message.value=document.f.chat_message.value;
cf.chat_msgidnr.value = parseInt(cf.chat_msgidnr.value) + 1;
cf.chat_message.value = document.f.chat_message.value;
cf.submit();
document.f.chat_message.value='';
document.f.chat_message.focus();
@ -42,10 +43,7 @@ function empty_field_and_submit() {
</script>
</head>
<body bgcolor="<?php echo $THEME->body ?>"
OnLoad="document.f.chat_message.focus();document.f.chat_message.select();">
<body bgcolor="<?php echo $THEME->body ?>" onload="document.f.chat_message.focus();document.f.chat_message.select();">
<!--
<form action="<?php echo "http://$CFG->chat_serverhost:$CFG->chat_serverport"; ?>" method="GET" target="empty" name="f" onsubmit="return empty_field_and_submit()">
@ -62,11 +60,12 @@ function empty_field_and_submit() {
<!--
<form action="../insert.php" method="GET" target="empty" id="chatform" onsubmit="return empty_field_and_submit()">
-->
<input type="hidden" name="win" value="message">
<input type="hidden" name="chat_version" value="sockets">
<input type="hidden" name="chat_message">
<input type="hidden" name="chat_sid" value="<?php echo $chat_sid ?>">
<input type="hidden" name="groupid" value="<?php echo $groupid ?>">
<input type="hidden" name="win" value="message" />
<input type="hidden" name="chat_version" value="sockets" />
<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>
</body>