This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

TCL newbie needs help on putting a list... Or alternatives..

Old posts that have not been replied to for several years.
Locked
K
Kingster

TCL newbie needs help on putting a list... Or alternatives..

Post by Kingster »

OK... Maybe I am missing something very fundamental about lists, but I can't for the life of me figure this out. I am basically modding the qstat4eggdrop.tcl to display it the way I want it displayed, but I'll be damned if I can get it to work right.

Here's what I have right now:

Code: Select all

# qstat.tcl - Qstat4Eggdrop version 1.8
#
# Modified for UnrealPlayground by Kingster <kingster@unrealplayground.com>
#
# This script will query halflife, quake 2, quake 3 and UT servers to
# display server status and players using the public commands.
#
# Orginal script (1.0) by Mikael Blomqvist <micke@peachpuff.com>
# Modified (1.5) by ST8 <st8@q3f.net> and in part by Ad <ad@contempt.org.uk>
# Modified again (1.7) by Peter Postma <peterpostma@yahoo.com>
#   changes: - security hole fixed. (passing bad arguments to TCL's exec)
#            - display players fixed.
# Version 1.8 by Peter Postma <peterpostma@yahoo.com>
#   changes: - doesn't need a temp file anymore to display player info
#            - use regsub for input checking
#            - better error checking / error messages
#            - lot of clean up
#
# This script requires Qstat! Get it @ http://www.qstat.org
# Typ !qstat for a command list.

# Configuration settings:

# Public trigger
set tr "!"

# Flags needed to use the commands
set qstat_flag "-|-"

# Path to qstat folder containing qstat stuff/scripts and the qstat program
set pathqstat "/home/ircadmin/MonkBOT/qstat"

# Channels you _dont_ want the bot to reply to public triggers on (seperate with spaces):
set nopub ""



################################################################
# This is where the evil TCL code starts, read at your peril!  #
################################################################

set qversion "1.8"

bind pub $qstat_flag ${tr}servers pub:servers
bind pub $qstat_flag ${tr}server1 pub:server1
bind pub $qstat_flag ${tr}server2 pub:server2
bind pub $qstat_flag ${tr}server3 pub:server3

proc qstat:check_input {text} {
  regsub -all {<|>|&|\|/|%|[|]|[$]} $text "" text

  return $text
}

proc pub:servers {nick host hand chan arg} {
  global pathqstat tr nopub
  if {[lsearch -exact $nopub [string tolower $chan]] >= 0} {return 0}
  set stat [open "|$pathqstat/qstat -f $pathqstat/servers.lst -sort l -Ts $pathqstat/servermini.qstat" r]
  pub:qstat_results $nick $stat
  close $stat
  return 0
}

proc pub:server1 {nick host hand chan arg} {
  global pathqstat tr nopub
  if {[lsearch -exact $nopub [string tolower $chan]] >= 0} {return 0}
  set stat [open "|$pathqstat/qstat -uns 204.149.41.5 -sort TF -P -Ts $pathqstat/serverfull.qstat -Tp $pathqstat/players.qstat" r]
  pub:qstat_results $nick $stat
  close $stat
  return 0
}

proc pub:server2 {nick host hand chan arg} {
  global pathqstat tr nopub
  if {[lsearch -exact $nopub [string tolower $chan]] >= 0} {return 0}
  set stat [open "|$pathqstat/qstat -uns 64.246.32.42 -sort TF -P -Ts $pathqstat/serverfull.qstat -Tp $pathqstat/players.qstat" r]
  pub:qstat_results $nick $stat
  close $stat
  return 0
}

proc pub:server3 {nick host hand chan arg} {
  global pathqstat tr nopub
  if {[lsearch -exact $nopub [string tolower $chan]] >= 0} {return 0}
  set stat [open "|$pathqstat/qstat -uns 64.246.42.102 -sort TF -P -Ts $pathqstat/serverfull.qstat -Tp $pathqstat/players.qstat" r]
  pub:qstat_results $nick $stat
  close $stat
  return 0
}

proc pub:qstat_results {nick pf} {
  set output_list ""
  while {[gets $pf line] >= 0} {
    lappend output_list $line
  }
  set output_line [join $output_list "\n"]
  if {[string match "DOWN*" $output_line]} {
      putquick "PRIVMSG $nick :Connection refused while querying server"
      break
    } elseif {[string match "HOSTNOTFOUND*" $output_line]} {
      putquick "PRIVMSG $nick :Host not found"
      break
    } elseif {[string match "TIMEOUT*" $output_line]} {
      putquick "PRIVMSG $nick :Timeout while querying server"
      break
    } else {
    putquick "PRIVMSG $nick : $output_line"
    }
  }
}
Basically, my idea was to put the info returned from qstat into a list, separate each line returned from qstat with a \n (set output_line [join $output_list "\n"]) so it would send it to the server as one line but get sent to the requestor in as many lines as it needed...

Problem is, when it goes to send the line, it only send to where the \n was inserted.

I know there has to be a better way to do this... Can anyone help? Or am I beyond help? :-?
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

This is not due tot he code (as such), but the way in which IRC servers process messages.

While most people assume, that sending a \n in a line to the server, will force the text on to the next line, this is not true.

The IRC RFC dictates, that commands sent tot he server, are processed until it reaches a \n, at which point, it's the start of a new command.

IE, sending

Code: Select all

putserv "PRIVMSG #help :hello1\nPRIVMSG #help :hello2"
is the same as

Code: Select all

putserv "PRIVMSG #help :hello1"
putserv "PRIVMSG #help :hello2"
From what I remember, the RFC dictates that either a line-feed or a newline character dictates the end of a line.

The only way, is to use, multiple putserv (or equivilant) commands.

In this situation, you could loop through the list with foreach, and output the entire list.
K
Kingster

Thanks! So... Would this work?

Post by Kingster »

Thanks for that info ppslim. I was figuring I would have to do something like a foreach... Would this work? Like I said - I'm pretty new at this.

Code: Select all

foreach a [lindex $output_line [expr [llength $output_line] -1]] { 
  puthelp "PRIVMSG $nick :$a" 
} 
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

3 changes need to be made.

locate and remove this line

Code: Select all

set output_line [join $output_list "\n"]
In each of the [string match] commands below the removed line, you ned to replace the variable $output_line with

Code: Select all

[lindex $output_list 0]
IE

Code: Select all

string match "DOWN*" $output_line
should become

Code: Select all

string match "DOWN*" [lindex $output_list 0]
An last, at the base of that script, change the following line:

Code: Select all

putquick "PRIVMSG $nick : $output_line"
To this block.

Code: Select all

foreach output_line $output_list {
putquick "PRIVMSG $nick : $output_line"
}
K
Kingster

Post by Kingster »

Yes... that worked. Like a charm. One last question... I found the topic that lists the color codes... That is a lot of help...

However, is there something like \n that I can use for a tab (to get even columns)? Something like \t?

Where can I find a list of those codes? And can I put those codes into the array as I reading the qstat output into them? Qstat uses a template file for the output, and I want to put the tab into the code, so it would be something like

Code: Select all

$teamnum \t $frags \t $ping \t $playername
Since the line is sent to the list as a full line, will those tabs (if that is the right code) make it into the list properly? Or do I need to do something different?
Locked