コード例 #1
0
        private void processConnectionPayload(NetcodePacketHeader header, int length, ByteArrayReaderWriter stream)
        {
            if (checkReplay(header))
            {
                return;
            }
            if (this.state != ClientState.Connected)
            {
                return;
            }

            var decryptKey    = serverToClientKey;
            var payloadPacket = new NetcodePayloadPacket()
            {
                Header = header
            };

            if (!payloadPacket.Read(stream, length, decryptKey, connectToken.ProtocolID))
            {
                return;
            }

            lastResponseTime = time;
            if (OnMessageReceived != null)
            {
                OnMessageReceived(payloadPacket.Payload, payloadPacket.Length);
            }

            payloadPacket.Release();
        }
コード例 #2
0
        // process an incoming payload
        private void processConnectionPayload(ByteArrayReaderWriter reader, NetcodePacketHeader header, int size, EndPoint sender)
        {
            if (checkReplay(header, sender))
            {
                return;
            }

            // encryption mapping was not registered, so don't bother
            int cryptIdx = encryptionManager.FindEncryptionMapping(sender, time);

            if (cryptIdx == -1)
            {
                log("No crytpo key for sender", NetcodeLogLevel.Debug);
                return;
            }

            // grab the decryption key and decrypt the packet
            var decryptKey = encryptionManager.GetReceiveKey(cryptIdx);

            var payloadPacket = new NetcodePayloadPacket()
            {
                Header = header
            };

            if (!payloadPacket.Read(reader, size - (int)reader.ReadPosition, decryptKey, protocolID))
            {
                return;
            }

            var clientIndex = encryptionManager.GetClientID(cryptIdx);
            var client      = clientSlots[clientIndex];

            // trigger callback
            if (OnClientMessageReceived != null)
            {
                OnClientMessageReceived(client, payloadPacket.Payload, payloadPacket.Length);
            }

            payloadPacket.Release();
        }