ircproxy  The Ultimate Cyborg

Channel Class Reference

#include <Channel.h>

Inheritance diagram for Channel:

Target IdentityReference

List of all members.


Detailed Description

An IRC Channel.

Definition at line 35 of file Channel.h.


Public Types

typedef std::map< std::string,
Member
members_type
 The type returned by members().

Public Member Functions

 Channel (Identity &identity, std::string const &target_name, Network &private_network, int)
 Construct a Channel instance for identity identity with name target_name on private network private_network.
 ~Channel ()
 Destructor.
virtual void new_client_message_received (ClientMessageIn const &msg)
 Received a channel message.
virtual void new_server_message_received (ServerMessageIn const &msg)
 Received a channel message.
members_typemembers (void)
 Accessor to the members map.
members_type const & members (void) const
 Accessor to the members map.
void set_received_names (void)
 This is called when the first end of NAMES (numeric 366) is being received.
void reset_received_names (void)
 This is called when a channel is rejoined after a reconnect.
void set_creation_time (time_t creation_time)
 This is called when numeric 329 is being received.
bool received_names (void) const
 Return true if the first end of NAMES (numeric 366) has been received.
time_t creation_time (void) const
 Return the creation time of the channel, or 0 when not known.
bool has_key (void) const
 Returns true if Channel::key is valid.
std::string const & key (void) const
 Returns the last channel key that was seen.

Private Member Functions

 Channel (Identity &identity, std::string const &target_name, Network &network)
 Construct a Channel instance for identity identity with name target_name on network network.

Private Attributes

members_type M_members
 The members on this channel.
bool M_received_names
 True if we received the NAMES reply after joining.
time_t M_creation_time
 The time as received from numeric 329, or 0 if nothing was received (yet).
std::string M_key
 Last known channel key, if any.

Member Typedef Documentation

typedef std::map<std::string, Member> Channel::members_type

The type returned by members().

Definition at line 38 of file Channel.h.


Constructor & Destructor Documentation

Channel::Channel ( Identity identity,
std::string const &  target_name,
Network network 
) [inline, private]

Construct a Channel instance for identity identity with name target_name on network network.

Definition at line 50 of file Channel.h.

References ASSERT, Network::is_private(), and debug::channels::dc::objects.

00050                                                                               :
00051       Target(&network), IdentityReference(&identity),
00052       M_received_names(false), M_creation_time(0)
00053       {
00054         ASSERT(!network.is_private());
00055         Dout(dc::objects, "Constructing Channel(" << identity << ", \"" << target_name << "\", " << network << ") " << static_cast<IdentityReference&>(*this));
00056       }
public:

Channel::Channel ( Identity identity,
std::string const &  target_name,
Network private_network,
int   
) [inline]

Construct a Channel instance for identity identity with name target_name on private network private_network.

Definition at line 59 of file Channel.h.

References ASSERT, Network::is_private(), and debug::channels::dc::objects.

00059                                                                                            :
00060       Target(&private_network), IdentityReference(&identity),
00061       M_received_names(true), M_creation_time(0)
00062       {
00063         ASSERT(private_network.is_private());
00064         Dout(dc::objects, "Constructing private Channel(" << identity << ", \"" << target_name << "\", " << private_network << ") " <<
00065             static_cast<IdentityReference&>(*this));
00066       }
#ifdef CWDEBUG

Channel::~Channel (  )  [inline]

Destructor.

Definition at line 69 of file Channel.h.

00069 { Dout(dc::objects, "Destructing Channel " << *this); }


Member Function Documentation

void Channel::new_client_message_received ( ClientMessageIn const &  msg  )  [virtual]

Received a channel message.

Implements Target.

Definition at line 31 of file Channel.cc.

References ASSERT, Identity::client_session(), ClientMessageIn::client_session(), default_priority(), DoutEntering, Prefix::empty(), Prefix::get_nick(), IdentityReference::identity(), ClientSession::joined_channels(), MessageIn::key(), MessageIn::param(), MessageIn::params(), ServerSession::queue_msg(), and Identity::server_session().

