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.

Module output by using Tcl

Discussion of Eggdrop's code and module programming in C.
Post Reply
K
Kappa007
Voice
Posts: 38
Joined: Tue Jul 26, 2005 9:53 pm

Module output by using Tcl

Post by Kappa007 »

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 ;)
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
Post Reply