#!/bin/bash

#send insults in bash!
#this sends insults as ascii decimals in an nmap port scan!
#(by john tate and my friends hyperintelligent daughter aria's help)

nerd="darkrp.orbitalservers.gg"
insult="haha root you faggot fuck you"
nmap="nmap -sS -sU -Pn -PS" #this must end with -P because the appended port numbers come right next

#internal (global)
dec_str="" #if you put anything in here you break everything (ends up appended to $dec_str)

# Check if sudo command is available
if ! command -v sudo > /dev/null 2>&1; then
    echo "sudo command is not available. Exiting."
    exit 1
fi

# Check if the user has sudo privileges
if ! sudo -v 2> /dev/null; then
    echo "User does not have sudo privileges. Exiting."
    exit 1
fi

function char_to_decimal() {
  printf -v dec "%d" "'$1"
  dec_str+="$dec,"
}

function string_to_decimal() {
  local str="$1"
  for (( i=0; i<${#str}; i++ )); do
    char_to_decimal "${str:$i:1}"
  done
  # Remove trailing comma from dec_str
  dec_str=${dec_str%?} #that badboy question mark removes the trailing comma
}

# Usage:
string_to_decimal '$insult'

#this constructs an nmap command
command="sudo ${nmap}${dec_str} ${nerd}"

echo "running command: $command"
eval $command
