Skip to content

Commit

Permalink
Fixed firefox bug, readyState 3 is broken again
Browse files Browse the repository at this point in the history
  • Loading branch information
tinspin committed Feb 13, 2022
1 parent 90fa35e commit 41118f1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
2 changes: 1 addition & 1 deletion res/fuse.html
Expand Up @@ -105,7 +105,7 @@
<li>Global 100% Read Uptime (registered users<br>will always be able to login and play)</li>
<li>&nbsp;</li>
<li>Low internal latency: <a href="http://fuse.rupy.se/data">statistics</a> (Raspberry Pi 2)</li>
<li>Open-Source: <a href="https://github.com/tinspin/fuse">https://github.com/tinspin/fuse</a></li>
<li>Source Available: <a href="https://github.com/tinspin/fuse">https://github.com/tinspin/fuse</a></li>
<li>Integrated Forum: <a href="http://talk.binarytask.com">http://talk.binarytask.com</a></li>
<li>&nbsp;</li>
<li>Physics: Client predicts everything</li>
Expand Down
27 changes: 23 additions & 4 deletions res/play.html
Expand Up @@ -157,6 +157,7 @@
return split;
}
}
var body_fix;
function http(path, data) {
hide_fail();
var async = false;
Expand Down Expand Up @@ -208,17 +209,31 @@
catch(e) {}
}
if(state == 3) {
if(send_game) {
setTimeout(function() { push('game|' + game); list() }, 1000); // Give IE time to handle 2000kb payload.
send_game = false;
}
if(ie)
xhr.onprogress = function() {
var body = xhr.responseText.substring(size, xhr.responseText.length);
chop(body, '\n'); // last \n instead
body_fix = xhr.responseText.substring(size, xhr.responseText.length);
chop(body_fix, '\n'); // last \n instead
size = xhr.responseText.length;
};
else
xhr.onreadystatechange = function() {
/* Now firefox sends multiple readyState == 3 for each chunk.
* The ugly workaround I'm doing now is to see if the body is
* new and ONLY then I chop it! I'm quitting browser dev and
* focusing on C clients.
*/
if(xhr.readyState == 3) {
var body = xhr.responseText.substring(size, xhr.responseText.length);
chop(body, '\n\n'); // last \n\n instead
var temp_body = xhr.responseText.substring(size, xhr.responseText.length);
//console.log(temp_body + ' hello ' + (temp_body != body_fix));
if(temp_body != body_fix && temp_body.indexOf('data: noop') == -1) {
//console.log('yo');
chop(temp_body, '\n\n'); // last \n\n instead
body_fix = temp_body;
}
size = xhr.responseText.length;
}
};
Expand All @@ -237,13 +252,15 @@
var trim = part[i].trim();
if(trim.length > 0)
try {
//console.log(trim);
if(trim.indexOf('data: ') == 0)
read(trim.substring(6, trim.length));
else
read(trim);
}
catch(e) {
alert(e + ' ' + body);
console.log(e + ' ' + body);
}
}
}
Expand All @@ -269,10 +286,12 @@
function read(data) {
if(show)
element('pull').innerHTML += data + '\n';
/*
if(send_game) {
setTimeout(function() { push('game|' + game); list() }, 1000); // Give IE time to handle 2000kb payload.
send_game = false;
}
*/
var split = data.split('|');
if(split.length > 0) {
if(split[0] == 'chat') {
Expand Down
7 changes: 5 additions & 2 deletions src/fuse/Router.java
Expand Up @@ -720,8 +720,11 @@ else if(split[0].equals("poll")) {
if(poll == null)
return "poll|fail|user not online";

if(user.poll == null || !user.poll.equals(poll.name))
return "poll|fail|wrong user";
if(user.poll == null || !user.poll.equals(poll.name)) {
if(debug)
System.err.println(user.poll + " " + poll.name);
return "poll|fail|wrong user";
}

if(accept) {
if(type.equals("join")) {
Expand Down

0 comments on commit 41118f1

Please sign in to comment.