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

📄 dxircservercore.pas

📁 Well known and usefull component for delphi 7
💻 PAS
📖 第 1 页 / 共 3 页
字号:
                               write fServerName; // 3.0a
    property OnReadTimeout:IRCTSimpleEvent read fOnCommandTimeout
                                           write fOnCommandTimeout; // 3.0a
  end;

implementation

Uses
   DXSock,
   DXString;

Type
  PIRCBasicEvent=^TIRCBasicEvent;
  TIRCBasicEvent=record
     Tag:Integer;
     Command:String;
     EventProcedure:IRCTBasicEvent;
  End;
  PIRCSimpleEvent=^TIRCSimpleEvent;
  TIRCSimpleEvent=record
     Tag:Integer;
     Command:String;
     EventProcedure:IRCTSimpleEvent;
  End;
  PIRCComplexEvent=^TIRCComplexEvent;
  TIRCComplexEvent=record
     Tag:Integer;
     Command:String;
     EventProcedure:IRCTComplexEvent;
  End;
  PIRCMultipleEvent=^TIRCMultipleEvent;
  TIRCMultipleEvent=record
     Tag:Integer;
     Command:String;
     EventProcedure:IRCTMultipleEvent;
  End;

///////////////////////////////////////////////////////////////////////////////
// RFC 1459...
//   PASS <password>
//   NICK <nickname> [hopcount] (hopcount is from server to server)
//   USER <username> <hostname> <servername> <realname>
//   SERVER <servername> <hopcount> <info>
//   OPER <user> <password>
//   QUIT [quit message]
//   SQUIT <server> <comment>
//
//   // Channel Commands
//   JOIN <channel>[,<channel>...] [<key>[,<key>]]
//   PART <channel>[,<channel>...]
//   MODE <channel> [[+|-]o|p|s|i|t|n|b|v] [<limits>] [<user>] [<ban mask>]
//   MODE <nickname> [[+|-]i|w|s|o]
//   TOPIC <channel> [<topic>]
//   NAMES [<channel>[,<channel>...]]
//   LIST [<channel>[,<channel>...]] [<server>]
//   INVITE <nickname> <channel>
//   KICK <channel>[,<channel>...] <user>[,<user>...] [<comment>]
//
//   // Server Commands
//   VERSION [<server>]
//   STATS [<query> [<server>]]
//   LINKS [[<remote server>] <server mask>]
//   TIME [<server>]
//   CONNECT <target server> [<port> [<remote server>]]
//   TRACE [<server>]
//   ADMIN [<server>]
//   INFO [<server>]
//
//   // Messages
//   PRIVMSG <receiver>[,<receiver>...] <text>
//   NOTICE <nickname> <text>
//
//   // User Based Queries
//   WHO [<name> [<o>]]
//   WHOIS [<server>] <nickname>[,<nickname>...]
//   WHOWAS <nickname> [<count> [<server>]]
//
//   // Miscellaneous
//   KILL <nickname> <comment>
//   PING <server1> [<server2>]
//   PONG <daemon1> [<daemon2>]
//   AWAY [<message>]
//   REHASH
//   RESTART
//   SUMMON <user> [<server>]
//   USERS [<server>]
//   WALLOPS <text>
//   USERHOST <nickname> [<nickname>]
//   ISON <nickname> [<nickname>]
///////////////////////////////////////////////////////////////////////////////

constructor TDXIRCServerCore.Create(AOwner:TComponent);
begin
   inherited Create(AOwner);
   ServerPort:=6667;
   fEventArray:=TList.Create;
end;

destructor TDXIRCServerCore.Destroy;
Var
   PBasicEvent:PIRCBasicEvent;
   PSimpleEvent:PIRCSimpleEvent;
   PComplexEvent:PIRCComplexEvent;
   PMultipleEvent:PIRCMultipleEvent;

