Esempio n. 1
0
        /// <summary>
        /// This method makes a copy of the original message and prepares it for
        /// sending it to the relay.
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        private static Message.Message CreateRconMessage(Message.Message message)
        {
            // get relay address from the unreachable peer
            var relayAddresses = message.Recipient.PeerSocketAddresses.ToArray();
            PeerSocketAddress socketAddress;

            if (relayAddresses.Length > 0)
            {
                // we should be fair and choose one of the relays randomly
                socketAddress = relayAddresses[Utils.Utils.RandomPositiveInt(relayAddresses.Length)];
            }
            else
            {
                throw new ArgumentException("There are no PeerSocketAddresses available for this relayed peer. This should not be possible!");
            }

            // we need to make a copy of the original message
            var rconMessage = new Message.Message();

            rconMessage.SetSender(message.Sender);
            rconMessage.SetVersion(message.Version);
            rconMessage.SetIntValue(message.MessageId);

            // make the message ready to send
            PeerAddress recipient =
                message.Recipient
                .ChangeAddress(socketAddress.InetAddress)
                .ChangePorts(socketAddress.TcpPort, socketAddress.UdpPort)
                .ChangeIsRelayed(false);

            rconMessage.SetRecipient(recipient);
            rconMessage.SetCommand(Rpc.Rpc.Commands.Rcon.GetNr());
            rconMessage.SetType(Message.Message.MessageType.Request1);

            return(rconMessage);
        }
Esempio n. 2
0
        /// <summary>
        /// This method makes a copy of the original message and prepares it for 
        /// sending it to the relay.
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        private static Message.Message CreateRconMessage(Message.Message message)
        {
            // get relay address from the unreachable peer
            var relayAddresses = message.Recipient.PeerSocketAddresses.ToArray();
            PeerSocketAddress socketAddress;

            if (relayAddresses.Length > 0)
            {
                // we should be fair and choose one of the relays randomly
                socketAddress = relayAddresses[Utils.Utils.RandomPositiveInt(relayAddresses.Length)];
            }
            else
            {
                throw new ArgumentException("There are no PeerSocketAddresses available for this relayed peer. This should not be possible!");
            }

            // we need to make a copy of the original message
            var rconMessage = new Message.Message();
            rconMessage.SetSender(message.Sender);
            rconMessage.SetVersion(message.Version);
            rconMessage.SetIntValue(message.MessageId);

            // make the message ready to send
            PeerAddress recipient =
                message.Recipient
                    .ChangeAddress(socketAddress.InetAddress)
                    .ChangePorts(socketAddress.TcpPort, socketAddress.UdpPort)
                    .ChangeIsRelayed(false);
            rconMessage.SetRecipient(recipient);
            rconMessage.SetCommand(Rpc.Rpc.Commands.Rcon.GetNr());
            rconMessage.SetType(Message.Message.MessageType.Request1);

            return rconMessage;
        }