Compare commits

..

2 commits

Author SHA1 Message Date
nak
22fd48f70a Fix hole card rendering 2026-03-21 23:25:56 +00:00
nak
6a8800dc64 Fix sit/stand code (real) 2026-03-21 23:08:28 +00:00
2 changed files with 50 additions and 38 deletions

View file

@ -165,24 +165,6 @@
return { rank: rank, suit: suit }; return { rank: rank, suit: suit };
} }
function onCardsDealt(cards) {
if (!cards || cards.length < 2) return;
var card1 = parseCard(cards[0]);
var card2 = parseCard(cards[1]);
print("[pokerCards] dealt " + cards[0] + " " + cards[1]);
_pendingCards = { card1: card1, card2: card2 };
_rendererID = Entities.addEntity({
type: "Web",
name: "card-renderer",
sourceUrl: "https://wizards.cyou/tablet/card-face.html",
position: MyAvatar.position,
dimensions: { x: 0.01, y: 0.01, z: 0.01 },
visible: false,
}, "local");
}
function onWebEventReceived(id, data) { function onWebEventReceived(id, data) {
print("[pokerCards] webEvent from " + id + " renderer is " + _rendererID); print("[pokerCards] webEvent from " + id + " renderer is " + _rendererID);
if (id !== _rendererID) return; if (id !== _rendererID) return;
@ -205,18 +187,6 @@
} }
} }
// ── web entity event listener ────────────────────────────────
function onWebEventReceived(id, data) {
if (id !== _rendererID) return;
try {
var msg = JSON.parse(data);
if (msg.type === "cardTexture") {
onTextureReady(msg.dataURI);
}
} catch(e) {}
}
// ── lifecycle ──────────────────────────────────────────────── // ── lifecycle ────────────────────────────────────────────────
this.preload = function(entityID) { this.preload = function(entityID) {

View file

@ -90,7 +90,17 @@
function doStand(cb) { function doStand(cb) {
_username = _username || AccountServices.username; _username = _username || AccountServices.username;
var tok = _token; var tok = _token
// If no token, need to re-auth first
if (!_token) {
ensureSession(function(err) {
if (err) { print("[pokerSeat] doStand: no session: " + err); if (cb) cb(); return; }
doStand(cb);
});
return;
}
print("[pokerSeat] doStand called, token: " + (tok ? "ok" : "null") + " username: " + _username + " pokerID: " + _pokerID); print("[pokerSeat] doStand called, token: " + (tok ? "ok" : "null") + " username: " + _username + " pokerID: " + _pokerID);
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
@ -104,17 +114,33 @@
var resp = {}; var resp = {};
try { resp = JSON.parse(xhr.responseText); } catch(e) {} try { resp = JSON.parse(xhr.responseText); } catch(e) {}
if (xhr.status === 200 && resp.returned === 0) { // Mid-hand block — server refused, queue a deferred stand
// Deferred stand — mid-hand, wait for hand to end if (xhr.status === 400) {
// Don't null token yet — we may need it for a retry print("[pokerSeat] stand deferred (mid-hand)");
print("[pokerSeat] deferred stand, waiting for hand to end");
_pendingStand = true; _pendingStand = true;
notify("You'll stand at the end of this hand");
if (cb) cb(); if (cb) cb();
return; return;
} }
// Immediate stand — clear token and clean up now // Auth failure — token expired, don't touch avatar state
if (xhr.status === 401) {
print("[pokerSeat] stand 401, token expired");
_token = null; _token = null;
if (cb) cb();
return;
}
// Any other non-200 — server error, log and bail without touching avatar
if (xhr.status !== 200) {
print("[pokerSeat] stand failed (" + xhr.status + "), leaving avatar state intact");
if (cb) cb();
return;
}
// 200 — successful stand, clean up everything
_token = null;
_pendingStand = false;
if (isSeated) { if (isSeated) {
MyAvatar.endSit(getSeatPosition(), getSeatRotation()); MyAvatar.endSit(getSeatPosition(), getSeatRotation());
isSeated = false; isSeated = false;
@ -149,7 +175,7 @@
ensureSession(function (err) { ensureSession(function (err) {
if (err) { notify(err); _busy = false; return; } if (err) { notify(err); _busy = false; return; }
_username = AccountServices.username; _username = AccountServices.username;
if (!_username) { cb("Not logged in to Overte"); return; } if (!_username) { notify("Not logged in to Overte"); _busy = false; return; }
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
xhr.open("POST", POKER_BASE + "/tables/" + _pokerID + "/sit", true); xhr.open("POST", POKER_BASE + "/tables/" + _pokerID + "/sit", true);
@ -246,6 +272,22 @@
isSeated = false; isSeated = false;
_pendingStand = false; _pendingStand = false;
} }
Messages.messageReceived.disconnect(onMessage);
Messages.unsubscribe("poker:standComplete");
_token = null; _token = null;
}; };
Messages.subscribe("poker:standComplete");
Messages.messageReceived.connect(onMessage);
function onMessage(channel, message) {
if (channel !== "poker:standComplete") return;
try {
var data = JSON.parse(message);
if (data.username !== _username) return;
} catch(e) { return; }
_pendingStand = false;
// Now actually stand
doStand(null);
}
}); });