00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef SERVERSESSION_H
00017 #define SERVERSESSION_H
00018
00019 #ifndef USE_PCH
00020 #include <libcw/sock.h>
00021 #include "debug.h"
00022 #endif
00023
00024 #include "Target.h"
00025 #include "ServerSessionInput.h"
00026 #include "ServerSessionOutput.h"
00027 #include "IdentityReference.h"
00028 #include "Matcher.h"
00029 #include "NickPair.h"
00030 #include "UserMode.h"
00031 #include "AuthState.h"
00032 #include "Queue.h"
00033 #include "PseudoMessageEvent.h"
00034 #include "WhoRequest.h"
00035 #include "ISupport.h"
00036 #include "networks_type.h"
00037 #include "Index.h"
00038
00039 class Server;
00040 class ServerConnection;
00041
00042
00043
00044
00045
00046
00047 class ServerSession : public Index<ServerSession>, public IdentityReference, public sock_dtct<ServerSessionInput, ServerSessionOutput>, public event_client_ct {
00048 public:
00049 typedef target_hold_map_type joined_channels_type;
00050 typedef std::map<std::string, boost::shared_ptr<Channel> > join_pipeline_type;
00051
00052 private:
00053 ServerConnection& M_server_connection;
00054 MatcherEventServer M_message_event_server;
00055 NickPair M_server_session_nicks;
00056 joined_channels_type M_joined_channels;
00057 UserMode M_user_mode;
00058 boost::shared_ptr<AuthState> M_auth_state;
00059 Queue M_output_queue;
00060 std::queue<WhoRequest> M_who_queue;
00061 ISupport M_i_support;
00062 std::string M_network_name;
00063 static int S_server_sessions;
00064 std::string M_umodes;
00065 join_pipeline_type M_join_pipeline;
00066 std::string M_disconnect_reason;
00067
00068 public:
00069 Bool M_detected_network;
00070
00071 public:
00072
00073 ServerSession(Identity& identity, ServerConnection& server_connection) :
00074 IdentityReference(&identity), M_server_connection(server_connection),
00075 M_server_session_nicks(*this), M_output_queue(server_connection, 0.5, 5, 5),
00076 M_i_support(server_connection)
00077 #ifdef CWDEBUG
00078 , M_detected_network("M_detected_network")
00079 #endif
00080 {
00081 Dout(dc::objects, "Constructing ServerSession(" << identity << ", " << server_connection << ")");
00082 ++S_server_sessions;
00083 }
00084
00085 ~ServerSession();
00086
00087
00088 void start_authentication(void);
00089
00090
00091 void set_auth_ping_argument(std::string const& auth_ping_argument) { if (M_auth_state.get()) M_auth_state->set_auth_ping_argument(auth_ping_argument); }
00092
00093
00094 std::string const& auth_ping_argument(void) const { ASSERT(M_auth_state.get()); return M_auth_state->auth_ping_argument(); }
00095
00096
00097 void construct_network_object(std::string const& network_name, std::string const& domain);
00098
00099
00100 void detected_network(networks_type::iterator network_iter);
00101
00102
00103 void authentication_successful(void);
00104
00105
00106 void fatal_error(char const* error_msg);
00107
00108
00109 void found_network_name(void);
00110
00111
00112 MatcherEventServer& message_event_server(void) { return M_message_event_server; }
00113
00114 MatcherEventServer const& message_event_server(void) const { return M_message_event_server; }
00115
00116
00117 NickPair& nicks(void) { return M_server_session_nicks; }
00118
00119
00120 NickPair const& nicks(void) const { return M_server_session_nicks; }
00121
00122
00123 joined_channels_type& joined_channels(void) { return M_joined_channels; }
00124
00125
00126 joined_channels_type const& joined_channels(void) const { return M_joined_channels; }
00127
00128
00129 UserMode& user_mode(void) { return M_user_mode; }
00130
00131
00132 UserMode const& user_mode(void) const { return M_user_mode; }
00133
00134
00135 void queue_msg(MessageOut const& msg) { DoutEntering(dc::debug, "ServerSession::queue_msg(" << msg << ")"); M_output_queue.queue_msg(msg); }
00136
00137
00138 void queue_msg_as_is(ClientMessageIn const& msg);
00139
00140
00141 WhoRequest current_who_request(void)
00142 {
00143 ASSERT(!M_who_queue.empty());
00144 Dout(dc::debug, "ServerSession::current_who_request returns " << M_who_queue.front() << ". Number of items: " << M_who_queue.size());
00145 return M_who_queue.front();
00146 }
00147
00148
00149 void pop_who_request(void)
00150 {
00151 ASSERT(!M_who_queue.empty());
00152 M_who_queue.pop();
00153 Dout(dc::debug, "Calling ServerSession::pop_who_request. Remaining number of items: " << M_who_queue.size());
00154 }
00155
00156
00157 void send_nick_write_event(PseudoMessageEventType const&, std::string nick) { nicks().send_nick(nick); }
00158
00159
00160 void send_who_write_event(PseudoMessageEventType const& event_type, WhoRequest who_request);
00161
00162
00163 void force_quit(timer_event_type_ct const& LIBCW_UNUSED_UNLESS_DEBUG(expired_at));
00164
00165
00166 ISupport const& i_support(void) const { return M_i_support; }
00167
00168
00169 ISupport& i_support(void) { return M_i_support; }
00170
00171
00172 boost::shared_ptr<Channel> join_pipeline(std::string const& channel_name);
00173
00174
00175 void set_disconnect_reason(std::string const& disconnect_reason) { ASSERT(M_disconnect_reason.empty()); M_disconnect_reason = disconnect_reason; }
00176
00177
00178 ServerConnection& server_connection(void) const { return M_server_connection; }
00179
00180
00181 boost::shared_ptr<Nick> get_nick(std::string const& nick_name, bool create = false);
00182
00183 protected:
00184
00185 virtual void new_message_received(ServerMessageIn const&);
00186
00187
00188 virtual void network_connection_terminated(void);
00189
00190 private:
00191
00192 void send_rejoins(void);
00193 };
00194
00195 #endif // SERVERSESSION_H