⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 idirc.pas

📁 Indy控件的使用源代码
💻 PAS
📖 第 1 页 / 共 5 页
字号:
    Part                  Part channel/s with an optional reason (if supported
                          by the IRC server).
    Kick                  Kick a person from a channel.
    Quit                  Quit the IRC network.
    CTCP                  Send a CTCP command to a user/channel.
    CTCPReply             Send a reply to a CTCP command.
    IsChannel             Returns True if the name is a channel name.
    IsOp                  Returns True if the user has operator status.
    IsVoice               Returns True if the user has a voice.
    MatchHostmask         Returns True if the address matches the hostmask.
    GetTopic              Get the topic for the specified channel.
    SetTopic              Set the topic for the specifiec channel.

  Methods to be added later:
    Ban                   Ban hostmask/s from a channel.
    Unban                 Unban hostmask/s from a channel.
    Op                    Op nick/s in a channel.
    Deop                  Deop nick/s in a channel.
    Voice                 Give a voice to nick/s.
    Devoice               Take voice from nick/s.
    Invite                Invite someone to a channel.
    DCCChat               Initiate a DCC chat.
    DCCSend               Initiate a DCC send of a file.
}

interface

uses
  Classes, IdAssignedNumbers, IdBaseComponent, IdComponent, IdTCPConnection,
  IdException, IdTCPClient, IdThread, IdStack, IdGlobal;

