1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
/*
cpIRC - C++ class based IRC protocol wrapper
Copyright (C) 2003 Iain Sheppard
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contacting the author:
~~~~~~~~~~~~~~~~~~~~~~
email: iainsheppard@yahoo.co.uk
IRC: #magpie @ irc.quakenet.org
*/
#include <stdio.h>
#include <stdarg.h>
#define __CPIRC_VERSION__ 0.1
#define __IRC_DEBUG__ 1
#define IRC_USER_VOICE 1
#define IRC_USER_HALFOP 2
#define IRC_USER_OP 4
struct irc_reply_data
{
char* nick;
char* ident;
char* host;
char* target;
};
struct irc_command_hook
{
char* irc_command;
int (*function)(char*, irc_reply_data*, void*);
irc_command_hook* next;
};
struct channel_user
{
char* nick;
char* channel;
char flags;
channel_user* next;
};
class IRC
{
public:
IRC();
~IRC();
int start(char* server, int port, char* nick, char* user, char* name, char* pass);
void disconnect();
int privmsg(char* target, char* message);
int privmsg(char* fmt, ...);
int notice(char* target, char* message);
int notice(char* fmt, ...);
int join(char* channel);
int part(char* channel);
int kick(char* channel, char* nick);
int kick(char* channel, char* nick, char* message);
int mode(char* modes);
int mode(char* channel, char* modes, char* targets);
int nick(char* newnick);
int quit(char* quit_message);
int raw(char* data);
void hook_irc_command(char* cmd_name, int (*function_ptr)(char*, irc_reply_data*, void*));
int message_loop();
int is_op(char* channel, char* nick);
int is_voice(char* channel, char* nick);
char* current_nick();
private:
void call_hook(char* irc_command, char*params, irc_reply_data* hostd);
/*void call_the_hook(irc_command_hook* hook, char* irc_command, char*params, irc_host_data* hostd);*/
void parse_irc_reply(char* data);
void split_to_replies(char* data);
void insert_irc_command_hook(irc_command_hook* hook, char* cmd_name, int (*function_ptr)(char*, irc_reply_data*, void*));
void delete_irc_command_hook(irc_command_hook* cmd_hook);
int irc_socket;
bool connected;
bool sentnick;
bool sentpass;
bool sentuser;
char* cur_nick;
FILE* dataout;
FILE* datain;
channel_user* chan_users;
irc_command_hook* hooks;
};
|