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 void DeriveSharedKey(OperationResponse operationResponse) { if ((int)operationResponse.ReturnCode != 0) { this.EnqueueDebugReturn(DebugLevel.ERROR, "Establishing encryption keys failed. " + operationResponse.ToStringFull()); this.EnqueueStatusCallback(StatusCode.EncryptionFailedToEstablish); } else { byte[] otherPartyPublicKey = (byte[])operationResponse[PhotonCodes.ServerKey]; if (otherPartyPublicKey == null || otherPartyPublicKey.Length == 0) { this.EnqueueDebugReturn(DebugLevel.ERROR, "Establishing encryption keys failed. Server's public key is null or empty. " + operationResponse.ToStringFull()); this.EnqueueStatusCallback(StatusCode.EncryptionFailedToEstablish); } else { this.CryptoProvider.DeriveSharedKey(otherPartyPublicKey); this.isEncryptionAvailable = true; this.EnqueueStatusCallback(StatusCode.EncryptionEstablished); } } }
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); }