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

📄 lmain.pas

📁 乐都SQL版传奇全套代码,绝对可编译
💻 PAS
📖 第 1 页 / 共 5 页
字号:

procedure TFrmMain.FormCreate(Sender: TObject);
var
  nX, nY                                : Integer;
  Config                                : pTConfig;
begin
  Config := @g_Config;
  g_dwGameCenterHandle := Str_ToInt(ParamStr(1), 0);
  SendGameCenterMsg(SG_FORMHANDLE,IntToStr(Self.Handle));
  nX := Str_ToInt(ParamStr(2), -1);
  nY := Str_ToInt(ParamStr(3), -1);
  if (nX >= 0) or (nY >= 0) then
  begin
    Left := nX;
    Top := nY;
  end;
  Config.boRemoteClose := False;

  
  //  g_MainMsgList:=TStringList.Create;
  CS_DB := TCriticalSection.Create;

  StringList_0 := TStringList.Create;

  nSessionIdx := 1;
  n47328C := 1;
  nMemoHeigh := Memo1.Height;
  Config.GateList := TList.Create;
  Config.SessionList := TGList.Create;
  Config.ServerNameList := TStringList.Create;
  SList_0344 := TStringList.Create;
  Config.AccountCostList := TQuickList.Create;
  Config.IPaddrCostList := TQuickList.Create;
  ParseList := TThreadParseList.Create(true);
  LoadAddrTable(Config);
  MonitorGrid.Cells[0, 0] := '服务器名';
  MonitorGrid.Cells[1, 0] := '用户数';
  MonitorGrid.Cells[2, 0] := '状态';
  MonitorGrid.Cells[3, 0] := '服务器名';
  MonitorGrid.Cells[4, 0] := '用户数';
  MonitorGrid.Cells[5, 0] := '状态';
  DataModule_ID:=TDataModule_ID.Create(nil);
end;

//00469598

procedure TFrmMain.FormDestroy(Sender: TObject);
var
  I, II                                 : Integer;
  GateInfo                              : pTGateInfo;
  UserInfo                              : pTUserInfo;
  Config                                : pTConfig;
begin
  Config := @g_Config;
  StopService(Config);
  for I := 0 to Config.GateList.Count - 1 do
  begin
    GateInfo := Config.GateList.Items[I];
    for II := 0 to GateInfo.UserList.Count - 1 do
    begin
      UserInfo := GateInfo.UserList.Items[I];
      Dispose(UserInfo);
    end;
    GateInfo.UserList.Free;
    Dispose(GateInfo);
  end;
  Config.GateList.Free;
  Config.SessionList.Free;
  Config.ServerNameList.Free;
  SList_0344.Free;
  StringList_0.Free;
  CS_DB.Free;
end;
//0046A7F4

procedure TFrmMain.ExecTimerTimer(Sender: TObject);
var
  Config                                : pTConfig;
begin
  Config := @g_Config;
  if bo470D20 and not g_boDataDBReady then
    exit;
  bo470D20 := true;
  try
    ProcessGate(Config);
  finally
    bo470D20 := False;
  end;
end;
//0046D178

procedure TFrmMain.Memo1DblClick(Sender: TObject);
begin
  OpenRouteConfig();

end;

//0046A9BC

procedure TFrmMain.Timer1Timer(Sender: TObject);
var
  I                                     : Integer;
var
  Config                                : pTConfig;
begin
  Config := @g_Config;
  Label1.Caption := IntToStr(Config.dwProcessGateTime);
  CkLogin.Checked := GSocket.Socket.Connected;
  CkLogin.Caption := '连接 (' + IntToStr(GSocket.Socket.ActiveConnections) +
    ')';
  LbMasCount.Caption := IntToStr(nOnlineCountMin) + '/' +
    IntToStr(nOnlineCountMax);
  if Memo1.Lines.Count > 2000 then
    Memo1.Clear;
  EnterCriticalSection(g_OutMessageCS);
  try
    for I := 0 to g_MainMsgList.Count - 1 do
    begin
      Memo1.Lines.Add(g_MainMsgList.Strings[I]);
    end;
    g_MainMsgList.Clear;
  finally
    LeaveCriticalSection(g_OutMessageCS);
  end;
  I := 0;
  while (true) do
  begin
    if StringList_0.Count <= I then
      break;
    if GetTickCount - LongWord(StringList_0.Objects[I]) > 60000 then
    begin
      StringList_0.Delete(I);
      Continue;
    end;
    Inc(I);
  end;
  SessionClearKick(Config);
  SessionClearNoPayMent(Config);
