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

📄 unit_main.pas

📁 一款传奇登陆器的源代码,使用DELPHI写的,大家可以参考下
💻 PAS
📖 第 1 页 / 共 3 页
字号:
          msg.Comm:=SM_EditChar_Fail;                  //未知原因
          msg.param:=2;
          Send_Str:=EncodeMessage(msg);
        end;
        80:
        begin
          Tmp_Msg_Char.Comm:=SM_FindStoragepass_Success;
          Tmp_Msg_Char.param:=0;
          Tmp_soCket_Char:=C_Socket;
          Timer2.Enabled:=True;
          Exit;
        end;
        81:
        begin
          msg.Comm:=SM_FindStoragepass_Fail;
          msg.param:=1;                      //未知错误
          Send_Str:=EncodeMessage(msg);
        end;
        82:
        begin
          msg.Comm:=SM_FindStoragepass_Fail;                  //没找到
          msg.param:=2;
          Send_Str:=EncodeMessage(msg);
        end;
        else
        begin
          Timer_Recv.Enabled:=True;
          Exit;
        end;
      end;
      New(Send_Msg);
      Send_Msg.Socket:=C_Socket;
      Send_Msg.Str:=Send_Str;
      MsgSend_List.Add(PTmsg(Send_Msg));
    finally
      Timer_Recv.Enabled:=True;
    end;
  end;
end;

function TFrmMain.DecodeMessagePacket(Socket:TCustomWinSocket;data:String):integer;
var
  head, body: String;
  ue:TUserInfo;
  pf:T_SFindQuiz;
  Cf:T_CFindPass;
  Cp:T_CEditPass;
  CC:T_CFindChar;
  SC:P_SFindChar;
  SS:P_SFindStorage;
  Ce:T_CEditChar;
  msg:TDefaultMessage;
  Str:String;
  LoginId,oldPassWord,PassWord,Quz1,Answer1,Quz2,Answer2,UserName,BirthDay,Phone,SSNo,Email:string;
  port:integer;
  ErrorCode:integer;
