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

📄 lmain.pas

📁 传奇服务端代码 LoginSrvSQL 通讯部分
💻 PAS
📖 第 1 页 / 共 5 页
字号:
        ConnInfo.boKicked   := True;

        break;
      end;
    end;
  finally
    Config.SessionList.UnLock;
  end;
end;

//00469F00
procedure SessionAdd(Config: pTConfig; sAccount, sIPaddr: string;
  nSessionID: integer; boPayCost: boolean);
var
  ConnInfo: pTConnInfo;
begin
  New(ConnInfo);
  ConnInfo.sAccount := sAccount;
  ConnInfo.sIPaddr  := sIPaddr;
  ConnInfo.nSessionID := nSessionID;
  ConnInfo.boPayCost := boPayCost;
  ConnInfo.dwKickTick := GetTickCount();
  ConnInfo.dwStartTick := GetTickCount();
  ConnInfo.boKicked := False;
  Config.SessionList.Lock;
  try
    Config.SessionList.Add(ConnInfo);
  finally
    Config.SessionList.UnLock;
  end;
end;
//0046A5AC
procedure SendGateKickMsg(Socket: TCustomWinSocket; sSockIndex: string);
var
  sSendMsg: string;
begin
  sSendMsg := '%+-' + sSockIndex + '$';
  Socket.SendText(sSendMsg);
end;

procedure SessionUpdate(Config: pTConfig; nSessionID: integer;
  sServerName: string; boPayCost: boolean);
var
  ConnInfo: pTConnInfo;
  I: integer;
begin
  Config.SessionList.Lock;
  try
    for I := 0 to Config.SessionList.Count - 1 do begin
      ConnInfo := Config.SessionList.Items[I];
      if (ConnInfo.nSessionID = nSessionID) then begin
        ConnInfo.sServerName := sServerName;
        ConnInfo.boPayCost := boPayCost;
        break;
      end;
    end;
  finally
    Config.SessionList.UnLock;
  end;
end;
//00469694
procedure GenServerNameList(Config: pTConfig);
var
  I, II: integer;
  boD:   boolean;
begin
  try
    Config.ServerNameList.Clear;
    for I := 0 to Config.nRouteCount - 1 do begin
      boD := True;
      for II := 0 to Config.ServerNameList.Count - 1 do begin
        if Config.ServerNameList.Strings[II] = Config.GateRoute[I].sServerName then
          boD := False;
      end;
      if boD then Config.ServerNameList.Add(Config.GateRoute[I].sServerName);
    end;
  except
    MainOutMessage('TFrmMain.GenServerNameList');
  end;
end;
//00469DB4
procedure SessionClearNoPayMent(Config: pTConfig);
var
  I: integer;
  ConnInfo: pTConnInfo;
begin
  Config.SessionList.Lock;
  try
    for I := Config.SessionList.Count - 1 downto 0 do begin
      ConnInfo := Config.SessionList.Items[I];
      if not ConnInfo.boKicked and not Config.boTestServer and not ConnInfo.boPayCost then
      begin
        if (GetTickCount - ConnInfo.dwStartTick) > 60 * 60 * 1000 then begin
          ConnInfo.dwStartTick := GetTickCount();
          if not IsPayMent(Config, ConnInfo.sIPaddr, ConnInfo.sAccount) then
          begin
            FrmMasSoc.SendServerMsg(SS_KICKUSER, ConnInfo.sServerName,
              ConnInfo.sAccount + '/' + IntToStr(ConnInfo.nSessionID));
            Dispose(ConnInfo);
            Config.SessionList.Delete(I);
          end;
        end;
      end;
    end;
  finally
    Config.SessionList.UnLock;
  end;
end;
//0046DD38
procedure LoadIPaddrCostList(Config: pTConfig; QuickList: TQuickList);
begin
  try
    CS_DB.Enter;
    Config.IPaddrCostList.Clear;
    Config.IPaddrCostList.AddStrings(QuickList);
  finally
    CS_DB.Leave;
  end;
