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 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373
|
/*
** ClanLib SDK
** Copyright (c) 1997-2005 The ClanLib Team
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any damages
** arising from the use of this software.
**
** Permission is granted to anyone to use this software for any purpose,
** including commercial applications, and to alter it and redistribute it
** freely, subject to the following restrictions:
**
** 1. The origin of this software must not be misrepresented; you must not
** claim that you wrote the original software. If you use this software
** in a product, an acknowledgment in the product documentation would be
** appreciated but is not required.
** 2. Altered source versions must be plainly marked as such, and must not be
** misrepresented as being the original software.
** 3. This notice may not be removed or altered from any source distribution.
**
** Note: Some of the libraries ClanLib may link to may have additional
** requirements or restrictions.
**
** File Author(s):
**
** Magnus Norddahl
** (if your name is missing here, please add it)
*/
//! clanNetwork="Internet Relay Chat"
//! header=network.h
#ifndef header_irc_connection
#define header_irc_connection
#ifdef CL_API_DLL
#ifdef CL_NETWORK_EXPORT
#define CL_API_NETWORK __declspec(dllexport)
#else
#define CL_API_NETWORK __declspec(dllimport)
#endif
#else
#define CL_API_NETWORK
#endif
#if _MSC_VER > 1000
#pragma once
#endif
#ifdef _MSC_VER
#pragma warning (disable:4786)
#endif
#include <string>
#include <vector>
#include <list>
#include <queue>
#include "../../signals.h"
#include "irc_numerics.h"
class CL_IRCConnection_Generic;
//: IRC Connection class.
//- !group=Network/Internet Relay Chat!
//- !header=network.h!
//- <p>The CL_IRCConnection class represents a socket connection to an IRC
//- server. Upon construction it will connect to the server+port given and
//- then parse each line written by the IRC server. Each time
//- CL_System::keep_alive() is called, the CL_IRCConnection will emit the
//- signals for those commands received.</p>
//- <p>Most IRC networks will expect the connecting IRC client to first send
//- a "nick" command and then a "user" command, as part of the logon
//- process. CL_IRCConnection will not do this, so the general logon
//- procedure looks somewhat like this:</p>
//- <pre>
//- CL_IRCConnection connection("irc.freenode.net", "6667");
//- connection.send_nick("MyNick");
//- connection.send_user("username", "our.hostname", "irc.freenode.net", "User Name");
//- </pre>
//- <p>IRC servers will occationally send a "ping" line, which have to be
//- replied with a "pong" command. If this isn't done within some server
//- specific timeout, the IRC network will disconnect the client.
//- CL_IRCConnection will also not do this automatically, so its important
//- you at least hook up the ping slot, to a function looking like this:</p>
//- <pre>
//- void on_ping(const std::string &daemon1, const std::string &daemon2)
//- { connection.send_pong(daemon1, daemon2); }
//- </pre>
class CL_API_NETWORK CL_IRCConnection
{
//! Construction:
public:
//: Constructs a CL_IRCConnection and connects a server.
//param server: IRC server host name. Ie. "irc.freenode.net".
//param port: IRC server port. Defaults to "6667".
CL_IRCConnection();
CL_IRCConnection(const std::string &server, const std::string &port = "6667");
CL_IRCConnection(const CL_IRCConnection ©);
~CL_IRCConnection();
//! Attributes:
public:
//: Returns our current nick name.
const std::string &get_nick() const;
//: Returns the username passed to send_user.
const std::string &get_username() const;
//: Returns hostname passed to send_user.
const std::string &get_hostname() const;
//: Returns server name passed to send_user.
const std::string &get_servername() const;
//: Returns the real name passed to send_user.
const std::string &get_realname() const;
//! Operations:
public:
CL_IRCConnection &operator =(const CL_IRCConnection ©);
//: Send command to IRC server.
//param prefix: Sender prefix.
//param command: IRC command.
//param params: List of parameters for IRC command.
//- <p>This is the low-level IRC send command. Useful if you need to
//- send a command not supported by the other higher level send
//- functions.</p>
void send_command(const std::string &prefix, const std::string &command, const std::vector<std::string> ¶ms);
//: Send password.
//param password: Password parameter to send with "pass" command.
//- <p>Sends a "pass" command to IRC server.</p>
void send_pass(const std::string &password);
//: Send nick.
//param nick: Nick name to use.
//param hopcount: Can't remember. Check the RFC. :-)
//- <p>Sets or changes your nick.</p>
void send_nick(const std::string &nick, int hopcount = -1);
//: Send user login/identify command.
//param username: Client username.
//param hostname: Client hostname.
//param servername: Hostname of IRC server.
//param realname: Real name of client user.
//- <p>This command identifies the IRC client to the IRC network.
//- Each of the parameters passsed will be used to create your fully
//- qualified prefix on the network.</p>
void send_user(const std::string &username, const std::string &hostname, const std::string &servername, const std::string &realname);
//: Send operator login command
//param user: Operator login name.
//param password: Operator password.
void send_oper(const std::string &user, const std::string &password);
//: Send quit command.
void send_quit(const std::string &quitmessage = "");
//: Send join channel command.
//param channel: Channel to join, ie. "#clanlib"
//param key: Channel key, if any.
//param channels: List of channels to join.
//param keys: List of channel keys.
void send_join(const std::string &channel, const std::string &key = "");
void send_join(const std::list<std::string> &channels, const std::list<std::string> &keys);
//: Send part channel command.
//param channel: Channel to leave.
//param reason: Reason for leaving.
//param channels: List of channels to leave.
void send_part(const std::string &channel, const std::string &reason = "");
void send_part(const std::list<std::string> &channels, const std::string &reason = "");
//: Send set mode command.
//param target: Channel or nick mode change apply to.
//param mode: Mode change to perform, ie. "+o".
//param args: Arguements to mode command.
void send_mode(const std::string &target, const std::string &mode, const std::vector<std::string> &args);
//: Set/Get topic on channel.
//param channel: Channel name.
//param topic: New topic to be set.
//- <p>If no topic is specified, this will make the IRC server send
//- back what the topic is on a given channel.</p>
void send_topic(const std::string &channel, const std::string &topic);
void send_topic(const std::string &channel);
//: List nicks on channel(s).
//param channel: Channel to list.
void send_names(const std::string &channel = "");
void send_names(const std::list<std::string> &channels);
//: Send list of channels.
//param channel: Channel name substring to match.
//param server: Server to limit results from.
void send_list(const std::string &channel = "", const std::string &server = "");
void send_list(const std::list<std::string> &channels, const std::string &server = "");
//: Send channel join invitation.
//param nickname: Nick to receive invitation.
//param channel: Channel being invited to.
void send_invite(const std::string &nickname, const std::string &channel);
//: Send kick command
void send_kick(const std::string &channel, const std::string &user, const std::string &comment = "");
void send_kick(const std::list<std::string> &channels, const std::list<std::string> &users, const std::string &comment = "");
//: Send version command.
void send_version(const std::string &server = "");
//: Send statistics command.
void send_stats(const std::string &query = "", const std::string &server = "");
//: Send links command.
void send_links(const std::string &remote_server = "", const std::string &server_mask = "");
//: Send time command.
void send_time(const std::string &server = "");
//: Send connect command.
void send_connect(const std::string &target_server, int port = 0, const std::string &remote_server = "");
//: Send trace command.
void send_trace(const std::string &server = 0);
//: Send admin command.
void send_admin(const std::string &server = 0);
//: Send info command.
void send_info(const std::string &server = 0);
//: Send channel message or private message.
//param reciver: Channel or nick to receive message.
//param text: Message to send.
void send_privmsg(const std::string &receiver, const std::string &text);
void send_privmsg(const std::list<std::string> &receivers, const std::string &text);
//: Send Client To Client Protocol (CTCP) message.
//param reciver: Channel or nick to receive message.
//param command: CTCP command.
//param data: CTCP data.
void send_privmsg_ctcp(const std::string &receiver, const std::string &command, const std::string &data);
void send_privmsg_ctcp(std::list<std::string> &receivers, const std::string &command, const std::string &data);
//: Send notice message.
//param nickname: Nick to receive notice.
//param text: Notice to send.
void send_notice(const std::string &nickname, const std::string &text);
//: Send Client To Client Protocol (CTCP) notice.
//param nickname: Nick to receive notice.
//param command: CTCP command.
//param data: CTCP data.
void send_notice_ctcp(const std::string &nickname, const std::string &command, const std::string &data);
//: Send who command.
//param name: Nick to retrieve information about.
//param oper: If set to true, use IRC operator rights.
void send_who(const std::string &name, bool oper = false);
//: Send whois command.
//param nickmask: Nick to retrieve information about
//param server: Server to query.
void send_whois(const std::string &nickmask);
void send_whois(const std::string &server, const std::string &nickmask);
void send_whois(const std::list<std::string> &nickmasks);
void send_whois(const std::string &server, const std::list<std::string> &nickmasks);
//: Send whowas command.
//param nickname: Nick to retrieve information about
//param count: Amount of users with that nick to get information about.
//param server: Server to query.
void send_whowas(const std::string &nickname, int count = 0, const std::string &server = "");
//: Send kill command.
//param nickname: Nick to kill.
//param comment: Reason given for killing nick.
void send_kill(const std::string &nickname, const std::string &comment);
//: Send ping command
//param server: Server to send to.
//param server2: Server to relay through.
void send_ping(const std::string &server, const std::string &server2 = "");
//: Send pong command
//param daemon: Server that sent ping command.
//param daemon2: Server ping command was relayed through.
void send_pong(const std::string &daemon, const std::string &daemon2 = "");
//: Extracts nick part of a fully qualified IRC prefix.
static std::string extract_nick(const std::string &str);
//: Extracts user part of a fully qualified IRC prefix.
static std::string extract_user(const std::string &str);
//: Extracts address part of a fully qualified IRC prefix.
static std::string extract_address(const std::string &str);
//! Signals:
public:
//: sig_socket_error(error_message)
CL_Signal_v1<const std::string &> &sig_socket_error();
//: sig_command_received(prefix, command, params)
CL_Signal_v3<const std::string &, const std::string &, const std::vector<std::string> &> &sig_command_received();
//: sig_unknown_command_received(prefix, command, params)
CL_Signal_v3<const std::string &, const std::string &, const std::vector<std::string> &> &sig_unknown_command_received();
//: sig_numeric_reply(prefix, code, params)
CL_Signal_v3<const std::string &, int, const std::vector<std::string> &> &sig_numeric_reply();
//: sig_name_reply(self, channel, users)
CL_Signal_v3<const std::string &, const std::string &, const std::vector<std::string> &> &sig_name_reply();
//: sig_nick(old_nick, new_nick)
CL_Signal_v2<const std::string &, const std::string &> &sig_nick();
//: sig_join(nick, channel)
CL_Signal_v2<const std::string &, const std::string &> &sig_join();
//: sig_part(nick, channel, reason)
CL_Signal_v3<const std::string &, const std::string &, const std::string &> &sig_part();
//: sig_mode(prefix, receiver, mode, params)
CL_Signal_v4<const std::string &, const std::string &, const std::string &, const std::vector<std::string> &> &sig_mode();
//: sig_topic(prefix, channel, topic)
CL_Signal_v3<const std::string &, const std::string &, const std::string &> &sig_topic();
//: sig_invite(prefix, nick, channel)
CL_Signal_v3<const std::string &, const std::string &, const std::string &> &sig_invite();
//: sig_kick(prefix, chan, user, comment)
CL_Signal_v4<const std::string &, const std::string &, const std::string &, const std::string &> &sig_kick();
//: sig_privmsg(prefix, receiver, text)
CL_Signal_v3<const std::string &, const std::string &, const std::string &> &sig_privmsg();
//: sig_notice(prefix, receiver, text)
CL_Signal_v3<const std::string &, const std::string &, const std::string &> &sig_notice();
//: sig_privmsg_ctcp(prefix, receiver, command, data)
CL_Signal_v4<const std::string &, const std::string &, const std::string &, const std::string &> &sig_privmsg_ctcp();
//: sig_notice_ctcp(prefix, receiver, command, data)
CL_Signal_v4<const std::string &, const std::string &, const std::string &, const std::string &> &sig_notice_ctcp();
//: sig_ping(daemon1, daemon2)
CL_Signal_v2<const std::string &, const std::string &> &sig_ping();
//! Implementation:
private:
CL_IRCConnection_Generic *impl;
};
#endif
|