internal void SendData(byte[] data) { try { this.bytesOut += (long)data.Length; bool trafficStatsEnabled = base.TrafficStatsEnabled; if (trafficStatsEnabled) { TrafficStats expr_3D = base.TrafficStatsOutgoing; int totalPacketCount = expr_3D.TotalPacketCount; expr_3D.TotalPacketCount = totalPacketCount + 1; base.TrafficStatsOutgoing.TotalCommandsInPackets += this.outgoingCommandsInStream; } bool isSimulationEnabled = base.NetworkSimulationSettings.IsSimulationEnabled; if (isSimulationEnabled) { base.SendNetworkSimulated(delegate { this.rt.Send(data, data.Length); }); } else { this.rt.Send(data, data.Length); } } catch (Exception ex) { bool flag = base.debugOut >= DebugLevel.ERROR; if (flag) { base.Listener.DebugReturn(DebugLevel.ERROR, ex.ToString()); } SupportClass.WriteStackTrace(ex); } }
public static void WriteStackTrace(Exception throwable) { SupportClass.WriteStackTrace(throwable, (TextWriter)null); }
internal virtual bool DeserializeMessageAndCallback(byte[] inBuff) { if (inBuff.Length < 2) { if (this.debugOut >= DebugLevel.ERROR) { this.Listener.DebugReturn(DebugLevel.ERROR, "Incoming UDP data too short! " + (object)inBuff.Length); } return(false); } if ((int)inBuff[0] != 243 && (int)inBuff[0] != 253) { if (this.debugOut >= DebugLevel.ERROR) { this.Listener.DebugReturn(DebugLevel.ALL, "No regular operation UDP message: " + (object)inBuff[0]); } return(false); } byte num1 = (byte)((uint)inBuff[1] & (uint)sbyte.MaxValue); bool flag = ((int)inBuff[1] & 128) > 0; MemoryStream memoryStream = (MemoryStream)null; if ((int)num1 != 1) { try { if (flag) { inBuff = this.CryptoProvider.Decrypt(inBuff, 2, inBuff.Length - 2); memoryStream = new MemoryStream(inBuff); } else { memoryStream = new MemoryStream(inBuff); memoryStream.Seek(2L, SeekOrigin.Begin); } } catch (Exception ex) { if (this.debugOut >= DebugLevel.ERROR) { this.Listener.DebugReturn(DebugLevel.ERROR, ex.ToString()); } SupportClass.WriteStackTrace(ex); return(false); } } int num2 = 0; switch ((int)num1 - 1) { case 0: this.InitCallback(); break; case 2: OperationResponse operationResponse1 = Protocol.DeserializeOperationResponse(memoryStream); if (this.TrafficStatsEnabled) { this.TrafficStatsGameLevel.CountResult(this.ByteCountCurrentDispatch); num2 = SupportClass.GetTickCount(); } this.Listener.OnOperationResponse(operationResponse1); if (this.TrafficStatsEnabled) { this.TrafficStatsGameLevel.TimeForResponseCallback(operationResponse1.OperationCode, SupportClass.GetTickCount() - num2); break; } break; case 3: EventData eventData = Protocol.DeserializeEventData(memoryStream); if (this.TrafficStatsEnabled) { this.TrafficStatsGameLevel.CountEvent(this.ByteCountCurrentDispatch); num2 = SupportClass.GetTickCount(); } this.Listener.OnEvent(eventData); if (this.TrafficStatsEnabled) { this.TrafficStatsGameLevel.TimeForEventCallback(eventData.Code, SupportClass.GetTickCount() - num2); break; } break; case 6: OperationResponse operationResponse2 = Protocol.DeserializeOperationResponse(memoryStream); if (this.TrafficStatsEnabled) { this.TrafficStatsGameLevel.CountResult(this.ByteCountCurrentDispatch); num2 = SupportClass.GetTickCount(); } if ((int)operationResponse2.OperationCode == (int)PhotonCodes.InitEncryption) { this.DeriveSharedKey(operationResponse2); } else { this.EnqueueDebugReturn(DebugLevel.ERROR, "Received unknown internal operation. " + operationResponse2.ToStringFull()); } if (this.TrafficStatsEnabled) { this.TrafficStatsGameLevel.TimeForResponseCallback(operationResponse2.OperationCode, SupportClass.GetTickCount() - num2); break; } break; default: this.EnqueueDebugReturn(DebugLevel.ERROR, "unexpected msgType " + (object)num1); break; } return(true); }
internal virtual bool DeserializeMessageAndCallback(StreamBuffer stream) { if (stream.IntLength < 2) { if ((int)this.debugOut >= 1) { this.Listener.DebugReturn(DebugLevel.ERROR, "Incoming UDP data too short! " + stream.IntLength); } return(false); } byte b = stream.ReadByteAsByte(); if (b != 243 && b != 253) { if ((int)this.debugOut >= 1) { this.Listener.DebugReturn(DebugLevel.ALL, "No regular operation UDP message: " + b); } return(false); } byte b2 = stream.ReadByteAsByte(); byte b3 = (byte)(b2 & 0x7F); bool flag = (b2 & 0x80) > 0; if (b3 != 1) { try { if (flag) { byte[] buf = this.CryptoProvider.Decrypt(stream.GetBuffer(), 2, stream.IntLength - 2); stream = new StreamBuffer(buf); } else { stream.Seek(2L, SeekOrigin.Begin); } } catch (Exception ex) { if ((int)this.debugOut >= 1) { this.Listener.DebugReturn(DebugLevel.ERROR, "msgType: " + b3 + " exception: " + ex.ToString()); } SupportClass.WriteStackTrace(ex); return(false); } } if (FullLogging) { Listener.DebugReturn(DebugLevel.ERROR, SupportClass.StreamBufferToString(stream)); } int num = 0; switch (b3) { case 3: { OperationResponse operationResponse = this.SerializationProtocol.DeserializeOperationResponse(stream); if (this.TrafficStatsEnabled) { this.TrafficStatsGameLevel.CountResult(this.ByteCountCurrentDispatch); num = SupportClass.GetTickCount(); } this.Listener.OnOperationResponse(operationResponse); if (this.TrafficStatsEnabled) { this.TrafficStatsGameLevel.TimeForResponseCallback(operationResponse.OperationCode, SupportClass.GetTickCount() - num); } break; } case 4: { try { EventData eventData = this.SerializationProtocol.DeserializeEventData(stream, this.reusableEventData); if (this.TrafficStatsEnabled) { this.TrafficStatsGameLevel.CountEvent(this.ByteCountCurrentDispatch); num = SupportClass.GetTickCount(); } this.Listener.OnEvent(eventData); if (this.TrafficStatsEnabled) { this.TrafficStatsGameLevel.TimeForEventCallback(eventData.Code, SupportClass.GetTickCount() - num); } if (this.photonPeer.ReuseEventInstance) { this.reusableEventData = eventData; } } catch (Exception e) { if (debugOut >= DebugLevel.INFO) { this.EnqueueDebugReturn(DebugLevel.ERROR, "Received abnormal EventData: " + e.Message + "\nException: " + e.StackTrace); } return(true); } break; } case 1: this.InitCallback(); break; case 7: { OperationResponse operationResponse = this.SerializationProtocol.DeserializeOperationResponse(stream); if (this.TrafficStatsEnabled) { this.TrafficStatsGameLevel.CountResult(this.ByteCountCurrentDispatch); num = SupportClass.GetTickCount(); } if (operationResponse.OperationCode == PhotonCodes.InitEncryption) { this.DeriveSharedKey(operationResponse); } else if (operationResponse.OperationCode == PhotonCodes.Ping) { TPeer tPeer = this as TPeer; if (tPeer != null) { tPeer.ReadPingResult(operationResponse); } } else { this.EnqueueDebugReturn(DebugLevel.ERROR, "Received unknown internal operation. " + operationResponse.ToStringFull()); } if (this.TrafficStatsEnabled) { this.TrafficStatsGameLevel.TimeForResponseCallback(operationResponse.OperationCode, SupportClass.GetTickCount() - num); } break; } case 8: { object obj = this.SerializationProtocol.DeserializeMessage(stream); if (this.TrafficStatsEnabled) { this.TrafficStatsGameLevel.CountEvent(this.ByteCountCurrentDispatch); num = SupportClass.GetTickCount(); } if (this.TrafficStatsEnabled) { this.TrafficStatsGameLevel.TimeForMessageCallback(SupportClass.GetTickCount() - num); } break; } case 9: { if (this.TrafficStatsEnabled) { this.TrafficStatsGameLevel.CountEvent(this.ByteCountCurrentDispatch); num = SupportClass.GetTickCount(); } byte[] array = stream.ToArrayFromPos(); if (this.TrafficStatsEnabled) { this.TrafficStatsGameLevel.TimeForRawMessageCallback(SupportClass.GetTickCount() - num); } break; } default: this.EnqueueDebugReturn(DebugLevel.ERROR, "unexpected msgType " + b3); break; } return(true); }
internal virtual bool DeserializeMessageAndCallback(byte[] inBuff) { bool flag = inBuff.Length < 2; bool result; if (flag) { bool flag2 = this.debugOut >= DebugLevel.ERROR; if (flag2) { this.Listener.DebugReturn(DebugLevel.ERROR, "Incoming UDP data too short! " + inBuff.Length); } result = false; } else { bool flag3 = inBuff[0] != 243 && inBuff[0] != 253; if (flag3) { bool flag4 = this.debugOut >= DebugLevel.ERROR; if (flag4) { this.Listener.DebugReturn(DebugLevel.ALL, "No regular operation UDP message: " + inBuff[0]); } result = false; } else { byte b = inBuff[1] & 127; bool flag5 = (inBuff[1] & 128) > 0; StreamBuffer streamBuffer = null; bool flag6 = b != 1; if (flag6) { try { bool flag7 = flag5; if (flag7) { inBuff = this.CryptoProvider.Decrypt(inBuff, 2, inBuff.Length - 2); streamBuffer = new StreamBuffer(inBuff); } else { streamBuffer = new StreamBuffer(inBuff); streamBuffer.Seek(2L, SeekOrigin.Begin); } } catch (Exception ex) { bool flag8 = this.debugOut >= DebugLevel.ERROR; if (flag8) { this.Listener.DebugReturn(DebugLevel.ERROR, ex.ToString()); } SupportClass.WriteStackTrace(ex); result = false; return(result); } } int num = 0; switch (b) { case 1: this.InitCallback(); goto IL_360; case 3: { OperationResponse operationResponse = this.protocol.DeserializeOperationResponse(streamBuffer); bool trafficStatsEnabled = this.TrafficStatsEnabled; if (trafficStatsEnabled) { this.TrafficStatsGameLevel.CountResult(this.ByteCountCurrentDispatch); num = SupportClass.GetTickCount(); } this.Listener.OnOperationResponse(operationResponse); bool trafficStatsEnabled2 = this.TrafficStatsEnabled; if (trafficStatsEnabled2) { this.TrafficStatsGameLevel.TimeForResponseCallback(operationResponse.OperationCode, SupportClass.GetTickCount() - num); } goto IL_360; } case 4: { EventData eventData = this.protocol.DeserializeEventData(streamBuffer); bool trafficStatsEnabled3 = this.TrafficStatsEnabled; if (trafficStatsEnabled3) { this.TrafficStatsGameLevel.CountEvent(this.ByteCountCurrentDispatch); num = SupportClass.GetTickCount(); } this.Listener.OnEvent(eventData); bool trafficStatsEnabled4 = this.TrafficStatsEnabled; if (trafficStatsEnabled4) { this.TrafficStatsGameLevel.TimeForEventCallback(eventData.Code, SupportClass.GetTickCount() - num); } goto IL_360; } case 7: { OperationResponse operationResponse = this.protocol.DeserializeOperationResponse(streamBuffer); bool trafficStatsEnabled5 = this.TrafficStatsEnabled; if (trafficStatsEnabled5) { this.TrafficStatsGameLevel.CountResult(this.ByteCountCurrentDispatch); num = SupportClass.GetTickCount(); } bool flag9 = operationResponse.OperationCode == PhotonCodes.InitEncryption; if (flag9) { this.DeriveSharedKey(operationResponse); } else { bool flag10 = operationResponse.OperationCode == PhotonCodes.Ping; if (flag10) { TPeer tPeer = this as TPeer; bool flag11 = tPeer != null; if (flag11) { tPeer.ReadPingResult(operationResponse); } else { this.EnqueueDebugReturn(DebugLevel.ERROR, "Ping response not used. " + operationResponse.ToStringFull()); } } else { this.EnqueueDebugReturn(DebugLevel.ERROR, "Received unknown internal operation. " + operationResponse.ToStringFull()); } } bool trafficStatsEnabled6 = this.TrafficStatsEnabled; if (trafficStatsEnabled6) { this.TrafficStatsGameLevel.TimeForResponseCallback(operationResponse.OperationCode, SupportClass.GetTickCount() - num); } goto IL_360; } } this.EnqueueDebugReturn(DebugLevel.ERROR, "unexpected msgType " + b); IL_360: result = true; } } return(result); }
internal virtual bool DeserializeMessageAndCallback(byte[] inBuff) { OperationResponse opRes; if (inBuff.Length < 2) { if (this.debugOut >= DebugLevel.ERROR) { this.Listener.DebugReturn(DebugLevel.ERROR, "Incoming UDP data too short! " + inBuff.Length); } return(false); } if ((inBuff[0] != 0xf3) && (inBuff[0] != 0xfd)) { if (this.debugOut >= DebugLevel.ERROR) { this.Listener.DebugReturn(DebugLevel.ALL, "No regular operation UDP message: " + inBuff[0]); } return(false); } byte msgType = (byte)(inBuff[1] & 0x7f); bool isEncrypted = (inBuff[1] & 0x80) > 0; MemoryStream stream = null; if (msgType != 1) { try { if (isEncrypted) { inBuff = this.CryptoProvider.Decrypt(inBuff, 2, inBuff.Length - 2); stream = new MemoryStream(inBuff); } else { stream = new MemoryStream(inBuff); stream.Seek(2L, SeekOrigin.Begin); } } catch (Exception ex) { if (this.debugOut >= DebugLevel.ERROR) { this.Listener.DebugReturn(DebugLevel.ERROR, ex.ToString()); } SupportClass.WriteStackTrace(ex, null); return(false); } } int timeBeforeCallback = 0; switch (msgType) { case 1: this.InitCallback(); break; case 3: opRes = Protocol.DeserializeOperationResponse(stream); if (this.TrafficStatsEnabled) { this.TrafficStatsGameLevel.CountResult(this.ByteCountCurrentDispatch); timeBeforeCallback = SupportClass.GetTickCount(); } this.Listener.OnOperationResponse(opRes); if (this.TrafficStatsEnabled) { this.TrafficStatsGameLevel.TimeForResponseCallback(opRes.OperationCode, SupportClass.GetTickCount() - timeBeforeCallback); } break; case 4: { EventData ev = Protocol.DeserializeEventData(stream); if (this.TrafficStatsEnabled) { this.TrafficStatsGameLevel.CountEvent(this.ByteCountCurrentDispatch); timeBeforeCallback = SupportClass.GetTickCount(); } this.Listener.OnEvent(ev); if (this.TrafficStatsEnabled) { this.TrafficStatsGameLevel.TimeForEventCallback(ev.Code, SupportClass.GetTickCount() - timeBeforeCallback); } break; } case 7: opRes = Protocol.DeserializeOperationResponse(stream); if (this.TrafficStatsEnabled) { this.TrafficStatsGameLevel.CountResult(this.ByteCountCurrentDispatch); timeBeforeCallback = SupportClass.GetTickCount(); } if (opRes.OperationCode == PhotonCodes.InitEncryption) { this.DeriveSharedKey(opRes); } else { this.EnqueueDebugReturn(DebugLevel.ERROR, "Received unknown internal operation. " + opRes.ToStringFull()); } if (this.TrafficStatsEnabled) { this.TrafficStatsGameLevel.TimeForResponseCallback(opRes.OperationCode, SupportClass.GetTickCount() - timeBeforeCallback); } break; default: this.EnqueueDebugReturn(DebugLevel.ERROR, "unexpected msgType " + msgType); break; } return(true); }