* @return rconMessage
*/
private static Message createRconMessage(final Message message) {
// get Relay InetAddress from unreachable peer
Object[] relayInetAdresses = message.recipient().peerSocketAddresses().toArray();
PeerSocketAddress socketAddress = null;
if (relayInetAdresses.length > 0) {
// we should be fair and choose one of the relays randomly
socketAddress = (PeerSocketAddress) relayInetAdresses[Utils.randomPositiveInt(relayInetAdresses.length)];
} else {
throw new IllegalArgumentException(
"There are no PeerSocketAdresses available for this relayed Peer. This should not be possible!");
}
// we need to make a copy of the original message
Message rconMessage = new Message();
rconMessage.sender(message.sender());
rconMessage.version(message.version());
// store the message id in the payload to get the cached message later
rconMessage.intValue(message.messageId());
// the message must have set the keepAlive Flag true. If not, the relay
// peer will close the PeerConnection to the unreachable peer.
rconMessage.keepAlive(true);
// making the message ready to send
PeerAddress recipient = message.recipient().changeAddress(socketAddress.inetAddress())
.changePorts(socketAddress.tcpPort(), socketAddress.udpPort()).changeRelayed(false);
rconMessage.recipient(recipient);
rconMessage.command(RPC.Commands.RCON.getNr());
rconMessage.type(Message.Type.REQUEST_1);
return rconMessage;
}