ArchBlackmann irc bot - works in ReactOS - happy hacking
[reactos.git] / rosapps / games / 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 // leave a channel
52 bool Part ( const std::string& channel, const std::string& text );
53
54 // log off
55 bool Quit ( const std::string& text );
56
57 ////////////////////// callback functions ////////////////////////////
58
59 // OnConnected: you just successfully logged into irc server
60 virtual bool OnConnected() = 0;
61
62 // OnJoin: you just successfully joined this channel
63 virtual bool OnJoin ( const std::string& user, const std::string& channel ) = 0;
64
65 // OnPrivMsg: you just received a private message from a user
66 virtual bool OnPrivMsg ( const std::string& from, const std::string& text ) = 0;
67
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;
71
72 // OnChannelMode: notification of a change of a channel's mode
73 virtual bool OnChannelMode ( const std::string& channel, const std::string& mode ) = 0;
74
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;
79
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;
82
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;
85
86 // notification that you have received the entire list of users for a channel
87 virtual bool OnEndChannelUsers ( const std::string& channel ) = 0;
88
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
91 // dropped.
92 virtual bool OnPing ( const std::string& text );
93
94 ////////////////////// other functions ////////////////////////////
95
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 );
99
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 );
105
106 ////////////////////// private stuff ////////////////////////////
107 private:
108 bool _Recv ( std::string& buf );
109
110 static int THREADAPI Callback ( IRCClient* irc );
111
112 static bool _debug;
113 std::string _nick;
114 int _timeout;
115 std::string _apop_challenge;
116
117 volatile bool _inRun;
118
119 // disable copy semantics
120 IRCClient ( const IRCClient& );
121 IRCClient& operator = ( const IRCClient& );
122 };
123
124 #endif//IRCCLIENT_H