DELPHI版传奇引擎学习菜鸟篇(applem2)-02

每天只学习一个知识点,也是一种进步.

接着学习GShare.pas的实现部分,其实这个应该叫做GAMECENTER共享单元,我刚开始理解的是错误的,这是根据名字起的.

在学习实现部分之前,声明部分还有一些变量:

//虽然光看这些变量不可能全部知道带表什么,但是为了学习,还是注释一下
var
  //下面4个应该是更新数据(格式)用的,默认为本机更新
  g_sDataListAddrs: string = ‘127.0.0.1‘;
  g_wDataListPort: Word = 18888;
  g_sDataListPassWord: string = ‘123456‘;
  g_boGetDataListOK: Boolean = False;
  //下面3个是获取更新列表用的,
  g_DataListReadBuffer: PChar;
  g_nDataListReadLength: Integer;
  g_GetDatList: TStringList;

  //下面6个很明显,从字面就能看出意思对应启动设置\窗口\按钮状态
  g_nFormIdx: Integer;
  g_IniConf: Tinifile;
  g_sButtonStartGame: string = ‘启动游戏服务器(&S)‘;
  g_sButtonStopGame: string = ‘停止游戏服务器(&T)‘;
  g_sButtonStopStartGame: string = ‘中止启动游戏服务器(&T)‘;
  g_sButtonStopStopGame: string = ‘中止停止游戏服务器(&T)‘;
  //下面对应的都是配置变量,主窗口都有对应的控件
  g_sConfFile: string = ‘.\Config.ini‘;
  g_sBackListFile: string = ‘.\BackupList.txt‘;
  g_sGameName: string = ‘测试引擎‘;
  g_sGameDirectory: string = ‘.\‘;
  g_sHeroDBName: string = ‘HeroDB‘;
  g_sExtIPaddr: string = ‘127.0.0.1‘;
  g_sExtIPaddr2: string = ‘127.0.0.1‘;
  g_boAutoRunBak: Boolean = False;
  g_boCloseWuXin: Boolean = False;
  g_boIP2: Boolean = False;
  // 声明并初始化服务端配置结构,也许类似这样的应该定义为类,前边也好多
  g_Config: TConfig = (
      DBServer: (
        MainFormX: 0;
        MainFormY: 373;
        GatePort: 5100;
        ServerPort: 6000;
        GetStart: True;
        ProgramFile: ‘DBServer.exe‘;
      );
      LoginSrv: (
        MainFormX: 252;
        MainFormY: 0;
        GatePort: 5500;
        ServerPort: 5600;
        MonPort: 3000;
        GetStart: True;
        ProgramFile: ‘LoginSrv.exe‘;
      );
      M2Server:(
        MainFormX: 561;
        MainFormY: 0;
        GatePort: 5000;
        MsgSrvPort: 4900;
        GetStart: True;
        ProgramFile: ‘M2Server.exe‘;
        ProgramFile: ‘PlugTop.exe‘;
      );
      LogServer:(
        MainFormX: 252;
        MainFormY: 286;
        Port: 10000;
        GetStart: True;
        ProgramFile: ‘LogDataServer.exe‘;
      );

       RunGate:(
        MainFormX: 437;
        MainFormY: 373;
        GetStart: (True, False, False, False, False, False, False, False);
        GatePort: (7200, 7201, 7202, 7203, 7204, 7205, 7206, 7207);
        ProgramFile: ‘RunGate.exe‘;
      );
      SelGate:(
        MainFormX: 0;
        MainFormY: 180;
        GatePort: (7100, 7101);
        GetStart1: True;
        GetStart2: False;
        ProgramFile: ‘SelGate.exe‘;
      );
      LoginGate:(
        MainFormX: 0;
        MainFormY: 0;
        GatePort: 7000;
        GetStart: True;
        ProgramFile: ‘LoginGate.exe‘;
      );
       PlugTop:(
        MainFormX: 525;
        MainFormY:300;
        GetStart: True;
        ProgramFile: ‘PlugTop.exe‘;
      );
    );
  //声明服务程序变量,暂时就这么理解吧
  DBServer: TProgram;
  LoginServer: TProgram;
  LogServer: TProgram;
  M2Server: TProgram;
  RunGate: array[0..MAXRUNGATECOUNT - 1] of TProgram;
  SelGate: TProgram;
  SelGate1: TProgram;
  LoginGate: TProgram;
  LoginGate2: TProgram;
  PlugTop: TProgram;
  //下面是检测程序运行状态的变量,暂时理解为心跳检测吧
  g_dwStopTick: LongWord;
  g_dwStopTimeOut: LongWord = 10000;
  g_dwM2CheckCodeAddr: LongWord;
  g_dwDBCheckCodeAddr: LongWord;
  g_BackUpManager: TBackUpManager;
  m_nBackStartStatus: Integer = 0;

