00001
00002
00003
00004 #ifndef __SESSION_H__
00005 #define __SESSION_H__
00006
00007 #include <string>
00008 #include <boost/signal.hpp>
00009 #include <boost/bind.hpp>
00010 #include <map>
00011 #include "parser.h"
00012 #include "netsocket.h"
00013 #include "user.h"
00014 #include "channel.h"
00015 #include "irclist.h"
00016 #include "mainuserlist.h"
00017 #include "channellist.h"
00018
00019 namespace ircpp {
00020
00021 class message;
00022
00023
00045 class session {
00046
00047
00048 public:
00049 explicit session(listmode mode = automatic);
00050 bool connect(const std::string& hostname, unsigned int port = 6667, const std::string& password = "", bool login = true);
00051 void run();
00052 bool service_socket(fd_set *readfds, fd_set *writefds, fd_set *exceptfds, int *maxfd);
00053 bool connected();
00054 bool disconnect();
00055 bool set_nick(const std::string& newnick);
00056 bool set_username(const std::string& username);
00057 bool set_realname(const std::string& realname);
00058 const user& nulluser() const;
00059 const channel& nullchannel() const;
00060 const user& me() const;
00061 const user& server() const;
00062 void auto_pong(bool on);
00063 bool auto_pong();
00064 bool has_capab(const std::string& name);
00065 const std::string& capab(const std::string& name);
00066 void ptr(void* p);
00067 void* ptr() const;
00068
00069
00074 boost::signal0<void> sig_connected;
00080 boost::signal1<void, const std::string&> sig_disconnected;
00087 boost::signal2<void, const std::string&, const int> sig_socket_error;
00095 boost::signal1<void, user*> sig_user_deletable;
00103 boost::signal1<void, channel*> sig_channel_deletable;
00109 boost::signal1<void, const std::string&> sig_parseerror;
00110
00111
00112 public:
00113 bool cmd_raw(const std::string& rawline);
00114 bool cmd_pass(const std::string& password);
00115 bool cmd_nick(const std::string& newnick);
00116 bool cmd_user(const std::string& username, const std::string& hostname, const std::string& servername, const std::string& realname);
00117 bool cmd_quit(const std::string& quitmsg);
00118 bool cmd_join(const std::string& channel, const std::string& key = "");
00119 bool cmd_part(const std::string& channel, const std::string& partmsg = "");
00120 bool cmd_mode(const std::string& target, const std::string& modestring);
00121 bool cmd_topic(const std::string& channel, const std::string& topic);
00122 bool cmd_names(const std::string& channel);
00123 bool cmd_list(const std::string& params = "");
00124 bool cmd_invite(const std::string& nick, const std::string& channel);
00125 bool cmd_kick(const std::string& nick, const std::string& channel, const std::string& reason = "");
00126 bool cmd_privmsg(const std::string& to, const std::string& message);
00127 bool cmd_notice(const std::string& to, const std::string& message);
00128 bool cmd_ctcp(const std::string& to, const std::string& command, const std::string& params);
00129 bool cmd_ping(const std::string& params);
00130 bool cmd_pong(const std::string& params);
00131 bool cmd_away(const std::string& message = "");
00132 bool cmd_oper(const std::string& opernick, const std::string& operpass);
00133 bool cmd_who(const std::string& params);
00134 bool cmd_whois(const std::string& target);
00135
00136
00137 public:
00144 boost::signal1<void, const message &> sig_all_msgs;
00150 boost::signal1<void, const message &> sig_unknown_msg;
00157 boost::signal1<void, const message &> sig_numeric_msg;
00161 boost::signal1<void, const message &> sig_nick_msg;
00165 boost::signal1<void, const message &> sig_quit_msg;
00169 boost::signal1<void, const message &> sig_join_msg;
00173 boost::signal1<void, const message &> sig_part_msg;
00181 boost::signal1<void, const message &> sig_mode_msg;
00195 boost::signal1<void, const message &> sig_singlemode_msg;
00199 boost::signal1<void, const message &> sig_topic_msg;
00203 boost::signal1<void, const message &> sig_invite_msg;
00207 boost::signal1<void, const message &> sig_kick_msg;
00212 boost::signal1<void, const message &> sig_privmsg_msg;
00216 boost::signal1<void, const message &> sig_ctcp_msg;
00220 boost::signal1<void, const message &> sig_notice_msg;
00224 boost::signal1<void, const message &> sig_ping_msg;
00228 boost::signal1<void, const message &> sig_pong_msg;
00232 boost::signal1<void, const message &> sig_error_msg;
00233
00234
00235 listmode list_mode() const;
00236
00237 const channel& find_channel(const std::string& name) const;
00238 const irclist<channel>::iterator channellist_begin() const;
00239 const irclist<channel>::iterator channellist_end() const;
00240
00241 const user& find_user(const std::string& nick) const;
00242 const irclist<user>::iterator userlist_begin() const;
00243 const irclist<user>::iterator userlist_end() const;
00244
00245
00246 public:
00247 bool is_channel(const std::string& str) const;
00248 void strip_modechars(std::string& s);
00249
00250
00251 public:
00252 bool operator==(const session& s) const;
00253 bool operator!=(const session& s) const;
00254
00255
00256 private:
00257 void message_sorter(const message& msg);
00258 void singlemode_slot(const message& msg);
00259 void disconnect_slot(const std::string& reason);
00260 void connect_slot();
00261 void error_slot(const std::string&, int);
00262 void parseerror_slot(const std::string& line);
00263
00264
00265 void parse_005(const message& msg);
00266 void clear_on_connect();
00267
00268
00269 private:
00270 netsocket socket;
00271 parser _parser;
00272
00273
00274 private:
00275 bool _connected;
00276 bool login_on_connect;
00277 unsigned int port;
00278 user _server;
00279 user _me;
00280 user _nulluser;
00281 channel _nullchannel;
00282 listmode _listmode;
00283 mainuserlist _userlist;
00284 channellist _channellist;
00285 std::string server_password;
00286 bool _auto_pong;
00287 std::map<std::string, std::string> _capabs;
00288 void* _ptr;
00289
00290
00291 friend class parser;
00292 friend class channel;
00293 friend class message;
00294 friend class user;
00295 friend class mainuserlist;
00296 friend class channellist;
00297 friend class channeluserlist;
00298
00299 };
00300 }
00301
00302 #endif