传奇单机版,GM论坛,传奇版本库,GM基地

DD145登录器源码Delphi冷雨夜lyy源代码

[复制链接]
查看: 230   回复: 0     # 登录器源码

197

主题

199

帖子

7614

积分

霸王教主

Rank: 9Rank: 9Rank: 9

积分
7614
2022-9-12 17:13:48   显示全部楼层   阅读模式  
lyy登录器源码DD145版,编译通过可使用,二次开发可利用性高,小白勿下,干货收藏

DD145.png
[Delphi] 纯文本查看 复制代码
unit LyThread;

{$I Ver.Inc}

interface

uses
  Classes, StdCtrls, Windows, SysUtils, Controls, IdHTTP, FastIniFile, DateUtils;

type
  TExistFile = class(TThread)
  private
  protected
    procedure Execute; override;
  public
    constructor Create(); reintroduce;
  end;

  TUpIP = class(TThread)
  private
    Str: string;
    function Get(URL: string): boolean;
    function AddList: boolean;
    function CheckUpdateInfo: boolean;
    function CheckFixFile: boolean;
    function GetIni: boolean;
  protected
    procedure Execute; override;
    procedure ShowForm;
    procedure ShowLoginUPForm;
    procedure ReStartLogin;
    procedure GetIniCrcError;
  public
    constructor Create(const DownUrl: string); reintroduce;
  end;

var
  TExistFile_Thread : TExistFile;       //释放文件线程
  TUpIP_Thread      : TUpIP;            //自动更新线程

implementation

uses Mir3, MAIN, LyyMir3UP, Func;

constructor TExistFile.Create();
begin
  FreeOnTerminate := True;              // 自动删除
  inherited Create(False);              // 直接运行
end;

