mIRC Home    About    Download    Register    News    Help

Print Thread
#27009 30/05/03 02:22 AM
Joined: May 2003
Posts: 177
P
Prizm Offline OP
Vogon poet
OP Offline
Vogon poet
P
Joined: May 2003
Posts: 177
How can I make mIRC loop through $read and return a line with no text in it?

I have a text file called rserv.txt. The contents of the file is exactly like this:

Welcome!

Please note that this server is monitored!


---

I want that to appear exactly like that when I do /loop

Here's my loop command:

Code:
alias loop {
  var %i = 1
  while ($read(rserv.txt,nt,%i)) {
    echo -a $ifmatch
    inc %i
  }
}


All my code seems to be doing is returning the 1st line. Why isn't it returning the rest of the file?

#27010 30/05/03 02:40 AM
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
You can't do that with $read(). You can get pretty close by using $readn or $lines() and echo a <Ctrl+B> instead of a truly blank line etc, but the recommended method for what you want is /loadbuf. Not only does it echo all the blank lines and multiple spaces but is also far faster than looping through $read().


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
#27011 30/05/03 02:43 AM
Joined: May 2003
Posts: 177
P
Prizm Offline OP
Vogon poet
OP Offline
Vogon poet
P
Joined: May 2003
Posts: 177
I need to send the text in the file through a socket. How would you recommend doing it? I was thinking of /loadbuf'ing the file into a hidden custom window and parsing it that way. Any better way?

Example:

Code:
alias loop {
  if (!$window(@rservmsg)) { window -h @rservmsg }
  loadbuf @rservmsg rserv.txt
  var %i = 1
  while ($line(@rservmsg,%i)) {
    echo -a $replace($ifmatch,$chr(32),$chr(160))
    inc %i
  }
  if ($window(@rservmsg)) { window -c @rservmsg }
}


#27012 30/05/03 02:57 AM
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
In this case, I'd use binary transfer, ie read 8192-byte chunks from the file to a &binvar with /bread, then /sockwrite that &binvar. There are plenty of example scripts of this kind around (I'd imagine #helpdesk's website has something relative), including some on these boards (a Search would probably reveal them).


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
#27013 30/05/03 03:00 AM
Joined: May 2003
Posts: 730
S
Hoopy frood
Offline
Hoopy frood
S
Joined: May 2003
Posts: 730
your loop can be done like that:
alias loop {
var %i = 1
while (%i <= $lines(rserv.txt)) {
if ($read(ruserv.txt,%i) != $null) echo -a $ifmatch
else echo -a $chr(160)
inc %i
}
}

#27014 30/05/03 03:12 AM
Joined: May 2003
Posts: 177
P
Prizm Offline OP
Vogon poet
OP Offline
Vogon poet
P
Joined: May 2003
Posts: 177
That site is all messed up. I can't access any documents.

#27015 30/05/03 12:15 PM
Joined: Dec 2002
Posts: 774
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Dec 2002
Posts: 774
What's wrong w/ the good ol' /play
/help /play


Code:
//if ( khaled isgod ) echo yes | else echo no
#27016 30/05/03 01:42 PM
Joined: May 2003
Posts: 177
P
Prizm Offline OP
Vogon poet
OP Offline
Vogon poet
P
Joined: May 2003
Posts: 177
You can't use /play with sockets. And I need to send the contents of the text file via sockets.

OK, I tried using /bread, it seems to be doing exactly what I want, but could someone tell me if I did it correctly?

Code:
    if (($isfile(rserv.txt)) &amp;&amp; ($file(rserv.txt).size &gt; 0)) {
      bread rserv.txt 0 [color:red]$file(rserv.txt).size[/color] &amp;rserv
      sockwrite user &amp;rserv
}

#27017 30/05/03 02:17 PM
Joined: May 2003
Posts: 730
S
Hoopy frood
Offline
Hoopy frood
S
Joined: May 2003
Posts: 730
heh no, i suggest u to send 8192 bytes each time cuz that's the maximum binary variable can store,
if ($isfile(rserv.txt)) {
var %x = 8192,%y = 0
:blah
bread rserv.txt %y %x &rserv
if ($bvar(&rserv,0)) { sockwrite user &rserv | %x = %x + 8192 | %y = %y + 8192 | goto blah }
}




Last edited by ScatMan; 30/05/03 02:36 PM.
#27018 30/05/03 02:21 PM
Joined: May 2003
Posts: 177
P
Prizm Offline OP
Vogon poet
OP Offline
Vogon poet
P
Joined: May 2003
Posts: 177
Ahhh, I see.


Link Copied to Clipboard