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

📄 msgcommain.pas

📁 Delphi MsgCommunicator 2-10 component.I ve used, really good job. can be Server-Client message appl
💻 PAS
📖 第 1 页 / 共 2 页
字号:
 
procedure TMsgCryptoParamsEditor.SetInitVectorValue(Index: Integer; Value: Byte); 
begin 
 if (Index < 0) or (Index >= MaxInitVectorSize) then 
  raise EMsgException.Create(10718,ErrorLInvalidVectorIndex,[Index,MaxInitVectorSize]); 
 FInitVector[Index] := Value;
end; // SetInitVectorValue
 
	
function TMsgCryptoParamsEditor.GetVectorSize: Integer;
begin
 Result := Msg_MAX_VECTOR+1; 
end; // GetVectorSize 
	
 
function TMsgCryptoParamsEditor.GetKeySize: Integer; 
begin 
 Result := FKeyInfo.KeySize;
end; // GetVectorSize
 
 
procedure TMsgCryptoParamsEditor.SetKeySize(Value: Integer); 
begin 
 if (Value < 0) or (Value > MaxKeySize) then 
  raise EMsgException.Create(10720,ErrorLInvalidKeySize,[Value,MaxKeySize]); 
 FKeyInfo.KeySize := Value;
 FPassword := ''; 
end; // GetVectorSize 
 
 
function TMsgCryptoParamsEditor.GetKeyValue(Index: Integer): Byte; 
begin 
 if (Index < 0) or (Index >= KeySize) then 
  raise EMsgException.Create(10721,ErrorLInvalidKeyIndex,[Index,KeySize]); 
 Result := FKeyInfo.Key[Index]; 
end;
	
	
procedure TMsgCryptoParamsEditor.SetKeyValue(Index: Integer; Value: Byte);
begin 
 if (Index < 0) or (Index >= KeySize) then
  raise EMsgException.Create(10722,ErrorLInvalidKeyIndex,[Index,KeySize]);
 FKeyInfo.Key[Index] := Value; 
 FPassword := '';
end; // SetKeyValue
 
 
function TMsgCryptoParamsEditor.GetMaxKeySize: Integer; 
begin 
 Result := Msg_MAX_KEY+1; 
end; // GetMaxKeySize 
 
	
procedure TMsgCryptoParamsEditor.SetKey(Key: Pointer; KeySize: Integer);
begin 
 if (KeySize < 0) or (KeySize > MaxKeySize) then
  raise EMsgException.Create(10719,ErrorLInvalidKeySize,[KeySize,MaxKeySize]); 
 Move(Key^,FKeyInfo.Key[0],KeySize); 
 FKeyInfo.KeySize := KeySize;
 FPassword := ''; 
end; //SetKey
 
 
function TMsgCryptoParamsEditor.GetKey: Pointer;
begin
 Result := @FKeyInfo.Key;
end; // GetKey


procedure TMsgCryptoParamsEditor.MakeRandomKey(KeySize: Integer);
begin
 if (KeySize < 0) or (KeySize > MaxKeySize) then
  raise EMsgException.Create(10723,ErrorLInvalidKeySize,[KeySize,MaxKeySize]);
 FKeyInfo.KeySize := KeySize;
 MsgGenerateRandomBuffer(@FKeyInfo.Key[0],KeySize);
 FPassword := '';
end;

procedure TMsgCryptoParamsEditor.MakeRandomInitVector;
begin
 MsgGenerateRandomBuffer(@FInitVector[0],MaxInitVectorSize);
 FUseInitVector := True;
end;


procedure TMsgCryptoParamsEditor.SetInitVector(Vector: Pointer);
begin
  Move(Vector^, FInitVector[0], MaxInitVectorSize);
end; // SetInitVector


function TMsgCryptoParamsEditor.GetInitVector: Pointer;
begin
  Result := @FInitVector;
end; // GetInitVector


//------------------------------------------------------------------------------
// Assign
//------------------------------------------------------------------------------
procedure TMsgCryptoParamsEditor.Assign(Source: TPersistent);
begin
 FKeyInfo := TMsgCryptoParamsEditor(Source).FKeyInfo;
 FInitVector := TMsgCryptoParamsEditor(Source).FInitVector;
 FPassword := TMsgCryptoParamsEditor(Source).FPassword;
 FCryptoAlgorithm := TMsgCryptoParamsEditor(Source).CryptoAlgorithm;
 FCryptoMode := TMsgCryptoParamsEditor(Source).CryptoMode;
 FUseInitVector := TMsgCryptoParamsEditor(Source).FUseInitVector;
end; // Assign


////////////////////////////////////////////////////////////////////////////////
//
// TMsgNetworkSettingsEditor
//
////////////////////////////////////////////////////////////////////////////////


//------------------------------------------------------------------------------
// set packet size
//------------------------------------------------------------------------------
procedure TMsgNetworkSettingsEditor.SetPacketSize(Value: Integer);
begin
  if (Value >= MsgMinPacketSize) and (Value <= MsgMaxPacketSize) then
   FPacketSize := Value;
end; // SetPacketSize


//------------------------------------------------------------------------------
// Create
//------------------------------------------------------------------------------
constructor TMsgNetworkSettingsEditor.Create;
begin
  inherited Create;
  FPacketSize := MsgDefaultPacketSize;
  FMaxThreadCount := MsgMaxThreadCount;
  FConnectionParamsTunning := MsgConnectionParamsTunning;
  FTestPacketCount := MsgTestPacketCount;
  FDisconnectRetryCount := MsgDisconnectRetryCount;
  FDisconnectDelay := MsgDisconnectDelay;
