UE5多人MOBA+GAS 54、用戶登錄和會話創建請求

文章目錄

  • 創建主菜單需要的
    • 創建主菜單游戲模式
    • 創建主菜單游戲控制器
    • 創建主菜單界面UI
    • 實現登錄游戲實例
  • 創建等待界面
  • 配置和獲取協調器 URL
  • 撰寫和發送會話創建請求


創建主菜單需要的

創建主菜單游戲模式

MainMenuGameMode
在這里插入圖片描述

創建主菜單游戲控制器

MainMenuPlayerController
在這里插入圖片描述

#pragma once#include "CoreMinimal.h"
#include "MenuPlayerController.h"
#include "MainMenuPlayerController.generated.h"/*** */
UCLASS()
class CRUNCH_API AMainMenuPlayerController : public AMenuPlayerController
{GENERATED_BODY()
public:	AMainMenuPlayerController();
};
#include "MainMenuPlayerController.h"AMainMenuPlayerController::AMainMenuPlayerController()
{// 禁用自動管理相機目標bAutoManageActiveCameraTarget = false;
}

分別創建兩個的藍圖
在這里插入圖片描述
在這里插入圖片描述
創建一個攝像機,自動啟用玩家0
在這里插入圖片描述

創建主菜單界面UI

MainMenuWidget

#pragma once#include "CoreMinimal.h"
#include "Blueprint/UserWidget.h"
#include "Components/WidgetSwitcher.h"
#include "Framework/MGameInstance.h"
#include "MainMenuWidget.generated.h"class UButton;
/*** */
UCLASS()
class CRUNCH_API UMainMenuWidget : public UUserWidget
{GENERATED_BODY()
public:virtual void NativeConstruct() override;/******************************/	/*           Main             *//******************************/	
private:UPROPERTY(meta = (BindWidget))TObjectPtr<UWidgetSwitcher> MainSwitcher;// 游戲實例UPROPERTY()TObjectPtr<UMGameInstance> MGameInstance;/******************************/	/*           Login            *//******************************/
private:// 登錄界面的根組件UPROPERTY(meta = (BindWidget))TObjectPtr<UWidget> LoginWidgetRoot;// 登錄按鈕UPROPERTY(meta = (BindWidget))TObjectPtr<UButton> LoginButton;// 登錄按鈕點擊事件UFUNCTION()void OnLoginButtonClicked();/*** 登錄完成時的回調函數* @param bWasSuccessful 是否登錄成功* @param PlayerNickname 登錄成功時的玩家昵稱* @param ErrorMsg 登錄失敗時的錯誤信息*/void LoginCompleted(bool bWasSuccessful, const FString& PlayerNickname, const FString& ErrorMsg);
};
#include "MainMenuWidget.h"#include "Components/Button.h"void UMainMenuWidget::NativeConstruct()
{Super::NativeConstruct();// 獲取游戲實例MGameInstance = GetGameInstance<UMGameInstance>();if (MGameInstance){}// 綁定登錄按鈕點擊事件LoginButton->OnClicked.AddDynamic(this, &UMainMenuWidget::OnLoginButtonClicked);
}void UMainMenuWidget::OnLoginButtonClicked()
{// 登錄按鈕點擊時觸發UE_LOG(LogTemp, Warning, TEXT("Longing In!"))
}void UMainMenuWidget::LoginCompleted(bool bWasSuccessful, const FString& PlayerNickname, const FString& ErrorMsg)
{if (bWasSuccessful){UE_LOG(LogTemp, Warning, TEXT("登錄成功: %s"), *PlayerNickname)}else{UE_LOG(LogTemp, Warning, TEXT("登錄失敗: %s"), *ErrorMsg)}
}

創建藍圖版本
在這里插入圖片描述
然后修改對應命名
在這里插入圖片描述

設置切換器的錨點
在這里插入圖片描述
在這里插入圖片描述

設置一下登錄
在這里插入圖片描述
添加一個尺寸框包裹
在這里插入圖片描述

添加一個背景模糊
在這里插入圖片描述
把UI添加到主菜單玩家控制器中
在這里插入圖片描述
在這里插入圖片描述

實現登錄游戲實例

UMGameInstance

/*** 登錄完成委托* 參數:*   - bWasSuccessful:登錄是否成功*   - PlayerNickName:玩家昵稱*   - ErrorMsg:錯誤信息*/
DECLARE_MULTICAST_DELEGATE_ThreeParams(FOnLoginCompleted, bool /*bWasSuccessful*/, const FString& /*PlayerNickName*/, const FString& /*ErrorMsg*/);
/*************************************//*             登錄功能              *//*************************************/
public:// 檢查是否已登錄bool IsLoggedIn() const;// 檢查是否正在登錄中bool IsLoggingIn() const;// 客戶端通過賬戶門戶登錄void ClientAccountPortalLogin();// 登錄完成委托FOnLoginCompleted OnLoginCompleted;private:// 客戶端登錄實現void ClientLogin(const FString& Type, const FString& Id, const FString& Token);// 登錄完成回調void LoginCompleted(int NumOfLocalPlayer, bool bWasSuccessful, const FUniqueNetId& UserId, const FString& Error);// 登錄委托句柄FDelegateHandle LoggingInDelegateHandle;
bool UMGameInstance::IsLoggedIn() const
{if (IOnlineIdentityPtr IdentityPtr = UTNetStatics::GetIdentityPtr()){// 查詢本地玩家0的登錄狀態,是否為已登錄return IdentityPtr->GetLoginStatus(0) == ELoginStatus::LoggedIn;}// 如果IdentityPtr無效,則默認未登錄return false;
}bool UMGameInstance::IsLoggingIn() const
{// 如果登錄委托句柄有效,說明還在等待登錄回調return LoggingInDelegateHandle.IsValid();
}void UMGameInstance::ClientAccountPortalLogin()
{// 調用統一的ClientLogin接口,使用AccountPortal方式ClientLogin("AccountPortal", "", "");
}void UMGameInstance::ClientLogin(const FString& Type, const FString& Id, const FString& Token)
{if (IOnlineIdentityPtr IdentityPtr = UTNetStatics::GetIdentityPtr()){// 如果已經有一個登錄委托在監聽,先移除它,避免重復綁定if (LoggingInDelegateHandle.IsValid()){IdentityPtr->OnLoginCompleteDelegates->Remove(LoggingInDelegateHandle);LoggingInDelegateHandle.Reset();}// 綁定登錄完成回調LoggingInDelegateHandle = IdentityPtr->OnLoginCompleteDelegates->AddUObject(this, &UMGameInstance::LoginCompleted);// 調用OnlineSubsystem的登錄函數(異步)if (!IdentityPtr->Login(0,FOnlineAccountCredentials(Type, Id, Token))){UE_LOG(LogTemp, Warning, TEXT("登錄失敗!"))if (LoggingInDelegateHandle.IsValid()){IdentityPtr->OnLoginCompleteDelegates->Remove(LoggingInDelegateHandle);LoggingInDelegateHandle.Reset();}// 通知外部,登錄失敗OnLoginCompleted.Broadcast(false, "", "登錄失敗!");}}
}void UMGameInstance::LoginCompleted(int32 NumOfLocalPlayer, bool bWasSuccessful, const FUniqueNetId& UserId,const FString& Error)
{if (IOnlineIdentityPtr IdentityPtr = UTNetStatics::GetIdentityPtr()){// 移除登錄完成委托if (LoggingInDelegateHandle.IsValid()){IdentityPtr->OnLoginCompleteDelegates->Remove(LoggingInDelegateHandle);LoggingInDelegateHandle.Reset();}FString PlayerNickname = "";if (bWasSuccessful){// 獲取玩家昵稱PlayerNickname = IdentityPtr->GetPlayerNickname(UserId);UE_LOG(LogTemp, Warning, TEXT("登錄成功: %s"), *(PlayerNickname))}else{UE_LOG(LogTemp, Warning, TEXT("登錄失敗: %s"), *(Error))}OnLoginCompleted.Broadcast(bWasSuccessful, PlayerNickname, Error);}else{OnLoginCompleted.Broadcast(false, "", "無法找到身份指針");}
}

UMainMenuWidget到主菜單UI中綁定委托


void UMainMenuWidget::NativeConstruct()
{Super::NativeConstruct();// 獲取游戲實例MGameInstance = GetGameInstance<UMGameInstance>();if (MGameInstance){MGameInstance->OnLoginCompleted.AddUObject(this, &UMainMenuWidget::LoginCompleted);}// 綁定登錄按鈕點擊事件LoginButton->OnClicked.AddDynamic(this, &UMainMenuWidget::OnLoginButtonClicked);
}void UMainMenuWidget::OnLoginButtonClicked()
{// 登錄按鈕點擊時觸發UE_LOG(LogTemp, Warning, TEXT("Longing In!"))if (MGameInstance && !MGameInstance->IsLoggedIn() && !MGameInstance->IsLoggingIn()){// 觸發登錄MGameInstance->ClientAccountPortalLogin();}
}

編譯運行后點擊登錄會跳轉到網頁登錄
在這里插入圖片描述

創建等待界面

WaitingWidget
在這里插入圖片描述

#pragma once#include "CoreMinimal.h"
#include "Blueprint/UserWidget.h"
#include "Components/Button.h"
#include "Components/TextBlock.h"
#include "WaitingWidget.generated.h"/*** 等待界面控件* 用于在需要玩家等待(如連接、加載、匹配)時顯示提示信息,* 并可選提供“取消”按鈕。*/
UCLASS()
class CRUNCH_API UWaitingWidget : public UUserWidget
{GENERATED_BODY()
public:virtual void NativeConstruct() override;// 獲取 Cancel 按鈕的點擊事件引用,并清空之前綁定的所有回調。FOnButtonClickedEvent& ClearAndGetButtonClickedEvent();/*** 設置等待提示信息,并控制“取消”按鈕是否可見。* @param WaitInfo   等待提示文本* @param bAllowCancel 是否允許取消(決定按鈕顯隱)*/void SetWaitInfo(const FText& WaitInfo, bool bAllowCancel = false);private:// 等待提示文本UPROPERTY(meta = (BindWidget))TObjectPtr<UTextBlock> WaitInfoText;// 取消按鈕UPROPERTY(meta = (BindWidget))TObjectPtr<UButton> CancelButton;
};
#include "WaitingWidget.h"void UWaitingWidget::NativeConstruct()
{Super::NativeConstruct();
}FOnButtonClickedEvent& UWaitingWidget::ClearAndGetButtonClickedEvent()
{// 清空按鈕已有的點擊事件CancelButton->OnClicked.Clear();return CancelButton->OnClicked;
}void UWaitingWidget::SetWaitInfo(const FText& WaitInfo, bool bAllowCancel)
{// 設置取消按鈕的可見性if (CancelButton){CancelButton->SetVisibility(bAllowCancel ? ESlateVisibility::Visible : ESlateVisibility::Hidden);}// 更新提示文字if (WaitInfoText){WaitInfoText->SetText(WaitInfo);}
}

回到主菜單界面UMainMenuWidget

	/******************************/	/*           Main             *//******************************/// 切換到主界面void SwitchToMainWidget();// 主界面的根組件UPROPERTY(meta = (BindWidget))TObjectPtr<UWidget> MainWidgetRoot;/******************************/	/*           等待			  *//******************************/
private:// 等待界面UPROPERTY(meta = (BindWidget))TObjectPtr<UWaitingWidget> WaitingWidget;// 切換到等待界面FOnButtonClickedEvent& SwitchToWaitingWidget(const FText& WaitInfo, bool bAllowCancel = false);
void UMainMenuWidget::NativeConstruct()
{Super::NativeConstruct();// 獲取游戲實例MGameInstance = GetGameInstance<UMGameInstance>();if (MGameInstance){MGameInstance->OnLoginCompleted.AddUObject(this, &UMainMenuWidget::LoginCompleted);if (MGameInstance->IsLoggedIn()){SwitchToMainWidget();}}// 綁定登錄按鈕點擊事件LoginButton->OnClicked.AddDynamic(this, &UMainMenuWidget::OnLoginButtonClicked);
}void UMainMenuWidget::SwitchToMainWidget()
{if (MainSwitcher){MainSwitcher->SetActiveWidget(MainWidgetRoot);}
}void UMainMenuWidget::OnLoginButtonClicked()
{// 登錄按鈕點擊時觸發UE_LOG(LogTemp, Warning, TEXT("Longing In!"))if (MGameInstance && !MGameInstance->IsLoggedIn() && !MGameInstance->IsLoggingIn()){// 觸發登錄MGameInstance->ClientAccountPortalLogin();// SwitchToWaitingWidget(FText::FromString("正在登錄..."));SwitchToWaitingWidget(FText::FromString(FString(TEXT("正在登錄..."))));}
}void UMainMenuWidget::LoginCompleted(bool bWasSuccessful, const FString& PlayerNickname, const FString& ErrorMsg)
{if (bWasSuccessful){UE_LOG(LogTemp, Warning, TEXT("登錄成功: %s"), *PlayerNickname)}else{UE_LOG(LogTemp, Warning, TEXT("登錄失敗: %s"), *ErrorMsg)}SwitchToMainWidget();
}FOnButtonClickedEvent& UMainMenuWidget::SwitchToWaitingWidget(const FText& WaitInfo, bool bAllowCancel)
{// 切換到等待界面MainSwitcher->SetActiveWidget(WaitingWidget);// 設置等待信息WaitingWidget->SetWaitInfo(WaitInfo, bAllowCancel);return WaitingWidget->ClearAndGetButtonClickedEvent();
}

創建等待UI藍圖版本
在這里插入圖片描述
設置按鈕錨點和位置
在這里插入圖片描述
可以添加等待動畫
在這里插入圖片描述
主界面菜單中添加該UI
在這里插入圖片描述
在這里插入圖片描述
主菜單界面UMainMenuWidget中創建用于創建會話的按鈕已經輸入

	/******************************/	/*           會話			  *//******************************/// 創建會話按鈕UPROPERTY(meta=(BindWidget))TObjectPtr<UButton> CreateSessionButton;// 輸入房間(會話)的名稱的文本框UPROPERTY(meta=(BindWidget))TObjectPtr<UEditableText> NewSessionNameText;// 點擊“創建會話”按鈕時調用UFUNCTION()void CreateSessionBtnClicked();// 取消房間創建(如等待界面點擊取消時觸發)UFUNCTION()void CancelSessionCreation();// 房間(會話)名稱輸入框文字變更時調用(用于校驗是否可創建)UFUNCTION()void NewSessionNameTextChanged(const FText& NewText);
void UMainMenuWidget::NativeConstruct()
{Super::NativeConstruct();// 獲取游戲實例MGameInstance = GetGameInstance<UMGameInstance>();if (MGameInstance){MGameInstance->OnLoginCompleted.AddUObject(this, &UMainMenuWidget::LoginCompleted);if (MGameInstance->IsLoggedIn()){SwitchToMainWidget();}}// 綁定登錄按鈕點擊事件LoginButton->OnClicked.AddDynamic(this, &UMainMenuWidget::OnLoginButtonClicked);// 綁定創建會話按鈕點擊事件CreateSessionButton->OnClicked.AddDynamic(this, &UMainMenuWidget::CreateSessionBtnClicked);// 綁定新會話名稱輸入框內容改變事件NewSessionNameText->OnTextChanged.AddDynamic(this, &UMainMenuWidget::NewSessionNameTextChanged);
}void UMainMenuWidget::CreateSessionBtnClicked()
{// 確保玩家已登錄if (MGameInstance && MGameInstance->IsLoggedIn()){// 請求創建并加入一個新的房間(會話)MGameInstance->RequestCreateAndJoinSession(FName(NewSessionNameText->GetText().ToString()));// 切換到等待界面,提示“Creating Lobby”,并綁定取消操作SwitchToWaitingWidget(FText::FromString(FString(TEXT("創建大廳"))), true).AddDynamic(this, &UMainMenuWidget::CancelSessionCreation);}
}void UMainMenuWidget::CancelSessionCreation()
{if (MGameInstance){MGameInstance->CancelSessionCreation();}SwitchToMainWidget();
}void UMainMenuWidget::NewSessionNameTextChanged(const FText& NewText)
{// 創建按鈕是否可用CreateSessionButton->SetIsEnabled(!NewText.IsEmpty());
}

游戲實例UMGameInstance中補充函數

	/*************************************//*      客戶端會話創建和搜索			 *//*************************************/
public:// 請求創建并加入新會話void RequestCreateAndJoinSession(const FName& NewSessionName);// 取消會話創建void CancelSessionCreation();
void UMGameInstance::RequestCreateAndJoinSession(const FName& NewSessionName)
{UE_LOG(LogTemp, Warning, TEXT("請求創建并加入會話: %s"), *(NewSessionName.ToString()))
}void UMGameInstance::CancelSessionCreation()
{UE_LOG(LogTemp, Warning, TEXT("取消會話創建"))
}

添加控件
在這里插入圖片描述
再修改一下
在這里插入圖片描述
在這里插入圖片描述

配置和獲取協調器 URL

	/*** 獲取協調器URL鍵值* @return 協調器服務URL的FName鍵*/static FName GetCoordinatorURLKey();/*** 獲取協調器URL地址* @return 協調器服務地址字符串*/static FString GetCoordinatorURL();/*** 獲取默認協調器URL* @return 默認的協調器服務地址*/static FString GetDefaultCoordinatorURL();
FName UTNetStatics::GetCoordinatorURLKey()
{// 返回用于解析命令行參數的鍵值(這里是固定字符串 "COORDINATOR_URL")return FName("COORDINATOR_URL");
}FString UTNetStatics::GetCoordinatorURL()
{// 優先從命令行中獲取 Coordinator URLFString CoordinatorURL = GetCommandlineArgAsString(GetCoordinatorURLKey());if (CoordinatorURL != ""){// 如果命令行中有值,則直接返回return CoordinatorURL;}// 如果命令行參數為空,則使用配置文件中的默認值return GetDefaultCoordinatorURL();
}FString UTNetStatics::GetDefaultCoordinatorURL()
{FString CoordinatorURL = "";// 從配置文件 [Crunch.Net] 節點中讀取鍵 "CoordinatorURL"// 目標配置文件為 DefaultGame.iniGConfig->GetString(TEXT("Crunch.Net"), TEXT("CoordinatorURL"), CoordinatorURL, GGameIni);// 打印日志,方便調試,輸出獲取到的默認 URLUE_LOG(LogTemp, Warning, TEXT("Getting Default Coordinator URL as: %s"), *CoordinatorURL)// 返回默認配置中的 URLreturn CoordinatorURL;
}

填寫本地主機號,這里的 127.0.0.1表示 本機
在這里插入圖片描述

[Crunch.Net]
CoordinatorURL="127.0.0.1"

撰寫和發送會話創建請求

UMGameInstance

#include "Interfaces/IHttpResponse.h"
#include "Interfaces/IHttpRequest.h"/*************************************//*      客戶端會話創建和搜索			 *//*************************************/private:// 會話創建請求完成回調void SessionCreationRequestCompleted(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bConnectedSuccessfully, FGuid SessionSearchId);
void UMGameInstance::RequestCreateAndJoinSession(const FName& NewSessionName)
{UE_LOG(LogTemp, Warning, TEXT("請求創建并加入會話: %s"), *(NewSessionName.ToString()))// 創建HTTP請求對象,準備向協調器發起會話創建請求FHttpRequestRef Request = FHttpModule::Get().CreateRequest();// 生成唯一會話搜索ID用于后續查詢FGuid SessionSearchId = FGuid::NewGuid();// 獲取協調器服務的基礎URL地址FString CoordinatorURL  = UTNetStatics::GetCoordinatorURL();// 拼接目標 API 地址:<CoordinatorURL>/SessionsFString URL = FString::Printf(TEXT("%s/Sessions"), *CoordinatorURL);UE_LOG(LogTemp, Warning, TEXT("發送會話創建請求到 URL:%s"), *URL)// 配置 HTTP 請求:目標地址 + 請求方式 POSTRequest->SetURL(URL);Request->SetVerb("POST");// 設置 HTTP 請求頭,指定請求體為 JSON 格式Request->SetHeader(TEXT("Content-Type"), TEXT("application/json"));// 構造 JSON 請求體,包含 SessionName 和 SessionSearchIdTSharedPtr<FJsonObject> JsonObject = MakeShareable(new FJsonObject);JsonObject->SetStringField(UTNetStatics::GetSessionNameKey().ToString(), NewSessionName.ToString());JsonObject->SetStringField(UTNetStatics::GetSessionSearchIdKey().ToString(), SessionSearchId.ToString());// 將 JSON 對象轉換為字符串FString RequestBody;TSharedRef<TJsonWriter<>> Writer = TJsonWriterFactory<>::Create(&RequestBody);FJsonSerializer::Serialize(JsonObject.ToSharedRef(), Writer);// 設置 HTTP 請求體Request->SetContentAsString(RequestBody);// 綁定會話創建完成回調Request->OnProcessRequestComplete().BindUObject(this, &UMGameInstance::SessionCreationRequestCompleted, SessionSearchId);// 發送 HTTP 請求,測試中在python中編寫代碼接收請求信息if (!Request->ProcessRequest()){UE_LOG(LogTemp, Warning, TEXT("會話創建請求失敗"))}
}void UMGameInstance::SessionCreationRequestCompleted(FHttpRequestPtr Request, FHttpResponsePtr Response,bool bConnectedSuccessfully, FGuid SessionSearchId)
{if (!bConnectedSuccessfully){UE_LOG(LogTemp, Warning, TEXT("連接協調服務器失敗,網絡連接未成功!"))return;}UE_LOG(LogTemp, Warning, TEXT("連接協調服務器成功!"))
}

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/920119.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/920119.shtml
英文地址,請注明出處:http://en.pswp.cn/news/920119.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

SCSS上傳圖片占位區域樣式

_App.scss// 上傳圖片占位區域樣式---------------------------------------- [theme"uploadImage"] {transition: 0.2s;position: relative;cursor: pointer;border-radius: 4px;/*居中填滿*/background-repeat: no-repeat;background-position: center;background-…

Prometheus+Grafana監控mysql

1、簡述 使用 Prometheus 結合 Grafana 監控 MySQL 是一套成熟且廣泛應用的方案&#xff0c;能實現對 MySQL 性能、狀態等指標的實時采集、存儲、可視化及告警。 2、整體架構說明 Prometheus&#xff1a;負責定時從 MySQL 采集監控指標&#xff08;需借助 Exporter&#xff0…

網絡流量分析——Tcpdump 數據包過濾

文章目錄.PCAP 文件Tcpdump 數據包過濾過濾和高級語法選項有用的 TCPDump 過濾器主機過濾器源/目標過濾器使用源和端口作為過濾器將目標與網絡過濾器結合使用協議過濾器 - 通用名稱協議過濾器 - 編號端口過濾器端口范圍過濾器小于/大于過濾器利用更大的AND 過濾器無濾鏡的基本捕…

DeepSeek V3.1 橫空出世:重新定義大語言模型的邊界與可能

當大語言模型領域的競爭進入白熱化階段&#xff0c;一場靜默的技術革命正在悄然醞釀。2025 年8月19日&#xff0c;DeepSeek 團隊帶著全新升級的 V3.1 版本強勢登場&#xff0c;這個被業內稱為 “智能體時代敲門磚” 的模型&#xff0c;究竟藏著多少顛覆認知的黑科技&#xff1f…

Unity Netcode for GameObjects(多人聯機小Demo)

提示&#xff1a;文章寫完后&#xff0c;目錄可以自動生成&#xff0c;如何生成可參考右邊的幫助文檔 文章目錄前言一、安裝 Netcode for GameObjects二、做個小Dome1.NetcodeManageNet2.創建UI3.創建預制體4.代碼介紹UI代碼隨機位置代碼總結前言 Netcode for GameObjects 是 …

Ant Design for UI 選擇下拉框

1. 單選框 與多選框<template><div class"demo-page" style"padding: 40px; max-width: 1200px; margin: 0 auto; font-family: Microsoft YaHei, Arial, sans-serif;"><h1 style"color: #1890ff; text-align: center; margin-bottom…

動手學深度學習01-引言

動手學深度學習pytorch 參考地址&#xff1a;https://zh.d2l.ai/ 文章目錄動手學深度學習pytorch1-第01章-引言1. 機器學習/深度學習基礎1.1 什么是機器學習&#xff1f;1.2 深度學習與機器學習的關系&#xff1f;2. 數據&#xff08;Data&#xff09;2.1 什么是樣本、特征、標…

大模型提示詞工程背后的原理:深入理解Prompt Learning(提示學習)

“ 知其然也要知其所以然&#xff0c;為什么會有提示詞工程&#xff1f;” 了解和使用過大模型的人應該都知道提示詞工程&#xff0c;即使不了解提示詞工程&#xff0c;至少也應該聽說過&#xff0c;提示詞工程說白了就是一種和大模型交流的方法&#xff0c;它的作用就是讓大模…

AI 智能體安全設計模式:從三大“反模式”看如何構建可信的 AI 系統

摘要&#xff1a;當我們將 AI 智能體&#xff08;Agent&#xff09;從實驗原型推向生產環境時&#xff0c;許多團隊在不經意間重復著一些危險的錯誤實踐。這些反復出現的錯誤&#xff0c;在軟件工程中被稱為“反模式”&#xff08;Anti-Patterns&#xff09;。本文基于 Curity …

【前端安全】前端安全第一課:防止 XSS 和 CSRF 攻擊的常見手法

【前端安全】前端安全第一課&#xff1a;防止 XSS 和 CSRF 攻擊的常見手法 所屬專欄&#xff1a; 《前端小技巧集合&#xff1a;讓你的代碼更優雅高效》 上一篇&#xff1a; 【性能指標】決戰性能之巔&#xff1a;深入理解核心 Web 指標&#xff08;Core Web Vitals&#xff0…

QT新建文件或者項目解釋:那些模板分別是什么意思?

在 Qt Creator 的 “New File or Project” 界面中&#xff0c;不同分類下的模板有著不同的用途和適用場景&#xff0c;以下是對各部分的詳細說明&#xff1a;一、“項目” 分類下1. Application&#xff08;應用程序&#xff09;用途&#xff1a;用于創建可直接運行的應用程序…

《支付回調狀態異常的溯源與架構級修復》

在后端開發領域&#xff0c;能通過錯誤日志直接定位的問題&#xff0c;只能算作“基礎挑戰”&#xff1b;而那些依賴特定數據量、并發量或外部交互場景才會觸發的隱性問題&#xff0c;往往像藏在電路中的虛焊點&#xff0c;平時看似正常&#xff0c;關鍵時刻卻會導致整個系統斷…

C語言 運算符 (2)

一、內容概要內容提neirong關系運算符 邏輯運算符 逗號運算符 位運算二、運算符2.1 關系運算符說明&#xff1a; >,<,>,<,,! &#xff08;都是雙目的&#xff09;所有關系運算符都是雙目運算符&#xff08;二元運算符&#xff09;&#xff0c;運算符左側和右側、可…

mac版SVN客戶端: macSvn 下載、使用指南【保姆級教程】

做項目要用SVN&#xff0c;在Mac平臺找順手的客戶端好難。Windows下的TortoiseSVN很贊&#xff0c;Mac卻一直沒對等工具。直到發現新發布的MacSVN&#xff0c;布局和操作深得我心&#xff0c;內置常用工具&#xff0c;還能無縫集成到OS與任務欄&#xff0c;便捷易上手&#xff…

MongoDB分片集群自動化部署

OS&#xff1a;CentOS Linux release 7.9.2009 (Core) 場景&#xff1a; 需要半自動化或者自動化部署MongoDB集群時&#xff0c;可用此腳本。提高交付效率。 腳本實現架構圖&#xff1a;腳本&#xff1a; check_clear_host.sh #此腳本有2個功能及是檢查 資源規格和清理資源上的…

go-redis庫使用總結

文章目錄1. 概述與特性2. 安裝與初始化2.1 安裝2.2 初始化3 基本使用模式3.1 單實例客戶端3.2 連接池與自動重連4. 常用 Redis 數據結構操作4.1 字符串&#xff08;String&#xff09;4.2 哈希&#xff08;Hash&#xff09;4.3 列表&#xff08;List&#xff09;4.4 集合&#…

【軟件設計模式】策略模式

1.概念策略&#xff08;Strategy&#xff09;模式定義了一系列算法&#xff0c;并將每個算法封裝起來&#xff0c;使它們可以相互替換&#xff0c;且算法的變化不會影響使用算法的客戶。策略模式屬于行為型設計模式&#xff0c;它通過對算法進行封裝&#xff0c;把使用算法的責…

Mac電腦英特爾版本最新系統15.6.1安裝php環境

Mac電腦安裝php環境 版本環境&#xff1a; 2025-08-22 14:09:19 安裝 最新系統15.6.1系統&#xff1a; 新版本的mac不帶php環境&#xff0c;需要自己 安裝 brew install php8.3 啟動說明 查看 . 使用官方方法安裝 NVM curl -o- https://raw.githubusercontent.com/nvm-sh/…

Android焦點窗口變化導致遙控鍵值監聽失效問題分析

最近在做語音全局控制Android系統功能&#xff0c;通過集成第三方語音識別sdk得到相關控制指令&#xff0c;然后將指令通過進程間通信傳遞給當前應用并作出響應。有很多通用指令&#xff0c;比如播放/暫停&#xff0c;Android系統本身就有全局控制指令&#xff1a;KeyEvent.KEY…

降本增效:基于 JavaScript 的 AI 編程 IDE 上下文壓縮優化方案

降本增效&#xff1a;基于 JavaScript 的 AI 編程 IDE 上下文壓縮優化方案 在當前 AI 輔助編程&#xff08;AI Pair Programming&#xff09;日益普及的背景下&#xff0c;開發者越來越依賴如 GitHub Copilot、Tabnine、CodeLlama 等智能編碼工具。然而&#xff0c;一個普遍存在…