internal TConnect(TPeer npeer, string ipPort) { if (npeer.debugOut >= DebugLevel.ALL) { npeer.Listener.DebugReturn(DebugLevel.ALL, "new TConnect()"); } this.peer = npeer; }
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); }