const
  { Numerics as defined in RFC1459. }
  RPL_TRACELINK	        =	200	;	{	Link <version & debug level> <destination> <next server> }
  RPL_TRACECONNECTING	  =	201	;	{	Try. <class> <server> }
  RPL_TRACEHANDSHAKE	  =	202	;	{	H.S. <class> <server> }
  RPL_TRACEUNKNOWN	    =	203	;	{	???? <class> [<client IP address in dot form>] }
  RPL_TRACEOPERATOR	    =	204	;	{	Oper <class> <nick> }
  RPL_TRACEUSER	        =	205	;	{	User <class> <nick> }
  RPL_TRACESERVER	      =	206	;	{	Serv <class> <int>S <int>C <server> <nick!user|*!*>@<host|server> }
  RPL_TRACENEWTYPE	    =	208	;	{	<newtype> 0 <client name> }
  RPL_STATSLINKINFO	    =	211	;	{	<linkname> <sendq> <sent messages> <sent bytes> <received messages> <received bytes> <time open> }
  RPL_STATSCOMMANDS	    =	212	;	{	<command> <count> }
  RPL_STATSCLINE	      =	213	;	{	C <host> * <name> <port> <class> }
  RPL_STATSNLINE	      =	214	;	{	N <host> * <name> <port> <class> }
  RPL_STATSILINE	      =	215	;	{	I <host> * <host> <port> <class> }
  RPL_STATSKLINE	      =	216	;	{	K <host> * <username> <port> <class> }
  RPL_STATSYLINE	      =	218	;	{	Y <class> <ping frequency> <connect frequency> <max sendq> }
  RPL_ENDOFSTATS	      =	219	;	{	<stats letter> :End of /STATS report }
  RPL_UMODEIS	          =	221	;	{	<user mode string> }
  RPL_STATSLLINE	      =	241	;	{	L <hostmask> * <servername> <maxdepth> }
  RPL_STATSUPTIME	      =	242	;	{	:Server Up %d days %d:%02d:%02d }
  RPL_STATSOLINE	      =	243	;	{	O <hostmask> * <name> }
  RPL_STATSHLINE	      =	244	;	{	H <hostmask> * <servername> }
  RPL_LUSERCLIENT	      =	251	;	{	:There are <integer> users and <integer> invisible on <integer> servers }
  RPL_LUSEROP	          =	252	;	{	<integer> :operator(s) online }
  RPL_LUSERUNKNOWN	    =	253	;	{	<integer> :unknown connection(s) }
  RPL_LUSERCHANNELS	    =	254	;	{	<integer> :channels formed }
  RPL_LUSERME	          =	255	;	{	:I have <integer> clients and <integer> servers }
  RPL_ADMINME	          =	256	;	{	<server> :Administrative info }
  RPL_ADMINLOC1	        =	257	;	{	:<admin info> }
  RPL_ADMINLOC2	        =	258	;	{	:<admin info> }
  RPL_ADMINEMAIL	      =	259	;	{	:<admin info> }
  RPL_TRACELOG	        =	261	;	{	File <logfile> <debug level> }
  RPL_NONE	            =	300	;	{	Dummy reply number. Not used. }
  RPL_AWAY	            =	301	;	{	<nick> :<away message> }
  RPL_USERHOST	        =	302	;	{	:[<reply><space><reply>] }
  RPL_ISON	            =	303	;	{	:[<nick> <space><nick>] }
  RPL_UNAWAY	          =	305	;	{	:You are no longer marked as being away }
  RPL_NOWAWAY	          =	306	;	{	:You have been marked as being away }
  RPL_WHOISUSER	        =	311	;	{	<nick> <user> <host> * :<real name> }
  RPL_WHOISSERVER	      =	312	;	{	<nick> <server> :<server info> }
  RPL_WHOISOPERATOR	    =	313	;	{	<nick> :is an IRC operator }
  RPL_WHOWASUSER	      =	314	;	{	<nick> <user> <host> * :<real name> }
  RPL_ENDOFWHO	        =	315	;	{	<name> :End of /WHO list }
  RPL_WHOISIDLE	        =	317	;	{	<nick> <integer> :seconds idle }
  RPL_ENDOFWHOIS	      =	318	;	{	<nick> :End of /WHOIS list }
  RPL_WHOISCHANNELS	    =	319	;	{	<nick> :[@|+]<channel><space> }
  RPL_LISTSTART	        =	321	;	{	Channel :Users  Name }
  RPL_LIST	            =	322	;	{	<channel> <# visible> :<topic> }
  RPL_LISTEND	          =	323	;	{	:End of /LIST }
  RPL_CHANNELMODEIS	    =	324	;	{	<channel> <mode> <mode params> }
  RPL_NOTOPIC	          =	331	;	{	<channel> :No topic is set }
  RPL_TOPIC	            =	332	;	{	<channel> :<topic> }
  RPL_INVITING	        =	341	;	{	<channel> <nick> }
  RPL_SUMMONING	        =	342	;	{	<user> :Summoning user to IRC }
  RPL_VERSION	          =	351	;	{	<version>.<debuglevel> <server> :<comments> }
  RPL_WHOREPLY	        =	352	;	{	<channel> <user> <host> <server> <nick> <H|G>[*][@|+] :<hopcount> <real name> }
  RPL_NAMREPLY	        =	353	;	{	<channel> :[[@|+]<nick> [[@|+]<nick> [...]]] }
  RPL_LINKS	            =	364	;	{	<mask> <server> :<hopcount> <server info> }
  RPL_ENDOFLINKS	      =	365	;	{	<mask> :End of /LINKS list }
  RPL_ENDOFNAMES	      =	366	;	{	<channel> :End of /NAMES list }
  RPL_BANLIST	          =	367	;	{	<channel> <banid> }
  RPL_ENDOFBANLIST	    =	368	;	{	<channel> :End of channel ban list }
  RPL_ENDOFWHOWAS	      =	369	;	{	<nick> :End of WHOWAS }
  RPL_INFO	            =	371	;	{	:<string> }
  RPL_MOTD	            =	372	;	{	:- <text> }
  RPL_ENDOFINFO	        =	374	;	{	:End of /INFO list }
  RPL_MOTDSTART	        =	375	;	{	":- <server> Message of the day -," }
  RPL_ENDOFMOTD	        =	376	;	{	:End of /MOTD command }
  RPL_YOUREOPER	        =	381	;	{	:You are now an IRC operator }
  RPL_REHASHING	        =	382	;	{	<config file> :Rehashing }
  RPL_TIME	            =	391	;	{ }
  RPL_USERSSTART	      =	392	;	{	:UserID   Terminal  Host }
  RPL_USERS	            =	393	;	{	:%-8s %-9s %-8s }
  RPL_ENDOFUSERS	      =	394	;	{	:End of users }
  RPL_NOUSERS	          =	395	;	{	:Nobody logged in }
  ERR_NOSUCHNICK	      =	401	;	{	<nickname> :No such nick/channel }
  ERR_NOSUCHSERVER	    =	402	;	{	<server name> :No such server }
  ERR_NOSUCHCHANNEL	    =	403	;	{	<channel name> :No such channel }
  ERR_CANNOTSENDTOCHAN	=	404	;	{	<channel name> :Cannot send to channel }
  ERR_TOOMANYCHANNELS	  =	405	;	{	<channel name> :You have joined too many channels }
  ERR_WASNOSUCHNICK	    =	406	;	{	<nickname> :There was no such nickname }
  ERR_TOOMANYTARGETS	  =	407	;	{	<target> :Duplicate recipients. No message delivered }
  ERR_NOORIGIN	        =	409	;	{	:No origin specified }
  ERR_NORECIPIENT	      =	411	;	{	:No recipient given (<command>) }
  ERR_NOTEXTTOSEND	    =	412	;	{	:No text to send }
  ERR_NOTOPLEVEL	      =	413	;	{	<mask> :No toplevel domain specified }
  ERR_WILDTOPLEVEL	    =	414	;	{	<mask> :Wildcard in toplevel domain }
  ERR_UNKNOWNCOMMAND	  =	421	;	{	<command> :Unknown command }
  ERR_NOMOTD	          =	422	;	{	:MOTD File is missing }
  ERR_NOADMININFO	      =	423	;	{	<server> :No administrative info available }
  ERR_FILEERROR	        =	424	;	{	:File error doing <file op> on <file> }
  ERR_NONICKNAMEGIVEN	  =	431	;	{	:No nickname given }
  ERR_ERRONEUSNICKNAME	=	432	;	{	<nick> :Erroneus nickname }
  ERR_NICKNAMEINUSE	    =	433	;	{	<nick> :Nickname is already in use }
  ERR_NICKCOLLISION	    =	436	;	{	<nick> :Nickname collision KILL }
  ERR_USERNOTINCHANNEL	=	441	;	{	<nick> <channel> :They aren't on that channel }    {Do not Localize}
  ERR_NOTONCHANNEL	    =	442	;	{	<channel> :You're not on that channel }    {Do not Localize}
  ERR_USERONCHANNEL	    =	443	;	{	<user> <channel> :is already on channel }
  ERR_NOLOGIN	          =	444	;	{	<user> :User not logged in }
  ERR_SUMMONDISABLED	  =	445	;	{	:SUMMON has been disabled }
  ERR_USERSDISABLED	    =	446	;	{	:USERS has been disabled }
  ERR_NOTREGISTERED	    =	451	;	{	:You have not registered }
  ERR_NEEDMOREPARAMS	  =	461	;	{	<command> :Not enough parameters }
  ERR_ALREADYREGISTRED	=	462	;	{	:You may not reregister }
  ERR_NOPERMFORHOST	    =	463	;	{	:Your host isn't among the privileged }    {Do not Localize}
  ERR_PASSWDMISMATCH	  =	464	;	{	:Password incorrect }
  ERR_YOUREBANNEDCREEP	=	465	;	{	:You are banned from this server }
  ERR_KEYSET	          =	467	;	{	<channel> :Channel key already set }
  ERR_CHANNELISFULL	    =	471	;	{	<channel> :Cannot join channel (+l) }
  ERR_UNKNOWNMODE	      =	472	;	{	<char> :is unknown mode char to me }
  ERR_INVITEONLYCHAN	  =	473	;	{	<channel> :Cannot join channel (+i) }
  ERR_BANNEDFROMCHAN	  =	474	;	{	<channel> :Cannot join channel (+b) }
  ERR_BADCHANNELKEY	    =	475	;	{	<channel> :Cannot join channel (+k) }
  ERR_NOPRIVILEGES	    =	481	;	{	:Permission Denied- You're not an IRC operator }    {Do not Localize}
  ERR_CHANOPRIVSNEEDED	=	482	;	{	<channel> :You're not channel operator }    {Do not Localize}
  ERR_CANTKILLSERVER	  =	483	;	{	:You cant kill a server! }
  ERR_NOOPERHOST	      =	491	;	{	:No O-lines for your host }
  ERR_UMODEUNKNOWNFLAG	=	501	;	{	:Unknown MODE flag }
  ERR_USERSDONTMATCH	  =	502	;	{	:Cant change mode for other users }

type
  { TIdIRCUser }

  TIdIRC = class;

  //TODO: This needs to be a TCollecitonItem
  TIdIRCUser = class(TCollectionItem)
  protected
    FClient: TIdIRC;
    FNick: String;
    FAddress: String;
    FData: TObject;
    FReason: String;
  public
    Count: Integer;
    constructor Create(AClient: TIdIRC; ANick, AAddress: String); reintroduce;
    destructor Destroy; override;
    procedure Say(AMsg: String);
    property Nick: String read FNick write FNick;
    property Address: String read FAddress write FAddress;
    property Data: TObject read FData write FData;
    property Reason: String read FReason write FReason;
  end;

  { TIdIRCUsers }
  TIdIRCSortCompareUsers = procedure (Sender :TObject;
    AItem1, AItem2 : TIdIRCUser; var AResult : Integer);
  //TODO: This needs to be a TCollection
  TIdIRCUsers = class(TCollection)
  protected
    FClient: TIdIRC;
    FOnSortCompareUsers : TIdIRCSortCompareUsers;
    procedure SetItem ( Index: Integer; const Value: TIdIRCUser );
    function GetItem(Index: Integer): TIdIRCUser;

  public
    constructor Create(AClient: TIdIRC);
    destructor Destroy; override;
    function Add(ANick, AAddress: String): TIdIRCUser;
    procedure Remove(AUser: TIdIRCUser);
    function Address(ANick: String): String;
    function Find(ANick: String; var AIndex: Integer): Boolean;
    function Get(ANick: String): TIdIRCUser;
    procedure Nick(AFromNick, AToNick: String);
    procedure Sort;
    property Items[Index: Integer] : TIdIRCUser read GetItem write SetItem;
    property OnSortCompareUsers : TIdIRCSortCompareUsers
      read FOnSortCompareUsers write FOnSortCompareUsers;
  end;

  { TChannel }

  TIdIRCChangeType = (ctNone, ctAdd, ctSubtract);

  TIdIRCChannelMode = (cmPrivate, cmSecret, cmInviteOnly, cmOpsSetTopic,
    cmNoExternalMessages, cmModerated, cmUserLimit, cmKey);
  TIdIRCChannelModes = Set of TIdIRCChannelMode;

  TIdIRCCloseType = (ctReset, ctPart, ctKick);

  TIdIRCChannelUpdateType = (cuMode, cuTopic, cuUser, cuNames, cuNick, cuJoin,
    cuPart, cuKick, cuQuit);
  TIdIRCOnChannelUpdate = procedure (Sender: TObject; AUpdateType:
    TIdIRCChannelUpdateType; AUser: TIdIRCUser; AInfo: Integer) of object;

  //TODO: This needs to be a TCollectionItem
  TIdIRCChannel = class(TCollectionItem)
  protected
    FClient: TIdIRC;
    FName: String;
    FTopic: String;
    FMode: TIdIRCChannelModes;
    FLimit: Integer;
    FKey: String;
    FNames: TStringList;
    FBans: TStringList;
    FActive: Boolean;
    FData: TObject;
    FModeChange: Boolean;
    ModeOptions: String;
    ModeParams: String;
    ChangeType: TIdIRCChangeType;
    FCloseType: TIdIRCCloseType;
    FOnChannelUpdate: TIdIRCOnChannelUpdate;
    procedure SetTopic(AValue: String);
    procedure SetMode(AValue: TIdIRCChannelModes);
    procedure SetLimit(AValue: Integer);
    procedure SetKey(AValue: String);
    function GetModeString: String;
  public
    constructor Create(AClient: TIdIRC; AName: String); reintroduce;
    destructor Destroy; override;
    procedure Say(AMsg: String);
    procedure Part(AReason: String);
    procedure Kick(ANick, AReason: String);
    procedure BeginMode;
    procedure EndMode;
    procedure Op(ANick: String);
    procedure Deop(ANick: String);
    procedure Voice(ANick: String);
    procedure Devoice(ANick: String);
    procedure Ban(AHostmask: String);
    procedure Unban(AHostmask: String);
    procedure TopicChanged(ATopic: String);
    procedure ModeChanged(AMode: TIdIRCChannelModes);
    procedure LimitChanged(ALimit: Integer);
    procedure KeyChanged(AKey: String);
    function AddUser(ANick, AAddress: String): TIdIRCUser;
    procedure RemoveUser(AUser: TIdIRCUser);
    function HasUser(ANick: String): Boolean;
    function Find(ANick: String; var AIndex: Integer): Boolean;
    procedure GotOp(AUser: TIdIRCUser);
    procedure GotDeop(AUser: TIdIRCUser);
    procedure GotVoice(AUser: TIdIRCUser);
    procedure GotDevoice(AUser: TIdIRCUser);
    procedure ChangedNick(AUser: TIdIRCUser; ANewNick: String);
    procedure Joined(AUser: TIdIRCUser);
    procedure Parted(AUser: TIdIRCUser);
    procedure Kicked(AUser: TIdIRCUser);
    procedure Quit(AUser: TIdIRCUser);
    property Name: String read FName;
    property Topic: String read FTopic write SetTopic;
    property Mode: TIdIRCChannelModes read FMode write SetMode;
    property Limit: Integer read FLimit write SetLimit;
    property Key: String read FKey write SetKey;
    property ModeChange: Boolean read FModeChange;
    property ModeString: String read GetModeString;
    property Names: TStringList read FNames;
    property Bans: TStringList read FBans;
    property Active: Boolean read FActive write FActive;
    property CloseType: TIdIRCCloseType read FCloseType write FCloseType;
    property Data: TObject read FData write FData;
    property OnChannelUpdate: TIdIRCOnChannelUpdate read FOnChannelUpdate write FOnChannelUpdate;
  end;
  
  { TIdIRCChannels }

  TIdIRCSortCompareChanels = procedure (Sender :TObject; AItem1, AItem2 : TIdIRCChannel; var AResult : Integer);

  //TODO: This needs to be a TCollection
  TIdIRCChannels = class(TCollection)
  protected
    FClient: TIdIRC;
    FOnSortCompareChanels : TIdIRCSortCompareChanels;
    function GetItem(Index:Integer): TIdIRCChannel;
    procedure SetItem ( Index: Integer; const Value: TIdIRCChannel );
  public
    constructor Create(AClient: TIdIRC); reintroduce;
    destructor Destroy; override;
    function Add(AName: String): TIdIRCChannel;
    procedure Remove(AName: String);
    function Find(AName: String; var AIndex: Integer): Boolean;
    function Get(AName: String): TIdIRCChannel;
    procedure ChangedNick(AUser: TIdIRCUser; ANewNick: String);
    procedure Quit(AUser: TIdIRCUser);
  public
    procedure Sort; virtual;
    property Items[Index: Integer] : TIdIRCChannel read GetItem write SetItem;
  end;

  { TIdIRCReplies }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -