mIRC Home    About    Download    Register    News    Help

Topic Options
#209075 - 03/02/09 10:22 PM hash tables
MTec007 Offline
Fjord artisan

Registered: 05/02/07
Posts: 234
Loc: Tennesee
im trying to write a script but it is limited by windows. Can this script be converted to use hash tables so it will work properly, no matter how much information is there, ie many #channels and tons of nicks.


Code:
alias -l list_chan {
  set %fii %fii <b> $+ $network ( $+ $me $+ )</b><br>
  var %a = 1, %b = $chan(0)
  set %fii %fii <table>
  while %a <= %b {
    var %c = 1, %d = $nick($chan(%a),0)
    while %c <= %d {
      set %fiinick %fiinick <option> $+ $nick($chan(%a),%c).pnick $+ </option>
      inc %c
    }
    ;<option>&#160;</option>
    set %fii %fii <tr><td><select size="8"> $+ %fiinick $+ </select></td><td><b> $+ $chan(%a) $+ </b> $&
<br>---Topic: $&
$chan(%a).topic $+ <br>---Mode: $chan(%a).mode $+ <br>---Key: $&
 $chan(%a).key $+ <br>---Limit: $chan(%a).limit $+ <br>---Users: $&
 $nick($chan(%a),0,a) <b>(@: $nick($chan(%a),0,o) $+ ;%: $&
$nick($chan(%a),0,h) $+ ;+: $nick($chan(%a),0,v) $+ )</b></td></tr><tr><td>&#160;</td><td>&#160;</td></tr>
    inc %a
    unset %fiinick
  }
  set %fii %fii </table>
  return %fii
}


Edited by MTec007 (03/02/09 11:16 PM)
_________________________
mIRC.net E-Motz.com

Top
#209079 - 03/02/09 10:57 PM Re: hash tables [Re: MTec007]
argv0 Offline
Planetary brain

Registered: 13/10/03
Posts: 3918
Loc: Montreal, QC, Canada
Limited by windows? Where exactly is the windows limitation here? Are you referring to mIRC windows or Windows as an operating system?

Either way, the only limitation I see here is that you're trying to fill html into a variable that can only hold up to 4096 characters (and ~800 chars prior to 6.35). This is not a "windows" limitation, it's a limitation in mIRC's script interpreter... Hash tables will not solve this problem-- you probably want to write this stuff to a file.

* On a sidenote, please cut up long lines in your code snippets because it makes this page impossible to read.
_________________________
- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"

Top
#209082 - 03/02/09 11:06 PM Re: hash tables [Re: argv0]
Wims Offline
Planetary brain

Registered: 31/07/06
Posts: 3509
Loc: France
It's certainly a typo, but the limitation of ~4096 characters appears in mIRC 6.32, not 6.35
_________________________
Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net

Top
#209085 - 03/02/09 11:17 PM Re: hash tables [Re: Wims]
MTec007 Offline
Fjord artisan

Registered: 05/02/07
Posts: 234
Loc: Tennesee
regardless, it IS a limitation. why won't a hash table work? i thought that they could hold large amounts of data.
_________________________
mIRC.net E-Motz.com

Top
#209089 - 03/02/09 11:47 PM Re: hash tables [Re: MTec007]
RusselB Offline
Planetary brain

Registered: 03/08/04
Posts: 7252
Loc: Ontario, Canada
Hash tables can hold large amounts of data, but like normal (non-binary) variables, each item in the hash table has roughly the same limitation for the number of characters.

For what the OP appears to be trying to do, I would recommend using a binary variable, as each variable can contain a lot more information.

Top
#209091 - 03/02/09 11:52 PM Re: hash tables [Re: RusselB]
argv0 Offline
Planetary brain

Registered: 13/10/03
Posts: 3918
Loc: Montreal, QC, Canada
I'd suggest /fopen for writing html before binvars-- firstly because it would be simpler to manipulate than a binvar but moreso because whatever ends up using it won't have to reparse the data 4096 bytes at a time through a binvar loop. Also it would ease the debugging process of being able to view an html file..

It would be interesting to know what in mIRC would be processing this? If it's not meant for mIRC to use, I'd say files for sure-- if it's being passed to some HTML dialog viewer DLL then maybe it's a different story (though any HTML viewer I know can just load up a file from a filesystem real easy).
_________________________
- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"

