/// <summary> /// Called when [init]. /// </summary> /// <param name = "peer">The peer.</param> /// <param name = "data">The data.</param> public void OnInit(IPhotonPeer peer, byte[] data, byte channelCount) { try { if (log.IsDebugEnabled) { Encoding utf8Encoding = Encoding.UTF8; log.DebugFormat("OnInit - {0}", utf8Encoding.GetString(data)); } if (data[0] == '<' && data[21] == '>') { byte[] bytes = peer.GetLocalPort() == 943 ? this.silverlightPolicyBytesUtf8 : this.policyBytesUtf8; // in case the policy app ever serves a websocket port... MessageContentType contentType = peer.GetListenerType() == ListenerType.WebSocketListener ? MessageContentType.Text : MessageContentType.Binary; peer.Send(bytes, MessageReliablity.Reliable, 0, contentType); if (log.IsDebugEnabled) { log.Debug("Policy sent."); } } peer.DisconnectClient(); // silverlight does not disconnect by itself } catch (Exception e) { log.Error(e); throw; } }
public void Application_OnOutboundConnectionEstablished(IPhotonPeer peer) { lock (this.syncRoot) { this.photonPeer = peer; } if (peer.GetListenerType() != ListenerType.WebSocketListener) { if (log.IsDebugEnabled) { log.Debug("OnOutboundConnectionEstablished: sending init request"); } byte[] data = this.protocol.SerializeInitRequest(this.appName, Versions.TcpOutboundPeerVersion); SendResults results = peer.Send(data, MessageReliablity.Reliable, 0, MessageContentType.Binary); LogInitRequest(peer, 0, data, (SendResult)results); } }
/// <summary> /// Called by the unmanaged socket server when a peer intializes the connection. /// This method determines the used rpc protocol and then calls <see cref="M:Photon.SocketServer.ApplicationBase.CreatePeer(Photon.SocketServer.InitRequest)">CreatePeer</see>. /// </summary> /// <param name="nativePeer">The photon peer.</param> /// <param name="data"> The data.</param> /// <param name="channelCount">The number of channels that will be used by this peer. </param> void IPhotonApplication.OnInit(IPhotonPeer nativePeer, byte[] data, byte channelCount) { try { InitRequest request; PhotonCounter.InitPerSec.Increment(); if (operationDataLogger.IsDebugEnabled) { operationDataLogger.DebugFormat("OnInit - ConnID={0}, data=({1} bytes) {2}", new object[] { nativePeer.GetConnectionID(), data.Length, BitConverter.ToString(data) }); } if (log.IsDebugEnabled) { log.DebugFormat("OnInit - ConnID={0}, IP {1} on port {2}, type = {3}", new object[] { nativePeer.GetConnectionID(), nativePeer.GetRemoteIP(), nativePeer.GetLocalPort(), nativePeer.GetListenerType() }); } if (nativePeer.GetListenerType() == ListenerType.HTTPListener) { string str = ""; if (data.Length > 7) { str = Encoding.ASCII.GetString(data, 7, data.Length - 7); log.DebugFormat("OnInit - {0}", new object[] { str }); } log.DebugFormat("OnInit - HttpPeer cnnected. " + str, new object[0]); if (str.Contains("json")) { request = new InitRequest("LiteLobby", new Version(0, 3, 6), JsonProtocol.Instance); } else { request = new InitRequest("LiteLobby", new Version(0, 3, 6), GpBinaryByteProtocolV16.HeaderV2Instance); } } else if (nativePeer.GetListenerType() == ListenerType.WebSocketListener) { if (!Protocol.TryParseWebSocketInitRequest(data, this.ApplicationName, Versions.DefaultWebsocketPeerVersion, out request)) { log.Warn("OnInit - Failed to parse init request for WebSocket peer: {0}" + data); nativePeer.DisconnectClient(); return; } } else if (!Protocol.TryParseInitRequest(data, out request)) { if (log.IsDebugEnabled) { if (data.Length == 0) { log.Debug("OnInit - Data must contain at least one byte."); } else { log.DebugFormat("OnInit - Failed to parse init request with protocol {0}", new object[] { data[0] }); } } nativePeer.DisconnectClient(); return; } request.PhotonPeer = nativePeer; ThreadPool.QueueUserWorkItem(new WaitCallback(this.CreatePeerInternal), request); } catch (Exception exception) { log.Error(exception); throw; } }