到此GShare.pas的声明部分结束,觉得还可以优化,接下来是实现部分,实现一共有5个函数\过程:

procedure LoadConfig();//加载配置
procedure SaveConfig();//保存配置
{运行服务}
function RunProgram(var ProgramInfo: TProgram; sHandle: string; dwWaitTime: LongWord): LongWord;
{停止服务}
function StopProgram(var ProgramInfo: TProgram; dwWaitTime: LongWord): Integer;
{发送消息}
procedure SendProgramMsg(DesForm: THandle; wIdent: Word; sSendMsg: string);

加载保存配置就是读取和写入服务端里边的INI和TXT配置文件,启动停止服务发送数据(消息)用的是API:

//读取配置信息
procedure LoadConfig();
begin
  //下面一堆都是读取INI文件,准备后续优化一下
  g_sGameDirectory := g_IniConf.ReadString(BasicSectionName, ‘GameDirectory‘, g_sGameDirectory);
  g_sHeroDBName := g_IniConf.ReadString(BasicSectionName, ‘HeroDBName‘, g_sHeroDBName);
  g_sGameName := g_IniConf.ReadString(BasicSectionName, ‘GameName‘, g_sGameName);
  g_sExtIPaddr := g_IniConf.ReadString(BasicSectionName, ‘ExtIPaddr‘, g_sExtIPaddr);
  g_sExtIPaddr2 := g_IniConf.ReadString(BasicSectionName, ‘ExtIPaddr2‘, g_sExtIPaddr2);
  g_boAutoRunBak := g_IniConf.ReadBool(BasicSectionName, ‘AutoRunBak‘, g_boAutoRunBak);
  g_boIP2 := g_IniConf.ReadBool(BasicSectionName, ‘IP2‘, g_boIP2);
  g_boCloseWuXin := g_IniConf.ReadBool(BasicSectionName, ‘CloseWuXin‘, g_boCloseWuXin);

  g_Config.DBServer.MainFormX := g_IniConf.ReadInteger(DBServerSectionName, ‘MainFormX‘, g_Config.DBServer.MainFormX);
  g_Config.DBServer.MainFormY := g_IniConf.ReadInteger(DBServerSectionName, ‘MainFormY‘, g_Config.DBServer.MainFormY);
  g_Config.DBServer.GatePort := g_IniConf.ReadInteger(DBServerSectionName, ‘GatePort‘, g_Config.DBServer.GatePort);
  g_Config.DBServer.ServerPort := g_IniConf.ReadInteger(DBServerSectionName, ‘ServerPort‘, g_Config.DBServer.ServerPort);
  g_Config.DBServer.GetStart := g_IniConf.ReadBool(DBServerSectionName, ‘GetStart‘, g_Config.DBServer.GetStart);

  g_Config.LoginSrv.MainFormX := g_IniConf.ReadInteger(LoginSrvSectionName, ‘MainFormX‘, g_Config.LoginSrv.MainFormX);
  g_Config.LoginSrv.MainFormY := g_IniConf.ReadInteger(LoginSrvSectionName, ‘MainFormY‘, g_Config.LoginSrv.MainFormY);
  g_Config.LoginSrv.GatePort := g_IniConf.ReadInteger(LoginSrvSectionName, ‘GatePort‘, g_Config.LoginSrv.GatePort);
  g_Config.LoginSrv.ServerPort := g_IniConf.ReadInteger(LoginSrvSectionName, ‘ServerPort‘, g_Config.LoginSrv.ServerPort);
  g_Config.LoginSrv.MonPort := g_IniConf.ReadInteger(LoginSrvSectionName, ‘MonPort‘, g_Config.LoginSrv.MonPort);
  g_Config.LoginSrv.GetStart := g_IniConf.ReadBool(LoginSrvSectionName, ‘GetStart‘, g_Config.LoginSrv.GetStart);

  g_Config.M2Server.MainFormX := g_IniConf.ReadInteger(M2ServerSectionName, ‘MainFormX‘, g_Config.M2Server.MainFormX);
  g_Config.M2Server.MainFormY := g_IniConf.ReadInteger(M2ServerSectionName, ‘MainFormY‘, g_Config.M2Server.MainFormY);
  g_Config.M2Server.GatePort := g_IniConf.ReadInteger(M2ServerSectionName, ‘GatePort‘, g_Config.M2Server.GatePort);
  g_Config.M2Server.MsgSrvPort := g_IniConf.ReadInteger(M2ServerSectionName, ‘MsgSrvPort‘, g_Config.M2Server.MsgSrvPort);
  g_Config.M2Server.GetStart := g_IniConf.ReadBool(M2ServerSectionName, ‘GetStart‘, g_Config.M2Server.GetStart);

  g_Config.LogServer.MainFormX := g_IniConf.ReadInteger(LogServerSectionName, ‘MainFormX‘, g_Config.LogServer.MainFormX);
  g_Config.LogServer.MainFormY := g_IniConf.ReadInteger(LogServerSectionName, ‘MainFormY‘, g_Config.LogServer.MainFormY);
  g_Config.LogServer.Port := g_IniConf.ReadInteger(LogServerSectionName, ‘Port‘, g_Config.LogServer.Port);
  g_Config.LogServer.GetStart := g_IniConf.ReadBool(LogServerSectionName, ‘GetStart‘, g_Config.LogServer.GetStart);

  g_Config.RunGate.MainFormX := g_IniConf.ReadInteger(RunGateSectionName, ‘MainFormX‘, g_Config.RunGate.MainFormX);
  g_Config.RunGate.MainFormY := g_IniConf.ReadInteger(RunGateSectionName, ‘MainFormY‘, g_Config.RunGate.MainFormY);
  g_Config.RunGate.GetStart[0] := g_IniConf.ReadBool(RunGateSectionName, ‘GetStart1‘, g_Config.RunGate.GetStart[0]);
  g_Config.RunGate.GetStart[1] := g_IniConf.ReadBool(RunGateSectionName, ‘GetStart2‘, g_Config.RunGate.GetStart[1]);
  g_Config.RunGate.GetStart[2] := g_IniConf.ReadBool(RunGateSectionName, ‘GetStart3‘, g_Config.RunGate.GetStart[2]);
  g_Config.RunGate.GetStart[3] := g_IniConf.ReadBool(RunGateSectionName, ‘GetStart4‘, g_Config.RunGate.GetStart[3]);
  g_Config.RunGate.GetStart[4] := g_IniConf.ReadBool(RunGateSectionName, ‘GetStart5‘, g_Config.RunGate.GetStart[4]);
  g_Config.RunGate.GetStart[5] := g_IniConf.ReadBool(RunGateSectionName, ‘GetStart6‘, g_Config.RunGate.GetStart[5]);
  g_Config.RunGate.GetStart[6] := g_IniConf.ReadBool(RunGateSectionName, ‘GetStart7‘, g_Config.RunGate.GetStart[6]);
  g_Config.RunGate.GetStart[7] := g_IniConf.ReadBool(RunGateSectionName, ‘GetStart8‘, g_Config.RunGate.GetStart[7]);

  g_Config.RunGate.GatePort[0] := g_IniConf.ReadInteger(RunGateSectionName, ‘GatePort1‘, g_Config.RunGate.GatePort[0]);
  g_Config.RunGate.GatePort[1] := g_IniConf.ReadInteger(RunGateSectionName, ‘GatePort2‘, g_Config.RunGate.GatePort[1]);
  g_Config.RunGate.GatePort[2] := g_IniConf.ReadInteger(RunGateSectionName, ‘GatePort3‘, g_Config.RunGate.GatePort[2]);
  g_Config.RunGate.GatePort[3] := g_IniConf.ReadInteger(RunGateSectionName, ‘GatePort4‘, g_Config.RunGate.GatePort[3]);
  g_Config.RunGate.GatePort[4] := g_IniConf.ReadInteger(RunGateSectionName, ‘GatePort5‘, g_Config.RunGate.GatePort[4]);
  g_Config.RunGate.GatePort[5] := g_IniConf.ReadInteger(RunGateSectionName, ‘GatePort6‘, g_Config.RunGate.GatePort[5]);
  g_Config.RunGate.GatePort[6] := g_IniConf.ReadInteger(RunGateSectionName, ‘GatePort7‘, g_Config.RunGate.GatePort[6]);
  g_Config.RunGate.GatePort[7] := g_IniConf.ReadInteger(RunGateSectionName, ‘GatePort8‘, g_Config.RunGate.GatePort[7]);

  g_Config.SelGate.MainFormX := g_IniConf.ReadInteger(SelGateSectionName, ‘MainFormX‘, g_Config.SelGate.MainFormX);
  g_Config.SelGate.MainFormY := g_IniConf.ReadInteger(SelGateSectionName, ‘MainFormY‘, g_Config.SelGate.MainFormY);
  g_Config.SelGate.GatePort[0] := g_IniConf.ReadInteger(SelGateSectionName, ‘GatePort1‘, g_Config.SelGate.GatePort[0]);
  g_Config.SelGate.GatePort[1] := g_IniConf.ReadInteger(SelGateSectionName, ‘GatePort2‘, g_Config.SelGate.GatePort[1]);
  g_Config.SelGate.GetStart1 := g_IniConf.ReadBool(SelGateSectionName, ‘GetStart1‘, g_Config.SelGate.GetStart1);
  g_Config.SelGate.GetStart2 := g_IniConf.ReadBool(SelGateSectionName, ‘GetStart2‘, g_Config.SelGate.GetStart2);

  g_Config.LoginGate.MainFormX := g_IniConf.ReadInteger(LoginGateSectionName, ‘MainFormX‘, g_Config.LoginGate.MainFormX);
  g_Config.LoginGate.MainFormY := g_IniConf.ReadInteger(LoginGateSectionName, ‘MainFormY‘, g_Config.LoginGate.MainFormY);
  g_Config.LoginGate.GatePort := g_IniConf.ReadInteger(LoginGateSectionName, ‘GatePort‘, g_Config.LoginGate.GatePort);
  g_Config.LoginGate.GetStart := g_IniConf.ReadBool(LoginGateSectionName, ‘GetStart‘, g_Config.LoginGate.GetStart);

  g_Config.PlugTop.MainFormX := g_IniConf.ReadInteger(PlugTopSectionName, ‘MainFormX‘, g_Config.PlugTop.MainFormX);
  g_Config.PlugTop.MainFormY := g_IniConf.ReadInteger(PlugTopSectionName, ‘MainFormY‘, g_Config.PlugTop.MainFormY);
  g_Config.PlugTop.GetStart := g_IniConf.ReadBool(PlugTopSectionName, ‘GetStart‘, g_Config.PlugTop.GetStart);