begin
   If Assigned(fEventArray) then Begin
      While fEventArray.Count>0 do Begin
         Case PIRCBasicEvent(fEventArray[0]).Tag of
            1:Begin
              PBasicEvent:=fEventArray[0];
              Dispose(PBasicEvent);
            End;
            2:Begin
              PSimpleEvent:=fEventArray[0];
              Dispose(PSimpleEvent);
            End;
            3:Begin
              PComplexEvent:=fEventArray[0];
              Dispose(PComplexEvent);
            End;
            4:Begin
              PMultipleEvent:=fEventArray[0];
              Dispose(PMultipleEvent);
            End;
         End;
         fEventArray.Delete(0);
      End;
      fEventArray.Free;
      fEventArray:=Nil;
   End;
   inherited Destroy;
end;

///////////////////////////////////////////////////////////////////////////////
//ADDBASICEVENT:
//              Allows you to dynamically assign a new command to the internal
//              parser. This allows the servercore to support the 'pre-defined'
//              OnCommand* events, plus you can add other commands dynamically
//              at run-time in your application without requiring a source code
//              modification to our components!
//
//              To make support easier for us, we ask that you use the Add*Event
//              procedures to expand our code, reducing code changes when an
//              upgrade is released!
//
//              See documentation for complete information on how this works.
//
//              Example Usage: AddBasicEvent('CDROM',MySpecialEvent);
///////////////////////////////////////////////////////////////////////////////
Procedure TDXIRCServerCore.AddBasicEvent(Command:String;EventProc:IRCTBasicEvent);
Var
   PBasicEvent:PIRCBasicEvent;
   Loop:Integer;

Begin
   Command:=Uppercase(Command);
   Loop:=0;
   While Loop<fEventArray.Count do Begin
      If PIRCBasicEvent(fEventArray[Loop]).Command=Command then Begin
         PIRCBasicEvent(fEventArray[Loop]).EventProcedure:=EventProc;
         Exit;
      End
      Else Inc(Loop);
   End;
   New(PBasicEvent);
   PBasicEvent.Tag:=1;      // Denotes Event in fEventArray is a TBasicEvent!
   PBasicEvent.Command:=Command;
   PBasicEvent.EventProcedure:=EventProc;
   fEventArray.Add(PBasicEvent);
End;

///////////////////////////////////////////////////////////////////////////////
//ADDSIMPLEEVENT:
//              Allows you to dynamically assign a new command to the internal
//              parser. This allows the servercore to support the 'pre-defined'
//              OnCommand* events, plus you can add other commands dynamically
//              at run-time in your application without requiring a source code
//              modification to our components!
//
//              To make support easier for us, we ask that you use the Add*Event
//              procedures to expand our code, reducing code changes when an
//              upgrade is released!
//
//              See documentation for complete information on how this works.
//
//              Example Usage: AddSimpleEvent('CDROM',MySpecialEvent);
///////////////////////////////////////////////////////////////////////////////
Procedure TDXIRCServerCore.AddSimpleEvent(Command:String;EventProc:IRCTSimpleEvent);
Var
   PSimpleEvent:PIRCSimpleEvent;
   Loop:Integer;

Begin
   Command:=Uppercase(Command);
   Loop:=0;
   While Loop<fEventArray.Count do Begin
      If PIRCSimpleEvent(fEventArray[Loop]).Command=Command then Begin
         PIRCSimpleEvent(fEventArray[Loop]).EventProcedure:=EventProc;
         Exit;
      End
      Else Inc(Loop);
   End;
   New(PSimpleEvent);
   PSimpleEvent.Tag:=2;      // Denotes Event in fEventArray is a TBasicEvent!
   PSimpleEvent.Command:=Command;
   PSimpleEvent.EventProcedure:=EventProc;
   fEventArray.Add(PSimpleEvent);
End;

///////////////////////////////////////////////////////////////////////////////
//ADDCOMPLEXEVENT:
//              Allows you to dynamically assign a new command to the internal
//              parser. This allows the servercore to support the 'pre-defined'
//              OnCommand* events, plus you can add other commands dynamically
//              at run-time in your application without requiring a source code
//              modification to our components!
//
//              To make support easier for us, we ask that you use the Add*Event
//              procedures to expand our code, reducing code changes when an
//              upgrade is released!
//
//              See documentation for complete information on how this works.
//
//              Example Usage: AddComplexEvent('CDROM',MySpecialEvent);
///////////////////////////////////////////////////////////////////////////////
Procedure TDXIRCServerCore.AddComplexEvent(Command:String;EventProc:IRCTComplexEvent);
Var
   PComplexEvent:PIRCComplexEvent;
   Loop:Integer;