00032 {
00033   DoutEntering(dc::debug, "Channel::new_client_message_received(" << msg << ") for target \"" << in_name(msg.client_session()) << "\".");
00034 
00035   using namespace keys;
00036 
00037   switch (msg.key())
00038   {
00039     case JOIN:
00040     {
00041       Prefix prefix(msg);
00042       ASSERT(prefix.empty() || prefix.get_nick()->is_me());
00043       ClientSession::joined_channels_type::iterator iter = identity().client_session().joined_channels().find(msg.param(0));
00044       if (iter == identity().client_session().joined_channels().end())
00045       {
00046         // Pass the JOIN on as-is for unknown channel.
00047         MessageOut msgout(default_priority(msg.key()));
00048         identity().server_session().queue_msg(msgout << prefix << msg.key() << msg.params(0));
00049       }
00050       else
00051         Dout(dc::warning, "Ignoring a JOIN for a channel that we are already on.");
00052       break;
00053     }
00054     case MODE:
00055     case PRIVMSG:
00056     case NOTICE:
00057     case PART:
00058     case CPRIVMSG:
00059     case CNOTICE:
00060     case KICK:
00061     case NAMES:
00062     case TOPIC:
00063     {
00064       // FIXME.
00065       // For now, just pass it to the server as-is.
00066 
00067       // Extract the prefix of the input message.
00068       Prefix prefix(msg);
00069       // Construct a message with default priority.
00070       MessageOut msgout(default_priority(msg.key()));
00071       // Pass the message to the server.
00072       identity().server_session().queue_msg(msgout << prefix << msg.key() << msg.params(0));
00073       break;
00074     }
00075   }
00076 }

void Channel::new_server_message_received ( ServerMessageIn const &  msg  )  [virtual]

Received a channel message.

Implements Target.

Definition at line 82 of file Channel.cc.

References Target::add_joined_nick(), edragon::caught(), Identity::client_session(), default_priority(), DoutEntering, Target::get_joined_nick(), Prefix::get_nick(), IdentityReference::identity(), MessageIn::key(), MessageIn::param(), MessageIn::params(), MessageIn::prefix_str(), ServerSession::queue_msg(), ClientSession::queue_msg(), Identity::server_session(), ServerMessageIn::server_session(), Target::serverside_get_channel(), and Target::sub_channel().

00083 {
00084   DoutEntering(dc::debug, "Channel::new_server_message_received(" << msg << ") for target \"" << in_name(msg.server_session()) << "\".");
00085 
00086   using namespace keys;
00087 
00088   switch (msg.key())
00089   {
00090     case PART:
00091     {
00092       Prefix prefix(msg);
00093       boost::shared_ptr<Nick> nick(prefix.get_nick());
00094       MessageOut msgout(default_priority(msg.key()));
00095       identity().client_session().queue_msg(msgout << prefix << msg.key() << msg.params(0));
00096       if (nick->is_me())
00097         sub_channel(identity());
00098       else
00099         sub_joined_nick(nick);
00100       break;
00101     }
00102     case JOIN:
00103     {
00104       Prefix prefix(msg);
00105       boost::shared_ptr<Nick> nick(prefix.get_nick());
00106       boost::shared_ptr<Channel> channel = Target::serverside_get_channel(identity(), msg.param(0), false);
00107       MessageOut msgout(default_priority(msg.key()));
00108       identity().client_session().queue_msg(msgout << prefix << msg.key() << channel);
00109       Target::add_joined_nick(identity(), nick->in_name(msg.server_session()), channel);
00110       break;
00111     }
00112     case KICK:
00113     {
00114       Prefix prefix(msg);
00115       boost::shared_ptr<Channel> channel = Target::serverside_get_channel(identity(), msg.param(0), false);
00116       boost::shared_ptr<Nick> nick = Target::get_joined_nick(identity(), msg.param(1), channel);
00117       MessageOut msgout(default_priority(msg.key()));
00118       identity().client_session().queue_msg(msgout << prefix << msg.key() << channel << nick << msg.params(2));
00119       if (nick->is_me())
00120         sub_channel(identity());
00121       else
00122         sub_joined_nick(nick);
00123       break;
00124     }
00125     case PRIVMSG:
00126     {
00127       std::string prefix(msg.prefix_str());
00128       std::string::size_type pos = prefix.find('!');
00129       std::string text(msg.param(1));
00130       if (pos != std::string::npos)
00131       {
00132         ++pos;
00133         if (prefix[pos] == '~')
00134           ++pos;
00135       }
00136       if (pos != std::string::npos &&
00137           (prefix.substr(pos) == "carlo@10.11.0.4" || prefix.substr(pos) == "carlo@terp.frl" || prefix.substr(pos) == "carlo@aleric.users.undernet.org") &&
00138           text[0] == '!')
00139       {
00140         std::string::size_type command_end = text.find(' ');
00141         std::string argument;
00142         if (command_end != std::string::npos)
00143         {
00144           argument = text.substr(command_end + 1);
00145           --command_end;
00146         }
00147         std::string command = text.substr(1, command_end);
00148         boost::shared_ptr<Channel> channel = Target::serverside_get_channel(identity(), msg.param(0), false);
00149         MessageOut msgout(default_priority(PRIVMSG));
00150         if (command == "use_count")
00151         {
00152           if (!argument.empty())
00153           {
00154             try
00155             {
00156               boost::shared_ptr<Channel> channel2 = Target::serverside_get_channel(identity(), argument, false);
00157               identity().server_session().queue_msg(msgout << PRIVMSG << channel <<
00158                   ":channel2.use_count() =" << channel2.use_count());
00159             }
00160             catch (unknown_target& error)
00161             {
00162               Debug(edragon::caught(error));
00163               identity().server_session().queue_msg(msgout << PRIVMSG << channel << ":No such channel:" << argument);
00164             }
00165           }
00166           else
00167             identity().server_session().queue_msg(msgout << PRIVMSG << channel <<
00168                 ":channel.use_count() =" << channel.use_count());
00169         }
00170         else
00171         {
00172           identity().server_session().queue_msg(msgout << PRIVMSG << channel <<
00173               ":No such command: \"" << JustInTimeCatenate(command) << JustInTimeCatenate("\""));
00174         }
00175       }
00176       /* FALL_THROUGH */
00177     }
00178     case MODE:
00179     case NOTICE:
00180     case NAMES:
00181     case TOPIC:
00182     default:
00183     {
00184       Dout(dc::warning, "Unhandled channel message " << msg << ". Passing to client as-is.");
00185       // Pass to client as-is.
00186       Prefix prefix(msg);
00187       MessageOut msgout(default_priority(msg.key()));
00188       identity().client_session().queue_msg(msgout << prefix << msg.key() << msg.params(0));
00189     }
00190   }
00191 }

