photon 配置及日志输出

来源:互联网 发布:linux系统api有哪些 编辑:程序博客网 时间:2024/05/19 11:47

下载安装photon好 

下载证书添加到 deploy /bin_Win64 文件夹中

打开visio 新建类库 添加引用ExitGames.Logging.Log4Net.dll,ExitGamesLibs.dll,log4net.dll,Photon.SocketServer.dll,PhotonHostRuntimeInterfaces.dll

及Litjson.dll

新建类 继承自ApplicationBase 

//客户端连接        protected override PeerBase CreatePeer(InitRequest initRequest)        {            return new MobaClient(initRequest);        }        //服务器初始化        protected override void Setup()        {            InitLogging();            LoginInfo("服务器初始化成功");        }        //服务器断开        protected override void TearDown()        {            LoginInfo("服务器断开");        }        #region 日志功能        private static readonly ILogger log = ExitGames.Logging.LogManager.GetCurrentClassLogger();        private void InitLogging()        {            ExitGames.Logging.LogManager.SetLoggerFactory(Log4NetLoggerFactory.Instance);            GlobalContext.Properties["Photon:ApplicationLogPath"] = Path.Combine(this.ApplicationRootPath, "log");            GlobalContext.Properties["LogFileName"] = "MOBA" + this.ApplicationName;            XmlConfigurator.ConfigureAndWatch(new FileInfo(Path.Combine(this.BinaryPath, "log4net.config")));        }        public static void LoginInfo(string text) {            log.Info(text.ToString());        }        #endregion
新建类继承自ClientPeer

public MobaClient(InitRequest initRequest) : base(initRequest)        {        }        //客户端断开连接        protected override void OnDisconnect(DisconnectReason reasonCode, string reasonDetail)        {        }        //客户端发起请求        protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters)        {        }
之后更改deploy\bin_Win64 目录下的PhotonServer.config 这个配置文件

复制LoadBalancing标签内的代码进行配置

<TestGameMaxMessageSize="512000"MaxQueuedDataPerPeer="512000"PerPeerMaxReliableDataInTransit="51200"PerPeerTransmitRateLimitKBSec="256"PerPeerTransmitRatePeriodMilliseconds="200"MinimumTimeout="5000"MaximumTimeout="30000"DisplayName="MOBA (Server)">//更改成自己的项目服务器名称    <!-- 0.0.0.0 opens listeners on all available IPs. Machines with multiple IPs should define the correct one here. -->    <!-- Port 5055 is Photon's default for UDP connections. -->    <UDPListeners>      <UDPListenerIPAddress="0.0.0.0"Port="5055"OverrideApplication="MOBA">//UDP监听      </UDPListener>          </UDPListeners>    <!-- 0.0.0.0 opens listeners on all available IPs. Machines with multiple IPs should define the correct one here. -->    <TCPListeners>      <!-- TCP listener for Game clients on Master application -->      <TCPListenerIPAddress="0.0.0.0"Port="4530"OverrideApplication="MOBA"//TCP监听PolicyFile="Policy\assets\socket-policy.xml"InactivityTimeout="10000">      </TCPListener>            <!-- DON'T EDIT THIS. TCP listener for GameServers on Master application -->      <TCPListenerIPAddress="0.0.0.0"Port="4520">      </TCPListener>    </TCPListeners>    <!-- Policy request listener for Unity and Flash (port 843) and Silverlight (port 943)  -->    <PolicyFileListeners>      <!-- multiple Listeners allowed for different ports -->      <PolicyFileListenerIPAddress="0.0.0.0"Port="843"PolicyFile="Policy\assets\socket-policy.xml">      </PolicyFileListener>      <PolicyFileListenerIPAddress="0.0.0.0"Port="943"PolicyFile="Policy\assets\socket-policy-silverlight.xml">      </PolicyFileListener>    </PolicyFileListeners>    <!-- Defines the Photon Runtime Assembly to use. -->    <RuntimeAssembly="PhotonHostRuntime, Culture=neutral"Type="PhotonHostRuntime.PhotonDomainManager"UnhandledExceptionPolicy="Ignore">    </Runtime>    <!-- Defines which applications are loaded on start and which of them is used by default. Make sure the default application is defined. -->    <!-- Application-folders must be located in the same folder as the bin_win32 folders. The BaseDirectory must include a "bin" folder. -->    <Applications Default="MOBA">      <ApplicationName="MOBA"BaseDirectory="MOBA"Assembly="MOBAServer"Type="MOBAServer.MOBAApplication" //命名空间及基类ForceAutoRestart="true"WatchFiles="dll;config"ExcludeFiles="log4net.config">      </Application>            <!-- CounterPublisher Application -->      <ApplicationName="CounterPublisher"BaseDirectory="CounterPublisher"Assembly="CounterPublisher"Type="Photon.CounterPublisher.Application"ForceAutoRestart="true"WatchFiles="dll;config"ExcludeFiles="log4net.config">      </Application>    </Applications>  </TestGame>
将其发布在deploy目录下
之后运行启动后 就可以看见日志内容了

0 0
原创粉丝点击