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

📄 dxbbsservercore.pas

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

interface

///////////////////////////////////////////////////////////////////////////////
//    Component: TDXBBSServerCore
//       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: *Example*
// ========================================================================
///////////////////////////////////////////////////////////////////////////////

uses
  Classes,
  DXServerCore;

{$I DXSock.def}

type
  BBSTSimpleEvent = procedure(ClientThread: TDXClientThread) of object;
  BBSTBasicEvent = procedure(ClientThread: TDXClientThread; Parm: string) of object;
  BBSTComplexEvent = procedure(ClientThread:TDXClientThread;Parm1,Parm2:string) of object;
  BBSTOtherEvent = procedure(ClientThread: TDXClientThread; Command: string; Parm: string; var Handled: Boolean) of object;

  // DXBBSServerCore is a proprietary protocol established by
  // Brain Patchwork DX, LLC. during a co-development project with
  // a customer. It can be massaged into a new protocol if you are
  // looking for a starting point to make your own
  // implementations.
  // 
  // 
  // 
  // Summary
  // A proprietary protocol by Brain Patchwork DX, LLC.
TDXBBSServerCore = class(TDXServerCore)
  private
    fOnCommandTimeout:BBSTSimpleEvent;
    fOnCommandAUTH: BBSTComplexEvent;
    fOnCommandMENU: BBSTBasicEvent;
    fOnCommandPING: BBSTSimpleEvent;
    fOnCommandPONG: BBSTSimpleEvent;
    fOnCommandOther: BBSTOtherEvent;
  protected
    Procedure SetOnCommandPING(value: BBSTSimpleEvent);
    Procedure SetOnCommandPONG(value: BBSTSimpleEvent);
    Procedure SetOnCommandMENU(value: BBSTBasicEvent);
    Procedure SetOnCommandAUTH(value: BBSTComplexEvent);
  public
    constructor Create(AOwner:TComponent); {$IFNDEF OBJECTS_ONLY} override; {$ENDIF}
    destructor Destroy; override;
    procedure SayHello(ClientThread:TDXClientThread;Header,MOTD:TStream);
    procedure SayGoodbye(ClientThread:TDXClientThread;Footer:TStream);
    procedure ProcessSession(ClientThread:TDXClientThread);
    Procedure AddBasicEvent(Command:String;EventProc:BBSTBasicEvent);
    Procedure AddSimpleEvent(Command:String;EventProc:BBSTSimpleEvent);
    Procedure AddComplexEvent(Command:String;EventProc:BBSTComplexEvent);
  published
    // When the BBS Server Core receives an AUTH command, the string
    // from the client is parsed and this event is fired.
    // 
    // 
    // 
    // The first parameter is always the clientthread.
    //
    // 
    // 
    // The next parameter is usally a login name, it is up to your
    // implementation if this is case sensative of not.
    // 
    // 
    // 
    // The next parameter in our implementation is a MD5 hash code
    // for the password. Allowing us to transmit it an readable text
    // and know that it will be rare for someone to hack the hash
    // code.
    // 
    // 
    //
    // Summary
    // AUTH command received.                                       
property OnCommandAUTH: BBSTComplexEvent read fOnCommandAUTH
                                             write SetOnCommandAUTH;
    // When the BBS Server Core receives an MENU command, the string
    // from the client is parsed and this event is fired.
    // 
    // 
    // 
    // The first parameter is always the clientthread.
    // 
    // 
    // 
    // In our implementation the second parameter was a numeric code
    // which referenced internal functions on the server. You could
    // actually implement this to work like the old BBS packages,
    // and this be the menu letter corresponding to the fuinction,
    // but then you would have to track session information per user
    // connected.
    // 
    // 
    //
    // Summary
    // MENU command received.                                       
property OnCommandMENU: BBSTBasicEvent read fOnCommandMENU
                                           write SetOnCommandMENU;
    // When the BBS Server Core receives an PING command, the string
    // from the client is parsed and this event is fired.
    // 
    // 
    // 
    // The first parameter is always the clientthread.
    // 
    // 
    // 
    // In our implementation the client sends a PING statment to the
    // server, and the server tries to respond as fast as possible
    // with a PONG reply. Like IRC protocol.
    // 
    //
    // 
    // Summary
    // PING command received.                                       
property OnCommandPING: BBSTSimpleEvent read fOnCommandPING
                                            write SetOnCommandPING;
    // When the BBS Server Core receives an PONG command, the string
    // from the client is parsed and this event is fired.
    // 
    //
    // 
    // The first parameter is always the clientthread.
    // 
    // 
    // 
    // In our implementation the server periodically sends a PING
    // message to the client, which tries to respond to the server
    // as fast as possible with a PONG reply.
    //
    // 
    // 
    // Summary
    // PONG command received.                                       
property OnCommandPONG: BBSTSimpleEvent read fOnCommandPONG
                                            write SetOnCommandPONG;
    // Almost every protocol in our suite has this "Unknown Command
    // was received" event handler. If you do not implement this
    // event handler, the internal "default" error message will be
    // sent to the client sending the unknown command.
    //
    // 
    // 
    // Summary
    // Unknown command was received.                               
property OnCommandOther: BBSTOtherEvent read fOnCommandOther
                                            write fOnCommandOther;
    // When the BBS Server Core does not receives a command within
    // the Timeout property.
    // 
    // 
    // 
    // The first parameter is always the clientthread.
    // 
    // 
    // 
    // Unlike most of our server implementations, we needed to be
    // able to set the TIMEOUT low, and when a command was not
    // received from the client within this TIMEOUT. This event
    // would fire and we would write to the client a PING command.
    // Internally (via the fpSessionData pointer) we would track how
    // many PING commands were sent, and after an excess amount we
    // would terminate the session. And in our OnCommandPONG event
    // we would set this counter back to zero.
    //
    //
    //
    // Summary
    // No command received within timeout limit.
property OnCommandTimeout: BBSTSimpleEvent read fOnCommandTimeout
                                            write fOnCommandTimeout;
    // Used internally to show the date of this release in the
    // object inspector. Only useful when reporting bugs to
    // development team.
  end;

implementation

uses
   DXSock,
   DxString;

Type
  PBBSBasicEvent=^TBBSBasicEvent;
  TBBSBasicEvent=record
     Tag:Integer;
     Command:String;
     EventProcedure:BBSTBasicEvent;
  End;
  PBBSSimpleEvent=^TBBSSimpleEvent;
  TBBSSimpleEvent=record
     Tag:Integer;
     Command:String;
     EventProcedure:BBSTSimpleEvent;
  End;
  PBBSComplexEvent=^TBBSComplexEvent;
  TBBSComplexEvent=record
     Tag:Integer;
     Command:String;
     EventProcedure:BBSTComplexEvent;
  End;


constructor TDXBBSServerCore.Create(AOwner:TComponent);
begin
   inherited Create(AOwner);
   ServerPort:=7625;
   Timeout:=12000; // client should send a command, or noop every 10 seconds!
end;

destructor TDXBBSServerCore.Destroy;
Var
   PBasicEvent:PBBSBasicEvent;
   PSimpleEvent:PBBSSimpleEvent;
   PComplexEvent:PBBSComplexEvent;

begin
   If Assigned(fEventArray) then Begin
      While fEventArray.Count>0 do Begin
         Case PBBSBasicEvent(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;

// 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

⌨️ 快捷键说明

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