Base Applications 基本應(yīng)用程序
The Photon Server SDK includes several applications that should provide a good starting point for your own development. What each SDK does and for which game-style it might be a useful basis is described below.
以下是Photon服務(wù)器SDk包含的內(nèi)置應(yīng)用程序,可以作為你的應(yīng)用的開始點(diǎn)。
Lite
The Lite Application is probably the most often referenced application. It implements the basic framework for room based games in which players gets together to play a match in a small group. Each room reflects a game and is identified by its name. Anyone connected can join and leave without restriction. Inside a room any client can raise events to send data across to the others. Properties can be set for rooms and actors to keep certain values available for everyone joining.
Lite 是一個(gè)最常引用的應(yīng)用,它實(shí)現(xiàn)了一個(gè)多玩家一起競(jìng)賽的房間游戲的基本框架,通過名稱確定每個(gè)房間,一個(gè)房間就是一個(gè)游戲,任何人都可以不受限制的加入或離開,在房間內(nèi)任何客戶端都可以觸發(fā)事件去發(fā)送數(shù)據(jù)給別人,可以為房間和玩家設(shè)置屬性來確保進(jìn)入的玩家有準(zhǔn)確可用的值
Games, which don’t need an authoritative server, can be built on top of Lite without modifications.
所有游戲,不需要一個(gè)權(quán)威的服務(wù)器,可以建立在Lite之上并且不需要修改它
This application can easily be extended with server-side logic per room. Matchmaking could group players in rooms, depending on your game’s requirements.
這個(gè)應(yīng)用可以容易的擴(kuò)展服務(wù)器端的邏輯,根據(jù)你的游戲需求匹配一組玩家到房間里
Lite Lobby
The Lite Lobby Application is an example of how to build on top of Lite and extend its functionality. Lite Lobby adds new types of rooms: Lobbies. These won’t send join/leave events but list currently used room names. The player (or client code) can easily chose from running games. The count of users in a room is provided additionally.
Lite Lobby是一個(gè)在Lite之上建立并擴(kuò)展功能的例子,它添加了新的房間類型:大廳。這里不會(huì)發(fā)送加入或離開事件,只是當(dāng)前可用的房間名稱列表。玩家可以很容易的選擇正在進(jìn)行的游戲,房間中玩家的數(shù)量是可供增加的
This application adds “manual matchmaking” to Lite and could also be a basis for your game.
這個(gè)應(yīng)用增加了手動(dòng)匹配
MMO
The MMO Demo Application is a good solution for games where all players share a large world. It provides interest management and the most common base classes for items, actors, properties, and more.
MMO樣例程序是一個(gè)為玩家們分享一個(gè)大型世界的游戲解決方案,它提供了興趣管理和最常見的類型,比如物品、玩家、屬性等等
Games with a shared world contain more game-specific logic on the server side typically, so this application should be understood as a sound starting point.
這游戲是一個(gè)在服務(wù)端包含了更多的游戲邏輯的分享的世界,這個(gè)應(yīng)用被認(rèn)為是一個(gè)合理的開始點(diǎn)
Policy
The Policy Application runs on Photon to send the crossdomain.xml to web player platforms (e.g. Unity Web Player). Flash and Silverlight request an authorization before they contact a server.
Policy應(yīng)用運(yùn)行在Photon上用于發(fā)送crossdomain.xml到web player平臺(tái)。Flash 和 Silverlight在連接一個(gè)服務(wù)器之前需要請(qǐng)求一個(gè)授權(quán)
It has its own page in the DevNet: Policy Application
它有自己的頁面在DevNet上
Counter Publisher
This application reads and forwards local PerfMon counters of Photon Core to the Dashboard. It does not interfere with other applications, and clients should not connect to it.
這個(gè)應(yīng)用讀取本地的PerfMon計(jì)數(shù)器到Dashboard。它不會(huì)影響其他應(yīng)用程序,客戶端也不要去連接它
Basic Concepts 基本概念
The following article will show you the important basic concepts for Photon.
以下是要告訴你的Photon重要基本概念
Applications 應(yīng)用程序
An Application is the server side logic for a game. All features of a game (e.g. remote procedure calls, data storing, etc.) are implemented in a Photon application. The C# source is compiled and the resulting assemblies are loaded by Photons native core. To setup applications and to define start parameters the Photon Core uses configuration files.一個(gè)應(yīng)用既是一個(gè)服務(wù)端的游戲邏輯,一個(gè)游戲的所有特征是在Photon應(yīng)用中被實(shí)現(xiàn)的。由C#編寫的源碼被編譯成程序集并加載到Photons native core。部署應(yīng)用并且在Photon配置文件中定義參數(shù)。Usually, all logics of a game are provided in a single application. Photon is still able to run several applications at the same time. Each application can have a different task. For example, a separate application can be made to send out policy files for web-based clients. By running a separate Policy Application next to your game logic you can add functionality.通常,一個(gè)游戲的所有邏輯是由一個(gè)應(yīng)用程序提供的,Photon 是可以同時(shí)運(yùn)行多個(gè)應(yīng)用程序,每個(gè)應(yīng)用程序可以有不同的任務(wù)。比如,一個(gè)獨(dú)立的應(yīng)用程序可以被用于為基于Web的客戶端發(fā)送policy文件,通過運(yùn)行一個(gè)獨(dú)立的Policy應(yīng)用程序?yàn)槟愕挠螒蜻壿嬏砑庸δ?/div>A client chooses the application it wants to use by simply providing the application’s name on connect.一個(gè)客戶端在連接的時(shí)候需要使用應(yīng)用的名字去選擇應(yīng)用程序Game Logic 游戲邏輯
The game logic defines how a client can interact with the server. It implements operations, events, and anything that the server does by itself.游戲邏輯定義了客戶端如何與服務(wù)器進(jìn)行交互。它實(shí)現(xiàn)了操作、事件和其他服務(wù)器想做的事情A good basis for room based games is provided as “Lite” Application , found in the SDK folder src-server/Lite. It does not know (your) game’s logic (yet), but provides rooms where players can communicate and interact easily. The application “Lite Lobby” extends Lite with lists of rooms if you want your users to select a room manually.Lite是一個(gè)很好的基于房間的游戲基礎(chǔ)應(yīng)用,src-server/Lite中可以找到它,它不知道你的游戲邏輯,但是提供了房間,玩家可以輕松的進(jìn)行交流與互動(dòng)。Lite Lobby擴(kuò)展了Lite,提供了房間列表,以便于用戶可以手動(dòng)選擇房間If your game is going to be a single, huge world, the MMO Demo Application is a good basis for it. This application handles interest management for your clients and provides classes for items, properties, actors and more.如果你的游戲是一個(gè)獨(dú)立的巨大的世界,那MMO是一個(gè)很好的基礎(chǔ)應(yīng)用,這個(gè)應(yīng)用為你的客戶端提供了興趣管理和一些類型,例如商品、屬性、玩家等等。Alternatively any game logic can be developed directly on top of the C# framework. The entry point for this is the application class, defined in the Photon.Socketserver.dll.或者任何游戲的邏輯都可以在C# framework之上進(jìn)行開發(fā),這程序的入口必須定義在Photon.Socketserver.dllOperations 操作
An operation is Photon’s equivalent to a remote procedure call. Photon clients use operation calls for anything they want to get done.一個(gè)操作相當(dāng)于是一次遠(yuǎn)程過程調(diào)用(RPC)。Photon客戶端使用操作調(diào)用進(jìn)行他們想要做的事情Operations and all of their parameters are defined in the server-side application as needed. Clients can call any operation by setting up a hashtable with keys and values fitting the operation’s conventions. The client and server frameworks take care of serialization, transfer and deserialization.操作和屬性是被定義在服務(wù)端的應(yīng)用程序中的。客戶端可以調(diào)用任意操作,只要通過設(shè)置一個(gè)hashtable 的鍵和值來制定該操作的合約即可,客戶端和服務(wù)端的frameworks負(fù)責(zé)序列化、傳遞和反序列化Each operation can also provide a result. This is one way to provide a client with requested data. Of course the result can be skipped, which saves bandwidth.每個(gè)操作也可以提供一個(gè)結(jié)果。這是一個(gè)提供給客戶端請(qǐng)求數(shù)據(jù)的方法,當(dāng)然結(jié)果是可以被跳過的,跳過可以節(jié)省帶寬流量Operation calls and results are a thing between one client and the server. The other clients won’t know about these.操作的調(diào)用和結(jié)果是一個(gè)客戶端和服務(wù)器之間發(fā)生的,其他客戶端是無法得知。Events 事件
Photon Events are messages for clients. Each event is typed by a byte code and carries game updates. The Lite Application defines several events but it’s possible to define custom events purely on the client side.Photon事件是對(duì)客戶端的消息,每個(gè)事件的類型是一個(gè)byte代碼,Lite定義了許多的事件,也可以在客戶端定義通用的事件Unlike operation results, a received event is most likely caused another client’s operation call. This means: Events might arrive anytime. Lite sends events when someone joins or leaves a room.不像操作結(jié)果,一個(gè)接受到的事件最有可能觸發(fā)其他客戶端的操作調(diào)用,這意味著,事件可能隨時(shí)發(fā)生,Lite應(yīng)用中當(dāng)某個(gè)玩家加入和離開房間時(shí)會(huì)發(fā)送事件The Operation RaiseEvent (in Lite) makes events truly universal: Any client can create new events by putting together a hashtable with the data and applying a code on sending it. Game data can be sent without any need to change the server.這個(gè)RaiseEvent操作使得事件真正的通用:任意客戶端可以創(chuàng)建一個(gè)裝有數(shù)據(jù)和應(yīng)用代碼的hashtable的新的事件進(jìn)行發(fā)送,游戲數(shù)據(jù)可以被發(fā)送無需去改變服務(wù)器Of course, for more elaborate server side reaction to events, custom operations can be defined which check event data, compile it or create other events.當(dāng)然,對(duì)于更為復(fù)雜的服務(wù)器端事件的反應(yīng),通用操作可以被定義為檢查、編譯事件數(shù)據(jù)或創(chuàng)建其他事件Connections and Timeouts 連接與超時(shí)
Unlike plain UDP, Photon’s reliable UDP protocol establishes a connection between server and clients: Commands within a UDP package have sequence numbers and a flag if they are reliable. If so, the receiving end has to acknowledge the command. Reliable commands are repeated in short intervals until an acknowledgement arrives. If it does not arrive, the connection is timed out.不像常規(guī)的UDP,Photon使用的是可靠的UDP協(xié)議建立客戶端與服務(wù)端的連接:命令在一個(gè)UDP包中,其中包含序列化的數(shù)字和一個(gè)可靠性標(biāo)志,這樣接收端才能識(shí)別這個(gè)命令,可靠的命令是在很短的時(shí)間間隔內(nèi)重復(fù)直到被確認(rèn),如果不被確認(rèn)到,則連接超時(shí)Both sides monitor this connection independently from their perspective. Both sides have their rules to decide if the other is still available.兩端監(jiān)控連接都是獨(dú)立的,兩端還可以定義自己的規(guī)則If a timeouts is detected, a disconnect happens on that side of the connection. As we think the other side does not respond anymore, no message is sent to it. This is why timeout disconnects are one sided and not synchronous.如果一個(gè)超時(shí)被檢測(cè)到,就會(huì)斷開連接,這時(shí)我們認(rèn)為另一邊未響應(yīng),沒有信息可以發(fā)送給它,這就是為什么超時(shí)斷開是發(fā)生在一側(cè)并且是不同步的
Product Overview 產(chǎn)品概述
On the client-side, Photon supports various platforms. Even though programming in C, C# and Flash is very different, the basic workflow stays similar. In this online documentation we try to explain the concepts and background, while language specifics are left to the reference documentation per platform.在客戶端,Photon支持多樣的平臺(tái),使用C,C#,F(xiàn)lash進(jìn)行編程的方式是不同的,但是基本的工作流是相似的。在這文檔中我們嘗試去解釋它的概念和背景,而語言的細(xì)節(jié)部分需要查閱每個(gè)語言平臺(tái)的參考文檔。Each Photon Client SDK comes with a fitting reference documentation for its platform and language.每一個(gè)客戶端SDk都帶有相關(guān)平臺(tái)的參考文檔。Project Setup 項(xiàng)目設(shè)置
You need to include a single library to communicate with Photon on the client-side. This is a different setup per platform.在客戶端你需要包含一個(gè)獨(dú)立的library ,每個(gè)平臺(tái)的設(shè)置是不同的。
- DotNet
Add a reference to the PhotonDotNet.dll in your DotNet project to make its classes known. Import the lib’s namespace with: using ExitGames.Client.Photon;在項(xiàng)目中引用PhotonDotNet.dll,引用命名空間using ExitGames.Client.Photon
- Unity3d
You need to import the PhotonUnity3D.dll into your project in Unity. Simply open a Unity project/scene, open an explorer and drag and drop the .dll from <sdk>\libs\debug\ into the editor. Again, import the lib’s namespace with: using ExitGames.Client.Photon;你需要導(dǎo)入PhotonUnity3D.dll到項(xiàng)目中,打開Unity 的project/scene,打開資源管理器從<sdk>\libs\debug\ 拖放PhotonUnity3D.dll到editor,導(dǎo)入命名空間using ExitGames.Client.Photon;Workflow 工作流
The simplified lifecycle for any multiplayer game looks like this:多人游戲的簡化生命周期如下:
- Connect to server
連接服務(wù)器
- Make RPC calls
RPC調(diào)用
- Receive something
接收數(shù)據(jù)
- Disconnect
斷開連接很簡單,讓我們來看看每一個(gè)步驟,以Lite為例。
- Connect to server 連接服務(wù)器
Actually, you do a little more than just connect in this step. In short:事實(shí)上,你做的不只是連接而已:
- Implement the interface IPhotonPeerListener in one of your classes
在你的類中實(shí)現(xiàn)接口IPhotonPeerListener
- Create a LitePeer instance with your server’s address
創(chuàng)建LitePeer 實(shí)例和你服務(wù)器的地址
- In your game loop, call Service about 10 times a second
在你的游戲循環(huán)中大約10秒調(diào)用一次服務(wù)
- Now call Connect to establish the connection. The application name should match one in the PhotonServer.config
現(xiàn)在建立連接,這應(yīng)用程序的名字要與PhotonServer.config中的匹配
- Your implementation if PeerStatusCallback is called when the connection is ready or failed
你要實(shí)現(xiàn)的是當(dāng)連接是未連接的時(shí)候調(diào)用PeerStatusCallback
- The returned status be StatusCode.Connect
返回的狀態(tài)是StatusCode.ConnectThe peer instance provides you with some methods to talk to Photon. It does not have its own thread. It updates when you call Service instead. This will keep the connection alivepeer 實(shí)例提供了一些方法去訪問Photon,它沒有自己的線程,當(dāng)你調(diào)用服務(wù)時(shí)它進(jìn)行更新,并保持著連接We assume that Photon is running the “Lite” Application, which it does by default.我們假設(shè)Photon運(yùn)行著Lite,以下是默認(rèn)情況。
- Make RPC calls RPC調(diào)用
After connecting, the client can call methods in the Lite Application just about anytime it needs to. The methods available as “remote procedure call” are called operations.連接后,客戶端可以再任何時(shí)候去調(diào)用Lite應(yīng)用的方法,這樣的遠(yuǎn)程過程調(diào)用被稱為操作Operation calls are asynchronous and won’t block your game. They are queued internally until you intently send something by calling SendOutgoingCommands. There will be a short delay until the result is received. These results are defined per operation and are not used at all sometimes.操作調(diào)用是異步的,并且不會(huì)阻礙你的游戲。他們是在內(nèi)部排隊(duì)的直到你需要發(fā)送他們的時(shí)候通過SendOutgoingCommands發(fā)送。收到結(jié)果只需要很短暫的延遲時(shí)間,這些結(jié)果是被定義為操作并且不是所有的時(shí)間都被使用的。
- Call OpJoin with any room name to get into a game
調(diào)用OpJoin 可以加入游戲
- Wait for the callback: OperationResult with opCode: LiteOpCode.Join
等待回調(diào)帶有 opCode: LiteOpCode.Join 的 OperationResult
- Send any hashtable with content by calling OpRaiseEvent. Other players in the room will receive events.
通過調(diào)用OpRaiseEvent發(fā)送帶有內(nèi)容的hashtable ,其他這個(gè)房間的玩家也將收到相關(guān)的事件信息。Joining a room and raising events in it is provided (server side) by the Lite Application logic we use in this sample. You can use other applications and implement your own operations.這是一個(gè)按照Lite應(yīng)用的邏輯加入房間并觸發(fā)事件的例子,你可以使用其他的應(yīng)用并且實(shí)現(xiàn)你自己的操作
- Receive something 接收數(shù)據(jù)
In the previous step you already received an operation result. We differentiate those from other incoming messages, so called events. Lite will forward the event you raised to others in a room.在前面的步驟,你已經(jīng)接收到了操作的結(jié)果,我區(qū)別于來自其他地方的信息,所以稱之為事件,Lite將發(fā)送這事件觸發(fā)到房間中的其他人。Receiving events will call IPhotonPeerListener.EventAction. The evCode will match the one you used in OpRaiseEvent
調(diào)用IPhotonPeerListener.EventAction接收事件,evCode 將與你使用的OpRaiseEvent進(jìn)行匹配The client library will internally queue received packages, so your game decides when to use them. EventAction is called by your calls to PhotonPeer.Service.這客戶端將接收到的數(shù)據(jù)包進(jìn)行內(nèi)部排隊(duì),由你的游戲決定何時(shí)使用它們,通過調(diào)用PhotonPeer.Service來調(diào)用EventAction
- Disconnect 斷開連接
When a client is closed, the best is to disconnect. That’s nice, but not a must-have as a timeout will disconnect clients that don’t answer anymore.當(dāng)客戶端是關(guān)閉的時(shí)候,最好是斷開連接,但不是作為超時(shí)斷開。
- To close the connection: call Disconnect
關(guān)閉連接:調(diào)用Disconnect
- Check “disconnect” return in PeerStatusCallback with statusCode: StatusCode.Disconnect
檢查 “disconnect” ,PeerStatusCallback 的返回值為statusCode: StatusCode.Disconnect
- Now the client can stop calling service
現(xiàn)在客戶端可以停止調(diào)用服務(wù)了LitePeer versus PhotonPeer LitePeer與PhotonPeer
Aside from the LitePeer, the client libraries also include a PhotonPeer which could be used. The PhotonPeer has the bare minimum of API needed for Photon. It is the base for LitePeer, which adds operations like “Join”, “Leave” and “RaiseEvent”, which are available with the Lite Application.除了LitePeer,客戶端還包含了一個(gè)PhotonPeer 可以使用,PhotonPeer 對(duì)于Photon只有有限的API,它是LitePeer的基礎(chǔ),Lite中LitePeer增加了“Join”、“Leave” 、“RaiseEvent”等。Reliable UDP 可靠的UDP
Under the hood, Photon clients and servers send operations and events via UDP. This guarantees low overhead, flexibility and performance but is unreliable by definition.在底層,Photon客戶端和服務(wù)器通過UDP發(fā)送操作和事件的,這保證了低開銷、靈活性和性能但是被定義為不可靠的。Within the UDP packages, Photon uses a thin binary protocol to enable aggregation, ordering, detection of packet loss and more. It is based on eNet and used in similar form on client and server.在UDP包中,Photon 使用了一個(gè)精簡的二進(jìn)制協(xié)議來進(jìn)行聚合、排序、檢測(cè)數(shù)據(jù)包丟失,它是基于eNet的被用于服務(wù)器和客戶端So called “commands” are used to transfer the payload, such as operations. On the client side, Photon gives you full control of when commands are put into a UDP package and send.所謂的“commands”是用于傳遞這負(fù)載的,例如操作。在客戶端,由Photon控制命令以UDP包的形式進(jìn)行發(fā)送As a result, the API also includes methods that manage the connection to the server. Basically, there are two “layers”: the “command layer” and the “operation layer”:因此,API還包括管理連接服務(wù)器的方法,基本上,他們是由兩個(gè)層組成:“command layer” 和 “operation layer”
- Command layer: manages the communication protocol to establish and maintain communication.
命令層:管理通信協(xié)議建立連接并保持通信
- Operation layer: gives access to rooms, events and custom Operations. Client side, methods of this layer are prefixed with “Op”.
操作層:用于訪問房間、事件、自定義操作。在客戶端,這層的方法被加上了前綴 “Op”Reliable vs. Unreliable 可靠對(duì)不可靠
With Photon’s underlying protocol, everything that’s sent across can be made flagged as reliable or unreliable. The operation request is not changed by this though, only the command that’s used.Photon的底層協(xié)議,可以被標(biāo)記為可靠或不可靠,僅僅在命令被使用的時(shí)候操作請(qǐng)求是不可更改的。Photon keeps track of the ordering. Even unreliable commands are synchronized/sequenced within the order of reliable commands. So an unreliable command, which was sent after a certain reliable command, will also be dispatched after the reliable command was dispatched (even if that command was delayed).Photon 保持跟蹤,不可靠的命令是隨著可靠的命令進(jìn)行同步測(cè)序,所以一個(gè)不可靠的命令,被發(fā)送在一個(gè)可靠的命令之后,也將在可靠命令被分派之后再進(jìn)行分派。Operations and events that are sent as unreliable might get lost. As example, this is no problem for position updates, which are quickly replaced. On the server side, Operations that are received unreliable, should not create a result: The client can not expect that the operation even reached the server.操作和事件發(fā)送是不可能丟失的,舉例,對(duì)于位置的更新這不是問題,更新很快就被替換了,在服務(wù)端,接收到的不可靠的操作不會(huì)創(chuàng)建這樣一個(gè)結(jié)果:客戶端不會(huì)期望這操作到達(dá)服務(wù)器。Connection and Timeout 連接與超時(shí)
The client has two rules to define a timeout:這客戶端有兩種規(guī)則去定義超時(shí):
- Retries: A reliable command is sent multiple times to be acknowledged, each time the interval between retries gets longer, depending on general rountrip times. If the number of retries reaches a limit (in DotNet: SentCountAllowance), this causes a disconnect.
重試:一個(gè)可靠的命令將會(huì)被發(fā)送多次以用作確認(rèn),每次重試的時(shí)間間隔變長,根據(jù)統(tǒng)一的區(qū)域時(shí)間定義,如果重試次數(shù)達(dá)到一個(gè)極限,將會(huì)斷開連接。
- DisconnectTimeout: This defines a maximum number of milliseconds, before a reliable command must be answered. This is independent of the retry counting. In DotNet, the setting is: DisconnectTimeout.
斷開超時(shí):這定義了一個(gè)可靠命令必須答復(fù)的時(shí)間間隔的最大毫秒值,這是獨(dú)立于重試計(jì)數(shù)的,在DotNet中設(shè)置為DisconnectTimeoutThe settings are described in more detail in the client API documentation.這詳細(xì)的信息請(qǐng)閱覽客戶端文檔。
Setup and Config 設(shè)置與配置
This chapter explains how files and folders are organized for the Photon Server and how things are setup. Everything needed is in the deploy folder.這章解釋了在服務(wù)器上文件和文件夾是如何被組織和配置的。Content 內(nèi)容
- Organization of Server and Applications 組織服務(wù)器與應(yīng)用程序
- Configuration: PhotonServer.config 配置PhotonServer.config
- The Application Node 應(yīng)用程序節(jié)點(diǎn)
- UDPListeners and TCPListeners Nodes UDP監(jiān)聽和TCP監(jiān)聽節(jié)點(diǎn)
- TCPSilverlightListeners and TCPFlashListeners Nodes TCP的Silverlight和Flash的監(jiān)聽節(jié)點(diǎn)
- Timeout Settings 超時(shí)設(shè)置
- Send Delay and Ack Delay 發(fā)送延遲和Ack延遲
Organization of Server and Applications 組織服務(wù)器與應(yīng)用程序
There are four versions of Photon in the folders: “bin_Win32”, “bin_x64”, “bin_Win32_xp” and “bin_win64_xp”. We refer to these as binaries-folders.在文件夾中這有不同版本的Photon:“bin_Win32”, “bin_x64”, “bin_Win32_xp” and “bin_win64_xp”,我選擇需要使用的那個(gè)二進(jìn)制文件夾。Photon requires a separate folder next to the binaries-folder per application (e.g. “Lite” in the deploy folder). The assemblies must be in a “bin” subfolder (e.g. Lite/bin).Photon需要獨(dú)立的文件夾去存放應(yīng)用程序,程序集必須放在文件夾內(nèi)的Bin目錄下。The following folders in the Server SDK deploy folder are applications: Lite, LiteLobby, MMO, CounterPublisher, Policy Applications are setup in Photon’s config file, as explained below.在服務(wù)器SDk deploy 文件夾下的應(yīng)用程序有: Lite, LiteLobby, MMO, CounterPublisher, Policy Applications,被配置在Photon的配置文件中。The bin_tools folder currently contains useful tools:bin_tools文件夾中有以下可用的工具:
- Baretail: Our favorite log viewer in the free edition. It is used by PhotonControl to view the latest logs.
日志查看器
- Photon Dashboard: The service to collect and concentrate Dashboard Counters and display them on a webpage.
儀表板計(jì)數(shù)器
- Perfmon: Contains a list of PerfMon counters used when you setup counter logging to a file. This is explained under “Administration”.
性能監(jiān)視器
- Stardust: A commandline testclient that can be used to get some load on a machine. This is shown in Photon in 5 Minutes
命令行測(cè)試客戶端,可以用來測(cè)試機(jī)器的負(fù)載Configuration: PhotonServer.config 配置PhotonServer.config
The main configuration file for Photon is the PhotonServer.config. An identical copy is located in each binaries-folder in the SDK. It is used to setup applications, listeners for IPs and performance specific values. It does not contain config values for the game logic.PhotonServer.config是Photon的主配置文件,在每個(gè)二進(jìn)制文件夾中,它是用來配置應(yīng)用程序,監(jiān)聽器和性能值。他不能用來配置游戲邏輯的值。The default values make sure Photon scales nicely on more cores but does not overwhelm a regular machine. In general performance tweaks are not needed.這默認(rèn)值保證了Photon的兼容性,一般情況下性能不需要調(diào)整The following settings are most commonly used. More options are described in the “photon-configuration.pdf”, located in the Server SDK.以下是最常用的設(shè)置項(xiàng),更多的設(shè)置請(qǐng)參看“photon-configuration.pdf”,在本地服務(wù)器的SDK中。The Application Node 應(yīng)用程序節(jié)點(diǎn)
The config file defines which applications Photon should load on startup. In the “Applications” node, several “Application” entries can be added.配置文件定義了Photon將運(yùn)行哪些應(yīng)用程序,在 “Applications” 節(jié)點(diǎn)中為每個(gè)應(yīng)用程序添加一個(gè) “Application”節(jié)點(diǎn)。
<
Applications
Default
=
"Lite"
>
<!-- Lite Application -->
<
Application
Name
=
"Lite"
BaseDirectory
=
"Lite\Lite"
Assembly
=
"Lite"
Type
=
"Lite.LiteApplication"
EnableAutoRestart
=
"true"
WatchFiles
=
"dll;config"
ExcludeFiles
=
"log4net.config"
>
</
Application
>
</
Applications
>
Each application is assigned a name by which the clients reference it on connect (compare: Photon Client Workflow ).每個(gè)應(yīng)用的名字是作為客戶端連接的依據(jù)。The BaseDirectory defines the folder in which an application resides. It does not name the “\bin” folder but expects it by convention. The Assembly names the .dll of an application and “Type its “main” class (which derives from Photon.SocketServer.Application).BaseDirectory 定義了應(yīng)用程序所在的文件夾,不能命名為 “\bin”,但是要包含它。Assembly 是程序集的名稱,Type 是主類的名稱(繼承于Photon.SocketServer.Application)The setting EnableAutoRestart tells Photon to start a shadow copy of the loaded application. This allows developers to replace the files without locking issues, making development more convenient. Photon will automatically start a new instance of an application 10 seconds after files are changed. WatchFiles and ExcludeFiles refines the list of files that trigger a restart. Clients that connected to a previous shadow copy will stay in it. New connects will use the new logic.設(shè)置EnableAutoRestart 可以讓Photon加載應(yīng)用的副本。這將允許開發(fā)人員在替換文件時(shí)不用擔(dān)心文件被鎖住的問題,使的開發(fā)更加的方便。Photon將在文件更改后10秒重新啟動(dòng)一個(gè)新的應(yīng)用實(shí)例。WatchFiles 和 ExcludeFiles 在觸發(fā)重啟時(shí)改進(jìn)文件列表,連接之前副本的客戶將繼續(xù)使用舊副本,新的連接將創(chuàng)建新的游戲邏輯。To load multiple applications, simply add more application nodes (with unique name). One of them can be made the default application by using its name (“Lite” in the example). The default app is the fallback for clients that try to connect to an unknown application.加載多個(gè)應(yīng)用程序,只需加入新的application 節(jié)點(diǎn)(名字必須是唯一的)。可以通過應(yīng)用名稱來設(shè)置應(yīng)用程序?yàn)槟J(rèn)應(yīng)用。當(dāng)客戶端嘗試連接一個(gè)未知的應(yīng)用時(shí)將連接到默認(rèn)應(yīng)用程序。Applications that are not setup in the PhotonServer.config won’t be loaded and don’t need to be deployed. When an application is in the config but the files are missing Photon won’t start and name the issue in the logs.當(dāng) PhotonServer.config中的某個(gè)應(yīng)用程序文件丟失時(shí),該應(yīng)用程序?qū)⒉槐患虞d和部署,Photon服務(wù)將不會(huì)啟動(dòng),該問題將記錄在日志中。UDPListeners and TCPListeners Nodes UDP監(jiān)聽和TCP監(jiān)聽節(jié)點(diǎn)
These configure UDP and TCP endpoints on your machine respectively. You can use either (e.g. only UDP) or both.在你的機(jī)器上配置UDP和TCP的端口,你可以使用其中的一種或兩種。The default IP 0.0.0.0 makes Phonton listen on any locally available IP. By replacing the wildcard IP, Photon will open only specific IPs and ports. Multiple UDPListener and TCPListener nodes can be defined, opening several IP/port combinations.默認(rèn)IP是0.0.0.0,這使得Photon將監(jiān)聽所有的本地可用的IP。通過替換IP通配符,Photon將打開指定的IP和端口。可以定義多個(gè)UDPListener 和 TCPListener 節(jié)點(diǎn)來打開多組IP與端口組合。Per UDPListener and TCPListener node, you can setup an OverrideApplication or DefaultApplication. Override means: any client that connects to this port will end up in the application named, no matter what the client connects to. Default is a fallback, in case the application named by a client is not found.每個(gè)UDPListener 和 TCPListener 節(jié)點(diǎn),你可以設(shè)置一個(gè)OverrideApplication 或 DefaultApplication。Override 的意義是:任意連接該端口的客戶端無論它連接到什么都將在已命名的應(yīng)用中結(jié)束,Default 是備用的,用在客戶端找不到已命名的應(yīng)用程序。
<
UDPListeners
>
<
UDPListener
IPAddress
=
"0.0.0.0"
Port
=
"5055"
OverrideApplication
=
"Master"
>
</
UDPListener
>
<
UDPListener
IPAddress
=
"0.0.0.0"
Port
=
"5056"
OverrideApplication
=
"Game1"
>
</
UDPListener
>
</
UDPListeners
>
Note: If you are using a license that's bound to an IP you need to set this IP in the config.注:如果你是使用一個(gè)綁定了IP地址的許可證,你需要將這個(gè)IP地址配置到配置文件中。TCPSilverlightListeners and TCPFlashListeners Nodes TCP的Silverlight和Flash的監(jiān)聽節(jié)點(diǎn)
Could be removed but are needed when you create Silverlight or Flash games respectively. Both client-side plugins require a server to respond with a “policy file” (unless the website is on the same domain as Photon).可以移除該配置,單當(dāng)你需要?jiǎng)?chuàng)建Silverlight 或 Flash 游戲時(shí)是需要的,客戶端請(qǐng)求服務(wù)器響應(yīng)一個(gè)policy文件(除非網(wǎng)站在同一個(gè)域內(nèi))Timeout Settings 超時(shí)設(shè)置
Two values in the instance node describe how the server times out unresponsive UDP clients: MinimumTimeout and MaximumTimeout.有兩個(gè)節(jié)點(diǎn)來描述服務(wù)器超時(shí):MinimumTimeout 和 MaximumTimeout
<
Instance1
EnablePerformanceCounters
=
"true"
DataSendingDelayMilliseconds
=
"50"
AckSendingDelayMilliseconds
=
"50"
MinimumTimeout
=
"5000"
MaximumTimeout="30000”>
A peer connected with UDP has MinimumTimeout milliseconds to respond before it can be disconnected. The actual time until disconnect, is determined dynamically per peer based on the RTT history. Previously good RTTs will disconnect faster.在連接斷開之前UDP通信有MinimumTimeout 的時(shí)間用于響應(yīng),斷開的實(shí)際時(shí)間是動(dòng)態(tài)的基于RTT歷史的。TCP connections have a separate InactivityTimeout setting in the nodes TCPListener and TCPPolicyListener (also in the PhotonServer.config). We set those to 5 seconds (5000ms). If no request arrives in this time, the connection will be timed out and closed. Clients will also regularly Ping the server, to avoid this. Clients don’t timeout for TCP.TCP連接有一個(gè)獨(dú)立的配置項(xiàng)InactivityTimeout 在TCPListener 和 TCPPolicyListener 節(jié)點(diǎn),我設(shè)置為5000ms,如果請(qǐng)求沒有在這個(gè)時(shí)間間隔內(nèi)到達(dá),連接將會(huì)超時(shí)并關(guān)閉。客戶端將定期Ping服務(wù)器以避免這樣的超時(shí)。Keep in mind that a client independently monitors a connection and might time it out as well. Both sides should have similar timeouts, fitting your game.保持客戶端獨(dú)立的監(jiān)控連接和時(shí)間,使雙方將有相似的超時(shí),以適應(yīng)你的游戲Send Delay and Ack Delay 發(fā)送延遲和Ack延遲
The attributes DataSendingDelayMilliseconds and AckSendingDelayMilliseconds represent a tradeoff between performance and minimal response times. This delay directly adds some lag to reduce the bandwidth usage: the wait allows the server to aggregate commands and send them in one package. The send delay is triggered when the server sends anything, the ack delay by incoming reliable data.屬性DataSendingDelayMilliseconds 和 AckSendingDelayMilliseconds 代表了性能與最小響應(yīng)時(shí)間之間的權(quán)衡。這延遲減小了帶寬流量的使用:這等待允許服務(wù)器識(shí)別命令并用一個(gè)數(shù)據(jù)包發(fā)送他們。當(dāng)服務(wù)器進(jìn)行發(fā)送時(shí)將觸發(fā)這個(gè)發(fā)送延遲,ack延遲是通過傳入可靠的數(shù)據(jù)。As you can see above, the default values are 50ms each. We found this to be a good value but it causes a \~50ms roundtrip time, even if client and server run on the same machine.正如你所看到的,這默認(rèn)值是50ms。我們發(fā)現(xiàn)它是一個(gè)很好的設(shè)置,在50ms內(nèi)進(jìn)行一次往返,即使當(dāng)客戶端和服務(wù)器在同一臺(tái)機(jī)器上也是如此。Depending on your game, you should load test with different values. A delay of 0 is a special case that skips usage of timers, so avoid low delays < 10.你可以根據(jù)你的游戲,加載測(cè)試不同的值。0ms是一個(gè)特殊值用于跳過延遲,盡量避免延遲小于10ms
Photon Control Photon控制器
Photon Control is your one-stop, control UI for Photon. Starting PhotonControl.exe doesn’t open a window, doesn’t start the server but adds an icon to the tray bar.A gray icon shows that Photon is not running. When any Photon Server is process running, the icon turns blue.Photon Control是一個(gè)針對(duì)Photon的一站式的可視化的控制軟件,打開PhotonControl.exe不會(huì)出現(xiàn)windows窗口,不會(huì)啟動(dòng)服務(wù),但會(huì)增加一個(gè)系統(tǒng)托盤,灰色的圖標(biāo)表示Photon不在運(yùn)行,而藍(lán)色的圖標(biāo)表示Photon正在運(yùn)行。Content 內(nèi)容
- Overview 概述
- Running Photon 運(yùn)行Photon
- Moving Photon 移動(dòng)Photon
- Changing the “LoadBalancing IP Config” Path 改變“LoadBalancing IP Config”的路徑
- Logs 日志
- Counters 計(jì)數(shù)器
- PerfMon Counters 性能監(jiān)視器
- Dashboard Counters 儀表板計(jì)數(shù)器
- Dashboard 儀表板
- Troubleshooting 故障診斷
- Dump File Setup 轉(zhuǎn)儲(chǔ)文件設(shè)置
Overview 概述
Click the icon to open the menu. It allows you to:點(diǎn)擊系統(tǒng)托盤去打開菜單:
- Start and stop Photon.
啟動(dòng)和停止Photon
- Install, start and stop Photon services.
初始化,啟動(dòng),停止 Photon服務(wù)
- Change the game server config for LoadBalancing (MyCloud).
改變游戲服務(wù)器為LoadBalancing(MyCloud)
- Setup and open Photon’s Performance Monitor (PerfMon) Counters.
設(shè)置并打開Photon的性能監(jiān)視器
- Open the log files.
打開日志文件
- Open working path in Explorer.
在資源管理器中打開工作路徑
- Verify you are using the latest version of Photon.
檢查更新Admin rights are required when you start Photon Control. This allows us to make an entry in the Windows Firewall and most importantly you can now add or remove services for Photon.On start, Photon Control reads your license to let you verify how long it is valid and checks if you use the latest version of Photon, shown in the “Photon Control” menu.The “Autostart Photon Control” option starts Photon Control when you login to Windows. This can be handy when you access a remote machine and can use “Explore Working Path” to spot Photon’s files.If the icon is not visible, click the tiny triangle and drag and drop the Photon Control icon from the popup back to the tray.需要管理員權(quán)限才能啟動(dòng)Photon Control,配置防火墻使Photon服務(wù)可用。當(dāng)Photon Control啟動(dòng)時(shí)會(huì)讀取許可證來設(shè)置Photon的版本,顯示在Photon Control的菜單上,設(shè)置“Autostart Photon Control” 選項(xiàng)可以在登錄系統(tǒng)時(shí)自動(dòng)啟動(dòng)Photon Control。這是非常方便的去遠(yuǎn)程訪問一個(gè)機(jī)器,并且可以通過 “Explore Working Path”找到Photon的文件,如果圖標(biāo)不可見,點(diǎn)擊小三角拖放該圖標(biāo)到托盤上。
Running Photon 運(yùn)行Photon
By default, two separate Photon configurations (also called “Instances”) are available. Each starts a combination of server applications and used ports. The “Default” instance is running Lite, LiteLobby, MMO and the Policy Application. Starting instance “LoadBalancing (MyCloud)” will run a Master Server and two Game Servers, which is a minimum Photon Cloud compatible setup.默認(rèn)情況下,有兩種獨(dú)立的Photon配置是可用的,每個(gè)可以啟動(dòng)一個(gè)服務(wù)器應(yīng)用程序和使用所需的端口,Default實(shí)例運(yùn)行的是Lite、 LiteLobby、MMO 和 Policy Application。LoadBalancing (MyCloud) 實(shí)例運(yùn)行的是一個(gè)主服務(wù)器和兩個(gè)游戲服務(wù)器,這是一個(gè)最小的 Photon Cloud 兼容設(shè)置。On a public server, Photon should run as service. This requires three steps in Photon Control:在一個(gè)公共服務(wù)器上,Photon作為服務(wù)運(yùn)行,需要以下三個(gè)步驟:
- Install the Photon service
初始化Photon服務(wù)
- Install the PerfMon Counters (they might prove useful)
初始化性能監(jiān)視器
- Start Photon as service
啟動(dòng)Photon作為服務(wù)The PerfMon Counters are not exactly a requirement to run but they can’t be enabled while Photon is running, so it makes sense to set them up first.Running Photon as application is an alternative for local development. When you log off, Photon will be shut down.PerfMon Counters不是服務(wù)運(yùn)行的必須條件,但是當(dāng)Photon正在運(yùn)行的時(shí)候他們不能被啟用,所以要一開始就設(shè)置它,運(yùn)行Photon為應(yīng)用程序是本地開發(fā)的一種選擇,當(dāng)你注銷時(shí),Photon就會(huì)被關(guān)閉。Moving Photon 移動(dòng)Photon
Before you move Photon from one folder to another, you should make sure to remove all services and also Photon Control autostart. Install again at the new location.在你移動(dòng)Photon從一個(gè)文件夾到另一個(gè)之前,你需要確認(rèn)移除所有的服務(wù),并且Photon Control是自動(dòng)啟動(dòng)的,然后在新的地方再次初始化。Changing the “LoadBalancing IP Config” Path 更改“LoadBalancing IP Config” 的路徑
While Photon Control can’t be modified extensively, some important settings can be found in PhotonControl.exe.config. The “GameServerConfigPaths” setting is the one you might need when your project is based off LoadBalancing but renamed.The GameServerConfigPaths is a list of ‘;’-separated paths, relative to the folder of PhotonControl.exe.Photon Control不能被廣泛的修改,一些重要的設(shè)置可以在PhotonControl.exe.config里找到。當(dāng)你的項(xiàng)目是基于LoadBalancing,但不是重命名的,“GameServerConfigPaths” 設(shè)置項(xiàng)可能是你需要的,GameServerConfigPaths 是一個(gè)以 ‘;’間隔的地址路徑列表,路徑相對(duì)于PhotonControl.exe所在的文件夾。Logs 日志Photon is logging essential information (state, exceptions, etc.) to several log files. Click on “Open Logs” to show all logs that Photon used in the past 12 hours. You can open more files as needed, of course.Photon會(huì)記錄一些必要的信息到服務(wù)器的日志文件中。點(diǎn)擊 “Open Logs” 可以看到所有過去12小時(shí)內(nèi)的日志,當(dāng)然,需要的話你可以打開更多的文件。There are two “log” folders:以下是2個(gè)日志文件夾:
- All application logs are in the deploy/log folder. Anything that is logged by your business logic goes into a fitting file in deploy/log.
所有應(yīng)用程序的日志是在deploy/log folder。任何的業(yè)務(wù)邏輯的記錄都會(huì)填充到這個(gè)文件夾下的一個(gè)文件中。
- The server core’s log folder is where your running executable is (e.g. bin_win32/log). They contain anything instance and CLR (dotnet runtime) related.
服務(wù)器的核心日志文件夾在你運(yùn)行的二進(jìn)制目錄之下的log文件夾內(nèi),其中包含了所有相關(guān)的實(shí)例和CLRWe use Log4Net in the logic layer. It can be configured extensively and proved very useful. Learn more about Log4Net here .我們可以在邏輯層內(nèi)使用Log4Net。它可以進(jìn)行廣泛的配置并已證明它是非常的有用。Counters 計(jì)數(shù)器
Photon keeps track of several essential values as support for performance- and error-analysis. These are published in two separate sets of Counters: “PerfMon Counters” and “Dashboard Counters”.Photon持續(xù)跟蹤一些基本的值用作性能和錯(cuò)誤分析。以下是兩個(gè)已公布的獨(dú)立的計(jì)數(shù)器:“PerfMon Counters” 和 “Dashboard Counters”。PerfMon Counters 性能監(jiān)視器
The PerfMon Counters are key values from the Photon Core. They track values like connected peers, package count, reliable UDP usage, bandwidth and much more. These Counters cannot be changed by the developer and are accessed by PerfMon. PerfMon is a GUI to create those performance graphs and is already installed with Windows.If PerfMon Counters should be logged over a longer time (and without running the GUI), Photon Control can setup and start logging to a file. Under “PerfMon Counters”, click “Create Logging Set” and “Start Logging”. The logs should end up under C:\PerfLogs\Admin\photon_perf_log_<date>.blgPerfMon Counters的值來自Photon Core。他們跟蹤一些值,例如連接用戶,包計(jì)數(shù),可靠UDP的使用,帶寬流量。這些計(jì)數(shù)器不能通過開發(fā)和訪問PerfMon而被改變。PerfMon 是一個(gè)已經(jīng)安裝在windows上的圖形化的工具用來創(chuàng)建一些性能圖形。如果在一個(gè)較長的時(shí)間范圍內(nèi)PerfMon計(jì)數(shù)器被記錄,Photon Control可能會(huì)設(shè)置和記錄信息到文件里。 在“PerfMon Counters”里可以點(diǎn)擊“Create Logging Set” 和“Start Logging”進(jìn)行配置。日志放置在C:\PerfLogs\Admin\photon_perf_log_<date>.blg。Dashboard Counters 儀表板計(jì)數(shù)器
The Dashboard Counters track values within the business logic and can be extended as needed.儀表板計(jì)數(shù)器是在業(yè)務(wù)邏輯中跟蹤數(shù)值的。Dashboard 儀表板
The Dashboard aggregates counter values and generates graphs for a website to monitor them.The Dashboard itself can be installed as service while Photon is already running. Which Counter Data an application publishes (if at all), depends on the application’s setup. Lite has several pre-defined Counters ready to use.儀表板收集計(jì)數(shù)器的值,并且在Web上生成圖形用于監(jiān)控它們。當(dāng)Photon運(yùn)行的時(shí)候儀表板可以作為服務(wù)進(jìn)行初始化。應(yīng)用程序的計(jì)數(shù)器數(shù)據(jù)的發(fā)布取決于應(yīng)用程序里的定義。Lite里包含有多個(gè)預(yù)定義的計(jì)數(shù)器可以使用。Troubleshooting 故障診斷
If Photon does not behave as expected, always have a look at the logs.如果Photon不是像預(yù)期的那樣,可以看一下日志。These are the most common pitfalls you should check as well.以下是最常見的錯(cuò)誤,你需要檢查一下
- Missing DotNet 3.5: In this case, Photon can’t start. Don’t mix this up with the CLR Version. The 2.0 CLR version is also used by DotNet 3.5.
缺少DotNet運(yùn)行環(huán)境
- Application missing: If Photon does not find one of the configured applications, it can’t start. Check the configuration against deployed folders.
缺少已配置的應(yīng)用程序文件
- Build not up to date: Switching to a new server SDK, you should always re-build your applications, referencing the assemblies from the libs folder. Otherwise they might be incompatible.
應(yīng)用引用的SDK版本與服務(wù)器不一致。
- Firewall: If Photon is running but not accessible from another machine, check the Firewalls. Newer Windows versions have roles and rights and your hoster most likely used hardware firewalls.
防火墻阻止了
- Lag: By default, the roundtrip time is about 50ms, even locally. This depends on a setting, explained on the setup page. Read: Send Delay and Ack Delay
延遲超過設(shè)置的值,默認(rèn)為50msDump File Setup 轉(zhuǎn)儲(chǔ)文件設(shè)置
If a server crashes and the reason for it is not found in the logs, Photon can be configured to create dump files. These reflect the state and memory of the crash and are invaluable to debug these cases.To enable the feature, you need to edit your PhotonServer.config. Set the instance-attribute “ProduceDumps” to true and restart the server.如果服務(wù)器崩潰了,日志中未能找到相關(guān)信息。Photon可以配置為轉(zhuǎn)儲(chǔ)文件。那些反應(yīng)了狀態(tài)和內(nèi)存的信息是在調(diào)試中非常有用的。啟用這個(gè)特性,你需要去編輯PhotonServer.config。設(shè)置“ProduceDumps”為True,并重啟服務(wù)器。It might look like this example:以下是一個(gè)例子:
<
Default
EnablePerformanceCounters
=
"true"
DataSendingDelayMilliseconds
=
"50"
AckSendingDelayMilliseconds
=
"50"
MinimumTimeout
=
"5000"
MaximumTimeout
=
"30000"
ProduceDumps
=
"true"
>
This will write up to 10 “full” dump files. Once a dump file is written, you can zip it with the logs and mail it to us with a description of the issue. In most cases, we will get in touch with you to get more information and solve the case.這將寫入完整的轉(zhuǎn)儲(chǔ)文件。一旦轉(zhuǎn)儲(chǔ)文件被寫入,你就可以壓縮它發(fā)送郵件給我們,在大多數(shù)情況下,我們會(huì)為你解答。![]()
只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。 【推薦】100%開源!大型工業(yè)跨平臺(tái)軟件C++源碼提供,建模,組態(tài)!![]()
相關(guān)文章:
- Photon 翻譯系列 —— M守護(hù)神
- Unity3d Photon官方MMO文檔
- Photon Server文檔翻譯
- Photon——緩存事件及調(diào)用操作
- Photon——主從服務(wù)器負(fù)載均衡及策略
- Photon——聊天室
- Photon——Hello World
- Photon——引擎介紹及相關(guān)準(zhǔn)備工作
網(wǎng)站導(dǎo)航: 博客園 IT新聞 BlogJava 博問 Chat2DB 管理