This document is about: SERVER 5
SWITCH TO

4.x to 5.0 RC1 Upgrade Guide

本指南適用於從v4版本升級到等於或高於v5.0 RC1的v5版本(不是v5 BETA)。

主要變更概述

如果您之前沒有許可証,並且使用20個免費的CCU引導模式運行服務器,你現在需要得到一個許可証,以便能夠使用新的服務器版本。 CounterPublisher(應用程序、項目和DLLs)已被廢棄並從SDK中刪除。 除此以外,一些配置上的變化需要審查。

許可証更新和升級

當升級到新的 Photon SDK 主要版本時,或者使用舊的SDK版本和新購買的許可証文件時,您應該在提前確保您的Photon SDK能在該許可証下運行。

最簡單的方法是將許可証文件放入您打算使用的Photon SDK文件夾中,然后通過Photon控制程序啟動Photon。 然后,您應該檢查托盤應用程序中顯示的許可証信息,另外檢查日志中是否有許可証錯誤。

代碼變更

這裡我們列出了您的自定義類中可能需要的改動,這些類別擴展了一些常用的類型。

ApplicationBase

如果您正在擴展ApplicationBase類。

  • 其中一個構造函數需要將IConfiguration 參數傳遞給基礎構造函數。 為了做到這一點,你需要導入NuGet包 "Microsoft.Extensions.Configuration.Abstractions"。 然后加載配置(從XML或JSON或其他地方),然后將其傳遞給基礎建構器。 您可參考我們在 "MasterApplication "或 "GameApplication "或 "PhotonApp "類中的操作。 我們使用的常見模式:

    C#

    using Photon.SocketServer;
    using Microsoft.Extensions.Configuration;
    
    public class CustomPhotonApplication : ApplicationBase
    {
        public CustomPhotonApplication() : base(LoadConfiguration())
        {
        }
    
        private static IConfiguration LoadConfiguration()
        {
    
  • (可選)覆蓋的新方法:

    • object DecryptAuthToken(InitRequest initRequest, byte[] authToken, int offset, int length, out Dictionary<byte, object> encryptionData, out string errorMsg)
    • void OnWebRTCChannelDestroyed(IPhotonWebRTCPeer peer, object userData, byte channelId)

ClientPeer

如果您正在擴展ClientPeer類:

  • void OnUnexpectedDataReceived(byte[] data, string debugMessage)消失,而被void OnDeserializationError(byte[] data, RtsMessageType msgType, string debugMessage, short errorCode = -12, byte code = 0, Exception exception = null)所取代。
  • OnDisconnected的第一個參數已從DisconnectReasonint改變: 更改前 void OnDisconnect(DisconnectReason reasonCode, string reasonDetail) 。 更改後 void OnDisconnect(int reasonCode, string reasonDetail)
  • (可選)覆蓋的新方法:
    • string GetHistograms()(可選)
    • void OnEncryptionQueueOverload(EncryptionQueueFailureParams failureParams)(可選)。

S2SPeerBase

與擴展ClientPeer時一樣,加上新的可選方法來覆蓋:void OnDisconnectMessage(DisconnectMessage message)

InboundS2SPeer

與擴展S2SPeerBase時相同。

OutboundS2SPeer

與擴展S2SPeerBase時一樣,加上新的可選方法來覆蓋 void OnConnectionEstablished(InitV3Response initResponse)

PhotonServer.config 變更

  • 我們現在支持一種新的語法來定義伺服器應用事件。 之前:

    XML

    <Configuration>
      <InstanceName>
      </InstanceName>
    </Configuration>
    

    之後:

    XML

    <Configuration>
      <Instance Name="InstanceName">
      </Instance>
    </Configuration>
    
  • 對LoadBalancing事件,現在默認的應用程序是NameServer,而不再是曾經在v4的Master。

  • 從LoadBalancing事件中刪除CounterPublisher應用節點。

  • 刪除MMO事件。

Obsolete 設定

有一些設置在v5中被刪除,由於新引入的模式驗証,如果這些設置仍然存在,伺服器將無法啟動。

應用程序

  • 共享目錄的邏輯是舊的,不使用。 刪除相關設置:
    • SharedDirIsExeDir

應用程序

  • 共享目錄的邏輯是舊的,不使用。 移除相關設置:
    • SharedDirIsExeDir
    • SharedDirectory
  • 更改時自動重啟應用程序的功能現在已被禁用。 移除相關設置:
    • 重啟延遲毫秒
    • 監視文件
    • 排除文件
    • 啟用陰影拷貝
    • 啟用自動重啟
    • 強制自動重啟
  • 解析器
  • 啟用外網

TCPListener

  • 認證設置已經改變[按此](#secure_listeners_setup)。 舊的認證設置已經消失:
    • 商店名稱
    • 使用機器存儲
    • 証書名稱
  • 斷開時間
  • 最大等待緩衝量
  • 最大待寫數據量
  • 流程控制通知步驟大小
  • 政策應用

HTTPListener

  • 訪問控制-允許-起源

事件

  • AttachConsole
  • TCPUsePageAllocator
  • UseStandardAllocator
  • UseLockFreeAllocator
  • UseTLSAllocator
  • ENETUseLowContentionBufferAllocator
  • ENETNumAllocators
  • ENETUsePageAllocator
  • ValidateCRCifPresent

IOPool / ENetIOPool / ENetThreadPool

"優先級 "設置已從所有三個範圍中刪除。

WebRTC

  • HTMLTemplate

Runtime

  • 刪除了優化廣播
  • UnhandledExceptionPolicy。用 "Ignore "或 "TerminateProcess "替換 "ReloadDomain "值。 "ReloadDomain "不再支援。

HTTP Listeners

WebSocketListeners(和其他HTTP listeners)的語法已經改變。

之前 (v4):

XML

    <WebSocketListeners>
      <WebSocketListener
        IPAddress="0.0.0.0"
        Port="9090"
        DisableNagle="true"
        InactivityTimeout="10000"
        OverrideApplication="Master">
      </WebSocketListener>
      <WebSocketListener
        IPAddress="0.0.0.0"
        Port="9091"
        DisableNagle="true"
        InactivityTimeout="10000"
        OverrideApplication="Game">
      </WebSocketListener>
    </WebSocketListeners>

之後 (v5):

XML

    <HTTPListeners>
      <HTTPListener
        Name="*:[PORT]::Master"
        IPAddress="0.0.0.0"
        Port="9090"
        DisableNagle="true"
        InactivityTimeout="10000">
        <Routing>
          <Route
            Url="/+"
            OverrideApplication="Master"
            PeerType="WebSocket"
            Counters="false" />
          <Route Url="/photon/m" Ping="true" Counters="false"/>
        </Routing>
      </HTTPListener>
      <HTTPListener
        Name="*:[PORT]::Game"
        IPAddress="0.0.0.0"
        Port="9091"
        DisableNagle="true"
        InactivityTimeout="10000"
        AppDataInactivityTimeout="15000">
        <Routing>
          <Route
            Url="/+"
            OverrideApplication="Game"
            PingEvery="2000"
            PeerType="WebSocket"
            Counters="false" />
          <Route Url="/photon/g" Ping="true" Counters="false"/>
        </Routing>
      </HTTPListener>
      <HTTPListener
        Name="*:[PORT]::NameServer"
        IPAddress="0.0.0.0"
        Port="9093"
        DisableNagle="true"
        InactivityTimeout="10000"
        AppDataInactivityTimeout="15000">
        <Routing>
          <Route
            Url="/+"
            OverrideApplication="NameServer"
            PeerType="WebSocket"
            Counters="false" />
          <Route Url="/photon/n" Ping="true" Counters="false"/>
        </Routing>
      </HTTPListener>
    </HTTPListeners>

安全設置

由於我們已經從安全通道(Schannel)轉移到了OpenSSL,安全認證格式和配置已經改變。

  • 刪除過時的屬性:
    • 商店名稱
    • 使用機器存儲(UseMachineStore
    • 認證名稱

用認證設置的新設置來代替。 閱讀更多關於認證設置

LoadBalancing 配置變更

文件名的變化

首先,最明顯的區別是,現在每個伺服器應用程序都有自己的配置文件,其名稱格式如下:"{application_name}.xml.config"。 這對Master和GameServer應用程序來說尤其重要,它們過去默認共享相同的文件名和內容:"Photon.LoadBalancing.dll.config"。 該文件的內容現在被分割成兩個文件:

  • "deploy\LoadBalancing\Master\bin\Master.xml.config"
  • "deploy\LoadBalancing\GameServer\bin\GameServer.xml.config"

以下是配置文件的列表:

Master

之前 (v4):

"deploy\Loadbalancing\Master\bin\Photon.LoadBalancing.dll.config"

之後 (v5):

"deploy\LoadBalancing\Master\bin\Master.xml.config"

GameServer

之前 (v4):

"deploy\Loadbalancing\GameServer\bin\Photon.LoadBalancing.dll.config"

之後 (v5):

"deploy\LoadBalancing\GameServer\bin\GameServer.xml.config"

插件

遊戲服務器插件配置不再是GameSever配置文件的一部分,它現在在自己的文件 "deploy\LoadBalancing\GameServer\bin\plugin.config "中完成。 在V4中,它曾經在 "deploy\LoadBalancing\GameServer\bin\Photon.LoadBalancing.dll.config "中,所以你需要從那裡移動插件配置。

之前 (v4):

"deploy\Loadbalancing\GameServer\bin\Photon.LoadBalancing.dll.config"

之後 (v5):

"deploy\LoadBalancing\GameServer\bin\plugin.config"

結構變更

第二個重要的變化是,配置文件有了新的結構。

舊的文件結構:

XML

<?xml version="1.0"?>
<configuration>
  <configSections>
    <!-- sections defined here -->
  </configSections>
  <applicationSettings>
     <!-- app settings -->
  </applicationSettings>
  <!-- other settings -->
  <Photon>
    <CounterPublisher>
    </CounterPublisher>
  </Photon>
  <startup>
  </startup>
</configuration>

新的文件結構:

XML

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <Photon>
    <!-- all settings here -->
  </Photon>
</configuration>

注意底部的<Photon>元素。

一些舊的配置部分(XML元素)不再需要:

  • <configSections>
  • <applicationSettings>
  • <startup>
  • <CounterPublisher>

一些元素被重新命名:

  • <Photon.LoadBalancing.Common.CommonSettings> 更改成<LoadBalacing>
  • <Photon.Common.Authentication.Settings> 更改成<Authentication>
  • <Photon.LoadBalancing.MasterServer.MasterServerSettings> 更改成 <Master>
  • <Photon.LoadBalancing.GameServer.GameServerSettings> 更改成 <GameServer>
  • <WebRpcSettings> 更改成<WebRpc>
  • <AuthSettings> 更改成 <CustomAuth>

另外,現在每個設置節點都有一個與設置匹配的自定義名稱,而不是以前的通用格式。 這適用於所有元素,除了<WebRPC>(以前是<WebRpcSettings>)和<CustomAuth>(以前是<AuthSettings)沒有改變。

舊的節點設置格式:

XML

<setting name="SettingName" serializeAs="String">
    <value>SettingValue</value>
</setting>

新的節點設置格式:

XML

<SettingName>SettingValue</SettingName>

下面是每個文件的詳細的更改明細:

Master

<CustomAuth>(以前是<AuthSettings)不再是MasterServer配置的一部分,而是在NameServer("deploy\NameServer\bin\NameServer.xml.config")中完成。

舊的文件結構:

XML

<?xml version="1.0"?>
<configuration>
  <configSections>
    <!-- sections defined here -->
  </configSections>
  <applicationSettings>
    <Photon.LoadBalancing.Common.CommonSettings>
    </Photon.LoadBalancing.Common.CommonSettings>
    <Photon.Common.Authentication.Settings>
    </Photon.Common.Authentication.Settings>
    <Photon.LoadBalancing.MasterServer.MasterServerSettings>
    </Photon.LoadBalancing.MasterServer.MasterServerSettings>
  </applicationSettings>
  <Photon>
    <CounterPublisher>
    </CounterPublisher>
  </Photon>
  <WebRpcSettings>
  </WebRpcSettings>
  <startup>
  </startup>
</configuration>

新的文件結構:

XML

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <Photon>
    <LoadBalancing>
    </LoadBalancing>
    <Authentication>
    </Authentication>
    <Master>
      <S2S>
      </S2S>
      <GS>
      </GS>
      <Limits>
        <Inbound>
        </Inbound>
        <Lobby>
        </Lobby>
      </Limits>
    </Master>
    <WebRpc>
      <HttpQueueSetting>
      </HttpQueueSettings>
    </WebRpc>
    <SocketServer>
      <S2S>
      </S2S>
    </SocketServer>
  </Photon>
</configuration>

GameServer

舊的文件結構:

XML

<?xml version="1.0"?>
<configuration>
  <configSections>
    <!-- sections defined here -->
  </configSections>
  <applicationSettings>
    <Photon.LoadBalancing.Common.CommonSettings>
    </Photon.LoadBalancing.Common.CommonSettings>
    <Photon.Common.Authentication.Settings>
    </Photon.Common.Authentication.Settings>
    <Photon.LoadBalancing.MasterServer.GameServerSettings>
    </Photon.LoadBalancing.MasterServer.GameServerSettings>
  </applicationSettings>
  <Photon>
    <CounterPublisher>
    </CounterPublisher>
  </Photon>
  <WebRpcSettings>
  </WebRpcSettings>
  <startup>
  </startup>
</configuration>

新的文件結構:

XML

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <Photon>
    <LoadBalancing>
    </LoadBalancing>
    <Authentication>
    </Authentication>
    <GameServer>
      <S2S>
      </S2S>
      <Master>
      </Master>
      <Limits>
        <Inbound>
          <EventCache>
          </EventCache>
          <Properties>
          </Properties>
          <Operations>
          </Operations>
        </Inbound>
      </Limits>
      <HttpQueueSetting>
      </HttpQueueSettings>
    </GameServer>
    <WebRpc>
      <HttpQueueSetting>
      </HttpQueueSettings>
    </WebRpc>
    <SocketServer>
      <S2S>
      </S2S>
    </SocketServer>
  </Photon>
</configuration>

插件

添加一個<Configuration></Configuration>的封裝元素:

XML

<Configuration>
  <PluginSettings Enabled="True">
    <Plugins>
      <!-- custom plugin settings here -->
    </Plugins>
  </PluginSettings>
</Configuration>

HttpQueueSettings

HttpQueue被用於所有的HTTP(出站)。 所以把序列的相關設置歸入一個組是有意義。 這組設置用於GameServer、WebRPC和CustomAuth設置(作為一個子組)。 大部分設置在第四版中已經有了,但現在它更有組織性(新結構),更乾淨,更一致(命名)。

  • HttpRequestTimeout: 序列可以響應HTTP等待多長時間(以毫秒為單位)。
  • LimitHttpResponseMaxSize: 允許HTTP響應有效載荷的最大尺寸。
  • MaxBackoffTime: 重試發送HTTP請求時的回退閾值。
  • MaxConcurrentRequests: 允許的最大的HTTP請求。
  • `MaxErrorRequests': 在處理序列請求時,可能發生的最大錯誤數。 如果達到了,HttpQueue將斷開連接(清除所有等待請求並拒絕接收),然後在ReconnectInterval後恢復。
  • MaxQueuedRequests: 可以等待的最大請求數。
  • MaxTimedOutRequests: 在序列中超時等待處理的請求的最大數量。 如果達到了,HttpQueue將斷開連接(清除所有等待的請求並拒絕接收),然後在ReconnectInterval後恢復。
  • QueueTimeout: 如果一個請求在HttpQueue中停留的時間超過了QueueTimeout毫秒,它將被自動刪除。
  • ReconnectInterval。在恢復HTTP請求的處理之前,序列需要等待多長時間(以毫秒計)。

來自GameServer、WebRPC或CustomAuth節點的相同或相似名稱的設置需要被刪除或移到一個<HttpQueueSettings>元素下。

NameServer (新)

在v5中,我們增加了NameServer應用,以前只有在Photon Cloud中才有。 它的配置是通過兩個文件完成的。

  • 一個用於實際應用的文件。自定義認証現在是在NameServer上進行,而不是在MasterServer上。所以要把以前配置的自定義認証設置從MasterServer的配置文件(過去稱為<AuthSettings>)移到NameServer的配置文件(部分重命名為<CustomAuth>):"deploy\NameServer\bin\NameServer.xml.config"。

  • 一個文件用於與該NameServer相關的區域(MasterServer)列表。該文件可以在 "deploy\NameServer\bin\NameServer.xml.config "的 "NameServerConfig "設置中更改。默認情況是:"deploy\Nameserver.json"

'NameServer' 現在是PhotonServer.config中LoadBalancing實例的默認應用,取代了以前v4中的 'Master'。

LoadBalancer 與 Workload 配置更改

等級名稱更新

在v4中,有5個級別。 這些級別的名稱是 "最低"、"低"、"中"、"高 "和 "最高"。

現在我們使用'0級', '1級', '2級', ..., '9級'。 '最低'被替換為'0級'。 '最低'被替換為'9級'。

Workload 配置更改

GameServer中的 "WorkloadConfigFile "設置了LoadBalancer配置文件的路徑。 在v5中默認為 "deploy\Workload.1Gbps.config"(過去為 "Workload.config")。 另一個文件在SDK中也適用:"Workload.config"。

控制器設置更新

舊的控制器設置:

XML

<add Name="{ControllerName}" InitialInput="0" InitialLevel="Lowest">
  <FeedbackLevels>
    <add Level="Lowest" Value="{LowestValue}"/>
    <add Level="Low" Value="{LowValue}"/>
    <add Level="Normal" Value="{NormalValue}"/>
    <add Level="High" Value="{HighValue}"/>
    <add Level="Highest" Value="{HighestValue}"/>
  </FeedbackLevels>
</add>

新的控制器設置:

XML

<Controller Name="{ContollerName}" InitialInput="0" InitialLevel="Lowest">
  <FeedbackLevels>
    <Level name="0" Level="Level0" Value="{Value0}" ValueDown="{ValueDown0}"/>
    <Level name="1" Level="Level1" Value="{Value1}" ValueDown="{ValueDown1}"/>
    <Level name="2" Level="Level2" Value="{Value2}" ValueDown="{ValueDown2}"/>
    <Level name="3" Level="Level3" Value="{Value3}" ValueDown="{ValueDown3}"/>
    <Level name="4" Level="Level4" Value="{Value4}" ValueDown="{ValueDown4}"/>
    <Level name="5" Level="Level5" Value="{Value5}" ValueDown="{ValueDown5}"/>
    <Level name="6" Level="Level6" Value="{Value6}" ValueDown="{ValueDown6}"/>
    <Level name="7" Level="Level7" Value="{Value7}" ValueDown="{ValueDown7}"/>
    <Level name="8" Level="Level8" Value="{Value8}" ValueDown="{ValueDown8}"/>
    <Level name="9" Level="Level9" Value="{Value9}" ValueDown="{ValueDown9}"/>
  </FeedbackLevels>
</Controller>

文件結構更新

舊的結構:

XML

<?xml version="1.0" encoding="utf-8" ?>
<FeedbackControlSystem>
  <FeedbackControllers>
      <!-- one or more controllers setup -->
  </FeedbackControllers>
</FeedbackControlSystem>

新結構(增加封裝<Configuration></Configuration> 元素/節點):

XML

<?xml version="1.0" encoding="utf-8" ?>
<Configuration>
  <FeedbackControlSystem>
    <FeedbackControllers>
      <!-- one or more controllers setup -->
    </FeedbackControllers>
  </FeedbackControlSystem>
</Configuration>

LoadBalancer 配置更改

LoadBalancer的配置文件是 "deploy\LoadBalancer.config"。

XML

<?xml version="1.0" encoding="utf-8" ?>
<LoadBalancer>
  <LoadBalancerWeights>
    <add Level="Lowest" Value="{LowestValue}"/>
    <add Level="Low" Value="{LowValue}"/>
    <add Level="Normal" Value="{NormalValue}"/>
    <add Level="High" Value="{HighValue}"/>
    <add Level="Highest" Value="{HighestValue}"/>
  </LoadBalancerWeights>
</LoadBalancer>

新結構(增加封裝<Configuration></Configuration> 元素/節點):

XML

<?xml version="1.0" encoding="utf-8" ?>
<Configuration>
  <LoadBalancer ReserveRatio="{ReserveRatio}" ValueUp="{ValueUp}">
    <LoadBalancerWeights>
      <Level name="0" Level="Level0" Value="{Value0}" />
      <Level name="1" Level="Level1" Value="{Value1}"/>
      <Level name="2" Level="Level2" Value="{Value2}"/>
      <Level name="3" Level="Level3" Value="{Value3}"/>
      <Level name="4" Level="Level4" Value="{Value4}"/>
      <Level name="5" Level="Level5" Value="{Value5}"/>
      <Level name="6" Level="Level6" Value="{Value6}"/>
      <Level name="7" Level="Level7" Value="{Value7}"/>
      <Level name="8" Level="Level8" Value="{Value8}"/>
      <Level name="9" Level="Level9" Value="{Value9}"/>
    </LoadBalancerWeights>
  </LoadBalancer>
</Configuration>
Back to top