Fix invalid token on changing seats
This commit is contained in:
parent
091e9df295
commit
aec4344851
1 changed files with 41 additions and 35 deletions
|
|
@ -108,62 +108,68 @@
|
|||
xhr.setRequestHeader("Authorization", "Bearer " + _token);
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState !== 4) return;
|
||||
print("[pokerSeat] sit error response: " + xhr.status + " " + xhr.responseText);
|
||||
print("[pokerSeat] sit response: " + xhr.status + " " + xhr.responseText);
|
||||
if (xhr.status === 200) {
|
||||
// Seat reserved — now physically sit the avatar
|
||||
MyAvatar.beginSit(getSeatPosition(), getSeatRotation());
|
||||
isSeated = true;
|
||||
Entities.editEntity(_entityID, { visible: false });
|
||||
Controller.actionEvent.connect(onActionEvent);
|
||||
|
||||
Messages.sendMessage("poker:seat", JSON.stringify({
|
||||
event: "sit",
|
||||
tableID: _tableID,
|
||||
pokerID: _pokerID,
|
||||
seatIndex: _seatIndex,
|
||||
username: _username,
|
||||
event: "sit", tableID: _tableID, pokerID: _pokerID,
|
||||
seatIndex: _seatIndex, username: _username,
|
||||
}));
|
||||
_busy = false;
|
||||
} else {
|
||||
try {
|
||||
var err = JSON.parse(xhr.responseText);
|
||||
notify(err.error || "Could not sit down");
|
||||
var resp = JSON.parse(xhr.responseText);
|
||||
if (resp.error === "already seated") {
|
||||
// Server thinks we're seated — stand first, then re-sit
|
||||
print("[pokerSeat] recovering stale seat, standing first");
|
||||
doStand(function() { onSit(); });
|
||||
return;
|
||||
}
|
||||
notify(resp.error || "Could not sit down");
|
||||
} catch (e) {
|
||||
notify("Could not sit down (" + xhr.status + ")");
|
||||
}
|
||||
}
|
||||
_busy = false;
|
||||
}
|
||||
};
|
||||
xhr.send(JSON.stringify({
|
||||
seatIndex: parseInt(_seatIndex),
|
||||
}));
|
||||
var payload = JSON.stringify({ seatIndex: parseInt(_seatIndex) });
|
||||
print("[pokerSeat] sit payload: " + payload + " token: " + _token + " url: " + POKER_BASE + "/tables/" + _pokerID + "/sit");
|
||||
xhr.send(payload);
|
||||
});
|
||||
}
|
||||
|
||||
function onStand() {
|
||||
if (!isSeated) return;
|
||||
|
||||
function doStand(cb) {
|
||||
var tok = getSharedToken(); // or _token if keeping per-instance
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", POKER_BASE + "/tables/" + _pokerID + "/stand", true);
|
||||
xhr.setRequestHeader("Content-Type", "application/json");
|
||||
xhr.setRequestHeader("Authorization", "Bearer " + _token);
|
||||
xhr.setRequestHeader("Authorization", "Bearer " + tok);
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState !== 4) return;
|
||||
// Stand regardless of server response — worst case server cleans up on disconnect
|
||||
_token = null; // invalidate immediately on stand
|
||||
if (isSeated) {
|
||||
MyAvatar.endSit(getSeatPosition(), getSeatRotation());
|
||||
isSeated = false;
|
||||
Entities.editEntity(_entityID, { visible: true });
|
||||
Controller.actionEvent.disconnect(onActionEvent);
|
||||
|
||||
Messages.sendMessage("poker:seat", JSON.stringify({
|
||||
event: "stand",
|
||||
tableID: _tableID,
|
||||
seatIndex: _seatIndex,
|
||||
username: _username,
|
||||
event: "stand", tableID: _tableID,
|
||||
seatIndex: _seatIndex, username: _username,
|
||||
}));
|
||||
}
|
||||
if (cb) cb();
|
||||
};
|
||||
xhr.send(JSON.stringify({ seatIndex: parseInt(_seatIndex) }));
|
||||
}
|
||||
|
||||
function onStand() {
|
||||
if (!isSeated) return;
|
||||
doStand(null);
|
||||
}
|
||||
|
||||
function onActionEvent(action, value) {
|
||||
if (action === JUMP_ACTION && value > 0) {
|
||||
onStand();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue