2012-02-06 22:00:24 +00:00
|
|
|
/*
|
Add ID codes for positive user identification, and minor fixups.
Users can specify an identification code when they connect (8-100 characters), only if they are using HTTPS. This code is combined with their nickname and a server-side secret, hashed with SHA-256, and condensed down to 64 bits by XORing every 8th byte with each other, and finally converted to base64 (with the trailing = removed). This code is displayed in a tooltip when hovering over the user's chat (TODO: mobile way to view it).
Sigils have been added to be displayed before the user's name in the chat. Admins get @, users with an ID code get +, and normal users get nothing. The IS_ADMIN field is now deprecated, as this can be determined from the user's sigil. It will be removed eventually, but is still being included in events even though the official client should not be using it anymore.
Kicks and bans are now always displayed to all users, even if the server isn't transmitting quit events normally.
2018-03-03 01:24:58 +00:00
|
|
|
* Copyright (c) 2012-2018, Andy Janata
|
2012-02-02 22:47:23 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without modification, are permitted
|
|
|
|
* provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* * Redistributions of source code must retain the above copyright notice, this list of conditions
|
|
|
|
* and the following disclaimer.
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright notice, this list of
|
|
|
|
* conditions and the following disclaimer in the documentation and/or other materials provided
|
|
|
|
* with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
|
|
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
|
|
|
|
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2012-01-12 22:25:04 +00:00
|
|
|
/**
|
|
|
|
* Builder for ajax requests. This contains methods to add every possible parameter to an ajax
|
|
|
|
* request, even if it doesn't make sense for the operation code.
|
|
|
|
*
|
2012-02-06 22:00:24 +00:00
|
|
|
* @author Andy Janata (ajanata@socialgamer.net)
|
2012-01-12 22:25:04 +00:00
|
|
|
* @param {string}
|
|
|
|
* op The operation code for the ajax request.
|
|
|
|
* @returns {cah.ajax.Builder}
|
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
cah.ajax.Builder = function(op) {
|
|
|
|
/**
|
|
|
|
* The data for this request.
|
|
|
|
*
|
|
|
|
* @type {object}
|
|
|
|
*/
|
|
|
|
this.data = {};
|
|
|
|
|
2012-01-17 00:28:21 +00:00
|
|
|
this.data[cah.$.AjaxRequest.OP] = op;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether this request has been run or not.
|
|
|
|
*
|
|
|
|
* @type {boolean}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this.run_ = false;
|
2012-01-12 22:25:04 +00:00
|
|
|
|
|
|
|
/**
|
2012-02-06 22:00:24 +00:00
|
|
|
* Error callback for this request. This is for communication-level errors. If this is not
|
|
|
|
* specified, the default handler of logging the error to the user will occur.
|
2012-01-12 22:25:04 +00:00
|
|
|
*
|
|
|
|
* @type {?function(jqXHR,textStatus,errorThrown)}
|
|
|
|
*/
|
|
|
|
this.errback = undefined;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Serial counter for ajax requests.
|
|
|
|
*
|
|
|
|
* @type {number}
|
|
|
|
*/
|
|
|
|
cah.ajax.Builder.serial = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set an error callback for the request.
|
|
|
|
*
|
2012-01-21 03:11:39 +00:00
|
|
|
* @param {Function}
|
|
|
|
* opt_errback Optional error callback. (jqXHR,textStatus,errorThrown)
|
2012-01-12 22:25:04 +00:00
|
|
|
* @returns {cah.ajax.Builder}
|
|
|
|
*/
|
2012-01-21 03:11:39 +00:00
|
|
|
cah.ajax.Builder.prototype.withErrback = function(opt_errback) {
|
2012-02-06 22:00:24 +00:00
|
|
|
this.assertNotExecuted_();
|
2012-01-12 22:25:04 +00:00
|
|
|
this.errback = errback;
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Run the ajax request.
|
|
|
|
*/
|
|
|
|
cah.ajax.Builder.prototype.run = function() {
|
2012-02-06 22:00:24 +00:00
|
|
|
this.assertNotExecuted_();
|
2012-01-17 00:28:21 +00:00
|
|
|
this.run_ = true;
|
|
|
|
|
|
|
|
this.data[cah.$.AjaxRequest.SERIAL] = cah.ajax.Builder.serial++;
|
2012-01-13 01:05:09 +00:00
|
|
|
cah.Ajax.instance.requestWithBuilder(this);
|
2012-01-12 22:25:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string}
|
|
|
|
* nickname Nickname field to use in the request.
|
|
|
|
* @returns {cah.ajax.Builder} This object.
|
|
|
|
*/
|
|
|
|
cah.ajax.Builder.prototype.withNickname = function(nickname) {
|
2012-02-06 22:00:24 +00:00
|
|
|
this.assertNotExecuted_();
|
2012-01-17 00:28:21 +00:00
|
|
|
this.data[cah.$.AjaxRequest.NICKNAME] = nickname;
|
2012-01-12 22:25:04 +00:00
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
2017-02-21 05:35:44 +00:00
|
|
|
/**
|
|
|
|
* @param {string}
|
|
|
|
* persistentId Persistent ID to use in the request.
|
|
|
|
* @returns {cah.ajax.Builder} This object.
|
|
|
|
*/
|
|
|
|
cah.ajax.Builder.prototype.withPersistentId = function(persistentId) {
|
|
|
|
this.assertNotExecuted_();
|
|
|
|
this.data[cah.$.AjaxRequest.PERSISTENT_ID] = persistentId;
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
2012-01-12 22:25:04 +00:00
|
|
|
/**
|
|
|
|
* @param {string}
|
|
|
|
* message Message field to use in the request.
|
|
|
|
* @returns {cah.ajax.Builder} This object.
|
|
|
|
*/
|
|
|
|
cah.ajax.Builder.prototype.withMessage = function(message) {
|
2012-02-06 22:00:24 +00:00
|
|
|
this.assertNotExecuted_();
|
2012-01-17 00:28:21 +00:00
|
|
|
this.data[cah.$.AjaxRequest.MESSAGE] = message;
|
2012-01-12 22:25:04 +00:00
|
|
|
return this;
|
|
|
|
};
|
2012-01-17 00:28:21 +00:00
|
|
|
|
2012-01-19 00:42:18 +00:00
|
|
|
/**
|
|
|
|
* @param {number}
|
|
|
|
* gameId Game id field to use in the request.
|
|
|
|
* @returns {cah.ajax.Builder} This object.
|
|
|
|
*/
|
|
|
|
cah.ajax.Builder.prototype.withGameId = function(gameId) {
|
2012-02-06 22:00:24 +00:00
|
|
|
this.assertNotExecuted_();
|
2012-01-19 00:42:18 +00:00
|
|
|
this.data[cah.$.AjaxRequest.GAME_ID] = gameId;
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
2012-01-27 02:07:39 +00:00
|
|
|
/**
|
|
|
|
* @param {number}
|
|
|
|
* cardId Card id field to use in the request.
|
|
|
|
* @returns {cah.ajax.Builder} This object.
|
|
|
|
*/
|
|
|
|
cah.ajax.Builder.prototype.withCardId = function(cardId) {
|
2012-02-06 22:00:24 +00:00
|
|
|
this.assertNotExecuted_();
|
2012-01-27 02:07:39 +00:00
|
|
|
this.data[cah.$.AjaxRequest.CARD_ID] = cardId;
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
2012-03-16 03:06:23 +00:00
|
|
|
/**
|
2014-04-02 11:46:27 +01:00
|
|
|
* @param {Object}
|
|
|
|
* options Game options to use in the request.
|
2012-03-16 03:06:23 +00:00
|
|
|
* @returns {cah.ajax.Builder} This object.
|
|
|
|
*/
|
2014-04-02 11:46:27 +01:00
|
|
|
cah.ajax.Builder.prototype.withGameOptions = function(options) {
|
2012-03-16 03:06:23 +00:00
|
|
|
this.assertNotExecuted_();
|
2014-04-02 11:46:27 +01:00
|
|
|
this.data[cah.$.AjaxRequest.GAME_OPTIONS] = $.toJSON(options);
|
2012-03-16 03:06:23 +00:00
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
2012-03-19 04:20:48 +00:00
|
|
|
/**
|
|
|
|
* @param {string}
|
|
|
|
* password Password field to use in the request.
|
|
|
|
* @returns {cah.ajax.Builder} This object.
|
|
|
|
*/
|
|
|
|
cah.ajax.Builder.prototype.withPassword = function(password) {
|
|
|
|
this.assertNotExecuted_();
|
|
|
|
this.data[cah.$.AjaxRequest.PASSWORD] = password;
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
2013-03-27 03:17:49 +00:00
|
|
|
/**
|
|
|
|
* @param {boolean}
|
|
|
|
* wall Whether or not this is a warn-all ("wall").
|
|
|
|
* @returns {cah.ajax.Builder} This object.
|
|
|
|
*/
|
|
|
|
cah.ajax.Builder.prototype.withWall = function(wall) {
|
|
|
|
this.assertNotExecuted_();
|
|
|
|
this.data[cah.$.AjaxRequest.WALL] = wall;
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
2013-10-02 12:28:16 +01:00
|
|
|
/**
|
|
|
|
* @param {boolean}
|
|
|
|
* emote Whether or not this is an emote
|
|
|
|
* @returns {cah.ajax.Builder} This object.
|
|
|
|
*/
|
|
|
|
cah.ajax.Builder.prototype.withEmote = function(emote) {
|
|
|
|
this.assertNotExecuted_();
|
|
|
|
this.data[cah.$.AjaxRequest.EMOTE] = emote;
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
2014-08-11 06:16:15 +01:00
|
|
|
/**
|
|
|
|
* @param {string}
|
|
|
|
* id The Cardcast ID of the deck to add.
|
|
|
|
* @returns {cah.ajax.Builder} This object.
|
|
|
|
*/
|
|
|
|
cah.ajax.Builder.prototype.withCardcastId = function(id) {
|
|
|
|
this.assertNotExecuted_();
|
|
|
|
this.data[cah.$.AjaxRequest.CARDCAST_ID] = id;
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
Add ID codes for positive user identification, and minor fixups.
Users can specify an identification code when they connect (8-100 characters), only if they are using HTTPS. This code is combined with their nickname and a server-side secret, hashed with SHA-256, and condensed down to 64 bits by XORing every 8th byte with each other, and finally converted to base64 (with the trailing = removed). This code is displayed in a tooltip when hovering over the user's chat (TODO: mobile way to view it).
Sigils have been added to be displayed before the user's name in the chat. Admins get @, users with an ID code get +, and normal users get nothing. The IS_ADMIN field is now deprecated, as this can be determined from the user's sigil. It will be removed eventually, but is still being included in events even though the official client should not be using it anymore.
Kicks and bans are now always displayed to all users, even if the server isn't transmitting quit events normally.
2018-03-03 01:24:58 +00:00
|
|
|
/**
|
|
|
|
* @param {string}
|
|
|
|
* id The user's identification code.
|
|
|
|
* @returns {cah.ajax.Builder} This object.
|
|
|
|
*/
|
|
|
|
cah.ajax.Builder.prototype.withIdCode = function(idCode) {
|
|
|
|
this.assertNotExecuted_();
|
|
|
|
this.data[cah.$.AjaxRequest.ID_CODE] = idCode;
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
2012-02-06 22:00:24 +00:00
|
|
|
/**
|
|
|
|
* Assert that the request from this builder has not already run. Throws an exception if it has.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
cah.ajax.Builder.prototype.assertNotExecuted_ = function() {
|
2012-01-17 00:28:21 +00:00
|
|
|
if (this.run_) {
|
|
|
|
throw "Request already executed.";
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-02-06 22:00:24 +00:00
|
|
|
/**
|
|
|
|
* Assert that the request from this builder has already run. Throws an exception if it has not.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
cah.ajax.Builder.prototype.assertExecuted_ = function() {
|
2012-01-17 00:28:21 +00:00
|
|
|
if (!this.run_) {
|
|
|
|
throw "Request not yet executed.";
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-02-06 22:00:24 +00:00
|
|
|
/**
|
|
|
|
* @returns {string} The operation code of the request this builder built.
|
|
|
|
*/
|
2012-01-17 00:28:21 +00:00
|
|
|
cah.ajax.Builder.prototype.getOp = function() {
|
2012-02-06 22:00:24 +00:00
|
|
|
this.assertExecuted_();
|
2012-01-17 00:28:21 +00:00
|
|
|
return this.data[cah.$.AjaxRequest.OP];
|
|
|
|
};
|
|
|
|
|
2012-02-06 22:00:24 +00:00
|
|
|
/**
|
|
|
|
* @returns {number} The serial id of the request this builder built.
|
|
|
|
*/
|
2012-01-17 00:28:21 +00:00
|
|
|
cah.ajax.Builder.prototype.getSerial = function() {
|
2012-02-06 22:00:24 +00:00
|
|
|
this.assertExecuted_();
|
2012-01-17 00:28:21 +00:00
|
|
|
return this.data[cah.$.AjaxRequest.SERIAL];
|
|
|
|
};
|