end;

procedure SaveConfig();   //保存配置信息
begin
  //没什么可注释的,写入INI
  g_IniConf.WriteString(BasicSectionName, ‘GameDirectory‘, g_sGameDirectory);
  g_IniConf.WriteString(BasicSectionName, ‘HeroDBName‘, g_sHeroDBName);
  g_IniConf.WriteString(BasicSectionName, ‘GameName‘, g_sGameName);
  g_IniConf.WriteString(BasicSectionName, ‘ExtIPaddr‘, g_sExtIPaddr);
  g_IniConf.WriteString(BasicSectionName, ‘ExtIPaddr2‘, g_sExtIPaddr2);
  g_IniConf.WriteBool(BasicSectionName, ‘AutoRunBak‘, g_boAutoRunBak);
  g_IniConf.WriteBool(BasicSectionName, ‘IP2‘, g_boIP2);
  g_IniConf.WriteBool(BasicSectionName, ‘CloseWuXin‘, g_boCloseWuXin);

  g_IniConf.WriteInteger(DBServerSectionName, ‘MainFormX‘, g_Config.DBServer.MainFormX);
  g_IniConf.WriteInteger(DBServerSectionName, ‘MainFormY‘, g_Config.DBServer.MainFormY);
  g_IniConf.WriteInteger(DBServerSectionName, ‘GatePort‘, g_Config.DBServer.GatePort);
  g_IniConf.WriteInteger(DBServerSectionName, ‘ServerPort‘, g_Config.DBServer.ServerPort);
  g_IniConf.WriteBool(DBServerSectionName, ‘GetStart‘, g_Config.DBServer.GetStart);

  g_IniConf.WriteInteger(LoginSrvSectionName, ‘MainFormX‘, g_Config.LoginSrv.MainFormX);
  g_IniConf.WriteInteger(LoginSrvSectionName, ‘MainFormY‘, g_Config.LoginSrv.MainFormY);
  g_IniConf.WriteInteger(LoginSrvSectionName, ‘GatePort‘, g_Config.LoginSrv.GatePort);
  g_IniConf.WriteInteger(LoginSrvSectionName, ‘ServerPort‘, g_Config.LoginSrv.ServerPort);
  g_IniConf.WriteInteger(LoginSrvSectionName, ‘MonPort‘, g_Config.LoginSrv.MonPort);
  g_IniConf.WriteBool(LoginSrvSectionName, ‘GetStart‘, g_Config.LoginSrv.GetStart);

  g_IniConf.WriteInteger(M2ServerSectionName, ‘MainFormX‘, g_Config.M2Server.MainFormX);
  g_IniConf.WriteInteger(M2ServerSectionName, ‘MainFormY‘, g_Config.M2Server.MainFormY);
  g_IniConf.WriteInteger(M2ServerSectionName, ‘GatePort‘, g_Config.M2Server.GatePort);
  g_IniConf.WriteInteger(M2ServerSectionName, ‘MsgSrvPort‘, g_Config.M2Server.MsgSrvPort);
  g_IniConf.WriteBool(M2ServerSectionName, ‘GetStart‘, g_Config.M2Server.GetStart);

  g_IniConf.WriteInteger(LogServerSectionName, ‘MainFormX‘, g_Config.LogServer.MainFormX);
  g_IniConf.WriteInteger(LogServerSectionName, ‘MainFormY‘, g_Config.LogServer.MainFormY);
  g_IniConf.WriteInteger(LogServerSectionName, ‘Port‘, g_Config.LogServer.Port);
  g_IniConf.WriteBool(LogServerSectionName, ‘GetStart‘, g_Config.LogServer.GetStart);

  g_IniConf.WriteInteger(RunGateSectionName, ‘MainFormX‘, g_Config.RunGate.MainFormX);
  g_IniConf.WriteInteger(RunGateSectionName, ‘MainFormY‘, g_Config.RunGate.MainFormY);
  g_IniConf.WriteBool(RunGateSectionName, ‘GetStart1‘, g_Config.RunGate.GetStart[0]);
  g_IniConf.WriteBool(RunGateSectionName, ‘GetStart2‘, g_Config.RunGate.GetStart[1]);
  g_IniConf.WriteBool(RunGateSectionName, ‘GetStart3‘, g_Config.RunGate.GetStart[2]);
  g_IniConf.WriteBool(RunGateSectionName, ‘GetStart4‘, g_Config.RunGate.GetStart[3]);
  g_IniConf.WriteBool(RunGateSectionName, ‘GetStart5‘, g_Config.RunGate.GetStart[4]);
  g_IniConf.WriteBool(RunGateSectionName, ‘GetStart6‘, g_Config.RunGate.GetStart[5]);
  g_IniConf.WriteBool(RunGateSectionName, ‘GetStart7‘, g_Config.RunGate.GetStart[6]);
  g_IniConf.WriteBool(RunGateSectionName, ‘GetStart8‘, g_Config.RunGate.GetStart[7]);

  g_IniConf.WriteInteger(RunGateSectionName, ‘GatePort1‘, g_Config.RunGate.GatePort[0]);
  g_IniConf.WriteInteger(RunGateSectionName, ‘GatePort2‘, g_Config.RunGate.GatePort[1]);
  g_IniConf.WriteInteger(RunGateSectionName, ‘GatePort3‘, g_Config.RunGate.GatePort[2]);
  g_IniConf.WriteInteger(RunGateSectionName, ‘GatePort4‘, g_Config.RunGate.GatePort[3]);
  g_IniConf.WriteInteger(RunGateSectionName, ‘GatePort5‘, g_Config.RunGate.GatePort[4]);
  g_IniConf.WriteInteger(RunGateSectionName, ‘GatePort6‘, g_Config.RunGate.GatePort[5]);
  g_IniConf.WriteInteger(RunGateSectionName, ‘GatePort7‘, g_Config.RunGate.GatePort[6]);
  g_IniConf.WriteInteger(RunGateSectionName, ‘GatePort8‘, g_Config.RunGate.GatePort[7]);

  g_IniConf.WriteInteger(SelGateSectionName, ‘MainFormX‘, g_Config.SelGate.MainFormX);
  g_IniConf.WriteInteger(SelGateSectionName, ‘MainFormY‘, g_Config.SelGate.MainFormY);
  g_IniConf.WriteInteger(SelGateSectionName, ‘GatePort1‘, g_Config.SelGate.GatePort[0]);
  g_IniConf.WriteInteger(SelGateSectionName, ‘GatePort2‘, g_Config.SelGate.GatePort[1]);
  g_IniConf.WriteBool(SelGateSectionName, ‘GetStart1‘, g_Config.SelGate.GetStart1);
  g_IniConf.WriteBool(SelGateSectionName, ‘GetStart2‘, g_Config.SelGate.GetStart2);

  g_IniConf.WriteInteger(LoginGateSectionName, ‘MainFormX‘, g_Config.LoginGate.MainFormX);
  g_IniConf.WriteInteger(LoginGateSectionName, ‘MainFormY‘, g_Config.LoginGate.MainFormY);
  g_IniConf.WriteInteger(LoginGateSectionName, ‘GatePort‘, g_Config.LoginGate.GatePort);
  g_IniConf.WriteBool(LoginGateSectionName, ‘GetStart‘, g_Config.LoginGate.GetStart);

  g_IniConf.WriteInteger(PlugTopSectionName, ‘MainFormX‘, g_Config.PlugTop.MainFormX);
  g_IniConf.WriteInteger(PlugTopSectionName, ‘MainFormY‘, g_Config.PlugTop.MainFormY);
  g_IniConf.WriteBool(PlugTopSectionName, ‘GetStart‘, g_Config.PlugTop.GetStart);
