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

📄 lmain.pas

📁 传奇服务端代码 LoginSrvSQL 通讯部分
💻 PAS
📖 第 1 页 / 共 5 页
字号:
            AccountDB.Update(n10, DBRecord);
          end;
        end;
      end;
    finally
      AccountDB.Close;
    end;

    if (nCode = 1) and IsLogin(Config, sLoginID) 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.nSessionID,
        UserInfo.boPayCost);
      //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;
    for I := 0 to Config.nRouteCount - 1 do begin
      if Config.boDynamicIPMode or ((Config.GateRoute[I].sServerName = sServerName) and
        (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;
        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;
  boPayCost:   boolean;
  nPayMode:    integer;
  sSelGateIP:  string;
  nSelGatePort: integer;
resourcestring
  sSelServerMsg = 'Server: %s/%s-%s:%d';
begin
  sServerName := DecodeString(sData);
  if (UserInfo.sAccount <> '') and (sServerName <> '') and
    IsLogin(Config, UserInfo.nSessionID) then begin
    GetSelGateInfo(Config, sServerName, Config.sGateIPaddr, sSelGateIP, nSelGatePort);

    if (sSelGateIP <> '') and (nSelGatePort > 0) then begin
      if Config.boDynamicIPMode then sSelGateIP := UserInfo.sGateIPaddr;
      //增加支动态IP

      if Config.boShowDetailMsg then
        MainOutMessage(format(sSelServerMsg, [sServerName, Config.sGateIPaddr,
          sSelGateIP, nSelGatePort]));

      UserInfo.boSelServer := True;
      boPayCost := False;
      nPayMode  := 5;
      if UserInfo.nIDHour > 0 then nPayMode := 2;
      if UserInfo.nIPHour > 0 then nPayMode := 4;
      if UserInfo.nIPDay > 0 then nPayMode := 3;
      if UserInfo.nIDDay > 0 then nPayMode := 1;
      if FrmMasSoc.IsNotUserFull(sServerName) then begin
        SessionUpdate(Config, UserInfo.nSessionID, sServerName, boPayCost);
        FrmMasSoc.SendServerMsg(SS_OPENSESSION, sServerName,
          UserInfo.sAccount + '/' + IntToStr(UserInfo.nSessionID) +
          '/' + IntToStr(integer(UserInfo.boPayCost)) + '/' +
          IntToStr(nPayMode) + '/' + UserInfo.sUserIPaddr);
        DefMsg := MakeDefaultMsg(SM_SELECTSERVER_OK, UserInfo.nSessionID, 0, 0, 0);

        SendGateMsg(UserInfo.Socket, UserInfo.sSockIndex, EncodeMessage(DefMsg) +
          EncodeString(sSelGateIP + '/' + IntToStr(nSelGatePort) +
          '/' + IntToStr(UserInfo.nSessionID)));
      end else begin
        UserInfo.boSelServer := False;
        SessionDel(Config, UserInfo.nSessionID);
        DefMsg := MakeDefaultMsg(SM_STARTFAIL, 0, 0, 0, 0);
        SendGateMsg(UserInfo.Socket, UserInfo.sSockIndex, EncodeMessage(DefMsg));
      end;
    end;
  end;
end;
//0046C570
procedure AccountUpdateUserInfo(Config: pTConfig; UserInfo: pTUserInfo; sData: string);
var
  UserEntry: TUserEntry;
  UserAddEntry: TUserEntryAdd;
  DBRecord: TAccountDBRecord;
  nLen:   integer;
  sUserEntryMsg: string;
  sUserAddEntryMsg: string;
  nCode:  integer;
  DefMsg: TDefaultMessage;
  n10:    integer;
begin
  try
    FillChar(UserEntry, SizeOf(TUserEntry), #0);
    FillChar(UserAddEntry, SizeOf(TUserEntryAdd), #0);
    nLen := GetCodeMsgSize(SizeOf(TUserEntry) * 4 / 3);
    sUserEntryMsg := Copy(sData, 1, nLen);
    sUserAddEntryMsg := Copy(sData, nLen + 1, Length(sData) - nLen);
    DecodeBuffer(sUserEntryMsg, @UserEntry, SizeOf(TUserEntry));
    DecodeBuffer(sUserAddEntryMsg, @UserAddEntry, SizeOf(TUserEntryAdd));
    nCode := -1;
    if (UserInfo.sAccount = UserEntry.sAccount) and
      CheckAccountName(UserEntry.sAccount) then begin

      try
        if AccountDB.Open then begin
          n10 := AccountDB.Index(UserEntry.sAccount);
          if (n10 >= 0) then begin
            if (AccountDB.Get(n10, DBRecord) >= 0) then begin
              DBRecord.UserEntry    := UserEntry;
              DBRecord.UserEntryAdd := UserAddEntry;
              AccountDB.Update(n10, DBRecord);
              nCode := 1;
            end;
          end else
            nCode := 0;
        end;
      finally
        AccountDB.Close;
      end;
    end; //0046C74B

    if nCode = 1 then begin
      WriteLogMsg(Config, 'upg', UserEntry, UserAddEntry);
      DefMsg := MakeDefaultMsg(SM_UPDATEID_SUCCESS, 0, 0, 0, 0);
    end else begin
      DefMsg := MakeDefaultMsg(SM_UPDATEID_FAIL, nCode, 0, 0, 0);
    end;
    SendGateMsg(UserInfo.Socket, UserInfo.sSockIndex, EncodeMessage(DefMsg));
  except
    MainOutMessage('TFrmMain.UpdateUserInfo');
  end;
end;

procedure AccountGetBackPassword(UserInfo: pTUserInfo; sData: string);
var
  sMsg:      string;
  sAccount:  string;
  sQuest1:   string;
  sAnswer1:  string;
  sQuest2:   string;
  sAnswer2:  string;
  sPassword: string;
  sBirthDay: string;
  nCode:     integer;
  nIndex:    integer;
  DefMsg:    TDefaultMessage;
  DBRecord:  TAccountDBRecord;
begin
  sMsg := DecodeString(sData);
  sMsg := GetValidStr3(sMsg, sAccount, [#9]);
  sMsg := GetValidStr3(sMsg, sQuest1, [#9]);
  sMsg := GetValidStr3(sMsg, sAnswer1, [#9]);
  sMsg := GetValidStr3(sMsg, sQuest2, [#9]);
  sMsg := GetValidStr3(sMsg, sAnswer2, [#9]);
  sMsg := GetValidStr3(sMsg, sBirthDay, [#9]);

  nCode := 0;

  try
    if (sAccount <> '') and AccountDB.Open then begin
      nIndex := AccountDB.Index(sAccount);
      if (nIndex >= 0) and (AccountDB.Get(nIndex, DBRecord) >= 0) then begin
        if (DBRecord.nErrorCount < 5) or
          ((GetTickCount - DBRecord.dwActionTick) > 180000) then begin
          nCode := -1;
          if (DBRecord.UserEntry.sQuiz = sQuest1) then begin
            nCode := -3;
            if DBRecord.UserEntry.sAnswer = sAnswer1 then begin
              if DBRecord.UserEntryAdd.sBirthDay = sBirthDay then begin
                nCode := 1;
              end;
            end;
          end;
          if nCode <> 1 then begin
            if (DBRecord.UserEntryAdd.sQuiz2 = sQuest2) then begin
              nCode := -3;
              if DBRecord.UserEntryAdd.sAnswer2 = sAnswer2 then begin
                if DBRecord.UserEntryAdd.sBirthDay = sBirthDay then begin
                  nCode := 1;
                end;
              end;
            end;
          end;
          if nCode = 1 then begin
            sPassword := DBRecord.UserEntry.sPassword;
          end else begin
            Inc(DBRecord.nErrorCount);
            DBRecord.dwActionTick := GetTickCount();
            AccountDB.Update(nIndex, DBRecord);
          end;
        end else begin
          nCode := -2;
          if GetTickCount < DBRecord.dwActionTick then begin
            DBRecord.dwActionTick := GetTickCount();
            AccountDB.Update(nIndex, DBRecord);
          end;
        end;
      end;
    end;
  finally
    AccountDB.Close;
  end;

  if nCode = 1 then begin
    DefMsg := MakeDefaultMsg(SM_GETBACKPASSWD_SUCCESS, 0, 0, 0, 0);
    SendGateMsg(UserInfo.Socket, UserInfo.sSockIndex, EncodeMessage(DefMsg) +
      EncodeString(sPassword));
  end else begin
    DefMsg := MakeDefaultMsg(SM_GETBACKPASSWD_FAIL, nCode, 0, 0, 0);
    SendGateMsg(UserInfo.Socket, UserInfo.sSockIndex, EncodeMessage(DefMsg));
  end;
end;

//0046A500
procedure SendGateMsg(Socket: TCustomWinSocket; sSockIndex, sMsg: string);
var
  sSendMsg: string;
begin
  sSendMsg := '%' + sSockIndex + '/#' + sMsg + '!$';
  Socket.SendText(sSendMsg);
end;
//0046A104
function IsLogin(Config: pTConfig; nSessionID: integer): boolean;
var
  ConnInfo: pTConnInfo;
  I: integer;
begin
  Result := False;
  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
        Result := True;
        break;
      end;
    end;
  finally
    Config.SessionList.UnLock;
  end;
end;
//00469B54
function IsLogin(Config: pTConfig; sLoginID: string): boolean;
var
  ConnInfo: pTConnInfo;
  I: integer;
begin
  Result := False;
  Config.SessionList.Lock;
  try
    for I := 0 to Config.SessionList.Count - 1 do begin
      ConnInfo := Config.SessionList.Items[I];
      if (ConnInfo.sAccount = sLoginID) then begin
        Result := True;
        break;
      end;
    end;
  finally
    Config.SessionList.UnLock;
  end;
end;
//00469BE8
procedure SessionKick(Config: pTConfig; sLoginID: string);
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.sAccount = sLoginID) and not ConnInfo.boKicked then begin
        FrmMasSoc.SendServerMsg(SS_CLOSESESSION, ConnInfo.sServerName,
          ConnInfo.sAccount + '/' + IntToStr(ConnInfo.nSessionID));
        ConnInfo.dwKickTick := GetTickCount();

⌨️ 快捷键说明

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