public override void Destruct() { base.Destruct(); if (this.m_timer != null) { this.m_timer.Destruct(); this.m_timer = null; } this.m_spawnData = null; this.m_spawned = null; this.m_randomizer = null; }
private void ScrambleNonceUsingMersenneTwister(byte[] nonce) { LogicMersenneTwisterRandom scrambler = new LogicMersenneTwisterRandom(this.m_scramblerSeed); int key = 0; for (int i = 0; i < 100; i++) { key = scrambler.Rand(256); } for (int i = 0; i < nonce.Length; i++) { nonce[i] ^= (byte)(key & (byte)scrambler.Rand(256)); } }
public LogicSpawnerComponent(LogicGameObject gameObject, LogicObstacleData spawnData, int radius, int intervalSeconds, int spawnCount, int maxSpawned, int maxLifetimeSpawns) : base(gameObject) { this.m_spawned = new LogicArrayList <int>(); this.m_randomizer = new LogicMersenneTwisterRandom(); this.m_spawnData = spawnData; this.m_radius = radius; this.m_intervalSeconds = intervalSeconds; this.m_spawnCount = spawnCount; this.m_maxSpawned = maxSpawned; this.m_maxLifetimeSpawns = maxLifetimeSpawns; this.m_randomizer.Initialize(this.m_parent.GetGlobalID()); this.m_spawned.EnsureCapacity(maxSpawned); }
/// <summary> /// Called when the gateway receive a packet. /// </summary> internal int OnReceive(byte[] packet, int length) { if (length >= 7) { length -= 7; int messageType = packet[1] | packet[0] << 8; int messageLength = packet[4] | packet[3] << 8 | packet[2] << 16; int messageVersion = packet[6] | packet[5] << 8; if (length >= messageLength) { int encodingLength = messageLength; byte[] encodingByteArray = new byte[messageLength]; Array.Copy(packet, 7, encodingByteArray, 0, messageLength); if (this._receiveEncrypter != null) { byte[] encryptedByteArray = encodingByteArray; byte[] decryptedByteArray = new byte[messageLength - this._receiveEncrypter.GetOverheadEncryption()]; this._receiveEncrypter.Decrypt(encryptedByteArray, decryptedByteArray, messageLength); encodingByteArray = decryptedByteArray; encodingLength -= this._receiveEncrypter.GetOverheadEncryption(); } PiranhaMessage message = LogicMagicMessageFactory.Instance.CreateMessageByType(messageType); if (message != null) { message.SetMessageVersion((short)messageVersion); message.GetByteStream().SetByteArray(encodingByteArray, encodingLength); try { message.Decode(); if (message.GetMessageType() == 20000) { ExtendedSetEncryptionMessage extendedSetEncryptionMessage = (ExtendedSetEncryptionMessage)message; LogicMersenneTwisterRandom scrambler = new LogicMersenneTwisterRandom(0); byte byte100 = 0; for (int i = 0; i < 100; i++) { byte100 = (byte)scrambler.NextInt(); } byte[] nonce = extendedSetEncryptionMessage.RemoveNonce(); string scrambledNonce = null; for (int i = 0; i < nonce.Length; i++) { scrambledNonce += (char)(nonce[i] ^ (byte)(scrambler.NextInt() & byte100)); } if (this._receiveEncrypter != null) { this._receiveEncrypter.Destruct(); this._receiveEncrypter = null; } if (this._sendEncrypter != null) { this._sendEncrypter.Destruct(); this._sendEncrypter = null; } this._receiveEncrypter = new RC4Encrypter(LogicMessagingConstants.RC4_KEY, scrambledNonce); this._sendEncrypter = new RC4Encrypter(LogicMessagingConstants.RC4_KEY, scrambledNonce); } else { this.MessageManager.ReceiveMessage(message); } } catch (Exception exception) { Logging.Error("Client::onReceive message decode exception, trace: " + exception); } Logging.Print("Client::sendMessage message " + message.GetType().Name + " received"); } else { Logging.Warning("NetworkMessaging::onReceive Ignoring message of unknown type " + messageType); } return(messageLength + 7); } } return(0); }