AD商业广告自由选择
AD商业广告自由选择

GOM引擎传奇角色名称限制2位数参数设置

正文概述 开源人   2025-09-13 12:41:32  
lpI1234FCOM专注游戏工具及源码例子分享
DBServer 中SelectClient
// 创建新角色
procedure TSelectClient.NewChr(sData: string; UserInfo: pTUserInfo);
var
  Data, sAccount, sChrName, sHair, sJob, sSex: string; // 角色相关数据
  nCode: Integer;                                      // 返回结果代码
  sMsg: string;                                        // 临时消息(未使用)
  HumRecord: THumInfo;                                 // 角色信息结构体
  I: Integer;
  DefMsg: TDefaultMessage;                             // 默认消息结构体,用于反馈客户端
  boNew: Boolean;                                      // 是否成功创建新角色
begin
  boNew := False;
  nCode := -1; // 默认状态:未定义错误

  // 是否允许创建角色
  if g_boCanCreateHuman then begin
    // 解码数据并依次取出账号、角色名、发型、职业、性别
    Data := DecodeString(sData);
    Data := GetValidStr3(Data, sAccount, ['/']);
    Data := GetValidStr3(Data, sChrName, ['/']);
    Data := GetValidStr3(Data, sHair, ['/']);
    Data := GetValidStr3(Data, sJob, ['/']);
    Data := GetValidStr3(Data, sSex, ['/']);

    // 基础检查
    if Trim(Data) <> '' then nCode := 0;
    sChrName := Trim(sChrName);
    if Length(sChrName) < 3 then nCode := 0;                // 名字太短
    if not CheckDenyChrName(sChrName) then nCode := 2;       // 是否在黑名单
    if not CheckChrName(sChrName) then nCode := 0;           // 是否是合法名字

    // 去掉非法字符
    for I := Length(sChrName) downto 1 do
      if (not (sChrName[I] in TextChars)) then Delete(sChrName, I, 1);

    // 检查是否包含敏感字符(过滤)
    if CheckFilterNewHumanChrName(sChrName) then nCode := 2;

    // 检查特殊符号
    if (not g_boDenyChrName) and (nCode = -1) then
      for I := 1 to Length(sChrName) do begin
        if (sChrName[I] in [' ', '/', '@', '?', '''', '"', '\',
                            '.', ',', ':', ';', '`', '~', '!',
                            '#', '$', '%', '^', '&', '*', '(', ')',
                            '-', '_', '+', '=', '|', '[', '{', ']', '}']) then
        begin
          nCode := 0; // 包含非法符号
          break;
        end;
      end;

    // 检查是否禁止全数字名字
    if (nCode = -1) and g_boForbidNumberName and CheckNumberName(sChrName) then
      nCode := 6;

    // 检查是否禁止全字母名字
    if (nCode = -1) and g_boForbidLetterName and CheckLetterName(sChrName) then
      nCode := 7;

    // ================== 检查数据库中是否已有该名字 ==================
    if nCode = -1 then begin
      try
        g_HumCharDB.Lock;
        if g_HumCharDB.Index(sChrName) >= 0 then nCode := 2; // 已存在
      finally
        g_HumCharDB.UnLock;
      end;

      try
        g_HumDataDB.Lock;
        if g_HumDataDB.Index(sChrName) >= 0 then nCode := 2; // 已存在
      finally
        g_HumDataDB.UnLock;
      end;

      // ================== 正式写入数据库,创建角色 ==================
      if nCode = -1 then begin
        try
          if g_HumCharDB.Open then begin
            // 检查账号下是否超过最大建角数
            if g_HumCharDB.ChrCountOfAccount(sAccount) < g_nCreateChrNameCount then begin
              FillChar(HumRecord, SizeOf(THumInfo), #0); // 清空结构体
              HumRecord.Header.boIsHero := False;
              HumRecord.Header.sName := sChrName;
              HumRecord.Header.nSelectID := 0;
              HumRecord.Header.boDeleted := False;

              HumRecord.sChrName := sChrName;
              HumRecord.sAccount := sAccount;
              HumRecord.boDeleted := False;
              HumRecord.boIsHero := False;
              HumRecord.btCount := 0;

              // 写入角色数据库
              if HumRecord.Header.sName <> '' then
                if not g_HumCharDB.Add(@HumRecord) then
                  nCode := 2   // 数据库添加失败
                else
                  boNew := True; // 角色信息写入成功
            end else
              nCode := 3; // 超过建角数量
          end;
        finally
          g_HumCharDB.Close;
        end;

        // ================== 新建角色数据 ==================
        if (nCode = -1) and boNew then begin
          if NewChrData(sChrName, Str_ToInt(sSex, 0), Str_ToInt(sJob, 0), Str_ToInt(sHair, 0)) then
            nCode := 1 // 成功
          else begin
            // 如果建档失败,回滚数据库
            if boNew then begin
              try
                if g_HumCharDB.Open then begin
                  g_HumCharDB.Delete(sChrName);
                end;
              finally
                g_HumCharDB.Close;
              end;
            end;
          end;
        end else begin
          // 如果建档失败,删除残留
          if boNew then begin
            try
              if g_HumCharDB.Open then begin
                g_HumCharDB.Delete(sChrName);
              end;
            finally
              g_HumCharDB.Close;
            end;
          end;
          nCode := 4; // 创建失败
        end;
      end;
    end;
  end else
    nCode := 5; // 禁止创建人物

  // ================== 返回结果给客户端 ==================
  if nCode = 1 then begin
    DefMsg := MakeDefaultMsg(SM_NEWCHR_SUCCESS, 0, 0, 0, 0);
  end else begin
    DefMsg := MakeDefaultMsg(SM_NEWCHR_FAIL, nCode, 0, 0, 0);
  end;
  SendUserSocket(UserInfo.sConnID, EncodeMessage(DefMsg));
end;


声明:本文系互联网搜索而收集整理,不以盈利性为目的,文字、图文资料源于互联网且共享于互联网。
如有侵权,请联系 yao4fvip#qq.com (#改@) 删除。