ircproxy The Ultimate Cyborg |
00001 // ircproxy -- An IRC bouncer. 00002 // 00003 //! @file Target.h 00004 //! @brief This file contains the declaration of class Target. 00005 // 00006 // Copyright (C) 2006, 2007 by 00007 // 00008 // Carlo Wood, Run on IRC <carlo@alinoe.com> 00009 // RSA-1024 0x624ACAD5 1997-01-26 Sign & Encrypt 00010 // Fingerprint16 = 32 EC A7 B6 AC DB 65 A6 F6 F6 55 DD 1C DC FF 61 00011 // 00012 // This file may be distributed under the terms of the Q Public License 00013 // version 1.0 as appearing in the file LICENSE.QPL included in the 00014 // packaging of this file. 00015 00016 #ifndef TARGET_H 00017 #define TARGET_H 00018 00019 #ifndef USE_PCH 00020 #include <string> 00021 #include <map> 00022 #include <boost/shared_ptr.hpp> 00023 #include <boost/weak_ptr.hpp> 00024 #include "debug.h" 00025 #endif 00026 00027 #include "IRC_compare.h" 00028 00029 class ClientMessageIn; 00030 class ServerMessageIn; 00031 class Network; 00032 class Identity; 00033 class ClientSession; 00034 class ServerSession; 00035 00036 /*! @brief An IRC message target (ie, channel or nickname), base class. 00037 * 00038 * This class represents the target that IRC messages can be targetted at. 00039 */ 00040 class Target { 00041 protected: 00042 Network* M_network; //!< The underlying network. 00043 00044 protected: 00045 //! Protected constructor. Use Target::get to access a target by name. 00046 Target(Network* network) : M_network(network) { } 00047 00048 public: 00049 //! Destructor. 00050 virtual ~Target(); 00051 00052 //! Return the network that this target belongs to. 00053 Network const& network(void) const { return *M_network; } 00054 00055 //! Return the network that this target belongs to. 00056 Network& network(void) { return *M_network; } 00057 00058 virtual std::string in_name(ClientSession const&) const = 0; 00059 virtual std::string in_name(ServerSession const&) const = 0; 00060 virtual std::string out_name(ClientSession const&) const = 0; 00061 virtual std::string out_name(ServerSession const&) const = 0; 00062 00063 public: 00064 //! Add a (non-existent) new channel with name \a channel_name. 00065 // This function updates the target maps for this identity. 00066 // It should only be called for channels that the identity has joined. 00067 // The Channel is added with the same name to both sides (serverside and clientside). 00068 // \param identity The identity that joined this channel. 00069 // \param channel_name The channel name of the target. This is unique per network. 00070 static boost::shared_ptr<Channel> add_channel(Identity& identity, std::string const& channel_name); 00071 00072 //! Remove this channel from the channel maps. 00073 //! Does the opposite of add_channel. Should only be called for channels that we have joined. 00074 void sub_channel(Identity& identity); 00075 00076 static void serverside_add_channel(ServerSession& server_session, boost::shared_ptr<Channel> new_channel); 00077 00078 //! Retrieve a shared pointer to the Channel object for \a channel_name. 00079 // \param identity The identity that needs this target at the moment. 00080 // \param channel_name The IRC name of the target. This is unique per network. 00081 static boost::shared_ptr<Channel> serverside_get_channel(Identity& identity, std::string const& channel_name, bool joined = false); 00082 00083 //! Retrieve a shared pointer to the Channel object for \a channel_name. 00084 // \param identity The identity that needs this target at the moment. 00085 // \param channel_name The IRC name of the target. This is unique per network. 00086 static boost::shared_ptr<Channel> clientside_get_channel(Identity const& identity, std::string const& channel_name); 00087 00088 //! Add a new nick with name \a nick_name to the joined channel with name \a channel_name. 00089 // This function updates the target maps for this identity. 00090 // It should only be called for channels that the identity has joined. 00091 // If the Nick isn't known already, then the Nick is added with the same name to both sides (serverside and clientside). 00092 // \param identity The identity that sees this nick join. 00093 // \param nick_name The serverside nick name of the joined target. This is unique per network. 00094 // \param channel_name The name of the channel that this nick joined. 00095 static boost::shared_ptr<Nick> add_joined_nick(Identity& identity, std::string const& nick_name, boost::shared_ptr<Channel>& channel); 00096 00097 //! Return a shared pointer to the Nick object with name \a nick_name that is joined to channel \a channel. 00098 // If no such nick name exist, the exception unknown_target is thrown. 00099 static boost::shared_ptr<Nick> get_joined_nick(Identity& identity, std::string const& nick_name, boost::shared_ptr<Channel>& channel); 00100 00101 public: 00102 //! This is called when a new message targetted at this target is received. 00103 virtual void new_client_message_received(ClientMessageIn const&) = 0; 00104 //! This is called when a new message targetted at this target is received. 00105 virtual void new_server_message_received(ServerMessageIn const&) = 0; 00106 00107 #ifdef CWDEBUG 00108 protected: 00109 virtual bool is_me(void) const { return false; } 00110 #endif 00111 }; 00112 00113 //! The type of the target maps that are used for mapping the target names to the real object. 00114 typedef std::map<std::string, boost::weak_ptr<Target>, IRC_less> target_lookup_map_type; 00115 00116 //! The type of the target maps that are used to keep targets alive. 00117 typedef std::map<std::string, boost::shared_ptr<Target>, IRC_less> target_hold_map_type; 00118 00119 #endif // TARGET_H
Copyright © 2005-2007 Carlo Wood. All rights reserved. |
---|