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

📄 dxradiusservercore.pas

📁 Well known and usefull component for delphi 7
💻 PAS
📖 第 1 页 / 共 2 页
字号:
unit DXRadiusServerCore;

interface

///////////////////////////////////////////////////////////////////////////////
//    Component: TDXRadiusServerCore
//       Author: G.E. Ozz Nixon Jr. (staff@bpdx.com)
// ========================================================================
// Source Owner: DX, Inc. 1995-2003
//    Copyright: All code is the property of DX, Inc. Licensed for
//               resell by Brain Patchwork DX (tm) and part of the
//               DX (r) product lines, which are (c) 1999-2003
//               DX, Inc. Source may not be distributed without
//               written permission from both Brain Patchwork DX,
//               and DX, Inc.
//      License: (Reminder), None of this code can be added to other
//               developer products without permission. This includes
//               but not limited to DCU's, DCP's, DLL's, OCX's, or
//               any other form of merging our technologies. All of
//               your products released to a public consumer be it
//               shareware, freeware, commercial, etc. must contain a
//               license notification somewhere visible in the
//               application.
//               Example is Internet Explorer - Help->About screen
//               shows the licensed code contained in the application.
// Code Version: (4th Generation Code)
// ========================================================================
//  Description: *NOT FINISHED V3.0 YET*
// ========================================================================
// RFC 2139
///////////////////////////////////////////////////////////////////////////////

uses
  Classes,
  DXServerCore;

{$I dxsock.def}

type
  RadiusTSimpleEvent = procedure(ClientThread: TDXServerThread) of object;
  RadiusTBasicEvent = procedure(ClientThread: TDXServerThread; Parm: string) of object;
  RadiusTComplexEvent = procedure(ClientThread:TDXServerThread;Parm1,Parm2:string) of object;
  RadiusTOtherEvent = procedure(ClientThread: TDXServerThread; Command: string; Parm: string; var Handled: Boolean) of object;

  TDXRadiusServerCore = class(TDXServerCore)
  private
    fOnCommandNORTH: RadiusTSimpleEvent;
    fOnCommandSOUTH: RadiusTSimpleEvent;
    fOnCommandEAST: RadiusTSimpleEvent;
    fOnCommandWEST: RadiusTSimpleEvent;
    fOnCommandQUIT: RadiusTSimpleEvent;
    fOnCommandINV: RadiusTSimpleEvent;    // INV = INVentory
    fOnCommandSAY: RadiusTBasicEvent;
    fOnCommandLOOK: RadiusTBasicEvent;
    fOnCommandOther: RadiusTOtherEvent;
    fEventArray:TList;
    fiTimeout:Cardinal;
    fbForceAbort:Boolean;
  protected
    Procedure SetOnCommandNORTH(value: RadiusTSimpleEvent);
    Procedure SetOnCommandSOUTH(value: RadiusTSimpleEvent);
    Procedure SetOnCommandEAST(value: RadiusTSimpleEvent);
    Procedure SetOnCommandWEST(value: RadiusTSimpleEvent);
    Procedure SetOnCommandQUIT(value: RadiusTSimpleEvent);
    Procedure SetOnCommandINV(value: RadiusTSimpleEvent);    // INV = INVentory
    Procedure SetOnCommandSAY(value: RadiusTBasicEvent);
    Procedure SetOnCommandLOOK(value: RadiusTBasicEvent);
  public
{$IFDEF OBJECTS_ONLY}
    constructor Create;
{$ELSE}
    constructor Create(AOwner:TComponent); override;
{$ENDIF}
    destructor Destroy; override;
    procedure SayHello(ClientThread:TDXServerThread;Header,MOTD:TStrings);
    procedure SayGoodbye(ClientThread:TDXServerThread;Footer:String);
    procedure ProcessSession(ClientThread:TDXServerThread);
    Procedure AddBasicEvent(Command:String;EventProc:RadiusTBasicEvent);
    Procedure AddSimpleEvent(Command:String;EventProc:RadiusTSimpleEvent);
    Procedure AddComplexEvent(Command:String;EventProc:RadiusTComplexEvent);
    Procedure ForceAbort;
  published
    property Timeout:Cardinal read fiTimeout
                           write fiTimeout;
    property OnCommandNORTH: RadiusTSimpleEvent read fOnCommandNORTH
                                            write SetOnCommandNORTH;
    property OnCommandSOUTH: RadiusTSimpleEvent read fOnCommandSOUTH
                                            write SetOnCommandSOUTH;
    property OnCommandEAST: RadiusTSimpleEvent read fOnCommandEAST
                                            write SetOnCommandEAST;
    property OnCommandWEST: RadiusTSimpleEvent read fOnCommandWEST
                                            write SetOnCommandWEST;
    property OnCommandQUIT: RadiusTSimpleEvent read fOnCommandQUIT
                                            write SetOnCommandQUIT;
    property OnCommandINV: RadiusTSimpleEvent read fOnCommandINV
                                            write SetOnCommandINV;
    property OnCommandSAY: RadiusTBasicEvent read fOnCommandSAY
                                            write SetOnCommandSAY;
    property OnCommandLOOK: RadiusTBasicEvent read fOnCommandLOOK
                                            write SetOnCommandLOOK;
    property OnCommandOther: RadiusTOtherEvent read fOnCommandOther
                                            write fOnCommandOther;
  end;

implementation

uses
   DXSock,
   DXString;

Type
  PRadiusBasicEvent=^TRadiusBasicEvent;
  TRadiusBasicEvent=record
     Tag:Integer;
     Command:MySmallString;
     EventProcedure:RadiusTBasicEvent;
  End;
  PRadiusSimpleEvent=^TRadiusSimpleEvent;
  TRadiusSimpleEvent=record
     Tag:Integer;
     Command:MySmallString;
     EventProcedure:RadiusTSimpleEvent;
  End;
  PRadiusComplexEvent=^TRadiusComplexEvent;
  TRadiusComplexEvent=record
     Tag:Integer;
     Command:MySmallString;
     EventProcedure:RadiusTComplexEvent;
  End;

///////////////////////////////////////////////////////////////////////////////
//CREATE:
//       Define the Default Port number to Listen On.
///////////////////////////////////////////////////////////////////////////////
{$IFDEF OBJECTS_ONLY}
constructor TDXRadiusServerCore.Create;
{$ELSE}
constructor TDXRadiusServerCore.Create(AOwner:TComponent);
{$ENDIF}
begin
{$IFDEF OBJECTS_ONLY}
   inherited Create;
{$ELSE}
   inherited Create(AOwner);
{$ENDIF}
   ServerPort:=1813;
   ProtocolToBind:=wpUDPOnly;
   fiTimeout:=120000;
   fEventArray:=TList.Create;
end;

///////////////////////////////////////////////////////////////////////////////
//DESTROY:
//        Destory this object.
///////////////////////////////////////////////////////////////////////////////
destructor TDXRadiusServerCore.Destroy;
Var
   PBasicEvent:PRadiusBasicEvent;
   PSimpleEvent:PRadiusSimpleEvent;
   PComplexEvent:PRadiusComplexEvent;

begin
   If Assigned(fEventArray) then Begin
      While fEventArray.Count>0 do Begin
         Case PRadiusBasicEvent(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;
         End;
         fEventArray.Delete(0);
      End;
   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 TDXRadiusServerCore.AddBasicEvent(Command:String;EventProc:RadiusTBasicEvent);
Var
   PBasicEvent:PRadiusBasicEvent;
   Loop:Integer;

Begin
   Command:=Uppercase(Command);
   Loop:=0;
   While Loop<fEventArray.Count do Begin
      If PRadiusBasicEvent(fEventArray[Loop]).Command=Command then Begin
         PRadiusBasicEvent(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: AddBasicEvent('CDROM',MySpecialEvent);
///////////////////////////////////////////////////////////////////////////////
Procedure TDXRadiusServerCore.AddSimpleEvent(Command:String;EventProc:RadiusTSimpleEvent);
Var
   PSimpleEvent:PRadiusSimpleEvent;
   Loop:Integer;

Begin
   Command:=Uppercase(Command);

⌨️ 快捷键说明

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