git.ucc.asn.au
/
progcomp2013.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Prevent race condition with player clicking before AJAX query finishes
[progcomp2013.git]
/
web
/
qwebchess
/
js.js
diff --git
a/web/qwebchess/js.js
b/web/qwebchess/js.js
index
db91e14
..
53e9288
100644
(file)
--- a/
web/qwebchess/js.js
+++ b/
web/qwebchess/js.js
@@
-87,7
+87,10
@@
$(document).ready(function()
}
\r
\r
if (legal)
\r
}
\r
\r
if (legal)
\r
+ {
\r
+ canClick = false;
\r
$.ajax({url : "/cgi-bin/qchess.cgi", data : {x : id[0], y : id[1]}}).done(function(data) {$(this).update(data)});
\r
$.ajax({url : "/cgi-bin/qchess.cgi", data : {x : id[0], y : id[1]}}).done(function(data) {$(this).update(data)});
\r
+ }
\r
});
\r
\r
$.fn.showMoves = function()
\r
});
\r
\r
$.fn.showMoves = function()
\r
@@
-213,7
+216,7
@@
$(document).ready(function()
$(this).html(emptyHTML);
\r
\r
// Collapse into quantum state if on a black square
\r
$(this).html(emptyHTML);
\r
\r
// Collapse into quantum state if on a black square
\r
- if ((dest.getX() + dest.getY()) % 2 != 0 && (dest.html()[0] == '?' || dest.html()[dest.html().length-1]
== '?'
))
\r
+ if ((dest.getX() + dest.getY()) % 2 != 0 && (dest.html()[0] == '?' || dest.html()[dest.html().length-1]
!= dest.html()[0]
))
\r
{
\r
oldHTML = dest.html();
\r
dest.html(oldHTML.replace(/<bold>.*<\/bold>/i, "<bold>?</bold>"));
\r
{
\r
oldHTML = dest.html();
\r
dest.html(oldHTML.replace(/<bold>.*<\/bold>/i, "<bold>?</bold>"));
\r
@@
-225,6
+228,7
@@
$(document).ready(function()
{
\r
console.log("AJAX Response:\n"+data);
\r
var lines = data.split("\n");
\r
{
\r
console.log("AJAX Response:\n"+data);
\r
var lines = data.split("\n");
\r
+ var timeout = false;
\r
for (var i = 0; i < lines.length; ++i)
\r
{
\r
var tokens = lines[i].split(" ");
\r
for (var i = 0; i < lines.length; ++i)
\r
{
\r
var tokens = lines[i].split(" ");
\r
@@
-237,7
+241,7
@@
$(document).ready(function()
if (s1.html()[4] != '0')
\r
{
\r
s2 = $("#board").find("#"+tokens[3]+tokens[4]);
\r
if (s1.html()[4] != '0')
\r
{
\r
s2 = $("#board").find("#"+tokens[3]+tokens[4]);
\r
-
canClick = fals
e;
\r
+
timeout = tru
e;
\r
setTimeout((function(x)
\r
{
\r
return function()
\r
setTimeout((function(x)
\r
{
\r
return function()
\r
@@
-296,6
+300,8
@@
$(document).ready(function()
break;
\r
}
\r
}
\r
break;
\r
}
\r
}
\r
+ if (timeout == false)
\r
+ canClick = true;
\r
}
\r
\r
//Reset the colour of a square
\r
}
\r
\r
//Reset the colour of a square
\r
UCC
git Repository :: git.ucc.asn.au