示例#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
        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);
            }

            if (OnHoldMessageReceived != null)
            {
                int  numListeners = OnHoldMessageReceived?.GetInvocationList().Length ?? 0;
                int  numDone      = 0;
                bool released     = false;
                if (numListeners > 0)
                {
                    OnHoldMessageReceived?.Invoke(payloadPacket.Payload, payloadPacket.Length, () => {
                        numDone++;
                        if (numDone >= numListeners && !released)
                        {
                            released = true;
                            payloadPacket.Release();
                        }
                    });
                }
                else
                {
                    payloadPacket.Release();
                }
            }
            else
            {
                payloadPacket.Release();
            }
        }
示例#3
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;
            }

            // locate the client by endpoint
            if (!endpointClientIDMap.ContainsKey(sender))
            {
                payloadPacket.Release();
                return;
            }

            var clientIndex = endpointClientIDMap[sender];
            var client      = clientSlots[clientIndex];

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

            payloadPacket.Release();
        }
示例#4
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);
            }

            if (OnClientHoldMessageReceived != null)
            {
                int  numListeners = OnClientHoldMessageReceived?.GetInvocationList().Length ?? 0;
                int  numDone      = 0;
                bool released     = false;
                if (numListeners > 0)
                {
                    OnClientHoldMessageReceived?.Invoke(client, payloadPacket.Payload, payloadPacket.Length, () => {
                        numDone++;
                        if (numDone >= numListeners && !released)
                        {
                            released = true;
                            payloadPacket.Release();
                        }
                    });
                }
                else
                {
                    payloadPacket.Release();
                }
            }
            else
            {
                payloadPacket.Release();
            }
        }