Fix poker_sit token issues
This commit is contained in:
parent
aec4344851
commit
ecf4baa8b4
1 changed files with 37 additions and 41 deletions
|
|
@ -6,9 +6,6 @@
|
||||||
//
|
//
|
||||||
// tableID — Overte entity UUID of the table mesh, used for position calculations
|
// tableID — Overte entity UUID of the table mesh, used for position calculations
|
||||||
// pokerID — poker table slug used for API calls (matches table config id)
|
// pokerID — poker table slug used for API calls (matches table config id)
|
||||||
//
|
|
||||||
// Seat layout is loaded from poker_constants.js so this script
|
|
||||||
// does not need to know anything about the table geometry.
|
|
||||||
|
|
||||||
var constants = Script.require(Script.resolvePath("poker_constants.js"));
|
var constants = Script.require(Script.resolvePath("poker_constants.js"));
|
||||||
var POKER_SEATS = constants.POKER_SEATS;
|
var POKER_SEATS = constants.POKER_SEATS;
|
||||||
|
|
@ -17,8 +14,8 @@
|
||||||
var JUMP_ACTION = 50;
|
var JUMP_ACTION = 50;
|
||||||
|
|
||||||
var _entityID = null;
|
var _entityID = null;
|
||||||
var _tableID = null; // Overte entity UUID of the table mesh
|
var _tableID = null;
|
||||||
var _pokerID = null; // poker table slug for API calls
|
var _pokerID = null;
|
||||||
var _seatIndex = null;
|
var _seatIndex = null;
|
||||||
var _seatData = null;
|
var _seatData = null;
|
||||||
var _token = null;
|
var _token = null;
|
||||||
|
|
@ -61,6 +58,7 @@
|
||||||
|
|
||||||
function ensureSession(cb) {
|
function ensureSession(cb) {
|
||||||
if (_token) { cb(null, _token); return; }
|
if (_token) { cb(null, _token); return; }
|
||||||
|
|
||||||
_username = MyAvatar.displayName;
|
_username = MyAvatar.displayName;
|
||||||
if (!_username) { cb("Not logged in to Overte"); return; }
|
if (!_username) { cb("Not logged in to Overte"); return; }
|
||||||
|
|
||||||
|
|
@ -87,6 +85,32 @@
|
||||||
|
|
||||||
// ── sit / stand ──────────────────────────────────────────────
|
// ── sit / stand ──────────────────────────────────────────────
|
||||||
|
|
||||||
|
function doStand(cb) {
|
||||||
|
var tok = _token;
|
||||||
|
var xhr = new XMLHttpRequest();
|
||||||
|
xhr.open("POST", POKER_BASE + "/tables/" + _pokerID + "/stand", true);
|
||||||
|
xhr.setRequestHeader("Content-Type", "application/json");
|
||||||
|
xhr.setRequestHeader("Authorization", "Bearer " + tok);
|
||||||
|
xhr.onreadystatechange = function () {
|
||||||
|
if (xhr.readyState !== 4) return;
|
||||||
|
_token = null;
|
||||||
|
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,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
if (cb) cb();
|
||||||
|
};
|
||||||
|
xhr.send(JSON.stringify({ seatIndex: parseInt(_seatIndex) }));
|
||||||
|
}
|
||||||
|
|
||||||
function onSit() {
|
function onSit() {
|
||||||
if (isSeated || _busy) return;
|
if (isSeated || _busy) return;
|
||||||
_busy = true;
|
_busy = true;
|
||||||
|
|
@ -100,8 +124,6 @@
|
||||||
ensureSession(function (err) {
|
ensureSession(function (err) {
|
||||||
if (err) { notify(err); _busy = false; return; }
|
if (err) { notify(err); _busy = false; return; }
|
||||||
|
|
||||||
// POST to server — handles buy-in deduction and seat reservation.
|
|
||||||
// Server will reject if seat is taken or balance insufficient.
|
|
||||||
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);
|
||||||
xhr.setRequestHeader("Content-Type", "application/json");
|
xhr.setRequestHeader("Content-Type", "application/json");
|
||||||
|
|
@ -115,15 +137,17 @@
|
||||||
Entities.editEntity(_entityID, { visible: false });
|
Entities.editEntity(_entityID, { visible: false });
|
||||||
Controller.actionEvent.connect(onActionEvent);
|
Controller.actionEvent.connect(onActionEvent);
|
||||||
Messages.sendMessage("poker:seat", JSON.stringify({
|
Messages.sendMessage("poker:seat", JSON.stringify({
|
||||||
event: "sit", tableID: _tableID, pokerID: _pokerID,
|
event: "sit",
|
||||||
seatIndex: _seatIndex, username: _username,
|
tableID: _tableID,
|
||||||
|
pokerID: _pokerID,
|
||||||
|
seatIndex: _seatIndex,
|
||||||
|
username: _username,
|
||||||
}));
|
}));
|
||||||
_busy = false;
|
_busy = false;
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
var resp = JSON.parse(xhr.responseText);
|
var resp = JSON.parse(xhr.responseText);
|
||||||
if (resp.error === "already seated") {
|
if (resp.error === "already seated") {
|
||||||
// Server thinks we're seated — stand first, then re-sit
|
|
||||||
print("[pokerSeat] recovering stale seat, standing first");
|
print("[pokerSeat] recovering stale seat, standing first");
|
||||||
doStand(function () { onSit(); });
|
doStand(function () { onSit(); });
|
||||||
return;
|
return;
|
||||||
|
|
@ -135,34 +159,8 @@
|
||||||
_busy = false;
|
_busy = false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var payload = JSON.stringify({ seatIndex: parseInt(_seatIndex) });
|
|
||||||
print("[pokerSeat] sit payload: " + payload + " token: " + _token + " url: " + POKER_BASE + "/tables/" + _pokerID + "/sit");
|
|
||||||
xhr.send(payload);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
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 " + tok);
|
|
||||||
xhr.onreadystatechange = function () {
|
|
||||||
if (xhr.readyState !== 4) return;
|
|
||||||
_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,
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
if (cb) cb();
|
|
||||||
};
|
|
||||||
xhr.send(JSON.stringify({ seatIndex: parseInt(_seatIndex) }));
|
xhr.send(JSON.stringify({ seatIndex: parseInt(_seatIndex) }));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function onStand() {
|
function onStand() {
|
||||||
|
|
@ -191,7 +189,6 @@
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load seat geometry from constants keyed by table's seat count
|
|
||||||
var seatCount = getTableSeatCount();
|
var seatCount = getTableSeatCount();
|
||||||
var layout = POKER_SEATS[seatCount];
|
var layout = POKER_SEATS[seatCount];
|
||||||
if (!layout || !layout[parseInt(_seatIndex)]) {
|
if (!layout || !layout[parseInt(_seatIndex)]) {
|
||||||
|
|
@ -203,7 +200,6 @@
|
||||||
print("[pokerSeat] loaded seat " + _seatIndex + " at table " + _tableID);
|
print("[pokerSeat] loaded seat " + _seatIndex + " at table " + _tableID);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Mouse + controller triggers
|
|
||||||
this.clickDownOnEntity = function () { onSit(); };
|
this.clickDownOnEntity = function () { onSit(); };
|
||||||
this.clickUpOnEntity = function () { _busy = false; };
|
this.clickUpOnEntity = function () { _busy = false; };
|
||||||
this.startNearTrigger = function () { onSit(); };
|
this.startNearTrigger = function () { onSit(); };
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue