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

📄 dxdictionaryservercore.pas

📁 Well known and usefull component for delphi 7
💻 PAS
📖 第 1 页 / 共 2 页
字号:
Begin
   Command:=Uppercase(Command);
   Loop:=0;
   While Loop<fEventArray.Count do Begin
      If PDICTDefineEvent(fEventArray[Loop]).Command=Command then Begin
         PDICTDefineEvent(fEventArray[Loop]).EventProcedure:=EventProc;
         Exit;
      End
      Else Inc(Loop);
   End;
   New(PDefineEvent);
   PDefineEvent.Tag:=2;      // Denotes Event in fEventArray is a TDefineEvent!
   PDefineEvent.Command:=Command;
   PDefineEvent.EventProcedure:=EventProc;
   fEventArray.Add(PDefineEvent);
End;

Procedure TDXDictionaryServerCore.AddMatchEvent(Command:String;EventProc:DICTTMatchEvent);
Var
   PMatchEvent:PDICTMatchEvent;
   Loop:Integer;

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

Procedure TDXDictionaryServerCore.AddShowEvent(Command:String;EventProc:DICTTShowEvent);
Var
   PShowEvent:PDICTShowEvent;
   Loop:Integer;

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

Procedure TDXDictionaryServerCore.AddAuthEvent(Command:String;EventProc:DICTTAuthEvent);
Var
   PAuthEvent:PDICTAuthEvent;
   Loop:Integer;

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

Procedure TDXDictionaryServerCore.AddOptionEvent(Command:String;EventProc:DICTTOptionEvent);
Var
   POptionEvent:PDICTOptionEvent;
   Loop:Integer;

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

Procedure TDXDictionaryServerCore.SetOnCommandAUTH(value:DictTAuthEvent);
Begin
   fOnCommandAUTH:=Value;
   AddAuthEvent('AUTH',Value);
End;

Procedure TDXDictionaryServerCore.SetOnCommandCLIENT(value:DictTShowEvent);
Begin
   fOnCommandCLIENT:=Value;
   AddShowEvent('CLIENT',Value);
End;

Procedure TDXDictionaryServerCore.SetOnCommandDEFINE(value:DictTDefineEvent);
Begin
   fOnCommandDEFINE:=Value;
   AddDefineEvent('DEFINE',Value);
End;

Procedure TDXDictionaryServerCore.SetOnCommandHELP(value:DictTBasicEvent);
Begin
   fOnCommandHELP:=Value;
   AddBasicEvent('HELP',Value);
End;

Procedure TDXDictionaryServerCore.SetOnCommandMATCH(value:DictTMatchEvent);
Begin
   fOnCommandMATCH:=Value;
   AddMatchEvent('MATCH',Value);
End;

Procedure TDXDictionaryServerCore.SetOnCommandOPTION(value:DictTOptionEvent);
Begin
   fOnCommandOPTION:=Value;
   AddOptionEvent('OPTION',Value);
End;

Procedure TDXDictionaryServerCore.SetOnCommandQUIT(value:DictTBasicEvent);
Begin
   fOnCommandQUIT:=Value;
   AddBasicEvent('QUIT',Value);
End;

Procedure TDXDictionaryServerCore.SetOnCommandSASLAUTH(value:DictTAuthEvent);
Begin
   fOnCommandSASLAUTH:=Value;
   AddAuthEvent('SASLAUTH',Value);
End;

Procedure TDXDictionaryServerCore.SetOnCommandSHOW(value:DictTShowEvent);
Begin
   fOnCommandSHOW:=Value;
   AddShowEvent('SHOW',Value);
End;

Procedure TDXDictionaryServerCore.SetOnCommandSTAT(value:DictTBasicEvent);
Begin
   fOnCommandSTAT:=Value;
   AddBasicEvent('STAT',Value);
   AddBasicEvent('STATUS',Value);
End;

procedure TDXDictionaryServerCore.ProcessSession(ClientThread: TDXClientThread);
var
  s, sCmd: string;
  WasHandled: Boolean;
  Loop:Integer;
  OutData:Pointer;

begin
   fbForceAbort:=False;
   with ClientThread.Socket do begin
      while Connected do begin
         If fbForceAbort then Exit;
         S:=ReadLn(Timeout);
         If LastReadTimeout or Not Connected then Exit;
         if S='' then continue;
         if assigned({$IFDEF TLS_EDITION}OnReadFilter{$ELSE}OnFilter{$ENDIF}) then begin
            Loop:=FilterRead(@S[1],OutData,Length(S),ClientThread);
            SetLength(S,Loop);
            If Assigned(OutData) then Begin
               FastMove(TDXBSArray(OutData^),S[1],Loop);
{$IFDEF TLS_EDITION}OnReadFilter{$ELSE}OnFilter{$ENDIF}(ddFreePointer,nil,OutData,Loop,Loop,WasHandled,ClientThread) ;
            End;
         End;
         sCmd:=UpperCase(Fetch(S,#32,False));
         Loop:=0;
         WasHandled:=False;
         While (Loop<fEventArray.Count) and (Not WasHandled) do Begin
            If PDICTBasicEvent(fEventArray[Loop]).Command=sCMD then Begin
               Case PDICTBasicEvent(fEventArray[Loop]).Tag of
                  1:if Assigned(PDICTBasicEvent(fEventArray[Loop]).EventProcedure) then
                       DICTTBasicEvent(PDICTBasicEvent(fEventArray[Loop]).EventProcedure)(ClientThread);
                  2:if Assigned(PDICTDefineEvent(fEventArray[Loop]).EventProcedure) then
                       DICTTDefineEvent(PDICTDefineEvent(fEventArray[Loop]).EventProcedure)(ClientThread,Fetch(S,#32,False),S);
                  3:if Assigned(PDICTMatchEvent(fEventArray[Loop]).EventProcedure) then
                       DICTTMatchEvent(PDICTMatchEvent(fEventArray[Loop]).EventProcedure)(ClientThread,Fetch(S,#32,False),Fetch(S,#32,False),S);
                  4:if Assigned(PDICTShowEvent(fEventArray[Loop]).EventProcedure) then
                       DICTTShowEvent(PDICTShowEvent(fEventArray[Loop]).EventProcedure)(ClientThread,S);
                  5:if Assigned(PDICTAuthEvent(fEventArray[Loop]).EventProcedure) then
                       DICTTAuthEvent(PDICTAuthEvent(fEventArray[Loop]).EventProcedure)(ClientThread,Fetch(S,#32,False),S);
                  6:if Assigned(PDICTOptionEvent(fEventArray[Loop]).EventProcedure) then
                       DICTTOptionEvent(PDICTOptionEvent(fEventArray[Loop]).EventProcedure)(ClientThread,Fetch(S,#32,False),S);
               End;
               WasHandled:=True;
            End
            Else Inc(Loop);
         End;
         If sCMD='QUIT' then Exit;
         If Not WasHandled then Begin
            if assigned(OnCommandOther) then
               OnCommandOther(ClientThread, sCmd, s, WasHandled);
         end;
         if not WasHandled then
            Writeln('500 command not recognized (' + sCMD + ')');
      end;
   end;
end;

end.

⌨️ 快捷键说明

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