end; // Create


//------------------------------------------------------------------------------
// Destroy
//------------------------------------------------------------------------------
destructor TMsgNetworkSettingsEditor.Destroy;
begin
  inherited Destroy;
end; // Destroy


//------------------------------------------------------------------------------
// Assign
//------------------------------------------------------------------------------
procedure TMsgNetworkSettingsEditor.Assign(Source: TPersistent);
begin
  if (Source <> nil) then
   if (Source is TMsgNetworkSettingsEditor) then
    begin
      FPacketSize := TMsgNetworkSettingsEditor(Source).PacketSize;
      FMaxThreadCount := TMsgNetworkSettingsEditor(Source).MaxThreadCount;
      FConnectionParamsTunning := TMsgNetworkSettingsEditor(Source).ConnectionParamsTunning;
      FTestPacketCount := TMsgNetworkSettingsEditor(Source).TestPacketCount;
      FDisconnectRetryCount := TMsgNetworkSettingsEditor(Source).DisconnectRetryCount;
      FDisconnectDelay := TMsgNetworkSettingsEditor(Source).DisconnectDelay;
    end;
end; // Assign


//------------------------------------------------------------------------------
// Copy network settings to ConnectParams
//------------------------------------------------------------------------------
procedure TMsgNetworkSettingsEditor.CopySettingsToConnectParams(var ConnectParams: TMsgConnectParams);
begin
  ConnectParams.PacketSize := FPacketSize;
  ConnectParams.MaxThreadCount := FMaxThreadCount;
  ConnectParams.ConnectionParamsTunning := FConnectionParamsTunning;
  ConnectParams.TestPacketCount := FTestPacketCount;
  ConnectParams.DisconnectRetryCount := FDisconnectRetryCount;
  ConnectParams.DisconnectDelay := FDisconnectDelay;
end; // CopySettingsToConnectParams

// TMsgNetworkSettingsEditor



////////////////////////////////////////////////////////////////////////////////
//
// TMsgConnectionParamsEditor
//
////////////////////////////////////////////////////////////////////////////////


//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
constructor TMsgConnectionParamsEditor.Create;
begin
  inherited;
  FCryptoParamsEditor := TMsgCryptoParamsEditor.Create;
  FLocalPort := MsgDefaultClientPort;
  FLocalHost := MsgDefaultServerHost;
end;//Create


//------------------------------------------------------------------------------
// Destroy
//------------------------------------------------------------------------------
destructor TMsgConnectionParamsEditor.Destroy;
begin
  FCryptoParamsEditor.Free;
  inherited;
end; // Destroy


//------------------------------------------------------------------------------
// Assign
//------------------------------------------------------------------------------
procedure TMsgConnectionParamsEditor.Assign(Source: TPersistent);
begin
  if (Source <> nil) then
   if (Source is TMsgConnectionParamsEditor) then
    begin
      FLocalPort := TMsgConnectionParamsEditor(Source).LocalPort;
      FLocalHost := TMsgConnectionParamsEditor(Source).LocalHost;
      FCryptoParamsEditor.Assign(TMsgConnectionParamsEditor(Source).CryptoParams);
    end;
end; // Assign


//------------------------------------------------------------------------------
// return ConnectParams
//------------------------------------------------------------------------------
function TMsgConnectionParamsEditor.GetConnectParams: TMsgConnectParams;
begin
  Result.CryptoInfo := FCryptoParamsEditor.GetCryptoParams;
  Result.LocalHost := FLocalHost;
  Result.LocalPort := FLocalPort;
  Result.ServerID := Integer(MSG_INVALID_USER_ID);  // -1;  // invalid value
end; // GetConnectParams




////////////////////////////////////////////////////////////////////////////////
//
// Global functions
//
////////////////////////////////////////////////////////////////////////////////


//------------------------------------------------------------------------------
// compression algorithm
//------------------------------------------------------------------------------
function ConverTMsgCompressionAlgorithmToMsgCompressionAlgorithm(
    CompressionAlgorithm: TMsgCompressionAlgorithm
          ): TMsgCompressionAlgorithm1;
begin
 Result := acaNone;
 case (CompressionAlgorithm) of
  caZLIB: Result := acaZLIB;
  caBZIP: Result := acaBZIP;
  caPPM: Result := acaPPM;
 end;
end; // ConverTMsgCompressionAlgorithmToMsgCompressionAlgorithm


//------------------------------------------------------------------------------
// compression algorithm
//------------------------------------------------------------------------------
function ConverTMsgCompressionAlgorithm1ToCompressionAlgorithm(
            CompressionAlgorithm: TMsgCompressionAlgorithm1
          ): TMsgCompressionAlgorithm;
begin
 Result := caNone;
 case (CompressionAlgorithm) of
  acaZLIB: Result := caZLIB;
  acaBZIP: Result := caBZIP;
  acaPPM: Result := caPPM;
 end;
end; // ConverTMsgCompressionAlgorithm1ToCompressionAlgorithm


initialization

{$IFDEF DEBUG_LOG_INIT}
aaWriteToLog('MsgComMain> initialization started');
{$ENDIF}

{$IFDEF DEBUG_LOG_INIT}
aaWriteToLog('MsgComMain> initialization finished');
{$ENDIF}

end.

⌨️ 快捷键说明

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