6f8f36061def3c7b56dcf6cf5b8f27865f508473
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
);
52 bool Part ( const std::string
& channel
, const std::string
& text
);
55 bool Quit ( const std::string
& text
);
57 ////////////////////// callback functions ////////////////////////////
59 // OnConnected: you just successfully logged into irc server
60 virtual bool OnConnected() = 0;
62 // OnJoin: you just successfully joined this channel
63 virtual bool OnJoin ( const std::string
& user
, const std::string
& channel
) = 0;
65 // OnPrivMsg: you just received a private message from a user
66 virtual bool OnPrivMsg ( const std::string
& from
, const std::string
& text
) = 0;
68 // OnChannelMsg: you just received a chat line in a channel
69 virtual bool OnChannelMsg ( const std::string
& channel
, const std::string
& from
,
70 const std::string
& text
) = 0;
72 // OnChannelMode: notification of a change of a channel's mode
73 virtual bool OnChannelMode ( const std::string
& channel
, const std::string
& mode
) = 0;
75 // OnUserModeInChannel: notification of a mode change of a user with respect to a channel.
76 // f.ex.: this will be called when someone is oped in a channel.
77 virtual bool OnUserModeInChannel ( const std::string
& src
, const std::string
& channel
,
78 const std::string
& user
, const std::string
& mode
) = 0;
80 // OnMode: you will receive this when you change your own mode, at least...
81 virtual bool OnMode ( const std::string
& user
, const std::string
& mode
) = 0;
83 // notification of what users are in a channel ( you may get multiple of these... )
84 virtual bool OnChannelUsers ( const std::string
& channel
, const std::vector
<std::string
>& users
) = 0;
86 // notification that you have received the entire list of users for a channel
87 virtual bool OnEndChannelUsers ( const std::string
& channel
) = 0;
89 // OnPing - default implementation replies to PING with a valid PONG. required on some systems to
90 // log in. Most systems require a response in order to stay connected, used to verify a client hasn't
92 virtual bool OnPing ( const std::string
& text
);
94 ////////////////////// other functions ////////////////////////////
96 // this is for sending data to irc server. it's public in case you need to send some
97 // command not supported by this base class...
98 bool Send ( const std::string
& buf
);
100 // if launch_thread is true, this function will spawn a thread that will process
101 // incoming packets until the socket dies.
102 // otherwise ( launch_thread is false ) this function will do that processing
103 // in *this* thread, and not return until the socket dies.
104 int Run ( bool launch_thread
);
106 ////////////////////// private stuff ////////////////////////////
108 bool _Recv ( std::string
& buf
);
110 static int THREADAPI
Callback ( IRCClient
* irc
);
115 std::string _apop_challenge
;
117 volatile bool _inRun
;
119 // disable copy semantics
120 IRCClient ( const IRCClient
& );
121 IRCClient
& operator = ( const IRCClient
& );