v0.0.0-...-555a4d7 Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Jan 8, 2011 License: BSD-3-Clause Imports: 21 Imported by: 0




View Source
const (
	// Commands
	CMD_AWAY      = "AWAY"
	CMD_DIE       = "DIE"
	CMD_HELP      = "HELP"
	CMD_JOIN      = "JOIN"
	CMD_KICK      = "KICK"
	CMD_KILL      = "KILL"
	CMD_LIST      = "LIST"
	CMD_MODE      = "MODE"
	CMD_NICK      = "NICK"
	CMD_OPER      = "OPER"
	CMD_OPME      = "OPME"
	CMD_PART      = "PART"
	CMD_PASS      = "PASS"
	CMD_PING      = "PING"
	CMD_PONG      = "PONG"
	CMD_QUIT      = "QUIT"
	CMD_USER      = "USER"
	CMD_WHO       = "WHO"

	// Signon responses
	RPL_WELCOME  = "001"
	RPL_CREATED  = "003"
	RPL_MYINFO   = "004"

	// Command replies
	RPL_ADMINEMAIL      = "259"
	RPL_ADMINLOC1       = "257"
	RPL_ADMINLOC2       = "258"
	RPL_ADMINME         = "256"
	RPL_AWAY            = "301"
	RPL_BANLIST         = "367"
	RPL_ENDOFINFO       = "374"
	RPL_ENDOFLINKS      = "365"
	RPL_ENDOFMOTD       = "376"
	RPL_ENDOFNAMES      = "366"
	RPL_ENDOFSTATS      = "219"
	RPL_ENDOFUSERS      = "394"
	RPL_ENDOFWHO        = "315"
	RPL_ENDOFWHOIS      = "318"
	RPL_EXCEPTLIST      = "348"
	RPL_INFO            = "371"
	RPL_INVITELIST      = "346"
	RPL_INVITING        = "341"
	RPL_ISON            = "303"
	RPL_LINKS           = "364"
	RPL_LISTSTART       = "321"
	RPL_LIST            = "322"
	RPL_LISTEND         = "323"
	RPL_LUSERCLIENT     = "251"
	RPL_LUSERME         = "255"
	RPL_LUSEROP         = "252"
	RPL_MOTD            = "372"
	RPL_MOTDSTART       = "375"
	RPL_NAMEREPLY       = "353"
	RPL_NOTOPIC         = "331"
	RPL_NOUSERS         = "395"
	RPL_NOWAWAY         = "306"
	RPL_REHASHING       = "382"
	RPL_SERVLIST        = "234"
	RPL_SERVLISTEND     = "235"
	RPL_STATSOLINE      = "243"
	RPL_STATSpLINE      = "249"
	RPL_STATSPLINE      = "220"
	RPL_STATSUPTIME     = "242"
	RPL_SUMMONING       = "342"
	RPL_TIME            = "391"
	RPL_TOPIC           = "332"
	RPL_TRACECLASS      = "209"
	RPL_TRACEEND        = "262"
	RPL_TRACELINK       = "200"
	RPL_TRACELOG        = "261"
	RPL_TRACESERVER     = "206"
	RPL_TRACEUSER       = "205"
	RPL_TRYAGAIN        = "263"
	RPL_UMODEIS         = "221"
	RPL_UNAWAY          = "305"
	RPL_UNIQOPIS        = "325"
	RPL_USERHOST        = "302"
	RPL_USERS           = "393"
	RPL_USERSSTART      = "392"
	RPL_VERSION         = "351"
	RPL_WHOISHOST       = "378"
	RPL_WHOISIDLE       = "317"
	RPL_WHOISMODES      = "379"
	RPL_WHOISSECURE     = "671"
	RPL_WHOISSERVER     = "312"
	RPL_WHOISUSER       = "311"
	RPL_WHOREPLY        = "352"
	RPL_YOUREOPER       = "381"

	// Error replies
	ERR_BADCHANMASK       = "476"
	ERR_BADMASK           = "415"
	ERR_BANLISTFULL       = "478"
	ERR_FILEERROR         = "424"
	ERR_KEYSET            = "467"
	ERR_NOADMININFO       = "423"
	ERR_NOCHANMODES       = "477"
	ERR_NOLOGIN           = "444"
	ERR_NOMOTD            = "422"
	ERR_NOOPERHOST        = "491"
	ERR_NOORIGIN          = "409"
	ERR_NOPRIVILEGES      = "481"
	ERR_NORECIPIENT       = "411"
	ERR_NOSUCHNICK        = "401"
	ERR_NOSUCHSERVER      = "402"
	ERR_NOTEXTTOSEND      = "412"
	ERR_NOTONCHANNEL      = "442"
	ERR_NOTOPLEVEL        = "413"
	ERR_RESTRICTED        = "484"
	ERR_UNKNOWNMODE       = "472"
	ERR_WILDTOPLEVEL      = "414"

	// Custom numerics
	RPL_HELPSTART     = "704" // Sent at start of HELP response
	RPL_HELPTXT       = "705" // Sent for lines of HELP response
	RPL_ENDOFHELP     = "706" // Sent at end of HELP response
	RPL_STATSMEMMEM   = "710" // STATS reply for "mem" - Memory statistics
	RPL_STATSMEMHEAP  = "711" // STATS reply for "mem" - Heap statistics
	RPL_STATSMEMRTIME = "712" // STATS reply for "mem" - Runtime statistics

	// Custom errors
	ERR_BANONCHAN   = "435" // Cannot change nickname while banned on channel
	ERR_UNKNOWNSTAT = "910" // STATS error for unknown STAT request
View Source
const MODE_ARG = 2 // Modes that can be set with an argument or removed without one
View Source
const MODE_CHOP = 4 // Chanel operator modes
View Source
const MODE_FLAG = 3 // Modes can only be set and unset (the only type without an argument)
View Source
const MODE_INVAL = -1
View Source
const MODE_KEY = 1 // Modes that require the same argument to remove them as was used to set
View Source
const MODE_LIST = 0 // Mode contains a list of arguments that can be added to and removed from
View Source
const MODE_USER = 5 // Modes which are valid user modes


View Source
var AllowHopClearModes = AllowHopSetModes + "b"
View Source
var AllowHopSetModes = "eI" + "kl" + "imnpstq" + "hv"
View Source
var Commands = map[string]CommandHook{
	CMD_AWAY:      {client_away, 0, false, true, false},
	CMD_CLEARCHAN: {client_clearchan, 1, true, true, false},
	CMD_CLEAROPS:  {client_clearops, 1, true, true, false},
	CMD_DIE:       {client_die, 1, true, true, false},
	CMD_HELP:      {client_help, 0, false, true, true},
	CMD_INVITE:    {client_invite, 2, false, true, false},
	CMD_JOIN:      {client_join, 1, false, true, false},
	CMD_KICK:      {client_kick, 2, false, true, false},
	CMD_KILL:      {client_kill, 2, true, true, false},
	CMD_LIST:      {client_list, 0, false, true, false},
	CMD_MODE:      {client_mode, 1, false, true, false},
	CMD_NAMES:     {client_names, 0, false, true, false},
	CMD_NICK:      {client_register, 1, false, true, true},
	CMD_NOTICE:    {client_notice, 0, false, true, true},
	CMD_OJOIN:     {client_ojoin, 1, true, true, false},
	CMD_OPER:      {client_oper, 2, false, true, false},
	CMD_OPME:      {client_clearops, 1, true, true, false},
	CMD_PART:      {client_part, 1, false, true, false},
	CMD_PASS:      {client_register, 1, false, false, true},
	CMD_PING:      {client_ping, 1, false, true, false},
	CMD_PRIVMSG:   {client_privmsg, 2, false, true, false},
	CMD_QUIT:      {client_quit, 0, false, true, false},
	CMD_STATS:     {client_stats, 1, false, true, false},
	CMD_SQUIT:     {client_noop, 0, false, true, false},
	CMD_TOPIC:     {client_topic, 1, false, true, false},
	CMD_USER:      {client_register, 4, false, false, true},
	CMD_WALLOPS:   {client_wallops, 1, true, true, false},
	CMD_WHO:       {client_who, 0, false, true, false},
	CMD_WHOIS:     {client_whois, 1, false, true, false},
View Source
var Help = map[string]CommandHelp{
	CMD_CLEARCHAN: CommandHelp{
		Summary: "Close a channel (PART all users) and join as the first op",
		Usage:   []string{"<#channel>"},
		Help: `The CLEARCHAN command will force all users out of a channel by issuing PART
commands.  The operator issuing the command will then immediately join the
empty channel and become the channel op.`,
		Operator: true,
	CMD_CLEAROPS: CommandHelp{
		Summary: "Remove all channel ops on a channel and become a channel op",
		Usage:   []string{"<#channel>"},
		Help: `The CLEAROPS (also OPME) command will remove channel operator and halfoperator
status from all users on a channel and give channel operator status to the
issuing operator.`,
		Operator: true,
	CMD_HELP: CommandHelp{
		Summary: "Request help on commands supported by this IRCd",
		Usage:   []string{"", "<command>", "<searchmask>"},
		Help: `The HELP command can do three things:
1. It can list all commands understood by the IRCd, if executed with no parameters.
2. It can give you the detailed help (including summary, usage, and detail) on a
   particular command if executed with a parameter containing no *s.
3. It can list all of the commands that match a given mask, and report their summaries,
   if executed with a parameter containing one or more *s.`,
		Unreg: true,
	CMD_INVITE: CommandHelp{
		Summary: "Invite a user into a channel",
		Usage:   []string{"<nick> <#channel>"},
		Help: `The INVITE command allows a user (who must be an operator or halfoperator on
the channel if the channel has mode +i) to invite another user into a channel.
When a user has been invited to a channel, they may join regardless of keys
(+k), limits (+l), bans (+b), or invitation-only (+i) channel modes.`,
	CMD_JOIN: CommandHelp{
		Summary: "Join a channel",
		Usage:   []string{"<#channel>[,<#channel[,...]] [<key>[,<key>[,...]]]"},
		Help: `The JOIN command requests that a user be added to a channel.  More than one
channel may be joined in a single command with a comma-separated list.
Channels with a key (+k) require that the <key> argument be specified.  Each
key in the comma-separated list of keys is associated with the corresponding
channel in the list of channels.  If the list of channels is longer than the
list of keys, no key is used to join the later channels in the list.  If the
joining user is the first user on a channel, the user will gain channel
operator (+o) mode upon joining.`,
	CMD_KICK: CommandHelp{
		Summary: "Remove a client from a channel",
		Usage:   []string{"<#channel> <nick> [:<reason>]", "<#channel> <nick>,<nick>[,...] [:<reason>]", "<#channel>,<#channel>[,...] <nick>,<nick>[,...] [:<reason>]"},
		Help: `The KICK command allows a channel operator to remove any client in the
channel.  If the <reason> is provided, it will be included in the KICK
notification to both the client and other users on the channel.  A channel
halfoperator may also KICK any user except a channel operator.  Multiple kicks
can be issued in the same command for a single channel and multiple
comma-separated nicks or for multiple channels by providing the same number of
channels as nicks.`,
	CMD_KILL: CommandHelp{
		Summary: "Disconnect a client from the server",
		Usage:   []string{"<nick> :<reason>"},
		Help: `The KILL command allows the operator to cause the server to disconnect a
client.  A reason for doing so must be provided, and this is sent to the user
being KILLed as well as being reflected (along with the nickname of the KILLing
operator) in the QUIT message of the disconnecting client.`,
		Operator: true,
	CMD_LIST: CommandHelp{
		Summary: "List channels and their topics",
		Usage:   []string{"", "<#channel>[,<#channel>[,...]]"},
		Help: `The LIST command does one of the following:
1. Lists all channels known to the server (if no channels are provided)
2. Lists the channels specified (if a comma-separated list of channels is provided)

For each channel listed, the name of the channel, the number of visible users
on the channel, and the topic of the channel are displayed.`,
	CMD_MODE: CommandHelp{
		Summary: "Modify user or channel modes",
		Usage:   []string{"(<nick>|<#channel>)", "<nick> (+|-)<modes>[(+|-)<modes>[...]]", "<#channel> [(+|-)]<modes>[(+|-)<modes>[...]] [<arg> [<arg> [...]]"},
		Help: `In the first usage above, USER modes are modified.  In the second usage,
CHANNEL modes are modified.  See the corresponding sections below.

Using the format above without any mode changes (e.g. only a <nick> or a
<#channel>) causes the server to report the modes of the given nick (only if it
is yours) or channel.

All mode changes follow the same basic format.  The string is processed from
left to right.  If any modes are found before a '+' or a '-' is found, that
mode is queried.  Querying only applies to list modes (see CHANNEL MODES
below).  If any other mode is queried, it is as if the mode were prefixed with
a '+'.  Any mode after a '+' or a '-' is added (if '+') or removed (if '-')
from the USER or CHANNEL.  If the mode requires an argument (see CHANNEL MODES
below), the argument for that mode is included in a space-separated list of
arguments after the full mode string.  The list of arguments must match the
ordering of the list of modes in the mode string which require arguments.

The following modes are recognized:
   +i      User is invisible (set by default)
   +o      User is an OPER (cannot be set, only unset)
   +w      User receives WALLOPS (set automatically for operators)
   +Z      User is connected via SSL (set by server only)

It is invalid to attempt to change or view the mode of another user.  Only the
user modes +i, +r, and +w may be set by a user.  The OPER command is used to
set the +o mode, though it may be unset (deopered) via the MODE command.

The following modes are recognized:
   Status Modes (Give status to user with +, remove with -)
   +o <nick>    Operator     User is a channel operator (prefix: @)
   +h <nick>    Halfop       User is a channel halfoperator (prefix: %)
   +v <nick>    Voice        User may speak if Moderated or Banned (prefix: +)
   Flag Modes (No arguments required)
   +i           Invite-only  Users must be INVITEd to JOIN (only [h]ops can INVITE)
   +m           Moderated    Users must have +v, +o, or +h to speak
   +n           Nobody-else  Only users on the channel may speak (default)
   +p           Private      Does not show up on WHOIS
   +s           Secret       Does not show up on LIST
   +t           Topic-ops    Only users with +o or +h may set TOPIC (default)
   +q           Quiet        No JOINs or PARTs or NICKs are sent to channel
   List Modes (Add to list with +, remove from list using -)
   +b <mask>    Ban          Users matching <mask> may not JOIN or speak
   +e <mask>    Exban        Users matching <mask> are excepted from +b
   +I <mask>    Invex        Users matching <mask> do not need an INVITE to join
   Key Modes (Same argument used to set mode required to remove it)
   +k <key>     Key          Users JOINing must provide <key>
   Limit Modes (Argument only required to set mode, not to remove it)
   +l <#>       Limit        No more than # users may JOIN the channel

Only channel operators and halfoperators may set modes.  Channel halfoperators
may set all modes except +b and +o and may remove all modes except +o.  List
modes may (as stated above) be queried by issuing a mode change with no + or -.
In order to remove an entry from a List Mode or to remove a Key Mode, the
opposite mode change including the exact text of the List item or Key Mode must
be made.  Limit modes do not require an argument to unset.  Users may have
multiple statuses, however only one will be reported in NAMES (the highest one).`,
	CMD_NAMES: CommandHelp{
		Summary: "Get a list of users on a channel",
		Usage:   []string{"<#channel>[,<#channel[,...]]"},
		Help: `The NAMES command sends back a series of replies listing the users who have
JOINed the channel(s) specified.  Each nick is optionally prefixed by a
character indicating the user's highest status mode on the channel.  See HELP
MODE for prefixes.`,
	CMD_NICK: CommandHelp{
		Summary: "Set or change your IRC Nickname",
		Usage:   []string{"<nick>"},
		Help: `This command must be sent (along with USER) to register a client connection with the server.
After registration, this command is also used to change the client's nickname.  If the nickname
is already in use, an error will be returned.`,
		Unreg: true,
	CMD_NOTICE: CommandHelp{
		Summary: "Send a NOTICE to a user or channel",
		Usage:   []string{"(<nick>|<#channel>)[,...] :<message>"},
		Help: `A NOTICE differs from a PRIVMSG only that it should never be responded to
automatically.  No error messages will be returned for sending to an invalid
nick or when the message cannot be delivered to a channel, and bots and
services should not respond to NOTICE messages.`,
	CMD_OJOIN: CommandHelp{
		Summary: "Join a channel regardless of modes and become a channel operator",
		Usage:   []string{"<#channel>"},
		Help: `The OJOIN command allows the issuing operator to JOIN a channel regardless of
bans, limits, invite-only modes etc.  Upon joining the channel, the operator
automatically becomes a channel operator.`,
		Operator: true,
	CMD_OPER: CommandHelp{
		Summary: "Request IRC Operator status",
		Usage:   []string{"<o:line> <password>"},
		Help: `The OPER command is used to register with the server as an IRC Operator.  If
the user's host and the provided password match the requested O:line, the user
is given the +o usermode and becomes an IRC Operator.`,
	CMD_OPME: CommandHelp{
		Summary:  "Alias for CLEAROPS",
		Operator: true,
	CMD_PART: CommandHelp{
		Summary: "Leave channels you have JOINed",
		Usage:   []string{"<#channel>[,<#channel>[,...]] [:<reason>]"},
		Help: `The PART command removes you from the channel(s) specified, providing the
given <reason> (if any) for your departure.`,
	CMD_PASS: CommandHelp{
		Summary: "Specify a password for connecting",
		Usage:   []string{"<password>"},
		Help: `The PASS command is only legal before registration (NICK/USER) is complete.
It is used to register servers and is one criterion for client connection
class matching upon registration.`,
	CMD_PING: CommandHelp{
		Summary: "Check if the server is responding",
		Usage:   []string{"<text>"},
		Help:    `The server, upon receipt of a PING command, will respond with the same <text>.`,
	CMD_PRIVMSG: CommandHelp{
		Summary: "Deliver a message to a user or channel",
		Usage:   []string{"(<nick>|<#channel>)[,...] :<message>"},
		Help: `The PRIVMSG command delivers the <message> to the nick(s) and/or channel(s)
specified.  The list of destinations for the message is comma-separated, and
delivery to each destination is not conditional on successful delivery to any
other.  In general, a user must be on a channel in order to be able to send
messages to it (the +n channel mode).`,
	CMD_QUIT: CommandHelp{
		Summary: "Disconnect from the server",
		Usage:   []string{"[:<reason>]"},
		Help: `The QUIT command notifies all channels you are in that you have left IRC
and provides the given <reason> (if any) for your departure.  The server will
then close your connection when your unregistration is compelete.`,
	CMD_STATS: CommandHelp{
		Summary: "Request server STATisticS",
		Usage:   []string{"<type>[,<type>[,...]]"},
		Help: `The following statistics are supported:
   p   opers      Get a list of staff members currently signed onto IRC
   P   ports      Get a list of active ports on the server
   M   mem        Get a memory usage readout
   o   olines     Get a list of O:lines (operators only)
   l   links      Get a list of server links (operators only)

The single-character requests are for backward-compatibility with other IRC
daemons.  Each request will generate a list of numeric replies containing the
data requested.  If multiple <type>s are given, the response will be as if
multiple STATS commands were issued, one for each <type>.`,
	CMD_TOPIC: CommandHelp{
		Summary: "Request or change a channel discussion topic",
		Usage:   []string{"", ":<topic>"},
		Help: `The TOPIC command is used to request (in the first instance) or set (in the
second instance) the topic of discussion on a given channel.  If the channel
has mode +t set, only a channel operator or halfoperator can set the topic,
otherwise any member of the channel may do so.`,
	CMD_USER: CommandHelp{
		Summary: "Register as the given user and real name",
		Usage:   []string{"<user> . . :<real name>"},
		Help: `The USER command, along with the NICK command, completes a client's
registration with the server.  The second and third argument are ignored.  The
<user> and <real name> may not be changed once registration is complete.`,
	CMD_WALLOPS: CommandHelp{
		Summary: "Write a message to ALL OPeratorS",
		Usage:   []string{":<message>"},
		Help: `The WALLOPS command delivers a message to all users with user mode +w.
Operators get this user mode by default when they oper up, but any user may set
the mode and receive these messages, so be careful what information you include.`,
	CMD_WHO: CommandHelp{
		Summary: "Get a detailed list of users on a channel",
		Usage:   []string{"<#channel>[,<#channel>[,...]]"},
		Help: `The WHO command lists detailed infomation, including the username, hostname,
away status, channel status prefix, and real name of each user on a channel.`,
	CMD_WHOIS: CommandHelp{
		Summary: "Get detailed user information",
		Usage:   []string{"<nick>[,<nick>[,...]]"},
		Help: `The WHOIS command lists detailed infomation, including the username, hostname,
away status, channel membership, and real name of each user specified.  If the
user is connected securely or is an operator, these will also be reflected in
the WHOIS output.`,
View Source
var ModePrefixList = []string{"ohv", "@%+"}
View Source
var ModeTypeList = []string{"beI", "k", "l", "imnpstq"}
View Source
var ModeUserClear = "iow"
View Source
var ModeUserList = "iowZ"
View Source
var ModeUserSet = "iw"


func GlobMatch

func GlobMatch(pat, candidate string) bool

TODO: Should both be run through irctolower?

func IsModeType

func IsModeType(m int, t ModeType) bool

func SHA1

func SHA1(str string) string


type CEInfo

type CEInfo struct {
	Client                                            *Client
	All                                               bool
	Reply                                             chan bool
	Oper, Secure                                      bool
	Nick, User, Host, Name, Modes, Addr, Away, Server string
	Channels                                          []string

type CEJoin

type CEJoin struct {
	Channel *Channel
	Reply   chan bool

type CEMessage

type CEMessage struct {
	Message *ClientMessage
	Reply   chan bool

Client Events (CE)

type CEPart

type CEPart struct {
	Channel *Channel
	Reply   chan bool

type CEWallops

type CEWallops struct {
	Source  Name
	Message string
	Reply   chan bool

type CHApplyModes

type CHApplyModes struct {
	Client  *Client
	Changes []*ModeChange
	Reply   chan bool

type CHClearOps

type CHClearOps struct {
	Source *Client
	Reply  chan bool

type CHGetPeers

type CHGetPeers struct {
	Client *Client
	Reply  chan bool
	Peers  []*Client

type CHInvite

type CHInvite struct {
	Client   *Client
	Invitees []*Client
	Reply    chan bool

type CHIsBanned

type CHIsBanned struct {
	Client *Client
	Reply  chan bool

type CHJoin

type CHJoin struct {
	Client *Client
	Key    string
	Reply  chan bool

Channel Events (CH)

type CHKick

type CHKick struct {
	Kicker  *Client
	Victims []*Client
	Reason  string
	Reply   chan bool

type CHList

type CHList struct {
	Client *Client
	Reply  chan bool

type CHOJoin

type CHOJoin struct {
	Client *Client
	Reply  chan bool

type CHPart

type CHPart struct {
	Client *Client
	Reply  chan bool
	Notify []*Client

type CHPrefix

type CHPrefix struct {
	Requestor, User *Client
	All             bool
	Reply           chan bool
	Prefix          string

type CHQueryModes

type CHQueryModes struct {
	Client  *Client
	Queries []int
	Reply   chan bool

type CHSend

type CHSend struct {
	Client *Client
	Type   string
	Reply  chan bool

type CHSendMessage

type CHSendMessage struct {
	Client  *Client
	Message string
	Reply   chan bool

type CHSendNotice

type CHSendNotice struct {
	Client  *Client
	Message string
	Reply   chan bool

type CHSetTopic

type CHSetTopic struct {
	Client *Client
	Topic  string
	Reply  chan bool

type ChangeTime

type ChangeTime struct {
	By string
	At int64

type Channel

type Channel struct {
	Server *Server
	Events chan Event

	// General
	Name    string     // Name of the channel as defined by the first user
	Topic   string     // Channel topic
	TopicTS ChangeTime // Time/user that set the topic

	// Modes
	Flags    string                        // Active channel flags TODO
	KeyModes map[int]string                // Key-type modes TODO
	ArgModes map[int]string                // Limit-type modes TODO
	BanModes map[int]map[string]ChangeTime // Bans and timestamps TODO
	// contains filtered or unexported fields

func NewChannel

func NewChannel(srv *Server, name string) *Channel

func (*Channel) Close

func (chn *Channel) Close(force bool)

Should never be called in the coroutine of a user on this channel

func (*Channel) HasModeFlag

func (chn *Channel) HasModeFlag(mode int) bool

type ChannelPrivs

type ChannelPrivs string

func AddToPrivs

func AddToPrivs(priv ChannelPrivs, mode int) ChannelPrivs

func DelFromPrivs

func DelFromPrivs(priv ChannelPrivs, mode int) ChannelPrivs

func NewChannelPrivs

func NewChannelPrivs(privs string) ChannelPrivs

func (ChannelPrivs) Has

func (cus ChannelPrivs) Has(mode int) bool

func (ChannelPrivs) Prefix

func (cus ChannelPrivs) Prefix() string

type Client

type Client struct {
	Server *Server

	Events chan Event

	// General
	Nick string // Set to client's nickname
	User string // Set to client's username
	Addr string // Set to client's actual hostname
	Host string // Set to client's hostname
	Pass string // Set if a PASS is given
	Name string // GECOS/longname/description
	Oper string // Set if client OPER'd
	Away string // Set if user is away (unsynchronized)

	// Flags
	IsUser   bool
	IsServer bool
	IsClosed bool
	IsSSL    bool

	// Modes
	Modes ClientPrivs
	// contains filtered or unexported fields

This struct is the foundation of all of the client data stored by an IRC server or needed by a command

func NewClient

func NewClient(srv *Server, netconn net.Conn, port int) *Client

func (*Client) Close

func (cli *Client) Close(reason string, serverclose bool)

func (*Client) Invite

func (cli *Client) Invite(peer *Client, target string)

func (*Client) Join

func (cli *Client) Join(newmember *Client, channame string)

func (*Client) Kick

func (cli *Client) Kick(kicker *Client, channel, victim, reason string)

func (*Client) Kill

func (cli *Client) Kill(killer Name, victim, reason string)

func (*Client) LongName

func (cli *Client) LongName() string

func (*Client) Mode

func (cli *Client) Mode(sender Name, channel, newmodes string)

func (*Client) NickChange

func (cli *Client) NickChange(peer *Client, newnick string)

This breaks convention because it would conflict with the parameter

func (*Client) Notice

func (cli *Client) Notice(peer *Client, target, message string)

func (*Client) Numeric

func (cli *Client) Numeric(numeric string, args ...string)

func (*Client) Part

func (cli *Client) Part(oldpeer *Client, channel, message string)

func (*Client) Pong

func (cli *Client) Pong(source *Server, message string)

func (*Client) Privmsg

func (cli *Client) Privmsg(peer *Client, target, message string)

func (*Client) Quit

func (cli *Client) Quit(oldpeer *Client, message string)

func (*Client) RawNumeric

func (cli *Client) RawNumeric(numeric string, args ...string)

func (*Client) SendMode

func (cli *Client) SendMode()

func (*Client) ServerNotice

func (cli *Client) ServerNotice(source Name, message string)

func (*Client) ShortName

func (cli *Client) ShortName() string

func (*Client) Topic

func (cli *Client) Topic(peer *Client, target, topic string)

func (*Client) UMode

func (cli *Client) UMode(newmodes string)

func (*Client) Wallops

func (cli *Client) Wallops(source Name, message string)

type ClientMessage

type ClientMessage struct {
	Command string
	Args    []string

Generic client message

func ParseClient

func ParseClient(line string) (cm *ClientMessage, err os.Error)

Parse a message from a client into a ClientMessage

type ClientPrivs

type ClientPrivs string

func AddToClientPrivs

func AddToClientPrivs(priv ClientPrivs, mode int) ClientPrivs

func DelFromClientPrivs

func DelFromClientPrivs(priv ClientPrivs, mode int) ClientPrivs

func NewClientPrivs

func NewClientPrivs(privs string) ClientPrivs

func (ClientPrivs) Has

func (cus ClientPrivs) Has(mode int) bool

func (ClientPrivs) String

func (cus ClientPrivs) String() string

type CommandHelp

type CommandHelp struct {
	Summary  string   // A single-line sumamry of the command
	Usage    []string // A list of possible argument combinations (do not include the command)
	Help     string   // A multi-line string with detailed help information
	Operator bool     // Show this command to Operators only
	Unreg    bool     // Show this command to unregistered users

Store the help information for a particular command

type CommandHook

type CommandHook struct {
	HookFunc    func(cli *Client, srv *Server, message *ClientMessage)
	MinArgCount int  // Minimum arguments to call with
	RequireOper bool // Require Operator Privileges?
	AllowReg    bool // Allowed from registered users?
	AllowUnreg  bool // Allowed from unregistered?

type Config

type Config struct {
	Filename string
	Object   *conf.ConfigFile

func ReadConfig

func ReadConfig(file string) (cfg *Config, err os.Error)

Read the configuration from the specified file

func (*Config) Get

func (cfg *Config) Get(section, option string) string

Get a string from the configuration file

func (*Config) GetIfDefined

func (cfg *Config) GetIfDefined(section, option, dflt string) string

Get a string from the configuration file or the given default

func (*Config) GetMatchingSections

func (cfg *Config) GetMatchingSections(pattern string) (secs []*ConfigSection)

Get a sorted list of sections that match a given pattern

func (*Config) GetSection

func (cfg *Config) GetSection(section string) (sec *ConfigSection)

Get a wrapper for the specified section. If it does not exist, the err value will be set, but the wrapper will still be provided.

func (*Config) GetSections

func (cfg *Config) GetSections() (secs []*ConfigSection)

Get a sorted list of sections

func (*Config) Has

func (cfg *Config) Has(section, option string) bool

Get whether the option is set or not

func (*Config) HasSection

func (cfg *Config) HasSection(section string) bool

Get a wrapper for the specified section. If it does not exist, the err value will be set, but the wrapper will still be provided.

func (*Config) Rehash

func (cfg *Config) Rehash() (err os.Error)

Reread the configuration file (can only be from the original filename). Only if the configuration is successfully read will the Config object reflect the file's new contents

func (*Config) Require

func (cfg *Config) Require(section, option string) string

Exit the application if the given option is not specified

func (*Config) RequireSection

func (cfg *Config) RequireSection(section string) *ConfigSection

Exit the application if the given section is not specified

type ConfigSection

type ConfigSection struct {
	Name string
	// contains filtered or unexported fields

func (*ConfigSection) Get

func (sec *ConfigSection) Get(option string) string

func (*ConfigSection) GetIfDefined

func (sec *ConfigSection) GetIfDefined(option, dflt string) string

func (*ConfigSection) Has

func (sec *ConfigSection) Has(option string) bool

func (*ConfigSection) Require

func (sec *ConfigSection) Require(option string) string

type Event

type Event interface{}

This type represents an event within the IRC server. When passed, an event handler is expected to do a typeswitch to get the actual type. Most event types should have a Reply chan bool, on which a single boolean success value should be sent in order to indicate completion. These should always be sent over the channel as a POINTER TO THE EVENT.

type Lock

type Lock struct {
	Critical chan Event
	Reply    chan bool

The following event causes an event loop to ener a critical section. The Critical member will be set by the client, and after sending the event it can be used by the client to execute events exclusively. To exit the critical section, the client must close Critical. Be very careful using this, as it has the potential to deadlock the receiving event loop. The reply channel is notified by sending a boolean value TWICE, once on entering (true) and once on exiting (false) of the critical section.

type Mode

type Mode struct {
	Char  int
	Type  ModeType
	Value string

func (*Mode) IsType

func (m *Mode) IsType(t ModeType) bool

type ModeChange

type ModeChange struct {
	Plus bool  // true for +, false for -
	Mode *Mode // The mode that is being changed

func ParseModeChange

func ParseModeChange(modestr string, args ...string) (mc []*ModeChange, query, bad []int)

Parse a channel mode change

func ParseUserModeChange

func ParseUserModeChange(modestr string, args ...string) (mc []*ModeChange, bad []int)

func (*ModeChange) String

func (mc *ModeChange) String() string

type ModeType

type ModeType int

func GetModeType

func GetModeType(mode int) ModeType

type Name

type Name interface {
	ShortName() string
	LongName() string

Name interface for things that can be either a client or a server

type PortRecord

type PortRecord struct {
	Clients int
	Pseudo  bool
	SSL     bool

type PseudoAddr

type PseudoAddr struct {
	// contains filtered or unexported fields

func NewPseudoAddr

func NewPseudoAddr(id int) *PseudoAddr

func (*PseudoAddr) Network

func (pa *PseudoAddr) Network() string

func (*PseudoAddr) String

func (pa *PseudoAddr) String() string

type PseudoClients

type PseudoClients struct {
	Server *Server
	// contains filtered or unexported fields

func NewPseudoClients

func NewPseudoClients(server *Server, clients int, chancounts []string) *PseudoClients

type PseudoConn

type PseudoConn struct {
	// contains filtered or unexported fields

func (*PseudoConn) Close

func (pc *PseudoConn) Close() (err os.Error)

func (*PseudoConn) LocalAddr

func (pc *PseudoConn) LocalAddr() net.Addr

func (*PseudoConn) Read

func (pc *PseudoConn) Read(b []byte) (n int, err os.Error)

adhere to the net.Conn interface

func (*PseudoConn) RemoteAddr

func (pc *PseudoConn) RemoteAddr() net.Addr

func (*PseudoConn) SetReadTimeout

func (pc *PseudoConn) SetReadTimeout(int64) os.Error

func (*PseudoConn) SetTimeout

func (pc *PseudoConn) SetTimeout(int64) os.Error

These don't do anything

func (*PseudoConn) SetWriteTimeout

func (pc *PseudoConn) SetWriteTimeout(int64) os.Error

func (*PseudoConn) Write

func (pc *PseudoConn) Write(b []byte) (n int, err os.Error)

type SEChanList

type SEChanList struct {
	Client   *Client
	Channels []string

type SEClearChan

type SEClearChan struct {
	Source  *Client
	Channel string

type SEDelChan

type SEDelChan struct {
	Channel *Channel
	Reply   chan bool

type SEDie

type SEDie struct {
	Source *Client
	Reason string

type SEGetChan

type SEGetChan struct {
	Name    string
	Reply   chan bool
	Channel *Channel

type SEGetClient

type SEGetClient struct {
	Name   string
	Reply  chan bool
	Client *Client

type SEGetPeers

type SEGetPeers struct {
	Client  *Client
	Target  string
	Reply   chan bool
	Peers   map[*Client]bool
	Nick    *Client
	Channel *Channel

type SEInvite

type SEInvite struct {
	Client   *Client
	Nicks    []string
	Channels []string

type SEKick

type SEKick struct {
	Kicker   *Client
	Victims  []string
	Channels []string
	Reason   string

type SEKill

type SEKill struct {
	Source *Client
	Victim string
	Reason string

type SEMode

type SEMode struct {
	Client  *Client
	Channel string
	Queries []int
	Changes []*ModeChange

type SENewChan

type SENewChan struct {
	Name    string
	Reply   chan bool
	Channel *Channel

type SEOJoin

type SEOJoin struct {
	Source  *Client
	Channel string

type SEOperList

type SEOperList struct {
	Reply chan bool
	Opers []*Client

type SEOperNotify

type SEOperNotify struct {
	Source  Name
	Message string

type SEPing

type SEPing struct {
	Destination, Message string
	Client               *Client


type SERegister

type SERegister struct {
	Client *Client
	Nick   string
	Reply  chan bool

Server Events (SE)

type SEReregister

type SEReregister struct {
	Client   *Client
	Old, New string
	Reply    chan bool

type SETopic

type SETopic struct {
	Client  *Client
	Channel string
	Query   bool
	Topic   string

type SEUMode

type SEUMode struct {
	Client  *Client
	User    string
	Changes []*ModeChange

type SEUnregister

type SEUnregister struct {
	Client *Client
	Reason string
	Reply  chan bool

type SEWallops

type SEWallops struct {
	Source  Name
	Message string

type SEWhois

type SEWhois struct {
	Client *Client
	Nick   string

type Server

type Server struct {
	/// Server data
	// The name of the server (e.g., its network, and software version
	Name    string
	Network string
	Version string
	Created string
	Motd    string

	/// Data
	Ports map[int]*PortRecord

	/// Channels
	Events chan Event

	/// Configuration
	Config *Config // do NOT call rehash outside of SERehash event
	// contains filtered or unexported fields

This struct is the foundation of the server architecture, maintaining all of the data necessary to maintain and accept clients and to pass messages to and from the rest of the software

func NewServer

func NewServer(configfile, version, created string) *Server

Create a new server

func (*Server) Listen

func (srv *Server) Listen(port int) os.Error

Listen on the given port. This function is NOT thread safe and should only be called from within the primary goroutine. TODO: Add the ability to listen on an address and a port

func (*Server) ListenSSL

func (srv *Server) ListenSSL(port int) os.Error

Listen on the given port. This function is NOT thread safe and should only be called from within the primary goroutine. TODO: Add the ability to listen on an address and a port TODO: Make the certificates configurable

func (*Server) LongName

func (srv *Server) LongName() string

func (*Server) Run

func (srv *Server) Run()

The Run() function causes the program to go into a signal wait loop, returning when a SIGINT is received and forcing a stop when TSTP is received. It is recommended that all applications utilizing the server functionality of this package call Run() when the main() is finished with setup. This function will return when a SIGINT or SIGQUIT is received.

func (*Server) ShortName

func (srv *Server) ShortName() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL