Differences between revisions 34 and 35
Revision 34 as of 2021-03-16 13:56:53
Size: 3449
Editor: zbjxb
Comment:
Revision 35 as of 2021-11-02 03:48:14
Size: 3477
Editor: zbjxb
Comment:
Deletions are marked like this. Additions are marked like this.
Line 45: Line 45:
----
CategoryUnrealEngine

参考

UE4的多人在线游戏采用的是client-server模型。意味着有一个单独的server负责游戏状态的裁判,同时所有其他remote终端都维持一份本地相对server的近似。

Server是多人里重要的一部分,它做出所有重要的决定:

  • 所有状态控制任务
  • 处理remote client连接
  • 切换新关卡
  • 负责游戏流程:开局、结束等
  • etc...

Starting a Server

基本命令行(这些命令use the editor,因而不依赖cooked data):

Type

Command

Listen Server

UE4Editor.exe ProjectName MapName?Listen -game

Dedicated Server

UE4Editor.exe ProjectName MapName -server -game -log

Client

UE4Editor.exe ProjectName ServerIP -game

multiplayer.png

Server Gameplay Flow

The server is in charge of driving the flow of gameplay. It is the server's job to notify clients that it is time to travel to a new map, when gameplay starts and ends, along with actor replication updates, etc.

主要的游戏框架超出本文的范畴,这里只是简单提及一些:
Gameplay state and flow are generally driven through the GameMode Actor. Only the server contains a valid copy of this Actor (the client doesn't contain a copy at all). To communicate this state to the client, there is a GameState Actor, that will shadow important state of the GameMode Actor. This GameState Actor is marked to be replicated to each client. Clients will contain an approximate copy of this GameState Actor, and can use this Actor as a reference to know the general state of the game.

上面的话解释一下就是:UE4游戏进展基本上是靠GameMode Actor来驱动的。并且只有Server上有该Actor,其他client端没有。client端要想获知游戏进展,需要依靠GameState Actor,在Server上有一个Authoritative GameState Actor,它屏蔽了GameMode Actor的一些重要内部细节,并将除此之外的关于game state的信息replicates到remote proxies,client端可根据这些proxies获知游戏状态。

Connection Process

终端连接过程。

  1. Client发送连接请求
  2. 如果Server接受请求:发回当前关卡
  3. Server等待Client加载当前关卡
  4. Client加载完成后,Server会调用AGameModeBase::PreLogin

    • 这里GameMode可以选择拒绝连接

  5. 如果GameMode接受连接,Server会进一步调用AGameModeBase::Login

    • The role of this function is to create a PlayerController, which will then be replicated to the newly connected client. Once received, this PlayerController will replace the clients temporary PlayerController that was used as a placeholder during the connection process.(相关)

    • Note that APlayerController::BeginPlay will be called here. It should be noted that it is NOT yet safe to call RPC functions on this actor. You should wait until AGameModeBase::PostLogin is called.

  6. 假如一切顺利,到这里会调用AGameModeBase::PostLogin

    • At this point, it is safe for the server to start calling RPC functions on this PlayerController.


CategoryUnrealEngine

UE4-Networking-And-Multiplayer/Client-Server Model (last edited 2021-11-02 03:48:14 by zbjxb)