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

📄 rundb.pas

📁 乐都SQL版传奇全套代码,绝对可编译
💻 PAS
📖 第 1 页 / 共 2 页
字号:
            End;
          End;
        until not SocketStream.WaitForData(dwTimeOut);
     finally
         SocketStream.Free;
     end;
   End;

End;
{var
  boLoadDBOK                            : Boolean;
  dwTimeOutTick                         : LongWord;
  s24, s28, s2C, sCheckFlag, sDefMsg, s38: string;
  nLen                                  : Integer;
  nCheckCode                            : Integer;

resourcestring
  sLoadDBTimeOut                        = '[RunDB] 读取人物数据超时...';
  sSaveDBTimeOut                        = '[RunDB] 保存人物数据超时...';
begin
  boLoadDBOK := False;
  Result := False;
  dwTimeOutTick := GetTickCount();
  while (True) do
  begin
    if (GetTickCount - dwTimeOutTick) > dwTimeOut then
    begin
      n4EBB6C := n4EBB68;
      break;
    end;
    s24 := '';
  //  EnterCriticalSection(UserDBSection);
    try
      if Pos('!', g_Config.sDBSocketRecvText) > 0 then
      begin
        s24 := g_Config.sDBSocketRecvText;
        g_Config.sDBSocketRecvText := '';
      end;
    finally
   //   LeaveCriticalSection(UserDBSection);
    end;
    if s24 <> '' then
    begin
      s28 := '';
      s24 := ArrestStringEx(s24, '#', '!', s28);
      if s28 <> '' then
      begin
        s28 := GetValidStr3(s28, s2C, ['/']);
        nLen := length(s28);
        if (nLen >= SizeOf(TDefaultMessage)) and (Str_ToInt(s2C, 0) = nQueryID)
          then
        begin
          nCheckCode := MakeLong(Str_ToInt(s2C, 0) xor 170, nLen);
          sCheckFlag := EncodeBuffer(@nCheckCode, SizeOf(Integer));
         // if CompareBackLStr(s28, sCheckFlag, length(sCheckFlag)) then
          begin
            if nLen = DEFBLOCKSIZE then
            begin
              sDefMsg := s28;
              s38 := '';                                    // -> 004B3F56
            end
            else
            begin                                           //004B3F1F
              sDefMsg := Copy(s28, 1, DEFBLOCKSIZE);
              s38 := Copy(s28, DEFBLOCKSIZE + 1, length(s28) - DEFBLOCKSIZE -
                6);
            end;                                            //004B3F56
            Msg := DecodeMessage(sDefMsg);
            sStr := s38;
            boLoadDBOK := True;
            Result := True;
            break;
          end ;

        end
        else
        begin                                               //004B3F90
          Inc(g_Config.nLoadDBErrorCount);                  // -> 004B3FA5
          break;
        end;
      end;                                                  //004B3FA5
    end
    else
    begin                                                   //004B3F99
      Sleep(0);
     // Application.ProcessMessages;
    end;
  end;

  if not boLoadDBOK then
  begin
    if boLoadRcd then
    begin
      MainOutMessage(sLoadDBTimeOut);
    end
    else
    begin
    ;//  MainOutMessage(sSaveDBTimeOut);
    end;
  end;
                                                       //004B3FD7
  if (GetTickCount - dwTimeOutTick) > dwRunDBTimeMax then
  begin
    dwRunDBTimeMax := GetTickCount - dwTimeOutTick;
  end;
  g_Config.boDBSocketWorking := False;
end;
 }