begin
  Result:=0;
  LoginId:='';
  PassWord:='';
  Quz1:='';
  Answer1:='';
  Quz2:='';
  Answer2:='';
  head := Copy (data, 1, DEFBLOCKSIZE);
  body := Copy (data, DEFBLOCKSIZE+1, Length(data)-DEFBLOCKSIZE);
  msg  := DecodeMessage (head);
  if msg.Comm = CM_AddNewId then
  begin
    DecodeBuffer(body,@ue,Sizeof(TUserInfo));
    if (Length(Trim(ue.LoginId))<5) or (Length(Trim(ue.PassWord))<5) or (Length(Trim(ue.Quz1))<5) or (Length(Trim(ue.Answer1))<5) or (Length(Trim(ue.Quz2))<5) or (Length(Trim(ue.Answer2))<5) then
    begin
     Result:=11;//帐号、密码等不能少于5位
     exit;
    end;
    if pos(' ',Trim(ue.LoginId))>0 then
    begin
      Result:=13;
      exit;
    end;
    if pos(' ',Trim(ue.PassWord))>0 then
    begin
      Result:=13;
      exit;
    end;
    LoginId:=Trim(ue.LoginId);
    PassWord:=Trim(ue.PassWord);
    UserName:=Trim(ue.UserName);
    BirthDay:=Trim(ue.BirthDay);
    Phone:=Trim(ue.Phone);
    SSNo:=Trim(ue.SSNo);
    Email:=Trim(ue.Email);
    Quz1:=ue.Quz1;
    Answer1:=ue.Answer1;
    Quz2:=ue.Quz2;
    Answer2:=ue.Answer2;
    with StoredProc_Add_User do
    begin
      Parameters.ParamByName('@uid').Value:=LoginId;
      Parameters.ParamByName('@username').Value:=UserName;
      Parameters.ParamByName('@birthday').Value:=BirthDay;
      Parameters.ParamByName('@phone').Value:=UserName;
      Parameters.ParamByName('@ssno').Value:=SSNo;
      Parameters.ParamByName('@email').Value:=Email;
      Parameters.ParamByName('@quest1').Value:=Quz1;
      Parameters.ParamByName('@answer1').Value:=Answer1;
      Parameters.ParamByName('@quest2').Value:=Quz2;
      Parameters.ParamByName('@answer2').Value:=Answer2;
      Parameters.ParamByName('@password').Value:=PassWord;
      try
        ExecProc;
        ErrorCode:=Parameters.paramByName('@RETURN_VALUE').Value;
        if ErrorCode=0 then
        begin
          Result:=10;//建立成功
        end;
        if ErrorCode=1 then
        begin
          Result:=11;//有数据为空
        end;
        if ErrorCode=2 then
        begin
          Result:=12;//帐号存在
        end;
        if ErrorCode=3 then
        begin
          Result:=13;//不知明错误
        end;
      except
        Result:=13;
      end;
    end;
  end;
  if msg.Comm=CM_FindQuiz then
  begin
    DecodeBuffer(body,@pf,Sizeof(T_SFindQuiz));
    LoginId:=pf.LoginId;
    with StoredProc_Find_Quiz do
    begin
      Parameters.ParamByName('@uid').Value:=LoginId;
      try
        ExecProc;
        ErrorCode:=Parameters.paramByName('@RETURN_VALUE').Value;
        if (ErrorCode=0) and (Parameters.paramByName('@quest1').Value<>null) and (Parameters.paramByName('@quest2').Value<>null) then
        begin
          Result:=20;//查找帐号成功
          Result_FindQuiz.LoginId:='';
          Result_FindQuiz.Quz1:='';
          Result_FindQuiz.Quz2:='';
          Result_FindQuiz.LoginId:=LoginId;
          Result_FindQuiz.Quz1:=Parameters.paramByName('@quest1').Value;
          Result_FindQuiz.Quz2:=Parameters.paramByName('@quest2').Value;
        end;
        if ErrorCode=1 then Result:=21;//帐号为空;
        if ErrorCode=2 then Result:=22;//帐号不存在
      except
        Result:=21;
      end;
    end;
  end;
  if msg.Comm=Cm_FindPass then
  begin
    DecodeBuffer(body,@cf,Sizeof(T_CFindPASS));
    LoginId:=cf.LoginId;
    Quz1:=Cf.Quz1;
    Quz2:=Cf.Quz2;
    Answer1:=cf.Answer1;
    Answer2:=Cf.Answer2;
    with StoredProc_FindPass do
    begin
      Parameters.ParamByName('@uid').Value:=LoginId;
      Parameters.ParamByName('@quest1').Value:=Quz1;
      Parameters.ParamByName('@answer1').Value:=Answer1;
      Parameters.ParamByName('@quest2').Value:=Quz2;
      Parameters.ParamByName('@answer2').Value:=Answer2;
      try
        ExecProc;
        ErrorCode:=Parameters.paramByName('@RETURN_VALUE').Value;
        if ErrorCode=0 then
        begin
          Result_FindPass.PassWord:='';
          Result_FindPass.PassWord:=Parameters.paramByName('@password').Value;
          Result:=30;//密码找到
        end;
        if ErrorCode=1 then
        begin
          Result:=31;//有数据为空
        end;
        if ErrorCode=2 then
        begin
          Result:=32;//格式不符合
        end;
      except
        Result:=32;//格式不符合
      end;
    end;
  end;
  if msg.Comm=CM_EditPass then
  begin
    DecodeBuffer(body,@Cp,Sizeof(T_CEditPass));
    LoginId:=Cp.LoginId;
    PassWord:=Cp.NewPassWord;
    oldPassWord:=cp.OldPassWord;
    if Length(Trim(PassWord))<5 then
    begin
      Result:=41;//密码不能少于5位
      exit;
    end;
    with StoredProc_Edit_Pass do
    begin
      Parameters.ParamByName('@uid').Value:=LoginId;
      Parameters.ParamByName('@oldpassword').Value:=oldPassWord;
      Parameters.ParamByName('@newpassword').Value:=PassWord;
      try
        ExecProc;
        ErrorCode:=Parameters.paramByName('@RETURN_VALUE').Value;
        if ErrorCode=0 then
        begin
          Result:=40;
          Result_EditPass.PassWord:='';
          Result_EditPass.PassWord:=Parameters.paramByName('@newpassword').Value;
        end;
        if ErrorCode=1 then
        begin
          Result:=42;//帐号不存在
        end;
        if ErrorCode=2 then
        begin
          Result:=43;//旧密码错误
        end;
        if (ErrorCode=2) or (ErrorCode=3) then
        begin
          Result:=44;//有非法字符
        end;
      except
        Result:=44;//有非法字符
      end;
    end;
  end;
  if msg.Comm=CM_GetMirServer then
  begin
    Result:=50;
  end;
  if msg.Comm=CM_FindChar then
  begin
    DecodeBuffer(body,@CC,Sizeof(T_CFindChar));
    LoginId:=CC.LoginId;
    PassWord:=CC.Password;
    With ADOQuery_Game do
    begin
      Close;
      Sql.Clear;
      Sql.Add('exec find_char '''+LoginId+''','''+PassWord+'''');
      Try Open;
      except Result:=61;//未知错误
      end;
      if Recordset.RecordCount=0 then
      begin
        Result:=62;//没有找到角色
        exit;
      end;
      Try Result_chars.Free; except end;
      Result_Chars:=TList.Create;
      while not eof do
      begin
        New(SC);
        Sc.Idx:=Fields[0].AsInteger;
        Sc.Char:=Fields[1].AsString;
        Sc.Deleted:=Fields[2].AsInteger;
        Result_Chars.Add(SC);
        Next;
      end;
      Result:=60;
    end;
  end;
  if msg.Comm=CM_EditChar then
  begin
    DecodeBuffer(body,@Ce,Sizeof(T_CEditChar));
    with ADOStoredProc_Editchar.Parameters do
    begin
      ParamByName('@uid').Value:=Trim(ce.LoginId);
      ParamByName('@password').Value:=Trim(ce.Password);
      ParamByName('@idx').Value:=ce.Idx;
      ParamByName('@deleted').Value:=Ce.Deleted;
    end;
    try ADOStoredProc_Editchar.ExecProc; except result:=72 end;
    if ADOStoredProc_Editchar.Parameters.parambyname('@return_value').Value=0 then Result:=70;
    if ADOStoredProc_Editchar.Parameters.parambyname('@return_value').Value=1 then Result:=71;
    if ADOStoredProc_Editchar.Parameters.parambyname('@return_value').Value=2 then Result:=72;
  end;
  if msg.Comm=CM_FindStoragePass then
  begin
    DecodeBuffer(body,@CC,Sizeof(T_CFindChar));
    LoginId:=CC.LoginId;
    PassWord:=CC.Password;
    With ADOQuery_Game do
    begin
      Close;
      Sql.Clear;
      Sql.Add('exec find_storage '''+LoginId+''','''+PassWord+'''');
      Try Open;
      except Result:=81;//未知错误
      end;
      if Recordset.RecordCount=0 then
      begin
        Result:=82;//没有找到角色
        exit;
      end;
      Try Result_chars.Free; except end;
      Result_Chars:=TList.Create;
      while not eof do
      begin
        New(SS);
        SS.Idx:=Fields[0].AsInteger;
        SS.Char:=Fields[1].AsString;
        SS.StoragePass:=Fields[2].AsString;
        Result_Chars.Add(SS);
        Next;
      end;
      Result:=80;
    end;
  end;

end;


procedure TFrmMain.SSocketClientError(Sender: TObject;
  Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
  var ErrorCode: Integer);
begin
  ErrorCode:=0;
end;

procedure TFrmMain.Button1Click(Sender: TObject);
begin
  if Button1.Tag=0 then
  begin
    if not CheckEi then
    begin
      ShowMessage('请先运行EiServer!');
      exit;
    end;
    if CheckBox_Wg.Checked then
    begin
      if (not Frm_Eywg.Check_Bp.Checked) and (not Frm_Eywg.check_king.Checked) and (not Frm_Eywg.Check_dbt.Checked) and (not Frm_Eywg.Check_dscq.Checked) and (not Frm_Eywg.Check_007.Checked) and (not Frm_Eywg.Check_wj.Checked) then
      begin
        ShowMessage('请先指定禁止使用的外挂。');
        Frm_Eywg.ShowModal;
        exit;
      end;
    end;
    if (not FileExists(Edit_GuildPath.Text+'Guildlist.txt')) and Check_Guildindex.Checked then
    begin
      ShowMessage('行会数据不存在!');
      exit;
    end;
    if (Not DirectoryExists(Edit_indexPath.Text)) and (Check_LevelIndex.Checked or Check_GoldIndex.Checked or Check_Guildindex.Checked) then
    begin
      ShowMessage('请指定正确的WEB服务目录!');
      Exit;
    end;
    if CheckBox_VerCode.Checked then SetMir3(StrToInt64(Edit_VerCode.Text)) else SetMir3(20030704);
    Button1.Tag:=1;
    Button1.Caption:='关闭服务';
    ServerPort:=StrToInt(Edit_ServPort.text);
    SSocket.Port:=ServerPort;
    SSocket.Active:=True;
    Timer_BuildIdx.Interval:=StrToInt(Edit_indexTime.Text)*60*60*1000;
    Timer_BuildIdx.Enabled:=True;
   if Check_LevelIndex.Checked then Build_Mir3idx(0);
   if Check_GoldIndex.Checked then Build_Mir3idx(1);
   if Check_Guildindex.Checked then Build_Mir3idx(2);
  end
  else
  begin
    Try
      SetMir3(20030704);
      Button1.Tag:=0;
      Button1.Caption:='开启服务';
      SSocket.Close;
      ADOConnection1.Connected:=False;
      ADOConnection2.Connected:=False;
      ADOConnection3.Connected:=False;
      Button1.Enabled:=False;
      Button3.Enabled:=True;
    except end;
  end;
  FrmMain.Visible:=False;
end;

function TFrmMain.EncodeStr(temp:string):String;
var
  i:integer;
begin
  SetLength(Result,length(temp));
  for i:= 1 to length(temp) do
  begin
    Result[i] := chr(byte(temp[i]) xor 61);
  end;
end;




procedure TFrmMain.RunScript(const sSQL: String);
begin
  ADOQuery1.SQL.Text := sSQL;
  ADOQuery1.ExecSQL;
end;


procedure TFrmMain.Timer2Timer(Sender: TObject);
var
  Result_char:T_SFindChar;
  Result_Storage:T_SFindStorage;
  Send_str:String;
  Send_Msg:PTMsg;
begin
  Timer2.Enabled:=False;
  Try
  if Result_Chars.Count>0 then
  begin
    if Tmp_Msg_Char.Comm=SM_FindChar_Success then
    begin
      Result_char.Idx:=P_SFindChar(Result_Chars[0]).Idx;
      Result_char.Deleted:=P_SFindChar(Result_Chars[0]).Deleted;
      Result_char.Char:=P_SFindChar(Result_Chars[0]).Char;
    end;
    if Tmp_Msg_Char.Comm=SM_FindStoragepass_Success then
    begin
      Result_Storage.Idx:=P_SFindStorage(Result_Chars[0]).Idx;
      Result_Storage.Char:=P_SFindStorage(Result_Chars[0]).Char;
      Result_Storage.StoragePass:=P_SFindStorage(Result_Chars[0]).StoragePass;
      if Result_Storage.StoragePass='' then Result_Storage.StoragePass:='空';
    end;
    if Result_Chars.Count=1 then
    begin
      Tmp_Msg_Char.param:=99;
    end;
    if Tmp_Msg_Char.Comm=SM_FindChar_Success then Send_str:=EncodeMessage(Tmp_Msg_Char)+EncodeBuffer(@Result_Char,Sizeof(T_SFindChar));
    if Tmp_Msg_Char.Comm=SM_FindStoragepass_Success then Send_str:=EncodeMessage(Tmp_Msg_Char)+EncodeBuffer(@Result_Storage,Sizeof(T_SFindStorage));    Try Result_chars.Delete(0) except end;
    New(Send_Msg);
    Send_Msg.Socket:=Tmp_soCket_Char;
    Send_Msg.Str:=Send_Str;
    MsgSend_List.Add(PTmsg(Send_Msg));
  end;
  finally
    Timer2.Enabled:=True;
  end;
  if Result_chars.Count=0 then
  begin
    if not Timer_Recv.Enabled then Timer_Recv.Enabled:=True;
  end;
end;

procedure TFrmMain.Timer_BackupTimer(Sender: TObject);
begin
  Timer_Backup.Enabled:=False;
  with ADOQuery2 do
  begin
    Close;
    Sql.Clear;
    Sql:=Memo_Backup.Lines;
    ExecSQL;

⌨️ 快捷键说明

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