示例#1
0
        public bool RemoveEncryptionMapping(EndPoint address, double time)
        {
            for (int i = 0; i < numEncryptionMappings; i++)
            {
                if (MiscUtils.AddressEqual(encryptionMappings[i].Address, address))
                {
                    encryptionMappings[i].Reset();

                    if (i + 1 == numEncryptionMappings)
                    {
                        int index = i - 1;
                        while (index >= 0)
                        {
                            if ((encryptionMappings[index].TimeoutSeconds < 0 || encryptionMappings[index].LastAccessTime + encryptionMappings[index].TimeoutSeconds >= time) &&
                                (encryptionMappings[index].ExpireTime <0 || encryptionMappings[index].ExpireTime> time))
                            {
                                break;
                            }
                            index--;
                        }
                        numEncryptionMappings = index + 1;
                    }

                    return(true);
                }
            }

            return(false);
        }
示例#2
0
        public bool RemoveEncryptionMapping(EndPoint address, double time)
        {
            for (int i = 0; i < numEncryptionMappings; i++)
            {
                if (MiscUtils.AddressEqual(encryptionMappings[i].Address, address))
                {
                    encryptionMappings[i].Reset();

                    if (i + 1 == numEncryptionMappings)
                    {
                        int index = i - 1;
                        while (index >= 0)
                        {
                            if (encryptionMappings[i].LastAccessTime + Defines.NETCODE_TIMEOUT_SECONDS >= time &&
                                (encryptionMappings[i].ExpireTime <0 || encryptionMappings[i].ExpireTime> time))
                            {
                                break;
                            }
                            index--;
                        }
                        numEncryptionMappings = index + 1;
                    }

                    return(true);
                }
            }

            return(false);
        }
示例#3
0
        public int FindEncryptionMapping(EndPoint address, double time)
        {
            for (int i = 0; i < numEncryptionMappings; i++)
            {
                if (MiscUtils.AddressEqual(encryptionMappings[i].Address, address) &&
                    (encryptionMappings[i].LastAccessTime + encryptionMappings[i].TimeoutSeconds >= time || encryptionMappings[i].TimeoutSeconds < 0) &&
                    (encryptionMappings[i].ExpireTime < 0.0 || encryptionMappings[i].ExpireTime >= time))
                {
                    encryptionMappings[i].LastAccessTime = time;
                    return(i);
                }
            }

            return(-1);
        }
示例#4
0
        public int FindEncryptionMapping(EndPoint address, double time)
        {
            for (int i = 0; i < numEncryptionMappings; i++)
            {
                if (MiscUtils.AddressEqual(encryptionMappings[i].Address, address) &&
                    encryptionMappings[i].LastAccessTime + Defines.NETCODE_TIMEOUT_SECONDS >= time &&
                    (encryptionMappings[i].ExpireTime < 0.0 || encryptionMappings[i].ExpireTime >= time))
                {
                    encryptionMappings[i].LastAccessTime = time;
                    return(i);
                }
            }

            return(-1);
        }
示例#5
0
        public bool Touch(int index, EndPoint address, double time)
        {
            if (index < 0 || index >= numEncryptionMappings)
            {
                throw new IndexOutOfRangeException();
            }

            if (!MiscUtils.AddressEqual(encryptionMappings[index].Address, address))
            {
                return(false);
            }

            encryptionMappings[index].LastAccessTime = time;
            encryptionMappings[index].ExpireTime     = time + Defines.NETCODE_TIMEOUT_SECONDS;
            return(true);
        }
        public int FindEncryptionMapping(EndPoint address, double time)
        {
            for (int i = 0; i < numEncryptionMappings; i++)
            {
                if (MiscUtils.AddressEqual(encryptionMappings[i].Address, address) &&
                    (encryptionMappings[i].LastAccessTime + encryptionMappings[i].TimeoutSeconds >= time || encryptionMappings[i].TimeoutSeconds < 0) &&
                    (encryptionMappings[i].ExpireTime < 0.0 || encryptionMappings[i].ExpireTime >= time))
                {
                    encryptionMappings[i].LastAccessTime = time;
                    // Hotfix, sometimes expiry time wasn't being updated and this caused clients to disconnect..
                    encryptionMappings[i].ExpireTime = time + Defines.NETCODE_TIMEOUT_SECONDS;
                    return(i);
                }
            }

            return(-1);
        }
