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
19 std::string mychannel
;
20 static bool GetDebug() { return _debug
; }
21 static bool SetDebug ( bool debug
) { bool old
= _debug
; _debug
= debug
; return old
; }
23 // connect to server ( record greeting for apop if it exists )
24 bool Connect ( const std::string
& server
, short port
= 6667 );
26 bool Running() { return _inRun
; }
28 ////////////////////////// IRC Client Protocol commands ///////////////////////
30 // first thing you must call... mode can be ""
31 // network can be same as name of server used in Connect() above
32 bool User ( const std::string
& user
, const std::string
& mode
,
33 const std::string
& network
, const std::string
& realname
);
36 bool Nick ( const std::string
& nick
);
38 // change mode for self...
39 bool Mode ( const std::string
& mode
);
41 // set someone's mode in channel ( like oping someone )
42 bool Mode ( const std::string
& channel
, const std::string
& mode
, const std::string
& target
);
44 // request a list of names of clients in a channel
45 bool Names ( const std::string
& channel
);
48 bool Join ( const std::string
& channel
);
50 // send message to someone or some channel
51 bool PrivMsg ( const std::string
& to
, const std::string
& text
);
53 // send /me to someone or some channel
54 bool Action ( const std::string
& to
, const std::string
& text
);
57 bool Part ( const std::string
& channel
, const std::string
& text
);
60 bool Quit ( const std::string
& text
);
62 ////////////////////// callback functions ////////////////////////////
64 // OnConnected: you just successfully logged into irc server
65 virtual bool OnConnected() = 0;
67 virtual bool OnNick ( const std::string
& oldNick
, const std::string
& newNick
) { return true; }
69 // OnJoin: someone just successfully joined a channel you are in ( also sent when you successfully join a channel )
70 virtual bool OnJoin ( const std::string
& user
, const std::string
& channel
) { return true; }
72 // OnPart: someone just left a channel you are in
73 virtual bool OnPart ( const std::string
& user
, const std::string
& channel
) { return true; }
75 // OnPrivMsg: you just received a private message from a user
76 virtual bool OnPrivMsg ( const std::string
& from
, const std::string
& text
) { return true; }
78 virtual bool OnPrivAction ( const std::string
& from
, const std::string
& text
) { return true; }
80 // OnChannelMsg: you just received a chat line in a channel
81 virtual bool OnChannelMsg ( const std::string
& channel
, const std::string
& from
,
82 const std::string
& text
) { return true; }
84 // OnChannelAction: you just received a "/me" line in a channel
85 virtual bool OnChannelAction ( const std::string
& channel
, const std::string
& from
,
86 const std::string
& text
) { return true; }
88 // OnChannelMode: notification of a change of a channel's mode
89 virtual bool OnChannelMode ( const std::string
& channel
, const std::string
& mode
)
92 // OnUserModeInChannel: notification of a mode change of a user with respect to a channel.
93 // f.ex.: this will be called when someone is oped in a channel.
94 virtual bool OnUserModeInChannel ( const std::string
& src
, const std::string
& channel
,
95 const std::string
& mode
, const std::string
& target
) { return true; }
97 // OnMode: you will receive this when you change your own mode, at least...
98 virtual bool OnMode ( const std::string
& user
, const std::string
& mode
) { return true; }
100 // notification of what users are in a channel ( you may get multiple of these... )
101 virtual bool OnChannelUsers ( const std::string
& channel
, const std::vector
<std::string
>& users
)
104 // OnKick: if the client has been kicked
105 virtual bool OnKick ( void ) { return true; }
107 // OnKick: if the client has been kicked
108 virtual bool OnBanned ( const std::string
& channel
) { return true; }
110 // notification that you have received the entire list of users for a channel
111 virtual bool OnEndChannelUsers ( const std::string
& channel
) { return true; }
113 // OnPing - default implementation replies to PING with a valid PONG. required on some systems to
114 // log in. Most systems require a response in order to stay connected, used to verify a client hasn't
116 virtual bool OnPing ( const std::string
& text
);
118 ////////////////////// other functions ////////////////////////////
120 // this is for sending data to irc server. it's public in case you need to send some
121 // command not supported by this base class...
122 bool Send ( const std::string
& buf
);
124 // if launch_thread is true, this function will spawn a thread that will process
125 // incoming packets until the socket dies.
126 // otherwise ( launch_thread is false ) this function will do that processing
127 // in *this* thread, and not return until the socket dies.
128 int Run ( bool launch_thread
);
130 ////////////////////// private stuff ////////////////////////////
132 bool _Recv ( std::string
& buf
);
134 static int THREADAPI
Callback ( IRCClient
* irc
);
139 std::string _apop_challenge
;
141 volatile bool _inRun
;
143 // disable copy semantics
144 IRCClient ( const IRCClient
& );
145 IRCClient
& operator = ( const IRCClient
& );