end;
{启动服务,用的大部分是API}
function RunProgram(var ProgramInfo: TProgram; sHandle: string; dwWaitTime: LongWord): LongWord;
var
  StartupInfo: TStartupInfo; //获取窗口状态
  sCommandLine: string;      //程序完整路径
  sCurDirectory: string;     //程序目录
begin
  Result := 0;
  FillChar(StartupInfo, SizeOf(TStartupInfo), #0); //这个虽然查看了API参考,还是不理解,暂时就认为它是初始化吧
  GetStartupInfo(StartupInfo);//获取进程的启动信息
  {格式化程序完整路径字符串}
  sCommandLine := format(‘%s%s %s %d %d‘, [ProgramInfo.sDirectory, ProgramInfo.sProgramFile, sHandle, ProgramInfo.nMainFormX, ProgramInfo.nMainFormY]);
  sCurDirectory := ProgramInfo.sDirectory; //取得程序运行目录
  if not CreateProcess(nil,  //如果启动服务失败返回错误代码
    PChar(sCommandLine),
    nil,
    nil,
    True,
    0,
    nil,
    PChar(sCurDirectory),
    StartupInfo,
    ProgramInfo.ProcessInfo) then
  begin
    Result := GetLastError();
  end;
  Sleep(dwWaitTime);  //等待
end;
{停止服务,这个函数很简单,不再注释}
function StopProgram(var ProgramInfo: TProgram; dwWaitTime: LongWord): Integer;
var
  dwExitCode: LongWord;
begin
  Result := 0;
  dwExitCode := 0;
  if TerminateProcess(ProgramInfo.ProcessHandle, dwExitCode) then
  begin
    Result := GetLastError();
  end;
  Sleep(dwWaitTime);
end;
{这个是向指定程序发送数据}
procedure SendProgramMsg(DesForm: THandle; wIdent: Word; sSendMsg: string);
var
  SendData: TCopyDataStruct;
  nParam: Integer;
begin
  nParam := MakeLong(0, wIdent);
  SendData.cbData := length(sSendMsg) + 1;
  GetMem(SendData.lpData, SendData.cbData);
  StrCopy(SendData.lpData, PChar(sSendMsg));
  SendMessage(DesForm, WM_COPYDATA, nParam, Cardinal(@SendData));
  FreeMem(SendData.lpData);
end;
{初始化和反初始化}
initialization
  begin
    g_IniConf := Tinifile.Create(g_sConfFile);
  end;

finalization
  begin
    g_IniConf.Free;
  end;

主要是加载和保存配置过程过程重复的事情很多,可以考虑改进.

整个GShare.pas单元学习完毕,接下来可以开始主单元文件学习了.

时间: 2024-08-26 12:16:05

DELPHI版传奇引擎学习菜鸟篇(applem2)-02的相关文章

DELPHI版传奇引擎学习菜鸟篇(applem2)

一点废话:因为非工科出身,又对编程有点兴趣,杂乱的学习了好多(C,C++,PYTHON…)等好多语言,最后发现DEKLPI上手比较快,对于不知道线代和高数等是什么的我来说也许是较好的选择了,毕竟只是兴趣而已,对于DELPHI的资料不是没有,就是觉得没有自己可以渐进入门的.因为以前玩过一个叫传奇的游戏,所以知道最早的传奇是DELPHI开发的,感觉还好,这就找了不少服务端学习(呵呵,研究说不上,因为咱没到那层次),自己动手架设修改,有时还提供给网友玩公益.然后就找传奇的DELPHI源码,不算很多,毕

DELPHI版传奇引擎学习菜鸟篇(applem2)-03

3.2 Gmain.pas单元 这是引擎控制台的主窗口,就是之前说的那个4500行代码的单元,对大神来说,这不算什么,对我看来说,光是理清里边的关系就很吃力.我知道也许从程序的架构角度去理解会好一些,但咱不懂那些,只好继续以一个菜鸟的方式按单元\按页面逐项查看,期待能获得一些营养. 接口部分也有近500行代码,虽然我是初学delphi,但也知道把所有的功能和定义都放到一个单元对以后维护带来很大不变,这份代码是谁写的我不清楚,但是至少不像比较标准的架构,除了重复的复制代码,就是一些嵌套的过程中的过

DELPHI版传奇引擎学习菜鸟篇(applem2)-05

1-4是大概把GAMECENTER过了一遍,终于把消息机制入了一点门,接下来是服务端第一个服务的学习--DBServer.是一个数据库服务器,在学习这个单元的时候,发现了这个端的大概由来,不知道是哪个大牛反编译后重写的,看来之前我理解的是错误的,代码杂乱的原因不是没有考虑到正题设计,这是由DEDEDARK反编译的端,根据自己的经验补写的实现代码,不知道我这辈子能不能达到这样的水平,那得需要对汇编多熟悉才行啊. function TFrmNewChr.sub_49BD60(var sChrName

DELPHI版传奇引擎学习菜鸟篇(applem2)-06

引擎源代码的学习暂时放下了几天,因为需要掌握一些进程处理方面的消息,之前在GAMECENTER中的启动服务过程好好琢磨了一下,将服务启动过程单独拿出来,原先是用主界面的过程判断处理启动,好长的代码,终于提炼出来了一个通用启动过程,停止服务的过程和这个是类似的. {运行外部程序的函数} function RunProgram(var ProgramInfo: TProgram; sHandle: string; dwWaitTime: LongWord): LongWord; var Startu

DELPHI版传奇引擎学习菜鸟篇(applem2)-04

接着学习,从学习的过程中,我发现了这个引擎控制台的主要功能,这也是一行一行代码敲进去的结果,之前我对这个单元的功能了解的还是少,不知不觉中就发现了它主要实现的功能,对里边的代码理解也进了一步. 从我的理解它大概有如下功能: a.实现整个服务端的启动配置. b.进行数据更新,这里指的是对数据库(人物\物品\怪物…)的更新. c.服务端初始化(清理数据和M2的变量复位) d.启动所有服务并监控其运行状态. e.备份数据. 除了d,其他的都还容易理解,基本上拖拉控件写上事件就可以完成,唯独对服务进程进

Xshell学习--菜鸟篇

1)关于Xshell 网上更多的资料里提到的SSH客户端是putty,因为简单.开源.免费.但是也正是由于功能过于简单,所以在这里推荐大家使用Xshell. Xshell最初并不能免费使用,而且也没有带中文语言,所以导致用户非常少,但是现在已经可以免费安装并且能设置中文,相信使用的人会越来越多. 简单说下个人认为Xshell的优点: 1,界面设计简洁,很人性化,用起来让人觉得很舒服. 2,支持标签,打开多个链接的时候很方便. 3,可以保存密码.(至于安全问题,见仁见智吧,个人觉得,如果能拿到保存

Docker虚拟化实战学习——基础篇(转)

Docker虚拟化实战学习--基础篇 2018年05月26日 02:17:24 北纬34度停留 阅读数:773更多 个人分类: Docker Docker虚拟化实战和企业案例演练 深入剖析虚拟化技术概念和应用场景 虚拟化,一是项技术--,是一种资源解决方案. 虚拟化技术是将物理资源转变为逻辑上可以管理的资源,以打破物理结构之间的壁垒,使计算元件运行在虚拟的基础上,而不是真实的物理资源上. 通过虚拟化技术,可以将物理资源转变为逻辑资源(虚拟机),应用程序服务运行在虚拟资源上,而不是真实的物理机上.

如何制作一款HTML5 RPG游戏引擎——第四篇,情景对话

今天我们来实现情景对话.这是一个重要的功能,没有它,游戏将变得索然无味.所以我们不得不来完成它. 但是要知道,使用对话可不是一件简单的事,因为它内部的东西很多,比如说人物头像,人物名称,对话内容... 因此我们只能通过数组+JSON来将对话信息装起来,然后根据信息作出不同的显示.接下来我便要向大家展示实现方法. 先看本系列文章目录: 如何制作一款HTML5 RPG游戏引擎--第一篇,地图类的实现 http://blog.csdn.net/yorhomwang/article/details/88

如何制作一款HTML5 RPG游戏引擎——第五篇,人物&人物特效

上一次,我们实现了对话类,今天就来做一个游戏中必不可少的--人物类. 当然,你完全是可以自己写一个人物类,但是为了方便起见,还是决定把人物类封装到这个引擎里. 为了使这个类更有意义,我还给人物类加了几个特效,在以下讲解中会提到. 以下是本系列文章的目录: 如何制作一款HTML5 RPG游戏引擎--第一篇,地图类的实现 http://blog.csdn.net/yorhomwang/article/details/8892305 如何制作一款HTML5 RPG游戏引擎--第二篇,烟雨+飞雪效果 h