示例#7
0
        public bool AddEncryptionMapping(EndPoint address, byte[] sendKey, byte[] receiveKey, double time, double expireTime, int timeoutSeconds, uint clientID)
        {
            for (int i = 0; i < numEncryptionMappings; i++)
            {
                if (MiscUtils.AddressEqual(encryptionMappings[i].Address, address) &&
                    (timeoutSeconds >= 0 && encryptionMappings[i].LastAccessTime + timeoutSeconds >= time))
                {
                    encryptionMappings[i].ExpireTime     = expireTime;
                    encryptionMappings[i].LastAccessTime = time;
                    encryptionMappings[i].TimeoutSeconds = timeoutSeconds;
                    encryptionMappings[i].ClientID       = clientID;

                    Buffer.BlockCopy(sendKey, 0, encryptionMappings[i].SendKey, 0, 32);
                    Buffer.BlockCopy(receiveKey, 0, encryptionMappings[i].ReceiveKey, 0, 32);
                    return(true);
                }
            }

            for (int i = 0; i < encryptionMappings.Length; i++)
            {
                if ((encryptionMappings[i].TimeoutSeconds >= 0 && encryptionMappings[i].LastAccessTime + encryptionMappings[i].TimeoutSeconds < time) ||
                    (encryptionMappings[i].ExpireTime >= 0.0 && encryptionMappings[i].ExpireTime < time))
                {
                    encryptionMappings[i].Address        = address;
                    encryptionMappings[i].ExpireTime     = expireTime;
                    encryptionMappings[i].LastAccessTime = time;
                    encryptionMappings[i].TimeoutSeconds = timeoutSeconds;
                    encryptionMappings[i].ClientID       = clientID;

                    Buffer.BlockCopy(sendKey, 0, encryptionMappings[i].SendKey, 0, 32);
                    Buffer.BlockCopy(receiveKey, 0, encryptionMappings[i].ReceiveKey, 0, 32);

                    if (i + 1 > numEncryptionMappings)
                    {
                        numEncryptionMappings = i + 1;
                    }

                    return(true);
                }
            }

            return(false);
        }
示例#8
0
        public bool AddEncryptionMapping(EndPoint address, byte[] sendKey, byte[] receiveKey, double time, double expireTime)
        {
            for (int i = 0; i < numEncryptionMappings; i++)
            {
                if (MiscUtils.AddressEqual(encryptionMappings[i].Address, address) &&
                    encryptionMappings[i].LastAccessTime + Defines.NETCODE_TIMEOUT_SECONDS >= time)
                {
                    encryptionMappings[i].ExpireTime     = expireTime;
                    encryptionMappings[i].LastAccessTime = time;

                    Buffer.BlockCopy(sendKey, 0, encryptionMappings[i].SendKey, 0, 32);
                    Buffer.BlockCopy(receiveKey, 0, encryptionMappings[i].ReceiveKey, 0, 32);
                    return(true);
                }
            }

            for (int i = 0; i < encryptionMappings.Length; i++)
            {
                if (encryptionMappings[i].LastAccessTime + Defines.NETCODE_TIMEOUT_SECONDS < time ||
                    (encryptionMappings[i].ExpireTime >= 0.0 && encryptionMappings[i].ExpireTime < time))
                {
                    encryptionMappings[i].Address        = address;
                    encryptionMappings[i].ExpireTime     = expireTime;
                    encryptionMappings[i].LastAccessTime = time;

                    Buffer.BlockCopy(sendKey, 0, encryptionMappings[i].SendKey, 0, 32);
                    Buffer.BlockCopy(receiveKey, 0, encryptionMappings[i].ReceiveKey, 0, 32);

                    if (i + 1 > numEncryptionMappings)
                    {
                        numEncryptionMappings = i + 1;
                    }

                    return(true);
                }
            }

            return(false);
        }
示例#9
0
        private void processDatagram(Datagram datagram)
        {
            if (!MiscUtils.AddressEqual(datagram.sender, currentServerEndpoint))
            {
                return;
            }

            using (var reader = ByteArrayReaderWriter.Get(datagram.payload))
            {
                NetcodePacketHeader packetHeader = new NetcodePacketHeader();
                packetHeader.Read(reader);

                int length = datagram.payloadSize - (int)reader.ReadPosition;

                switch (packetHeader.PacketType)
                {
                case NetcodePacketType.ConnectionChallenge:
                    processChallengePacket(packetHeader, length, reader);
                    break;

                case NetcodePacketType.ConnectionDenied:
                    processConnectionDenied(packetHeader, length, reader);
                    break;

                case NetcodePacketType.ConnectionKeepAlive:
                    processConnectionKeepAlive(packetHeader, length, reader);
                    break;

                case NetcodePacketType.ConnectionPayload:
                    processConnectionPayload(packetHeader, length, reader);
                    break;

                case NetcodePacketType.ConnectionDisconnect:
                    processConnectionDisconnect(packetHeader, length, reader);
                    break;
                }
            }
        }