00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef USE_PCH
00017 #include "sys.h"
00018 #endif
00019
00020 #include "Channel.h"
00021 #include "MessageIn.h"
00022 #include "keys.h"
00023 #include "Identity.h"
00024 #include "ClientSession.h"
00025 #include "exceptions.h"
00026
00027
00028
00029
00030
00031 void Channel::new_client_message_received(ClientMessageIn const& msg)
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
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
00065
00066
00067
00068 Prefix prefix(msg);
00069
00070 MessageOut msgout(default_priority(msg.key()));
00071
00072 identity().server_session().queue_msg(msgout << prefix << msg.key() << msg.params(0));
00073 break;
00074 }
00075 }
00076 }
00077
00078
00079
00080
00081
00082 void Channel::new_server_message_received(ServerMessageIn const& msg)
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
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
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 }
00192
00193 void Channel::sub_joined_nick(boost::shared_ptr<Nick> nick)
00194 {
00195 #if 0 // FIXME
00196 DoutEntering(dc::maps|dc::debug, "Channel::sub_joined_nick(" << nick << ") for " << *this);
00197 nick->sub_channel(*this);
00198 Channel::members_type::iterator iter = M_members.find(nick->serverside_name());
00199 ASSERT(iter != M_members.end());
00200 Dout(dc::maps, "Erasing " << nick->serverside_name() << " from members of " << *this);
00201 M_members.erase(iter);
00202 #endif
00203 }