function MakeHumRcdFromLocal(var HumanRcd: THumDataInfo): Boolean;
begin
  FillChar(HumanRcd, SizeOf(THumDataInfo), #0);
  HumanRcd.Data.Abil.Level := 30;
  Result := True;
end;

function LoadHumRcdFromDB(sAccount, sCharName, sStr: string; var HumanRcd:
  THumDataInfo; nCertCode: Integer): Boolean;               //004B3A68
begin
  Result := False;
  FillChar(HumanRcd, SizeOf(THumDataInfo), #0);
  if LoadRcd(sAccount, sCharName, sStr, nCertCode, HumanRcd) then
  begin
    if (HumanRcd.Data.sChrName = sCharName) and ((HumanRcd.Data.sAccount = '')
      or (HumanRcd.Data.sAccount = sAccount)) then
      Result := True;

  end;
  Inc(g_Config.nLoadDBCount);
end;

function SaveHumRcdToDB(sAccount, sCharName: string; nSessionID: Integer; var
  HumanRcd: THumDataInfo): Boolean;                         //004B3B5C
begin
  Result := SaveRcd(sAccount, sCharName, nSessionID, HumanRcd);
  Inc(g_Config.nSaveDBCount);
end;
function RCheckGuildName(GuildName:string):Boolean;
var
  dwTimeOutTick:LongWord;
begin
  Result:=True;
  if g_MemShared.Open=0 then Exit;

  
  g_MemShared.Name:=GuildName;
  g_MemShared.HasChecked:=1;
  dwTimeOutTick:=GetTickCount;
  while (True) do
  begin
    if (GetTickCount - dwTimeOutTick) > 5000 then
    begin
      n4EBB6C := n4EBB68;
      break;
    end;
    if g_MemShared.HasChecked=2 then
    begin
      Result:=True;
      Break;
    End;
    if g_MemShared.HasChecked=3 then
    begin
      Result:=False;
      Break;
    End;
    Application.ProcessMessages;
  ENd;
  g_MemShared.HasChecked:=0;
 { nQueryID := GetQueryID(@g_Config);
  Result := False;
  n4EBB68 := DB_CHECKGUILDNAME;
  SendDBSockMsg(nQueryID, EncodeMessage(MakeDefaultMsg(DB_CHECKGUILDNAME,
    0, 0, 0, 0)) + EncodeString(GuildName));
  if GetDBSockMsg(nQueryID, Msg, sStr, 15000, False) then
  begin
    if (Msg.Ident = DBR_CHECKGUILDNAME) and (Msg.Recog = 0) then
      Result := True;
  end;
  }
ENd;
function SaveRcd(sAccount, sCharName: string; nSessionID: Integer; var HumanRcd:
  THumDataInfo): Boolean;                                   //004B42C8
var

  i:Integer;
begin
  Result:=False;
  EnterCriticalSection(UserHumDataSection);
  try
    for i:=0 to 99 do
    begin
       if g_MemShared.SaveData[i].SaveStatus=0 then
       begin
         Move(HumanRcd.Data,g_MemShared.SaveData[i].HumanData,SizeOf(ThumData));
         g_MemShared.SaveData[i].SaveStatus:=1;
         Result:=True;
         Break;
       end;

    End;
  finally
    LeaveCriticalSection(UserHumDataSection);
  end;

end;

//004B4080

function LoadRcd(sAccount, sCharName, sStr: string; nCertCode: Integer; var
  HumanRcd: THumDataInfo): Boolean;
var

  dwTimeOutTick  : LongWord;
begin
  Result:=False;
  EnterCriticalSection(UserHumDataSection);
  try

   { while (g_MemShared.LoadData.LoadStatus=1) do
    begin
      if (GetTickCount - dwTimeOutTick) > 5000 then
      begin
        break;
      end;
      //if g_MemShared.LoadData.LoadStatus=0 then Break;
      Sleep(1);
    End;
   }
  //  if g_MemShared.HasLoaded<>0 then Exit;
    g_MemShared.LoadData.LoadStatus:=1;
    g_MemShared.LoadData.LoadHuman.sAccount := sAccount;
    g_MemShared.LoadData.LoadHuman.sChrName := sCharName;
    g_MemShared.LoadData.LoadHuman.sUserAddr := sStr;
    g_MemShared.LoadData.LoadHuman.nSessionID := nCertCode;
    dwTimeOutTick := GetTickCount();

    dwTimeOutTick := GetTickCount();
    while (True) do
    begin
      if (GetTickCount - dwTimeOutTick) > 5000 then
      begin
         MainOutMessage('读取人物失败超时');
        break;
      end;
      if g_MemShared.LoadData.LoadStatus>=2 then
      begin
         if g_MemShared.LoadData.LoadStatus=2 then
         Begin
           Result:=True;
           if g_MemShared.LoadData.LoadData.sChrName=sCharName then
           Begin
             Move(g_MemShared.LoadData.LoadData,HumanRcd.data,sizeof(THumData));
           end
           else
             Result:=False;
         end
         else
           MainOutMessage('读取人物失败'+Inttostr(g_MemShared.LoadData.LoadStatus)+' '+g_memshared.LoadData.LoadHuman.sChrName);
         g_MemShared.LoadData.LoadStatus:=0;
         Break;
      End;
      Sleep(1);
    End;
  finally
    LeaveCriticalSection(  UserHumDataSection);
  end;
end;
//004B3BEC

procedure SendDBSockMsg(nQueryID: Integer; sMsg: string);
var
  sSENDMSG                              : string;
  nCheckCode                            : Integer;
  sCheckStr                             : string;

  Config                                : pTConfig;



  Len                                   : Integer;
  
begin
  Config := @g_Config;

  if not DBSocketConnected then
    exit;
  EnterCriticalSection(UserDBSection);
  try
    Config.sDBSocketRecvText := '';
  finally
    LeaveCriticalSection(UserDBSection);
  end;
  nCheckCode := MakeLong(nQueryID xor 170, length(sMsg) + 6);
  sCheckStr := EncodeBuffer(@nCheckCode, SizeOf(Integer));
  sSENDMSG := '#' + IntToStr(nQueryID) + '/' + sMsg + sCheckStr + '!';
  Config.boDBSocketWorking := True;

  
  FrmMain.DBSocket.Socket.sendtext(sSENDMSG);

end;

//004E3E04

function GetQueryID(Config: pTConfig): Integer;
begin
  Inc(Config.nDBQueryID);
  if Config.nDBQueryID > High(SmallInt) - 1 then
    Config.nDBQueryID := 1;
  Result := Config.nDBQueryID;
end;
end.

⌨️ 快捷键说明

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