end;
//0046DCD0
procedure LoadAccountCostList(Config: pTConfig; QuickList: TQuickList);
begin
  try
    CS_DB.Enter;
    Config.AccountCostList.Clear;
    Config.AccountCostList.AddStrings(QuickList);
  finally
    CS_DB.Leave;
  end;
end;



procedure TFrmMain.Panel2DblClick(Sender: TObject);
begin
  MainOutMessage(GetServerListInfo);
end;


procedure TFrmMain.GameCenterGetUserAccount(sData: string);
var
  DBRecord: TAccountDBRecord;
  nIndex:   integer;
  nCode:    integer;
  DefMsg:   TDefaultMessage;
begin
  try
    nCode := -1;
    if AccountDB.Open then begin
      nIndex := AccountDB.Index(sData);
      if (nIndex >= 0) and (AccountDB.Get(nIndex, DBRecord) >= 0) then begin
        nCode := 1;
      end;
    end;
  finally
    AccountDB.Close;
  end;

  if nCode > 0 then begin
    DefMsg := MakeDefaultMsg(0, nCode, 0, 0, 0);
  end else begin
    DefMsg := MakeDefaultMsg(SG_USERACCOUNTNOTFOUND, nCode, 0, 0, 0);
  end;
end;

procedure TFrmMain.GameCenterChangeAccountInfo(sData: string);
var
  NewRecord, DBRecord: TAccountDBRecord;
  DefMsg:  TDefaultMessage;
  sDefMsg: string;
  nCode, nIndex: integer;
begin
  if Length(sData) < DEFBLOCKSIZE then exit;
  sDefMsg := Copy(sData, 1, DEFBLOCKSIZE);
  sData   := Copy(sData, DEFBLOCKSIZE + 1, Length(sData) - DEFBLOCKSIZE);
  DefMsg  := DecodeMessage(sDefMsg);
  DecodeBuffer(sData, @NewRecord, SizeOf(NewRecord));
  nCode := -1;

  try
    if AccountDB.Open then begin
      nIndex := AccountDB.Index(NewRecord.UserEntry.sAccount);
      if (nIndex >= 0) and (AccountDB.Get(nIndex, DBRecord) >= 0) then begin
        if DBRecord.UserEntry.sAccount = NewRecord.UserEntry.sAccount then begin
          DBRecord.nErrorCount  := 0;
          DBRecord.dwActionTick := 0;
          DBRecord.UserEntry    := NewRecord.UserEntry;
          DBRecord.UserEntryAdd := NewRecord.UserEntryAdd;
          AccountDB.Update(nIndex, DBRecord);
          nCode := 1;
        end else begin
          nCode := 2;
        end;
      end;
    end;
  finally
    AccountDB.Close;
  end;

  DefMsg := MakeDefaultMsg(0, nCode, 0, 0, 0);
end;


procedure SaveContLogMsg(Config: pTConfig; sLogMsg: string);
var
  Year, Month, Day, Hour, Min, Sec, MSec: word;
  sLogDir, sLogFileName: string;
  LogFile: TextFile;
begin
  if sLogMsg = '' then exit;

  DecodeDate(Date, Year, Month, Day);
  DecodeTime(Time, Hour, Min, Sec, MSec);
  if not DirectoryExists(Config.sCountLogDir) then begin
    CreateDir(Config.sCountLogDir);
  end;
  sLogDir := Config.sCountLogDir + IntToStr(Year) + '-' + IntToStr2(Month);
  if not DirectoryExists(sLogDir) then begin
    CreateDirectory(PChar(sLogDir), nil);
  end;
  sLogFileName := sLogDir + '\' + IntToStr(Year) + '-' + IntToStr2(Month) +
    '-' + IntToStr2(Day) + '.txt';
  AssignFile(LogFile, sLogFileName);
  if not FileExists(sLogFileName) then begin
    Rewrite(LogFile);
  end else begin
    Append(LogFile);
  end;
  sLogMsg := sLogMsg + #9 + TimeToStr(Time);

  WriteLn(LogFile, sLogMsg);
  CloseFile(LogFile);
end;