end;

//0046A674

procedure TFrmMain.StartTimerTimer(Sender: TObject);
var
  Config                                : pTConfig;
  i                                     : Integer;
begin
  Config := @g_Config;
  StartService(Config);
  StartTimer.Enabled := False;

    
    if Config.DataBaseConfig.DATABase<>'' then
    Begin

      DataModule_ID.ADOConnectionID.ConnectionString:=Format(ConnectStr,[Config.DataBaseConfig.DAtaPassWord,Config.DataBaseConfig.DataAccount,Config.DataBaseConfig.DATABase,Config.DataBaseConfig.DataServer]);
      Try
         DataModule_ID.ADOConnectionID.Connected:=True;
         Memo1.Lines.Add( '0) 和SQL数据库连接成功...' );
      except
         Memo1.Lines.Add( '0) 和SQL数据库连接失败...' );
         Exit;
      End;
    end;

  Memo1.Lines.Add('1) 正在启动服务器...');
  SendGameCenterMsg(SG_STARTNOW,'正在启动登录服务器...');
  Application.ProcessMessages;
  ParseList.Resume;
  Memo1.Lines.Add('2) 正在等待服务器连接...');
  while (true) do
  begin
    Application.ProcessMessages;
    if Application.Terminated then
      exit;
    if FrmMasSoc.CheckReadyServers then
      break;
    Sleep(1);
  end;
  GSocket.Active := False;
  GSocket.Address := Config.sGateAddr;
  GSocket.Port := Config.nGatePort;
  GSocket.Active := true;
  ClientSocket1.Active:=FAlse;
  ClientSocket1.Port:=Config.nRemotePort;
  //ClientSocket1.Host:=Config.sRemoteAddr;
  ClientSocket1.Active:=True;
  Memo1.Lines.Add('3) 服务器启动完成...');
  SendGameCenterMsg(SG_STARTOK,'登录服务器启动完成...');
  ExecTimer.Enabled := true;
end;

procedure TFrmMain.MENU_CONTROL_EXITClick(Sender: TObject);
begin
  Close;
end;

procedure TFrmMain.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
//0x0046DDB0
var
  Config                                : pTConfig;
resourcestring
  sExitMsg                              = '是否确认停止登录服务器 ?';
  sExitTitle                            = '确认信息';
begin
  Config := @g_Config;
  if Config.boRemoteClose then
    exit;
  if MessageBox(Handle, PChar(sExitMsg), PChar(sExitTitle), MB_YESNO +
    MB_ICONQUESTION) = mrYes then
    CanClose := true
  else
    CanClose := False;
end;


//0046DB40

procedure TFrmMain.CountLogTimerTimer(Sender: TObject);
var
  sLogMsg                               : string;
  Config                                : pTConfig;
resourcestring
  sFormatMsg                            = '%d/%d';
begin
  Config := @g_Config;
  sLogMsg := format(sFormatMsg, [nOnlineCountMin, nOnlineCountMax]);
  SaveContLogMsg(Config, sLogMsg);
  nOnlineCountMax := 0;
end;

procedure TFrmMain.BtnShowServerUsersClick(Sender: TObject);
var
  I                                     : Integer;
begin
  for I := 0 to nUserLimit - 1 do
  begin
    MainOutMessage(UserLimit[I].sServerName + ' ' +
      IntToStr(UserLimit[I].nLimitCountMin) + '/' +
      IntToStr(UserLimit[I].nLimitCountMax));
  end;
end;
//0046ECB4

procedure TFrmMain.MonitorTimerTimer(Sender: TObject);
var
  I                                     : Integer;
  nCol                                  : Integer;
  sServerName                           : string;
  ServerList                            : TList;
  MsgServer                             : pTMsgServerInfo;
