egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Module output by using Tcl

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Modules & Programming
View previous topic :: View next topic  
Author Message
Kappa007
Voice


Joined: 26 Jul 2005
Posts: 38

PostPosted: Sun Feb 12, 2006 9:03 pm    Post subject: Module output by using Tcl Reply with quote

Synopsis:
----------
This article is for Eggdrop module developers.
This article covers Module <-> Tcl interaction in concern of server output routines.

As an example: A posibility how to output encrypted text from an Eggdrop module
by utilizing a 3rd party Tcl encryption script e.g. Mircryption/McEggdrop .



Motivation:
------------
dprintf(DP_SERVER, ... ) sends directly to the output socket.
No Tcl evaluation is performed, no scripts are invoked.

So unless we encrypt the text we want to send ourself, the bot will recognize encrypted commands
but respond in plaintext. That's kinda ugly if you ask me Wink
Even if we would use the blowfish module to encrypt the text we still got the problem that we don't have the keys.



Solution:
----------
We do NOT use dprintf() to send to the server but instead stuff our output into the Tcl Interpreter.
This is done by using Tcl_GlobalEval() as the ".tcl" command on the partyline does.

Change

dprintf(DP_SERVER, "PRIVMSG #chan :text")

to

Tcl_GlobalEval(interp, "putserv {PRIVMSG #chan :text}" )

and you're set.
If you care: Tcl_GlobalEval and Tcl_GlobalEvalObj are older procedures that are now deprecated. [from Tcl 8.4 manual]
use Tcl_EvalEx( interp, "putserv {PRIVMSG #chan :text}", -1, TCL_EVAL_GLOBAL ) instead.



Additional notes:
------------------
Be aware that scripts might rename/rebind/change/whatever the tcl commands.
So this solution could be classified as 'hack'.
Also you have to take care about escaping.
Replacing \ by \\ and afterwards { and } by \{ and \} could be sufficient when using {<string>}

A neat feature of that method could be not to use {<string>} but "<string>".
Then the Tcl interpreter would evaluate it, which means you could use Tcl statements in your output.
Designing your modules to only output Tcl variable names like $MyWelcomeText and using a separate Tcl file
which you either load by using "readtclprog()" or via the eggdrop config you could easily change the output
or add multi-language support to your module.


Regards,
Kappa007
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Modules & Programming All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber