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.

question with some tcl + php code

Old posts that have not been replied to for several years.
Locked
b
blotter45
Voice
Posts: 17
Joined: Mon Feb 28, 2005 8:37 am

question with some tcl + php code

Post by blotter45 »

Hiya guys,

I've got an eggdrop tcl script, which takes output from a php script, and then announces it to a channel.

The php output is in the form:

line 1
line 2
line 3
etc

here are the lines of php code that send the output:

Code: Select all

$fp = fsockopen ($botaddr, $botport, $errno, $errstr, 120);
fputs($fp,"{ \00314:::::::::::::::::::::::::::::::::: \0031[ \002\0037Test Title \002\0031] \00314:::::::::::::::::::::::::::::::::: } ");
fputs($fp,"{ [\00314".$title."\0031] \00314::\0031 [\00314HEADING\0031] \00314::\0034 ".$lastthread." \00314::\0031 [\00314BY\0031] \00314::\0034 ".$lastposter." \00314@\0037 ".$tname." } ");
fputs($fp,"{ \00314:::::::::::::::::::::::::::::::::: \0031[ \002\0037--------------------- \002\0031] \00314:::::::::::::::::::::::::::::::::: } \n\n");
sometimes those php variables contain characters like []{}, so those have to be processed properly, without causing tcl errors.

here is the tcl script that processes the php output:

Code: Select all


listen 22625 script vbulletinaccept_admin1

proc vbulletinaccept_admin1 {idx} {
  putlog "ADMIN1: incoming connection on idx: $idx"
  control $idx vbincoming_admin1
}

proc vbincoming_admin1 {idx arg} {
  if {[join $arg] != ""} {
    for { set i 0 } { $i < [llength $arg] } { incr i } {
      if {[lindex $arg $i] != ""} {
        putserv "PRIVMSG #somechan :[lindex $arg $i]"
      }
    }
  }
  killdcc $idx
}
I've tried many different approaches in that tcl proc, but so far nothing works well to elimintate to tcl errors :(

The tcl code is supposed to take each line from the php script, and output them on irc. But I get alot of tcl errors about "unmatched open brace in list", and only 1 line of text is shown on irc, also not sure if that is the correct fputs syntax for the php code..

Is there something I'm missing on the php side of things, or is there a way to prevent any errors from the tcl side? I have also tried using regsub to add backslashes to characters like {}[] in the tcl proc, but no luck their either :(
G
Galadhrim
Op
Posts: 123
Joined: Fri Apr 11, 2003 8:38 am
Location: Netherlands, Enschede

Post by Galadhrim »

The tcl code is supposed to take each line from the php script, and output them on irc. But I get alot of tcl errors about "unmatched open brace in list", and only 1 line of text is shown on irc...[/code]

Try using the php function addcslashes. I think the problem is not the tcl code but the php code. If you tried adding blackslashes in TCL then the problem should be resolved earlier.

Code: Select all

string addcslashes ( string str, string charlist )

Returns a string with backslashes before characters that are listed in charlist parameter. It escapes \n, \r etc. in C-like style, characters with ASCII code lower than 32 and higher than 126 are converted to octal representation. 

Be careful if you choose to escape characters 0, a, b, f, n, r, t and v. They will be converted to \0, \a, \b, \f, \n, \r, \t and \v. In PHP \0 (NULL), \r (carriage return), \n (newline) and \t (tab) are predefined escape sequences, while in C all of these are predefined escape sequences. 
also not sure if that is the correct fputs syntax for the php code..
its fine.


So before you send the string to the bot. so like:

Code: Select all

$fp = fsockopen ($botaddr, $botport, $errno, $errstr, 120); 
fputs($fp, addcslashes("{ mystring }", "[]{}")); 
Last edited by Galadhrim on Tue May 24, 2005 11:46 am, edited 2 times in total.
g
greenbear
Owner
Posts: 733
Joined: Mon Sep 24, 2001 8:00 pm
Location: Norway

Post by greenbear »

convert $arg to a list, using 'split', before doing anything to it.

Code: Select all

set arg [lrange [split $arg] 0 end]
and to convert it back to a string, you can use 'join'
b
blotter45
Voice
Posts: 17
Joined: Mon Feb 28, 2005 8:37 am

Post by blotter45 »

Galadhrim wrote:
The tcl code is supposed to take each line from the php script, and output them on irc. But I get alot of tcl errors about "unmatched open brace in list", and only 1 line of text is shown on irc...[/code]

Try using the php function addcslashes. I think the problem is not the tcl code but the php code. If you tried adding blackslashes in TCL then the problem should be resolved earlier.

Code: Select all

string addcslashes ( string str, string charlist )

Returns a string with backslashes before characters that are listed in charlist parameter. It escapes \n, \r etc. in C-like style, characters with ASCII code lower than 32 and higher than 126 are converted to octal representation. 

Be careful if you choose to escape characters 0, a, b, f, n, r, t and v. They will be converted to \0, \a, \b, \f, \n, \r, \t and \v. In PHP \0 (NULL), \r (carriage return), \n (newline) and \t (tab) are predefined escape sequences, while in C all of these are predefined escape sequences. 
also not sure if that is the correct fputs syntax for the php code..
its fine.


So before you send the string to the bot. so like:

Code: Select all

$fp = fsockopen ($botaddr, $botport, $errno, $errstr, 120); 
fputs($fp, addcslashes("{ mystring }", "[]{}")); 
Thanks for the quick reply to this! And it seems using addcslashes does fix the errors I was getting, and now all lines are shown rather than just one, but now there is a new problem, all of the php variables are empty when they get to the eggdrop :(
b
blotter45
Voice
Posts: 17
Joined: Mon Feb 28, 2005 8:37 am

Post by blotter45 »

I think this is a step in the right direction tho:

fputs($fp, addcslashes("{ mystring }", "[]{}"));

when I use that method, all the the characters are properly shown on irc, but each word is shown on it's own line, that's the only problem.

and then I tried using addcslashes($varname, "[]{}") on each different variable instead, and that shows the proper number of lines on irc, but each of the variables is empty.
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

hmm, okay thats what I would do:
remove all those wannabe list braces {} from the fputs thing in the php scripts. mark each end of a line with unique character... like \n or using an other like ~ or ° depending, which wont cause other troubles ^-^.
then in your tcl scripts, use at the very begining:
set arg [split $arg \n]
or whatever character you chose. you finished the output with a double \n\n, so I dont know how you transfer the lines, i cant tell if it will cause troubles. in case you use \n and finish with \n\n the last element is emtpy, so you can remove it with:
set arg [lreplace $arg end end]

the rest of the code with the for loop and the lindex thing should now be nolonger any problem.

why using split instead of addcslashes? because split knows the best which chars has be backlashed and where {} have to be used!
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
b
blotter45
Voice
Posts: 17
Joined: Mon Feb 28, 2005 8:37 am

Post by blotter45 »

De Kus wrote:hmm, okay thats what I would do:
remove all those wannabe list braces {} from the fputs thing in the php scripts. mark each end of a line with unique character... like \n or using an other like ~ or ° depending, which wont cause other troubles ^-^.
then in your tcl scripts, use at the very begining:
set arg [split $arg \n]
or whatever character you chose. you finished the output with a double \n\n, so I dont know how you transfer the lines, i cant tell if it will cause troubles. in case you use \n and finish with \n\n the last element is emtpy, so you can remove it with:
set arg [lreplace $arg end end]

the rest of the code with the for loop and the lindex thing should now be nolonger any problem.

why using split instead of addcslashes? because split knows the best which chars has be backlashed and where {} have to be used!
Thaks for your reply ;)

I tried your suggestions also, but all I end up with is just the first line of output being shown on irc.

ie, if I do this for the fputs in php:

Code: Select all

fputs($fp, "line one here \n");
fputs($fp, "line two here \n");
fputs($fp, "line three here \n");
fputs($fp, "last line \n\n");
then only the first line gets sent out to irc, not the rest :(

(the \n\n is needed in the last fputs line, otherwise the script will just hang)
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

have you checked the content of $arg?
have you tried to put everything in one statement like:
fputs($fp, "line one here \nline two here \nline three here \nlast line \n\n");?

if you split the text over seperate fputs, you seem to get the proc called multiple times. because you kill the dcc all remaining lines are lost.
you can try something like that:

Code: Select all

proc vbincoming_admin1 {idx arg} {
   if { $arg != "" && $arg != "\n"} {
      putserv "PRIVMSG #somechan :$arg"
   } elseif { $arg == "\n" } {
      killdcc $idx
   }
   return 0
}
if you know if it will be called with nothing or \n the last time, you further optimize it ^^
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
Locked