Fork me on GitHub
随笔 - 215  文章 - 13  trackbacks - 0
<2018年12月>
2526272829301
2345678
9101112131415
16171819202122
23242526272829
303112345


专注即时通讯及网游服务端编程
------------------------------------
Openresty 官方模块
Openresty 标准模块(Opm)
Openresty 三方模块
------------------------------------
本博收藏大部分文章为转载,并在文章开头给出了原文出处,如有再转,敬请保留相关信息,这是大家对原创作者劳动成果的自觉尊重!!如为您带来不便,请于本博下留言,谢谢配合。

常用链接

留言簿(1)

随笔分类

随笔档案

相册

Awesome

Blog

Book

GitHub

Link

搜索

  •  

积分与排名

  • 积分 - 211162
  • 排名 - 118

最新评论

阅读排行榜

Base Applications 基本应用程序

 
     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服务器SDk包含的内置应用程序,可以作为你的应用的开始点。
 

   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 是一个最常引用的应用,它实现了一个多玩家一起竞赛的房间游戏的基本框架,通过名称确定每个房间,一个房间就是一个游戏,任何人都可以不受限制的加入或离开,在房间内任何客户端都可以触发事件去发送数据给别人,可以为房间和玩家设置属性来确保进入的玩家有准确可用的值
 
     Games, which don’t need an authoritative server, can be built on top of Lite without modifications.
     所有游戏,不需要一个权威的服务器,可以建立在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.
     这个应用可以容易的扩展服务器端的逻辑,根据你的游戏需求匹配一组玩家到房间里

Read more: Lite Concepts

   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是一个在Lite之上建立并扩展功能的例子,它添加了新的房间类型:大厅。这里不会发送加入或离开事件,只是当前可用的房间名称列表。玩家可以很容易的选择正在进行的游戏,房间中玩家的数量是可供增加的
 
     This application adds “manual matchmaking” to Lite and could also be a basis for your game.
     这个应用增加了手动匹配
 
Read more: Lite Lobby Concepts
     
     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样例程序是一个为玩家们分享一个大型世界的游戏解决方案,它提供了兴趣管理和最常见的类型,比如物品、玩家、属性等等
 
     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.
     这游戏是一个在服务端包含了更多的游戏逻辑的分享的世界,这个应用被认为是一个合理的开始点

Read more: MMO

   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应用运行在Photon上用于发送crossdomain.xml到web player平台。Flash 和 Silverlight在连接一个服务器之前需要请求一个授权
 
     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.
     这个应用读取本地的PerfMon计数器到Dashboard。它不会影响其他应用程序,客户端也不要去连接它

