Advertisement
Guest User

ss

a guest
Feb 19th, 2020
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.56 KB | None | 0 0
  1. // ===== Legend Mod auxiliary processing =====
  2. // Returns the argument if it is valid as the URL of the custom skin, otherwise returns the empty string
  3. prot.checkSkinURL = function(skinURL) {
  4. return /^https?:\/\/i\.(?:imgur|hizliresim)\.com\/\w{6,8}\.(?:jpg|jpeg|png)\??\d*$/i.test(skinURL) ? skinURL : '';
  5. };
  6.  
  7. // Cache custom skins
  8. prot.cacheCustomSkin = function(nick, playerColor, skinURL){
  9. if(! skinURL){
  10. return;
  11. }
  12. var skinID = ":party" === this.gameMode ? nick + playerColor : nick;
  13. this.customSkinsMap[skinID] = skinURL;
  14. if(! this.customSkinsCache.hasOwnProperty(skinURL)){
  15. this.loadSkin(this.customSkinsCache, skinURL);
  16. }
  17. };
  18. prot.getCustomSkin = function(nick, playerColor) {
  19. var skinID = ":party" === this.gameMode ? nick + playerColor : nick;
  20. return this.customSkinsMap.hasOwnProperty(skinID)
  21. ? this.getCachedSkin(this.customSkinsCache, this.customSkinsMap[skinID]) : null;
  22. };
  23. prot.loadSkin = function(skinsCache, skinURL) {
  24. var ogar = this;
  25. skinsCache[skinURL] = new Image();
  26. skinsCache[skinURL].crossOrigin = "Anonymous";
  27. skinsCache[skinURL].onload = function(){
  28. if(this.complete && this.width && this.height && this.width <= 0x7d0 && this.height <= 0x7d0){
  29. ogar.cacheQueue.push(skinURL);
  30. if(0x1 == ogar.cacheQueue.length){
  31. ogar.cacheSkin(ogar.customSkinsCache);
  32. }
  33. }
  34. };
  35. skinsCache[skinURL].src = skinURL;
  36. };
  37. prot.cacheSkin = function(skinsCache){
  38. if(0x0 === this.cacheQueue.length){
  39. return;
  40. }
  41. var skinURL = this.cacheQueue.shift();
  42. if(! skinURL){
  43. return;
  44. }
  45. var canvas = document.createElement("canvas");
  46. canvas.width = 0x200;
  47. canvas.height = 0x200;
  48. var skinCxt = canvas.getContext('2d');
  49. skinCxt.beginPath();
  50. skinCxt.arc(0x100, 0x100, 0x100, 0x0, 0x2 * Math.PI, !0x1);
  51. skinCxt.clip();
  52. skinCxt.drawImage(this.customSkinsCache[skinURL], 0x0, 0x0, 0x200, 0x200);
  53. this.customSkinsCache[skinURL + "_cached"] = new Image();
  54. this.customSkinsCache[skinURL + "_cached"].src = canvas.toDataURL();
  55. canvas = null;
  56. this.cacheSkin(this.customSkinsCache);
  57. };
  58. prot.getCachedSkin = function(skinsCache, skinURL) {
  59. var skinImg = skinsCache[skinURL + "_cached"];
  60. return skinImg && skinImg.complete && skinImg.width ? skinImg : null;
  61. };
  62.  
  63. // ===== General-purpose communication processing =====
  64. prot.flushData = function(){
  65. };
  66. prot.strToBuff = function (code, value){
  67. var sndBuf = prot.createView(1 + 2 * value.length);
  68. sndBuf.setUint8(0, code);
  69. for (var idx = 0; idx < value.length; idx ++){
  70. sndBuf.setUint16(1 + 2 * idx, value.charCodeAt(idx), !0x0);
  71. }// I do not want to output the terminating NULL character
  72. return sndBuf;
  73. };
  74. prot.sendBuffer = function(buf){
  75. if(! this.isConnected()){
  76. my.log("soket is not open");
  77. return false;
  78. }
  79. this.socket.send(buf.buffer);
  80. };
  81. prot.createView = function(bufsize){
  82. return new DataView(new ArrayBuffer(bufsize));
  83. };
  84. prot.isConnected = function(){
  85. return this.socket && this.socket.readyState == WebSocket.OPEN;
  86. };
  87. // ===== Other general-purpose processing =====
  88. function loadScript(url, callback){
  89. var script = document.createElement("script");
  90. script.type = "text/javascript";
  91. script.src = url;
  92. if(typeof callback !== 'undefined'){
  93. script.onload = callback;
  94. }
  95. document.head.appendChild(script);
  96. }
  97. function escapeHtml(e) {
  98. return e.replace(/&/g, "&amp;")
  99. .replace(/</g, "&lt;")
  100. .replace(/>/g, "&gt;")
  101. .replace(/"/g, "&quot;")
  102. .replace(/'/g, "&#039;");
  103. }
  104. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement