- (Hack)fix build.
[reactos.git] / irc / ArchBlackmann / IRCClient.h
1 // IRCClient.h
2 // This file is (C) 2004 Royce Mitchell III
3 // and released under the BSD & LGPL licenses
4
5 #ifndef IRCCLIENT_H
6 #define IRCCLIENT_H
7
8 #include <string>
9 #include <vector>
10 #include "SockUtils.h"
11 #include "ThreadPool.h"
12
13 class IRCClient : public suBufferedRecvSocket
14 {
15
16 public:
17 IRCClient();
18
19 std::string mychannel;
20 static bool GetDebug() { return _debug; }
21 static bool SetDebug ( bool debug ) { bool old = _debug; _debug = debug; return old; }
22
23 // connect to server ( record greeting for apop if it exists )
24 bool Connect ( const std::string& server, short port = 6667 );
25
26 bool Running() { return _inRun; }
27
28 ////////////////////////// IRC Client Protocol commands ///////////////////////
29
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 );
34
35 // change nick...
36 bool Nick ( const std::string& nick );
37
38 // change mode for self...
39 bool Mode ( const std::string& mode );
40
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 );
43
44 // request a list of names of clients in a channel
45 bool Names ( const std::string& channel );
46
47 // join a channel...
48 bool Join ( const std::string& channel );
49
50 // send message to someone or some channel
51 bool PrivMsg ( const std::string& to, const std::string& text );
52
53 // send /me to someone or some channel
54 bool Action ( const std::string& to, const std::string& text );
55
56 // leave a channel
57 bool Part ( const std::string& channel, const std::string& text );
58
59 // log off
60 bool Quit ( const std::string& text );
61
62 ////////////////////// callback functions ////////////////////////////
63
64 // OnConnected: you just successfully logged into irc server
65 virtual bool OnConnected() = 0;
66
67 virtual bool OnNick ( const std::string& oldNick, const std::string& newNick ) { return true; }
68
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; }
71
72 // OnPart: someone just left a channel you are in
73 virtual bool OnPart ( const std::string& user, const std::string& channel ) { return true; }
74
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; }
77
78 virtual bool OnPrivAction ( const std::string& from, const std::string& text ) { return true; }
79
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; }
83
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; }
87
88 // OnChannelMode: notification of a change of a channel's mode
89 virtual bool OnChannelMode ( const std::string& channel, const std::string& mode )
90 { return true; }
91
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; }
96
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; }
99
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 )
102 { return true; }
103
104 // OnKick: if the client has been kicked
105 virtual bool OnKick ( void ) { return true; }
106
107 // OnKick: if the client has been kicked
108 virtual bool OnBanned ( const std::string& channel ) { return true; }
109
110 // notification that you have received the entire list of users for a channel
111 virtual bool OnEndChannelUsers ( const std::string& channel ) { return true; }
112
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
115 // dropped.
116 virtual bool OnPing ( const std::string& text );
117
118 ////////////////////// other functions ////////////////////////////
119
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 );
123
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 );
129
130 ////////////////////// private stuff ////////////////////////////
131 private:
132 bool _Recv ( std::string& buf );
133
134 static int THREADAPI Callback ( IRCClient* irc );
135
136 static bool _debug;
137 std::string _nick;
138 int _timeout;
139 std::string _apop_challenge;
140
141 volatile bool _inRun;
142
143 // disable copy semantics
144 IRCClient ( const IRCClient& );
145 IRCClient& operator = ( const IRCClient& );
146 };
147
148 #endif//IRCCLIENT_H