Basic Concepts 基本概念

 
     The following article will show you the important basic concepts for Photon.
     以下是要告诉你的Photon重要基本概念
 

     Applications 应用程序

     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.
     一个应用既是一个服务端的游戏逻辑,一个游戏的所有特征是在Photon应用中被实现的。由C#编写的源码被编译成程序集并加载到Photons native core。部署应用并且在Photon配置文件中定义参数。
 
     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.
     通常,一个游戏的所有逻辑是由一个应用程序提供的,Photon 是可以同时运行多个应用程序,每个应用程序可以有不同的任务。比如,一个独立的应用程序可以被用于为基于Web的客户端发送policy文件,通过运行一个独立的Policy应用程序为你的游戏逻辑添加功能
     
     A client chooses the application it wants to use by simply providing the application’s name on connect.
     一个客户端在连接的时候需要使用应用的名字去选择应用程序

     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.
     游戏逻辑定义了客户端如何与服务器进行交互。它实现了操作、事件和其他服务器想做的事情
 
     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是一个很好的基于房间的游戏基础应用,src-server/Lite中可以找到它,它不知道你的游戏逻辑,但是提供了房间,玩家可以轻松的进行交流与互动。Lite Lobby扩展了Lite,提供了房间列表,以便于用户可以手动选择房间
 
     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.
     如果你的游戏是一个独立的巨大的世界,那MMO是一个很好的基础应用,这个应用为你的客户端提供了兴趣管理和一些类型,例如商品、属性、玩家等等。
     
     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之上进行开发,这程序的入口必须定义在Photon.Socketserver.dll

     Operations 操作

     An operation is Photon’s equivalent to a remote procedure call. Photon clients use operation calls for anything they want to get done.
     一个操作相当于是一次远程过程调用(RPC)。Photon客户端使用操作调用进行他们想要做的事情
 
     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.
     操作和属性是被定义在服务端的应用程序中的。客户端可以调用任意操作,只要通过设置一个hashtable 的键和值来制定该操作的合约即可,客户端和服务端的frameworks负责序列化、传递和反序列化
     
     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.
     每个操作也可以提供一个结果。这是一个提供给客户端请求数据的方法,当然结果是可以被跳过的,跳过可以节省带宽流量
 
     Operation calls and results are a thing between one client and the server. The other clients won’t know about these.
     操作的调用和结果是一个客户端和服务器之间发生的,其他客户端是无法得知。

     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事件是对客户端的消息,每个事件的类型是一个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.
     不像操作结果,一个接受到的事件最有可能触发其他客户端的操作调用,这意味着,事件可能随时发生,Lite应用中当某个玩家加入和离开房间时会发送事件
 
     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.
     这个RaiseEvent操作使得事件真正的通用:任意客户端可以创建一个装有数据和应用代码的hashtable的新的事件进行发送,游戏数据可以被发送无需去改变服务器
 
     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.
     当然,对于更为复杂的服务器端事件的反应,通用操作可以被定义为检查、编译事件数据或创建其他事件

     Connections and Timeouts 连接与超时

     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.
     不像常规的UDP,Photon使用的是可靠的UDP协议建立客户端与服务端的连接:命令在一个UDP包中,其中包含序列化的数字和一个可靠性标志,这样接收端才能识别这个命令,可靠的命令是在很短的时间间隔内重复直到被确认,如果不被确认到,则连接超时
 
     Both sides monitor this connection independently from their perspective. Both sides have their rules to decide if the other is still available.
     两端监控连接都是独立的,两端还可以定义自己的规则
 
     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.
     如果一个超时被检测到,就会断开连接,这时我们认为另一边未响应,没有信息可以发送给它,这就是为什么超时断开是发生在一侧并且是不同步的

