Example #1
0
        // process an incoming disconnect message
        private void processConnectionDisconnect(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;
            }

            var decryptKey = encryptionManager.GetReceiveKey(cryptIdx);

            var disconnectPacket = new NetcodeDisconnectPacket()
            {
                Header = header
            };

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

            // locate the client by endpoint and free their slot
            if (!endpointClientIDMap.ContainsKey(sender))
            {
                log("No client found for sender endpoint", NetcodeLogLevel.Debug);
                return;
            }
            var clientIndex = endpointClientIDMap[sender];

            var client = clientSlots[clientIndex];

            clientSlots[clientIndex] = null;

            endpointClientIDMap.Remove(sender);

            // remove encryption mapping
            encryptionManager.RemoveEncryptionMapping(sender, time);

            // trigger client disconnect callback
            if (OnClientDisconnected != null)
            {
                OnClientDisconnected(client);
            }

            log("Client {0} disconnected", NetcodeLogLevel.Info, client.RemoteEndpoint);
        }
Example #2
0
        private void processConnectionDisconnect(NetcodePacketHeader header, int length, ByteArrayReaderWriter stream)
        {
            if (checkReplay(header))
            {
                return;
            }
            if (this.state != ClientState.Connected)
            {
                return;
            }

            var decryptKey       = serverToClientKey;
            var disconnectPacket = new NetcodeDisconnectPacket()
            {
                Header = header
            };

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

            Disconnect();
        }
        // process an incoming disconnect message
        private void processConnectionDisconnect(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;
            }

            var decryptKey = encryptionManager.GetReceiveKey(cryptIdx);

            var disconnectPacket = new NetcodeDisconnectPacket()
            {
                Header = header
            };

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

            // locate the client by endpoint and free their slot
            var clientIndex = encryptionManager.GetClientID(cryptIdx);

            var client = clientSlots[clientIndex];

            if (client == null)
            {
                return;
            }

            clientSlots[clientIndex] = null;

            // remove encryption mapping
            encryptionManager.RemoveEncryptionMapping(sender, time);

            // make sure all other clients still have their encryption mappings
            foreach (RemoteClient otherClient in clientSlots)
            {
                if (otherClient == null)
                {
                    continue;
                }
                if (encryptionManager.FindEncryptionMapping(otherClient.RemoteEndpoint, time) == -1)
                {
                    log("Encryption mapping removed wrong mapping!", NetcodeLogLevel.Debug);
                }
            }

            // trigger client disconnect callback
            if (OnClientDisconnected != null)
            {
                OnClientDisconnected(client);
            }

            log("Client {0} disconnected", NetcodeLogLevel.Info, client.RemoteEndpoint);
        }