members_type& Channel::members ( void   )  [inline]

Accessor to the members map.

Definition at line 80 of file Channel.h.

References M_members.

Referenced by Target::sub_channel().

00080 { return M_members; }

members_type const& Channel::members ( void   )  const [inline]

Accessor to the members map.

Definition at line 82 of file Channel.h.

References M_members.

00082 { return M_members; }

void Channel::set_received_names ( void   )  [inline]

This is called when the first end of NAMES (numeric 366) is being received.

Definition at line 87 of file Channel.h.

References M_received_names.

00087 { M_received_names = true; }

void Channel::reset_received_names ( void   )  [inline]

This is called when a channel is rejoined after a reconnect.

Definition at line 90 of file Channel.h.

References M_received_names.

00090 { M_received_names = false; }

void Channel::set_creation_time ( time_t  creation_time  )  [inline]

This is called when numeric 329 is being received.

Definition at line 93 of file Channel.h.

References M_creation_time.

bool Channel::received_names ( void   )  const [inline]

Return true if the first end of NAMES (numeric 366) has been received.

Definition at line 96 of file Channel.h.

References M_received_names.

00096 { return M_received_names; }

time_t Channel::creation_time ( void   )  const [inline]

Return the creation time of the channel, or 0 when not known.

Definition at line 99 of file Channel.h.

References M_creation_time.

00099 { return M_creation_time; }

bool Channel::has_key ( void   )  const [inline]

Returns true if Channel::key is valid.

Definition at line 102 of file Channel.h.

References M_key.

00102 { return !M_key.empty(); }

std::string const& Channel::key ( void   )  const [inline]

Returns the last channel key that was seen.

Definition at line 105 of file Channel.h.

References M_key.

00105 { return M_key; }


Member Data Documentation

The members on this channel.

Definition at line 41 of file Channel.h.

Referenced by members().

bool Channel::M_received_names [private]

True if we received the NAMES reply after joining.

Definition at line 42 of file Channel.h.

Referenced by received_names(), reset_received_names(), and set_received_names().

time_t Channel::M_creation_time [private]

The time as received from numeric 329, or 0 if nothing was received (yet).

Definition at line 43 of file Channel.h.

Referenced by creation_time(), and set_creation_time().

std::string Channel::M_key [private]

Last known channel key, if any.

Definition at line 44 of file Channel.h.

Referenced by has_key(), and key().


The documentation for this class was generated from the following files:

Copyright © 2005-2007 Carlo Wood.  All rights reserved.