Top
#209093 - 04/02/09 12:43 AM Re: hash tables [Re: argv0]
MTec007 Offline
Fjord artisan

Registered: 05/02/07
Posts: 234
Loc: Tennesee
im making a html web server that implements dynamic content like connections, channels etc, as one of the features. the problem with saving the information to a file is i have to load it right back into a var and send it through a socket.
_________________________
mIRC.net E-Motz.com

Top
#209094 - 04/02/09 01:10 AM Re: hash tables [Re: MTec007]
argv0 Offline
Planetary brain

Registered: 13/10/03
Posts: 3918
Loc: Montreal, QC, Canada
your server doesn't support serving static content from the filesystem? doesn't sound like much of a server to me.

in any case, if you used /fopen you would rewind the file handle (/fseek fh 0) and re-read (fread into a bvar) the contents which would be nearly efficient as direct memory access.

..or you could just write to a bvar directly..

point is, hash tables will serve little use here, this is not their purpose.
_________________________
- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"

Top
#209096 - 04/02/09 01:23 AM Re: hash tables [Re: argv0]
MTec007 Offline
Fjord artisan

Registered: 05/02/07
Posts: 234
Loc: Tennesee
the server does support files but in this case, the server is parsing though the file whilst sending it, and replacing a string, %_SERVERS_CHANNELS_% with what i am trying to do here. the whole procedure string from a sockread.

this is almost what happens, its very hard to process in my head to write it here:
Code:
sockread -> alias to parse the file, make the replacement -> send file to browser
             |
             v
             an alias to return the below information
             |
             v
             a alias to call another alias on all connections
             |
             v
             this problem alias, returns the information I want
_________________________
mIRC.net E-Motz.com

Top
#209098 - 04/02/09 01:50 AM Re: hash tables [Re: MTec007]
hixxy Offline
Hoopy frood

Registered: 06/09/05
Posts: 2876
I'm not entirely sure how useful this is going to be for you, but I've converted your script to use binary variables.

Code:
alias -l list_chan {
  bset -t &fii 1 <b> $+ $network ( $+ $me $+ )</b><br> <table>
  var %a = 1, %b = $chan(0)
  while %a <= %b {
    var %c = 1, %d = $nick($chan(%a),0)
    while %c <= %d {
      bset -t &fiinick $calc($bvar(&fiinick,0) + 1) <option> $+ $nick($chan(%a),%c).pnick $+ </option>
      inc %c
    }
    ;<option>&#160;</option>
    bset -t &fii $calc($bvar(&fii,0) + 1) <tr><td><select size="8">
    bcopy &fii $calc($bvar(&fii,0) + 1) &fiinick 1 -1 
    bset -t &fii $calc($bvar(&fii,0) + 1) </select></td><td><b> $+ $chan(%a) $+ </b> $&
      <br>---Topic: $&
      $chan(%a).topic $+ <br>---Mode: $chan(%a).mode $+ <br>---Key: $&
      $chan(%a).key $+ <br>---Limit: $chan(%a).limit $+ <br>---Users: $&
      $nick($chan(%a),0,a) <b>(@: $nick($chan(%a),0,o) $+ ;%: $&
      $nick($chan(%a),0,h) $+ ;+: $nick($chan(%a),0,v) $+ )</b></td></tr><tr><td>&#160;</td><td>&#160;</td></tr>
    inc %a
  }
  bset -t &fii $calc($bvar(&fii,0) + 1) </table>
}


Now you just need to decide whether a binary variable is appropriate for what you need to do.

Top
#209099 - 04/02/09 02:05 AM Re: hash tables [Re: hixxy]
MTec007 Offline
Fjord artisan

Registered: 05/02/07
Posts: 234
Loc: Tennesee
that works well for the channels i regular in, but if i try say, freenode/##php then it fails. this is turning out to be a lot harder than i had expected.

* Line too long: $bvar

alias -l new_servers_channels {
bunset &fii &fiinick
var %nsc = <b>Currently Active:</b><br><b> $+ $scid($activecid).network ( $+ $scid($activecid).me $+ ): $active $+ </b><br><br>
list_all
-> return %nsc $bvar(&fii,1,$bvar(&fii,0)).text
}


Edited by MTec007 (04/02/09 02:05 AM)
_________________________
mIRC.net E-Motz.com

Top
#209137 - 04/02/09 11:35 PM Re: hash tables [Re: MTec007]
hixxy Offline
Hoopy frood

