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 "Nick.h"
00021 #include "Identity.h"
00022 #include "Channel.h"
00023 #include "ClientSession.h"
00024 #include "ServerSession.h"
00025
00026 Nick::Nick(Identity& identity) : Target(&identity.private_network()), M_common_channels(0)
00027 {
00028 Dout(dc::objects, "Constructing my own Nick(" << identity << "\")");
00029 }
00030
00031 Nick::Nick(ClientSession const& client_session, std::string const& target_name, Network& private_network) :
00032 Target(&private_network), M_common_channels(0)
00033 {
00034 ASSERT(private_network.is_private());
00035 M_clientside_name[client_session] = target_name;
00036 Dout(dc::objects, "Constructing Nick(" << client_session << ", \"" << target_name << "\", " << private_network << ")");
00037 }
00038
00039 Nick::Nick(ServerSession const& server_session, std::string const& target_name) :
00040 Target(&server_session.server_connection().network()), M_common_channels(0)
00041 {
00042 M_serverside_name[server_session] = target_name;
00043 Dout(dc::objects, "Constructing Nick(" << server_session << ", \"" << target_name << "\")");
00044 }
00045
00046 void Nick::serverside_nick_changed_to(ServerSession const& server_session, std::string const& new_nick)
00047 {
00048 ASSERT(!debug::secondary_connection);
00049 DoutEntering(dc::debug, "Nick::serverside_nick_changed_to(\"" << new_nick << "\")");
00050 if (!M_network->is_private())
00051 {
00052 target_lookup_map_type::iterator iter = M_network->targets().find(in_name(server_session));
00053 ASSERT(iter != M_network->targets().end());
00054 boost::weak_ptr<Target> this_target(iter->second);
00055 Dout(dc::maps, "Erasing " << in_name(server_session) << " from Network map.");
00056 M_network->targets().erase(iter);
00057 for (NickData::common_channels_type::iterator iter1 = data().common_channels().begin(); iter1 != data().common_channels().end(); ++iter1)
00058 {
00059 boost::shared_ptr<Channel> channel(iter1->second);
00060 Channel::members_type::iterator iter2 = channel->members().find(in_name(server_session));
00061 ASSERT(iter2 != channel->members().end());
00062 Dout(dc::maps, "Erasing " << in_name(server_session) << " from members of " << *channel);
00063 Member member(iter2->second);
00064 channel->members().erase(iter2);
00065 Dout(dc::maps, "Inserting " << new_nick << " in members of " << *channel);
00066 channel->members().insert(Channel::members_type::value_type(new_nick, member));
00067 }
00068 Dout(dc::maps, "Inserting " << new_nick << " in Network map.");
00069 #if defined(CWDEBUG) || defined(DEBUG)
00070 std::pair<target_lookup_map_type::iterator, bool> res =
00071 #endif
00072 M_network->targets().insert(target_lookup_map_type::value_type(new_nick, this_target));
00073 ASSERT(res.second);
00074 }
00075 M_serverside_name[server_session] = new_nick;
00076 }
00077
00078 void Nick::clientside_nick_changed_to(ClientSession const& client_session, std::string const& new_nick)
00079 {
00080 DoutEntering(dc::debug, "Nick::clientside_nick_changed_to(\"" << new_nick << "\")");
00081 M_clientside_name[client_session] = new_nick;
00082 }
00083
00084 void Nick::new_client_message_received(ClientMessageIn const& msg)
00085 {
00086 DoutEntering(dc::debug, "Nick::new_client_message_received(" << msg << ") for target \"" << in_name(msg.client_session()) << "\".");
00087 }
00088
00089 void Nick::new_server_message_received(ServerMessageIn const& msg)
00090 {
00091 DoutEntering(dc::debug, "Nick::new_server_message_received(" << msg << ") for target \"" << in_name(msg.server_session()) << "\".");
00092 }
00093
00094 void Nick::add_channel(boost::shared_ptr<Channel> const& channel)
00095 {
00096 #if 0
00097 Dout(dc::maps, "Inserting " << channel->in_name(...) << " in common_channels of " << *this);
00098 #if defined(CWDEBUG) || defined(DEBUG)
00099 std::pair<NickData::common_channels_type::iterator, bool> res =
00100 #endif
00101 M_data.common_channels().insert(NickData::common_channels_type::value_type(channel->serverside_name(), channel));
00102 ASSERT(res.second);
00103 #endif
00104 }
00105
00106 void Nick::sub_channel(Channel const& channel)
00107 {
00108 #if 0
00109 NickData::common_channels_type::iterator iter = M_data.common_channels().find(channel.serverside_name());
00110 ASSERT(iter != M_data.common_channels().end());
00111 Dout(dc::maps, "Erasing " << channel.serverside_name() << " from common_channels of " << *this);
00112 M_data.common_channels().erase(iter);
00113 #endif
00114 }
00115
00116 std::string Nick::in_name(ClientSession const& client_session) const
00117 {
00118 return M_clientside_name[client_session];
00119 }
00120
00121 std::string Nick::in_name(ServerSession const& server_session) const
00122 {
00123 return M_serverside_name[server_session];
00124 }
00125
00126 std::string Nick::out_name(ClientSession const& client_session) const
00127 {
00128 return M_clientside_name[client_session];
00129 }
00130
00131 std::string Nick::out_name(ServerSession const& server_session) const
00132 {
00133 return M_serverside_name[server_session];
00134 }
00135
00136 void Nick::set_in_nick(ClientSession const& client_session, std::string const& in_nick)
00137 {
00138 M_clientside_name[client_session] = in_nick;
00139 }
00140
00141 void Nick::set_in_nick(ServerSession const& server_session, std::string const& in_nick)
00142 {
00143 M_serverside_name[server_session] = in_nick;
00144 }
00145
00146 void Nick::set_out_nick(ClientSession const& client_session, std::string const& out_nick)
00147 {
00148 M_clientside_name[client_session] = out_nick;
00149 }
00150
00151 void Nick::set_out_nick(ServerSession const& server_session, std::string const& out_nick)
00152 {
00153 M_serverside_name[server_session] = out_nick;
00154 }
00155
00156 std::string MyNick::out_name(ClientSession const& client_session) const
00157 {
00158 return M_clientside_out_name[client_session];
00159 }
00160
00161 std::string MyNick::out_name(ServerSession const& server_session) const
00162 {
00163 return M_serverside_out_name[server_session];
00164 }
00165
00166 void MyNick::set_out_nick(ClientSession const& client_session, std::string const& out_nick)
00167 {
00168 M_clientside_out_name[client_session] = out_nick;
00169 }
00170
00171 void MyNick::set_out_nick(ServerSession const& server_session, std::string const& out_nick)
00172 {
00173 M_serverside_out_name[server_session] = out_nick;
00174 }
00175