Advertisement
SReject

GetMcStatus

Oct 19th, 2015
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
mIRC 4.79 KB | None | 0 0
  1. ;; /GetMcStatus - Messages active channel with the current statuses
  2. ;; $GetMcStatus - returns the current statuses
  3. ;; //echo -a $GetMcStatus - Echos the current statuses
  4.  
  5. alias getMcStatus {
  6.   var %status = $mcStatus
  7.   var %state = $gettok(%status, 1, 32)
  8.   var %val = $gettok(%status, 2-, 32)
  9.   var %msg
  10.   var %n = 1
  11.   var %site
  12.   if (%state != 1 || !%val) {
  13.     return 04[MOJANG STATUS] An error occured while checking mojang server statuses $+ $iif(%val,: %val)
  14.   }
  15.   else {
  16.     %msg = 03[MOJANG STATUS]
  17.     tokenize 124 %val
  18.     while (%n <= $0) {
  19.       %site = $gettok($(,$ $+ %n), 1, 58)
  20.       %status = $gettok($(,$ $+ %n), 2, 58)
  21.       if (%status == 0) {
  22.         %status = 04Down
  23.       }
  24.       elseif (%status == 1) {
  25.         %status = 07Intermitten
  26.       }
  27.       elseif (%status == 2) {
  28.         %status = 03Up
  29.       }
  30.       else {
  31.         %status = %status
  32.       }
  33.       %msg = %msg %site $+ : %status
  34.       if (%n < $0) {
  35.         %msg = %msg -
  36.       }
  37.       inc %n
  38.     }
  39.     $iif($isid, return, msg $active) %msg
  40.   }
  41. }
  42. alias -l mcstatus {
  43.   ; basic variables
  44.   var %error, %status, %resp, %statVar = status={status:0,error:"Services not polled"}, %regex, %n = 1
  45.  
  46.   ; js to add to scripting shell
  47.   var %getStatus = function getStatus(){for(var a=['MSXML2.SERVERXMLHTTP.6.0','MSXML2.SERVERXMLHTTP.3.0','MSXML2.SERVERXMLHTTP','MSXML2.XMLHTTP.6.0','MSXML2.XMLHTTP.3.0','Microsoft.XMLHTTP'],b,c=0;c<a.length;c+=1){try{b=new ActiveXObject(a[c])}catch(e){}}if(b!==undefined){b.open("GET","http://status.mojang.com/check",false);b.setRequestHeader("Cache-Control","no-cache");b.send();status={status:b.status,error:null,resp:b.responseText}}else{status={status:0,error:"XMLHTTPRequest object not found"}}}
  48.  
  49.   ; initialize COM object
  50.   if (!$com(mcStatus)) {
  51.  
  52.     ; Create instance of MSScriptControl.ScriptControl
  53.     .comopen mcStatus MSScriptControl.ScriptControl
  54.     if (!$com(mcStatus) || $comerr) {
  55.       %error = Unable to locate MSScriptControl.ScriptControl
  56.     }
  57.  
  58.     ; Set script language to JScript
  59.     elseif (!$com(mcStatus, language, 4, bstr, jscript) || $comerr) {
  60.       %error = Unable to set script language to JScript for MSScriptControl.ScriptControl
  61.     }
  62.  
  63.     ; Add getStatus() function to the ScriptControl
  64.     elseif (!$com(mcStatus, addcode, 1, bstr, %getStatus) || $comerr) {
  65.       %error = Unable to add getStatus() function to the ScriptControl
  66.     }
  67.  
  68.     ; Create status variable within the ScriptControl instance
  69.     elseif (!$com(mcStatus, ExecuteStatement, 1, bstr, %statVar) || $comerr) {
  70.       %error = Unable to initalize status variable
  71.     }
  72.  
  73.     ; Goto error if one was encountered
  74.     if (%error) {
  75.       goto error
  76.     }
  77.   }
  78.  
  79.   ; Call getStatus()
  80.   if (!$com(mcStatus, ExecuteStatement, 1, bstr, getStatus $+ $chr(40) $+ $chr(41)) || $comerr) {
  81.     %error = Unable to execute getStatus()
  82.   }
  83.   else {
  84.     if (!$com(mcStatus, eval, 1, bstr, status.status) || $comerr) {
  85.       %error = Unable to retrieve status from getStatus()
  86.       goto error
  87.     }
  88.     var %status = $com(mcStatus).result
  89.  
  90.     if (%status == 0) {
  91.       return 0 XMLHTTPRequest object not found
  92.     }
  93.     elseif (%status !== 200) {
  94.       return 0 Server Error %status
  95.     }
  96.     elseif (!$com(mcStatus, eval, 1, bstr, status.resp) || $comerr) {
  97.       %error = Unable to retrieve response from getStatus()
  98.       goto error
  99.     }
  100.  
  101.     noop $regex(mcStatus, $com(mcStatus).result, /"([^"]+)":"([^"]+)"/g)
  102.     while (%n <= $regml(mcStatus, 0)) {
  103.       var %site = $regml(mcStatus, %n)
  104.       if (%site == minecraft.net) {
  105.         %site = Minecraft.net
  106.       }
  107.       elseif (%site == session.minecraft.net) {
  108.         %site = Session Tracker
  109.       }
  110.       elseif (%site == account.mojang.com) {
  111.         %site = Account Tracker
  112.       }
  113.       elseif (%site == auth.mojang.com) {
  114.         %site = Auth Tracker
  115.       }
  116.       elseif (%site == skins.minecraft.net) {
  117.         %site = Skin Server
  118.       }
  119.       elseif (%site == authserver.mojang.com) {
  120.         %site = Auth Server
  121.       }
  122.       elseif (%site == sessionserver.mojang.com) {
  123.         %site = Session Server
  124.       }
  125.       elseif (%site == api.mojang.com) {
  126.         %site = API Server
  127.       }
  128.       elseif (%site == textures.minecraft.net) {
  129.         %site = Texture Server
  130.       }
  131.       inc %n
  132.  
  133.  
  134.       var %value = $regml(mcStatus, %n)
  135.       if (%value == red) {
  136.         %value = 0
  137.       }
  138.       elseif (%value == yellow) {
  139.         %value = 1
  140.       }
  141.       elseif (%value == green) {
  142.         %value = 2
  143.       }
  144.       inc %n
  145.  
  146.       %resp = $addtok(%resp, %site $+ : $+ %value, 124)
  147.     }
  148.     return 1 %resp
  149.   }
  150.  
  151.  
  152.  
  153.   :error
  154.   %error = $iif($error, $error, %error)
  155.   if (%error) {
  156.     reseterror
  157.     if ($com(mcstatus)) { .comclose mcstatus }
  158.     if ($isid) return 0 %error
  159.   }
  160. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement