00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef NICK_H
00017 #define NICK_H
00018
00019 #ifndef USE_PCH
00020 #include "debug.h"
00021 #endif
00022
00023 #include "Target.h"
00024 #include "IdentityReference.h"
00025 #include "IPNumber.h"
00026 #include "Flags.h"
00027 #include "random_nick.h"
00028 #include "Array.h"
00029
00030 class ClientMessageIn;
00031 class ServerMessageIn;
00032
00033
00034 typedef unsigned int mask_type;
00035
00036 mask_type const username_bit = 1;
00037 mask_type const hostname_bit = 2;
00038 mask_type const ip_bit = 4;
00039 mask_type const realname_bit = 8;
00040 mask_type const servername_bit = 16;
00041 mask_type const idletime_bit = 32;
00042 mask_type const accountname_bit = 64;
00043 mask_type const hopcount_bit = 128;
00044 mask_type const flags_bit = 256;
00045
00046
00047
00048
00049
00050
00051 class NickData {
00052 public:
00053 typedef std::map<std::string, boost::weak_ptr<Channel> > common_channels_type;
00054
00055 protected:
00056 mask_type M_initialized;
00057 std::string M_username;
00058 std::string M_hostname;
00059 IPNumber M_ip;
00060 std::string M_realname;
00061 std::string M_servername;
00062 int M_idletime;
00063 std::string M_accountname;
00064 int M_hopcount;
00065 Flags M_flags;
00066 common_channels_type M_common_channels;
00067
00068 public:
00069
00070 NickData(void) : M_initialized(0) { }
00071
00072
00073 mask_type initialized(void) const { return M_initialized; }
00074
00075 std::string const& username(void) const { ASSERT(M_initialized & username_bit); return M_username; }
00076
00077 std::string const& hostname(void) const { ASSERT(M_initialized & hostname_bit); return M_hostname; }
00078
00079 IPNumber const& ip(void) const { ASSERT(M_initialized & ip_bit); return M_ip; }
00080
00081 std::string const& realname(void) const { ASSERT(M_initialized & realname_bit); return M_realname; }
00082
00083 std::string const& servername(void) const { ASSERT(M_initialized & servername_bit); return M_servername; }
00084
00085 int idletime(void) const { ASSERT(M_initialized & idletime_bit); return M_idletime; }
00086
00087 std::string const& accountname(void) const { ASSERT(M_initialized & accountname_bit); return M_accountname; }
00088
00089 int hopcount(void) const { ASSERT(M_initialized & hopcount_bit); return M_hopcount; }
00090
00091 Flags const& flags(void) const { ASSERT(M_initialized & flags_bit); return M_flags; }
00092
00093
00094 void set_username(std::string const& username) { M_initialized |= username_bit; M_username = username; }
00095
00096 void set_hostname(std::string const& hostname) { M_initialized |= hostname_bit; M_hostname = hostname; }
00097
00098 void set_ip(IPNumber const& ip) { M_initialized |= ip_bit; M_ip = ip; }
00099
00100 void set_realname(std::string const& realname) { M_initialized |= realname_bit; M_realname = realname; }
00101
00102 void set_servername(std::string const& servername) { M_initialized |= servername_bit; M_servername = servername; }
00103
00104 void set_idletime(int idletime) { M_initialized |= idletime_bit; M_idletime = idletime; }
00105
00106 void set_accountname(std::string const& accountname) { M_initialized |= accountname_bit; M_accountname = accountname; }
00107
00108 void set_hopcount(int hopcount) { M_initialized |= hopcount_bit; M_hopcount = hopcount; }
00109
00110 void set_flags(Flags const& flags) { M_initialized |= flags_bit; M_flags = flags; }
00111
00112
00113 void reset(void) { M_initialized = 0; }
00114
00115
00116 common_channels_type& common_channels(void) { return M_common_channels; }
00117
00118
00119 common_channels_type const& common_channels(void) const { return M_common_channels; }
00120 };
00121
00122
00123 class WhoEventType : public NickData {
00124 };
00125
00126
00127 class WhoRequestData {
00128 private:
00129 std::string M_nick;
00130 public:
00131
00132 WhoRequestData(std::string const& nick) : M_nick(nick) { }
00133
00134 std::string const& nick(void) const { return M_nick; }
00135 };
00136
00137
00138 class WhoEventRequestBase : public event_request_base_tct<WhoEventType> {
00139 public:
00140 typedef WhoRequestData event_request_data_ct;
00141 private:
00142 event_request_data_ct M_request_data;
00143 public:
00144
00145 WhoEventRequestBase(event_client_tracker_ct* event_client_tracker, event_request_data_ct const& event_request_data) :
00146 event_request_base_tct<WhoEventType>(event_client_tracker), M_request_data(event_request_data) { }
00147 };
00148
00149
00150 typedef event_data_server_tct<WhoEventRequestBase> WhoEventServer;
00151
00152
00153
00154
00155 class Nick : public Target {
00156 private:
00157 NickData M_data;
00158 int M_common_channels;
00159 Array<std::string> M_clientside_name;
00160 Array<std::string> M_serverside_name;
00161
00162 protected:
00163
00164 Nick(Identity& identity);
00165
00166 public:
00167
00168 Nick(ServerSession const& server_session, std::string const& target_name);
00169
00170
00171 Nick(ClientSession const& client_session, std::string const& target_name, Network& private_network);
00172
00173 #ifdef CWDEBUG
00174
00175 ~Nick() { Dout(dc::objects, "Destructing Nick " << *this); }
00176 private:
00177
00178 Nick(Nick const& nick) : Target(nick),
00179 M_data(nick.M_data), M_common_channels(nick.M_common_channels)
00180 { DoutFatal(dc::core, "Copy-constructing Nick from " << nick); }
00181 #endif
00182
00183 public:
00184
00185 bool is_initialized(mask_type mask) const { return (M_data.initialized() & mask) == mask; }
00186
00187 bool is_synced(mask_type mask) const { return M_common_channels > 0 && (M_data.initialized() & mask) == mask; }
00188
00189 mask_type initialized(mask_type mask) const { return M_data.initialized() & mask; }
00190
00191 mask_type synced(mask_type mask) const { return M_common_channels > 0 ? M_data.initialized() & mask : 0; }
00192
00193
00194 NickData const& data(void) const { return M_data; }
00195
00196 NickData& data(void) { return M_data; }
00197
00198
00199 void serverside_nick_changed_to(ServerSession const& server_session, std::string const& new_nick);
00200
00201
00202 void clientside_nick_changed_to(ClientSession const& client_session, std::string const& new_nick);
00203
00204
00205 void add_channel(boost::shared_ptr<Channel> const& channel);
00206
00207
00208 void sub_channel(Channel const& channel);
00209
00210
00211 virtual bool is_me(void) const { return false; }
00212
00213
00214
00215
00216 void set_network(Network* network) { ASSERT(!network->is_private() && (M_network->is_private() || M_network == network)); M_network = network; }
00217
00218 virtual void new_client_message_received(ClientMessageIn const& msg);
00219 virtual void new_server_message_received(ServerMessageIn const& msg);
00220
00221 virtual std::string in_name(ClientSession const& client_session) const;
00222 virtual std::string in_name(ServerSession const& server_session) const;
00223 virtual std::string out_name(ClientSession const& client_session) const;
00224 virtual std::string out_name(ServerSession const& server_session) const;
00225
00226 virtual void set_in_nick(ClientSession const& client_session, std::string const& in_nick);
00227 virtual void set_in_nick(ServerSession const& server_session, std::string const& in_nick);
00228 virtual void set_out_nick(ClientSession const& client_session, std::string const& out_nick);
00229 virtual void set_out_nick(ServerSession const& server_session, std::string const& out_nick);
00230 };
00231
00232
00233
00234
00235 class MyNick : public Nick {
00236 private:
00237 Array<std::string> M_clientside_out_name;
00238 Array<std::string> M_serverside_out_name;
00239
00240 public:
00241
00242 MyNick(Identity& identity) : Nick(identity) { }
00243
00244
00245 virtual bool is_me(void) const { return true; }
00246
00247 virtual std::string out_name(ClientSession const& client_session) const;
00248 virtual std::string out_name(ServerSession const& server_session) const;
00249
00250 virtual void set_out_nick(ClientSession const& client_session, std::string const& out_nick);
00251 virtual void set_out_nick(ServerSession const& server_session, std::string const& out_nick);
00252 };
00253
00254 #endif // NICK_H