2 // This file is (C) 2004 Royce Mitchell III
3 // and released under the BSD & LGPL licenses
10 #include "SockUtils.h"
11 #include "ThreadPool.h"
13 class IRCClient
: public suBufferedRecvSocket
18 static bool GetDebug() { return _debug
; }
19 static bool SetDebug ( bool debug
) { bool old
= _debug
; _debug
= debug
; return old
; }
21 // connect to server ( record greeting for apop if it exists )
22 bool Connect ( const std::string
& server
, short port
= 6667 );
24 bool Running() { return _inRun
; }
26 ////////////////////////// IRC Client Protocol commands ///////////////////////
28 // first thing you must call... mode can be ""
29 // network can be same as name of server used in Connect() above
30 bool User ( const std::string
& user
, const std::string
& mode
,
31 const std::string
& network
, const std::string
& realname
);
34 bool Nick ( const std::string
& nick
);
36 // change mode for self...
37 bool Mode ( const std::string
& mode
);
39 // set someone's mode in channel ( like oping someone )
40 bool Mode ( const std::string
& channel
, const std::string
& mode
, const std::string
& target
);
42 // request a list of names of clients in a channel
43 bool Names ( const std::string
& channel
);
46 bool Join ( const std::string
& channel
);
48 // send message to someone or some channel
49 bool PrivMsg ( const std::string
& to
, const std::string
& text
);
51 // send /me to someone or some channel
52 bool Action ( const std::string
& to
, const std::string
& text
);
55 bool Part ( const std::string
& channel
, const std::string
& text
);
58 bool Quit ( const std::string
& text
);
60 ////////////////////// callback functions ////////////////////////////
62 // OnConnected: you just successfully logged into irc server
63 virtual bool OnConnected() = 0;
65 virtual bool OnNick ( const std::string
& oldNick
, const std::string
& newNick
) { return true; }
67 // OnJoin: someone just successfully joined a channel you are in ( also sent when you successfully join a channel )
68 virtual bool OnJoin ( const std::string
& user
, const std::string
& channel
) { return true; }
70 // OnPart: someone just left a channel you are in
71 virtual bool OnPart ( const std::string
& user
, const std::string
& channel
) { return true; }
73 // OnPrivMsg: you just received a private message from a user
74 virtual bool OnPrivMsg ( const std::string
& from
, const std::string
& text
) { return true; }
76 virtual bool OnPrivAction ( const std::string
& from
, const std::string
& text
) { return true; }
78 // OnChannelMsg: you just received a chat line in a channel
79 virtual bool OnChannelMsg ( const std::string
& channel
, const std::string
& from
,
80 const std::string
& text
) { return true; }
82 // OnChannelAction: you just received a "/me" line in a channel
83 virtual bool OnChannelAction ( const std::string
& channel
, const std::string
& from
,
84 const std::string
& text
) { return true; }
86 // OnChannelMode: notification of a change of a channel's mode
87 virtual bool OnChannelMode ( const std::string
& channel
, const std::string
& mode
)
90 // OnUserModeInChannel: notification of a mode change of a user with respect to a channel.
91 // f.ex.: this will be called when someone is oped in a channel.
92 virtual bool OnUserModeInChannel ( const std::string
& src
, const std::string
& channel
,
93 const std::string
& mode
, const std::string
& target
) { return true; }
95 // OnMode: you will receive this when you change your own mode, at least...
96 virtual bool OnMode ( const std::string
& user
, const std::string
& mode
) { return true; }
98 // notification of what users are in a channel ( you may get multiple of these... )
99 virtual bool OnChannelUsers ( const std::string
& channel
, const std::vector
<std::string
>& users
)
102 // notification that you have received the entire list of users for a channel
103 virtual bool OnEndChannelUsers ( const std::string
& channel
) { return true; }
105 // OnPing - default implementation replies to PING with a valid PONG. required on some systems to
106 // log in. Most systems require a response in order to stay connected, used to verify a client hasn't
108 virtual bool OnPing ( const std::string
& text
);
110 ////////////////////// other functions ////////////////////////////
112 // this is for sending data to irc server. it's public in case you need to send some
113 // command not supported by this base class...
114 bool Send ( const std::string
& buf
);
116 // if launch_thread is true, this function will spawn a thread that will process
117 // incoming packets until the socket dies.
118 // otherwise ( launch_thread is false ) this function will do that processing
119 // in *this* thread, and not return until the socket dies.
120 int Run ( bool launch_thread
);
122 ////////////////////// private stuff ////////////////////////////
124 bool _Recv ( std::string
& buf
);
126 static int THREADAPI
Callback ( IRCClient
* irc
);
131 std::string _apop_challenge
;
133 volatile bool _inRun
;
135 // disable copy semantics
136 IRCClient ( const IRCClient
& );
137 IRCClient
& operator = ( const IRCClient
& );