Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ===== Legend Mod auxiliary processing =====
- // Returns the argument if it is valid as the URL of the custom skin, otherwise returns the empty string
- prot.checkSkinURL = function(skinURL) {
- return /^https?:\/\/i\.(?:imgur|hizliresim)\.com\/\w{6,8}\.(?:jpg|jpeg|png)\??\d*$/i.test(skinURL) ? skinURL : '';
- };
- // Cache custom skins
- prot.cacheCustomSkin = function(nick, playerColor, skinURL){
- if(! skinURL){
- return;
- }
- var skinID = ":party" === this.gameMode ? nick + playerColor : nick;
- this.customSkinsMap[skinID] = skinURL;
- if(! this.customSkinsCache.hasOwnProperty(skinURL)){
- this.loadSkin(this.customSkinsCache, skinURL);
- }
- };
- prot.getCustomSkin = function(nick, playerColor) {
- var skinID = ":party" === this.gameMode ? nick + playerColor : nick;
- return this.customSkinsMap.hasOwnProperty(skinID)
- ? this.getCachedSkin(this.customSkinsCache, this.customSkinsMap[skinID]) : null;
- };
- prot.loadSkin = function(skinsCache, skinURL) {
- var ogar = this;
- skinsCache[skinURL] = new Image();
- skinsCache[skinURL].crossOrigin = "Anonymous";
- skinsCache[skinURL].onload = function(){
- if(this.complete && this.width && this.height && this.width <= 0x7d0 && this.height <= 0x7d0){
- ogar.cacheQueue.push(skinURL);
- if(0x1 == ogar.cacheQueue.length){
- ogar.cacheSkin(ogar.customSkinsCache);
- }
- }
- };
- skinsCache[skinURL].src = skinURL;
- };
- prot.cacheSkin = function(skinsCache){
- if(0x0 === this.cacheQueue.length){
- return;
- }
- var skinURL = this.cacheQueue.shift();
- if(! skinURL){
- return;
- }
- var canvas = document.createElement("canvas");
- canvas.width = 0x200;
- canvas.height = 0x200;
- var skinCxt = canvas.getContext('2d');
- skinCxt.beginPath();
- skinCxt.arc(0x100, 0x100, 0x100, 0x0, 0x2 * Math.PI, !0x1);
- skinCxt.clip();
- skinCxt.drawImage(this.customSkinsCache[skinURL], 0x0, 0x0, 0x200, 0x200);
- this.customSkinsCache[skinURL + "_cached"] = new Image();
- this.customSkinsCache[skinURL + "_cached"].src = canvas.toDataURL();
- canvas = null;
- this.cacheSkin(this.customSkinsCache);
- };
- prot.getCachedSkin = function(skinsCache, skinURL) {
- var skinImg = skinsCache[skinURL + "_cached"];
- return skinImg && skinImg.complete && skinImg.width ? skinImg : null;
- };
- // ===== General-purpose communication processing =====
- prot.flushData = function(){
- };
- prot.strToBuff = function (code, value){
- var sndBuf = prot.createView(1 + 2 * value.length);
- sndBuf.setUint8(0, code);
- for (var idx = 0; idx < value.length; idx ++){
- sndBuf.setUint16(1 + 2 * idx, value.charCodeAt(idx), !0x0);
- }// I do not want to output the terminating NULL character
- return sndBuf;
- };
- prot.sendBuffer = function(buf){
- if(! this.isConnected()){
- my.log("soket is not open");
- return false;
- }
- this.socket.send(buf.buffer);
- };
- prot.createView = function(bufsize){
- return new DataView(new ArrayBuffer(bufsize));
- };
- prot.isConnected = function(){
- return this.socket && this.socket.readyState == WebSocket.OPEN;
- };
- // ===== Other general-purpose processing =====
- function loadScript(url, callback){
- var script = document.createElement("script");
- script.type = "text/javascript";
- script.src = url;
- if(typeof callback !== 'undefined'){
- script.onload = callback;
- }
- document.head.appendChild(script);
- }
- function escapeHtml(e) {
- return e.replace(/&/g, "&")
- .replace(/</g, "<")
- .replace(/>/g, ">")
- .replace(/"/g, """)
- .replace(/'/g, "'");
- }
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement