UE5——网络——几种网络模式

cpp 复制代码
/**
 * The network mode the game is currently running.
 * @see https://docs.unrealengine.com/latest/INT/Gameplay/Networking/Overview/
 */
enum ENetMode
{
	/** Standalone: a game without networking, with one or more local players. Still considered a server because it has all server functionality. */
	NM_Standalone,

	/** Dedicated server: server with no local players. */
	NM_DedicatedServer,

	/** Listen server: a server that also has a local player who is hosting the game, available to other players on the network. */
	NM_ListenServer,

	/**
	 * Network client: client connected to a remote server.
	 * Note that every mode less than this value is a kind of server, so checking NetMode < NM_Client is always some variety of server.
	 */
	NM_Client,

	NM_MAX,
};

NM_Standalone:单机游戏:一个没有网络的游戏,有一个或多个本地玩家。仍然被视为服务器,因为它具有所有服务器功能。

NM_DedicatedServer:专用服务器:没有本地玩家的服务器。只作为服务器部分,接受其他客户端的连接。

NM_ListenServer:侦听服务器:也有一个本地玩家主持游戏的服务器,可供网络上的其他玩家使用。自己作为客户端,同时也是服务器,可以接受其他客户端的连接。

NM_Client:网络客户端:连接到远程服务器的客户端。请注意,每个小于此值的模式都是一种服务器,因此检查NetMode<NM_Client总是某种服务器。已经联网的客户端,连接了其他DedicatedServer 或者 ListenServer

cpp 复制代码
/** The network role of an actor on a local/remote network context */
UENUM()
enum ENetRole
{
	/** No role at all. */
	ROLE_None,
	/** Locally simulated proxy of this actor. */
	ROLE_SimulatedProxy,
	/** Locally autonomous proxy of this actor. */
	ROLE_AutonomousProxy,
	/** Authoritative control over the actor. */
	ROLE_Authority,
	ROLE_MAX,
};

ROLE_SimulatedProxy:此参与者的本地模拟代理,模拟的NetRole,指的是已经连接DedicateServer或者ListenServer的客户端上面的,游戏玩家或者怪物。这些角色在本客户端,只有被模拟的权限。

ROLE_AutonomousProxy:此参与者的本地自治代理。有自治权的角色,指的是已经连接DedicateServer或者ListenServer的客户端上面的主角。自己是有操作和预表现(客户端先行)权限的,但是需要经过服务器的校验和纠错。

ROLE_Authority:对行动者的权威控制,有自治权的角色,指的是已经连接DedicateServer或者ListenServer的客户端上面的主角。自己是有操作和预表现(客户端先行)权限的,但是需要经过服务器的校验和纠错。

GetLocalRole()返回本地计算机对此参与者的控制程度

1.Play Standalone

2.Play As Listen Server


3.Play As Client


GetRemoteRole()返回远程计算机对此参与者的控制程度

1.Play Standalone


2.Play As Listen Server


3.Play As Client

代码部分

cpp 复制代码
oid UMainWidget::SetDisplayText(FString TextToDisplay)
{
	if (DisplayText)
	{
		DisplayText->SetText(FText::FromString(TextToDisplay));
	}
}

void UMainWidget::ShowPlayerNetRole(APawn* InPawn)
{
	//ENetRole RemoteRole = InPawn->GetLocalRole();
	ENetRole RemoteRole = InPawn->GetRemoteRole();
	
	FString Role;
	switch (RemoteRole)
	{
	case ENetRole::ROLE_Authority:
		Role = FString("Authority");
		break;
	case ENetRole::ROLE_AutonomousProxy:
		Role = FString("Autonomous Proxy");
		break;
	case ENetRole::ROLE_SimulatedProxy:
		Role = FString("Simulated Proxy");
		break;
	case ENetRole::ROLE_None:
		Role = FString("None");
		break;
	}
	FString RemoteRoleString = FString::Printf(TEXT("Role: %s"), *Role);
	SetDisplayText(RemoteRoleString);
}
相关推荐
mzhan01720 分钟前
Linux: network: wireshark:tcp 0.5 秒‘息停’发数据数据图表
网络·测试工具·wireshark
LRX_1989271 小时前
网络管理员教程(初级)第六版--第4章 Web网站建设
网络·计算机网络
鹓于1 小时前
滥用 CDN 缓存功能(传播恶意内容)
网络
王道长服务器 | 亚马逊云1 小时前
AWS Elemental MediaConvert:视频转码不再难
linux·服务器·网络·云计算·音视频·aws
qq_479875431 小时前
TCP网络编程本质
服务器·网络·tcp/ip
zhangzhangkeji1 小时前
UE5 材质-16:贴花材质,decaL
ue5
国科安芯2 小时前
ASP3605A电源芯片在高速ADC子卡中的适配性研究
网络·人工智能·单片机·嵌入式硬件·安全
要加油哦~2 小时前
前端八股文 | HTTP - 实时通信方式/前后端通信方式
网络·网络协议·http
曹勖之3 小时前
使用 Datasmith 将 Rhino 模型导入 Unreal Engine 5(UE5)
ue5
AA陈超3 小时前
虚幻引擎5 GAS开发俯视角RPG游戏 P06-13 属性菜单 - 边框值
c++·游戏·ue5·游戏引擎·虚幻