Compare commits
No commits in common. "22fd48f70a4654931c6ad72f94205d60d381effb" and "4c775bffa03e2fa1d2ab0d1869e1e8e828689d12" have entirely different histories.
22fd48f70a
...
4c775bffa0
2 changed files with 38 additions and 50 deletions
|
|
@ -165,6 +165,24 @@
|
|||
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) {
|
||||
print("[pokerCards] webEvent from " + id + " renderer is " + _rendererID);
|
||||
if (id !== _rendererID) return;
|
||||
|
|
@ -187,6 +205,18 @@
|
|||
}
|
||||
}
|
||||
|
||||
// ── 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 ────────────────────────────────────────────────
|
||||
|
||||
this.preload = function(entityID) {
|
||||
|
|
|
|||
|
|
@ -90,17 +90,7 @@
|
|||
|
||||
function doStand(cb) {
|
||||
_username = _username || AccountServices.username;
|
||||
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;
|
||||
}
|
||||
|
||||
var tok = _token;
|
||||
print("[pokerSeat] doStand called, token: " + (tok ? "ok" : "null") + " username: " + _username + " pokerID: " + _pokerID);
|
||||
|
||||
var xhr = new XMLHttpRequest();
|
||||
|
|
@ -114,33 +104,17 @@
|
|||
var resp = {};
|
||||
try { resp = JSON.parse(xhr.responseText); } catch(e) {}
|
||||
|
||||
// Mid-hand block — server refused, queue a deferred stand
|
||||
if (xhr.status === 400) {
|
||||
print("[pokerSeat] stand deferred (mid-hand)");
|
||||
if (xhr.status === 200 && resp.returned === 0) {
|
||||
// Deferred stand — mid-hand, wait for hand to end
|
||||
// Don't null token yet — we may need it for a retry
|
||||
print("[pokerSeat] deferred stand, waiting for hand to end");
|
||||
_pendingStand = true;
|
||||
notify("You'll stand at the end of this hand");
|
||||
if (cb) cb();
|
||||
return;
|
||||
}
|
||||
|
||||
// Auth failure — token expired, don't touch avatar state
|
||||
if (xhr.status === 401) {
|
||||
print("[pokerSeat] stand 401, token expired");
|
||||
// Immediate stand — clear token and clean up now
|
||||
_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) {
|
||||
MyAvatar.endSit(getSeatPosition(), getSeatRotation());
|
||||
isSeated = false;
|
||||
|
|
@ -175,7 +149,7 @@
|
|||
ensureSession(function (err) {
|
||||
if (err) { notify(err); _busy = false; return; }
|
||||
_username = AccountServices.username;
|
||||
if (!_username) { notify("Not logged in to Overte"); _busy = false; return; }
|
||||
if (!_username) { cb("Not logged in to Overte"); return; }
|
||||
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", POKER_BASE + "/tables/" + _pokerID + "/sit", true);
|
||||
|
|
@ -272,22 +246,6 @@
|
|||
isSeated = false;
|
||||
_pendingStand = false;
|
||||
}
|
||||
Messages.messageReceived.disconnect(onMessage);
|
||||
Messages.unsubscribe("poker:standComplete");
|
||||
_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);
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue