Advertisement
Guest User

sqdqsdqsd

a guest
Apr 17th, 2019
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. var firstHost = null;
  3. var xorKey = new Array();
  4. var base64Charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  5. var base64Reverse = new Array();
  6. for(var i = base64Charset.length - 1;i >= 0;i--){
  7.     base64Reverse[base64Charset.charAt(i)] = i;
  8. }
  9. String.prototype.replace = function(searchStr, replaceStr):String {
  10.     var arr:Array = this.split(searchStr);
  11.     return arr.join(replaceStr);
  12. };
  13.  
  14. function encodeBase64(s:Array){
  15.     var r = "";
  16.     var p = "";
  17.     var c = s.length % 3;
  18.     if(c > 0){
  19.         for(;c < 3;c++){
  20.             p += "=";
  21.             s.push(0);
  22.         }
  23.     }
  24.    
  25.     for(c = 0;c < s.length; c+=3){
  26.         var n = (s[c] << 16) + (s[c + 1] << 8) + (s[c + 2]);
  27.        
  28.         r += base64Charset.charAt((n >> 18) & 63) +
  29.                 base64Charset.charAt((n >> 12) & 63) +
  30.                 base64Charset.charAt((n >> 6) & 63) +
  31.                 base64Charset.charAt(n & 63);
  32.     }
  33.    
  34.     return r.substr(0, r.length - p.length) + p;
  35. };
  36.  
  37. function decodeBase64(encoded:String){
  38.     for(var i = 0;i < encodedLength;i++){
  39.         if(base64Charset.indexOf(encodedLength.charAt(i)) == -1){
  40.             encodedLength.replace(encodedLength.charAt(i--), "");
  41.         }
  42.     }
  43.    
  44.     var p = (encoded.charAt(encoded.length - 1) == "=" ?
  45.              (encoded.charAt(encoded.length - 2) == "=" ? "AA" : "A") : "");
  46.     var r = new Array();
  47.     encoded = encoded.substr(0, encoded.length - p.length) + p;
  48.     for(var c = 0;c < encoded.length;c+=4){
  49.         var n = (base64Reverse[encoded.charAt(c)] << 18)
  50.                 + (base64Reverse[encoded.charAt(c+1)] << 12)
  51.                 + (base64Reverse[encoded.charAt(c+2)] << 6)
  52.                 + base64Reverse[encoded.charAt(c+3)];
  53.  
  54.         r.push((n >>> 16) & 255);
  55.         r.push((n >>> 8) & 255);
  56.         r.push(n & 255);
  57.     }
  58.     return r.slice(0, r.length - p.length);
  59. };
  60.  
  61. dofus_aks_Aks.connect = function (sHost, nPort, bSaveHost)
  62. {
  63.     if(firstHost == null || firstHost == sHost){
  64.         xorKey = null;
  65.         firstHost = sHost;
  66.     }
  67.    
  68.     if (bSaveHost == undefined)
  69.     {
  70.         bSaveHost = true;
  71.     } // end if
  72.     if (this._bConnected)
  73.     {
  74.         return (null);
  75.     } // end if
  76.     if (this._bConnecting)
  77.     {
  78.         return (null);
  79.     } // end if
  80.     this.api.ui.loadUIComponent("Waiting", "Waiting", undefined, {bStayIfPresent: true});
  81.     if (sHost == undefined)
  82.     {
  83.         sHost = this.api.datacenter.Basics.serverHost;
  84.     }
  85.     else if (bSaveHost)
  86.     {
  87.         this.api.datacenter.Basics.serverHost = sHost;
  88.     } // end else if
  89.     if (nPort == undefined)
  90.     {
  91.         nPort = this.api.datacenter.Basics.serverPort;
  92.     }
  93.     else if (bSaveHost)
  94.     {
  95.         this.api.datacenter.Basics.serverPort = nPort;
  96.     } // end else if
  97.     this._bConnecting = true;
  98.     this._aLastPings = new Array();
  99.     var connect = this._xSocket.connect(sHost, nPort);
  100.     return (connect);
  101. };
  102. dofus_aks_Aks.onData = function(sData){
  103.     ank.utils.Timer.removeTime(this.Lag,"lag");
  104.     if(this._bLag){
  105.         dofus.utils.Api.getInstance().ui.unloadUIComponent("WaitingMessage");
  106.         ank.utils.Timer.removeTimer(this.Deco, "deco");
  107.         this._bLag = false;
  108.     }
  109.    
  110.     if(this._isWaitingForData){
  111.         this._isWaitingForData = false;
  112.         this.api.ui.unloadUIComponent("Waiting");
  113.         var timer = getTimer() - this._nLastWaitingSend;
  114.         this._aLastPings.push(timer);
  115.         if(this._aLastPings.length > dofus.aks.Aks.EVALUATE_AVERAGE_PING_ON_COMMANDS){
  116.             this._aLastPings.shift();
  117.         }
  118.     }
  119.    
  120.     if(xorKey != null && xorKey.length > 0){
  121.         sData = decodeBase64(sData);
  122.         var finalData:String = "";
  123.         for(var i = 0;i < sData.length;i++){
  124.             finalData += String.fromCharCode(sData[i] ^ (xorKey[xorKey.length - (i % xorKey.length) - 1]));
  125.         }
  126.         sData = finalData;
  127.     }
  128.     else{
  129.         var newXorKey = new Array();
  130.         var xorKeySize = sData.charCodeAt(sData.length - 1);
  131.         for(var i = 0;i < xorKeySize;i++){
  132.             newXorKey.unshift(sData.charCodeAt(sData.length - i - 2));
  133.         }
  134.        
  135.         xorKey = newXorKey;
  136.     }
  137.     if (_global.PRECV)
  138.     {
  139.         this.api.kernel.showMessage(undefined, "Packet reçus : " + "<b>" + sData + "</b>", "DEBUG_CLIENT");
  140.     } // end if
  141.     this._oDataProcessor.process(sData);
  142. };
  143.  
  144. dofus_aks_Aks.send = function (sData, bWaiting, sWaitingMessage, bNoLimit, bNoCyphering)
  145. {
  146.     this.api.kernel.GameManager.signalActivity();
  147.     if (bWaiting || bWaiting == undefined)
  148.     {
  149.         if (sWaitingMessage != undefined)
  150.         {
  151.             this.api.ui.loadUIComponent("WaitingMessage", "WaitingMessage", {text: sWaitingMessage}, {bAlwaysOnTop: true, bForceLoad: true});
  152.         } // end if
  153.         this._sDebug = sData;
  154.         this.api.ui.loadUIComponent("Waiting", "Waiting");
  155.         this._isWaitingForData = true;
  156.         if (this.api.datacenter.Basics.inGame && this._bAutoReco)
  157.         {
  158.             ank.utils.Timer.setTimer(this.Lag, "lag", this, this.onLag, Number(this.api.lang.getConfigText("DELAY_RECO_MESSAGE")));
  159.         } // end if
  160.        
  161.     } // end if
  162.    
  163.     while(sData.charAt(sData.length -1) == '\n' || sData.charAt(sData.length - 1) == '\r'){
  164.         sData = sData.substr(0, sData.length - 1);
  165.     }
  166.  
  167.     if (_global.PSEND)
  168.     {
  169.         this.api.kernel.showMessage(undefined, "Envoie du packet : " + "<b>" + sData + "</b>", "DEBUG_PAKET");
  170.     } // end if
  171.  
  172.     var finalData:Array = new Array();
  173.     for(var i = 0;i < sData.length;i++){
  174.         finalData.push(sData.charCodeAt(i) ^ (xorKey[i % xorKey.length]));
  175.     }
  176.     finalData = encodeBase64(finalData);
  177.     this._xSocket.send(finalData);
  178.     if (bWaiting || bWaiting == undefined)
  179.     {
  180.         this._nLastWaitingSend = getTimer();
  181.     } // end if
  182. };*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement