/** * Socket event handlers for the Wownerogue game */ const SocketHandlers = { _initialized: false, _didConnect: false, _setBannerStatus: function(text, color) { const el = $('#statusValue'); if (!el.length) return; el.text(text); if (color) el.css('color', color); }, _hasPayoutAddress: false, _creditsBalance: 0, _gameMode: null, // Set from the server's game-modes event. Declare it exactly once: a duplicate // key in this object literal would silently shadow the other. _directModeEnabled: false, _directPayoutsEnabled: false, _paymentsEnabled: false, _isSmirkExplicitlyEnabled: function(data) { return !!data && data.smirkEnabled === true; }, _fairnessOffer: null, _pendingFairnessAttempt: null, _randomClientSeed: function() { try { if (!window.crypto || typeof window.crypto.getRandomValues !== 'function') return null; var bytes = new Uint8Array(32); window.crypto.getRandomValues(bytes); return Array.prototype.map.call(bytes, function(b) { return b.toString(16).padStart(2, '0'); }).join(''); } catch (e) { return null; } }, /** Build a start payload only after receiving the server's commitment. */ fairnessAttempt: function(extra) { var offer = this._fairnessOffer; if (!offer || !offer.offerId || !/^[0-9a-f]{64}$/i.test(String(offer.commitment || ''))) { socket.emit('fairness_offer_request'); $('#messages').append($('
' + shortHash + ' ' +
'' + shortClientSeed + ''
);
$('#messages').append($proofMsg);
if (!proofMatchesAttempt) {
$('#messages').append($('' + shortServerSeed + ' ' +
'' + shortClientSeed + '' + shortEffectiveSeed + '' + shortCommitment + '${message}