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

📄 unit_findstorage.pas

📁 一款传奇登陆器的源代码,使用DELPHI写的,大家可以参考下
💻 PAS
字号:
unit Unit_FindStorage;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, SUIForm, StdCtrls, SUIEdit, SUIButton, SUIDlg,
  ComCtrls, SUIStatusBar, ScktComp, cxControls, cxContainer, cxMCListBox,
  SUIImagePanel;

type
  TFrm_FindStorage = class(TForm)
    suiMessageDialog1: TsuiMessageDialog;
    CSocket: TClientSocket;
    Timer1: TTimer;
    suiForm1: TsuiForm;
    suiStatusBar1: TsuiStatusBar;
    suiImagePanel1: TsuiImagePanel;
    Label2: TLabel;
    Edit_ID: TsuiEdit;
    Label3: TLabel;
    Edit_Pass: TsuiEdit;
    Bt_Close: TsuiButton;
    Bt_Find: TsuiButton;
    suiImagePanel2: TsuiImagePanel;
    cxMCListBox1: TcxMCListBox;
    procedure Show_Message(text:String;Icon:TsuiIconType);
    procedure Bt_CloseClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure CSocketError(Sender: TObject; Socket: TCustomWinSocket;
      ErrorEvent: TErrorEvent; var ErrorCode: Integer);
    procedure CSocketRead(Sender: TObject; Socket: TCustomWinSocket);
    function DecodeMessagePacket(data:String):integer;
    procedure Bt_FindClick(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Frm_FindStorage: TFrm_FindStorage;
  Step:string;
implementation

uses Unit_Main, Unit_Msg, Unit_MyPro;

{$R *.dfm}

procedure TFrm_FindStorage.Show_Message(text:String;Icon:TsuiIconType);
begin
  suiMessageDialog1.Caption:='提示信息';
  suiMessageDialog1.Text:=text;
  suiMessageDialog1.IconType:=Icon;
  suiMessageDialog1.ShowModal;
end;


procedure TFrm_FindStorage.Bt_CloseClick(Sender: TObject);
begin
  Close;
end;

procedure TFrm_FindStorage.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  CSocket.Active:=False;
  Edit_ID.Text:='';
  Edit_Pass.Text:='';
  cxMCListBox1.Items.Clear;
  Bt_Find.Enabled:=True;
end;

procedure TFrm_FindStorage.CSocketError(Sender: TObject;
  Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
  var ErrorCode: Integer);
begin
  suiStatusBar1.Panels[0].Text:='连接失败,可能未开启注册服务。';
  CSocket.Active:=False;
  ErrorCode:=0;
end;

procedure TFrm_FindStorage.CSocketRead(Sender: TObject;
  Socket: TCustomWinSocket);
var
  str,data:string;
begin
  str:=Socket.ReceiveText;
  str:=ArrestStringEx(str,'#','!',data);
  DecodeMessagePacket(data);
end;

function TFrm_FindStorage.DecodeMessagePacket(data:String):integer;
var
  head, body: String;
  msg:TDefaultMessage;
  SS:T_SFindStorage;
  i:integer;
begin
  Result:=0;
  head := Copy (data, 1, DEFBLOCKSIZE);
  body := Copy (data, DEFBLOCKSIZE+1, Length(data)-DEFBLOCKSIZE);
  msg  := DecodeMessage (head);
  if msg.Comm=SM_FindStoragepass_Fail then
  begin
    if msg.param=1 then
    begin
      show_message('查找角色失败,请联系管理员!',suiWarning);
      Edit_ID.Enabled:=True;
      Edit_ID.SetFocus;
      Bt_Find.Enabled:=True;
    end;
    if msg.param=2 then
    begin
      show_message('查找角色失败,请检查ID和密码输入!',suiWarning);
      Edit_ID.Enabled:=True;
      Edit_ID.SetFocus;
      Bt_Find.Enabled:=True;
    end;
    CSocket.Close;
    suiStatusBar1.Panels[0].Text:='断开连接。';
  end;
  if msg.Comm=SM_FindStoragepass_Success then
  begin
    Bt_Find.Enabled:=False;
    DecodeBuffer(body,@Ss,Sizeof(T_SFindStorage));
    cxMCListBox1.Items.Add(IntToStr(ss.Idx)+';'+Trim(ss.Char)+';'+Trim(ss.StoragePass));
    if msg.param=99 then
    begin
      CSocket.Close;
      suiStatusBar1.Panels[0].Text:='断开连接。';
    end;
  end;
end;



procedure TFrm_FindStorage.Bt_FindClick(Sender: TObject);
begin
  if Length(Edit_Pass.Text)<5 then
  begin
    show_message('密码不能少于5位!',suiWarning);
    Edit_Pass.SetFocus;
    exit;
  end;
  suiStatusBar1.Panels[0].Text:='正在向服务器发送查找角色请求!';
  CSocket.Active:=False;
  CSocket.Address:=Reg_SvrIp;
  CSocket.Port:=Reg_SvrPort;
  Try
    CSocket.Active:=True;
  except end;
  Step:='FindChar';
  Timer1.Enabled:=True;

end;

procedure TFrm_FindStorage.Timer1Timer(Sender: TObject);
var
  CC:T_CFindChar;
  CE:T_CEditChar;
  msg:TDefaultMessage;
begin
  if Step='FindChar' then
  begin
    CC.LoginId:=Edit_ID.Text;
    CC.Password:=Edit_Pass.Text;
    msg:=MakeDefaultMsg(CM_FindStoragePass,0);
    SendSocket(CSocket.Socket,EncodeMessage(msg)+EncodeBuffer(@CC, sizeof(T_CFindChar)));
    Step:='';
  end;
  Timer1.Enabled:=False;
end;

procedure TFrm_FindStorage.FormCreate(Sender: TObject);
begin
  SetForm_Style(suiForm1,ExeType);
end;

end.

⌨️ 快捷键说明

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