Product Overview 产品概述

 
     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支持多样的平台,使用C,C#,Flash进行编程的方式是不同的,但是基本的工作流是相似的。在这文档中我们尝试去解释它的概念和背景,而语言的细节部分需要查阅每个语言平台的参考文档。
 
     Each Photon Client SDK comes with a fitting reference documentation for its platform and language.
     每一个客户端SDk都带有相关平台的参考文档。

     Project Setup 项目设置

 
     You need to include a single library to communicate with Photon on the client-side. This is a different setup per platform.
     在客户端你需要包含一个独立的library ,每个平台的设置是不同的。
  • 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;
     在项目中引用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;
     你需要导入PhotonUnity3D.dll到项目中,打开Unity 的project/scene,打开资源管理器从<sdk>\libs\debug\ 拖放PhotonUnity3D.dll到editor,导入命名空间using ExitGames.Client.Photon;
 

     Workflow 工作流

 
     The simplified lifecycle for any multiplayer game looks like this:
     多人游戏的简化生命周期如下:
 
  • Connect to server
          连接服务器
  • Make RPC calls
          RPC调用
  • Receive something
          接收数据
  • Disconnect
          断开连接
 
     Pretty simple. Let’s have a look at each step, assuming you use C# and the Lite Application .
     很简单,让我们来看看每一个步骤,以Lite为例。
 
  • Connect to server 连接服务器
 
     Actually, you do a little more than just connect in this step. In short:
     事实上,你做的不只是连接而已:
 
  • Implement the interface IPhotonPeerListener in one of your classes
          在你的类中实现接口IPhotonPeerListener
  • Create a LitePeer instance with your server’s address
          创建LitePeer 实例和你服务器的地址
  • In your game loop, call Service about 10 times a second
          在你的游戏循环中大约10秒调用一次服务
  • Now call Connect to establish the connection. The application name should match one in the PhotonServer.config
          现在建立连接,这应用程序的名字要与PhotonServer.config中的匹配
  • Your implementation if PeerStatusCallback is called when the connection is ready or failed
          你要实现的是当连接是未连接的时候调用PeerStatusCallback 
  • The returned status be StatusCode.Connect
          返回的状态是StatusCode.Connect
 
     The 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 alive
     peer 实例提供了一些方法去访问Photon,它没有自己的线程,当你调用服务时它进行更新,并保持着连接
 
     We assume that Photon is running the “Lite” Application, which it does by default.
     我们假设Photon运行着Lite,以下是默认情况。
 
  • Make RPC calls RPC调用
 
     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.
     连接后,客户端可以再任何时候去调用Lite应用的方法,这样的远程过程调用被称为操作
 
     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.
     操作调用是异步的,并且不会阻碍你的游戏。他们是在内部排队的直到你需要发送他们的时候通过SendOutgoingCommands发送。收到结果只需要很短暂的延迟时间,这些结果是被定义为操作并且不是所有的时间都被使用的。
 
  • Call OpJoin with any room name to get into a game
          调用OpJoin 可以加入游戏
  • Wait for the callback: OperationResult with opCode: LiteOpCode.Join
          等待回调带有 opCodeLiteOpCode.Join 的 OperationResult 
  • Send any hashtable with content by calling OpRaiseEvent. Other players in the room will receive events.
          通过调用OpRaiseEvent发送带有内容的hashtable ,其他这个房间的玩家也将收到相关的事件信息。
 
     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.
     这是一个按照Lite应用的逻辑加入房间并触发事件的例子,你可以使用其他的应用并且实现你自己的操作
 
  • Receive something 接收数据
 
     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.
     在前面的步骤,你已经接收到了操作的结果,我区别于来自其他地方的信息,所以称之为事件,Lite将发送这事件触发到房间中的其他人。
 
     Receiving events will call IPhotonPeerListener.EventAction. The evCode will match the one you used in OpRaiseEvent
     调用IPhotonPeerListener.EventAction接收事件,evCode 将与你使用的OpRaiseEvent进行匹配
 
     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.
     这客户端将接收到的数据包进行内部排队,由你的游戏决定何时使用它们,通过调用PhotonPeer.Service来调用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.
     当客户端是关闭的时候,最好是断开连接,但不是作为超时断开。
 
  • To close the connection: call Disconnect
          关闭连接:调用Disconnect
  • Check “disconnect” return in PeerStatusCallback with statusCode: StatusCode.Disconnect
          检查 “disconnect” ,PeerStatusCallback 的返回值为statusCodeStatusCode.Disconnect
  • Now the client can stop calling service
          现在客户端可以停止调用服务了

     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,客户端还包含了一个PhotonPeer 可以使用,PhotonPeer 对于Photon只有有限的API,它是LitePeer的基础,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客户端和服务器通过UDP发送操作和事件的,这保证了低开销、灵活性和性能但是被定义为不可靠的。
 
     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 使用了一个精简的二进制协议来进行聚合、排序、检测数据包丢失,它是基于eNet的被用于服务器和客户端
 
     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”是用于传递这负载的,例如操作。在客户端,由Photon控制命令以UDP包的形式进行发送
 
     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还包括管理连接服务器的方法,基本上,他们是由两个层组成:“command layer” 和 “operation layer”
  • Command layer: manages the communication protocol to establish and maintain communication.
          命令层:管理通信协议建立连接并保持通信
  • Operation layer: gives access to rooms, events and custom Operations. Client side, methods of this layer are prefixed with “Op”.
          操作层:用于访问房间、事件、自定义操作。在客户端,这层的方法被加上了前缀 “Op”

     Reliable vs. Unreliable 可靠对不可靠

 
     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的底层协议,可以被标记为可靠或不可靠,仅仅在命令被使用的时候操作请求是不可更改的。
 
     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 保持跟踪,不可靠的命令是随着可靠的命令进行同步测序,所以一个不可靠的命令,被发送在一个可靠的命令之后,也将在可靠命令被分派之后再进行分派。
 
     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.
     操作和事件发送是不可能丢失的,举例,对于位置的更新这不是问题,更新很快就被替换了,在服务端,接收到的不可靠的操作不会创建这样一个结果:客户端不会期望这操作到达服务器。

     Connection and Timeout 连接与超时

 
     The client has two rules to define a timeout:
     这客户端有两种规则去定义超时:
 
  • 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.
          重试:一个可靠的命令将会被发送多次以用作确认,每次重试的时间间隔变长,根据统一的区域时间定义,如果重试次数达到一个极限,将会断开连接。
  • 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.
          断开超时:这定义了一个可靠命令必须答复的时间间隔的最大毫秒值,这是独立于重试计数的,在DotNet中设置为DisconnectTimeout
 
     The settings are described in more detail in the client API documentation.
     这详细的信息请阅览客户端文档。

