photon 配置及日志输出

下载安装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标签内的代码进行配置

<TestGame
		MaxMessageSize="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>
      <UDPListener
				IPAddress="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 -->
      <TCPListener
				IPAddress="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 -->
      <TCPListener
				IPAddress="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 -->
      <PolicyFileListener
			IPAddress="0.0.0.0"
			Port="843"
			PolicyFile="Policy\assets\socket-policy.xml">
      </PolicyFileListener>
      <PolicyFileListener
			IPAddress="0.0.0.0"
			Port="943"
			PolicyFile="Policy\assets\socket-policy-silverlight.xml">
      </PolicyFileListener>
    </PolicyFileListeners>



    <!-- Defines the Photon Runtime Assembly to use. -->
    <Runtime
			Assembly="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">
      <Application
				Name="MOBA"
				BaseDirectory="MOBA"
				Assembly="MOBAServer"
				Type="MOBAServer.MOBAApplication" //命名空间及基类
				ForceAutoRestart="true"
				WatchFiles="dll;config"
				ExcludeFiles="log4net.config"
				>
      </Application>
      

      <!-- CounterPublisher Application -->
      <Application
				Name="CounterPublisher"
				BaseDirectory="CounterPublisher"
				Assembly="CounterPublisher"
				Type="Photon.CounterPublisher.Application"
				ForceAutoRestart="true"
				WatchFiles="dll;config"
				ExcludeFiles="log4net.config">
      </Application>
    </Applications>
  </TestGame>
将其发布在deploy目录下
之后运行启动后 就可以看见日志内容了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值