latest version of ArchBlackmann
[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 public:
16 IRCClient();
17
18 static bool GetDebug() { return _debug; }
19 static bool SetDebug ( bool debug ) { bool old = _debug; _debug = debug; return old; }
20
21 // connect to server ( record greeting for apop if it exists )
22 bool Connect ( const std::string& server, short port = 6667 );
23
24 bool Running() { return _inRun; }
25
26 ////////////////////////// IRC Client Protocol commands ///////////////////////
27
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 );
32
33 // change nick...
34 bool Nick ( const std::string& nick );
35
36 // change mode for self...
37 bool Mode ( const std::string& mode );
38
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 );
41
42 // request a list of names of clients in a channel
43 bool Names ( const std::string& channel );
44
45 // join a channel...
46 bool Join ( const std::string& channel );
47
48 // send message to someone or some channel
49 bool PrivMsg ( const std::string& to, const std::string& text );
50
51 // send /me to someone or some channel
52 bool Action ( const std::string& to, const std::string& text );
53
54 // leave a channel
55 bool Part ( const std::string& channel, const std::string& text );
56
57 // log off
58 bool Quit ( const std::string& text );
59
60 ////////////////////// callback functions ////////////////////////////
61
62 // OnConnected: you just successfully logged into irc server
63 virtual bool OnConnected() = 0;
64
65 virtual bool OnNick ( const std::string& oldNick, const std::string& newNick ) { return true; }
66
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; }
69
70 // OnPart: someone just left a channel you are in
71 virtual bool OnPart ( const std::string& user, const std::string& channel ) { return true; }
72
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; }
75
76 virtual bool OnPrivAction ( const std::string& from, const std::string& text ) { return true; }
77
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; }
81
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; }
85
86 // OnChannelMode: notification of a change of a channel's mode
87 virtual bool OnChannelMode ( const std::string& channel, const std::string& mode )
88 { return true; }
89
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; }
94
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; }
97
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 )
100 { return true; }
101
102 // notification that you have received the entire list of users for a channel
103 virtual bool OnEndChannelUsers ( const std::string& channel ) { return true; }
104
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
107 // dropped.
108 virtual bool OnPing ( const std::string& text );
109
110 ////////////////////// other functions ////////////////////////////
111
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 );
115
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 );
121
122 ////////////////////// private stuff ////////////////////////////
123 private:
124 bool _Recv ( std::string& buf );
125
126 static int THREADAPI Callback ( IRCClient* irc );
127
128 static bool _debug;
129 std::string _nick;
130 int _timeout;
131 std::string _apop_challenge;
132
133 volatile bool _inRun;
134
135 // disable copy semantics
136 IRCClient ( const IRCClient& );
137 IRCClient& operator = ( const IRCClient& );
138 };
139
140 #endif//IRCCLIENT_H