Registered: 06/09/05
Posts: 2876
That's because you're trying to return the entire value of the binary variable, but the entire point of binary variables is to hold large amounts of data that mIRC commands cannot usually interpret.

Instead, you should return the name of the binary variable, and then in the command where you actually NEED to use the data (ie. writing it to a file), then you can either parse the data in chunks, or something else depending on what you do with it.

It's hard to help you without seeing where you actually use the data.

Top
#209138 - 04/02/09 11:50 PM Re: hash tables [Re: hixxy]
MTec007 Offline
Fjord artisan

Registered: 05/02/07
Posts: 234
Loc: Tennesee
this is everything i've got that has to do with this info. the info gets sent via socket here:

Quote:
alias -l sendfilenext {
var %queuespace = $calc(16384 - $sock($sockname).sq)
if ( %queuespace isnum 1- ) {
bread %sendfile %sendpos %queuespace &temp
if (%sendfile == $pws_htdocs $+ imggallery.html) { brepbytes &temp $+(%,_IMG_GALLERY_,%) $new_img_gallery }
sockwrite $sockname &temp
inc %sendpos %queuespace
if ( %sendpos >= $file(%sendfile).size ) {
sockmark $sockname
.remove $pws_temp $+ $sockname $+ .tmp
.remove $pws_temp $+ $sockname $+ _c.tmp
;unset %sendfile %sendpos
.timer 1 1 sockclose $sockname
unset %inuse
}
else { aline @pws 4 %sendpos >= $file(%sendfile).size  }
}
else { aline @pws 4 %queuespace isnum 1-  }
}

alias -l new_servers_channels {
bunset &fii &fiinick
var %nsc = <b>Currently Active:</b><br><b> $+ $scid($activecid).network ( $+ $scid($activecid).me $+ ): $active $+ </b><br><br>
list_all
return %nsc $bvar(&fii,1,$bvar(&fii,0)).text
}

alias -l list_all { .scon -at1 list_chan }

alias -l list_chan {
bset -t &fii $calc($bvar(&fii,0) + 1) <b> $+ $network ( $+ $me $+ )</b><br> <table>
var %a = 1, %b = $chan(0)
while %a <= %b {
var %c = 1, %d = $nick($chan(%a),0)
while %c <= %d {
bset -t &fiinick $calc($bvar(&fiinick,0) + 1) <option> $+ $nick($chan(%a),%c).pnick $+ </option>
inc %c
}
bset -t &fii $calc($bvar(&fii,0) + 1) <tr><td><select size="8">

bcopy &fii $calc($bvar(&fii,0) + 1) &fiinick 1 -1

bset -t &fii $calc($bvar(&fii,0) + 1) </select></td><td><b> $+ $chan(%a) $+ </b><br>---Topic: $chan(%a).topic $+ <br>---Mode: $chan(%a).mode $+ <br>---Key: $chan(%a).key $+ <br>---Limit: $chan(%a).limit $+ <br>---Users: $nick($chan(%a),0,a) <b>(@: $nick($chan(%a),0,o) $+ ;%: $nick($chan(%a),0,h) $+ ;+: $nick($chan(%a),0,v) $+ )</b></td></tr><tr><td>&#160;</td><td>&#160;</td></tr>
bunset &fiinick
inc %a
}
bset -t &fii $calc($bvar(&fii,0) + 1) </table>
}
_________________________
mIRC.net E-Motz.com

Top
#209139 - 05/02/09 12:13 AM Re: hash tables [Re: MTec007]
argv0 Offline
Planetary brain

Registered: 13/10/03
Posts: 3918
Loc: Montreal, QC, Canada
sendfile? bread? you said you weren't using files...

Your problem is the line:

return %nsc $bvar(&fii,1,$bvar(&fii,0)).text

As mentioned, the point of using bvars is to never directly access the data. You either want to simply return &fii or just know to read from &fii after calling that alias (the former case being the better design choice).
_________________________
- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"

Top
#209142 - 05/02/09 12:50 AM Re: hash tables [Re: argv0]
MTec007 Offline
Fjord artisan

Registered: 05/02/07
Posts: 234
Loc: Tennesee
the sendfile part is not the same thing. i dont know, maybe this has been a waste of my time. thanks any way.
_________________________
mIRC.net E-Motz.com

Top