IPv4 Fremnet Logo
TOOLS, TINKERINGS & CODE

If it helps

Node Usage 3 · Nov 15, 01:41 by Shannon Wynter

DO NOT USE THIS VERSION

Due to an upgrade on the node side of things, this version of Node Usage is discontinued.

Please proceed through the magic door to Node Usage 4!

Now with Auto-Update – Node Usage 4.







Greetings once again folks.

The wonderful people at Internode have upgraded their API’s for us, making them more secure and sane in the process. So I’ve had to make a new Node Usage update.

As a bonus (And mostly because I was bored) I’ve almost completely re-written the script, you can now customize a lot more of it and even brag about your line speed (As seen by node, not you)

Requirements

Installation
You have two options

  • You can go ALT+R and create a new script, copying and pasting the stuff below into it
  • You can grab the script from below, save it to your mIRC dir and type /load -rs nodeusage3.mrc

  1. ;***********************************************************  
  2. ;* NodeUsage Version 3.00 **********************************  
  3. ;***********************************************************  
  4. ;* Writen by Freman aka Fremean                            *  
  5. ;***********************************************************  
  6. ;* NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE *  
  7. ;*                                                         *  
  8. ;* If you wish to create your own usage meter interface,   *  
  9. ;* do not copy the interface from this script, please      *  
  10. ;* contact Internode at support@internode.on.net for the   *  
  11. ;* specifications document                                 *  
  12. ;*                                                         *  
  13. ;* NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE *  
  14. ;***********************************************************  
  15. ;* Pay a vist to http://fremnet.net/contact if you feel    *  
  16. ;* the burning desire to leave comments, compliments, or   *  
  17. ;* complaints                                              *  
  18. ;***********************************************************  
  19. ;* To catch me look for Freman/Fremean on Gamesurge. If    *  
  20. ;* I'am online and around, I'll get back to you            *  
  21. ;* Home Chan(s): #gamesonnet                               *  
  22. ;***********************************************************  
  23. ;* Commands:                                               *  
  24. ;*   /NodeUsage       - The spam command                   *  
  25. ;*   /NodeUsage.Setup - The setup dialog                   *  
  26. ;***********************************************************  
  27.   
  28. ;***********************************************************  
  29. ; Public Aliases  
  30. ;***********************************************************  
  31.   
  32. ; Main alias  
  33. alias NodeUsage {  
  34.   ; Record the target  
  35.   set %NodeUsage.ToChannel $active  
  36.   ; Make sure the environment is sane  
  37.   NodeUsage.Sanity  
  38.   ; Get the usage  
  39.   if ($NodeUsage.GetUsage) {  
  40.   
  41.     ; Store the global variables locally with the same name as the template functions  
  42.     var %gender %NodeUsage.Gender  
  43.   
  44.     var %updated $asctime(%NodeUsage.LastUpdate,h:nn tt zz)  
  45.     var %rollover $asctime(%NodeUsage.Rollover,dd/mm/yyyy)  
  46.     var %rduation $duration($calc(%NodeUsage.Rollover - $ctime))  
  47.     var %time_left $gettok(%rduation, $+(1-,$calc($numtok(%rduation,32)-1)),32)  
  48.   
  49.     var %line_speed %NodeUsage.LineSpeed  
  50.   
  51.     var %usage_used %NodeUsage.Used  
  52.     var %usage_limit %NodeUsage.Limit  
  53.     var %over_limit $calc(%usage_used - %usage_limit)  
  54.     var %limit_left $calc(%usage_limit - %usage_used)  
  55.     ; Don't ask me to explain this, it's 1 am.  
  56.     var %avg_left $round($calc(%limit_left / $round($calc(($ctime(01:01 %rollover) - $ctime)/24/60/60),0)),2)  
  57.   
  58.     var %perc_used $round($calc((%usage_used / %usage_limit)*100),2)  
  59.     var %perc_left $round($calc((%limit_left / %usage_limit)*100),2)  
  60.   
  61.     var %ex_rate %NodeUsage.ExcessRate  
  62.     var %ex_cost $calc(%ex_rate * %over_limit)  
  63.   
  64.     ; Select an output format  
  65.     var %format $iif(%usage_used > %usage_limit, %NodeUsage.OverFormat, %NodeUsage.UnderFormat)  
  66.   
  67.     ; Replace all the template variables  
  68.     var %output $replace(%format,*gender*,%gender,*updated*,%updated,*rollover*,%rollover,*time_left*,%time_left)  
  69.     %output = $replace(%output,*usage_used*,%usage_used,*usage_limit*,%usage_limit,*over_limit*,%over_limit)  
  70.     %output = $replace(%output,*limit_left*,%limit_left,*avg_left*,%avg_left,*line_speed*,%line_speed)  
  71.     %output = $replace(%output,*perc_left*,%perc_left,*perc_used*,%perc_used,*ex_rate*,%ex_rate,*ex_cost*,%ex_cost)  
  72.   
  73.     ; Select an output method  
  74.     var %method $iif(%usage_used > %usage_limit, %NodeUsage.OverMethod, %NodeUsage.UnderMethod)  
  75.   
  76.     ; Output  
  77.     if (%method == 1) {  
  78.       describe %NodeUsage.ToChannel %output  
  79.     }  
  80.     else {  
  81.       msg %NodeUsage.ToChannel %output  
  82.     }  
  83.   }  
  84. }  
  85.   
  86. ; Display the setup dialog  
  87. alias NodeUsage.Setup {  
  88.   dialog -m NodeUsage.Setup NodeUsage  
  89.   set %NodeUsage.Setup $true  
  90. }  
  91.   
  92. ;***********************************************************  
  93. ; Menus  
  94. ;***********************************************************  
  95. menu MenuBar {  
  96.   NodeUsage 3  
  97.   .NodeUsage:/nodeusage  
  98.   .NodeUsage Setup:/nodeusage.setup  
  99.   .Unload:/unload -rs $script  
  100. }  
  101.   
  102. menu Channel,Query,Chat {  
  103.   NodeUsage 3  
  104.   .NodeUsage:/nodeusage  
  105.   .Advertise:/say I found NodeUsage 3 at http://fremnet.net/article/261/node-usage-3  
  106. }  
  107.   
  108. menu NickList {  
  109.   NodeUsage 3  
  110.   .Tell use where to find:/msg $$1 I found NodeUsage 3 at http://fremnet.net/article/261/node-usage-3  
  111. }  
  112.   
  113. ;***********************************************************  
  114. ; Private Aliases  
  115. ;***********************************************************  
  116.   
  117. ; The initialization command  
  118. alias -l NodeUsage.Init {  
  119.   NodeUsage.SSLnVersion  
  120.   echo 3 -as .................................  
  121.   echo 3 -as . Node Usage V3.00 ..............  
  122.   echo 3 -as ..................... by Freman .  
  123.   echo 3 -as .................................  
  124.   echo 3 -as .. Spam the current channel .....  
  125.   echo 3 -as .............. with your usage ..  
  126.   echo 3 -as .................................  
  127.   echo 3 -as ..... Setting default vars. .....  
  128.   echo 3 -as .................................  
  129.   
  130.   set %NodeUsage.Username  
  131.   set %NodeUsage.Password  
  132.   set %NodeUsage.Gender his  
  133.   set %NodeUsage.GetSpeed 1  
  134.   set %NodeUsage.UnderMethod 1  
  135.   set %NodeUsage.OverMethod 1  
  136.   set %NodeUsage.OverFormat is over *gender* *usage_limit* meg node usage limit by *over_limit* megs, *time_left* till reset. [Last Updated: *updated*]  
  137.   set %NodeUsage.UnderFormat has *time_left* to use the remaining *limit_left* of *gender* *usage_limit* meg Internode usage limit. Average daily to end of month: *avg_left* mb [Last Updated: *updated*]  
  138.   NodeUsage.Setup  
  139. }  
  140.   
  141. ; Check out the environment, make sure it's sane - Wish I could find a simple way to progmatically adjust the SSL settings  
  142. alias -l NodeUsage.Sanity {  
  143.   if (%NodeUsage.Setup != $true) {  
  144.     NodeUsage.RaiseError I have not been setup, please /reload the script - When prompted to run the initialization commands, choose yes  
  145.   }  
  146.   if (%NodeUsage.Username == $null) {  
  147.     NodeUsage.RaiseError No username set, please run /NodeUsage.Setup  
  148.   }  
  149.   if (%NodeUsage.Password == $null) {  
  150.     NodeUsage.RaiseError No username set, please run /NodeUsage.Setup  
  151.   }  
  152. }  
  153.   
  154. ; Fires off a couple of sockets  
  155. alias -l NodeUsage.GetUsage {  
  156.   NodeUsage.SSLnVersion  
  157.   if ($calc($ctime - %NodeUsage.LastUpdate) > 3600) {  
  158.     ; Only query for speed if we're expecting speed  
  159.     if (%NodeUsage.GetSpeed == 1) {  
  160.       sockopen -e NodeUsage.Speed customer-webtools-api.internode.on.net 443  
  161.     }  
  162.     sockopen -e NodeUsage.Usage customer-webtools-api.internode.on.net 443  
  163.     return $false  
  164.   }  
  165.   return $true  
  166. }  
  167.   
  168. ; Make noise and fuss  
  169. alias -l NodeUsage.RaiseError {  
  170.   if ($sock(NodeUsage).status == active) {  
  171.     sockclose NodeUsage  
  172.   }  
  173.   if (!$line($active,0)) { linesep -a }  
  174.   echo $color(info) -a * [NodeUsage] $1-  
  175.   linesep -a  
  176.   halt  
  177. }  
  178.   
  179. ; More sanity checks :)  
  180. alias -l NodeUsage.SSLnVersion {  
  181.   ; Check version  
  182.   if ($version < 6.17) {  
  183.     NodeUsage.RaiseError I am sorry, I need mIRC 6.17 or better  
  184.   }  
  185.   ; Check for SSL support  
  186.   if ($sslready != $true) {  
  187.     NodeUsage.RaiseError I need a SSL enabled mIRC see http://www.mirc.co.uk/ssl.html  
  188.   }  
  189. }  
  190.   
  191.   
  192. ;****************************************************  
  193. ; Events  
  194. ;****************************************************  
  195. ; Executed as the script is loaded  
  196. on *:LOAD: {  
  197.   NodeUsage.Init  
  198. }  
  199.   
  200. ; Executed as the script is unloaded  
  201. on *:UNLOAD: {  
  202.   unset %NodeUsage.*  
  203. }  
  204.   
  205. on *:SOCKOPEN:NodeUsage.*: {  
  206.   if ($sockerr) { NodeUsage.RaiseError Socket Error ( $+ $sockerr $+ ) }  
  207.   sockwrite -tn $sockname POST /cgi-bin/padsl-usage HTTP/1.0  
  208.   sockwrite -tn $sockname Host: customer-webtools-api.internode.on.net  
  209.   sockwrite -tn $sockname User-Agent: NodeUsage/3.00 (http://fremnet.net)  
  210.   sockwrite -tn $sockname Connection: close  
  211.   var %Content username= $+ %NodeUsage.Username $+ @internode.on.net&password= $+ %NodeUsage.Password  
  212.   %Content = %Content $+ $iif(.Speed isin $sockname, &speed=1)  
  213.   sockwrite -tn $sockname Content-length: $len(%Content)  
  214.   sockwrite -tn $sockname  
  215.   sockwrite -tn $sockname %Content  
  216.   sockwrite -tn $sockname  
  217. }  
  218.   
  219. on *:SOCKREAD:NodeUsage.*: {  
  220.   if ($sockerr) { NodeUsage.RaiseError Socket Error ( $+ $sockerr $+ ) }  
  221.   var %data  
  222.   :nextread  
  223.   sockread %data  
  224.   if ($sockbr == 0) return  
  225.   if (%data == $null) %data = -  
  226.   
  227.   if (%data == Authentication failed) {  
  228.     NodeUsage.RaiseError Authentication Failure - Check your username/password. Type /NodeUsage.Setup  
  229.     halt;  
  230.   }  
  231.   
  232.   if ((.Speed isin $sockname) && $regex(%data, /^\d+(\.\d+)? [MK]?bits/)) {  
  233.     set %NodeUsage.LineSpeed %data  
  234.     sockclose $sockname  
  235.   }  
  236.   
  237.   if ((.Usage isin $sockname) && $regex(%data, /^\d+(\.\d+)? \d+/)) {  
  238.     tokenize 32 %data  
  239.     set %NodeUsage.LastUpdate $ctime  
  240.     set %NodeUsage.Used $round($1,2)  
  241.     set %NodeUsage.Limit $2  
  242.     set %NodeUsage.Rollover $ctime($3 01:01)  
  243.     set %NodeUsage.ExcessRate $4  
  244.     sockclose $sockname  
  245.   }  
  246.   
  247.   if ($sock(NodeUsage.*,0) == 0) {  
  248.     NodeUsage  
  249.     halt  
  250.   }  
  251.   
  252.   if ($sock($sockname).open) {  
  253.     goto nextread  
  254.   }  
  255.   
  256. }  
  257.   
  258. on *:DIALOG:NodeUsage.Setup:init:0: {  
  259.   did -c $dname $iif(%NodeUsage.Gender == his, 11, 12)  
  260.   did -c $dname $iif(%NodeUsage.UnderMethod == 1, 14, 15)  
  261.   did -c $dname $iif(%NodeUsage.OverMethod == 1, 28, 29)  
  262.   if (%NodeUsage.GetSpeed == 1) {  
  263.     did -c $dname 13  
  264.   }  
  265. }  
  266.   
  267. on *:DIALOG:NodeUsage.Setup:sclick:17: {  
  268.   set %NodeUsage.Gender $iif($did($dname,11).state == 1, his, her)  
  269.   set %NodeUsage.GetSpeed $did($dname,13).state  
  270.   set %NodeUsage.UnderMethod $did($dname,14).state  
  271.   set %NodeUsage.OverMethod $did($dname,28).state  
  272. }  
  273.   
  274.   
  275. dialog -l NodeUsage {  
  276.   title "NodeUsage Version 3.00"  
  277.   size -1 -1 269 183  
  278.   option dbu  
  279.   box "Output", 6, 4 42 262 123  
  280.   box "Format Variables", 19, 5 118 259 43  
  281.   box "Under Limit", 23, 5 49 259 34  
  282.   box "Authentication", 1, 4 4 130 35  
  283.   box "Information", 2, 136 4 130 35  
  284.   text "Username:", 3, 9 14 30 8  
  285.   text "Password:", 4, 9 26 30 8  
  286.   text "Format:", 7, 9 71 30 9  
  287.   text "Method:", 8, 9 59 30 8  
  288.   edit %NodeUsage.Username, 9, 44 12 80 10, %NodeUsage.Username  
  289.   edit %NodeUsage.Password, 10, 44 24 80 10, pass %NodeUsage.Password  
  290.   check "Get the line speed", 13, 168 27 61 8  
  291.   radio "Action (/me)", 14, 44 59 50 8, group  
  292.   radio "Say", 15, 99 59 50 8  
  293.   edit %NodeUsage.UnderFormat, 16, 44 70 215 10, autohs %NodeUsage.UnderFormat  
  294.   button "Ok", 17, 233 167 32 12, ok  
  295.   button "Cancel", 18, 4 167 32 12, cancel  
  296.   text "*gender*", 20, 164 138 40 8  
  297.   text "Gender:", 5, 141 14 30 8  
  298.   radio "Male", 11, 175 13 30 8, group  
  299.   radio "Female", 12, 220 13 30 8  
  300.   text "*usage_used*", 21, 11 128 40 8  
  301.   text "*usage_limit*", 22, 11 138 40 8  
  302.   box "Over Limit", 24, 5 84 259 34  
  303.   text "Method:", 25, 9 94 30 8  
  304.   text "Format:", 26, 9 106 30 9  
  305.   edit %NodeUsage.OverFormat, 27, 44 105 215 10, autohs %NodeUsage.OverFormat  
  306.   radio "Action (/me)", 28, 44 94 50 8, group  
  307.   radio "Say", 29, 99 94 50 8  
  308.   text "*limit_left*", 30, 62 128 40 8  
  309.   text "*updated*", 31, 113 128 40 8  
  310.   text "*rollover*", 32, 113 138 40 8  
  311.   text "*line_speed*", 33, 164 128 40 8  
  312.   text "*ex_rate*", 34, 215 128 40 8  
  313.   text "*over_limit*", 35, 62 138 40 8  
  314.   text "*time_left*", 36, 164 148 40 8  
  315.   text "*perc_used*", 37, 11 148 40 8  
  316.   text "*perc_left*", 38, 61 148 40 8  
  317.   text "*avg_left*", 39, 113 148 40 8  
  318.   text "*ex_cost*", 40, 215 138 40 8  
  319. }  
  320.  
  321. Download this code: NodeUsage3.mrc (Downloaded 170 time(s))

Comments

Commenting is closed for this article.

---== Copyright Shannon Wynter - All rights reserved - All wrongs avenged ==---
address-book