Setup and Config 设置与配置

 
     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.
     这章解释了在服务器上文件和文件夹是如何被组织和配置的。
 

     Content 内容

     Organization of Server and Applications 组织服务器与应用程序

 
     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”,我选择需要使用的那个二进制文件夹。
 
     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需要独立的文件夹去存放应用程序,程序集必须放在文件夹内的Bin目录下。
 
Photon Server Screenshot: Folder structure
 
     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.
     在服务器SDk deploy 文件夹下的应用程序有: 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.
          仪表板计数器
  • Perfmon: Contains a list of PerfMon counters used when you setup counter logging to a file. This is explained under “Administration”.
          性能监视器
  • Stardust: A commandline testclient that can be used to get some load on a machine. This is shown in Photon in 5 Minutes
          命令行测试客户端,可以用来测试机器的负载

     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的主配置文件,在每个二进制文件夹中,它是用来配置应用程序,监听器和性能值。他不能用来配置游戏逻辑的值。
 
     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.
     这默认值保证了Photon的兼容性,一般情况下性能不需要调整
 
     The following settings are most commonly used. More options are described in the “photon-configuration.pdf”, located in the Server SDK.
     以下是最常用的设置项,更多的设置请参看“photon-configuration.pdf”,在本地服务器的SDK中。

     The Application Node 应用程序节点

     The config file defines which applications Photon should load on startup. In the “Applications” node, several “Application” entries can be added.
     配置文件定义了Photon将运行哪些应用程序,在 “Applications” 节点中为每个应用程序添加一个 “Application”节点。
 
 
<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 ).
     每个应用的名字是作为客户端连接的依据。
 
     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 定义了应用程序所在的文件夹,不能命名为 “\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.
     设置EnableAutoRestart 可以让Photon加载应用的副本。这将允许开发人员在替换文件时不用担心文件被锁住的问题,使的开发更加的方便。Photon将在文件更改后10秒重新启动一个新的应用实例。WatchFiles 和 ExcludeFiles 在触发重启时改进文件列表,连接之前副本的客户将继续使用旧副本,新的连接将创建新的游戏逻辑。
 
     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.
     加载多个应用程序,只需加入新的application 节点(名字必须是唯一的)。可以通过应用名称来设置应用程序为默认应用。当客户端尝试连接一个未知的应用时将连接到默认应用程序。
 
     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.
     当 PhotonServer.config中的某个应用程序文件丢失时,该应用程序将不被加载和部署,Photon服务将不会启动,该问题将记录在日志中。

     UDPListeners and TCPListeners Nodes  UDP监听和TCP监听节点

 
     These configure UDP and TCP endpoints on your machine respectively. You can use either (e.g. only UDP) or both.
     在你的机器上配置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.
     默认IP是0.0.0.0,这使得Photon将监听所有的本地可用的IP。通过替换IP通配符,Photon将打开指定的IP和端口。可以定义多个UDPListener 和 TCPListener 节点来打开多组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.
     每个UDPListener 和 TCPListener 节点,你可以设置一个OverrideApplication 或 DefaultApplication。Override 的意义是:任意连接该端口的客户端无论它连接到什么都将在已命名的应用中结束,Default 是备用的,用在客户端找不到已命名的应用程序。
 
 
