Version 62 of XiRCON-II

Updated 2003-01-23 08:35:36

DG is authoring an IRC Client. It is a work in progress. No downloadable beta is ready, yet... watch this space.


This IRC client is a faithful XiRCON [L1 ] clone regarding how the user scripting operates. Here are some screenshots:

  • Doing Japanese:

http://tomasoft.sf.net/in_a_japanese_channel.gif

  • Doing Chinese:

http://tomasoft.sf.net/263.gif

  • Doing Klingon (in utf-8 over IRC and back using the CTCP/2 method of escaping):

http://tomasoft.sf.net/klingon.gif

  • being normal (boring):

http://tomasoft.sf.net/in_an_english_channel.gif


The client has been painfully designed to be 2 complimentary halves:

1.�The�back-end
The irc_engine Tcl extension DLL (100% Tcl API only, with a little STL) for handling everything that is not seen.
2.�The�UI
Whatever UI the user prefers according to the command control API. It could done in Tk, an implimentation in curses, Win32 GUI, or as odd as streaming html output with form input for posting.

The IRC_Engine back-end --

The irc_engine extension provides a single Incr Tcl class. The UI half (partialy undefined) also provides an Incr Tcl class. The two are brought together using inheritence like so:

 source irc_engine.itcl
 # ===============================================================
 # By selecting which IRC::ui class is sourced, we can switch
 # to what UI we want to use.
 # ===============================================================
 source irc_ui.itcl
 itcl::class IRC::connection {
    # ===============================================
    # Bring the 2 halves together using inheritence.
    # ===============================================
    inherit engine ui
    constructor {args} {
        eval engine::constructor $args
    } {}
    public method destroy {} {itcl::delete object $this}
 }

 ### Create a connection instance.
 set a [IRC::connection #auto someUserScript1.tcl someUserScript2.tcl]

 ### Connect to IRC.
 $a connect irc.qeast.net davygrvy DG {yo moma!}

In the above, $a is now the connection object. All behavior of the engine is located in a script file called default.tcl . The behavior of irc_engine can be scripted by the user by loading scripts which are queried for event hooks prior to doing the default behavior. I do have a generic framework to the system, but only Tcl is supported. I have code started for perl, python, and java, but I'll have to get back to it later.

Here's where it gets interesting for user scripts.. Each tcl user script is run in its own interpreter. It maintains some of its own commands such as [IRC::on], but aliases most up to the global interp (I also call it the controlling or UI interp). So from the script, a call to IRC::echo ... will alias up to the global as connection0 echo ... where connection0 is the Incr Tcl object. This allows us to have our scripts track with their connection object. Where this gets more interesting is that from this aliasing, I can assume commands that will be in the top-most object that are provided by the UI (thanks to inheritence). The echo method is located in the UI half, yet the user script is in a separate interp of the irc_engine extension half and always linked to its parent object.

irc_engine uses Tcl's event loop. This diagram shows some of the code paths:

http://tomasoft.sf.net/incoming_trail.gif

Tcl::Socket is just a wrapper for Tcl's socket API stuff. When a line from the server is received, it is parsed into its protocol parts and is the container for the parts that will get passed around to the subsiquent modules. IRCSplitAndQ is responsible for any text mappings (or multiple mappings) that need to be decoded, any CTCP/2 encoding escapes, any CTCP unquoting, any mode splitting, and removing/queueing of all embedded CTCP commands prior to the edited original getting posted as a job to the event loop. Phew!

http://tomasoft.sf.net/ircevent_trail.gif

When a job we had posted from IRCSplitAndQ is ready to be serviced by Tcl, our Tcl_EventProc named EvalCallback is called which just sets an interp lock then calls IRCEngine::EvalOneIRCEvent in the correct connection object. Within the Tcl_Event structure is our IRCParse C++ object all prepared to be serviced. First we run PreEvent(line), so certain IRC events such as 'join' can be set into the channels list prior to scripts being run. The same is true in the inverse, as a 'part' event will be removed from the channels list from PostEvent(). Space is left here for the inclusion of an Internal Address List when I get around to it.

Now after PreEvent() is run, all script providers in LIFO order are handed the IRCParse object. If any of the providers return IRCUserScriptProvider::COMPLETED (an enum), then the event is considered complete and all processing stops. If no providers claim the event as completed, then the default script will process it. If the default script doesn't handle it, and the mode for the connection is 'debugging' rather than normal, it will be displayed in red in the status window with event name or numeric. Same as:

 echo "\006CC\006***\006C\006 [event] [join [lrange [args] 1 end]]" status

Without the debugging mode, no red color or event code is displayed. Same as:

 echo "*** [join [lrange [args] 1 end]]" status

Here's an example of the user scripting and how identical it is to the idea of XiRCON. Old-time XiRCON'ers will notice, of course, the new use of namespaces and the msgcat package for handling multilingual strings. We must improve on XiRCON, too.

 package require IRC_Engine_User

 namespace eval ::IRC {
    on PRIVMSG {
        set dest [lindex [args] 0]
        set msg [lindex [args] 1]

        ### ignore an empty one.
        if {![string length $msg]} {complete; return}

        if {![icomp $dest [my_nick]]} {
            ### private msg
            echo "[color highlight]*[color nick][nick][color highlight]*[color private] $msg" query [nick]

        } elseif {[string index $dest 0] == "\$"} {
            ### server (global) message
            echo "[color highlight]<[color nick][nick][color highlight]>[color default] $msg" status

        } else {
            echo "[color highlight]<[color nick][nick][color highlight]>[color default] $msg" channel $dest

        }
        complete
    }
    on $RPL_TOPICWHOTIME     {
        echo "[color change]*** [mc {Topic for}] [color channel][lindex [args] 1][color change] [mc {was set by}] [color nick][lindex [args] 2][color change] [mc {on}] [clock format [lindex [args] 3]]"
        complete
    }
    on $RPL_UMODEIS            {
        echo "[color change]*** [mc {Your modes are}] [color mode]\"[join [lrange [args] 1 end]]\"" status
        complete
    }
 }

As in XiRCON, these are the commands available to an event hook for asking about the line that fired the event:

http://tomasoft.sf.net/ircparser.gif

Not shown is raw_line and it returns the whole thing as a string prior to any processing. raw_args is also prior to any processing. All return strings except for args which is a list (and is very processed). raw_line will be empty for any embedded event such as ctcp or mode+o. nick will equal host for a server message.

Unlike XiRCON, a PRIVMSG event that contains a CTCP in its entire trailing param, will fire a PRIVMSG anyway, even though it will be empty. It may seem silly at first, but the original raw_line would then have no way to get through. Think about it for a sec... It was a PRIVMSG that came in, and just so happened to contain within it a CTCP. I doesn't make sense to me to drop the original PRIVMSG. That was the event. Same is true for a NOTICE with a ctcp_reply.


The UI Half --

The first major feature is the support of ALL embedded text attributes ever known to mankind and robots alike. It supports ircII, mIrc, ANSI, besirc/hydra, and CTCP/2. As CTCP/2 is the most in features, this is the native usage of the display. The other attribute types are pre-translated up to CTCP/2. The CTCP/2 parser is also in the IRC_Engine as an Itcl class for use by Tk applications.

CTCP/2 embedded text attributes are described @ http://www.lag.net/~robey/ctcp . All attibutes in section 2 are supported -> http://www.lag.net/~robey/ctcp/ctcp2.2.txt . One extension was added using the CTCP/2 method for extending, for doing the tag color types. This will be especially useful for a UI in Tk and allows the display to define how "normal", "highlight", etc.. will be rendered rather than the parser filling in literal values. These tag colors are returned by the color command and are not intended for transmision -- internal use only. Similar to XiRCON's \aXX color codes where X is a hexidecimal number.

It should be noted that the parser reads it all, and whether an implimentation of a UI does actually do the attributes is a bit outside of my claims. For example, if I make a Win32 console text-mode UI for this client, I will have a choice of only 12 colors. As a 24-bit depth is available to the CTCP/2 color attribute, the 24-bit value will need to be truncated for that display type (ie. 256 levels of red get mashed to 3 levels, off/on/bright).

I should slow down for a moment and say that the UI is more of an API than an actual complete and realized implimention.

To better describe the concept of implementation seperate from the UI, here is an example of a UI that generates HTML as its output. This is the link to the output [L2 ] of this UI script getting a channel listing from a chinese server:

 #------------------------------------------------------------------------
 #  irc_ui_html.itcl --
 #
 #  UI for irc_engine.dll for HTML output.  Proof-of-concept.
 #
 #------------------------------------------------------------------------

 package require IRC_Engine

 itcl::class IRC::ui {
    constructor {args} {
        ### create a CTCP2 parser in tag mode.
        set displayAction [CTCP2::parse #auto [itcl::code $this dodisplay] tag]
        set f [open "irc_output.html" w]
        fconfigure $f -encoding utf-8
        puts $f {<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 <html>
 <head>
    <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
    <META NAME="Generator" CONTENT="IRC_Engine">
    <TITLE>Live on Internet Relay Chat.</TITLE>
 </head>
 <body text="#C0C0C0" bgcolor="#000000">
 <basefont size=4>
 <pre>}

    }
    destructor {
        if {[info exist displayAction]} {$displayAction destroy}
        if {[info exist f]} {close $f}
    }
    public {
        method destroy {} {itcl::delete object $this}
        method echo {what {where {}} {which {}}}
 #        method window {args}
        method menu {args}
        method hotkey {args}
        method alias {args}
        method channel {args}
        method query {args}
        method chat {args}
        method queries {args}
        method chats {args}
        method say {args}
        method input {args}
    }
    private {
        method dodisplay {args}
        variable displayAction
        variable f
        variable hadfontsetting 0
        variable hadbold 0
        variable hadunderline 0
        variable hadoverstrike 0
        variable haditalic 0
        variable hadblink 0
    }
 }

 itcl::body ::IRC::ui::dodisplay {args} {
    set cmd [lindex $args 0]
    switch -- $cmd {
        "tag" {
            if {$hadfontsetting} {
                puts -nonewline $f {</font>}
            }
            set hadfontsetting 1
            switch -- [lindex $args 1] {
                "default" {
                    puts -nonewline $f "<font color=\"#C0C0C0\">"
                }
                "public" {
                    puts -nonewline $f "<font color=\"#C0C0C0\">"
                }
                "private" {
                    puts -nonewline $f "<font color=\"#C0C0C0\">"
                }
                "action" {
                    puts -nonewline $f "<font color=\"#FF4500\">"
                }
                "notice" {
                    puts -nonewline $f "<font color=\"#D2B48C\">"
                }
                "ctcp" {
                    puts -nonewline $f "<font color=\"#CD5C5C\">"
                }
                "change" {
                    puts -nonewline $f "<font color=\"#BA55D3\">"
                }
                "join" {
                    puts -nonewline $f "<font color=\"#66CDAA\">"
                }
                "part" {
                    puts -nonewline $f "<font color=\"#66CDAA\">"
                }
                "kick" {
                    puts -nonewline $f "<font color=\"#32CD32\">"
                }
                "quit" {
                    puts -nonewline $f "<font color=\"#32CD32\">"
                }
                "highlight" {
                    puts -nonewline $f "<font color=\"#FF00FF\">"
                }
                "error" {
                    puts -nonewline $f "<font color=\"#FF0000\">"
                }
                "nick" {
                    puts -nonewline $f "<font color=\"#48D1CC\">"
                }
                "channel" {
                    puts -nonewline $f "<font color=\"#00FF00\">"
                }
                "mode" {
                    puts -nonewline $f "<font color=\"#FFFF00\">"
                }
                "socket" {
                    ### white.
                    puts -nonewline $f "<font color=\"#FFFFFF\">"
                }
            }
        }
        "bold" {
            if {[lindex $args 1]} {
                set hadbold 1
                puts -nonewline $f {<b>}
            } else {
                set hadbold 0
                puts -nonewline $f {</b>}
            }
        }
        "reverse" {}
        "underline" {
            if {[lindex $args 1]} {
                set hadunderline 1
                puts -nonewline $f {<u>}
            } else {
                set hadunderline 0
                puts -nonewline $f {</u>}
            }
        }
        "overstrike" {
            if {[lindex $args 1]} {
                set hadoverstrike 1
                puts -nonewline $f {<strike>}
            } else {
                set hadoverstrike 0
                puts -nonewline $f {</strike>}
            }
        }
        "italic" {
            if {[lindex $args 1]} {
                set haditalic 1
                puts -nonewline $f {<i>}
            } else {
                set haditalic 0
                puts -nonewline $f {</i>}
            }
        }
        "blink" {
            if {[lindex $args 1]} {
                set hadblink 1
                puts -nonewline $f {<blink>}
            } else {
                set hadblink 0
                puts -nonewline $f {</blink>}
            }
        }
        "url" {}
        "spacing" {}
        "fontsize" {
            if {$hadfontsetting} {
                puts -nonewline $f {</font>}
            }
            set hadfontsetting 1
            puts -nonewline $f "<font size=\"[expr {[lindex $args 1]+4}]\">"
        }
        "forecolor" {
            if {[lindex $args 1] == "reset"} {
                set hadfontsetting 1
                puts -nonewline $f {</font>}
            } else {
                if {$hadfontsetting} {
                    puts -nonewline $f {</font>}
                }
                set hadfontsetting 1
                puts -nonewline $f "<font color=\"[format #%02X%02X%02X [lindex $args 1] [lindex $args 2] [lindex $args 3]]\">"
            }
        }
        "backcolor" {}
        "segment" {
            puts -nonewline $f [lindex $args 1]
        }
    }
    puts $args
 }

 itcl::body ::IRC::ui::echo {what {where {}} {which {}}} {
    $displayAction parse $what
    if {$hadfontsetting} {
        set hadfontsetting 0
        puts -nonewline $f {</font>}
    }
    if {$hadbold} {
        set hadbold 0
        puts -nonewline $f {</b>}
    }
    if {$hadunderline} {
        set hadunderline 0
        puts -nonewline $f {</u>}
    }
    if {$hadoverstrike} {
        set hadoverstrike 0
        puts -nonewline $f {</strike>}
    }
    if {$haditalic} {
        set haditalic 0
        puts -nonewline $f {</i>}
    }
    if {$hadblink} {
        set hadblink 0
        puts -nonewline $f {</blink>}
    }
    puts $f {}
    flush $f
 }

The HTML output looks great. I don't see an obvious way to support background colors unless I try to use a table. Some sublties in how the attribute parser works is showing itself. I can see where I need to study the need for different modes it should operate in.

[More to come]


[ Category Internet | Category Application | Category Games | Category Object Orientation ]