begin
  try
    ServerList := FrmMasSoc.m_ServerList;
    if (ServerList.Count div 2) < 2 then
    begin
      MonitorGrid.RowCount := 2;
      MonitorGrid.Cells[0, 1] := '';
      MonitorGrid.Cells[1, 1] := '';
      MonitorGrid.Cells[2, 1] := '';
      MonitorGrid.Cells[3, 1] := '';
      MonitorGrid.Cells[4, 1] := '';
      MonitorGrid.Cells[5, 1] := '';
    end
    else
    begin
      MonitorGrid.RowCount := ((ServerList.Count div 2) + 1) + (ServerList.Count
        mod 2);
    end;                                                    //0046ED54
    for I := 0 to ServerList.Count - 1 do
    begin
      nCol := (I mod 2) * 3;
      MsgServer := ServerList.Items[I];
      sServerName := MsgServer.sServerName;
      if sServerName <> '' then
      begin
        if MsgServer.nServerIndex = 99 then
          MonitorGrid.Cells[nCol, (I div 2 + 1)] := sServerName + ' [DB]'
        else
          MonitorGrid.Cells[nCol, (I div 2 + 1)] := sServerName + ' ' +
            IntToStr(MsgServer.nServerIndex);
        MonitorGrid.Cells[nCol + 1, (I div 2 + 1)] :=
          IntToStr(MsgServer.nOnlineCount);
        if (GetTickCount - MsgServer.dwKeepAliveTick) < 30000 then
          MonitorGrid.Cells[nCol + 2, (I div 2 + 1)] := '正常'
        else
          MonitorGrid.Cells[nCol + 2, (I div 2 + 1)] := '超时';
      end
      else
      begin                                                 //0046EEF2
        MonitorGrid.Cells[nCol, (I div 2 + 1)] := '-';
        MonitorGrid.Cells[nCol + 1, (I div 2 + 1)] := '-';
        MonitorGrid.Cells[nCol + 2, (I div 2 + 1)] := '-';
      end;
    end;
  except
    MainOutMessage('TFrmMain.MonitorTimerTimer');
  end;
end;
//0046F060

procedure TFrmMain.SpeedButton2Click(Sender: TObject);
begin
  if Memo1.Height = nMemoHeigh then
    Memo1.Height := nMemoHeigh * 2
  else
    Memo1.Height := nMemoHeigh;
end;

//0046A178

function IsPayMent(Config: pTConfig; sIPaddr, sAccount: string): Boolean;
begin
  Result := False;
  try
    CS_DB.Enter;
    if (Config.AccountCostList.GetIndex(sAccount) >= 0) or
      (Config.IPaddrCostList.GetIndex(sIPaddr) >= 0) then
      Result := true;
  finally
    CS_DB.Leave;
  end;
end;
//0046A23C

procedure CloseUser(Config: pTConfig; sAccount: string; nSessionID: Integer);
var
  ConnInfo                              : pTConnInfo;
  I                                     : Integer;
begin
  Config.SessionList.Lock;
  try
    for I := Config.SessionList.Count - 1 downto 0 do
    begin
      ConnInfo := Config.SessionList.Items[I];
      if (ConnInfo.sAccount = sAccount) or (ConnInfo.nSessionID = nSessionID)
        then
      begin
        FrmMasSoc.SendServerMsg(SS_CLOSESESSION, ConnInfo.sServerName,
          ConnInfo.sAccount + '/' + IntToStr(ConnInfo.nSessionID));
        Dispose(ConnInfo);
        Config.SessionList.Delete(I);
      end;
    end;
  finally
    Config.SessionList.UnLock;
  end;
end;

procedure ProcessGate(Config: pTConfig);
var
  I                                     : Integer;
  II                                    : Integer;
  GateInfo                              : pTGateInfo;
  UserInfo                              : pTUserInfo;
begin
  EnterCriticalSection(Config.GateCriticalSection);
  try
    Config.dwProcessGateTick := GetTickCount();
    I := 0;
    while (true) do
    begin
      if Config.GateList.Count <= I then
        break;
      GateInfo := Config.GateList.Items[I];
      if GateInfo.sReceiveMsg <> '' then
      begin
        DecodeGateData(Config, GateInfo);
        Config.sGateIPaddr := GateInfo.sIPaddr;
        II := 0;
        while (true) do
        begin
          if GateInfo.UserList.Count <= II then
            break;
          UserInfo := GateInfo.UserList.Items[II];
          if UserInfo.sReceiveMsg <> '' then
            DecodeUserData(Config, UserInfo);
          Inc(II);
        end;
      end;
      Inc(I);
    end;
    if Config.dwProcessGateTime < Config.dwProcessGateTick then
      Config.dwProcessGateTime := GetTickCount - Config.dwProcessGateTick;
    if Config.dwProcessGateTime > 100 then
      Dec(Config.dwProcessGateTime, 100);
  finally
    LeaveCriticalSection(Config.GateCriticalSection);
  end;
end;

//0046AC08

procedure DecodeGateData(Config: pTConfig; GateInfo: pTGateInfo);
var
  nCount                                : Integer;
  sMsg                                  : string;
  sSockIndex                            : string;
  sData                                 : string;
  Code                                  : Char;
begin
  try
    nCount := 0;
    while (true) do
    begin

⌨️ 快捷键说明

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