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

📄 lmain.pas

📁 重庆飞尔的登陆服务器管理系统(LoginServer)源代码
💻 PAS
📖 第 1 页 / 共 5 页
字号:
unit LMain;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, WinSock,
  Controls, Forms, Dialogs, StdCtrls, ExtCtrls, JSocket, SyncObjs, Grids, Buttons, IniFiles, MudUtil, Parse,
  Menus, Grobal2, LSShare, SDK, Common, AppEvnts;
type
  TConnInfo = record //Size 0x20 Address: 0x00468601
    sAccount: string; //0x00
    sIPaddr: string; //0x04
    sServerName: string; //0x08
    nSessionID: Integer; //0x0C
    boPayCost: Boolean; //0x10
    bo11: Boolean; //0x11
    dwKickTick: LongWord; //0x14
    dwStartTick: LongWord; //0x18
    boKicked: Boolean; //0x1C
    nLockCount: Integer;
  end;
  pTConnInfo = ^TConnInfo;
  TGateInfo = record //Size 0x14 Address: 0x004686A0
    Socket: TCustomWinSocket; //0x00
    sIPaddr: string; //0x04
    sReceiveMsg: string; //0x08
    UserList: TList; //0x0C
    dwKeepAliveTick: LongWord; //0x10
  end;
  pTGateInfo = ^TGateInfo;
  TUserInfo = record //Size 0x68 Address: 0x004686C8
    sAccount: string; //0x00
    sUserIPaddr: string; //0x0B
    sGateIPaddr: string; //用户连接到网关,网关的连接IP
    sSockIndex: string; //0x20
    nVersionDate: Integer; //0x24
    boCertificationOK: Boolean; //0x28
    bo29: Boolean; //0x29
    bo2A: Boolean; //0x2A
    bo2B: Boolean; //0x2B
    nSessionID: Integer; //0x2C
    boPayCost: Boolean; //0x30
    nIDDay: Integer; //0x34
    nIDHour: Integer; //0x38
    nIPDay: Integer; //0x3C
    nIPHour: Integer; //0x40
    dtDateTime: TDateTime; //0x48
    boSelServer: Boolean; //0x50
    bo51: Boolean; //0x51
    Socket: TCustomWinSocket; //0x54
    sReceiveMsg: string; //0x58
    dwTime5C: LongWord; //0x5C
    bo60: Boolean; //0x60
    bo61: Boolean; //0x61
    bo62: Boolean; //0x62
    bo63: Boolean; //0x63
    dwClientTick: LongWord; //0x64
    nRandomCode: Integer;
    boRandomCode: Boolean; //0x5
    Gate: pTGateInfo;
  end;
  pTUserInfo = ^TUserInfo;
  TFrmMain = class(TForm)
    GSocket: TServerSocket;
    ExecTimer: TTimer;
    Panel1: TPanel;
    Memo1: TMemo;
    Timer1: TTimer;
    StartTimer: TTimer;
    WebLogTimer: TTimer;
    BtnDump: TSpeedButton;
    LogTimer: TTimer;
    MonitorGrid: TStringGrid;
    Panel2: TPanel;
    Label1: TLabel;
    SpeedButton1: TSpeedButton;
    LbMasCount: TLabel;
    CkLogin: TCheckBox;
    CbViewLog: TCheckBox;
    BtnView: TSpeedButton;
    CountLogTimer: TTimer;
    BtnShowServerUsers: TSpeedButton;
    MonitorTimer: TTimer;
    SpeedButton2: TSpeedButton;
    MainMenu: TMainMenu;
    MENU_CONTROL: TMenuItem;
    MENU_CONTROL_EXIT: TMenuItem;
    MENU_VIEW: TMenuItem;
    MENU_OPTION: TMenuItem;
    MENU_TOOLS: TMenuItem;
    MENU_HELP: TMenuItem;
    MENU_HELP_ABOUT: TMenuItem;
    MENU_OPTION_GENERAL: TMenuItem;
    MENU_OPTION_ROUTE: TMenuItem;
    MENU_VIEW_SESSION: TMenuItem;
    N1: TMenuItem;
    C1: TMenuItem;
    ApplicationEvents1: TApplicationEvents;
    CheckBoxAttack: TCheckBox;

    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure ExecTimerTimer(Sender: TObject);
    procedure Memo1DblClick(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure StartTimerTimer(Sender: TObject);
    procedure SpeedButton1Click(Sender: TObject);
    procedure BtnViewClick(Sender: TObject);
    procedure CountLogTimerTimer(Sender: TObject);
    procedure BtnShowServerUsersClick(Sender: TObject);
    procedure MonitorTimerTimer(Sender: TObject);
    procedure SpeedButton2Click(Sender: TObject);

    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    procedure GSocketClientConnect(Sender: TObject;
      Socket: TCustomWinSocket);
    procedure GSocketClientDisconnect(Sender: TObject;
      Socket: TCustomWinSocket);
    procedure GSocketClientError(Sender: TObject; Socket: TCustomWinSocket;
      ErrorEvent: TErrorEvent; var ErrorCode: Integer);
    procedure GSocketClientRead(Sender: TObject; Socket: TCustomWinSocket);
    procedure Panel2DblClick(Sender: TObject);
    procedure CbViewLogClick(Sender: TObject);
    procedure MENU_CONTROL_EXITClick(Sender: TObject);
    procedure MENU_OPTION_ROUTEClick(Sender: TObject);
    procedure MENU_VIEW_SESSIONClick(Sender: TObject);
    procedure MENU_HELP_ABOUTClick(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure MENU_OPTION_GENERALClick(Sender: TObject);
    procedure C1Click(Sender: TObject);
    procedure ApplicationEvents1Exception(Sender: TObject; e: Exception);
  private
    SList_0344: TStringList; //0x344
    ParseList: TThreadParseList; //0x350
    procedure GameCenterGetUserAccount(sData: string);
    procedure GameCenterChangeAccountInfo(sData: string);
    procedure OpenRouteConfig();
    { Private declarations }
  public
    procedure MyMessage(var MsgData: TWmCopyData); message WM_COPYDATA;
    { Public declarations }
  end;
procedure StartService(Config: pTConfig);
procedure StopService(Config: pTConfig);
procedure InitializeConfig(Config: pTConfig);
procedure UnInitializeConfig(Config: pTConfig);
procedure LoadConfig(Config: pTConfig);
procedure LoadAddrTable(Config: pTConfig);
procedure GenServerNameList(Config: pTConfig);

procedure WriteLogMsg(Config: pTConfig; sType: string; var UserEntry: TUserEntry; var UserAddEntry: TUserEntryAdd);
procedure SaveContLogMsg(Config: pTConfig; sLogMsg: string);

procedure SendGateMsg(Socket: TCustomWinSocket; sSockIndex, sMsg: string);
procedure SendGateKickMsg(Socket: TCustomWinSocket; sSockIndex: string);
procedure SendKeepAlivePacket(Socket: TCustomWinSocket);
procedure SendGateAddBlockList(Socket: TCustomWinSocket; sSockIndex: string);
procedure SendGateAddTempBlockList(Socket: TCustomWinSocket; sSockIndex: string);

procedure SessionAdd(Config: pTConfig; sAccount, sIPaddr: string; nSessionID: Integer; boPayCost, bo11: Boolean);
procedure SessionDel(Config: pTConfig; nSessionID: Integer);
procedure SessionKick(Config: pTConfig; sLoginID: string);
procedure SessionUpdate(Config: pTConfig; nSessionID: Integer; sServerName: string; boPayCost: Boolean);
procedure SessionClearKick(Config: pTConfig);
function IsPayMent(Config: pTConfig; sIPaddr, sAccount: string): Boolean;
procedure SessionClearNoPayMent(Config: pTConfig);
function IsLogin(Config: pTConfig; sLoginID: string): Boolean; overload;
function IsLogin(Config: pTConfig; nSessionID: Integer): Boolean; overload;

function GetServerListInfo(): string;
procedure GetSelGateInfo(Config: pTConfig; sServerName, sIPaddr: string; var sSelGateIP: string; var nSelGatePort: Integer);

function KickUser(Config: pTConfig; UserInfo: pTUserInfo; nKickType: Integer): Boolean;
procedure CloseUser(Config: pTConfig; sAccount: string; nSessionID: Integer);

procedure AccountCreate(Config: pTConfig; Msg: pTDefaultMessage; UserInfo: pTUserInfo; sData: string);
procedure AccountChangePassword(Config: pTConfig; UserInfo: pTUserInfo; sData: string);
procedure AccountCheckProtocol(UserInfo: pTUserInfo; nDate: Integer);
procedure AccountLogin(Config: pTConfig; UserInfo: pTUserInfo; sData: string);
procedure AccountSelectServer(Config: pTConfig; UserInfo: pTUserInfo; sData: string);
procedure AccountUpdateUserInfo(Config: pTConfig; UserInfo: pTUserInfo; sData: string);
procedure AccountGetBackPassword(UserInfo: pTUserInfo; sData: string);

procedure ReceiveSendUser(Config: pTConfig; sSockIndex: string; GateInfo: pTGateInfo; sData: string);
procedure ReceiveOpenUser(Config: pTConfig; sSockIndex: string; sIPaddr: string; GateInfo: pTGateInfo);
procedure ReceiveCloseUser(Config: pTConfig; sSockIndex: string; GateInfo: pTGateInfo);

procedure ProcessUserMsg(Config: pTConfig; UserInfo: pTUserInfo; sMsg: string);

procedure DecodeGateData(Config: pTConfig; GateInfo: pTGateInfo);
procedure DecodeUserData(Config: pTConfig; UserInfo: pTUserInfo);
procedure ProcessGate(Config: pTConfig);

procedure LoadAccountCostList(Config: pTConfig; QuickList: TQuickList);
procedure LoadIPaddrCostList(Config: pTConfig; QuickList: TQuickList);
var
  FrmMain: TFrmMain;

implementation

uses IDDB, MasSock, FrmFindId, HUtil32, EDcode, EDcodeUnit, GateSet,
  FAccountView, GrobalSession, BasicSet;

{$R *.DFM}
procedure TFrmMain.OpenRouteConfig;
begin
  FrmGateSetting := TFrmGateSetting.Create(nil);
  FrmGateSetting.Open;
  FrmGateSetting.Free;
end;
{
procedure TFrmMain.OpenRouteConfig;
var
  Config  :pTConfig;
begin
  Config:=@g_Config;
  if FrmGateSetting.Open then begin
    LoadAddrTable(Config);
  end;
end;
}
procedure TFrmMain.MENU_OPTION_ROUTEClick(Sender: TObject);
begin
  OpenRouteConfig();
end;

procedure TFrmMain.MENU_VIEW_SESSIONClick(Sender: TObject);
begin
  frmGrobalSession := TfrmGrobalSession.Create(nil);
  frmGrobalSession.Open;
  frmGrobalSession.Free;
end;

procedure TFrmMain.CbViewLogClick(Sender: TObject);
var
  Config: pTConfig;
begin
  Config := @g_Config;
  Config.boShowDetailMsg := CbViewLog.Checked;
end;

procedure TFrmMain.GSocketClientConnect(Sender: TObject;
  Socket: TCustomWinSocket);
var
  GateInfo: pTGateInfo;
  Config: pTConfig;
begin
  Config := @g_Config;
  if not ExecTimer.Enabled then begin
    Socket.Close;
    Exit;
  end;
  New(GateInfo);
  GateInfo.Socket := Socket;
  GateInfo.sIPaddr := GetGatePublicAddr(Config, Socket.RemoteAddress);
  GateInfo.sReceiveMsg := '';
  GateInfo.UserList := TList.Create;
  GateInfo.dwKeepAliveTick := GetTickCount();
  EnterCriticalSection(Config.GateCriticalSection);
  try
    Config.GateList.Add(GateInfo);
  finally
    LeaveCriticalSection(Config.GateCriticalSection);
  end;
end;

procedure TFrmMain.GSocketClientDisconnect(Sender: TObject;
  Socket: TCustomWinSocket);
var
  I: Integer;
  II: Integer;
  GateInfo: pTGateInfo;
  UserInfo: pTUserInfo;
  Config: pTConfig;
begin
  Config := @g_Config;
  EnterCriticalSection(Config.GateCriticalSection);
  try
    for I := 0 to Config.GateList.Count - 1 do begin
      GateInfo := Config.GateList.Items[I];
      if GateInfo.Socket = Socket then begin
        for II := 0 to GateInfo.UserList.Count - 1 do begin
          UserInfo := GateInfo.UserList.Items[II];
          if Config.boShowDetailMsg then
            MainOutMessage('Close: ' + UserInfo.sUserIPaddr);
          Dispose(UserInfo);
        end;
        GateInfo.UserList.Free;
        Dispose(GateInfo);
        Config.GateList.Delete(I);
        Break;
      end;
    end;
  finally
    LeaveCriticalSection(Config.GateCriticalSection);
  end;
end;

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

procedure TFrmMain.GSocketClientRead(Sender: TObject;
  Socket: TCustomWinSocket);
var
  I: Integer;
  GateInfo: pTGateInfo;
  Config: pTConfig;
begin
  Config := @g_Config;
  EnterCriticalSection(Config.GateCriticalSection);
  try
    for I := 0 to Config.GateList.Count - 1 do begin
      GateInfo := Config.GateList.Items[I];
      if GateInfo.Socket = Socket then begin
        GateInfo.sReceiveMsg := GateInfo.sReceiveMsg + Socket.ReceiveText;
        Break;
      end;
    end;
  finally
    LeaveCriticalSection(Config.GateCriticalSection);
  end;
end;

procedure LoadAddrTable(Config: pTConfig);
var
  LoadList: TStringList;
  sFileName: string;
  I: Integer;
  nRouteIdx: Integer;
  nSelGateIdx: Integer;
  sLineText, sTitle, sServerName, sGate, sRemote, sPublic, sGatePort: string;
  II: Integer;
begin
  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;

  sFileName := '.\!addrtable.txt';
  LoadList := TStringList.Create;
  if FileExists(sFileName) then begin
    LoadList.LoadFromFile(sFileName);
    nRouteIdx := 0;
    for I := 0 to LoadList.Count - 1 do begin
      sLineText := LoadList.Strings[I];
      if (sLineText <> '') and (sLineText[1] <> ';') then begin
        sLineText := GetValidStr3(sLineText, sServerName, [' ']);
        sLineText := GetValidStr3(sLineText, sTitle, [' ']);
        sLineText := GetValidStr3(sLineText, sRemote, [' ']);
        sLineText := GetValidStr3(sLineText, sPublic, [' ']);
        sLineText := Trim(sLineText);
        if (sTitle <> '') and (sRemote <> '') and (sPublic <> '') and (nRouteIdx < MAXGATEROUTE) then begin
          Config.GateRoute[nRouteIdx].sServerName := sServerName;
          Config.GateRoute[nRouteIdx].sTitle := sTitle;
          Config.GateRoute[nRouteIdx].sRemoteAddr := sRemote;
          Config.GateRoute[nRouteIdx].sPublicAddr := sPublic;
          nSelGateIdx := 0;
          while (sLineText <> '') do begin
            if nSelGateIdx > 9 then Break;
            sLineText := GetValidStr3(sLineText, sGate, [' ']);
            if sGate <> '' then begin
              if sGate[1] = '*' then begin
                sGate := Copy(sGate, 2, Length(sGate) - 1);
                Config.GateRoute[nRouteIdx].Gate[nSelGateIdx].boEnable := False;
              end else begin
                Config.GateRoute[nRouteIdx].Gate[nSelGateIdx].boEnable := True;
              end;
              sGatePort := GetValidStr3(sGate, sGate, [':']);
              Config.GateRoute[nRouteIdx].Gate[nSelGateIdx].sIPaddr := sGate;
              Config.GateRoute[nRouteIdx].Gate[nSelGateIdx].nPort := Str_ToInt(sGatePort, 0);
              Config.GateRoute[nRouteIdx].nSelIdx := 0;
              Inc(nSelGateIdx);
            end;
            sLineText := Trim(sLineText);
          end;
          Inc(nRouteIdx);
        end;
      end;
    end;
    Config.nRouteCount := nRouteIdx;
  end;
  LoadList.Free;

⌨️ 快捷键说明

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