procedure WriteLogMsg(Config: pTConfig; sType: string; var UserEntry: TUserEntry;
  var UserAddEntry: TUserEntryAdd);
var
  Year, Month, Day: word;
  sLogDir, sLogFileName: string;
  LogFile: TextFile;
  sLogFormat, sLogMsg: string;
begin
  DecodeDate(Date, Year, Month, Day);
  if not DirectoryExists(Config.sChrLogDir) then begin
    CreateDir(Config.sChrLogDir);
  end;
  sLogDir := Config.sChrLogDir + IntToStr(Year) + '-' + IntToStr2(Month);
  if not DirectoryExists(sLogDir) then begin
    CreateDirectory(PChar(sLogDir), nil);
  end;
  sLogFileName := sLogDir + '\Id_' + IntToStr2(Day) + '.log';
  AssignFile(LogFile, sLogFileName);
  if not FileExists(sLogFileName) then begin
    Rewrite(LogFile);
  end else begin
    Append(LogFile);
  end;
  sLogFormat := '*%s*'#9'%s'#9'"%s"'#9'%s'#9'%s'#9'%s'#9'%s'#9'%s'#9'%s'#9'%s'#9'%s'#9'%s'#9'[%s]';
  sLogMsg    := format(sLogFormat, [sType, UserEntry.sAccount,
    UserEntry.sPassword, UserEntry.sUserName, UserEntry.sSSNo,
    UserEntry.sQuiz, UserEntry.sAnswer, UserEntry.sEMail, UserAddEntry.sQuiz2,
    UserAddEntry.sAnswer2, UserAddEntry.sBirthDay, UserAddEntry.sMobilePhone,
    TimeToStr(Now)]);

  //sLogMsg:= UserAddEntry.sQuiz2 + UserAddEntry.sAnswer2 + UserAddEntry.sBirthDay + UserAddEntry.sMobilePhone + '[' + TimeToStr(Now) + ']';

  WriteLn(LogFile, sLogMsg);
  CloseFile(LogFile);
end;

procedure StartService(Config: pTConfig);
begin
  InitializeConfig(Config);
  LoadConfig(Config);
  LoadDBSetup;
end;

procedure StopService(Config: pTConfig);
begin
  UnInitializeConfig(Config);
end;

procedure InitializeConfig(Config: pTConfig);
resourcestring
  sConfigFile = '.\Logsrv.ini';
begin
  Config.IniConf := TIniFile.Create(sConfigFile);
  InitializeCriticalSection(Config.GateCriticalSection);
end;

procedure UnInitializeConfig(Config: pTConfig);
begin
  Config.IniConf.Free;
  DeleteCriticalSection(Config.GateCriticalSection);
end;

procedure LoadConfig(Config: pTConfig);

  function LoadConfigString(sSection, sIdent, sDefault: string): string;
  var
    sString: string;
  begin
    sString := Config.IniConf.ReadString(sSection, sIdent, '');
    if sString = '' then begin
      Config.IniConf.WriteString(sSection, sIdent, sDefault);
      Result := sDefault;
    end else begin
      Result := sString;
    end;
  end;

  function LoadConfigInteger(sSection, sIdent: string; nDefault: integer): integer;
  var
    nLoadInteger: integer;
  begin
    nLoadInteger := Config.IniConf.ReadInteger(sSection, sIdent, -1);
    if nLoadInteger < 0 then begin
      Config.IniConf.WriteInteger(sSection, sIdent, nDefault);
      Result := nDefault;
    end else begin
      Result := nLoadInteger;
    end;
  end;

  function LoadConfigBoolean(sSection, sIdent: string; boDefault: boolean): boolean;
  var
    nLoadInteger: integer;
  begin
    nLoadInteger := Config.IniConf.ReadInteger(sSection, sIdent, -1);
    if nLoadInteger < 0 then begin
      Config.IniConf.WriteBool(sSection, sIdent, boDefault);
      Result := boDefault;
    end else begin
      Result := nLoadInteger = 1;
    end;
  end;