<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.
     注:如果你是使用一个绑定了IP地址的许可证,你需要将这个IP地址配置到配置文件中。

     TCPSilverlightListeners and TCPFlashListeners Nodes  TCP的Silverlight和Flash的监听节点

 
     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).
     可以移除该配置,单当你需要创建Silverlight 或 Flash 游戏时是需要的,客户端请求服务器响应一个policy文件(除非网站在同一个域内)

     Timeout Settings 超时设置

 
     Two values in the instance node describe how the server times out unresponsive UDP clients: MinimumTimeout and MaximumTimeout.
     有两个节点来描述服务器超时: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 的时间用于响应,断开的实际时间是动态的基于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连接有一个独立的配置项InactivityTimeout 在TCPListener 和 TCPPolicyListener 节点,我设置为5000ms,如果请求没有在这个时间间隔内到达,连接将会超时并关闭。客户端将定期Ping服务器以避免这样的超时。
 
     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.
     保持客户端独立的监控连接和时间,使双方将有相似的超时,以适应你的游戏
 

     Send Delay and Ack Delay 发送延迟和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 代表了性能与最小响应时间之间的权衡。这延迟减小了带宽流量的使用:这等待允许服务器识别命令并用一个数据包发送他们。当服务器进行发送时将触发这个发送延迟,ack延迟是通过传入可靠的数据。
 
     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.
     正如你所看到的,这默认值是50ms。我们发现它是一个很好的设置,在50ms内进行一次往返,即使当客户端和服务器在同一台机器上也是如此。
 
     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.
     你可以根据你的游戏,加载测试不同的值。0ms是一个特殊值用于跳过延迟,尽量避免延迟小于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是一个针对Photon的一站式的可视化的控制软件,打开PhotonControl.exe不会出现windows窗口,不会启动服务,但会增加一个系统托盘,灰色的图标表示Photon不在运行,而蓝色的图标表示Photon正在运行。
 

     Content 内容

     Overview 概述

Photon Server: Photon Control

     Click the icon to open the menu. It allows you to:
     点击系统托盘去打开菜单:
  • Start and stop Photon.
          启动和停止Photon
  • Install, start and stop Photon services.
          初始化,启动,停止 Photon服务
  • Change the game server config for LoadBalancing (MyCloud).
          改变游戏服务器为LoadBalancing(MyCloud)
  • Setup and open Photon’s Performance Monitor (PerfMon) Counters.
          设置并打开Photon的性能监视器
  • 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.
     需要管理员权限才能启动Photon Control,配置防火墙使Photon服务可用。当Photon Control启动时会读取许可证来设置Photon的版本,显示在Photon Control的菜单上,设置“Autostart Photon Control” 选项可以在登录系统时自动启动Photon Control。这是非常方便的去远程访问一个机器,并且可以通过 “Explore Working Path”找到Photon的文件,如果图标不可见,点击小三角拖放该图标到托盘上。
     

Photon Server: Photon Control

     Running Photon 运行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.
     默认情况下,有两种独立的Photon配置是可用的,每个可以启动一个服务器应用程序和使用所需的端口,Default实例运行的是Lite、 LiteLobby、MMO 和 Policy Application。LoadBalancing (MyCloud) 实例运行的是一个主服务器和两个游戏服务器,这是一个最小的 Photon Cloud 兼容设置。
 
     On a public server, Photon should run as service. This requires three steps in Photon Control:
     在一个公共服务器上,Photon作为服务运行,需要以下三个步骤:
 
  • Install the Photon service
          初始化Photon服务
  • Install the PerfMon Counters (they might prove useful)
          初始化性能监视器
  • Start Photon as service
          启动Photon作为服务
Photon Server: Photon Control running Photon
 
     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不是服务运行的必须条件,但是当Photon正在运行的时候他们不能被启用,所以要一开始就设置它,运行Photon为应用程序是本地开发的一种选择,当你注销时,Photon就会被关闭。

     Moving Photon 移动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.
     在你移动Photon从一个文件夹到另一个之前,你需要确认移除所有的服务,并且Photon Control是自动启动的,然后在新的地方再次初始化。

     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不能被广泛的修改,一些重要的设置可以在PhotonControl.exe.config里找到。当你的项目是基于LoadBalancing,但不是重命名的,“GameServerConfigPaths” 设置项可能是你需要的,GameServerConfigPaths 是一个以 ‘;’间隔的地址路径列表,路径相对于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会记录一些必要的信息到服务器的日志文件中。点击 “Open Logs” 可以看到所有过去12小时内的日志,当然,需要的话你可以打开更多的文件。
 
     There are two “log” folders:
     以下是2个日志文件夹:
 
  • 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.
          所有应用程序的日志是在deploy/log folder。任何的业务逻辑的记录都会填充到这个文件夹下的一个文件中。
  • 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.
          服务器的核心日志文件夹在你运行的二进制目录之下的log文件夹内,其中包含了所有相关的实例和CLR
 
          We use Log4Net in the logic layer. It can be configured extensively and proved very useful. Learn more about Log4Net here .
          我们可以在逻辑层内使用Log4Net。它可以进行广泛的配置并已证明它是非常的有用。 

     Counters 计数器

     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持续跟踪一些基本的值用作性能和错误分析。以下是两个已公布的独立的计数器:“PerfMon Counters” 和 “Dashboard Counters”。

     PerfMon Counters 性能监视器

     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>.blg
     PerfMon Counters的值来自Photon Core。他们跟踪一些值,例如连接用户,包计数,可靠UDP的使用,带宽流量。这些计数器不能通过开发和访问PerfMon而被改变。PerfMon 是一个已经安装在windows上的图形化的工具用来创建一些性能图形。如果在一个较长的时间范围内PerfMon计数器被记录,Photon Control可能会设置和记录信息到文件里。 在“PerfMon Counters”里可以点击“Create Logging Set” 和“Start Logging”进行配置。日志放置在C:\PerfLogs\Admin\photon_perf_log_<date>.blg。

     Dashboard Counters 仪表板计数器

     The Dashboard Counters track values within the business logic and can be extended as needed.
     仪表板计数器是在业务逻辑中跟踪数值的。
 

     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.
     仪表板收集计数器的值,并且在Web上生成图形用于监控它们。当Photon运行的时候仪表板可以作为服务进行初始化。应用程序的计数器数据的发布取决于应用程序里的定义。Lite里包含有多个预定义的计数器可以使用。

     Troubleshooting 故障诊断

     If Photon does not behave as expected, always have a look at the logs.
     如果Photon不是像预期的那样,可以看一下日志。
 
     These are the most common pitfalls you should check as well.
     以下是最常见的错误,你需要检查一下
  • 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运行环境
  • Application missing: If Photon does not find one of the configured applications, it can’t start. Check the configuration against deployed folders.
          缺少已配置的应用程序文件
  • 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.
          应用引用的SDK版本与服务器不一致。
  • 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
          延迟超过设置的值,默认为50ms

     Dump File Setup 转储文件设置

     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.
     如果服务器崩溃了,日志中未能找到相关信息。Photon可以配置为转储文件。那些反应了状态和内存的信息是在调试中非常有用的。启用这个特性,你需要去编辑PhotonServer.config。设置“ProduceDumps”为True,并重启服务器。
     
     It might look like this example:
     以下是一个例子:
 
 
<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.
     这将写入完整的转储文件。一旦转储文件被写入,你就可以压缩它发送邮件给我们,在大多数情况下,我们会为你解答。
posted on 2015-11-25 11:25 思月行云 阅读(1793) 评论(0)  编辑 收藏 引用 所属分类: Photon

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   博问   Chat2DB   管理