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

📄 lmain.pas

📁 乐都SQL版传奇全套代码,绝对可编译
💻 PAS
📖 第 1 页 / 共 5 页
字号:
              DBRecord.UserEntryAdd := UserAddEntry;
              if UserEntry.sAccount <> '' then
                if DataModule_ID .Add(DBRecord) then
                  nErrCode := 1
                else
                  nErrCode := 0;

        finally
        end;
        end;
      end
      else
      begin
        MainOutMessage(format(sAddNewuserFail, [UserEntry.sAccount,
          UserAddEntry.sQuiz2]));
      end;                                                  //0046C480
    end;
    if nErrCode = 1 then
    begin
      WriteLogMsg(Config, sLogFlag, UserEntry, UserAddEntry);
      DefMsg := MakeDefaultMsg(SM_NEWID_SUCCESS, 0, 0, 0, 0);
      Inc(UserInfo.CreateCount);
    end
    else
    begin
      DefMsg := MakeDefaultMsg(SM_NEWID_FAIL, nErrCode, 0, 0, 0);
    end;
    SendGateMsg(UserInfo.Socket, UserInfo.sSockIndex, EncodeMessage(DefMsg));
  except
    MainOutMessage('TFrmMain.AddNewUser');
  end;
end;
//0046C814

procedure AccountChangePassword(Config: pTConfig; UserInfo: pTUserInfo; sData:
  string);
var
  sMsg                                  : string;
  sLoginID                              : string;
  sOldPassword                          : string;
  sNewPassword                          : string;
  DefMsg                                : TDefaultMessage;
  nCode                                 : Integer;
  n10                                   : Integer;
  DBRecord                              : TAccountDBRecord;
resourcestring
  sChgMsg                               = 'chg';
begin
  try
    sMsg := DecodeString(sData);
    sMsg := GetValidStr3(sMsg, sLoginID, [#9]);
    sNewPassword := GetValidStr3(sMsg, sOldPassword, [#9]);
    nCode := 0;
    try
      if  (length(sNewPassword) >= 3) then
      begin

        if DataModule_ID.Get (sLoginID, DBRecord)  then
        begin
          if (DBRecord.nErrorCount < 5) or ((GetTickCount -
            DBRecord.dwActionTick) > 180000) then
          begin
            if DBRecord.UserEntry.sPassword = sOldPassword then
            begin
              DBRecord.nErrorCount := 0;
              DBRecord.UserEntry.sPassword := sNewPassword;
              nCode := 1;
            end
            else
            begin
              Inc(DBRecord.nErrorCount);
              DBRecord.dwActionTick := GetTickCount();
              nCode := -1;
            end;
            DataModule_ID.Update(DBRecord);
          end
          else
          begin
            nCode := -2;
            if GetTickCount < DBRecord.dwActionTick then
            begin
              DBRecord.dwActionTick := GetTickCount();
              DataModule_ID.Update(DBRecord);
            end;
          end;
        end;
      end;
    finally
    end;
    if nCode = 1 then
    begin
      DefMsg := MakeDefaultMsg(SM_CHGPASSWD_SUCCESS, 0, 0, 0, 0);
      WriteLogMsg(Config, sChgMsg, DBRecord.UserEntry, DBRecord.UserEntryAdd);
    end
    else
    begin
      DefMsg := MakeDefaultMsg(SM_CHGPASSWD_FAIL, nCode, 0, 0, 0);
    end;
    SendGateMsg(UserInfo.Socket, UserInfo.sSockIndex, EncodeMessage(DefMsg));
  except
    MainOutMessage('TFrmMain.ChangePassword');
  end;
end;

procedure AccountCheckProtocol(UserInfo: pTUserInfo; nDate: Integer);
var
  DefMsg                                : TDefaultMessage;
begin
  if nDate < nVersionDate then
  begin
    DefMsg := MakeDefaultMsg(SM_CERTIFICATION_FAIL, 0, 0, 0, 0);
  end
  else
  begin
    DefMsg := MakeDefaultMsg(SM_CERTIFICATION_SUCCESS, 0, 0, 0, 0);
    UserInfo.nVersionDate := nDate;
    UserInfo.boCertificationOK := true;
  end;
  SendGateMsg(UserInfo.Socket, UserInfo.sSockIndex, EncodeMessage(DefMsg));
end;
//0046A368

function KickUser(Config: pTConfig; UserInfo: pTUserInfo): Boolean;
var
  I                                     : Integer;
  II                                    : Integer;
  GateInfo                              : pTGateInfo;
  User                                  : pTUserInfo;
resourcestring
  sKickMsg                              = 'Kick: %s';
begin
  Result := False;
  EnterCriticalSection(Config.GateCriticalSection);
  try
    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
        User := GateInfo.UserList.Items[II];
        if User = UserInfo then
        begin
          if Config.boShowDetailMsg then
            MainOutMessage(format(sKickMsg, [UserInfo.sUserIPaddr]));
          SendGateKickMsg(GateInfo.Socket, UserInfo.sSockIndex);
          Dispose(UserInfo);
          GateInfo.UserList.Delete(II);
          Result := true;
          exit;
        end;
      end;
    end;
  finally
    LeaveCriticalSection(Config.GateCriticalSection);
  end;
end;
//0046B400

procedure AccountLogin(Config: pTConfig; UserInfo: pTUserInfo; sData: string);
var
  sLoginID                              : string;
  sPassword                             : string;
  nCode                                 : Integer;
  boNeedUpdate                          : Boolean;
  DefMsg                                : TDefaultMessage;
  UserEntry                             : TUserEntry;
  nIDCost                               : Integer;
  nIPCost                               : Integer;
  nIDCostIndex                          : Integer;
  nIPCostIndex                          : Integer;
  DBRecord                              : TAccountDBRecord;
  n10                                   : Integer;
  boPayCost                             : Boolean;
  sServerName                           : string;
begin
  try
    sPassword := GetValidStr3(DecodeString(sData), sLoginID, ['/']);
    nCode := 0;
    boNeedUpdate := False;

    try
      begin

        if DataModule_ID.Get(sLoginId,DBRecord) then
        begin
          if (DBRecord.nErrorCount < 5) or ((GetTickCount -
            DBRecord.dwActionTick) > 60000) then
          begin
            if DBRecord.UserEntry.sPassword = sPassword then
            begin
              DBRecord.nErrorCount := 0;
             { if (DBRecord.UserEntry.sUserName = '') or
                (DBRecord.UserEntryAdd.sQuiz2 = '') then
              begin
                UserEntry := DBRecord.UserEntry;
                boNeedUpdate := true;
              end;
              }DBRecord.Header.CreateDate := UserInfo.dtDateTime;
              nCode := 1;
            end
            else
            begin
              Inc(DBRecord.nErrorCount);
              DBRecord.dwActionTick := GetTickCount();
              nCode := -1;
            end;
            DataModule_ID.Update(DBRecord);
          end
          else
          begin
            nCode := -2;
            DBRecord.dwActionTick := GetTickCount();
            DataModule_ID.Update( DBRecord);
          //  AccountDB.Update(n10, DBRecord);
          end;
        end;
      end;
    except
      MainOutMessage('TFrmMain.查询人物失败::'+sloginid);
    end;
    
    if (nCode = 1) and IsLogin(Config, sLoginID,UserInfo.sGateIPaddr) then
    begin
      SessionKick(Config, sLoginID);
      nCode := -3;
    end;
    if boNeedUpdate then
    begin
      DefMsg := MakeDefaultMsg(SM_NEEDUPDATE_ACCOUNT, 0, 0, 0, 0);
      SendGateMsg(UserInfo.Socket,
        UserInfo.sSockIndex,
        EncodeMessage(DefMsg) + EncodeBuffer(@UserEntry, SizeOf(TUserEntry)));
    end;
    if nCode = 1 then
    begin
      UserInfo.sAccount := sLoginID;
      UserInfo.nSessionID := GetSessionID();
      UserInfo.boSelServer := False;
      try
        CS_DB.Enter;
        nIDCostIndex := Config.AccountCostList.GetIndex(UserInfo.sAccount);
        nIPCostIndex := Config.IPaddrCostList.GetIndex(UserInfo.sUserIPaddr);
        nIDCost := 0;
        nIPCost := 0;
        boPayCost := False;
        if nIDCostIndex >= 0 then
          nIDCost := Integer(Config.AccountCostList.Objects[nIDCostIndex]);
        if nIPCostIndex >= 0 then
        begin
          nIPCost := Integer(Config.IPaddrCostList.Objects[nIPCostIndex]);
          boPayCost := true;
        end;
      finally
        CS_DB.Leave;
      end;
      if (nIDCost >= 0) or (nIPCost >= 0) then
        UserInfo.boPayCost := true
      else
        UserInfo.boPayCost := False;
      UserInfo.nIDDay := LoWord(nIDCost);
      UserInfo.nIDHour := HiWord(nIDCost);
      UserInfo.nIPDay := LoWord(nIPCost);
      UserInfo.nIPHour := HiWord(nIPCost);
      if not UserInfo.boPayCost then
      begin
        DefMsg := MakeDefaultMsg(SM_PASSOK_SELECTSERVER, 0, 0, 0,
          Config.ServerNameList.Count);
      end
      else
      begin
        DefMsg := MakeDefaultMsg(SM_PASSOK_SELECTSERVER,
          nIDCost,
          LoWord(nIPCost),
          HiWord(nIPCost),
          Config.ServerNameList.Count);
      end;
      sServerName := GetServerListInfo;
      SendGateMsg(UserInfo.Socket,
        UserInfo.sSockIndex,
        EncodeMessage(DefMsg) + EncodeString(sServerName));

      SessionAdd(Config,
        UserInfo.sAccount,
        UserInfo.sUserIPaddr,
        UserInfo.sGateIPaddr,
        UserInfo.nSessionID,
        UserInfo.boPayCost,
        False);
      //CODE:0046B857                 call    sub_46C150
    end
    else
    begin
      DefMsg := MakeDefaultMsg(SM_PASSWD_FAIL, nCode, 0, 0, 0);
      SendGateMsg(UserInfo.Socket, UserInfo.sSockIndex, EncodeMessage(DefMsg));
    end;
  except
    MainOutMessage('TFrmMain.LoginUser');
  end;
end;
//0046D890

procedure GetSelGateInfo(Config: pTConfig; sServerName, sIPaddr: string; var
  sSelGateIP: string; var nSelGatePort: Integer);
var
  I                                     : Integer;
  nGateIdx                              : Integer;
  nGateCount                            : Integer;
  nSelIdx                               : Integer;
  boSelected                            : Boolean;
begin
  try
    sSelGateIP := '';
    nSelGatePort := 0;
   //MainOutMessage(sServerName+' :'+sIPaddr);
    for I := 0 to Config.nRouteCount - 1 do
    begin
      if Config.boDynamicIPMode or ((Config.GateRoute[I].sServerName =
        sServerName) or (Config.GateRoute[I].sPublicAddr = sIPaddr)) then
      begin

        nGateCount := 0;
        nGateIdx := 0;
        while (true) do
        begin
          if (Config.GateRoute[I].Gate[nGateIdx].sIPaddr <> '') and
            (Config.GateRoute[I].Gate[nGateIdx].boEnable) then
            Inc(nGateCount);
          Inc(nGateIdx);
          if nGateIdx >= 10 then
            break;
        end;                                                //0046D956
        if nGateCount <= 0 then
          break; //如果没有相关网关IP设置,则跳出

        nSelIdx := Config.GateRoute[I].nSelIdx;
        boSelected := False;
        for nGateIdx := nSelIdx + 1 to 9 do
        begin
          if (Config.GateRoute[I].Gate[nGateIdx].sIPaddr <> '') and
            (Config.GateRoute[I].Gate[nGateIdx].boEnable) then
          begin
            Config.GateRoute[I].nSelIdx := nGateIdx;
            boSelected := true;
            break;
          end;
        end;
        if not boSelected then
        begin
          for nGateIdx := 0 to nSelIdx - 1 do
          begin
            if (Config.GateRoute[I].Gate[nGateIdx].sIPaddr <> '') and
              (Config.GateRoute[I].Gate[nGateIdx].boEnable) then
            begin
              Config.GateRoute[I].nSelIdx := nGateIdx;
              break;
            end;
          end;
        end;                                                //0046DA2B

        nSelIdx := Config.GateRoute[I].nSelIdx;
        sSelGateIP := Config.GateRoute[I].Gate[nSelIdx].sIPaddr;
        nSelGatePort := Config.GateRoute[I].Gate[nSelIdx].nPort;
       //  MainOutMessage(sSelGateIP+' :'+Inttostr(nSelGatePort));
        break;
      end;                                                  //0046DA72
    end;                                                    //0046DA7E
  except
    MainOutMessage('TFrmMain.GetSelGateInfo');
  end;
end;

function GetServerListInfo: string;
var
  sServerInfo                           : string;
  I                                     : Integer;
  sServerName                           : string;
  Config                                : pTConfig;
begin
  Config := @g_Config;
  try
    for I := 0 to Config.ServerNameList.Count - 1 do
    begin
      sServerName := Config.ServerNameList.Strings[I];
      if sServerName <> '' then
        sServerInfo := sServerInfo + sServerName + '/' +
          IntToStr(FrmMasSoc.ServerStatus(sServerName)) + '/';
    end;
    {
    for I := 0 to n473290 - 1 do begin
      if (GateRoute[i].sServerName <> '') then begin
        sServerInfo:=sServerInfo + GateRoute[i].sServerName + '/' + IntToStr(FrmMasSoc.ServerStatus(GateRoute[i].sServerName)) + '/';
      end;
    end;
    }
    Result := sServerInfo;
  except
    MainOutMessage('TFrmMain.GetServerListInfo');
  end;
end;

procedure AccountSelectServer(Config: pTConfig; UserInfo: pTUserInfo; sData:
  string);                                                    //0046B908
var
  sServerName                           : string;
  DefMsg                                : TDefaultMessage;

⌨️ 快捷键说明

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