begin
  Config.g_sSQLHost  := LoadConfigString('SQL', 'SQLHost', Config.g_sSQLHost);
  Config.g_sSQLDatabase  := LoadConfigString('SQL', 'SQLDatabase', Config.g_sSQLDatabase);
  Config.g_sSQLPassword  := LoadConfigString('SQL', 'SQLPassword', Config.g_sSQLPassword);
  Config.g_sSQLUserName  := LoadConfigString('SQL', 'SQLUsername', Config.g_sSQLUserName);

  Config.sDBServer  := LoadConfigString('Server', 'DBServer', Config.sDBServer);
  Config.sFeeServer := LoadConfigString('Server', 'FeeServer', Config.sFeeServer);
  Config.sLogServer := LoadConfigString('Server', 'LogServer', Config.sLogServer);

  Config.sGateAddr   := LoadConfigString('Server', 'GateAddr', Config.sGateAddr);
  Config.nGatePort   := LoadConfigInteger('Server', 'GatePort', Config.nGatePort);
  Config.sServerAddr := LoadConfigString('Server', 'ServerAddr', Config.sServerAddr);
  Config.nServerPort := LoadConfigInteger('Server', 'ServerPort', Config.nServerPort);
  Config.sMonAddr    := LoadConfigString('Server', 'MonAddr', Config.sMonAddr);
  Config.nMonPort    := LoadConfigInteger('Server', 'MonPort', Config.nMonPort);

  Config.nDBSPort      := LoadConfigInteger('Server', 'DBSPort', Config.nDBSPort);
  Config.nFeePort      := LoadConfigInteger('Server', 'FeePort', Config.nFeePort);
  Config.nLogPort      := LoadConfigInteger('Server', 'LogPort', Config.nLogPort);
  Config.nReadyServers := LoadConfigInteger('Server', 'ReadyServers', Config.nReadyServers);
  Config.boEnableMakingID := LoadConfigBoolean('Server', 'EnableMakingID', Config.boEnableMakingID);
  Config.boTestServer  := LoadConfigBoolean('Server', 'TestServer', Config.boTestServer);
  Config.boDynamicIPMode := LoadConfigBoolean('Server', 'DynamicIPMode', Config.boDynamicIPMode);
  Config.boMinimize    := LoadConfigBoolean('Server', 'Minimize', Config.boMinimize);

  Config.sCountLogDir := LoadConfigString('DB', 'CountLogDir', Config.sCountLogDir);
  Config.sFeedIDList := LoadConfigString('DB', 'FeedIDList', Config.sFeedIDList);
  Config.sFeedIPList := LoadConfigString('DB', 'FeedIPList', Config.sFeedIPList);
end;

procedure TFrmMain.R1Click(Sender: TObject);
var
  Config: pTConfig;
  I, II: Integer;
begin
  Config := @g_Config;
  Config.ServerNameList.Clear;
  for I := Low(Config.GateRoute) to High(Config.GateRoute) do begin
    Config.GateRoute[I].sServerName := '';
    Config.GateRoute[I].sTitle := '';
    Config.GateRoute[I].sRemoteAddr := '';
    Config.GateRoute[I].sPublicAddr := '';
    Config.GateRoute[I].nSelIdx := 0;
    for II := Low(Config.GateRoute[I].Gate) to High(Config.GateRoute[I].Gate) do begin
      Config.GateRoute[I].Gate[II].sIPaddr := '';
      Config.GateRoute[I].Gate[II].nPort := 0;
      Config.GateRoute[I].Gate[II].boEnable := False;
    end;
  end;
  LoadAddrTable(Config);
  MainOutMessage('加载路由列表完成...');
end;

procedure TFrmMain.C1Click(Sender: TObject);
var
  I: Integer;
begin
  for I := Low(ServerAddr) to High(ServerAddr) do begin
    ServerAddr[I] := '';
  end;
  FrmMasSoc.LoadServerAddr();
  for I := Low(UserLimit) to High(UserLimit) do begin
    UserLimit[I].sServerName := '';
    UserLimit[I].sName := '';
    UserLimit[I].nLimi

⌨️ 快捷键说明

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