Begin
   Command:=Uppercase(Command);
   Loop:=0;
   While Loop<fEventArray.Count do Begin
      If PIRCComplexEvent(fEventArray[Loop]).Command=Command then Begin
         PIRCComplexEvent(fEventArray[Loop]).EventProcedure:=EventProc;
         Exit;
      End
      Else Inc(Loop);
   End;
   New(PComplexEvent);
   PComplexEvent.Tag:=3;      // Denotes Event in fEventArray is a TBasicEvent!
   PComplexEvent.Command:=Command;
   PComplexEvent.EventProcedure:=EventProc;
   fEventArray.Add(PComplexEvent);
End;

///////////////////////////////////////////////////////////////////////////////
//ADDMULTIPLEEVENT:
//              Allows you to dynamically assign a new command to the internal
//              parser. This allows the servercore to support the 'pre-defined'
//              OnCommand* events, plus you can add other commands dynamically
//              at run-time in your application without requiring a source code
//              modification to our components!
//
//              To make support easier for us, we ask that you use the Add*Event
//              procedures to expand our code, reducing code changes when an
//              upgrade is released!
//
//              See documentation for complete information on how this works.
//
//              Example Usage: AddMULTIPLEEvent('CDROM',MySpecialEvent);
///////////////////////////////////////////////////////////////////////////////
Procedure TDXIRCServerCore.AddMultipleEvent(Command:String;EventProc:IRCTMultipleEvent);
Var
   PMultipleEvent:PIRCMultipleEvent;
   Loop:Integer;

Begin
   Command:=Uppercase(Command);
   Loop:=0;
   While Loop<fEventArray.Count do Begin
      If PIRCMultipleEvent(fEventArray[Loop]).Command=Command then Begin
         PIRCMultipleEvent(fEventArray[Loop]).EventProcedure:=EventProc;
         Exit;
      End
      Else Inc(Loop);
   End;
   New(PMultipleEvent);
   PMultipleEvent.Tag:=4;      // Denotes Event in fEventArray is a TBasicEvent!
   PMultipleEvent.Command:=Command;
   PMultipleEvent.EventProcedure:=EventProc;
   fEventArray.Add(PMultipleEvent);
End;

Procedure TDXIRCServerCore.SetOnCommandPASS(Value:IRCTBasicEvent);
Begin
   fOnCommandPASS:=Value;
   AddBasicEvent('PASS',Value);
End;

Procedure TDXIRCServerCore.SetOnCommandNICK(Value:IRCTMultipleEvent);
Begin
   fOnCommandNICK:=Value;
   AddMultipleEvent('NICK',Value);
End;

Procedure TDXIRCServerCore.SetOnCommandUSER(Value:IRCTMultipleEvent);
Begin
   fOnCommandUSER:=Value;
   AddMultipleEvent('USER',Value);
End;

Procedure TDXIRCServerCore.SetOnCommandSERVER(Value:IRCTMultipleEvent);
Begin
   fOnCommandSERVER:=Value;
   AddMultipleEvent('SERVER',Value);
End;

Procedure TDXIRCServerCore.SetOnCommandOPER(Value:IRCTComplexEvent);
Begin
   fOnCommandOPER:=Value;
   AddComplexEvent('OPER',Value);
End;

Procedure TDXIRCServerCore.SetOnCommandQUIT(Value:IRCTBasicEvent);
Begin
   fOnCommandQUIT:=Value;
   AddBasicEvent('QUIT',Value);
End;

Procedure TDXIRCServerCore.SetOnCommandSQUIT(Value:IRCTComplexEvent);
Begin
   fOnCommandSQUIT:=Value;
   AddComplexEvent('SQUIT',Value);
End;

Procedure TDXIRCServerCore.SetOnCommandJOIN(Value:IRCTMultipleEvent);
Begin
   fOnCommandJOIN:=Value;
   AddMultipleEvent('JOIN',Value);
End;

⌨️ 快捷键说明

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