Would you like to make this site your homepage? It's fast and easy...
Yes, Please make this my home page!
/***************************************************************************
*
* File: IRCModule.h
* Created: Sat Dec 4 1999
* (C) 1999 by David M. <captjay@superlink.net>
*
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef IRCMODULE_H
#define IRCMODULE_H
#include <qstring.h>
#include <qobject.h>
#include <qtimer.h>
#include "numeric.h"
//## end module.includes
// Channels
#include "Ban.h"
#include "Channels.h"
#include "Channel.h"
#include "ChanUser.h"
#include "IRCMessage.h"
class Socket;
class ClientSocket;
QString LongToIP(unsigned long longip);
/**
* @author David M.
* @short Handle a client connection to an Internet Relay Chat Server.
*
* Handles a client-side connection to an IRC server. This class uses various signals to notify
* other objects of events that occured on the IRC connection, such as joins, parts, quits, etc.
* It uses a @ref ClientSocket as its communication link to the server.
*
* NOTE: In this page, the "client" refers to the object currently being used as a connection to
* an IRC server. a "user" refers to any user on IRC, wether the client or another user.
* @see ClientSocket,Channels,Channel,ChanUser,Ban
*/
class IRCModule : public QObject {
Q_OBJECT
public:
IRCModule();
~IRCModule();
/**
* Attempt to connect to the specified server and port, with
* nickname and ident specified by values in parameter.
*
* If the connect is succesful, a onConnect event is
* generated. Note that a connection could be succesful, but the client disconnected afterwards,
* for instance if it is K-lined. In that case, an onConnected event will be generated, followed by
* an onDisconnect event when the server breaks the connection.
*
* PRECONDITIONS: !isConnected() ; serverName != "" ; serverPort > 1024 ; nick != "" ; ident != "" ;
* realName != ""
*
* @return true if a connection was established, false otherwise.
* @param serverName Hostname or IP of the server to connect to.
* @param serverPort TCP port to use to establish connection.
* @param nick Nickname to give the server when connecting. If that nickname is in use, the IRCModule will
* use variations on the nick until it can connect.
* @param ident Ident to use when connecting. If you have identd active, this value will be ignored
* by the server.
* @param realName Text to be placed in the client's real name field.
*/
bool connectTo(QString serverName, int serverPort, QString nick, QString ident, QString realName);
/**
* Set a specified mode on a channel.
* No checking is done on the mode, so it should be a mode the server can understand.
* The mode will also be sent regardless if the client is currently oped or not
* on that channel.
*
* PRECONDITIONS: isConnected()
*
*/
void setMode(QString channel, QString mode);
/**
* Send text to dest in PRIVMSG format. Use this method
* to send text to both channels and users.
*
* PRECONDITIONS: isConnected()
*
* @param dest Nickname or channel to send the message to.
* @param text Message text to send to the destination.
*/
void sendPrivmsg(QString dest, QString text);
/**
* Send text to dest in NOTICE format. Use this method
* to send text to both channels and users
* (although NOTICE'ing whole channels is usually not a good idea)
*
* PRECONDITIONS: isConnected()
*
* @param dest Nickname or channel to send the notice to.
* @param text Notice text to send to the destination.
*/
void sendNotice(QString dest, QString text);
/**
* Set a specified user mode on the client.
*
* User modes are not supported by the IRCModule, but it provides
* functionality for clients to support it.
*
* @param mode The mode to set.
*/
void setUserMode(QString mode);
/**
* Determine wether a succesful connection is currently active with an IRC server.
* @return true if the client is currently connected to a server, false otherwise.
*/
bool isConnected() const;
/**
* Make the client join a specified channel with a
* key if necessary. This method only sends the join
* command. an onJoin() event will be generated if its
* succesful, or the appropriate error numerics returned in
* an onNumeric() event.
*
* Requesting to join a channel that was already joined is
* an error.
*
* PRECONDITIONS: isConnected() ; !isOn(channel)
* @param channel Name of the channel to join.
* @param key Key to use to join the channel, if required.
*/
void join(QString channel, QString key = "");
/**
* Request that the client leave a channel in which it
* currently is.
*
* PRECONDITIONS : isConnected() ; isOn(channel)
* @param channel Name of the channel to part.
* @partComment Part comment to use, if desired.
*/
void part(QString channel, QString partComment = "");
/** Determine if the client is currently on a particular channel.
*
* @return true if the client is currently on the specified
* channel, false otherwise.
*
* PRECONDITIONS: isConnected()
*/
bool isOn(QString channel);
/*
* Send a kick command to the IRC server for the specified
* channel and user. The kick is sent regardless of wether
* the client is currently oped on the channel.
*
* PRECONDITIONS: isConnected()
*/
void kick(QString channel, QString nickname, QString comment);
/**
* Make the client quit IRC with the comment specified.
* The comment "Leaving" is used if no comment if given.
*
* PRECONDITIONS: isConnected()
*
*/
void quit(QString quitComment = "Leaving");
/**
* Determines if the client is currently oped on a specified
* channel. the client must be in that channel before calling
* this method.
*
* PRECONDITIONS: isConnected() ; isOn(channel)
*
* @return true if the client is oped on the given channel, false otherwise.
*/
bool isOpedOn(QString channel);
/**
*
* Access the client's internal channel list. This list contains information about
* the channels the client is on, including channel modes, userlists, user hosts
* if available, etc.
*
* @return A const reference to the internal channel list.
*
* @see Channels
*/
const Channels& channels() const;
/**
* Get the current nickname of the client.
*
* @return The current client's nickname.
*/
const QString& getNick() const;
/**
* Determine if a string is a valid channel name.
* A channel name is valid if it begins with either a #, & or + and it
* does not contain any whitespace.
*
* @return true if the string is a valid channel name, false otherwise.
*
*/
static bool isChannelName(const QString& nick);
/**
* Determine if a string is a valid server name.
* A server name contains at least one '.'.
*
* @return true if the string is a valid server name, false otherwise.
*/
static bool isServerName(const QString& name);
signals:
/**
* an onConnect signal is emitted when the client succesfully connected to a server.
* @param serverName The name of the server to which the connection was established.
* @param nickname The nick of the client on that server.
*/
void onConnect(QString serverName, QString nickname);
/**
* Emitted when a user sends a CTCP request to a channel the client is on.
*
* Note: CTCP's include ACTIONs.
*
* @param nick The nickname of the user who sent the CTCP.
* @param channel A pointer to the channel to which the CTCP was sent.
* @param ctcpType A string containing the CTCP's "type" (VERSION, PING, ACTION, etc).
* @param ctcpText A string containing the rest of the CTCP request. In other words, any text after
* CTCP type is contained in the ctcpText parameter.
* @see ChanUser
* @see Channel
*/
void onChannelCTCP(QString nick,const Channel* channel, QString ctcpType, QString ctcpText);
/**
* Emitted when the client receives a CTCP reply.
*
* This signal applies for replies directed to channels AND private replies. The dest
* parameter specifies where the reply was sent to.
*
* Note: channel-wide ctcp replies are unlikely.
*
* @param nuh nick!user@host of the user sending the reply.
* @param dest nick or channel to which the reply was sent.
* @param ctcpType CTCP type of the reply, e.g. PING, VERSION, etc.
* @param ctcpText Parameters of the reply.
*
*/
void onCTCPReply(QString nuh,QString dest, QString ctcpType, QString ctcpText);
/**
* Emitted when a user sends a regular message (PRIVMSG) to a channel the client is on.
*
* Note: This event does not include notices.
*
* @param nick The nickname of the user who sent the channel message.
* @param channel A pointer to the channel to which the message was sent.
* @param text A string containing the text of the message.
*
* @see ChanUser
* @see Channel
*/
void onChannelText(QString nick,const Channel* channel, QString text);
/**
* Emitted when a user sends a notice to a channel the client is on.
*
* @param nick The nickname of the user who sent the notice.
* @param channel A pointer to the channel to which the notice was sent.
* @param text A string containing the text of the notice.
*
*/
void onChannelNotice(QString nick,const Channel* channel, QString text);
/**
* Emitted when the client is disconnected from the server. This signal will be emitted
* when the connection terminates, regardless of the cause of disconnection. Calling @ref quit()
* results in an onDisconnect event when the server drops the connection.
*/
void onDisconnect();
/**
* Emitted when the client receives an ERROR message from the server. Such messages include
* K-lines, kills, server full, etc.
*
* @param errorMessage A string containing the full text the server included with the
* ERROR message.
*/
void onError(QString errorMessage);
/**
* Emitted when a user joins a channel. This signal is also emitted when
* the client joins a channel through the @ref join() method.
*
* @param nick The nickname of the user who joined.
* @param channel A pointer to the channel on which the join occured.
*
* @see ChanUser
* @see Channel
*/
void onJoin(QString nick,const Channel* channel);
/**
* Emitted when a user is kicked from a channel.
*
* @param from The nick of the user who sent the kick. Note that this
* can also be a server name.
* @param channel A pointer to the channel on which the kick occured. If the user
* getting kicked is the client, that pointer is no longer valid
* outside the scope of this event.
* @param kicked The nickname of the user who got kicked.
* @param comment The kick comment.
*
*/
void onKick(QString from, const Channel* channel, QString kicked, QString comment);
/**
* Emitted when a user on a common channel with the client, or the client itself changes nicknames.
*
* @param nick The previous nick of the user.
* @param newNick The new nick of the user.
*/
void onNickChange(QString nick,QString newNick);
/**
* Emitted when a user parts a channel. This signal is also emitted when
* the client parts a channel through the part() method.
*
* @param nick The nickname of the user who left the channel
* @param channel A pointer to the channel on which the join occured.
* @param comment A string containing the part comment, if any.
*
*/
void onPart(QString nick,const Channel* channel,QString comment);
/**
* Emitted when a user sends a CTCP request to the client directly (not a channel
* the client is on).
*
* @param nick The nickname of the user sending the CTCP request.
* @param ctcpType A string containing the type of the CTCP request (VERSION, PING, etc).
* @param ctcpText Any text after the ctcpType will be included in this string.
*
* @see onChannelCTCP
*/
void onPrivateCTCP(QString nick,QString ctcpType, QString ctcpText);
/**
* Emitted when a user sends a private message to the client directly (not a channel
* the client is on).
*
* @param nuh The nick!user@host of the user sending the message.
* @param text The text contained in the message.
*
* @see onChannelText
*/
void onPrivateText(QString nuh,QString text);
/**
* Emitted when a user sends a private notice to the client directly (not a channel
* the client is on).
*
* @param nuh The nick!user@host of the user sending the notice.
* @param text The text contained in the notice.
*
* @see onChannelNotice
*/
void onPrivateNotice(QString nuh,QString text);
/**
* Emitted when the client recieves a notice from the server.
*
* @param serverName The name of the server sending the notice.
* @param text The text contained in the notice.
*
*/
void onServerNotice(QString serverName,QString text);
/**
* Emitted when the client recieves a PING request from the server.
* The IRCModule replies to PING requests properly. There is no need
* to manually send a PONG reply when this signal occurs.
*/
void onPing();
/**
* Emitted when a user on a common channel with the client quits IRC.
*
* @param nuh nick!username@host of the user that left IRC.
* @param comment The quit message.
*/
void onQuit(QString nuh, QString comment);
/**
* Emitted when a numeric reply is received from the server.
*
* @param numeric The numeric number of the reply. see numeric.h
* @param message a raw IRCMessage containing the reply
* as recieved from the server.
*
*/
void onRawNumeric(int numeric, const IRCMessage& message);
/**
* Emitted when a user mode change is recieved. The IRCModule does not
* handle user modes, but provides this signal to allow clients to keep
* up to date with the current user modes.
*
* @param mode A string containing the mode change, as recieved from the server.
*/
void onUserModeChange(QString mode);
// Channel mode change events
/**
* Emitted on a mode +b on a channel.
*
* @param from A string containing the nick of the user who set the mode,
* or the name of the server in case of the server mode.
* @param channel A pointer to the channel on which the mode change occured.
* @param mask A string containing the ban mask that was added.
*/
void onBan(QString from, const Channel* channel, QString mask);
/**
* Emitted on a mode -b on a channel.
*
* @param from A string containing the nick of the user who set the mode,
* or the name of the server in case of the server mode.
* @param channel A pointer to the channel on which the mode change occured.
* @param mask A string containing the ban mask that was removed.
*/
void onUnban(QString from, const Channel* channel, QString mask);
/**
* Emitted on mode +o on a channel.
*
* @param from A string containing the nick of the user who set the mode,
* or the name of the server in case of a server mode.
* @param channel A pointer the the channel on which the mode change occured.
* @param dest A pointer to the ChanUser object of the user who was given ops.
*/
void onOp(QString from,const Channel* channel, const ChanUser* dest);
/**
* Emitted on mode -o on a channel.
*
* @param from A string containing the nick of the user who set the mode,
* or the name of the server in case of a server mode.
* @param channel A pointer the the channel on which the mode change occured.
* @param dest A pointer to the ChanUser object of the user who was deoped.
*/
void onDeop(QString from,const Channel* channel, const ChanUser* dest);
/**
* Emitted on mode +v on a channel.
*
* @param from A string containing the nick of the user who set the mode,
* or the name of the server in case of a server mode.
* @param channel A pointer the the channel on which the mode change occured.
* @param dest A pointer to the ChanUser object of the user who was voiced.
*/
void onVoice(QString from,const Channel* channel, const ChanUser* dest);
/**
* Emitted on mode -v on a channel.
*
* @param from A string containing the nick of the user who set the mode,
* or the name of the server in case of a server mode.
* @param channel A pointer the the channel on which the mode change occured.
* @param dest A pointer to the ChanUser object of the user who was devoiced.
*/
void onDevoice(QString from,const Channel* channel, const ChanUser* dest);
/**
* Emitted on channel-specific modes (t,n,m,i,l,k,s,p).
* This signal is emitted once per mode change. For instance, a mode +tn generates
* two onChanModeChange signals, one for +t, and one for +n
*
* @param from A string containing the nick!user@host of the user who set the mode,
* or the name of the server in case of a server mode.
* @param mode A string containing the mode change. The mode is preceded by a '+'
* if the mode was added, or a '-' if the mode was removed.
*/
void onChanModeChange(QString from,const Channel* channel, QString mode);
/**
* Emitted on any channel mode change, once per MODE message received from the server.
* This signal is provided for clients who want to display the mode change in one
* string, as recieved from the server.
*
* @param from A string containing the nick!user@host of the user who set the mode,
* or the name of the server in case of a server mode.
* @param channel A pointer the the channel on which the mode change occured.
* @param mode A string containing the mode change, exactly as recieved from the server.
*/
void onRawChannelMode(QString from, const Channel* channel, QString mode);
private slots:
void onDataWaiting(Socket* socket);
void onSocketDisconnect(Socket* socket);
private: //## implementation
void authenticate(const QString& nick,const QString& ident, const QString& realName );
void handleMessage(const QString& message);
void handleNumeric(const IRCMessage& message);
void handleNonNumeric(const IRCMessage& message);
//numeric reply handlers
void handleWelcome(const IRCMessage& message);
void handleWho(const IRCMessage& message);
void handleNames(const IRCMessage& message);
void handleChanModeIs(const IRCMessage& message);
void handleChanBanlistIs(const IRCMessage& message);
void handleNickInUse(const IRCMessage& message);
// non-numeric reply handlers
void handleCTCP(const IRCMessage& message);
void handleError(const IRCMessage& message);
void handleJoin(const IRCMessage& message);
void handleModeChange(const IRCMessage& message);
void handleChannelModeChange(const IRCMessage& message);
void handleNickChange(const IRCMessage& message);
void handleKick(const IRCMessage& message);
void handlePart(const IRCMessage& message);
void handlePrivMsg(const IRCMessage& message);
void handleNotice(const IRCMessage& message);
void handleCTCPReply(const IRCMessage& message);
void handleQuit(const IRCMessage& message);
void handlePing(const IRCMessage& message);
void handleDisconnect();
QString nickVariant(const QString& nickname);
// Private attributes
Channels* _channels;
ClientSocket* _clientSocket;
QTimer _nickTimer;
QString _currentServer;
QString _myNick;
QString _desiredNick;
};
// Class IRCModule
#endif
Generated by: nightsky@centauri on Sat Jan 15 23:06:10 2000, using kdoc 2.0a30. |