procedure TExistFile.Execute;
begin
  try
    if not DirectoryExists(FullPath + 'Update\') then ForceDirectories(FullPath + 'Update\');
    if not DirectoryExists(FullPath + 'Config\') then ForceDirectories(FullPath + 'Config\');
    //检测并生成WINRAR解压缩组件
    if not FileExists(FullPath + 'LyyConfig\UnzLib.dll') then ExtractRes('exefile', UnRARDLLRes, PChar(FullPath + 'Config\UnzLib.dll'));
    ExtractRes('exefile', 'Data_RES1', PChar(FullPath + 'Weapon.ord'));
    ExtractRes('exefile', 'Data_RES2', PChar(FullPath + 'BgmList.wwl'));
    ExtractRes('exefile', 'Data_RES3', PChar(FullPath + 'CmList.dat'));
    ExtractRes('exefile', 'Data_RES4', PChar(FullPath + 'Magic.exp'));
    ExtractRes('exefile', 'Data_RES5', PChar(FullPath + 'Map.Mif'));
    ExtractRes('exefile', 'Data_RES6', PChar(FullPath + 'MExplain.exp'));
    ExtractRes('exefile', 'Data_RES7', PChar(FullPath + 'MInfo.dat'));
    ExtractRes('exefile', 'Data_RES8', PChar(FullPath + 'SoundList.wwl'));
    
    DelFile(mir3path);                  //删除mir3.exe

    //if not DirectoryExists(DLLPath) then ForceDirectories(DLLPath);
  //  if not FileExists(DLLPath + 'mir3.dll') then ExtractRes('exefile', DbtDllRes, PChar(DLLPath + 'mir3.dll'));

    DelFile(FullPath + 'MyMir3.dll');
    ExtractRes('exefile', 'Mir3_RESO', PChar(FullPath + 'MyMir3.dll'));
    DelFile(FullPath + 'KingMir3.dll');
    ExtractRes('exefile', 'Mir3_RESP', PChar(FullPath + 'KingMir3.dll'));
//    DelFile(FullPath + 'LyyMir3.dll');
//    ExtractRes('exefile', 'Mir3_RESQ', PChar(FullPath + 'LyyMir3.dll'));
    DelFile(FullPath + 'ClentEx.dll');
    ExtractRes('exefile', 'Mir3_RESH', PChar(FullPath + 'ClentEx.dll'));

    //删除多余文件,加速游戏
    DelFile(FullPath + 'Data\CreateChr.dat');
    DelFile(FullPath + 'Data\StartGame.dat');
    DelFile(FullPath + 'Data\wemade.dat');
  except
  end;
end;

constructor TUpIP.Create(const DownUrl: string);
begin
  Str := DownUrl;
  FreeOnTerminate := True;              // 自动删除
  inherited Create(False);              // 直接运行
end;

procedure TUpIP.ReStartLogin;
begin
  Form1.suiMessageDialog1.Caption := '需要重启登录器';
  Form1.suiMessageDialog1.Text := '登录器配置文件升级成功,必须重新启动登录器后才生效,不重启可能无法正常游戏,是否现在就重新启动登录器!?';
  if Form1.suiMessageDialog1.ShowModal = mrok then
  begin
    _bReStartLogin := True;
    Form1.Close;
  end;
end;

procedure TUpIP.ShowLoginUPForm;
begin
  Form1.TrayIcon1.MinimizeApp;
  Form1.Timer1.Enabled := True;
end;

procedure TUpIP.ShowForm;
begin
  if _bEnableCue then
  begin
    Form1.suiMessageDialog1.Caption := '自动更新';
    Form1.suiMessageDialog1.Text := '检测到你的客户端有文件需要更新,是否现在更新(不更新可能影响正常游戏)!?';
    if Form1.suiMessageDialog1.ShowModal = mrok then
    begin
      Form_Update.ShowModal;
    end;
  end
  else
  begin
    Form_Update.ShowModal;
  end;
end;

function TUpIP.Get(URL: string): boolean; //获得更新信息
var
  sDownUrl          : string;
  IdHTTP            : TIDHttp;
  FileStr           : TStringList;
  ChkStr            : string;
begin
  try
    sDownUrl := URL;
    //if copy(sDownUrl, Length(sDownUrl), 1) <> '/' then sDownUrl := sDownUrl + '/';
    FileStr := TStringList.Create;
    IdHTTP := TIDHttp.Create(nil);
    try
      Result := False;
      IdHTTP.HandleRedirects := True;   //必须支持重定向否则可能出错
      IdHTTP.ReadTimeout := 30000;      //超过这个时间则不再访问
      FileStr.Add(IdHTTP.Get(sDownUrl));
      //判断是否正确的格式
      ChkStr := FileStr.Strings[0];
      if Q_PosStr(';;;;;LYY Mir3Login Update File;;;;;', ChkStr) > 0 then
      begin
        DelFile(sUpInfoini);
        FileStr.SaveToFile(sUpInfoini); //保存本地升级信息文件
        Result := True;
      end
      else
      begin
        Result := False;
      end;
    finally
      FreeAndNil(IdHTTP);
      FreeAndNil(FileStr);
    end;
  except
    Result := False;
  end;
end;

function TUpIP.CheckFixFile: boolean;
var
  NFile             : string;
  PUDL              : PTUpdateList;
  SelfPath          : string;
  SelFileTime       : TDateTime;
begin
  SelfPath := FullPath;
  SelfPath := Copy(SelfPath, 1, Length(SelfPath) - 1);
  while (True) do
  begin
    if UPList.Count = 0 then break;
    PUDL := UPList.Items[0];
    NFile := SelfPath + PUDL^.FilePath + PUDL^.ToFile;
    if not FileExists(NFile) then       //文件不存在
    begin
      //MessageBox(0, PChar(NFile), '文件不存在', MB_OK + MB_ICONSTOP);
      Result := True;
      Exit;
    end;
    SelFileTime := GetFileDateTime(NFile, fttLastWrite);
    if SecondsBetween(SelFileTime, PUDL^.FileDateTime) > 30 then
    begin
      //MessageBox(0, PChar(NFile), '文件日期不正确', MB_OK + MB_ICONSTOP);
      Result := True;
      Exit;
    end;
    Dispose(PTUpdateList(UPList.Items[0]));
    UPList.Delete(0);
  end;
  Result := False;
end;

function TUpIP.CheckUpdateInfo: boolean;
var
  Ini               : TFastIniFile;
begin
  try
    Ini := TFastIniFile.Create(sUpInfoini);
    try
      try
        _bCheckLong := Ini.ReadBoolean('UpdateInfo', 'CheckLong', False);
        _sLongURL := Ini.ReadString('UpdateInfo', 'LongURL', '');
        _sLongCode := Ini.ReadString('UpdateInfo', 'LongCode', '');
        _bCheckIni := Ini.ReadBoolean('UpdateInfo', 'CheckIni', False);
        _sIniURL := Ini.ReadString('UpdateInfo', 'IniURL', '');
        _sIniCode := Ini.ReadString('UpdateInfo', 'IniCode', '');
        _bCheckFix := Ini.ReadBoolean('UpdateInfo', 'CheckFix', False);
        _sDefUrl := Ini.ReadString('UpdateInfo', 'DefURL', '');
        _bEnableCue := Ini.ReadBoolean('UpdateInfo', 'EnableCue', False);
        _sDllURL := Ini.ReadString('UpdateInfo', 'DLLURL', '');
        _sDllCode := Ini.ReadString('UpdateInfo', 'DLLCode', '');
        if _bCheckLong then _bCheckLong := (_sLongURL <> '') and (_sLongCode <> '');
        if _bCheckIni then _bCheckIni := (_sIniURL <> '') and (_sIniCode <> '');
        if _bCheckFix then _bCheckFix := _sDefUrl <> '';
        Result := _bCheckLong or _bCheckIni or _bCheckFix;
      except
        Result := False;
      end;
    finally
      FreeAndNil(Ini);
    end;
  except
    Result := False;
  end;
end;

function TUpIP.AddList: boolean;
var
  Ini               : TFastIniFile;
  SectionStringList : TStringList;
  i                 : Integer;
  SectionName       : string;
  PUDL              : PTUpdateList;
  sFromFile, sFilePath, sFileDateTime: string;
  FileDateTime      : TDateTime;
begin
  try
    Ini := TFastIniFile.Create(sUpInfoini);
    SectionStringList := TStringList.Create;
    try
      try
        Ini.ReadSections(SectionStringList);
        for i := 0 to SectionStringList.Count - 1 do
        begin
          SectionName := SectionStringList.Strings[i];
          if Q_UpperCase(SectionName) <> Q_UpperCase('UpdateInfo') then
          begin
            try
              sFromFile := Ini.ReadString(SectionName, 'FromFile', '');
              sFilePath := Ini.ReadString(SectionName, 'FilePath', '');
              sFileDateTime := Ini.ReadString(SectionName, 'FileDateTime', '');
              if (sFromFile <> '') and (sFilePath <> '') and (sFileDateTime <> '') then
              begin
                FileDateTime := StrToDateTime(sFileDateTime);
                New(PUDL);
                PUDL^.FromFile := sFromFile;
                PUDL^.ToFile := SectionName;
                PUDL^.FilePath := sFilePath;
                PUDL^.FileDateTime := FileDateTime;
                UPList.Add(PUDL);
              end;
            except
              continue;
            end;
          end;
        end;
        //MessageBox(0, PChar(IntToStr(UPList.Count)), '', MB_OK + MB_ICONSTOP);
        Result := UPList.Count > 0;
      except
        Result := False;
      end;
    finally
      FreeAndNil(Ini);
      FreeAndNil(SectionStringList);
    end;
  except
    Result := False;
  end;
end;

procedure TUpIP.GetIniCrcError;
begin
  //MessShow(3, '由于更新中的登录器配置文件校验失败,登录器配置无法更新到最新状态,你可以继续游戏,但是可能不正常,请联系管理员解决!');
  Form1.suiMSNPopForm1.Title := '登录器配置文件更新失败';
  Form1.suiMSNPopForm1.MessageText := '登录器配置文件更新时校验失败,登录器配置无法更新到最新状态,这可能会影响你正常游戏,请联系管理员解决.';
  Form1.suiMSNPopForm1.Popup;
end;

function TUpIP.GetIni: boolean;         //下载
var
  IdHTTP            : TIDHttp;
  TempFile          : string;
  Error32           : WORD;
  TempCrc           : DWORD;
  TStream           : TMemoryStream;
begin
  try
    TempFile := FullPath + 'update\' + ExtractFileName(sUpIPini);
    DelFile(TempFile);
    TStream := TMemoryStream.Create;
    IdHTTP := TIDHttp.Create(nil);
    try
      IdHTTP.HandleRedirects := True;   //必须支持重定向否则可能出错
      IdHTTP.ReadTimeout := 30000;      //超过这个时间则不再访问
      IdHTTP.Get(_sIniURL, TStream);
      TStream.SaveToFile(TempFile);
    finally
      FreeAndNil(IdHTTP);
      FreeAndNil(TStream);
    end;
    //检测CRC
    Hex3Kol(TempFile, TempCrc, Error32);
    if (Error32 <> 0) or (Q_IntToStr(TempCrc) <> _sIniCode) then //校验失败
    begin
      Synchronize(GetIniCrcError);
      Result := False;
    end
    else
    begin
      DelFile(sUpIPini);                //删除目标文件
      CopyFile(PChar(TempFile), PChar(sUpIPini), False); //复制文件到目标
      DelFile(TempFile);                //删除update目录中的临时文件
      Result := True;
    end;
  except
    Result := False;
  end;
end;

procedure TUpIP.Execute;
begin
  if Get(Str) then
  begin
    //检测三选项以及读取选项内容
    if FileExists(sUpInfoini) and CheckUpdateInfo then
    begin
      //是否更新配置文件
      if _bCheckIni and (IniCrc <> 0) and (_sIniCode <> Q_IntToStr(IniCrc)) then
      begin
        if GetIni then                  //更新成功,提示重启登录器
        begin
          Synchronize(ReStartLogin);
          Exit;
        end;
      end;

      //是否更新登录器
      if _bCheckLong and (LongCrc <> 0) and (_sLongCode <> Q_IntToStr(LongCrc)) then
      begin
        Synchronize(ShowLoginUPForm);
        Exit;
      end;

      //是否更新补丁,并读取更新列表,并检测文件是否需要更新
      if _bCheckFix and AddList and CheckFixFile then
      begin
        Synchronize(ShowForm);
      end;
    end;
  end;
end;

end.

游客,如果您要查看本帖隐藏内容请回复





上一篇:冷雨夜Ei3.0登录器源码Delphi全套+网关+反外挂插件
下一篇:lyyloginGate登录网关源码-delphi编译通过
回复 关闭延时

使用道具 举报

您需要登录后才可以回帖   登录 立即注册

高级模式

Powered by Discuz! X3.4 © Comsenz Inc.

Archiver|手机版|小黑屋|美林传奇GM论坛 ( 蜀ICP备2020030293号-2 )